@hopecloud/jetstream-player 0.3.5 → 1.0.0
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/index.d.ts +2 -23
- package/dist/index.js +2 -114
- package/dist/player.d.ts +23 -0
- package/dist/player.js +114 -0
- package/package.json +22 -3
- package/.eslintrc.cjs +0 -32
- package/.prettierignore +0 -2
- package/docs/.vitepress/config.ts +0 -54
- package/docs/guide/getting-started.md +0 -111
- package/docs/guide/index.md +0 -11
- package/docs/index.md +0 -23
- package/docs/usage/player-events.md +0 -131
- package/docs/usage/player-methods.md +0 -186
- package/docs/usage/using-multiple-iframes.md +0 -98
- package/prettier.config.mjs +0 -7
- package/tsconfig.json +0 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
private iframe;
|
|
4
|
-
private options;
|
|
5
|
-
private registeredEvents;
|
|
6
|
-
constructor(el: string | HTMLIFrameElement, options: JetStreamPlayerOptions);
|
|
7
|
-
private registerEventHandler;
|
|
8
|
-
private registerEvents;
|
|
9
|
-
private dispatch;
|
|
10
|
-
private getterDispatch;
|
|
11
|
-
play(): void;
|
|
12
|
-
pause(): void;
|
|
13
|
-
mute(): void;
|
|
14
|
-
unmute(): void;
|
|
15
|
-
seekTo(seconds: number): void;
|
|
16
|
-
playNext(): void;
|
|
17
|
-
playPrev(): void;
|
|
18
|
-
isMuted(): Promise<boolean>;
|
|
19
|
-
isPaused(): Promise<boolean>;
|
|
20
|
-
getVideoCurrentTime(): Promise<number>;
|
|
21
|
-
getDuration(): Promise<number>;
|
|
22
|
-
dispose(): void;
|
|
23
|
-
}
|
|
1
|
+
export { JetStreamPlayer } from './player';
|
|
2
|
+
export { EventKey, EventMap, GettersEvents, JetStreamPlayerOptions, PlayerCommand, PlayerEvent, eventsMap, gettersEvents, } from './player.type';
|
package/dist/index.js
CHANGED
|
@@ -1,114 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
iframe = null;
|
|
4
|
-
options;
|
|
5
|
-
registeredEvents = {};
|
|
6
|
-
constructor(el, options) {
|
|
7
|
-
this.iframe =
|
|
8
|
-
typeof el === 'string'
|
|
9
|
-
? document.querySelector(el)
|
|
10
|
-
: el;
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.registerEvents();
|
|
13
|
-
}
|
|
14
|
-
registerEventHandler(event) {
|
|
15
|
-
const data = normalizeEventData(event);
|
|
16
|
-
const targetEvent = data.target;
|
|
17
|
-
if (event.source === this.iframe.contentWindow) {
|
|
18
|
-
if (targetEvent in this.registeredEvents) {
|
|
19
|
-
this.registeredEvents[targetEvent](data.target);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
registerEvents() {
|
|
24
|
-
if (!this.options.events ||
|
|
25
|
-
(this.options.events && Object.keys(this.options.events).length < 0)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
Object.entries(this.options.events).forEach(([eventName, cb]) => {
|
|
29
|
-
if (!(eventName in this.registeredEvents)) {
|
|
30
|
-
this.registeredEvents[eventName] = cb;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
window.addEventListener('message', this.registerEventHandler.bind(this));
|
|
34
|
-
}
|
|
35
|
-
dispatch(event) {
|
|
36
|
-
if (!this.iframe || !this.iframe.contentWindow) {
|
|
37
|
-
throw new Error('iframe is not provided or parent window not found!');
|
|
38
|
-
}
|
|
39
|
-
this.iframe.contentWindow.postMessage(denormalizeEventData(event), '*');
|
|
40
|
-
}
|
|
41
|
-
getterDispatch(getterEvent) {
|
|
42
|
-
return new Promise((resolve) => {
|
|
43
|
-
this.dispatch(getterEvent);
|
|
44
|
-
window.addEventListener('message', (event) => {
|
|
45
|
-
const data = normalizeEventData(event);
|
|
46
|
-
if (data.type === getterEvent.name) {
|
|
47
|
-
resolve(data.target);
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
once: true,
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
play() {
|
|
55
|
-
this.dispatch({
|
|
56
|
-
name: 'play',
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
pause() {
|
|
60
|
-
this.dispatch({
|
|
61
|
-
name: 'pause',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
mute() {
|
|
65
|
-
this.dispatch({
|
|
66
|
-
name: 'mute',
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
unmute() {
|
|
70
|
-
this.dispatch({
|
|
71
|
-
name: 'unmute',
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
seekTo(seconds) {
|
|
75
|
-
this.dispatch({
|
|
76
|
-
name: 'seekTo',
|
|
77
|
-
params: seconds,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
playNext() {
|
|
81
|
-
this.dispatch({
|
|
82
|
-
name: 'play-next',
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
playPrev() {
|
|
86
|
-
this.dispatch({
|
|
87
|
-
name: 'play-prev',
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
isMuted() {
|
|
91
|
-
return this.getterDispatch({
|
|
92
|
-
name: 'isMuted',
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
isPaused() {
|
|
96
|
-
return this.getterDispatch({
|
|
97
|
-
name: 'isPaused',
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
getVideoCurrentTime() {
|
|
101
|
-
return this.getterDispatch({
|
|
102
|
-
name: 'getVideoCurrentTime',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
getDuration() {
|
|
106
|
-
return this.getterDispatch({
|
|
107
|
-
name: 'getDuration',
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
dispose() {
|
|
111
|
-
window.removeEventListener('message', this.registerEventHandler);
|
|
112
|
-
this.registeredEvents = {};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
1
|
+
export { JetStreamPlayer } from './player';
|
|
2
|
+
export { eventsMap, gettersEvents, } from './player.type';
|
package/dist/player.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { JetStreamPlayerOptions } from './player.type';
|
|
2
|
+
export declare class JetStreamPlayer {
|
|
3
|
+
private iframe;
|
|
4
|
+
private options;
|
|
5
|
+
private registeredEvents;
|
|
6
|
+
constructor(el: string | HTMLIFrameElement, options: JetStreamPlayerOptions);
|
|
7
|
+
private registerEventHandler;
|
|
8
|
+
private registerEvents;
|
|
9
|
+
private dispatch;
|
|
10
|
+
private getterDispatch;
|
|
11
|
+
play(): void;
|
|
12
|
+
pause(): void;
|
|
13
|
+
mute(): void;
|
|
14
|
+
unmute(): void;
|
|
15
|
+
seekTo(seconds: number): void;
|
|
16
|
+
playNext(): void;
|
|
17
|
+
playPrev(): void;
|
|
18
|
+
isMuted(): Promise<boolean>;
|
|
19
|
+
isPaused(): Promise<boolean>;
|
|
20
|
+
getVideoCurrentTime(): Promise<number>;
|
|
21
|
+
getDuration(): Promise<number>;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
package/dist/player.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { denormalizeEventData, normalizeEventData } from './utils';
|
|
2
|
+
export class JetStreamPlayer {
|
|
3
|
+
iframe = null;
|
|
4
|
+
options;
|
|
5
|
+
registeredEvents = {};
|
|
6
|
+
constructor(el, options) {
|
|
7
|
+
this.iframe =
|
|
8
|
+
typeof el === 'string'
|
|
9
|
+
? document.querySelector(el)
|
|
10
|
+
: el;
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.registerEvents();
|
|
13
|
+
}
|
|
14
|
+
registerEventHandler(event) {
|
|
15
|
+
const data = normalizeEventData(event);
|
|
16
|
+
const targetEvent = data.target;
|
|
17
|
+
if (event.source === this.iframe.contentWindow) {
|
|
18
|
+
if (targetEvent in this.registeredEvents) {
|
|
19
|
+
this.registeredEvents[targetEvent](data.target);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
registerEvents() {
|
|
24
|
+
if (!this.options.events ||
|
|
25
|
+
(this.options.events && Object.keys(this.options.events).length < 0)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
Object.entries(this.options.events).forEach(([eventName, cb]) => {
|
|
29
|
+
if (!(eventName in this.registeredEvents)) {
|
|
30
|
+
this.registeredEvents[eventName] = cb;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
window.addEventListener('message', this.registerEventHandler.bind(this));
|
|
34
|
+
}
|
|
35
|
+
dispatch(event) {
|
|
36
|
+
if (!this.iframe || !this.iframe.contentWindow) {
|
|
37
|
+
throw new Error('iframe is not provided or parent window not found!');
|
|
38
|
+
}
|
|
39
|
+
this.iframe.contentWindow.postMessage(denormalizeEventData(event), '*');
|
|
40
|
+
}
|
|
41
|
+
getterDispatch(getterEvent) {
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
this.dispatch(getterEvent);
|
|
44
|
+
window.addEventListener('message', (event) => {
|
|
45
|
+
const data = normalizeEventData(event);
|
|
46
|
+
if (data.type === getterEvent.name) {
|
|
47
|
+
resolve(data.target);
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
once: true,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
play() {
|
|
55
|
+
this.dispatch({
|
|
56
|
+
name: 'play',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
pause() {
|
|
60
|
+
this.dispatch({
|
|
61
|
+
name: 'pause',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
mute() {
|
|
65
|
+
this.dispatch({
|
|
66
|
+
name: 'mute',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
unmute() {
|
|
70
|
+
this.dispatch({
|
|
71
|
+
name: 'unmute',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
seekTo(seconds) {
|
|
75
|
+
this.dispatch({
|
|
76
|
+
name: 'seekTo',
|
|
77
|
+
params: seconds,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
playNext() {
|
|
81
|
+
this.dispatch({
|
|
82
|
+
name: 'play-next',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
playPrev() {
|
|
86
|
+
this.dispatch({
|
|
87
|
+
name: 'play-prev',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
isMuted() {
|
|
91
|
+
return this.getterDispatch({
|
|
92
|
+
name: 'isMuted',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
isPaused() {
|
|
96
|
+
return this.getterDispatch({
|
|
97
|
+
name: 'isPaused',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getVideoCurrentTime() {
|
|
101
|
+
return this.getterDispatch({
|
|
102
|
+
name: 'getVideoCurrentTime',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
getDuration() {
|
|
106
|
+
return this.getterDispatch({
|
|
107
|
+
name: 'getDuration',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
dispose() {
|
|
111
|
+
window.removeEventListener('message', this.registerEventHandler);
|
|
112
|
+
this.registeredEvents = {};
|
|
113
|
+
}
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hopecloud/jetstream-player",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "JetStream Embed Player API",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"author": {
|
|
7
|
+
"email": "code@deepvision.team",
|
|
8
|
+
"name": "DeepVision Code"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/deeepvision/hcc-jetstream-player"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"registry": "https://npm.pkg.github.com/"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
6
27
|
"scripts": {
|
|
7
28
|
"build": "tsc",
|
|
8
29
|
"pack": "npm run build && npm pack",
|
|
@@ -13,8 +34,6 @@
|
|
|
13
34
|
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
14
35
|
"publish:next": "npm version patch -m \"release: %s\""
|
|
15
36
|
},
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"types": "dist/index.d.ts",
|
|
18
37
|
"devDependencies": {
|
|
19
38
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
20
39
|
"@typescript-eslint/parser": "^7.2.0",
|
package/.eslintrc.cjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
browser: true,
|
|
4
|
-
es2021: true,
|
|
5
|
-
},
|
|
6
|
-
extends: [
|
|
7
|
-
'eslint:recommended',
|
|
8
|
-
'plugin:@typescript-eslint/recommended',
|
|
9
|
-
'prettier',
|
|
10
|
-
],
|
|
11
|
-
overrides: [
|
|
12
|
-
{
|
|
13
|
-
env: {
|
|
14
|
-
node: true,
|
|
15
|
-
},
|
|
16
|
-
files: ['.eslintrc.{js,cjs}'],
|
|
17
|
-
parserOptions: {
|
|
18
|
-
sourceType: 'script',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
parser: '@typescript-eslint/parser',
|
|
23
|
-
parserOptions: {
|
|
24
|
-
ecmaVersion: 'latest',
|
|
25
|
-
sourceType: 'module',
|
|
26
|
-
},
|
|
27
|
-
plugins: ['@typescript-eslint'],
|
|
28
|
-
rules: {
|
|
29
|
-
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
30
|
-
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
31
|
-
},
|
|
32
|
-
};
|
package/.prettierignore
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default {
|
|
3
|
-
title: "Jetstream player API",
|
|
4
|
-
description: "Documentation of embed jetstream player API",
|
|
5
|
-
themeConfig: {
|
|
6
|
-
nav: [
|
|
7
|
-
{
|
|
8
|
-
text: 'Guide',
|
|
9
|
-
link: '/guide/'
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
text: 'Usage',
|
|
13
|
-
link: '/usage/using-multiple-iframes'
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
|
|
17
|
-
sidebar: [
|
|
18
|
-
{
|
|
19
|
-
text: 'Introduction',
|
|
20
|
-
items: [
|
|
21
|
-
{
|
|
22
|
-
text: 'What is Jetstream player API?',
|
|
23
|
-
link: '/guide/',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
text: 'Getting Started',
|
|
27
|
-
link: '/guide/getting-started',
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
text: 'Examples of use',
|
|
33
|
-
items: [
|
|
34
|
-
{
|
|
35
|
-
text: 'Using multiple iframes',
|
|
36
|
-
link: '/usage/using-multiple-iframes',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
text: 'Jetstream player API methods',
|
|
40
|
-
link: '/usage/player-methods',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
text: 'Jetstream player API events',
|
|
44
|
-
link: '/usage/player-events',
|
|
45
|
-
},
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
|
|
50
|
-
socialLinks: [
|
|
51
|
-
{ icon: 'github', link: 'https://github.com/deeepvision/hcc-jetstream-player' }
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
# Getting Started
|
|
2
|
-
|
|
3
|
-
## Try It Online
|
|
4
|
-
|
|
5
|
-
You can try Jetstrem player API directly in your browser on [StackBlitz](https://stackblitz.com/edit/hcc-jetstream-player-demo?file=src%2Fcomponents%2FVideoSandbox.vue).
|
|
6
|
-
|
|
7
|
-
## How to use?
|
|
8
|
-
|
|
9
|
-
If you want to use the library in your project, you need to perform the following steps:
|
|
10
|
-
|
|
11
|
-
- Installation
|
|
12
|
-
- Initialization `JetstreamPlayer` with iframe
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
Jetstrem player API can be installed in an existing project via npm.
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
npm i @hopecloud/jetstream-player
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Once installed, you will be able to import `JetstreamPlayer` clas from the library into your component
|
|
23
|
-
|
|
24
|
-
```js
|
|
25
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Inside of `JetstreamPlayer` class there are methods `play`, `pause`, etc.
|
|
29
|
-
You can find all available [methods](../usage/player-methods) and [events](../usage/player-events) in the following sections.
|
|
30
|
-
|
|
31
|
-
```js
|
|
32
|
-
class JetstreamPlayer {
|
|
33
|
-
iframe;
|
|
34
|
-
constructor(selector) {
|
|
35
|
-
this.iframe = document.querySelector(selector);
|
|
36
|
-
}
|
|
37
|
-
play() {
|
|
38
|
-
this.iframe.contentWindow?.postMessage('play', '*');
|
|
39
|
-
}
|
|
40
|
-
pause() {
|
|
41
|
-
this.iframe.contentWindow?.postMessage('pause', '*');
|
|
42
|
-
}
|
|
43
|
-
...
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Initialization `JetstreamPlayer` with iframe
|
|
48
|
-
|
|
49
|
-
### Important ☝️⬇️
|
|
50
|
-
|
|
51
|
-
In order to connect our iframe with `JetstreamPlayer` class, we need determines which player exactly you want to interact with. We should somehow distinguish between embedded windows in our template. Since we can have **_one_** or **_many_** iframes, we **strongly recommend** to assign a separate `id` to each iframe.
|
|
52
|
-
|
|
53
|
-
For example `id="iframe1"`, `id="iframe2"`
|
|
54
|
-
|
|
55
|
-
```html
|
|
56
|
-
<div style="display: block; position:relative; max-width: 100%; width: 100%;">
|
|
57
|
-
<div style="padding-top: 56.25%;">
|
|
58
|
-
<iframe
|
|
59
|
-
id="iframe1"
|
|
60
|
-
allow="autoplay; encrypted-media"
|
|
61
|
-
allowfullscreen
|
|
62
|
-
style="position:absolute; top:0; left:0; width:100%; height:100%; border-radius: 20px;"
|
|
63
|
-
src="https://dev.jstre.am/embed/jsv:fEccZ5231KM/jsp:Ov2URVCKycR"
|
|
64
|
-
></iframe>
|
|
65
|
-
</div>
|
|
66
|
-
</div>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Since the iframe already has the specified `id`, we can create a variable _(array of variables)_ to bind the `JetstreamPlayer` with our iframe.
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
let player: JetstreamPlayer | null;
|
|
73
|
-
|
|
74
|
-
player = new JetstreamPlayer('#iframe1');
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Pay attention ☝️⬇️
|
|
78
|
-
|
|
79
|
-
Initialization must occur when all DOM elements are loaded. Therefore, in our [Vue.js example](https://stackblitz.com/edit/hcc-jetstream-player-demo?file=src%2Fcomponents%2FVideoSandbox.vue), we initialize our players inside the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) lifecycle hook. Thus the player is initialized when template is fully loaded.
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
onMounted(() => {
|
|
83
|
-
player = new JetstreamPlayer('#iframe1');
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
After that, we can access the `player` variable and call the methods available in the `JetstreamPlayer` class.
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
setup() {
|
|
91
|
-
let player: JetstreamPlayer | null;
|
|
92
|
-
|
|
93
|
-
onMounted(() => {
|
|
94
|
-
player = new JetstreamPlayer('#iframe1');
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const playVideo = () => {
|
|
98
|
-
player.play();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const pauseVideo = () => {
|
|
102
|
-
player.pause();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
playVideo,
|
|
107
|
-
pauseVideo,
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
package/docs/guide/index.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# What is Jetstream player API?
|
|
2
|
-
|
|
3
|
-
## Short description
|
|
4
|
-
|
|
5
|
-
**Jetstream player API** is a library that allows you to control an embedded video player from the outside of `iframe` and subscribe to events of that player. As you know, videos are embedded in a website through an `iframe` tag. As a user, you can play and stop the video by clicking a button within the iframe itself. But how about playing/stopping the video programmatically and receiving events directly from the player?
|
|
6
|
-
|
|
7
|
-
Since our embed video player is a separate service that uses the `video.js` under the hood, we cannot do this directly. Modern browsers don't allow this to be done, including due to `CORS` policy. Therefore, in this library, we use `postMessage()` methods that send directly to the player and where these methods are processed. On its side, embed player has its own methods that it also sends and that can be caught where it is used.
|
|
8
|
-
|
|
9
|
-
Thus, we can interact with player and subscribe to the events of the required video or playlist.
|
|
10
|
-
|
|
11
|
-
This library is adapted to work with [Vue.js](https://vuejs.org/) / [React](https://react.dev/) framework components. Just want to try it out? Skip to the [Quickstart](./getting-started).
|
package/docs/index.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
# https://github.com/deeepvision/hcc-jetstream-player
|
|
3
|
-
layout: home
|
|
4
|
-
|
|
5
|
-
hero:
|
|
6
|
-
name: "Jetstrem Player API"
|
|
7
|
-
text: "Documentation of embed Jetstream Player"
|
|
8
|
-
tagline:
|
|
9
|
-
actions:
|
|
10
|
-
- theme: brand
|
|
11
|
-
text: Get started
|
|
12
|
-
link: /guide/index
|
|
13
|
-
- theme: alt
|
|
14
|
-
text: View on GitHub
|
|
15
|
-
link: https://github.com/deeepvision/hcc-jetstream-player
|
|
16
|
-
|
|
17
|
-
features:
|
|
18
|
-
- title: Convenience
|
|
19
|
-
details: No need to write special methods in the component. All the necessary methods are in the library
|
|
20
|
-
- title: Ease of use
|
|
21
|
-
details: All you need is to import the library
|
|
22
|
-
---
|
|
23
|
-
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# Jetstrem player API events
|
|
2
|
-
|
|
3
|
-
## `Embed player` available events
|
|
4
|
-
|
|
5
|
-
### Next events are available in this version of the library:
|
|
6
|
-
|
|
7
|
-
- `onEnded()`
|
|
8
|
-
- `onPlayVideo()`
|
|
9
|
-
- `onPauseVideo()`
|
|
10
|
-
- `onVolumeChange()`
|
|
11
|
-
|
|
12
|
-
This list is not exhaustive. New events can be added as needed.
|
|
13
|
-
|
|
14
|
-
In order to use these events, it is enough to import `JetstreamPlayer` class which contains these methods.
|
|
15
|
-
|
|
16
|
-
```js
|
|
17
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
18
|
-
|
|
19
|
-
setup() {
|
|
20
|
-
let player: JetstreamPlayer | null;
|
|
21
|
-
|
|
22
|
-
onMounted(() => {
|
|
23
|
-
player = new JetstreamPlayer('#iframe1');
|
|
24
|
-
|
|
25
|
-
player.onEnded(() => {
|
|
26
|
-
console.log('Video is ENDED');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
...
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Pay attention ☝️⬇️
|
|
35
|
-
|
|
36
|
-
These events are `callbacks` that act as **listeners**.
|
|
37
|
-
In order to subscribe to events, all DOM elements must be loaded. That's why we put this listener in the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) hook.
|
|
38
|
-
Otherwise, events may not work.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## `onEnded()` event
|
|
42
|
-
|
|
43
|
-
This event is called when a video or a video in a playlist ends. For example, if your component has two iframes, the first is a video and the second is a playlist. If some video ends in the playlist, `onEnded()` event will be triggered.
|
|
44
|
-
|
|
45
|
-
### Example of use:
|
|
46
|
-
|
|
47
|
-
```js
|
|
48
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
49
|
-
|
|
50
|
-
setup() {
|
|
51
|
-
const players = [];
|
|
52
|
-
|
|
53
|
-
onMounted(() => {
|
|
54
|
-
players.push(new JetstreamPlayer('#iframe1'));
|
|
55
|
-
players.push(new JetstreamPlayer('#iframe2'));
|
|
56
|
-
|
|
57
|
-
players[1]?.onEnded(() => {
|
|
58
|
-
console.log('Video 2 is ENDED');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## `onPlayVideo()` event
|
|
65
|
-
|
|
66
|
-
This event is a listener that fires when any video or playlist on your page starts playing. If your page has one or more embedded iframes and a video starts playing in the first window, event will be triggered for first player.
|
|
67
|
-
|
|
68
|
-
### Example of use:
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
72
|
-
|
|
73
|
-
setup() {
|
|
74
|
-
const players = [];
|
|
75
|
-
|
|
76
|
-
onMounted(() => {
|
|
77
|
-
players.push(new JetstreamPlayer('#iframe1'));
|
|
78
|
-
players.push(new JetstreamPlayer('#iframe2'));
|
|
79
|
-
|
|
80
|
-
players[0]?.onPlayVideo(() => {
|
|
81
|
-
console.log('Video 1 is PLAYING');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## `onPauseVideo()` event
|
|
88
|
-
|
|
89
|
-
This event is a listener that fires when any video or playlist on your page paused. If your page has one or more embedded iframes and a video paused in the second window, event will be triggered for second player.
|
|
90
|
-
|
|
91
|
-
### Example of use:
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
95
|
-
|
|
96
|
-
setup() {
|
|
97
|
-
const players = [];
|
|
98
|
-
|
|
99
|
-
onMounted(() => {
|
|
100
|
-
players.push(new JetstreamPlayer('#iframe1'));
|
|
101
|
-
players.push(new JetstreamPlayer('#iframe2'));
|
|
102
|
-
|
|
103
|
-
players[1]?.onPauseVideo(() => {
|
|
104
|
-
console.log('Video 2 is PAUSED');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## `onVolumeChange()` event
|
|
111
|
-
|
|
112
|
-
This event is a listener that fires when any video or playlist on your page change volume. If your page has one or more embedded iframes and a video paused in the second window, event will be triggered for second player.
|
|
113
|
-
|
|
114
|
-
### Example of use:
|
|
115
|
-
|
|
116
|
-
```js
|
|
117
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
118
|
-
|
|
119
|
-
setup() {
|
|
120
|
-
const players = [];
|
|
121
|
-
|
|
122
|
-
onMounted(() => {
|
|
123
|
-
players.push(new JetstreamPlayer('#iframe1'));
|
|
124
|
-
players.push(new JetstreamPlayer('#iframe2'));
|
|
125
|
-
|
|
126
|
-
players[1]?.onVolumeChange(() => {
|
|
127
|
-
console.log('Video 2 was changed volume');
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
```
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
# Jetstrem player API methods
|
|
2
|
-
|
|
3
|
-
## `JetstreamPlayer` class available methods
|
|
4
|
-
|
|
5
|
-
### Next methods are available in this version of the library:
|
|
6
|
-
|
|
7
|
-
- `play()`
|
|
8
|
-
- `pause()`
|
|
9
|
-
- `seekTo()`
|
|
10
|
-
- `mute()`
|
|
11
|
-
- `unmute()`
|
|
12
|
-
- `isMuted()`
|
|
13
|
-
- `playPrevious()`
|
|
14
|
-
|
|
15
|
-
This list is not exhaustive. New methods can be added to the library as needed.
|
|
16
|
-
|
|
17
|
-
In order to use these methods, it is enough to import the `JetstreamPlayer` class and call them as described in the previous section.
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
21
|
-
|
|
22
|
-
setup() {
|
|
23
|
-
let player: JetstreamPlayer | null;
|
|
24
|
-
|
|
25
|
-
onMounted(() => {
|
|
26
|
-
player = new JetstreamPlayer('#iframe1');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const playVideo = () => {
|
|
30
|
-
player.play();
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const pauseVideo = () => {
|
|
34
|
-
player.pause();
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
playVideo,
|
|
39
|
-
pauseVideo,
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## `play()` `pause()` methods
|
|
45
|
-
|
|
46
|
-
The `play` or `pause` method can be called for a video as well as for a playlist. We are able to interact with our videos or playlists programmatically in the same way as pressing pause or play within the iframe itself.
|
|
47
|
-
|
|
48
|
-
### Pay attention ☝️⬇️
|
|
49
|
-
|
|
50
|
-
When the web page with our embedded windows is just loaded and there has been no user action _(click, play)_ and video has the `sound settings on`, the programmatic `play()` function **will not execute**!
|
|
51
|
-
|
|
52
|
-
The `play()` function will not work due to [Autoplay policy in Chrome](https://developer.chrome.com/blog/autoplay/). The same behavior occurs with services **YouTube**, **Facebook**, etc.
|
|
53
|
-
|
|
54
|
-
Modern browsers don't provide an opportunity to avoid this setting. Therefore, for the first time, an action on the user side is necessary _(click in the iframe window)_. After this action, all methods will work clearly.
|
|
55
|
-
|
|
56
|
-
If the video or playlist has **sound settings off** `(muted)`, then all methods work in normal mode.
|
|
57
|
-
|
|
58
|
-
## `mute()` method
|
|
59
|
-
Mute function set media volume to silent.
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
63
|
-
|
|
64
|
-
setup() {
|
|
65
|
-
let player: JetstreamPlayer | null;
|
|
66
|
-
|
|
67
|
-
onMounted(() => {
|
|
68
|
-
player = new JetstreamPlayer('#iframe1');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const muteVideo = () => {
|
|
72
|
-
player.mute();
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
muteVideo,
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## `unmute()` method
|
|
82
|
-
Cancel volume mute.
|
|
83
|
-
|
|
84
|
-
```js
|
|
85
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
86
|
-
|
|
87
|
-
setup() {
|
|
88
|
-
let player: JetstreamPlayer | null;
|
|
89
|
-
|
|
90
|
-
onMounted(() => {
|
|
91
|
-
player = new JetstreamPlayer('#iframe1');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const unmuteVideo = () => {
|
|
95
|
-
player.unmute();
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
unmuteVideo,
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## `isMuted()` method
|
|
105
|
-
Returns `true` if the player volume is muted, `false` if not.
|
|
106
|
-
|
|
107
|
-
```js
|
|
108
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
109
|
-
|
|
110
|
-
setup() {
|
|
111
|
-
let player: JetstreamPlayer | null;
|
|
112
|
-
|
|
113
|
-
onMounted(() => {
|
|
114
|
-
player = new JetstreamPlayer('#iframe1');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const isMutedVideo = () => {
|
|
118
|
-
player.isMuted();
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
isMutedVideo,
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## `seekTo(seconds: Number)` method
|
|
128
|
-
|
|
129
|
-
Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing), the player will play the video.
|
|
130
|
-
The function pass one parameter `seconds`.
|
|
131
|
-
|
|
132
|
-
The **seconds** parameter identifies the time to which the player should advance.
|
|
133
|
-
The player will advance to that time if the player has already downloaded the portion of the video to which the user is seeking.
|
|
134
|
-
|
|
135
|
-
The specified time must be shorter than video duration. If the user sets a time that exceeds video duration, nothing will happen.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
140
|
-
|
|
141
|
-
setup() {
|
|
142
|
-
let player: JetstreamPlayer | null;
|
|
143
|
-
|
|
144
|
-
onMounted(() => {
|
|
145
|
-
player = new JetstreamPlayer('#iframe1');
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const seekTo = () => {
|
|
149
|
-
player.seekTo(45); // Set time on 45 second
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
seekTo
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## `playNext()` `playPrevious()` methods
|
|
159
|
-
|
|
160
|
-
The `playNext` or `playPrevious` method can be called only for a **playlist**. Calling these methods for a simple video will do nothing.
|
|
161
|
-
We are able to interact with playlist programmatically in the same way as pressing `playNext` or `playPrevious` within the playlist itself.
|
|
162
|
-
|
|
163
|
-
```js
|
|
164
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
165
|
-
|
|
166
|
-
setup() {
|
|
167
|
-
let playlistPlayer: JetstreamPlayer | null;
|
|
168
|
-
|
|
169
|
-
onMounted(() => {
|
|
170
|
-
playlistPlayer = new JetstreamPlayer('#iframe1');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const playNextVideo = () => {
|
|
174
|
-
playlistPlayer.playNext();
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const playPreviousVideo = () => {
|
|
178
|
-
playlistPlayer.playPrevious();
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
return {
|
|
182
|
-
playNextVideo,
|
|
183
|
-
playPreviousVideo,
|
|
184
|
-
};
|
|
185
|
-
}.
|
|
186
|
-
```
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# Using multiple iframes
|
|
2
|
-
|
|
3
|
-
## Two ways to use and assign a player for an iframe.
|
|
4
|
-
|
|
5
|
-
We can embed one or more windows with our player on web page. If the iframe is one, then the use is very simple. As shown in the previous chapter, this can be done as follows
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
9
|
-
|
|
10
|
-
setup() {
|
|
11
|
-
let player: JetstreamPlayer | null;
|
|
12
|
-
|
|
13
|
-
onMounted(() => {
|
|
14
|
-
player = new JetstreamPlayer('#iframe1');
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const playVideo = () => {
|
|
18
|
-
player.play();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const pauseVideo = () => {
|
|
22
|
-
player.pause();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
playVideo,
|
|
27
|
-
pauseVideo,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
If we have many iframes, there is no need to create a separate variable for each player.
|
|
33
|
-
#### Example of non-recommended use ⬇️
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
37
|
-
|
|
38
|
-
setup() {
|
|
39
|
-
let firstPlayer: JetstreamPlayer | null;
|
|
40
|
-
let secondPlayer: JetstreamPlayer | null;
|
|
41
|
-
|
|
42
|
-
onMounted(() => {
|
|
43
|
-
firstPlayer = new JetstreamPlayer('#iframe1');
|
|
44
|
-
secondPlayer = new JetstreamPlayer('#iframe2');
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const playVideo = () => {
|
|
48
|
-
firstPlayer.play();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const pauseVideo = () => {
|
|
52
|
-
secondPlayer.pause();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
playVideo,
|
|
57
|
-
pauseVideo,
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Recommended method
|
|
63
|
-
|
|
64
|
-
Instead, we can use a simpler method. We can grab all players into an `array`.
|
|
65
|
-
|
|
66
|
-
All we need is to create an empty array `const players = [];` and push each player there.
|
|
67
|
-
|
|
68
|
-
### Example
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
|
|
72
|
-
|
|
73
|
-
setup() {
|
|
74
|
-
const players = [];
|
|
75
|
-
|
|
76
|
-
onMounted(() => {
|
|
77
|
-
players.push(new JetstreamPlayer('#iframe1'));
|
|
78
|
-
players.push(new JetstreamPlayer('#iframe2'));
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const playEmbedVideo = (index) => {
|
|
82
|
-
players[index]?.play();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const pauseEmbedVideo = (index) => {
|
|
86
|
-
players[index]?.pause();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
playEmbedVideo,
|
|
91
|
-
pauseEmbedVideo,
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Now we can `play` and `stop` a video or playlist from an array by specifying an `index`.
|
|
97
|
-
|
|
98
|
-
We used the same method in the [Stackblitz](https://stackblitz.com/edit/hcc-jetstream-player-demo?file=src%2Fcomponents%2FVideoSandbox.vue) sandbox.
|
package/prettier.config.mjs
DELETED
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"strict": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"moduleResolution": "Bundler",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"outDir": "./dist"
|
|
11
|
-
},
|
|
12
|
-
"exclude": ["node_modules"],
|
|
13
|
-
"include": ["src/**/*.ts"]
|
|
14
|
-
}
|