@hopecloud/jetstream-player 0.2.7 → 0.2.8
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/dist/useEmbedPlayerMethods.d.ts +15 -22
- package/dist/useEmbedPlayerMethods.js +32 -54
- package/docs/index.md +2 -2
- package/package.json +3 -3
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare const initPlayerMethods: () => {
|
|
7
|
-
new (selector: string): {
|
|
8
|
-
iframe: HTMLIFrameElement;
|
|
9
|
-
play(): void;
|
|
10
|
-
pause(): void;
|
|
11
|
-
playNext(): void;
|
|
12
|
-
playPrevious(): void;
|
|
1
|
+
type CallbackType = () => void;
|
|
2
|
+
export declare class JetstreamPlayer {
|
|
3
|
+
iframe: HTMLIFrameElement;
|
|
4
|
+
callbacks: {
|
|
5
|
+
[key: string]: CallbackType;
|
|
13
6
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
7
|
+
constructor(selector: string);
|
|
8
|
+
play(): void;
|
|
9
|
+
pause(): void;
|
|
10
|
+
playNext(): void;
|
|
11
|
+
playPrevious(): void;
|
|
12
|
+
seekTo(seconds: number): void;
|
|
13
|
+
onEnded: (callback: CallbackType) => void;
|
|
14
|
+
playVideo: (callback: CallbackType) => void;
|
|
15
|
+
pauseVideo: (callback: CallbackType) => void;
|
|
16
|
+
}
|
|
24
17
|
export {};
|
|
@@ -1,60 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const onEnded = (callback) => {
|
|
7
|
-
callbacks.onEnded = callback;
|
|
8
|
-
};
|
|
9
|
-
export const playVideo = (callback) => {
|
|
10
|
-
callbacks.playVideo = callback;
|
|
11
|
-
};
|
|
12
|
-
export const pauseVideo = (callback) => {
|
|
13
|
-
callbacks.pauseVideo = callback;
|
|
14
|
-
};
|
|
15
|
-
export const initPlayerMethods = () => {
|
|
16
|
-
({ iframesWithEmbedVideo, allIframes, embedVideosSrc } = Array.from(document.querySelectorAll('iframe')).reduce((acc, iframe) => {
|
|
17
|
-
const { src } = iframe;
|
|
18
|
-
const iframeOrigin = new URL(src).origin;
|
|
19
|
-
// Check if iframe has embed player origin
|
|
20
|
-
if (iframeOrigin.includes('jstre')) {
|
|
21
|
-
acc.iframesWithEmbedVideo.push(iframe);
|
|
22
|
-
acc.embedVideosSrc.push(src);
|
|
23
|
-
}
|
|
24
|
-
acc.allIframes.push(iframe);
|
|
25
|
-
return acc;
|
|
26
|
-
}, { iframesWithEmbedVideo: [], allIframes: [], embedVideosSrc: [] }));
|
|
27
|
-
if (!eventListenerAdded) {
|
|
1
|
+
export class JetstreamPlayer {
|
|
2
|
+
iframe;
|
|
3
|
+
callbacks = {};
|
|
4
|
+
constructor(selector) {
|
|
5
|
+
this.iframe = document.querySelector(selector);
|
|
28
6
|
window.addEventListener('message', (event) => {
|
|
29
|
-
if (event.data.src) {
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
if (event.data.msg in callbacks) {
|
|
33
|
-
callbacks[event.data.msg](index);
|
|
7
|
+
if (event.data.src && this.iframe.src.includes(event.data.src.split('/').find(substr => (substr.startsWith('jsv:') || substr.startsWith('jspl:'))))) {
|
|
8
|
+
if (event.data.msg in this.callbacks) {
|
|
9
|
+
this.callbacks[event.data.msg]();
|
|
34
10
|
}
|
|
35
11
|
}
|
|
36
12
|
});
|
|
37
|
-
eventListenerAdded = true;
|
|
38
13
|
}
|
|
39
|
-
|
|
40
|
-
iframe;
|
|
41
|
-
constructor(selector) {
|
|
42
|
-
this.iframe = document.querySelector(selector);
|
|
43
|
-
}
|
|
44
|
-
play() {
|
|
45
|
-
this.iframe.contentWindow?.postMessage('play', '*');
|
|
46
|
-
}
|
|
47
|
-
pause() {
|
|
48
|
-
this.iframe.contentWindow?.postMessage('pause', '*');
|
|
49
|
-
}
|
|
50
|
-
playNext() {
|
|
51
|
-
this.iframe.contentWindow?.postMessage('playNext', '*');
|
|
52
|
-
}
|
|
53
|
-
playPrevious() {
|
|
54
|
-
this.iframe.contentWindow?.postMessage('playPrevious', '*');
|
|
55
|
-
}
|
|
14
|
+
play() {
|
|
15
|
+
this.iframe.contentWindow?.postMessage('play', '*');
|
|
56
16
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
17
|
+
pause() {
|
|
18
|
+
this.iframe.contentWindow?.postMessage('pause', '*');
|
|
19
|
+
}
|
|
20
|
+
playNext() {
|
|
21
|
+
this.iframe.contentWindow?.postMessage('playNext', '*');
|
|
22
|
+
}
|
|
23
|
+
playPrevious() {
|
|
24
|
+
this.iframe.contentWindow?.postMessage('playPrevious', '*');
|
|
25
|
+
}
|
|
26
|
+
seekTo(seconds) {
|
|
27
|
+
this.iframe.contentWindow?.postMessage({ method: 'seekTo', param: seconds }, '*');
|
|
28
|
+
}
|
|
29
|
+
onEnded = (callback) => {
|
|
30
|
+
this.callbacks.onEnded = callback;
|
|
31
|
+
};
|
|
32
|
+
playVideo = (callback) => {
|
|
33
|
+
this.callbacks.playVideo = callback;
|
|
34
|
+
};
|
|
35
|
+
pauseVideo = (callback) => {
|
|
36
|
+
this.callbacks.pauseVideo = callback;
|
|
37
|
+
};
|
|
38
|
+
}
|
package/docs/index.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hopecloud/jetstream-player",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Embeddable player for Jetstream videos",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"main": "dist/index.js",
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"typescript": "^5.0.
|
|
13
|
+
"typescript": "^5.0.4",
|
|
14
14
|
"vitepress": "^1.0.0-alpha.65"
|
|
15
15
|
}
|
|
16
|
-
}
|
|
16
|
+
}
|