Author: ygrego Date: 2015-03-26 15:57:08 +0000 (Thu, 26 Mar 2015) New Revision: 972 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/972 Log: -Addition of property "_timer" and "_channelService". -The method "bindToCurrentChannel" use the property "_timer" in order to control the differents timers launch in the method. Modified: oipf/js/impl/VideoBroadcastObject.js Modified: oipf/js/impl/VideoBroadcastObject.js =================================================================== --- oipf/js/impl/VideoBroadcastObject.js 2015-03-26 15:49:01 UTC (rev 971) +++ oipf/js/impl/VideoBroadcastObject.js 2015-03-26 15:57:08 UTC (rev 972) @@ -142,11 +142,12 @@ console.log("[INFO] createdCallback called."); }, - init: function () { + init: function (channelService) { console.log("[INFO] constructor of VideoBroadcast class called."); this.playState = 0; - this.listeners = {}; - this.callbacks = {}; + this._listeners = {}; + this._callbacks = {}; + this._channelService = channelService; }, /*! @@ -263,14 +264,14 @@ }, _getCallback : function(type) { - if(this.callbacks) { - return this.callbacks[type]; + if(this._callbacks) { + return this._callbacks[type]; } }, _setCallback: function(type, callback){ - if(this.callbacks) { - this.callbacks[type] = callback; + if(this._callbacks) { + this._callbacks[type] = callback; } }, @@ -314,29 +315,57 @@ var channelConfig = this.getChannelConfig(); var currentChannel = channelConfig.currentChannel; + var self = this; + this._timer && this._timer.cancel(); + switch (this.playState) { case this._UNREALIZED: //claimed scarce resources //Call method to claim scarces resources if (currentChannel) { - timeout(0) - .then(this.changePlayState.bind(this, this._CONNECTING)) - .then(timeout.bind(timeout, 0)) - .then(this.setCurrentChannel(currentChannel)) - .then(timeout.bind(timeout, 0)) - .then(this.changePlayState.bind(this, this._PRESENTING)); - + this._timer = oipf.utils.timeout(0) + .then(this.changePlayState.bind(this, this._CONNECTING)) + .then(this.setCurrentChannel.bind(this, currentChannel)) + .then(this.changePlayState.bind(this, this._PRESENTING)); + } else { - timeout(0) - .then(this.changePlayState.bind(this, this._UNREALIZED, 100)); + this._timer = oipf.utils.timeout(0) + .then(this.changePlayState.bind(this, this._UNREALIZED, 100)); } break; - + + case this._CONNECTING: + /*if (!verifyASuitableTunerAvailable(currentChannel.idType)) { + this.timer = oipf.utils.timeout(0) + .then(this.changePlayState.bind(this, this._CONNECTING)); + } else { + this.timer = oipf.utils.timeout(0) + .then(this.setCurrentChannel.bind(this, currentChannel)) + .then(this.changePlayState.bind(this, this._PRESENTING)); + }*/ + //Method documentation indicate it don't have effects in this state. + break; + + case this._PRESENTING: + /*if (!verifyASuitableTunerAvailable(currentChannel.idType)) { + this.timer = oipf.utils.timeout(0) + .then(this.changePlayState.bind(this, this._PRESENTING)); + }*/ + //Method documentation indicate it don't have effects in this state. + break; + case this._STOPPED: //FIX-ME :Make enable video and audio presentation - timeout(0) - .then(this.changePlayState.bind(this, this._CONNECTING)); + if (!verifyASuitableTunerAvailable(currentChannel.idType)) { + this._timer = oipf.utils.timeout(0) + .then(this.changePlayState.bind(this, this._STOPPED, 0)); + } else { + this._timer = oipf.utils.timeout(0) + .then(this.changePlayState.bind(this, this._CONNECTING)) + .then(this.setCurrentChannel.bind(this, currentChannel)) + .then(this.changePlayState.bind(this, this._PRESENTING)); + } break; }