branch-video-player-sdk 0.2.1 → 0.2.2
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.js +10 -10
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,14 +20,14 @@ const w = "/branch-video-runtime/player.html", h = (e) => /^\d+$/.test(e) && Num
|
|
|
20
20
|
if (t === -1) return E(e);
|
|
21
21
|
const n = e.slice(0, t);
|
|
22
22
|
return E(n) && !n.includes(":") && h(e.slice(t + 1));
|
|
23
|
-
},
|
|
23
|
+
}, U = (e) => {
|
|
24
24
|
const t = /^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);
|
|
25
25
|
return !t || !V(t[2]) ? null : { authority: t[2], suffix: t[3] || "" };
|
|
26
|
-
}, W = (e) =>
|
|
26
|
+
}, W = (e) => U(e) !== null, _ = (e, t) => {
|
|
27
27
|
if (!W(t) || e === "runtimeUrl" && t.includes("#")) throw new TypeError(`${e} must be an absolute HTTP(S) URL`);
|
|
28
28
|
return t;
|
|
29
29
|
}, $ = (e) => {
|
|
30
|
-
const t =
|
|
30
|
+
const t = U(e);
|
|
31
31
|
if (!t || t.suffix && t.suffix !== "/") throw new TypeError("parentOrigin must be an HTTP(S) origin");
|
|
32
32
|
return e.endsWith("/") ? e.slice(0, -1) : e;
|
|
33
33
|
};
|
|
@@ -51,15 +51,15 @@ const O = {
|
|
|
51
51
|
WPS_EVT_BUFFER_CHANGE: "bufferchange",
|
|
52
52
|
WPS_EVT_MILESTONE: "milestone",
|
|
53
53
|
WPS_EVT_EXIT_REQUESTED: "exitrequested"
|
|
54
|
-
},
|
|
54
|
+
}, R = (e) => {
|
|
55
55
|
if (typeof e != "string") return e;
|
|
56
56
|
const t = document.querySelector(e);
|
|
57
57
|
if (!t) throw new Error(`BranchVideo player container not found: ${e}`);
|
|
58
58
|
return t;
|
|
59
59
|
};
|
|
60
|
-
function
|
|
61
|
-
const t = e.parentOrigin ?? window.location.origin, n = e.runtimeUrl || w, i = b({ ...e, parentOrigin: t, runtimeUrl: n }), o = new URL(n
|
|
62
|
-
r.src = i, r.allow = "autoplay; fullscreen", r.title = e.title || "BranchVideo player", e.className && (r.className = e.className),
|
|
60
|
+
function y(e) {
|
|
61
|
+
const t = e.parentOrigin ?? window.location.origin, n = new URL(e.runtimeUrl || w, window.location.href).href, i = b({ ...e, parentOrigin: t, runtimeUrl: n }), o = new URL(n).origin, r = document.createElement("iframe");
|
|
62
|
+
r.src = i, r.allow = "autoplay; fullscreen", r.title = e.title || "BranchVideo player", e.className && (r.className = e.className), R(e.container).appendChild(r);
|
|
63
63
|
const f = /* @__PURE__ */ new Map(), d = [];
|
|
64
64
|
let l = "pending", u = !1;
|
|
65
65
|
const m = (s, c) => {
|
|
@@ -70,7 +70,7 @@ function N(e) {
|
|
|
70
70
|
}
|
|
71
71
|
l !== "failed" && r.contentWindow?.postMessage({ eventName: s, data: c, timestamp: Date.now() }, o);
|
|
72
72
|
}
|
|
73
|
-
},
|
|
73
|
+
}, S = () => {
|
|
74
74
|
for (; d.length; ) {
|
|
75
75
|
const s = d.shift();
|
|
76
76
|
r.contentWindow?.postMessage({ ...s, timestamp: Date.now() }, o);
|
|
@@ -87,7 +87,7 @@ function N(e) {
|
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
if (l !== "pending") return;
|
|
90
|
-
l = "ready",
|
|
90
|
+
l = "ready", S();
|
|
91
91
|
}
|
|
92
92
|
a === "error" && l === "pending" && (l = "failed", d.length = 0), f.get(a)?.forEach((g) => g(c.data));
|
|
93
93
|
}
|
|
@@ -111,5 +111,5 @@ function N(e) {
|
|
|
111
111
|
export {
|
|
112
112
|
w as DEFAULT_RUNTIME_PATH,
|
|
113
113
|
b as buildBranchVideoPlayerUrl,
|
|
114
|
-
|
|
114
|
+
y as createBranchVideoPlayer
|
|
115
115
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.BranchVideoPlayerSDK={}))})(this,(function(l){"use strict";const f="/branch-video-runtime/player.html",h=e=>/^\d+$/.test(e)&&Number(e)>0&&Number(e)<=65535,w=e=>{const n=e.split(".");return n.length===4&&n.every(t=>/^\d+$/.test(t)&&Number(t)<=255)},V=e=>{if(!/^[0-9a-f:]+$/i.test(e))return!1;const n=e.split("::");if(n.length>2)return!1;const t=n.flatMap(i=>i?i.split(":"):[]);return t.every(i=>/^[0-9a-f]{1,4}$/i.test(i))?n.length===2?t.length<8:t.length===8:!1},E=e=>{const n=e.endsWith(".")?e.slice(0,-1):e;return/^[\d.]+$/.test(n)?w(n):!!n&&!n.includes("..")&&n.split(".").every(t=>/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(t))},y=e=>{if(!e||e.includes("@"))return!1;if(e.startsWith("[")){const i=e.indexOf("]"),o=e.slice(1,i),r=e.slice(i+1);return i<=1||!V(o)?!1:!r||r.startsWith(":")&&h(r.slice(1))}const n=e.lastIndexOf(":");if(n===-1)return E(e);const t=e.slice(0,n);return E(t)&&!t.includes(":")&&h(e.slice(n+1))},_=e=>{const n=/^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);return!n||!y(n[2])?null:{authority:n[2],suffix:n[3]||""}},b=e=>_(e)!==null,T=(e,n)=>{if(!b(n)||e==="runtimeUrl"&&n.includes("#"))throw new TypeError(`${e} must be an absolute HTTP(S) URL`);return n},W=e=>{const n=_(e);if(!n||n.suffix&&n.suffix!=="/")throw new TypeError("parentOrigin must be an HTTP(S) origin");return e.endsWith("/")?e.slice(0,-1):e};function P(e){const n=e.runtimeUrl?T("runtimeUrl",e.runtimeUrl):f,t=T("scriptUrl",e.scriptUrl),i=e.parentOrigin===void 0?void 0:W(e.parentOrigin),o=[`script=${encodeURIComponent(t)}`,"embedPlatform=web_player_sdk","sdkProtocol=1"];i&&o.push(`parentOrigin=${encodeURIComponent(i)}`),e.cshost&&o.push(`cshost=${encodeURIComponent(e.cshost)}`),e.controls!==void 0&&o.push(`controls=${e.controls}`),e.debug!==void 0&&o.push(`debug=${e.debug}`);const r=n.includes("?")?"&":"?";return`${n}${r}${o.join("&")}`}const $={WPS_EVT_LOADED:"loaded",WPS_EVT_READY:"ready",WPS_EVT_STATE_CHANGE:"statechange",WPS_EVT_PROGRESS:"progress",WPS_EVT_ENDED:"ended",WPS_EVT_ERROR:"error",WPS_EVT_BUFFER_CHANGE:"bufferchange",WPS_EVT_MILESTONE:"milestone",WPS_EVT_EXIT_REQUESTED:"exitrequested"},O=e=>{if(typeof e!="string")return e;const n=document.querySelector(e);if(!n)throw new Error(`BranchVideo player container not found: ${e}`);return n};function
|
|
1
|
+
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.BranchVideoPlayerSDK={}))})(this,(function(l){"use strict";const f="/branch-video-runtime/player.html",h=e=>/^\d+$/.test(e)&&Number(e)>0&&Number(e)<=65535,w=e=>{const n=e.split(".");return n.length===4&&n.every(t=>/^\d+$/.test(t)&&Number(t)<=255)},V=e=>{if(!/^[0-9a-f:]+$/i.test(e))return!1;const n=e.split("::");if(n.length>2)return!1;const t=n.flatMap(i=>i?i.split(":"):[]);return t.every(i=>/^[0-9a-f]{1,4}$/i.test(i))?n.length===2?t.length<8:t.length===8:!1},E=e=>{const n=e.endsWith(".")?e.slice(0,-1):e;return/^[\d.]+$/.test(n)?w(n):!!n&&!n.includes("..")&&n.split(".").every(t=>/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(t))},y=e=>{if(!e||e.includes("@"))return!1;if(e.startsWith("[")){const i=e.indexOf("]"),o=e.slice(1,i),r=e.slice(i+1);return i<=1||!V(o)?!1:!r||r.startsWith(":")&&h(r.slice(1))}const n=e.lastIndexOf(":");if(n===-1)return E(e);const t=e.slice(0,n);return E(t)&&!t.includes(":")&&h(e.slice(n+1))},_=e=>{const n=/^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);return!n||!y(n[2])?null:{authority:n[2],suffix:n[3]||""}},b=e=>_(e)!==null,T=(e,n)=>{if(!b(n)||e==="runtimeUrl"&&n.includes("#"))throw new TypeError(`${e} must be an absolute HTTP(S) URL`);return n},W=e=>{const n=_(e);if(!n||n.suffix&&n.suffix!=="/")throw new TypeError("parentOrigin must be an HTTP(S) origin");return e.endsWith("/")?e.slice(0,-1):e};function P(e){const n=e.runtimeUrl?T("runtimeUrl",e.runtimeUrl):f,t=T("scriptUrl",e.scriptUrl),i=e.parentOrigin===void 0?void 0:W(e.parentOrigin),o=[`script=${encodeURIComponent(t)}`,"embedPlatform=web_player_sdk","sdkProtocol=1"];i&&o.push(`parentOrigin=${encodeURIComponent(i)}`),e.cshost&&o.push(`cshost=${encodeURIComponent(e.cshost)}`),e.controls!==void 0&&o.push(`controls=${e.controls}`),e.debug!==void 0&&o.push(`debug=${e.debug}`);const r=n.includes("?")?"&":"?";return`${n}${r}${o.join("&")}`}const $={WPS_EVT_LOADED:"loaded",WPS_EVT_READY:"ready",WPS_EVT_STATE_CHANGE:"statechange",WPS_EVT_PROGRESS:"progress",WPS_EVT_ENDED:"ended",WPS_EVT_ERROR:"error",WPS_EVT_BUFFER_CHANGE:"bufferchange",WPS_EVT_MILESTONE:"milestone",WPS_EVT_EXIT_REQUESTED:"exitrequested"},O=e=>{if(typeof e!="string")return e;const n=document.querySelector(e);if(!n)throw new Error(`BranchVideo player container not found: ${e}`);return n};function R(e){const n=e.parentOrigin??window.location.origin,t=new URL(e.runtimeUrl||f,window.location.href).href,i=P({...e,parentOrigin:n,runtimeUrl:t}),o=new URL(t).origin,r=document.createElement("iframe");r.src=i,r.allow="autoplay; fullscreen",r.title=e.title||"BranchVideo player",e.className&&(r.className=e.className),O(e.container).appendChild(r);const m=new Map,u=[];let a="pending",p=!1;const g=(s,c)=>{if(!p){if(a==="pending"){u.push({eventName:s,data:c});return}a!=="failed"&&r.contentWindow?.postMessage({eventName:s,data:c,timestamp:Date.now()},o)}},N=()=>{for(;u.length;){const s=u.shift();r.contentWindow?.postMessage({...s,timestamp:Date.now()},o)}},U=s=>{if(p||s.source!==r.contentWindow||s.origin!==o)return;const c=s.data;if(!c||typeof c.eventName!="string")return;const d=$[c.eventName];if(d){if(d==="ready"){if(c.data?.protocolVersion!==1){a==="pending"&&(a="failed",u.length=0);return}if(a!=="pending")return;a="ready",N()}d==="error"&&a==="pending"&&(a="failed",u.length=0),m.get(d)?.forEach(S=>S(c.data))}};return window.addEventListener("message",U),{iframe:r,play:()=>g("WPS_CMD_PLAY"),pause:()=>g("WPS_CMD_PAUSE"),seek:s=>{Number.isFinite(s)&&g("WPS_CMD_SEEK",{position:Math.max(0,s)})},on:(s,c)=>{const d=m.get(s)||new Set;return d.add(c),m.set(s,d),()=>d.delete(c)},destroy:()=>{p||(p=!0,u.length=0,m.clear(),window.removeEventListener("message",U),r.remove())}}}l.DEFAULT_RUNTIME_PATH=f,l.buildBranchVideoPlayerUrl=P,l.createBranchVideoPlayer=R,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|