r1784 - in oipf/lib: configuration init js/impl js/impl/model/constants js/utils
Author: ygrego Date: 2015-07-08 16:21:14 +0200 (Wed, 08 Jul 2015) New Revision: 1784 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1784 Log: General refactoring to improve recording object test, correct a bug in emulator about access to channel list. Modified: oipf/lib/configuration/OipfConfiguration.js oipf/lib/init/init.js oipf/lib/js/impl/ChannelConfig.js oipf/lib/js/impl/OipfObjectFactory.js oipf/lib/js/impl/RecordingSchedulerObject.js oipf/lib/js/impl/SearchManagerObject.js oipf/lib/js/impl/VideoBroadcastObject.js oipf/lib/js/impl/model/constants/RecordingSchedulerConstants.js oipf/lib/js/utils/OipfUtils.js Modified: oipf/lib/configuration/OipfConfiguration.js =================================================================== --- oipf/lib/configuration/OipfConfiguration.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/configuration/OipfConfiguration.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -17,7 +17,8 @@ //Programmes configuration this.programmeType = "xmlTV"; this.programmeCountry = "France"; - this.programmes = "./lib/build/xmlTVProgrammes.xml"; +// this.programmes = "./lib/build/xmlTVProgrammes.xml"; + this.programmes = "./lib/build/tnt_lite.xml"; //ApplicationManager this.applicationVisualizationMode = 3; Modified: oipf/lib/init/init.js =================================================================== --- oipf/lib/init/init.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/init/init.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -53,7 +53,7 @@ ]; if (!oipfObjectFactory) { - var oipfObjectFactory = new OipfObjectFactory (); + var oipfObjectFactory = new OipfObjectFactory(); } if (!Date.now) { Modified: oipf/lib/js/impl/ChannelConfig.js =================================================================== --- oipf/lib/js/impl/ChannelConfig.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/impl/ChannelConfig.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -23,7 +23,12 @@ constructor(channelService) { this._callbacks = {}; + this._listeners = {}; this._channelService = channelService; + this._eventManager = new EventManager(); + this._timerManager = new TimerManager(); + + this._timeout = this._timerManager.createTimer.bind(this._timerManager, 0); /* * Description: * The current channel of the OITF if the user has given permission @@ -50,7 +55,7 @@ * * Visibility Type : readonly Channel */ - this.currentChannel = this._channelService.currentChannel; + this.currentChannel = this._channelService && this._channelService.currentChannel || {}; /* * Description: @@ -79,15 +84,16 @@ * * Visibility Type : readonly ChannelList */ - this.channelList = this._channelService.channelList; + this.channelList = this._channelService && this._channelService.channelList || {}; /* Visibility : readonly FavouriteListCollection */ - this.favouriteLists = this._channelService.favouriteLists; + this.favouriteLists = this._channelService && this._channelService.favouriteLists || {}; /* Visibility : readonly FavouriteList */ - this.currentFavouriteList = this._channelService.currentFavouriteList; + this.currentFavouriteList = this._channelService && this._channelService.currentFavouriteList || {}; + } _getCallback(type) { @@ -136,4 +142,20 @@ set onChannelScan(callback) { this._setCallback("ChannelScan", callback); } + + addEventListener(type, listener) { + this._eventManager.addEventListener(type, listener, this); + } + + _fireEvent(event) { + this._eventManager.fireEvent(event, this); + } + + _fireEventChannelListUpdate() { + this._fireEvent(this._eventManager.createCustomEvent("ChannelListUpdate", [])); + } + + removeEventListener(type, listener) { + this._eventManager.removeEventListener(type, listener, this); + } } Modified: oipf/lib/js/impl/OipfObjectFactory.js =================================================================== --- oipf/lib/js/impl/OipfObjectFactory.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/impl/OipfObjectFactory.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -10,7 +10,8 @@ var modelFactory = new ModelFactory(); var dateUtils = new DateUtils(); this._oipfConfiguration = new OipfConfiguration(); - this._channelService = null; + this._channelService = new ChannelService(); + this._setInitPromise(); /*The ChannelConfig class provides the entry point for applications to get information about the list of channels * available. It can be obtained in two ways: @@ -34,7 +35,7 @@ * defined in section 9.3.6. | | * ------------------------------------------------------------------------ */ - this.channelConfig = null; + this.channelConfig = new ChannelConfig(); /* * Description: Access to the functionality of the application/oipfRemoteManagement embedded object SHALL adhere to the @@ -47,7 +48,7 @@ * Description: OITFs SHALL implement the application/oipfSearchManager embedded object. This object provides a * mechanism for applications to create and manage metadata searches. */ - this.searchManagerObject = null; + this.searchManagerObject = new SearchManagerObject(new ProgrammeService()); /* * Description: An OITF SHALL support a non-visual embedded object of type “ application/oipfApplicationManager ”, with @@ -60,10 +61,6 @@ new ApplicationManagerObject( this._oipfConfiguration.applicationVisualizationMode); this.capabilitiesObject = new CapabilitiesObject(modelFactory); - this._createDocument( - this._oipfConfiguration.channelList, "_setChannelConfig"); - this._createDocument( - this._oipfConfiguration.programmes, "_setSearchManagerObject"); //this.codManagerObject = new CodManagerObject(); //this.imsObject = new IMSObecjet(); //this.mdtfObject = new MDTFObject(); @@ -71,7 +68,7 @@ this.parentalControlManagerObject = new ParentalControlManagerObject(); this.configurationObject = new ConfigurationObject(); this.recordingSchedulerObject = new RecordingSchedulerObject( - this.configurationObject.configuration, modelFactory, dateUtils); + this.configurationObject.configuration, modelFactory, dateUtils); //this.downloadManagerObject= new DownloadManagerObject(); //this.downloadTriggerObject= new DownloadTriggerObject(); //this.drmAgentObject= new DrmAgentObject(); @@ -80,24 +77,48 @@ //this.remoteControlFunctionObject = new RemoteControlFunctionObject(); } + _setInitPromise() { + var self = this; + + var channelListUrl = this._oipfConfiguration.channelList; + var programmesUrl = this._oipfConfiguration.programmes; + + this._initPromise = this._createDocument(channelListUrl, "_setChannelConfig") + .then(function() { + return self._createDocument(programmesUrl, "_setSearchManagerObject"); + }); + } + + _getInitPromise() { + return this._initPromise; + } + _createDocument(filename, callbackName) { - var self = this; - if (window.XMLHttpRequest) { - this.xmlHttpRequest = new XMLHttpRequest(); - this.xmlHttpRequest.open("GET", filename); - this.xmlHttpRequest.send(); - this.xmlHttpRequest.onload = function() { - if(this.status == 200 && this.responseXML != null) { - var xmlToJson = new XmlToJson(this.responseXML); - var jsonData = xmlToJson.getJson(); + var self = this; - self[callbackName].call(self, jsonData); - console.log("A new doument has been created."); - } else { - console.log("An error occured during the document creation."); - } - }; - } + var promise = new Promise(function(resolve, reject) { + if (window.XMLHttpRequest) { + var xmlHttpRequest = new XMLHttpRequest(); + xmlHttpRequest.open("GET", filename); + xmlHttpRequest.send(); + xmlHttpRequest.onload = function() { + if (this.status == 200 && this.responseXML != null) { + var xmlToJson = new XmlToJson(this.responseXML); + var jsonData = xmlToJson.getJson(); + + self[callbackName].call(self, jsonData); + console.log("A new doument has been created."); + resolve(); + } else { + console.log("An error occured during the document creation."); + reject(); + } + }; + } + }); + + return promise; + } /* @@ -125,26 +146,26 @@ isObjectSupported(mimeType) { var mimeType_method = { - "channelConfig" : true, - "application/notifsocket" : false, - "application/oipfApplicationManager" : true, - "application/oipfCapabilities" : true, - "application/oipfCodManager" : false, - "application/oipfCommunicationServices" : false, - "application/oipfConfiguration" : true, - "application/oipfDownloadManager" : false, - "application/oipfDownloadTrigger" : false, - "application/oipfDrmAgent" : false, - "application/oipfGatewayInfo" : false, - "application/oipfMDTF" : false, - "application/oipfParentalControlManager" : true, - "application/oipfRecordingScheduler" : true, - "application/oipfRemoteControlFunction" : false, - "application/oipfRemoteManagement" : false, - "application/oipfSearchManager" : true, - "application/oipfStatusView" : false, - "video/broadcast" : true, - "video/mpeg" : false + channelConfig: true, + "application/notifsocket": false, + "application/oipfApplicationManager": true, + "application/oipfCapabilities": true, + "application/oipfCodManager": false, + "application/oipfCommunicationServices": false, + "application/oipfConfiguration": true, + "application/oipfDownloadManager": false, + "application/oipfDownloadTrigger": false, + "application/oipfDrmAgent": false, + "application/oipfGatewayInfo": false, + "application/oipfMDTF": false, + "application/oipfParentalControlManager": true, + "application/oipfRecordingScheduler": true, + "application/oipfRemoteControlFunction": false, + "application/oipfRemoteManagement": false, + "application/oipfSearchManager": true, + "application/oipfStatusView": false, + "video/broadcast": true, + "video/mpeg": false }; return mimeType_method[mimeType]; @@ -644,6 +665,7 @@ this._channelServicePromise.resolve(this._channelService); this.channelConfig = new ChannelConfig(this._channelService); + this.channelConfig._fireEventChannelListUpdate(); } _setSearchManagerObject(programmesJson) { @@ -652,9 +674,17 @@ var oipfProgrammes = new ProgrammeHelper(this._channelService, somesChannelInfo) .initProgrammes(programmesJson.tv.programme); - var programmeService = new ProgrammeService(oipfProgrammes); + this._programmeService = new ProgrammeService(oipfProgrammes); - this.searchManagerObject = new SearchManagerObject(programmeService); + this.searchManagerObject._setProgrammeService(this._programmeService); + this.searchManagerObject._setMetadata(this._programmeService); + + var self = this; + + this.searchManagerObject._initPromise = this._initPromise + .then(function() { + self.searchManagerObject._programmeService = self._programmeService; + }); } _getChannelServicePromise() { Modified: oipf/lib/js/impl/RecordingSchedulerObject.js =================================================================== --- oipf/lib/js/impl/RecordingSchedulerObject.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/impl/RecordingSchedulerObject.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -241,10 +241,7 @@ } } else if (recording.state == this.SCHEDULED) { - startTime && recording._setStartTime(startTime); - duration && recording._setDuration(duration); - repeatDays && (recording.repeatDays = repeatDays); - + this._updateFields(id, startTime, duration, repeatDays); } return false; @@ -258,14 +255,14 @@ this._setCallback("PVREvent", callback); } - _getCallback (type) { - if(this._callbacks) { + _getCallback(type) { + if (this._callbacks) { return this._callbacks[type]; } } _setCallback(type, callback) { - if(this._callbacks) { + if (this._callbacks) { this._callbacks[type] = callback; } } @@ -351,7 +348,7 @@ * Yannis - 29/04/2015 - Modify recordingStartTime of concerned recording. */ _planifyStartRecording(recording) { - if(this._isProgrammeStarted(recording)) { + if (this._isProgrammeStarted(recording)) { var timer = this._dispatchBeforeStartedEventAndStartedEvent(null, recording); console.log("The recording start now because the programme already had started."); @@ -385,7 +382,7 @@ * Yannis - 29/04/2015 - Modify recordingEndTime of concerned recording. */ _planifyEndRecording(recording) { - var timeToEnd = this._getDurationFromNowToSpecificTime(recording.startTime + + var timeToEnd = this._getDurationFromNowToSpecificTime(recording.startTime + recording.duration + recording.endPadding); var timer = this._timeoutRecording(this._dateUtils.secondsToMilliseconds(timeToEnd)) @@ -408,7 +405,7 @@ var currentTime = this._dateUtils.nowInSeconds(); - return (currentTime >= startTime && currentTime <= endTime); + return currentTime >= startTime; } /* @@ -422,8 +419,8 @@ var endTime = startTime + recording.duration; var currentTime = this._dateUtils.nowInSeconds(); - - return (endTime <= currentTime); + console.log(currentTime); + return endTime <= currentTime; } _getDurationFromNowToSpecificTime(time) { @@ -438,7 +435,8 @@ return false; } - var newStopTime = recording.startTime + duration + recording.endPadding; +// var newStopTime = recording.startTime + duration + recording.endPadding; + var newStopTime = this._dateUtils.nowInSeconds() + duration + recording.endPadding; if (newStopTime <= this._dateUtils.nowInSeconds()) { return false; @@ -445,7 +443,7 @@ } var recordings = this.recordings.filter(function(recording) { - return recording.id != id; + return recording.id != id; }); @@ -503,7 +501,7 @@ } var recordings = this.recordings.filter(function(recording) { - return recording.id != id; + return recording.id != id; }); for (var i = 0, l = recordings.length; i < l; i++) { Modified: oipf/lib/js/impl/SearchManagerObject.js =================================================================== --- oipf/lib/js/impl/SearchManagerObject.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/impl/SearchManagerObject.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -5,13 +5,25 @@ class SearchManagerObject { constructor(programmeService) { - this._programmeService = programmeService; + this._setProgrammeService(programmeService); this._listeners = {}; this._callbacks = {}; this._eventManager = new EventManager(); - this._metadata = this._programmeService.programmes; + this._setMetadata(this._programmeService); } + _setProgrammeService(programmeService) { + if (programmeService) { + this._programmeService = programmeService; + } + } + + _setMetadata(programmeService) { + if (programmeService.programmes) { + this._metadata = this._programmeService.programmes; + } + } + /* * Description: * This function is the DOM 0 event handler for events indicating changes in metadata. This SHALL be raised Modified: oipf/lib/js/impl/VideoBroadcastObject.js =================================================================== --- oipf/lib/js/impl/VideoBroadcastObject.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/impl/VideoBroadcastObject.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -148,7 +148,13 @@ this.playState = 0; this._listeners = {}; this._callbacks = {}; - this._channelService = oipfObjectFactory._channelService; + + this._channelServicePromise = oipfObjectFactory._getChannelServicePromise(); + this._channelServicePromise.promise.then(this._setChannelService.bind(this)); + this._setChannelService(); + + this._localSystem = oipfObjectFactory.createConfigurationObject().localSystem; + this._eventManager = new EventManager(); this._timerManager = new TimerManager(); @@ -160,7 +166,11 @@ this.init(); } + _setChannelService() { + this._channelService = oipfObjectFactory._channelService; + } + /*! * Description: * The function that is called when a request to switch a tuner to another channel resulted in an error preventing @@ -810,7 +820,8 @@ return false; } - this._volume = volume; + this._localSystem.volume = volume; + return true; } @@ -821,7 +832,7 @@ * */ getVolume() { - return this._volume || 0; + return this._localSystem && this._localSystem.volume || 0; } /* Modified: oipf/lib/js/impl/model/constants/RecordingSchedulerConstants.js =================================================================== --- oipf/lib/js/impl/model/constants/RecordingSchedulerConstants.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/impl/model/constants/RecordingSchedulerConstants.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -1,4 +1,4 @@ -/* +/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. @@ -5,7 +5,7 @@ */ var recordingConstants = { - state : {} + state: {} }; recordingConstants.state.STARTED = 1; Modified: oipf/lib/js/utils/OipfUtils.js =================================================================== --- oipf/lib/js/utils/OipfUtils.js 2015-07-08 14:07:41 UTC (rev 1783) +++ oipf/lib/js/utils/OipfUtils.js 2015-07-08 14:21:14 UTC (rev 1784) @@ -35,8 +35,18 @@ return field1 <= field2; } + /* + * Description: + * Use for search of metadata, this method verify, if field1 is contained in field2. + * + * Arguments: + * -field1: The String object which must be found into String object field2. + * -field2: The String object which should contains the String object field1. + * + * Return: Boolean + */ static contains(field1, field2) { - return field1 == field2; + return field2.includes(field1); } static generateFourDigit() {
participants (1)
-
ygrego@users.nuiton.org