Skip to content

Commit

Permalink
Delegate disconnecting from chromecast to Chrome.
Browse files Browse the repository at this point in the history
Show 'stop casting' dialog on chromecast control click when casting.
If user chooses to stop, delegate disconnecting to Chrome.

Related to #261

Change-Id: I3072a3723e0d0d526039946fb45713e20349e54c
  • Loading branch information
ismena committed Sep 2, 2016
1 parent 359d2c7 commit b335c5a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
2 changes: 1 addition & 1 deletion demo/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ ShakaControls.prototype.onFastForwardClick_ = function() {
/** @private */
ShakaControls.prototype.onCastClick_ = function() {
if (this.castProxy_.isCasting()) {
this.castProxy_.disconnect();
this.castProxy_.suggestDisconnect();
} else {
this.castButton_.disabled = true;
this.castProxy_.cast().then(function() {
Expand Down
6 changes: 3 additions & 3 deletions lib/cast/cast_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ shaka.cast.CastProxy.prototype.setAppData = function(appData) {


/**
* Disconnect from the cast connection.
* Show a dialog where user can choose to disconnect from the cast connection.
* @export
*/
shaka.cast.CastProxy.prototype.disconnect = function() {
this.sender_.disconnect();
shaka.cast.CastProxy.prototype.suggestDisconnect = function() {
this.sender_.showDisconnectDialog();
};


Expand Down
21 changes: 13 additions & 8 deletions lib/cast/cast_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ shaka.cast.CastSender =

/** @override */
shaka.cast.CastSender.prototype.destroy = function() {
this.disconnect();
this.rejectAllPromises_();
if (this.session_) {
this.session_.stop(function() {}, function() {});
this.session_ = null;
}

this.onStatusChanged_ = null;
this.onRemoteEvent_ = null;
Expand Down Expand Up @@ -236,18 +240,19 @@ shaka.cast.CastSender.prototype.cast = function(initState) {


/**
* Disconnect from the receiver app. Does nothing if not connected.
* Shows user a cast dialog where they can choose to stop
* casting. Relies on Chrome to perform disconnect if they do.
* Doesn't do anything if not connected.
*/
shaka.cast.CastSender.prototype.disconnect = function() {
shaka.cast.CastSender.prototype.showDisconnectDialog = function() {
if (!this.isCasting_) {
return;
}
var initState = this.onInitStateRequired_();

this.rejectAllPromises_();
if (this.session_) {
this.session_.stop(function() {}, function() {});
this.session_ = null;
}
chrome.cast.requestSession(
this.onSessionInitiated_.bind(this, initState),
this.onConnectionError_.bind(this));
};


Expand Down
8 changes: 4 additions & 4 deletions test/cast/cast_proxy_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ describe('CastProxy', function() {

describe('disconnect', function() {
it('delegates directly to the sender', function() {
expect(mockSender.disconnect).not.toHaveBeenCalled();
proxy.disconnect();
expect(mockSender.disconnect).toHaveBeenCalled();
expect(mockSender.showDisconnectDialog).not.toHaveBeenCalled();
proxy.suggestDisconnect();
expect(mockSender.showDisconnectDialog).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -658,7 +658,7 @@ describe('CastProxy', function() {
receiverName: jasmine.createSpy('receiverName'),
hasRemoteProperties: jasmine.createSpy('hasRemoteProperties'),
setAppData: jasmine.createSpy('setAppData'),
disconnect: jasmine.createSpy('disconnect'),
showDisconnectDialog: jasmine.createSpy('showDisconnectDialog'),
cast: jasmine.createSpy('cast'),
get: jasmine.createSpy('get'),
set: jasmine.createSpy('set'),
Expand Down
25 changes: 2 additions & 23 deletions test/cast/cast_sender_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ describe('CastSender', function() {
expect(sender.isCasting()).toBe(true);
expect(mockSession.stop).not.toHaveBeenCalled();

sender.disconnect();
expect(mockSession.stop).toHaveBeenCalled();
sender.showDisconnectDialog();
expect(mockCastApi.requestSession).toHaveBeenCalled();
fakeRemoteDisconnect();
}).catch(fail).then(done);
fakeSessionConnection();
Expand Down Expand Up @@ -475,27 +475,6 @@ describe('CastSender', function() {
}).catch(fail).then(done);
});

it('reject when disconnected by the user', function(done) {
var p = method(123, 'abc');
shaka.test.Util.capturePromiseStatus(p);

// Wait a tick for the Promise status to be set.
shaka.test.Util.delay(0.1).then(function() {
expect(p.status).toBe('pending');
sender.disconnect();

// Wait a tick for the Promise status to change.
return shaka.test.Util.delay(0.1);
}).then(function() {
expect(p.status).toBe('rejected');
return p.catch(function(error) {
shaka.test.Util.expectToEqualError(error, new shaka.util.Error(
shaka.util.Error.Category.PLAYER,
shaka.util.Error.Code.LOAD_INTERRUPTED));
});
}).catch(fail).then(done);
});

it('reject when disconnected remotely', function(done) {
var p = method(123, 'abc');
shaka.test.Util.capturePromiseStatus(p);
Expand Down

0 comments on commit b335c5a

Please sign in to comment.