@hopecloud/jetstream-player 1.0.28 → 1.1.1
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/README.md +1 -0
- package/dist/{iframe-builder-src.d.ts → @types/iframe-builder-src.d.ts} +1 -2
- package/dist/{iframe-builder.d.ts → @types/iframe-builder.d.ts} +1 -2
- package/dist/{iframe-pip-plugin.d.ts → @types/iframe-pip-plugin.d.ts} +0 -1
- package/dist/{index.d.ts → @types/index.d.ts} +0 -1
- package/dist/{player.d.ts → @types/player.d.ts} +1 -2
- package/dist/{player.type.d.ts → @types/player.type.d.ts} +0 -1
- package/dist/{utils.d.ts → @types/utils.d.ts} +0 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -0
- package/package.json +26 -20
- package/dist/iframe-builder-src.d.ts.map +0 -1
- package/dist/iframe-builder-src.js +0 -42
- package/dist/iframe-builder.d.ts.map +0 -1
- package/dist/iframe-builder.js +0 -28
- package/dist/iframe-pip-plugin.d.ts.map +0 -1
- package/dist/iframe-pip-plugin.js +0 -40
- package/dist/index.d.ts.map +0 -1
- package/dist/main.css +0 -7
- package/dist/player.d.ts.map +0 -1
- package/dist/player.js +0 -142
- package/dist/player.type.d.ts.map +0 -1
- package/dist/player.type.js +0 -10
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -18
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Docs: https://jetstream-player.docs.hope.cloud/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IFrameBuilderSrcOpt } from './player.type';
|
|
1
|
+
import { type IFrameBuilderSrcOpt } from './player.type';
|
|
2
2
|
export declare class IFrameBuilderSrc {
|
|
3
3
|
private options;
|
|
4
4
|
origin: string;
|
|
@@ -8,4 +8,3 @@ export declare class IFrameBuilderSrc {
|
|
|
8
8
|
appendPath(path: string, builtUrl: string): string;
|
|
9
9
|
buildSrc(): string;
|
|
10
10
|
}
|
|
11
|
-
//# sourceMappingURL=iframe-builder-src.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IFrameBuilderOpt } from './player.type';
|
|
1
|
+
import { type IFrameBuilderOpt } from './player.type';
|
|
2
2
|
export declare class IFrameBuilder {
|
|
3
3
|
options: IFrameBuilderOpt;
|
|
4
4
|
iframe: HTMLIFrameElement | null;
|
|
@@ -6,4 +6,3 @@ export declare class IFrameBuilder {
|
|
|
6
6
|
private generateIframe;
|
|
7
7
|
insertIframe(iframe: HTMLIFrameElement): void;
|
|
8
8
|
}
|
|
9
|
-
//# sourceMappingURL=iframe-builder.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JetstreamPlayerOptions } from './player.type';
|
|
1
|
+
import type { JetstreamPlayerOptions } from './player.type';
|
|
2
2
|
export declare class JetstreamPlayer {
|
|
3
3
|
private iframe;
|
|
4
4
|
private options;
|
|
@@ -23,4 +23,3 @@ export declare class JetstreamPlayer {
|
|
|
23
23
|
getDuration(): Promise<number>;
|
|
24
24
|
dispose(): void;
|
|
25
25
|
}
|
|
26
|
-
//# sourceMappingURL=player.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare const normalizeEventData: <T = unknown>(event: MessageEvent<string>) => T;
|
|
2
2
|
export declare const denormalizeEventData: <T = unknown>(data: T) => string;
|
|
3
3
|
export declare const isValidEventData: (rawData: string) => boolean;
|
|
4
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export * from './utils';
|
|
1
|
+
const e=["ready","timeupdate","play","pause","loadedmetadata","ended","volumechange","error"];class t{options;iframe=null;constructor(e){this.options=e,this.iframe=this.generateIframe()}generateIframe(){const e=document.createElement("iframe");return e.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",e.allowFullscreen=!0,e.frameBorder="0",e.src=this.options.src,e.width=this.options.width||"480px",e.height=this.options.height||"270px",e.classList.add("jet-stream-iframe-player"),e}insertIframe(e){const t=document.querySelector(this.options.selector);t?t.appendChild(e):console.error(`Div with id "${this.options.selector}" not found.`)}}class i{options;origin="https://jstre.am";baseURL=new URL(this.origin);constructor(e){if(""===e.mediaId)throw new Error("mediaId not provided!");this.options=e}getRegionBasedOrigin(){const e=this.baseURL,t=e.hostname.split(".");return this.options.region&&"eu"===this.options.region&&(t.length>2?t.splice(1,0,"eu"):t.splice(0,0,"eu")),e.hostname=t.join("."),e.origin}appendPath(e,t){const i=String(e).trim();return 0===i.indexOf("/")?t+=i:t+=`/${i}`,t}buildSrc(){const e=new URL(`${this.getRegionBasedOrigin()}/embed/${this.options.mediaId}`);return this.options.playerId&&(e.href=this.appendPath(this.options.playerId,e.href)),"eu"===this.options.region&&e.searchParams.append("region","eu"),e.href}}const s="fixed",r="20px",n="20px",o="330px",a="180px";class h{containerSelector;iframe;observer=null;constructor(e,t){this.containerSelector=e,this.iframe=t,this.containerSelector=e,this.iframe=t,this.init()}init(){if(!this.iframe||!this.containerSelector)return;const e=document.querySelector(this.containerSelector);if(!e)throw new Error("Selector of iframe not found");this.observer=new IntersectionObserver((([{isIntersecting:t}])=>{if(t)e.style.height="auto",this.iframe.removeAttribute("style");else{const t=e.getBoundingClientRect().height;e.style.height=`${t}px`,this.iframe.style.position=s,this.iframe.style.bottom=r,this.iframe.style.right=n,this.iframe.style.width=o,this.iframe.style.height=a}}),{root:null,rootMargin:"0px",threshold:.1}),this.observer.observe(e)}destory(){this.observer&&(this.observer.disconnect(),this.observer=null)}}const d=e=>JSON.parse(e.data),c=e=>JSON.stringify(e),p=e=>{if("string"!=typeof e)return!1;try{return JSON.parse(e),!0}catch(e){return console.log("Error parsing JSON",e),!1}};class m{iframe=null;options;registeredEvents={};iFramePiP=null;constructor(e,s){this.options=s;const r=new i({mediaId:s.mediaId,playerId:s.playerId,region:s.region}).buildSrc(),n=new t({selector:e,src:r,width:this.options.width,height:this.options.height});this.iframe=n.iframe,this.iframe&&(n.insertIframe(this.iframe),this.iframe.addEventListener("load",(()=>{this.registerEvents(),this.subscribeToRegisteredEvents()}),{once:!0}),void 0!==this.options.sticky&&this.options.sticky&&(this.iFramePiP=new h(e,this.iframe)))}registerEvents(){!this.options.events||this.options.events&&Object.keys(this.options.events).length<0||Object.entries(this.options.events).forEach((([e,t])=>{e in this.registeredEvents||(this.registeredEvents[e]=t)}))}subscribeEventHandler(e){if(e.source!==this.iframe.contentWindow)return;const t=d(e),i=t.type;i in this.registeredEvents&&this.registeredEvents[i](t.value)}subscribeToRegisteredEvents(){window.addEventListener("message",this.subscribeEventHandler.bind(this))}dispatch(e){if(!this.iframe||!this.iframe.contentWindow)throw new Error("iframe is not provided or parent window not found!");this.iframe.contentWindow.postMessage(c(e),"*")}getterDispatch(e){return new Promise((t=>{this.dispatch(e),window.addEventListener("message",(i=>{const s=d(i);s.type===e.name&&t(s.value)}),{once:!0})}))}play(){this.dispatch({name:"play"})}pause(){this.dispatch({name:"pause"})}mute(){this.dispatch({name:"mute"})}unmute(){this.dispatch({name:"unmute"})}seekTo(e){this.dispatch({name:"seekTo",params:e})}playNext(){this.dispatch({name:"play-next"})}playPrev(){this.dispatch({name:"play-prev"})}isMuted(){return this.getterDispatch({name:"is-muted"})}isPaused(){return this.getterDispatch({name:"is-paused"})}getVideoCurrentTime(){return this.getterDispatch({name:"get-video-current-time"})}getDuration(){return this.getterDispatch({name:"get-duration"})}dispose(){window.removeEventListener("message",this.subscribeEventHandler.bind(this)),this.registeredEvents={},this.iFramePiP?.destory()}}export{m as JetstreamPlayer,c as denormalizeEventData,p as isValidEventData,d as normalizeEventData,e as playerListenEvents};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hopecloud/jetstream-player",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Jetstream Embed Player API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -9,20 +9,17 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "
|
|
12
|
+
"url": "https://github.com/deeepvision/hcc-jetstream-player.git"
|
|
13
13
|
},
|
|
14
|
-
"source": "src/index.ts",
|
|
15
14
|
"main": "dist/index.js",
|
|
16
|
-
"
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"types": "dist/@types/index.d.ts",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"import": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
20
|
+
"types": "./dist/@types/index.d.ts",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
22
|
}
|
|
23
|
-
},
|
|
24
|
-
"./dist/main.css": {
|
|
25
|
-
"import": "./dist/main.css"
|
|
26
23
|
}
|
|
27
24
|
},
|
|
28
25
|
"files": [
|
|
@@ -30,25 +27,34 @@
|
|
|
30
27
|
],
|
|
31
28
|
"scripts": {
|
|
32
29
|
"clean": "rimraf dist/",
|
|
33
|
-
"
|
|
34
|
-
"build": "npm run clean && tsc && npm run copy-files",
|
|
30
|
+
"build": "npm run clean && rollup -c",
|
|
35
31
|
"pack": "npm run build && npm pack",
|
|
32
|
+
"publish:patch": "npm version patch -m \"release: %s\"",
|
|
33
|
+
"publish:minor": "npm version minor -m \"release: %s\"",
|
|
34
|
+
"postpublish:patch": "git push origin && git push origin --tags",
|
|
35
|
+
"postpublish:minor": "git push origin && git push origin --tags",
|
|
36
36
|
"docs:dev": "vitepress dev docs",
|
|
37
37
|
"docs:build": "vitepress build docs",
|
|
38
38
|
"docs:preview": "vitepress preview docs",
|
|
39
|
-
"lint": "eslint
|
|
40
|
-
"lint:fix": "eslint
|
|
41
|
-
"
|
|
39
|
+
"lint": "eslint",
|
|
40
|
+
"lint:fix": "eslint --fix",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
44
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
45
|
+
"@eslint/js": "^9.17.0",
|
|
46
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.19.1",
|
|
46
49
|
"copyfiles": "^2.4.1",
|
|
47
|
-
"eslint": "^
|
|
50
|
+
"eslint": "^9.17.0",
|
|
48
51
|
"eslint-config-prettier": "^9.1.0",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
52
|
+
"globals": "^15.14.0",
|
|
53
|
+
"prettier": "3.4.2",
|
|
54
|
+
"rimraf": "^6.0.1",
|
|
55
|
+
"rollup": "^4.30.1",
|
|
56
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
57
|
+
"typescript": "^5.7.3",
|
|
58
|
+
"vitepress": "1.5.0"
|
|
53
59
|
}
|
|
54
60
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iframe-builder-src.d.ts","sourceRoot":"","sources":["../src/iframe-builder-src.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAsB;IAErC,MAAM,SAAsB;IAE5B,OAAO,MAAwB;gBAEnB,OAAO,EAAE,mBAAmB;IAQxC,oBAAoB;IAiBpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAYzC,QAAQ;CAaT"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export class IFrameBuilderSrc {
|
|
2
|
-
constructor(options) {
|
|
3
|
-
this.origin = 'https://jstre.am';
|
|
4
|
-
this.baseURL = new URL(this.origin);
|
|
5
|
-
if (options.mediaId === '') {
|
|
6
|
-
throw new Error('mediaId not provided!');
|
|
7
|
-
}
|
|
8
|
-
this.options = options;
|
|
9
|
-
}
|
|
10
|
-
getRegionBasedOrigin() {
|
|
11
|
-
const url = this.baseURL;
|
|
12
|
-
const urlParts = url.hostname.split('.');
|
|
13
|
-
if (this.options.region && this.options.region === 'eu') {
|
|
14
|
-
if (urlParts.length > 2) {
|
|
15
|
-
urlParts.splice(1, 0, 'eu');
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
urlParts.splice(0, 0, 'eu');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
url.hostname = urlParts.join('.');
|
|
22
|
-
return url.origin;
|
|
23
|
-
}
|
|
24
|
-
appendPath(path, builtUrl) {
|
|
25
|
-
const pathString = String(path).trim();
|
|
26
|
-
if (pathString.indexOf('/') === 0) {
|
|
27
|
-
builtUrl += pathString;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
builtUrl += `/${pathString}`;
|
|
31
|
-
}
|
|
32
|
-
return builtUrl;
|
|
33
|
-
}
|
|
34
|
-
buildSrc() {
|
|
35
|
-
const url = new URL(`${this.getRegionBasedOrigin()}/embed/${this.options.mediaId}`);
|
|
36
|
-
if (this.options.playerId) {
|
|
37
|
-
url.href = this.appendPath(this.options.playerId, url.href);
|
|
38
|
-
}
|
|
39
|
-
this.options.region === 'eu' && url.searchParams.append('region', 'eu');
|
|
40
|
-
return url.href;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iframe-builder.d.ts","sourceRoot":"","sources":["../src/iframe-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,qBAAa,aAAa;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAQ;gBAE5B,OAAO,EAAE,gBAAgB;IAMrC,OAAO,CAAC,cAAc;IAgBtB,YAAY,CAAC,MAAM,EAAE,iBAAiB;CASvC"}
|
package/dist/iframe-builder.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class IFrameBuilder {
|
|
2
|
-
constructor(options) {
|
|
3
|
-
this.iframe = null;
|
|
4
|
-
this.options = options;
|
|
5
|
-
this.iframe = this.generateIframe();
|
|
6
|
-
}
|
|
7
|
-
generateIframe() {
|
|
8
|
-
const iframe = document.createElement('iframe');
|
|
9
|
-
iframe.allow =
|
|
10
|
-
'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
|
|
11
|
-
iframe.allowFullscreen = true;
|
|
12
|
-
iframe.frameBorder = '0';
|
|
13
|
-
iframe.src = this.options.src;
|
|
14
|
-
iframe.width = this.options.width || '480px';
|
|
15
|
-
iframe.height = this.options.height || '270px';
|
|
16
|
-
iframe.classList.add('jet-stream-iframe-player');
|
|
17
|
-
return iframe;
|
|
18
|
-
}
|
|
19
|
-
insertIframe(iframe) {
|
|
20
|
-
const parent = document.querySelector(this.options.selector);
|
|
21
|
-
if (parent) {
|
|
22
|
-
parent.appendChild(iframe);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
console.error(`Div with id "${this.options.selector}" not found.`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iframe-pip-plugin.d.ts","sourceRoot":"","sources":["../src/iframe-pip-plugin.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAe;IAIjB,iBAAiB,EAAE,MAAM;IACzB,MAAM,EAAE,iBAAiB;IAJlC,OAAO,CAAC,QAAQ,CAAqC;gBAG5C,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,iBAAiB;IAQlC,IAAI;IAmCJ,OAAO;CAMR"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export class IFramePiPPlugin {
|
|
2
|
-
constructor(containerSelector, iframe) {
|
|
3
|
-
this.containerSelector = containerSelector;
|
|
4
|
-
this.iframe = iframe;
|
|
5
|
-
this.observer = null;
|
|
6
|
-
this.containerSelector = containerSelector;
|
|
7
|
-
this.iframe = iframe;
|
|
8
|
-
this.init();
|
|
9
|
-
}
|
|
10
|
-
init() {
|
|
11
|
-
if (!this.iframe || !this.containerSelector)
|
|
12
|
-
return;
|
|
13
|
-
const parent = document.querySelector(this.containerSelector);
|
|
14
|
-
if (!parent) {
|
|
15
|
-
throw new Error('Selector of iframe not found');
|
|
16
|
-
}
|
|
17
|
-
this.observer = new IntersectionObserver(([{ isIntersecting }]) => {
|
|
18
|
-
if (!isIntersecting) {
|
|
19
|
-
const height = parent.getBoundingClientRect().height;
|
|
20
|
-
parent.style.height = `${height}px`;
|
|
21
|
-
this.iframe.classList.add('pip-active');
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
parent.style.height = 'auto';
|
|
25
|
-
this.iframe.classList.remove('pip-active');
|
|
26
|
-
}
|
|
27
|
-
}, {
|
|
28
|
-
root: null,
|
|
29
|
-
rootMargin: '0px',
|
|
30
|
-
threshold: 0.1,
|
|
31
|
-
});
|
|
32
|
-
this.observer.observe(parent);
|
|
33
|
-
}
|
|
34
|
-
destory() {
|
|
35
|
-
if (this.observer) {
|
|
36
|
-
this.observer.disconnect();
|
|
37
|
-
this.observer = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
package/dist/main.css
DELETED
package/dist/player.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,sBAAsB,EAGvB,MAAM,eAAe,CAAC;AAGvB,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,gBAAgB,CAAwC;IAEhE,OAAO,CAAC,SAAS,CAAqD;gBAE1D,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB;IAsCvD,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,cAAc;IAoBtB,IAAI;IAMJ,KAAK;IAML,IAAI;IAMJ,MAAM;IAMN,MAAM,CAAC,OAAO,EAAE,MAAM;IAOtB,QAAQ;IAMR,QAAQ;IAMR,OAAO;IAMP,QAAQ;IAMR,mBAAmB;IAMnB,WAAW;IAMX,OAAO;CAUR"}
|
package/dist/player.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { IFrameBuilder } from './iframe-builder';
|
|
2
|
-
import { IFrameBuilderSrc } from './iframe-builder-src';
|
|
3
|
-
import { IFramePiPPlugin } from './iframe-pip-plugin';
|
|
4
|
-
import { denormalizeEventData, normalizeEventData } from './utils';
|
|
5
|
-
export class JetstreamPlayer {
|
|
6
|
-
constructor(el, options) {
|
|
7
|
-
this.iframe = null;
|
|
8
|
-
this.registeredEvents = {};
|
|
9
|
-
this.iFramePiP = null;
|
|
10
|
-
this.options = options;
|
|
11
|
-
const sourceBuilder = new IFrameBuilderSrc({
|
|
12
|
-
mediaId: options.mediaId,
|
|
13
|
-
playerId: options.playerId,
|
|
14
|
-
region: options.region,
|
|
15
|
-
});
|
|
16
|
-
const src = sourceBuilder.buildSrc();
|
|
17
|
-
const iframeBuilder = new IFrameBuilder({
|
|
18
|
-
selector: el,
|
|
19
|
-
src: src,
|
|
20
|
-
width: this.options.width,
|
|
21
|
-
height: this.options.height,
|
|
22
|
-
});
|
|
23
|
-
this.iframe = iframeBuilder.iframe;
|
|
24
|
-
if (this.iframe) {
|
|
25
|
-
iframeBuilder.insertIframe(this.iframe);
|
|
26
|
-
this.iframe.addEventListener('load', () => {
|
|
27
|
-
this.registerEvents();
|
|
28
|
-
this.subscribeToRegisteredEvents();
|
|
29
|
-
}, {
|
|
30
|
-
once: true,
|
|
31
|
-
});
|
|
32
|
-
if (typeof this.options.sticky !== 'undefined' && this.options.sticky) {
|
|
33
|
-
this.iFramePiP = new IFramePiPPlugin(el, this.iframe);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
registerEvents() {
|
|
38
|
-
if (!this.options.events ||
|
|
39
|
-
(this.options.events && Object.keys(this.options.events).length < 0)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
Object.entries(this.options.events).forEach(([eventName, cb]) => {
|
|
43
|
-
if (!(eventName in this.registeredEvents)) {
|
|
44
|
-
this.registeredEvents[eventName] = cb;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
subscribeEventHandler(event) {
|
|
49
|
-
if (event.source !== this.iframe.contentWindow) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const data = normalizeEventData(event);
|
|
53
|
-
const eventType = data.type;
|
|
54
|
-
if (eventType in this.registeredEvents) {
|
|
55
|
-
this.registeredEvents[eventType](data.value);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
subscribeToRegisteredEvents() {
|
|
59
|
-
window.addEventListener('message', this.subscribeEventHandler.bind(this));
|
|
60
|
-
}
|
|
61
|
-
dispatch(event) {
|
|
62
|
-
if (!this.iframe || !this.iframe.contentWindow) {
|
|
63
|
-
throw new Error('iframe is not provided or parent window not found!');
|
|
64
|
-
}
|
|
65
|
-
this.iframe.contentWindow.postMessage(denormalizeEventData(event), '*');
|
|
66
|
-
}
|
|
67
|
-
getterDispatch(getterEvent) {
|
|
68
|
-
return new Promise((resolve) => {
|
|
69
|
-
this.dispatch(getterEvent);
|
|
70
|
-
window.addEventListener('message', (event) => {
|
|
71
|
-
const data = normalizeEventData(event);
|
|
72
|
-
if (data.type === getterEvent.name) {
|
|
73
|
-
resolve(data.value);
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
once: true,
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
play() {
|
|
81
|
-
this.dispatch({
|
|
82
|
-
name: 'play',
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
pause() {
|
|
86
|
-
this.dispatch({
|
|
87
|
-
name: 'pause',
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
mute() {
|
|
91
|
-
this.dispatch({
|
|
92
|
-
name: 'mute',
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
unmute() {
|
|
96
|
-
this.dispatch({
|
|
97
|
-
name: 'unmute',
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
seekTo(seconds) {
|
|
101
|
-
this.dispatch({
|
|
102
|
-
name: 'seekTo',
|
|
103
|
-
params: seconds,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
playNext() {
|
|
107
|
-
this.dispatch({
|
|
108
|
-
name: 'play-next',
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
playPrev() {
|
|
112
|
-
this.dispatch({
|
|
113
|
-
name: 'play-prev',
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
isMuted() {
|
|
117
|
-
return this.getterDispatch({
|
|
118
|
-
name: 'is-muted',
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
isPaused() {
|
|
122
|
-
return this.getterDispatch({
|
|
123
|
-
name: 'is-paused',
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
getVideoCurrentTime() {
|
|
127
|
-
return this.getterDispatch({
|
|
128
|
-
name: 'get-video-current-time',
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
getDuration() {
|
|
132
|
-
return this.getterDispatch({
|
|
133
|
-
name: 'get-duration',
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
dispose() {
|
|
137
|
-
var _a;
|
|
138
|
-
window.removeEventListener('message', this.subscribeEventHandler.bind(this));
|
|
139
|
-
this.registeredEvents = {};
|
|
140
|
-
(_a = this.iFramePiP) === null || _a === void 0 ? void 0 : _a.destory();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"player.type.d.ts","sourceRoot":"","sources":["../src/player.type.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,uGASrB,CAAC;AACX,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,YAAY,GACZ,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,OAAO,GACP,cAAc,GACd,OAAO,CAAC;AACZ,MAAM,MAAM,kBAAkB,GAC1B,UAAU,GACV,wBAAwB,GACxB,cAAc,GACd,WAAW,CAAC;AAChB,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,YAAY,GAAG,kBAAkB,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,WAAW,CAAC;AAChB,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,CAAC;IAC9C,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC;CACnE,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,KAAK,CAAC,GAC5C,mBAAmB,CAAC"}
|
package/dist/player.type.js
DELETED
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,uBACtB,aAAa,MAAM,CAAC,MAG5B,CAAC;AAEF,eAAO,MAAM,oBAAoB,sBAAuB,CAAC,WAExD,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,MAAM,YAW/C,CAAC"}
|
package/dist/utils.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const normalizeEventData = (event) => {
|
|
2
|
-
return JSON.parse(event.data);
|
|
3
|
-
};
|
|
4
|
-
export const denormalizeEventData = (data) => {
|
|
5
|
-
return JSON.stringify(data);
|
|
6
|
-
};
|
|
7
|
-
export const isValidEventData = (rawData) => {
|
|
8
|
-
if (typeof rawData !== 'string') {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
try {
|
|
12
|
-
JSON.parse(rawData);
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
};
|