diff --git a/src/App/App.js b/src/App/App.js index 8d1e4d187..53459cbd5 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -40,14 +40,11 @@ const App = () => { }; const onChromecastStateChange = () => { if (services.chromecast.active) { - services.chromecast.transport.dispatch({ - type: 'setOptions', - options: { - receiverApplicationId: CONSTANTS.CHROMECAST_RECEIVER_APP_ID, - autoJoinPolicy: chrome.cast.AutoJoinPolicy.PAGE_SCOPED, - resumeSavedSession: false, - language: null - } + services.chromecast.transport.setOptions({ + receiverApplicationId: CONSTANTS.CHROMECAST_RECEIVER_APP_ID, + autoJoinPolicy: chrome.cast.AutoJoinPolicy.PAGE_SCOPED, + resumeSavedSession: false, + language: null }); } }; diff --git a/src/services/Chromecast/ChromecastTransport.js b/src/services/Chromecast/ChromecastTransport.js index a92536fb4..83e97e648 100644 --- a/src/services/Chromecast/ChromecastTransport.js +++ b/src/services/Chromecast/ChromecastTransport.js @@ -193,55 +193,40 @@ function ChromecastTransport() { return null; }; - this.dispatch = function(action) { - if (action) { - switch (action.type) { - case 'setOptions': { - try { - cast.framework.CastContext.getInstance().setOptions(action.options); - } catch (error) { - events.emit('error', { - ...CAST_ERROR.INVALID_OPTIONS, - error - }); - } - - return; - } - case 'requestSession': { - try { - cast.framework.CastContext.getInstance().requestSession() - .catch((code) => { - onCastError(code); - }); - } catch (error) { - events.emit('error', { - ...CAST_ERROR.INVALID_OPTIONS, - error - }); - } - - return; - } - case 'endCurrentSession': { - cast.framework.CastContext.getInstance().endCurrentSession(action.stopCasting); - return; - } - case 'sendMessage': { - const castSession = cast.framework.CastContext.getInstance().getCurrentSession(); - if (castSession !== null) { - castSession.sendMessage(MESSAGE_NAMESPACE, JSON.stringify(action.data)) - .catch((code) => { - onCastError(code); - }); - } - - return; - } - } + this.setOptions = function(options) { + try { + cast.framework.CastContext.getInstance().setOptions(options); + } catch (error) { + events.emit('error', { + ...CAST_ERROR.INVALID_OPTIONS, + error + }); + } + }; + this.requestSession = function() { + try { + cast.framework.CastContext.getInstance().requestSession() + .catch((code) => { + onCastError(code); + }); + } catch (error) { + events.emit('error', { + ...CAST_ERROR.INVALID_OPTIONS, + error + }); + } + }; + this.endCurrentSession = function(stopCasting) { + cast.framework.CastContext.getInstance().endCurrentSession(stopCasting); + }; + this.sendMessage = function(data) { + const castSession = cast.framework.CastContext.getInstance().getCurrentSession(); + if (castSession !== null) { + castSession.sendMessage(MESSAGE_NAMESPACE, JSON.stringify(data)) + .catch((code) => { + onCastError(code); + }); } - - throw new Error('Invalid action dispatched: ' + JSON.stringify(action)); }; }