video-service.js
5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
/* globals Promise */
define('screens/player/runtime/impl/video-service', [
'underscore',
'jquery',
'screens/player/runtime/admin',
'screens/player/shared/serviceadmin',
'screens/player/store/store',
'screens/player/firmware/preferences/preferences',
'module'
], function(_, $, Admin, ServiceAdmin, Store, Preferences, mod) {
'use strict';
/**
* Implements the video service
*
* @class VideoService
*/
var VideoService = {
serviceId: mod.id,
/**
* @memberof VideoService
*/
serviceName: 'com.adobe.aem.screens.videoservice',
/**
* Window IO to post messages across iFrames
* @memberof VideoService
*/
wio: null,
/**
* Activate method.
* @returns {*|Promise} Optional a promise that resolves (or rejects) when completed.
*/
activate: function() {
return Promise.resolve();
},
/**
* Deactivate method.
*/
deactivate: function() {
// theoretically, we should unregister the handler. but the service admin doesn't support it yet.
this.wio = null;
},
isNativeVideoAvailable: function() {
return !!((window.plugins) && (window.plugins.ScreensVideoPlayer));
},
/**
* Initialize messaging across iFrames.
* @param {WindowIO} wio - Messaging across iFrames
*/
initMessaging: function(wio) {
if (!this.wio) {
this.wio = wio;
this.wio.on('check-native-video', this.checkNativeVideo.bind(this));
this.wio.on('native-video-play', this.playVideo.bind(this));
}
},
/**
* Check whether native playback is enabled.
* @returns {boolean} true if Native video is enabled, false otherwise
*/
checkNativeVideo: function() {
var preferencesService = ServiceAdmin.getService(Preferences.serviceName);
var config = preferencesService.getPreferences();
// Check capability and also admin UI preference
if ((window.plugins) && (window.plugins.ScreensVideoPlayer) && (this.wio) && (config.enableNativeVideo)) {
console.log('Native Video is available and enabled in preferences.');
this.wio.postMessage('native-video-enabled');
return true;
}
console.log('Native video not available.');
return false;
},
/**
* Plays the given video
* @param {Object} video - The video to play with information from the HTML5 element
*/
playVideo: function(video) {
console.log('native-video-play');
var store = ServiceAdmin.getService(Store.serviceName);
var adminUIVisible = store.getState()[Admin.NAMESPACE].visible;
var osdUIVisible = store.getState().osd.visible;
if ((window.plugins) && (window.plugins.ScreensVideoPlayer) && (adminUIVisible !== 'show') && (osdUIVisible !== 'show')) {
var options = {
successCallback: this.handleVideoCompleted.bind(this),
errorCallback: this.handleVideoInterrupted.bind(this),
id: video.id
};
console.log('Playing ' + video.URL);
window.plugins.ScreensVideoPlayer.playVideo(video.URL, options);
}
else {
video.message = 'video-close-event';
this.wio.postMessage('no-native-video', video);
}
},
handleVideoCompleted: function(response) {
console.log('Video ended');
if (this.wio) {
this.wio.postMessage('video-ended', response);
}
else {
console.log('Messaging not initialized');
}
},
handleVideoInterrupted: function(response) {
console.log('Video interrupted');
if (this.wio) {
this.wio.postMessage('no-native-video', response);
}
else {
console.log('Messaging not initialized');
}
}
};
return VideoService;
});
require([
'screens/player/runtime/impl/video-service',
'screens/player/shared/serviceadmin'
], function(Service, ServiceAdmin) {
'use strict';
ServiceAdmin.register(Service);
});