Skip to content

Commit

Permalink
Fix cast receiver idle behavior
Browse files Browse the repository at this point in the history
When we replay a video without reloading, the idle card should disappear.

Closes #558

Change-Id: Ib2bca456ad90c8f2b4554f22f1edb920c69c8ada
  • Loading branch information
joeyparrish committed Oct 25, 2016
1 parent ab43df2 commit bcc239c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/cast/cast_receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,19 @@ shaka.cast.CastReceiver.prototype.init_ = function() {

// Maintain idle state.
this.player_.addEventListener('loading', function() {
// No longer idle once loading. This allows us to show the spinner during
// the initial buffering phase.
this.isIdle_ = false;
this.onCastStatusChanged_();
}.bind(this));
this.video_.addEventListener('playing', function() {
// No longer idle once playing. This allows us to replay a video without
// reloading.
this.isIdle_ = false;
this.onCastStatusChanged_();
}.bind(this));
this.player_.addEventListener('unloading', function() {
// Go idle when unloading content.
this.isIdle_ = true;
this.onCastStatusChanged_();
}.bind(this));
Expand Down
15 changes: 15 additions & 0 deletions test/cast/cast_receiver_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,39 @@ describe('CastReceiver', function() {
var fakeLoadingEvent = {type: 'loading'};
var fakeUnloadingEvent = {type: 'unloading'};
var fakeEndedEvent = {type: 'ended'};
var fakePlayingEvent = {type: 'playing'};

shaka.test.Util.delay(0.2).then(function() {
expect(listener).not.toHaveBeenCalled();
expect(receiver.isIdle()).toBe(true);

mockPlayer.listeners['loading'](fakeLoadingEvent);
return shaka.test.Util.delay(0.2);
}).then(function() {
expect(listener).toHaveBeenCalled();
expect(receiver.isIdle()).toBe(false);
listener.calls.reset();

mockPlayer.listeners['unloading'](fakeUnloadingEvent);
return shaka.test.Util.delay(0.2);
}).then(function() {
expect(listener).toHaveBeenCalled();
expect(receiver.isIdle()).toBe(true);
listener.calls.reset();

mockVideo.ended = true;
mockVideo.listeners['ended'](fakeEndedEvent);
return shaka.test.Util.delay(5.2); // There is a long delay for 'ended'
}).then(function() {
expect(listener).toHaveBeenCalled();
listener.calls.reset();
expect(receiver.isIdle()).toBe(true);

mockVideo.ended = false;
mockVideo.listeners['playing'](fakePlayingEvent);
}).then(function() {
expect(listener).toHaveBeenCalled();
expect(receiver.isIdle()).toBe(false);
}).catch(fail).then(done);
});
});
Expand Down

0 comments on commit bcc239c

Please sign in to comment.