Author: ygrego Date: 2015-07-07 10:17:27 +0000 (Tue, 07 Jul 2015) New Revision: 1770 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1770 Log: Don't mix the services. Added: oipf/emulator/js/services/ChannelConfigService.js oipf/emulator/js/services/ConfigurationService.js oipf/emulator/js/services/SearchManagerService.js oipf/emulator/js/services/VideoBroadcastService.js Added: oipf/emulator/js/services/ChannelConfigService.js =================================================================== --- oipf/emulator/js/services/ChannelConfigService.js (rev 0) +++ oipf/emulator/js/services/ChannelConfigService.js 2015-07-07 10:17:27 UTC (rev 1770) @@ -0,0 +1,4 @@ + +OIPFServices.factory("ChannelConfigService", function() { + return oipfObjectFactory.createChannelConfig.call(oipfObjectFactory); +}); Added: oipf/emulator/js/services/ConfigurationService.js =================================================================== --- oipf/emulator/js/services/ConfigurationService.js (rev 0) +++ oipf/emulator/js/services/ConfigurationService.js 2015-07-07 10:17:27 UTC (rev 1770) @@ -0,0 +1,15 @@ +OIPFServices.factory("ConfigurationService", function() { + var configurationService = new Service(); + + configurationService.configurationObject = oipfObjectFactory.createConfigurationObject.call(oipfObjectFactory); + + configurationService.getPowerState = function() { + return this.configurationObject.localSystem.powerState; + }; + + configurationService.setPowerState = function(powerState) { + return this.configurationObject.localSystem.setPowerState(powerState); + }; + + return configurationService; +}); Added: oipf/emulator/js/services/SearchManagerService.js =================================================================== --- oipf/emulator/js/services/SearchManagerService.js (rev 0) +++ oipf/emulator/js/services/SearchManagerService.js 2015-07-07 10:17:27 UTC (rev 1770) @@ -0,0 +1,61 @@ +OIPFServices.factory("SearchManagerService", ["$q", function(promise) { + + var searchManagerService = new Service(); + + var searchManagerObject = oipfObjectFactory.createSearchManagerObject(); + + searchManagerObject.onMetadataSearch = function(resolve, reject, search, state) { + + console.log("[INFO]: onMetadataSearch called"); + + switch (state) { + + case 0: + if (search.result.length == 1) { + console.log("[TEST-RUNNING][Info] Label: Obtain current program according to oipf norm, State: found"); + resolve(); + } else { + console.log("[TEST-RUNNING][Info] Label: Obtain current program according to oipf norm, State: not found"); + reject(); + } + break; + + case 3: + var message = "[INFO] MetadataSearch in Idle state because of either search abort or parameters have been modified (query, constraints or search target)"; + console.log(message); + reject(); + break; + + case 4: + message = "[INFO] The search cannot be complete because of lack of ressources or any other reason."; + console.log(message); + reject(); + break; + + default: + console.log("Unknow state"); + reject(); + } + }; + + var deferred = promise.defer(); + + searchManagerObject.onMetadataSearch = searchManagerObject.onMetadataSearch + .bind(searchManagerObject, deferred.resolve, deferred.reject); + + searchManagerObject["_findCurrentProgramme"] = function(channel) { + var searchTarget = 1; + var metaDataSearch = this.createSearch(searchTarget); + var startTime = null; + metaDataSearch.findProgrammesFromStream(channel, startTime); + var offset = 0; + var count = 1; + metaDataSearch.result.getResults(offset, count); + + return deferred.promise; + }; + + searchManagerService.searchManagerObject = searchManagerObject; + + return searchManagerService; +}]); Added: oipf/emulator/js/services/VideoBroadcastService.js =================================================================== --- oipf/emulator/js/services/VideoBroadcastService.js (rev 0) +++ oipf/emulator/js/services/VideoBroadcastService.js 2015-07-07 10:17:27 UTC (rev 1770) @@ -0,0 +1,132 @@ +OIPFServices.factory("VideoBroadcastService", ["$q", function(promise) { + + var videoBroadcastService = new Service(); + var videoBroadcastObject = document.getElementById("videoBroadcast"); + + if (videoBroadcastObject) { + + videoBroadcastService.videoBroadcastObject = videoBroadcastObject; + + } else { + + console.log("There is no video-broadcast object present in DOM!!!!"); + + } + + videoBroadcastService.promiseManager = promise; + + videoBroadcastService.getCurrentChannel = function() { + return this.videoBroadcastObject.currentChannel; + }; + + videoBroadcastService.getCurrentChannelLogoUrl = function() { + return this.getCurrentChannel().logoUrl; + }; + + videoBroadcastService.bindToCurrentChannel = function() { + + var deferred = this.promiseManager.defer(); + this.previousState = this.videoBroadcastObject.playState; + this.currentIndex = 0; + + this.videoBroadcastObject.onPlayStateChange = + this.onChangeState.bind(this, deferred.resolve, deferred.reject); + + this.addTransition(videoBroadcastConstants.state.UNREALIZED, + videoBroadcastConstants.state.CONNECTING); + + this.addTransition(videoBroadcastConstants.state.CONNECTING, + videoBroadcastConstants.state.PRESENTING, + deferred.resolve); + + this.videoBroadcastObject.bindToCurrentChannel(); + + return deferred.promise; + }; + + videoBroadcastService.release = function() { + + var deferred = this.promiseManager.defer(); + + if (this.videoBroadcastObject.playState) { + this.currentIndex = 0; + this.previousState = this.videoBroadcastObject.playState; + + this.videoBroadcastObject.onPlayStateChange = + this.onChangeState.bind(this, deferred.resolve, deferred.reject); + + this.addTransition(this.previousState, + videoBroadcastConstants.state.UNREALIZED, + deferred.resolve); + + this.videoBroadcastObject.release && this.videoBroadcastObject.release(); + } + + + return deferred.promise; + }; + + videoBroadcastService.prevChannel = function() { + + var deferred = this.promiseManager.defer(); + this.currentIndex = 0; + + this.previousState = this.videoBroadcastObject.playState; + + this.addTransition(this.previousState, + videoBroadcastConstants.state.CONNECTING); + + this.addTransition(videoBroadcastConstants.state.CONNECTING, + videoBroadcastConstants.state.PRESENTING); + + this.videoBroadcastObject.onChannelChangeSucceeded = function(channel) { + deferred.resolve(); + }; + + this.videoBroadcastObject.prevChannel && this.videoBroadcastObject.prevChannel(); + + return deferred.promise; + } + + videoBroadcastService.nextChannel = function() { + + var deferred = this.promiseManager.defer(); + this.currentIndex = 0; + + this.previousState = this.videoBroadcastObject.playState; + + this.addTransition(this.previousState, + videoBroadcastConstants.state.CONNECTING); + + this.addTransition(videoBroadcastConstants.state.CONNECTING, + videoBroadcastConstants.state.PRESENTING); + + this.videoBroadcastObject.onChannelChangeSucceeded = function(channel) { + deferred.resolve(); + }; + + this.videoBroadcastObject.nextChannel && this.videoBroadcastObject.nextChannel(); + + return deferred.promise; + } + + videoBroadcastService.setVolume = function(buttonId) { + + if (buttonId == "V+") { + var volume = this.videoBroadcastObject.getVolume(); + var result = this.videoBroadcastObject.setVolume(volume+1); + } else if (buttonId == "V-") { + var volume = this.videoBroadcastObject.getVolume(); + result = this.videoBroadcastObject.setVolume(volume-1); + } + + return result; + } + + videoBroadcastService.getVolume = function() { + this.videoBroadcastObject.getVolume && console.log(this.videoBroadcastObject.getVolume()); + return this.videoBroadcastObject.getVolume && this.videoBroadcastObject.getVolume() || 50; + } + + return videoBroadcastService; +}]);