Skip to content

Commit

Permalink
- added playingChanged callback
Browse files Browse the repository at this point in the history
- passed entries to comingNext instead of videos
  • Loading branch information
Jonathan Raoult committed Feb 11, 2015
1 parent 58cf315 commit e915d1a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var sequencer = require('./sequencer'),
* @property {function(*): Video} videoProducer
* @property {function(*): *} nextEntryProducer
* @property {number} transitionDuration
* @property {?function(Video, ?Video)} comingNext
* @property {?function(Entry, ?Entry)} comingNext
* @property {?function(Entry)} playingChanged
* @property {?function(PlaybackState, PlaybackState)} stateChanged
* @property {?function(Entry, boolean)} loadingChanged called each time an entry started or stopped to load
* following an user action (does not include preloading)
Expand All @@ -52,6 +53,7 @@ function playback(config) {
var _config = defaults({}, config, {
comingNext: noop,
stateChanged: noop,
playingChanged: noop,
loadingChanged: noop,
loadFailed: noop,
debug: {
Expand Down Expand Up @@ -102,6 +104,7 @@ function playback(config) {
playbackSlotProducer: playbackSlotProducer,
comingNext: _config.comingNext,
stateChanged: _config.stateChanged,
playingChanged: _config.playingChanged,
loadingChanged: _config.loadingChanged,
loadFailed: _config.loadFailed
});
Expand Down
12 changes: 7 additions & 5 deletions src/main/sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ var States = enumeration(['pristine', 'playing', 'paused', 'stopped']);
* @name sequencerConfig
* @typedef {Object} sequencerConfig
* @property {function(?Entry):Entry} nextEntryProducer
* @property {function(Video, ?Video)} comingNext
* @property {function(Entry, ?Entry)} comingNext
* @property {function({entry: Entry, endingSoon: function, ending: function}):PlaybackSlot} playbackSlotProducer
* @property {function(SequencerState, SequencerState)} stateChanged
* @property {function(Entry)} playingChanged
* @property {function(Entry, boolean)} loadingChanged
* @property {function(Entry, ?Error)} loadFailed
*/
Expand Down Expand Up @@ -112,6 +113,7 @@ function sequencer(config) {
changedListener: function(prevSlot, slot) {
if (slot) {
slot.start();
_config.playingChanged(slot.entry);
var nextEntry = _config.nextEntryProducer(slot.entry);
if (nextEntry) {
preload(nextEntry);
Expand Down Expand Up @@ -166,14 +168,14 @@ function sequencer(config) {
}

function notifyComingNext() {
var nextVideo = null;
var nextEntry = null;
if (_skippingSlot.get()) {
nextVideo = _skippingSlot.get().video;
nextEntry = _skippingSlot.get().entry;
} else if (_preloadingSlot.get()) {
nextVideo = _preloadingSlot.get().video;
nextEntry = _preloadingSlot.get().entry;
}

_config.comingNext(_playingSlot.get().video, nextVideo);
_config.comingNext(_playingSlot.get().entry, nextEntry);
}

/**
Expand Down
29 changes: 28 additions & 1 deletion src/test/unit/sequencerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('A sequencer', function() {
comingNext: jasmine.createSpy('comingNextSpy'),
stateChanged: jasmine.createSpy('stateChangedSpy'),
loadingChanged: jasmine.createSpy('loadingChangedSpy'),
playingChanged: jasmine.createSpy('playingChangedSpy'),
loadFailed: jasmine.createSpy('loadFailedSpy')
};
return sequencer(defaults({}, inter(defaultConfig), defaultConfig));
Expand Down Expand Up @@ -167,6 +168,7 @@ describe('A sequencer', function() {
});
});


return slot;
}
};
Expand Down Expand Up @@ -256,7 +258,7 @@ describe('A sequencer', function() {
});

function runChecks() {
expect(comingNextSpy).toHaveBeenCalledWith(_entries[0].video, _entries[1].video);
expect(comingNextSpy).toHaveBeenCalledWith(_entries[0], _entries[1]);

done();
}
Expand Down Expand Up @@ -499,6 +501,31 @@ describe('A sequencer', function() {
}
});

it('calls playingChanged when en entry starts', function(done) {
var playingChangedSpy,

seq = sequencerWithDefaults(function(seqDefaultCfg) {
var expectedPlayingChangedCallsCount = 2,
runChecksAfter = after(expectedPlayingChangedCallsCount, runChecks);

playingChangedSpy = seqDefaultCfg.playingChanged.and.callFake(runChecksAfter);
});

seq.play();
seq.skip(_entries[0]);
defer(function() {
seq.skip(_entries[1]);
});

function runChecks() {
expect(playingChangedSpy.calls.allArgs()).toEqual([
[_entries[0]],
[_entries[1]]
]);
done();
}
});

it('calls loadingChanged on skip when en entry starts, stops and fails to load', function(done) {
var loadingChangedSpy,

Expand Down

0 comments on commit e915d1a

Please sign in to comment.