@hopecloud/jetstream-player 0.1.7 → 0.1.9
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.
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
type CallbackType = (index: number) => void;
|
|
2
|
-
export declare const onEnded: (callback: CallbackType) => void;
|
|
3
|
-
export declare const playVideo: (callback: CallbackType) => void;
|
|
4
|
-
export declare const pauseVideo: (callback: CallbackType) => void;
|
|
5
1
|
export declare const embedPlayer: {
|
|
6
2
|
play: (index: number) => void;
|
|
7
3
|
pause: (index: number) => void;
|
|
8
4
|
};
|
|
5
|
+
type CallbackType = (index: number) => void;
|
|
6
|
+
export declare const onEnded: (callback: CallbackType) => void;
|
|
7
|
+
export declare const playVideo: (callback: CallbackType) => void;
|
|
8
|
+
export declare const pauseVideo: (callback: CallbackType) => void;
|
|
9
|
+
export declare const initializeMessageListener: () => void;
|
|
9
10
|
export {};
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
let iframesWithEmbedVideo = [];
|
|
2
2
|
let allIframes = [];
|
|
3
3
|
let embedVideosSrc = [];
|
|
4
|
-
const callbacks = {};
|
|
5
|
-
export const onEnded = (callback) => {
|
|
6
|
-
callbacks.onEnded = callback;
|
|
7
|
-
};
|
|
8
|
-
export const playVideo = (callback) => {
|
|
9
|
-
callbacks.playVideo = callback;
|
|
10
|
-
};
|
|
11
|
-
export const pauseVideo = (callback) => {
|
|
12
|
-
callbacks.pauseVideo = callback;
|
|
13
|
-
};
|
|
14
4
|
document.addEventListener('DOMContentLoaded', () => {
|
|
15
5
|
({ iframesWithEmbedVideo, allIframes, embedVideosSrc } = Array.from(document.querySelectorAll('iframe')).reduce((acc, iframe) => {
|
|
16
6
|
const { src } = iframe;
|
|
@@ -23,15 +13,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
23
13
|
acc.allIframes.push(iframe);
|
|
24
14
|
return acc;
|
|
25
15
|
}, { iframesWithEmbedVideo: [], allIframes: [], embedVideosSrc: [] }));
|
|
26
|
-
window.addEventListener('message', (event) => {
|
|
27
|
-
if (event.data.src) {
|
|
28
|
-
const index = embedVideosSrc.findIndex(elem => elem.includes(event.data.src.split('/')
|
|
29
|
-
.find(substr => substr.startsWith('jsv:'))));
|
|
30
|
-
if (event.data.msg in callbacks) {
|
|
31
|
-
callbacks[event.data.msg](index);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
16
|
});
|
|
36
17
|
export const embedPlayer = new Proxy({
|
|
37
18
|
play: (index) => { },
|
|
@@ -44,3 +25,24 @@ export const embedPlayer = new Proxy({
|
|
|
44
25
|
};
|
|
45
26
|
}
|
|
46
27
|
});
|
|
28
|
+
const callbacks = {};
|
|
29
|
+
export const onEnded = (callback) => {
|
|
30
|
+
callbacks.onEnded = callback;
|
|
31
|
+
};
|
|
32
|
+
export const playVideo = (callback) => {
|
|
33
|
+
callbacks.playVideo = callback;
|
|
34
|
+
};
|
|
35
|
+
export const pauseVideo = (callback) => {
|
|
36
|
+
callbacks.pauseVideo = callback;
|
|
37
|
+
};
|
|
38
|
+
export const initializeMessageListener = () => {
|
|
39
|
+
window.addEventListener('message', (event) => {
|
|
40
|
+
if (event.data.src) {
|
|
41
|
+
const index = embedVideosSrc.findIndex(elem => elem.includes(event.data.src.split('/')
|
|
42
|
+
.find(substr => substr.startsWith('jsv:'))));
|
|
43
|
+
if (event.data.msg in callbacks) {
|
|
44
|
+
callbacks[event.data.msg](index);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|