Author: ygrego Date: 2015-03-19 13:34:16 +0000 (Thu, 19 Mar 2015) New Revision: 960 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/960 Log: Replacement of method "setTimeout" by "timeout" in all followings methods : "bindToCurrentChannel", "stop", "release", "_channelSwitch" and all content of "setTimeout" have been moved into new method "changePlayState". Modified: oipf/js/impl/VideoBroadcastObject.js Modified: oipf/js/impl/VideoBroadcastObject.js =================================================================== --- oipf/js/impl/VideoBroadcastObject.js 2015-03-19 13:23:03 UTC (rev 959) +++ oipf/js/impl/VideoBroadcastObject.js 2015-03-19 13:34:16 UTC (rev 960) @@ -27,6 +27,14 @@ */ var VideoBroadcastObject = Class.extend({ + _UNREALIZED: 0, + + _CONNECTING: 1, + + _PRESENTING: 2, + + _STOPPED: 3, + /* * Description: * The width of the area used for rendering the video object. This property is only writable if property @@ -35,13 +43,7 @@ * the DOM Level 2 Style interfaces (i.e. CSS2Properties interface style.width ), at least for values * specified in pixels. */ - get width () { - return null; - }, - - set width (val) { - - }, + width: null, /* * Description: * The height of the area used for rendering the video object. This property is only writable if property @@ -140,19 +142,10 @@ console.log("[INFO] createdCallback called."); }, - init: function (requiredCapabilities) { + init: function () { console.log("[INFO] constructor of VideoBroadcast class called."); this.playState = 0; - if (requiredCapabilities) { - this.allocationMethod = STATIC_ALLOCATION_VIDEOBROADCAST; - /* TODO: get scarce resources Scarce resources can be claimed by the video/broadcast or A/V Control object at instantiation time by specifying the - * requiredCapabilities parameter. In this case the STATIC_ALLOCATION method is used and the scarce resources - * are held by the object until it is either destroyed or the release() method is called. - */ - } else { - - this.allocationMethod = DYNAMIC_ALLOCATION_VIDEOBROADCAST; - } + this.listeners = {}; }, /*! @@ -295,41 +288,39 @@ bindToCurrentChannel: function() { var channelConfig = this.getChannelConfig(); var currentChan = channelConfig.currentChannel; - var self = this; + switch (this.playState) { - case 0: + case this._UNREALIZED: //claimed scarce resources //Call method to claim scarces resources - if (currentChan) { - this.currentChannel = currentChan; - - setTimeout(function () { - self.playState = 2; - self.onPlayStateChange && self.onPlayStateChange(self.playState); - }, 0); - + timeout(0) + .then(this.changePlayState.bind(this, this._CONNECTING)) + .then(timeout.bind(timeout, 0)) + .then(this.changePlayState.bind(this, this._PRESENTING, null, currentChan)); + } else { - - setTimeout(function () { - self.playState = 0; - self.onPlayStateChange && self.onPlayStateChange(self.playState, 100); - }, 0); + timeout(0) + .then(this.changePlayState.bind(this, this._UNREALIZED, 100)); } break; - case 3: - setTimeout(function () { - //Make enable video and audio presentation - self.playState = 1; - self.onPlayStateChange && self.onPlayStateChange(self.playState); - }, 0); + case this._STOPPED: + //FIX-ME :Make enable video and audio presentation + timeout(0) + .then(this.changePlayState.bind(this, this._CONNECTING)); break; } return this.currentChannel; }, + + changePlayState: function(state, error, channel) { + this.playState = state; + this.currentChannel = (channel? channel : this.currentChannel); + this.fireEvent(createCustomEvent("PlayStateChange", [this.playState, error])); + }, /* * Description: @@ -540,7 +531,7 @@ */ setChannel: function(channel, trickplay, contentAccessDescriptorURL) { - if ((this.playState >= 1) && (this.playState <= 3) && (!channel)) { + if ((this.playState >= this._CONNECTING) && (this.playState <= this._STOPPED) && (!channel)) { var tuner = verifyASuitableTunerAvailable(this, channel.idType); if (tuner) { @@ -550,11 +541,15 @@ } else { var self = this; - setTimeout(function () { + timeout(0) + .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); + }, 0);*/ } }, @@ -706,23 +701,15 @@ * the releasing of resources shall change this to DYNAMIC_ALLOCATION . */ release: function() { - if ((this.playState >= 1) && (this.playState <= 3)) { + if ((this.playState >= this._CONNECTING) && (this.playState <= this._STOPPED)) { /* Call method to : * - release tuner used by this video/broadcast object. * - stop visualization of the video. * - and scarce ressources loaded previously. */ - var self = this; - console.log("Hey Hey"); - setTimeout(function () { - self.playState = 0; - self.currentChannel = null; - self.allocationMethod = (self.allocationMethod == STATIC_ALLOCATION_VIDEOBROADCAST) ? DYNAMIC_ALLOCATION_VIDEOBROADCAST : self.allocationMethod; - self.onPlayStateChange && self.onPlayStateChange(self.playState); - }, 0); + timeout(0) + .then(this.changePlayState.bind(this, this._UNREALIZED)); - this.playState = 0; - } }, @@ -737,18 +724,13 @@ * */ stop: function() { - if ((this.playState >= 1) && (this.playState <= 2)) { + if ((this.playState == this._CONNECTING) || (this.playState == this._PRESENTING)) { /* Call method to : * - stop the presentation of the video and audio. * - and scarce ressources loaded previously. */ - this.release(); - var self = this; - console.log("Hey"); - setTimeout(function () { - self.playState = 3; - self.onPlayStateChange && self.onPlayStateChange(self.playState); - }, 0); + timeout(0) + .then(this.changePlayState.bind(this, this._STOPPED)); } }, @@ -764,17 +746,19 @@ //Verify that the currentChannel exists in the channel list of channel configuration if (!channelConfig.channelList.getChannel(object.currentChannel.channelId)) { - var self = object; - setTimeout(function () { + timeout(0) + .then(this.fireEvent.bind(this, createCustomEvent.bind(null, "ChannelChangeError", [null, 100]))); + /*setTimeout(function () { self.onChannelChangeError && self.onChannelChangeError(null, 100); - }, 0); + }, 0);*/ if (object.playState == 1) { - self = object; - setTimeout(function () { + timeout(0) + .then(this.changePlayState.bind(this, this._UNREALIZED, 100)); + /*setTimeout(function () { self.playState = 0; self.onPlayStateChange && self.onPlayStateChange(self.playState, 100); - }, 0); + }, 0);*/ } } else { /* @@ -798,23 +782,29 @@ if (tunerFound) { //ToDO: Error handling, if the switch fail, this instruction correspond to channel switch. object.currentChannel = previousChannel; - self = object; + 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); + }, 0);*/ } } } else { //When the OITF does not maintain channel list or favourite list by itself - self = object; + timeout(0) + .then(this.fireEvent.bind(this, createCustomEvent.bind(null, "ChannelChangeError", [null, 10]))); + /* setTimeout(function () { self.onChannelChangeError && self.onChannelChangeError(null, 10); - }, 0); + }, 0);*/ } } - - }); \ No newline at end of file
participants (1)
-
ygregoï¼ users.nuiton.org