diff --git a/demo/controls.js b/demo/controls.js index 32c8c0a851..cb1e465312 100644 --- a/demo/controls.js +++ b/demo/controls.js @@ -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() { diff --git a/lib/cast/cast_proxy.js b/lib/cast/cast_proxy.js index 1b5e362beb..d7bc44f3af 100644 --- a/lib/cast/cast_proxy.js +++ b/lib/cast/cast_proxy.js @@ -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(); }; diff --git a/lib/cast/cast_sender.js b/lib/cast/cast_sender.js index 0f7af7c918..3c69f6cc39 100644 --- a/lib/cast/cast_sender.js +++ b/lib/cast/cast_sender.js @@ -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; @@ -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)); }; diff --git a/test/cast/cast_proxy_unit.js b/test/cast/cast_proxy_unit.js index fd515c5590..7744b049fb 100644 --- a/test/cast/cast_proxy_unit.js +++ b/test/cast/cast_proxy_unit.js @@ -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(); }); }); @@ -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'), diff --git a/test/cast/cast_sender_unit.js b/test/cast/cast_sender_unit.js index a00e934973..979481093b 100644 --- a/test/cast/cast_sender_unit.js +++ b/test/cast/cast_sender_unit.js @@ -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(); @@ -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);