Author: ygrego Date: 2015-06-10 09:04:42 +0000 (Wed, 10 Jun 2015) New Revision: 1683 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1683 Log: Refactoring of file ChannelUtils.js in an ES6 class. Modified: oipf/lib/js/impl/RecordingSchedulerObject.js oipf/lib/js/impl/VideoBroadcastObject.js oipf/lib/js/impl/model/Application.js oipf/lib/js/impl/model/Channel.js oipf/lib/js/impl/model/Configuration.js oipf/lib/js/impl/model/LNBInfo.js oipf/lib/js/impl/model/LocalSystem.js oipf/lib/js/impl/model/ModelFactory.js oipf/lib/js/impl/model/Programme.js oipf/lib/js/impl/model/Recording.js oipf/lib/js/impl/model/ScheduledRecording.js oipf/lib/js/impl/model/SearchResults.js oipf/lib/js/impl/model/SignalInfo.js oipf/lib/js/impl/model/Tuner.js oipf/lib/js/utils/ChannelUtils.js Modified: oipf/lib/js/impl/RecordingSchedulerObject.js =================================================================== --- oipf/lib/js/impl/RecordingSchedulerObject.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/RecordingSchedulerObject.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -275,7 +275,7 @@ } _fireEvent(state, recording) { - var event = createCustomEvent("PVREvent", [state, recording]); + var event = this._eventManager.createCustomEvent("PVREvent", [state, recording]); this._eventManager.fireEvent(event, this); } Modified: oipf/lib/js/impl/VideoBroadcastObject.js =================================================================== --- oipf/lib/js/impl/VideoBroadcastObject.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/VideoBroadcastObject.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -370,7 +370,7 @@ break; case this._CONNECTING: - if (!channelUtils.verifyASuitableTunerAvailable(currentChannel.idType)) { + if (!ChannelUtils.verifyASuitableTunerAvailable(currentChannel.idType)) { this._timeout() .then(this.changePlayState.bind(this, this._CONNECTING)); } else { @@ -383,7 +383,7 @@ case this._PRESENTING: /*if (!verifyASuitableTunerAvailable(currentChannel.idType)) { - this.timer = oipf.utils.this._timeout() + this.timer = OipfUtils.this._timeout() .then(this.changePlayState.bind(this, this._PRESENTING)); }*/ //Method documentation indicate it don't have effects in this state. @@ -391,7 +391,7 @@ case this._STOPPED: //FIX-ME :Make enable video and audio presentation - if (!channelUtils.verifyASuitableTunerAvailable(currentChannel.idType, this)) { + if (!ChannelUtils.verifyASuitableTunerAvailable(currentChannel.idType, this)) { this._timeout() .then(this.changePlayState.bind(this, this._STOPPED, 0)); } else { @@ -421,7 +421,7 @@ changePlayState(state, error) { console.log("changeState", state); this.playState = state; - this._fireEvent(createCustomEvent("PlayStateChange", [this.playState, error])); + this._fireEvent(this._eventManager.createCustomEvent("PlayStateChange", [this.playState, error])); } noTransientError(channel) { @@ -442,7 +442,7 @@ if (this.noTransientError(this._CONNECTING) && this.noPermanentError(this._CONNECTING, channel)) { this.playState = this._CONNECTING; - this._fireEvent(createCustomEvent("PlayStateChange", [this.playState])); + this._fireEvent(this._eventManager.createCustomEvent("PlayStateChange", [this.playState])); this._timeout() .then(this.changeStateToPresentingWhenSwitching.bind(this, channel)); } @@ -453,9 +453,9 @@ if (this.noTransientError(this._PRESENTING)) { this.setCurrentChannel(channel); this.playState = this._PRESENTING; - this._fireEvent(createCustomEvent("PlayStateChange", [this.playState])); + this._fireEvent(this._eventManager.createCustomEvent("PlayStateChange", [this.playState])); this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeSucceeded", [channel]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeSucceeded", [channel]))); } } @@ -556,14 +556,14 @@ if (CHANNEL_CREATION[idType]) { //Verify a channel of this idType (ID_DVB_SI_DIRECT = 13). - if (channelUtils.isAValidTerrestrialDsd (dsd)) { //Verify the dsd validity. + if (ChannelUtils.isAValidTerrestrialDsd (dsd)) { //Verify the dsd validity. if ((sid >= 1) && (sid <= 65535)) { //Verify the rigth range of service id. - var newChannel = new Channel(idType, dsd, sid, "localChannel" + createUUID()); + var newChannel = new Channel(idType, dsd, sid, "localChannel" + OipfUtils.createUUID()); var channelConfig = this._channelService; - if (channelUtils.getChannelByDsd(channelConfig.channelList, dsd)) { + if (ChannelUtils.getChannelByDsd(channelConfig.channelList, dsd)) { /* Normally channelList is readonly but the method documentation say * that the channel must be add if it not already present. @@ -639,7 +639,7 @@ if (idType == 30) { var equivalentChannel = this._channelService.channelList.getChannelBySourceID(sourceID); } else if (idType == 40) { - equivalentChannel = channelUtils.getChannelByIpBroadcastID(ipBroadcastID); + equivalentChannel = ChannelUtils.getChannelByIpBroadcastID(ipBroadcastID); } else { equivalentChannel = this._channelService.channelList.getChannelByTriplet(onid, tsid, sid); } @@ -647,7 +647,7 @@ if (equivalentChannel) { var newChannel = new Channel(arguments.push(equivalentChannel.name)); } else { - newChannel = new Channel(arguments.push("localChannel:"+createUUID())); + newChannel = new Channel(arguments.push("localChannel:" + OipfUtils.createUUID())); } this._channelService.channelList.push(newChannel); @@ -678,16 +678,16 @@ if (this.playState >= this._UNREALIZED && this.playState <= this._STOPPED && channel) { - if (channelUtils.verifyASuitableTunerAvailable(channel.idType, this) && channel.idType != 41) { + if (ChannelUtils.verifyASuitableTunerAvailable(channel.idType, this) && channel.idType != 41) { this._timeout() .then(this.changeStateToConnectingWhenSwitching.bind(this, channel)); } else if (channel.idType == 40 || channel.idType == 41) { this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 8]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeError", [null, 8]))); } else { this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 0]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeError", [null, 0]))); } } else { if (this.playState != this._UNREALIZED) { @@ -884,7 +884,7 @@ //Verify that the currentChannel exists in the channel list of channel configuration if (!channelConfig.channelList.getChannel(this.currentChannel.channelId)) { this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 100]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeError", [null, 100]))); /*setTimeout(function () { self.onChannelChangeError && self.onChannelChangeError(null, 100); } 0);*/ @@ -912,18 +912,18 @@ channelCollection = channelConfig.currentFavouriteLists; } - var channelToChange = channelUtils.findChannel(channelCollection, this.currentChannel, step); + var channelToChange = ChannelUtils.findChannel(channelCollection, this.currentChannel, step); - if (channelUtils.verifyASuitableTunerAvailable(channelToChange.idType, this)) { + if (ChannelUtils.verifyASuitableTunerAvailable(channelToChange.idType, this)) { this._timeout() .then(this.changeStateToConnectingWhenSwitching.bind(this, channelToChange)); } else if (channelToChange.idType == 40 || channelToChange.idType == 41) { this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 8]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeError", [null, 8]))); } else { this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 0]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeError", [null, 0]))); } } @@ -931,7 +931,7 @@ } else { //When the OITF does not maintain channel list or favourite list by itself this._timeout() - .then(this._fireEvent.bind(this, createCustomEvent("ChannelChangeError", [null, 10]))); + .then(this._fireEvent.bind(this, this._eventManager.createCustomEvent("ChannelChangeError", [null, 10]))); } } Modified: oipf/lib/js/impl/model/Application.js =================================================================== --- oipf/lib/js/impl/model/Application.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/Application.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -194,7 +194,7 @@ } _fireEvent(eventName) { - var event = createCustomEvent(eventName, null); + var event = this._eventManager.createCustomEvent(eventName, null); this._eventManager.fireEvent(event, this); } } Modified: oipf/lib/js/impl/model/Channel.js =================================================================== --- oipf/lib/js/impl/model/Channel.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/Channel.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -131,7 +131,7 @@ 6: "_createChannelIPTV" }; - (arguments.length !== 6) && this._setCcid(createUUID()); + (arguments.length !== 6) && this._setCcid(OipfUtils.createUUID()); this[dispatcher[arguments.length]].apply(this, arguments); } @@ -173,7 +173,7 @@ } _createChannelFromConf(channelConf) { - oipf.utils.initProperties.call(this, channelConf); + OipfUtils.initProperties.call(this, channelConf); } } Modified: oipf/lib/js/impl/model/Configuration.js =================================================================== --- oipf/lib/js/impl/model/Configuration.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/Configuration.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -123,7 +123,7 @@ */ this.preferredTimeShiftMode = null; - oipf.utils.initProperties.call(this, defaultProperties); + OipfUtils.initProperties.call(this, defaultProperties); this._keys = {}; } Modified: oipf/lib/js/impl/model/LNBInfo.js =================================================================== --- oipf/lib/js/impl/model/LNBInfo.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/LNBInfo.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -89,7 +89,7 @@ */ this.orbitalPosition = null; - oipf.utils.initProperties.call(this, defaultProperties); + OipfUtils.initProperties.call(this, defaultProperties); } } Modified: oipf/lib/js/impl/model/LocalSystem.js =================================================================== --- oipf/lib/js/impl/model/LocalSystem.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/LocalSystem.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -381,7 +381,7 @@ this._timerManager = new TimerManager(); this._timeout = this._timerManager.createTimer; this._defaultProperties = defaultProperties; - oipf.utils.initProperties.call(this, defaultProperties.localSystem); + OipfUtils.initProperties.call(this, defaultProperties.localSystem); this.systemReady = true; } @@ -549,7 +549,7 @@ this.powerState = type; this._timeout() .then(this._fireEvent.bind( - this, createCustomEvent("PowerStateChange", [this.powerState]))); + this, this._eventManager.createCustomEvent("PowerStateChange", [this.powerState]))); return true; } Modified: oipf/lib/js/impl/model/ModelFactory.js =================================================================== --- oipf/lib/js/impl/model/ModelFactory.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/ModelFactory.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -28,7 +28,7 @@ getAProgrammeFromXmlTvData() { console.log("Method createXmlTvData"); - var randomIndex = oipf.utils.getRandomNumberBetweenMinMax(0, + var randomIndex = OipfUtils.getRandomNumberBetweenMinMax(0, this.xmlTvData.programmes.length); if (this.xmlTvData && this.xmlTvData.programmes[randomIndex]) { Modified: oipf/lib/js/impl/model/Programme.js =================================================================== --- oipf/lib/js/impl/model/Programme.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/Programme.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -326,7 +326,7 @@ */ this.recording = null; - oipf.utils.initProperties.call(this, initObject); + OipfUtils.initProperties.call(this, initObject); } /* Modified: oipf/lib/js/impl/model/Recording.js =================================================================== --- oipf/lib/js/impl/model/Recording.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/Recording.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -54,9 +54,9 @@ this.isManual = true; associatedScheduledRecording && - oipf.utils.initProperties.call(this, associatedScheduledRecording); + OipfUtils.initProperties.call(this, associatedScheduledRecording); - this.id = createUUID(); + this.id = OipfUtils.createUUID(); } _setRecordingStartTime(recordingStartTime) { Modified: oipf/lib/js/impl/model/ScheduledRecording.js =================================================================== --- oipf/lib/js/impl/model/ScheduledRecording.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/ScheduledRecording.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -234,7 +234,7 @@ this.customMetadata = null; this.state = this.RECORDING_SCHEDULED; - this.scheduleID = createUUID(); + this.scheduleID = OipfUtils.createUUID(); if (parameters.length == 1) { this._initFromProgramme.apply(this, parameters); } else { Modified: oipf/lib/js/impl/model/SearchResults.js =================================================================== --- oipf/lib/js/impl/model/SearchResults.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/SearchResults.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -193,7 +193,7 @@ var next = true; if (constraints.length > 0 && - oipf.utils.isPresent(constraints, programme.channel.name)) { + OipfUtils.isPresent(constraints, programme.channel.name)) { this._cachedResults.push(programme); next = false; @@ -217,7 +217,7 @@ var programme = programmes[i]; if (constraints.length > 0 && - oipf.utils.isPresent(constraints, programme.channel.name) && + OipfUtils.isPresent(constraints, programme.channel.name) && programme.duration) { var stopTime = programme.startTime + @@ -255,20 +255,20 @@ if (query._and.length > 0 && query._or.length > 0) { - return (oipf.utils[methodName].call(null, programme[field], value) && this._evaluateQueryLoop(query._and, programme)) - || (oipf.utils[methodName].call(null, programme[field], value) + return (OipfUtils[methodName].call(null, programme[field], value) && this._evaluateQueryLoop(query._and, programme)) + || (OipfUtils[methodName].call(null, programme[field], value) || this._evaluateQueryLoop(query._and, programme)); } else if (query._and.length > 0 && query._or.length === 0) { - return (oipf.utils[methodName].call(null, programme[field], value) && this._evaluateQueryLoop(query._and, programme)); + return (OipfUtils[methodName].call(null, programme[field], value) && this._evaluateQueryLoop(query._and, programme)); } else if (query._or.length > 0 && query._and.length === 0) { - return (oipf.utils[methodName].call(null, programme[field], value) && this._evaluateQueryLoop(query._or, programme)); + return (OipfUtils[methodName].call(null, programme[field], value) && this._evaluateQueryLoop(query._or, programme)); } else if (query._and.length === 0 && query._or.length === 0) { - return (oipf.utils[methodName].call(null, programme[field], value)); + return (OipfUtils[methodName].call(null, programme[field], value)); } } Modified: oipf/lib/js/impl/model/SignalInfo.js =================================================================== --- oipf/lib/js/impl/model/SignalInfo.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/SignalInfo.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -8,7 +8,7 @@ class SignalInfo { constructor(defaultProperties) { - oipf.utils.initProperties.call(this, defaultProperties); + OipfUtils.initProperties.call(this, defaultProperties); /* * Description: Modified: oipf/lib/js/impl/model/Tuner.js =================================================================== --- oipf/lib/js/impl/model/Tuner.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/impl/model/Tuner.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -14,7 +14,7 @@ class Tuner { constructor(name, idTypes, defaultProperties) { - oipf.utils.initProperties.call(this, defaultProperties); + OipfUtils.initProperties.call(this, defaultProperties); /* * Description: A unique identifier of the tuner. Modified: oipf/lib/js/utils/ChannelUtils.js =================================================================== --- oipf/lib/js/utils/ChannelUtils.js 2015-06-10 08:54:02 UTC (rev 1682) +++ oipf/lib/js/utils/ChannelUtils.js 2015-06-10 09:04:42 UTC (rev 1683) @@ -1,103 +1,106 @@ -var channelUtils = {}; +class ChannelUtils { -channelUtils.findChannel = function(channelCollection, channel, step) { - for (var i = 0, l = channelCollection.length; i < l; i++ ) { - - if (channelCollection[i] == channel) { - - if ((i == 0) && (step == -1)) { - var index = channelCollection.length + step; - - } else { - - if((i == (channelCollection.length-1)) && (step == 1)) { - index = 0; - + static findChannel(channelCollection, channel, step) { + for (var i = 0, l = channelCollection.length; i < l; i++) { + + if (channelCollection[i] == channel) { + + if ((i == 0) && (step == -1)) { + var index = channelCollection.length + step; + } else { - index = i + step; - + + if ((i == (channelCollection.length-1)) && (step == 1)) { + index = 0; + + } else { + index = i + step; + + } } + return channelCollection[index]; } - return channelCollection[index]; } - } - return null; -}; - -channelUtils.isAValidDVBTChannel = function (channel) { - return (channel.onid) && (channel.tsid) && (channel.sid); -}; - -/* - * Description: - * This method verify that a tuner is available to receive a channel with this "idType". - * And return the first tuner found which match the "idType". - * Actually all video broadcast will use the same tuner because there is only one and - * this choice would be directed by parameter. - * - * ToDo :Normally the method should check if the tuner don't locked by another object but - * no way to do that in the norm. - * - * Argument: - * - idType : the type of tuner researched. - * - * Return: Tuner - */ -channelUtils.verifyASuitableTunerAvailable = function(idType, object) { - var config = oipfObjectFactory.createConfigurationObject(); - var availableTuners = config.localSystem.tuners; - - for (var i = 0; i < availableTuners.length; i++) { - var tunerIdTypes = availableTuners[i].idTypes; - for (var j = 0; j < tunerIdTypes.length; j++) { - var tuner = availableTuners[i]; - if (tunerIdTypes[j] == idType) { - return tuner; + return null; + }; + + static isAValidDVBTChannel(channel) { + return (channel.onid) && (channel.tsid) && (channel.sid); + }; + + /* + * Description: + * This method verify that a tuner is available to receive a channel with this "idType". + * And return the first tuner found which match the "idType". + * Actually all video broadcast will use the same tuner because there is only one and + * this choice would be directed by parameter. + * + * ToDo :Normally the method should check if the tuner don't locked by another object but + * no way to do that in the norm. + * + * Argument: + * - idType : the type of tuner researched. + * + * Return: Tuner + */ + static verifyASuitableTunerAvailable(idType, object) { + var config = oipfObjectFactory.createConfigurationObject(); + var availableTuners = config.localSystem.tuners; + + for (var i = 0; i < availableTuners.length; i++) { + var tunerIdTypes = availableTuners[i].idTypes; + for (var j = 0; j < tunerIdTypes.length; j++) { + var tuner = availableTuners[i]; + if (tunerIdTypes[j] == idType) { + return tuner; + } } } - } - - return null; -}; - -channelUtils.getChannelByDsd = function(channelCollection, dsd) { - for (var i = 0, l = channelCollection.length; i < l; i++) { - if (channelCollection[i].dsd == dsd) { - return channelCollection[i]; + + return null; + }; + + static getChannelByDsd(channelCollection, dsd) { + for (var i = 0, l = channelCollection.length; i < l; i++) { + if (channelCollection[i].dsd == dsd) { + return channelCollection[i]; + } } - } -}; - -/* - * Description: - * This method verify the validity of the terrestrial delivery system descriptor. - * The argument will be compare to the dsd array byte defined either in - * the transport stream or directly in the terminal. - * - * Arguments - * - dsd: the delivery system descriptor string necessary to create a channel by intermediate of method - * createChannelObject. - */ -channelUtils.isAValidTerrestrialDsd = function(dsd) { - var dsdAttributes = dsd.split(","); - - if (TERRESTIAL_DELIVERY_SYSTEM_DESCRIPTOR.length == dsdAttributes.length) { - - for (var i = 0, l = TERRESTIAL_DELIVERY_SYSTEM_DESCRIPTOR.length; i < l; i++) { - - if (!(TERRESTIAL_DELIVERY_SYSTEM_DESCRIPTOR[i] == dsdAttributes[i])) { - return false; + }; + + /* + * Description: + * This method verify the validity of the terrestrial delivery system descriptor. + * The argument will be compare to the dsd array byte defined either in + * the transport stream or directly in the terminal. + * + * Arguments + * - dsd: the delivery system descriptor string necessary to create a channel by intermediate of method + * createChannelObject. + */ + static isAValidTerrestrialDsd(dsd) { + var dsdAttributes = dsd.split(","); + + if (TERRESTIAL_DELIVERY_SYSTEM_DESCRIPTOR.length == dsdAttributes.length) { + + for (var i = 0, l = TERRESTIAL_DELIVERY_SYSTEM_DESCRIPTOR.length; i < l; i++) { + + if (!(TERRESTIAL_DELIVERY_SYSTEM_DESCRIPTOR[i] == dsdAttributes[i])) { + return false; + } } + + return true; } - - return true; - } -}; - -channelUtils.getChannelByIpBroadcastID = function(channelCollection, ipBroadcastID) { - for (var i = 0, l = channelCollection.length; i < l; i++) { - if (channelCollection[i].ipBroadcastID == ipBroadcastID) { - return channelCollection[i]; + }; + + static getChannelByIpBroadcastID(channelCollection, ipBroadcastID) { + for (var i = 0, l = channelCollection.length; i < l; i++) { + if (channelCollection[i].ipBroadcastID == ipBroadcastID) { + return channelCollection[i]; + } } - } -}; + }; + +} +