@stremio/stremio-video 0.0.17-rc.6 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -71,10 +71,11 @@ function ChromecastSenderVideo(options) {
|
|
|
71
71
|
extraSubtitlesOutlineColor: false
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
function onTransportError(error,
|
|
74
|
+
function onTransportError(error, action) {
|
|
75
75
|
events.emit('error', Object.assign({}, ERROR.CHROMECAST_SENDER_VIDEO.MESSAGE_SEND_FAILED, {
|
|
76
76
|
error: error,
|
|
77
|
-
|
|
77
|
+
action: action,
|
|
78
|
+
message: 'Chromecast transport error'
|
|
78
79
|
}));
|
|
79
80
|
}
|
|
80
81
|
function onMessage(message) {
|
|
@@ -17,24 +17,39 @@ function IFrameVideo(options) {
|
|
|
17
17
|
iframeElement.style.border = 0;
|
|
18
18
|
iframeElement.style.backgroundColor = 'black';
|
|
19
19
|
iframeElement.allowFullscreen = false;
|
|
20
|
+
iframeElement.allow = 'autoplay';
|
|
20
21
|
containerElement.appendChild(iframeElement);
|
|
21
22
|
|
|
22
23
|
var events = new EventEmitter();
|
|
23
24
|
var destroyed = false;
|
|
24
|
-
var stream = null;
|
|
25
25
|
var observedProps = {
|
|
26
|
-
stream: false
|
|
26
|
+
stream: false,
|
|
27
|
+
paused: false,
|
|
28
|
+
time: false,
|
|
29
|
+
duration: false,
|
|
30
|
+
buffering: false,
|
|
31
|
+
buffered: false,
|
|
32
|
+
volume: false,
|
|
33
|
+
muted: false,
|
|
34
|
+
playbackSpeed: false
|
|
27
35
|
};
|
|
28
36
|
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return stream;
|
|
33
|
-
}
|
|
34
|
-
default: {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
+
function onMessage(event) {
|
|
38
|
+
if (event.source !== iframeElement.contentWindow) {
|
|
39
|
+
return;
|
|
37
40
|
}
|
|
41
|
+
|
|
42
|
+
var data = event.data || event.message;
|
|
43
|
+
if (!data || typeof data.event !== 'string') {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var eventName = data.event;
|
|
48
|
+
var args = Array.isArray(data.args) ? data.args : [];
|
|
49
|
+
events.emit.apply(events, [eventName].concat(args));
|
|
50
|
+
}
|
|
51
|
+
function sendMessage(action) {
|
|
52
|
+
iframeElement.contentWindow.postMessage(action, '*');
|
|
38
53
|
}
|
|
39
54
|
function onError(error) {
|
|
40
55
|
events.emit('error', error);
|
|
@@ -42,14 +57,13 @@ function IFrameVideo(options) {
|
|
|
42
57
|
command('unload');
|
|
43
58
|
}
|
|
44
59
|
}
|
|
45
|
-
function onPropChanged(propName) {
|
|
60
|
+
function onPropChanged(propName, propValue) {
|
|
46
61
|
if (observedProps[propName]) {
|
|
47
|
-
events.emit('propChanged', propName,
|
|
62
|
+
events.emit('propChanged', propName, propValue);
|
|
48
63
|
}
|
|
49
64
|
}
|
|
50
65
|
function observeProp(propName) {
|
|
51
66
|
if (observedProps.hasOwnProperty(propName)) {
|
|
52
|
-
events.emit('propValue', propName, getProp(propName));
|
|
53
67
|
observedProps[propName] = true;
|
|
54
68
|
}
|
|
55
69
|
}
|
|
@@ -58,29 +72,46 @@ function IFrameVideo(options) {
|
|
|
58
72
|
case 'load': {
|
|
59
73
|
command('unload');
|
|
60
74
|
if (commandArgs && commandArgs.stream && typeof commandArgs.stream.playerFrameUrl === 'string') {
|
|
61
|
-
|
|
62
|
-
onPropChanged('stream');
|
|
75
|
+
window.addEventListener('message', onMessage, false);
|
|
63
76
|
iframeElement.src = commandArgs.stream.playerFrameUrl;
|
|
77
|
+
return false;
|
|
64
78
|
} else {
|
|
65
79
|
onError(Object.assign({}, ERROR.UNSUPPORTED_STREAM, {
|
|
66
80
|
critical: true,
|
|
67
81
|
stream: commandArgs ? commandArgs.stream : null
|
|
68
82
|
}));
|
|
83
|
+
return true;
|
|
69
84
|
}
|
|
70
|
-
break;
|
|
71
85
|
}
|
|
72
86
|
case 'unload': {
|
|
73
|
-
|
|
87
|
+
window.removeEventListener('message', onMessage);
|
|
74
88
|
iframeElement.removeAttribute('src');
|
|
75
|
-
onPropChanged('stream');
|
|
76
|
-
|
|
89
|
+
onPropChanged('stream', null);
|
|
90
|
+
onPropChanged('paused', null);
|
|
91
|
+
onPropChanged('time', null);
|
|
92
|
+
onPropChanged('duration', null);
|
|
93
|
+
onPropChanged('buffering', null);
|
|
94
|
+
onPropChanged('buffered', null);
|
|
95
|
+
onPropChanged('volume', null);
|
|
96
|
+
onPropChanged('muted', null);
|
|
97
|
+
onPropChanged('playbackSpeed', null);
|
|
98
|
+
return true;
|
|
77
99
|
}
|
|
78
100
|
case 'destroy': {
|
|
79
101
|
command('unload');
|
|
80
102
|
destroyed = true;
|
|
103
|
+
onPropChanged('stream', null);
|
|
104
|
+
onPropChanged('paused', null);
|
|
105
|
+
onPropChanged('time', null);
|
|
106
|
+
onPropChanged('duration', null);
|
|
107
|
+
onPropChanged('buffering', null);
|
|
108
|
+
onPropChanged('buffered', null);
|
|
109
|
+
onPropChanged('volume', null);
|
|
110
|
+
onPropChanged('muted', null);
|
|
111
|
+
onPropChanged('playbackSpeed', null);
|
|
81
112
|
events.removeAllListeners();
|
|
82
113
|
containerElement.removeChild(iframeElement);
|
|
83
|
-
|
|
114
|
+
return true;
|
|
84
115
|
}
|
|
85
116
|
}
|
|
86
117
|
}
|
|
@@ -102,10 +133,18 @@ function IFrameVideo(options) {
|
|
|
102
133
|
switch (action.type) {
|
|
103
134
|
case 'observeProp': {
|
|
104
135
|
observeProp(action.propName);
|
|
136
|
+
sendMessage(action);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
case 'setProp': {
|
|
140
|
+
sendMessage(action);
|
|
105
141
|
return;
|
|
106
142
|
}
|
|
107
143
|
case 'command': {
|
|
108
|
-
command(action.commandName, action.commandArgs)
|
|
144
|
+
if (!command(action.commandName, action.commandArgs)) {
|
|
145
|
+
sendMessage(action);
|
|
146
|
+
}
|
|
147
|
+
|
|
109
148
|
return;
|
|
110
149
|
}
|
|
111
150
|
}
|
|
@@ -121,10 +160,10 @@ IFrameVideo.canPlayStream = function(stream) {
|
|
|
121
160
|
|
|
122
161
|
IFrameVideo.manifest = {
|
|
123
162
|
name: 'IFrameVideo',
|
|
124
|
-
external:
|
|
125
|
-
props: ['stream'],
|
|
126
|
-
commands: ['load', 'unload', 'destroy'],
|
|
127
|
-
events: ['propValue', 'propChanged', 'error']
|
|
163
|
+
external: true,
|
|
164
|
+
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'buffered', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOutlineColor', 'volume', 'muted', 'playbackSpeed', 'extraSubtitlesTracks', 'selectedExtraSubtitlesTrackId', 'extraSubtitlesDelay', 'extraSubtitlesSize', 'extraSubtitlesOffset', 'extraSubtitlesTextColor', 'extraSubtitlesBackgroundColor', 'extraSubtitlesOutlineColor'],
|
|
165
|
+
commands: ['load', 'unload', 'destroy', 'addExtraSubtitlesTracks'],
|
|
166
|
+
events: ['propValue', 'propChanged', 'ended', 'error', 'subtitlesTrackLoaded', 'audioTrackLoaded', 'extraSubtitlesTrackLoaded', 'implementationChanged']
|
|
128
167
|
};
|
|
129
168
|
|
|
130
169
|
module.exports = IFrameVideo;
|
|
@@ -4,9 +4,7 @@ var deepFreeze = require('deep-freeze');
|
|
|
4
4
|
var selectVideoImplementation = require('./selectVideoImplementation');
|
|
5
5
|
var ERROR = require('../error');
|
|
6
6
|
|
|
7
|
-
function StremioVideo(
|
|
8
|
-
options = options || {};
|
|
9
|
-
|
|
7
|
+
function StremioVideo() {
|
|
10
8
|
var video = null;
|
|
11
9
|
var events = new EventEmitter();
|
|
12
10
|
var destroyed = false;
|
|
@@ -18,15 +16,16 @@ function StremioVideo(options) {
|
|
|
18
16
|
|
|
19
17
|
events.on(eventName, listener);
|
|
20
18
|
};
|
|
21
|
-
this.dispatch = function(action) {
|
|
19
|
+
this.dispatch = function(action, options) {
|
|
22
20
|
if (destroyed) {
|
|
23
21
|
throw new Error('Video is destroyed');
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
if (action) {
|
|
27
25
|
action = deepFreeze(cloneDeep(action));
|
|
26
|
+
options = options || {};
|
|
28
27
|
if (action.type === 'command' && action.commandName === 'load' && action.commandArgs) {
|
|
29
|
-
var Video = selectVideoImplementation(action.commandArgs);
|
|
28
|
+
var Video = selectVideoImplementation(action.commandArgs, options);
|
|
30
29
|
if (video !== null && video.constructor !== Video) {
|
|
31
30
|
video.dispatch({ type: 'command', commandName: 'destroy' });
|
|
32
31
|
video = null;
|
|
@@ -41,7 +40,7 @@ function StremioVideo(options) {
|
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
video = new Video(
|
|
43
|
+
video = new Video(options);
|
|
45
44
|
video.on('ended', function() {
|
|
46
45
|
events.emit('ended');
|
|
47
46
|
});
|
|
@@ -5,28 +5,28 @@ var YouTubeVideo = require('../YouTubeVideo');
|
|
|
5
5
|
var withStreamingServer = require('../withStreamingServer');
|
|
6
6
|
var withHTMLSubtitles = require('../withHTMLSubtitles');
|
|
7
7
|
|
|
8
|
-
function selectVideoImplementation(
|
|
9
|
-
if (!
|
|
8
|
+
function selectVideoImplementation(commandArgs, options) {
|
|
9
|
+
if (!commandArgs.stream || typeof commandArgs.stream.externalUrl === 'string') {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
if (
|
|
13
|
+
if (options.chromecastTransport && options.chromecastTransport.getCastState() === cast.framework.CastState.CONNECTED) {
|
|
14
14
|
return ChromecastSenderVideo;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (typeof
|
|
17
|
+
if (typeof commandArgs.stream.ytId === 'string') {
|
|
18
18
|
return withHTMLSubtitles(YouTubeVideo);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
if (typeof
|
|
21
|
+
if (typeof commandArgs.stream.playerFrameUrl === 'string') {
|
|
22
22
|
return IFrameVideo;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if (typeof
|
|
25
|
+
if (typeof commandArgs.streamingServerURL === 'string') {
|
|
26
26
|
return withStreamingServer(withHTMLSubtitles(HTMLVideo));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (typeof
|
|
29
|
+
if (typeof commandArgs.stream.url === 'string') {
|
|
30
30
|
return withHTMLSubtitles(HTMLVideo);
|
|
31
31
|
}
|
|
32
32
|
|