Author: ygrego Date: 2015-03-26 10:19:58 +0000 (Thu, 26 Mar 2015) New Revision: 970 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/970 Log: -Addition of property "callback". -Addition method "_setCallback", "_getCallback", "noTransientError", "noPermanentError", "changeStateToConnectingWhenSwitching", "changeStateToPresentingWhenSwitching" and "setCurrentChannel". -Definition of getter and setter for method "onPlayStateChange" and "onChannelChangeSucceed". -The method "bindToCurrentChannel" uses now the method "setCurrentChannel". -Complete implementation of method "setChannel", "setVolume" and "getVolume". -The argument "object" of method "_channelSwitch" has been deleted, also in her calls in particular in method "_prevChannel", "_nextChannel". -Refactoring of method "_channelSwitch": -The verification on the state has been separated of verification which verify which entity manages the channel list. -When a channel can be switched the method "changeStateToConnectingWhenSwitching" is called. -All occurrences of "object" changed to "this". Modified: oipf/js/impl/VideoBroadcastObject.js Modified: oipf/js/impl/VideoBroadcastObject.js =================================================================== --- oipf/js/impl/VideoBroadcastObject.js 2015-03-25 14:02:18 UTC (rev 969) +++ oipf/js/impl/VideoBroadcastObject.js 2015-03-26 10:19:58 UTC (rev 970) @@ -146,6 +146,7 @@ console.log("[INFO] constructor of VideoBroadcast class called."); this.playState = 0; this.listeners = {}; + this.callbacks = {}; }, /*! @@ -212,8 +213,14 @@ * * • Number error – if the state has changed due to an error, this field contains an error code detailing the type of error. See the definition of * onChannelChangeError above for valid values. If no error has occurred, this argument SHALL take the value undefined . */ - onPlayStateChange: null, + get onPlayStateChange() { + return this._getCallback("PlayStateChange"); + }, + set onPlayStateChange(callback) { + this._setCallback("PlayStateChange", callback); + }, + /* * Description: * The function that is called when a request to switch a tuner to another channel has successfully completed. @@ -223,8 +230,14 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - onChannelChangeSucceeded: null, + get onChannelChangeSucceeded() { + return this._getCallback("ChannelChangeSucceeded"); + }, + set onChannelChangeSucceeded(callback) { + this._setCallback("ChannelChangeSucceeded", callback); + }, + /* * Description: * The function that is called when the value of fullScreen changes. @@ -249,6 +262,18 @@ }, + _getCallback : function(type) { + if(this.callbacks) { + return this.callbacks[type]; + } + }, + + _setCallback: function(type, callback){ + if(this.callbacks) { + this.callbacks[type] = callback; + } + }, + /* * * Description: @@ -287,18 +312,20 @@ */ bindToCurrentChannel: function() { var channelConfig = this.getChannelConfig(); - var currentChan = channelConfig.currentChannel; + var currentChannel = channelConfig.currentChannel; switch (this.playState) { case this._UNREALIZED: //claimed scarce resources //Call method to claim scarces resources - if (currentChan) { + if (currentChannel) { timeout(0) .then(this.changePlayState.bind(this, this._CONNECTING)) .then(timeout.bind(timeout, 0)) - .then(this.changePlayState.bind(this, this._PRESENTING, null, currentChan)); + .then(this.setCurrentChannel(currentChannel)) + .then(timeout.bind(timeout, 0)) + .then(this.changePlayState.bind(this, this._PRESENTING)); } else { timeout(0) @@ -313,15 +340,54 @@ break; } + return this.currentChannel; }, - changePlayState: function(state, error, channel) { + changePlayState: function(state, error) { this.playState = state; - this.currentChannel = (channel? channel : this.currentChannel); this.fireEvent(createCustomEvent("PlayStateChange", [this.playState, error])); }, + noTransientError: function(channel){ + + /*if (channel.locked) { + return true; + } else { + return false; + }*/ + return true; + }, + + noPermanentError: function(channel){ + return true; + }, + + changeStateToConnectingWhenSwitching: function(channel) { + + if (this.noTransientError(this._CONNECTING) && this.noPermanentError(this._CONNECTING, channel)) { + this.playState = this._CONNECTING; + this.fireEvent(createCustomEvent("PlayStateChange", [this.playState])); + timeout(0) + .then(this.changeStateToPresentingWhenSwitching.bind(this, channel)); + } + }, + + changeStateToPresentingWhenSwitching: function(channel) { + + if (this.noTransientError(this._PRESENTING)) { + this.setCurrentChannel(channel); + this.playState = this._PRESENTING; + this.fireEvent(createCustomEvent("PlayStateChange", [this.playState])); + timeout(0) + .then(this.fireEvent.bind(this, createCustomEvent("ChannelChangeSucceeded", [channel]))); + } + }, + + setCurrentChannel: function(channel) { + this.currentChannel = channel; + }, + /* * Description: * Creates a Channel object of the specified idType . This method is typically used to create a @@ -527,30 +593,30 @@ * onChannelChangeError property, specifying the value 0 (“Channel not supported by * tuner”) for the errorState , and dispatch the corresponding DOM event (see below). * - * + * FiX-ME: Yannis - 25/03/2015 - No take account trickplay + * FiX-ME: Yannis - 25/03/2015 - No verification about Transport Stream + * FiX-ME: Yannis - 25/03/2015 - No verification about possiblity of a local channel argument + * FiX-ME: Yannis - 25/03/2015 - No verification about same tuning + * parameters of argument channel with */ setChannel: function(channel, trickplay, contentAccessDescriptorURL) { - if ((this.playState >= this._CONNECTING) && (this.playState <= this._STOPPED) && (!channel)) { - var tuner = verifyASuitableTunerAvailable(this, channel.idType); - - if (tuner) { - + if (this.playState >= this._CONNECTING && this.playState <= this._STOPPED && channel) { + + if (verifyASuitableTunerAvailable(channel.idType, this) && channel.idType != 41) { + timeout(0) + .then(this.changeStateToConnectingWhenSwitching.bind(this, channel)); + + } else { + timeout(0) + .then(this.fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 100]))); } } else { - var self = this; timeout(0) - .then(this.release.bind(this)) + //.then(this.release.bind(this)) .then(this.changePlayState.bind(this, this._UNREALIZED)); - - /*setTimeout(function () { - self.playState = 0; - self.release(); - self.onPlayStateChange && self.onPlayStateChange(self.playState); - }, 0);*/ - } }, @@ -587,7 +653,7 @@ * */ prevChannel: function() { - this._channelSwitch(this, -1); + this._channelSwitch(-1); }, /* @@ -623,7 +689,7 @@ * */ nextChannel: function() { - this._channelSwitch(this, 1); + this._channelSwitch(1); }, /* @@ -659,28 +725,17 @@ * - volume: Integer value between 0 up to and including 100 to indicate volume level. * * Actually the norm don't talk about the way to obtain the current master volume for the main - * audio output mixer; So we'll base on the system volume. + * audio output mixer; So we'll base on the system volume. + * FIX-ME: Yannis - 24/03/2015 - Bindind with the configuration object. */ setVolume: function(volume) { - if (!Number.isInteger(volume)) { - + if (!Number.isInteger(volume) || volume < 0 || volume > 100 ) { return false; - - } else { - - if (volume == 0) { - //Muted the sound - return true; - } - if ((volume > 0) && (volume < 100)) { - - } - if (volume == 100) { - configurationObject = oipfObjectFactory.createConfigurationObject(); - - } - } + } + + this._volume = volume; + return true; }, /* @@ -690,6 +745,7 @@ * */ getVolume: function() { + return this._volume || 0; }, /* @@ -734,77 +790,66 @@ } }, - _channelSwitch: function(object, step) { + _channelSwitch: function(step) { //claimed scarce resources //Call method to claim scarce resources - var channelConfig = object.getChannelConfig(); + var channelConfig = this.getChannelConfig(); var favouriteLists = channelConfig.favouriteLists; - //Verify that OITF maintain channel list or favourite list by itself - if (channelConfig && favouriteLists && (object.playState > 0) && (object.playState < 4)) { + if ((this.playState > 0) && (this.playState < 4)) { + //Verify that OITF maintain channel list or favourite list by itself + if (channelConfig && favouriteLists) { - //Verify that the currentChannel exists in the channel list of channel configuration - if (!channelConfig.channelList.getChannel(object.currentChannel.channelId)) { - timeout(0) - .then(this.fireEvent.bind(this, createCustomEvent.bind(null, "ChannelChangeError", [null, 100]))); - /*setTimeout(function () { - self.onChannelChangeError && self.onChannelChangeError(null, 100); - }, 0);*/ - - if (object.playState == 1) { + //Verify that the currentChannel exists in the channel list of channel configuration + if (!channelConfig.channelList.getChannel(this.currentChannel.channelId)) { timeout(0) - .then(this.changePlayState.bind(this, this._UNREALIZED, 100)); + .then(this.fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 100]))); /*setTimeout(function () { - self.playState = 0; - self.onPlayStateChange && self.onPlayStateChange(self.playState, 100); + self.onChannelChangeError && self.onChannelChangeError(null, 100); }, 0);*/ - } - } else { - /* - * The norm affirm that the value "undefined" for the property "currentFavouriteList" - * means no current favourite list is activating. - * But test on this value for "currentFavouriteList" can cause confusion - * and when her value equals null, we have not the wanted behaviours. - */ - if (channelConfig.currentFavouriteList.length == 0) { - //Find the previous channel into channel list - var channelCollection = channelConfig.channelList; + + if (this.playState == 1) { + timeout(0) + .then(this.changePlayState.bind(this, this._UNREALIZED, 100)); + /*setTimeout(function () { + self.playState = 0; + self.onPlayStateChange && self.onPlayStateChange(self.playState, 100); + }, 0);*/ + } } else { - //Find the previous channel into the current favourite list - channelCollection = channelConfig.currentFavouriteLists; + /* + * The norm affirm that the value "undefined" for the property "currentFavouriteList" + * means no current favourite list is activating. + * But test on this value for "currentFavouriteList" can cause confusion + * and when her value equals null, we have not the wanted behaviours. + */ + if (channelConfig.currentFavouriteList.length == 0) { + //Find the previous channel into channel list + var channelCollection = channelConfig.channelList; + } else { + //Find the previous channel into the current favourite list + channelCollection = channelConfig.currentFavouriteLists; + } + + var channelToChange = findChannel(channelCollection, this.currentChannel, step); + + if (verifyASuitableTunerAvailable(channelToChange.idType, this)) { + timeout(0) + .then(this.changeStateToConnectingWhenSwitching.bind(this, channelToChange)); + } } + + } else { + //When the OITF does not maintain channel list or favourite list by itself + timeout(0) + .then(this.fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 10]))); - var previousChannel = findChannel(channelCollection, object.currentChannel, step); - - var tunerFound = verifyASuitableTunerAvailable(previousChannel.idType, object); - - if (tunerFound) { - //ToDO: Error handling, if the switch fail, this instruction correspond to channel switch. - object.currentChannel = previousChannel; - timeout(0) - .then(this.changePlayState.bind(this, this._CONNECTING)) - .then(timeout.bind(timeout, 0)) - .then(this.changePlayState.bind(this, this._PRESENTING)) - .then(timeout.bind(timeout, 0)) - .then(this.fireEvent.bind(this, createCustomEvent.bind(null, "ChannelChangeSucceeded", [previousChannel]))); - /* - setTimeout(function () { - self.playState = 1; - self.onPlayStateChange && self.onPlayStateChange(self.playState); - self.onChannelChangeSucceeded && self.onChannelChangeSucceeded(previousChannel); - }, 0);*/ - } } - } else { - //When the OITF does not maintain channel list or favourite list by itself + //When this method is called in play state UNREALIZED timeout(0) - .then(this.fireEvent.bind(this, createCustomEvent.bind(null, "ChannelChangeError", [null, 10]))); - /* - setTimeout(function () { - self.onChannelChangeError && self.onChannelChangeError(null, 10); - }, 0);*/ - } + .then(this.fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 100]))); + } } }); \ No newline at end of file
participants (1)
-
ygrego@users.nuiton.org