branch-video-player-sdk 0.2.11 → 0.2.13
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 +13 -13
- package/dist/index.js +58 -58
- package/dist/index.umd.cjs +1 -1
- package/dist/runtime/assets/{player-Bf_D5PLO.js → player-Dv33xIOl.js} +34 -34
- package/dist/runtime/player.html +54 -5
- package/dist/url.cjs +1 -1
- package/dist/url.d.ts +1 -0
- package/dist/url.js +39 -39
- package/package.json +30 -30
package/README.md
CHANGED
|
@@ -38,16 +38,16 @@ under paths on one origin.
|
|
|
38
38
|
Subscribe with `player.on()` to `loaded`, `ready`, `statechange`, `progress`,
|
|
39
39
|
`ended`, `error`, `bufferchange`, `milestone`, and `exitrequested`. `play`,
|
|
40
40
|
`pause`, and `seek` issued before trusted `ready` are queued in order.
|
|
41
|
-
|
|
42
|
-
## Web learning observations (0.2.10+)
|
|
43
|
-
|
|
44
|
-
The Runtime can report privacy-minimized Web learning observations through the existing `milestone` event. These observations are included in 0.2.10 and later; 0.2.9 does not contain them. No new SDK event name is required.
|
|
45
|
-
|
|
46
|
-
- `schemaVersion: 1`
|
|
47
|
-
- `type: web_step_visible | web_step_message`
|
|
48
|
-
- `nodeId`, `visitId`, `contentUrl` (origin + pathname only)
|
|
49
|
-
- Status messages additionally contain `messageName` and `messageStatus`.
|
|
50
|
-
|
|
51
|
-
Visibility is observed after the Runtime's existing Web visual handoff, not simply on node change. Status messages reuse the current origin/source fence and visit deduplication. Source-less legacy calls may still route for compatibility but are never telemetry. Initial UEStatus=0 and free-text payloads are excluded. Observer exceptions cannot stop playback or alter routing.
|
|
52
|
-
|
|
53
|
-
A status observation is **not a success verdict**. The host must apply an explicit content-specific completion contract; it must not assume the same numeric UEStatus means completed, skipped or timed out for every page. No answer bodies, initData or credential query values are forwarded.
|
|
41
|
+
|
|
42
|
+
## Web learning observations (0.2.10+)
|
|
43
|
+
|
|
44
|
+
The Runtime can report privacy-minimized Web learning observations through the existing `milestone` event. These observations are included in 0.2.10 and later; 0.2.9 does not contain them. No new SDK event name is required.
|
|
45
|
+
|
|
46
|
+
- `schemaVersion: 1`
|
|
47
|
+
- `type: web_step_visible | web_step_message`
|
|
48
|
+
- `nodeId`, `visitId`, `contentUrl` (origin + pathname only)
|
|
49
|
+
- Status messages additionally contain `messageName` and `messageStatus`.
|
|
50
|
+
|
|
51
|
+
Visibility is observed after the Runtime's existing Web visual handoff, not simply on node change. Status messages reuse the current origin/source fence and visit deduplication. Source-less legacy calls may still route for compatibility but are never telemetry. Initial UEStatus=0 and free-text payloads are excluded. Observer exceptions cannot stop playback or alter routing.
|
|
52
|
+
|
|
53
|
+
A status observation is **not a success verdict**. The host must apply an explicit content-specific completion contract; it must not assume the same numeric UEStatus means completed, skipped or timed out for every page. No answer bodies, initData or credential query values are forwarded.
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
const w = "/branch-video-runtime/player.html",
|
|
2
|
-
const
|
|
3
|
-
return
|
|
1
|
+
const w = "/branch-video-runtime/player.html", E = (e) => /^\d+$/.test(e) && Number(e) > 0 && Number(e) <= 65535, P = (e) => {
|
|
2
|
+
const n = e.split(".");
|
|
3
|
+
return n.length === 4 && n.every((r) => /^\d+$/.test(r) && Number(r) <= 255);
|
|
4
4
|
}, T = (e) => {
|
|
5
5
|
if (!/^[0-9a-f:]+$/i.test(e)) return !1;
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
9
|
-
return
|
|
10
|
-
},
|
|
11
|
-
const
|
|
12
|
-
return /^[\d.]+$/.test(
|
|
6
|
+
const n = e.split("::");
|
|
7
|
+
if (n.length > 2) return !1;
|
|
8
|
+
const r = n.flatMap((i) => i ? i.split(":") : []);
|
|
9
|
+
return r.every((i) => /^[0-9a-f]{1,4}$/i.test(i)) ? n.length === 2 ? r.length < 8 : r.length === 8 : !1;
|
|
10
|
+
}, _ = (e) => {
|
|
11
|
+
const n = e.endsWith(".") ? e.slice(0, -1) : e;
|
|
12
|
+
return /^[\d.]+$/.test(n) ? P(n) : !!n && !n.includes("..") && n.split(".").every((r) => /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(r));
|
|
13
13
|
}, V = (e) => {
|
|
14
14
|
if (!e || e.includes("@")) return !1;
|
|
15
15
|
if (e.startsWith("[")) {
|
|
16
|
-
const i = e.indexOf("]"),
|
|
17
|
-
return i <= 1 || !T(
|
|
16
|
+
const i = e.indexOf("]"), c = e.slice(1, i), t = e.slice(i + 1);
|
|
17
|
+
return i <= 1 || !T(c) ? !1 : !t || t.startsWith(":") && E(t.slice(1));
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
return
|
|
19
|
+
const n = e.lastIndexOf(":");
|
|
20
|
+
if (n === -1) return _(e);
|
|
21
|
+
const r = e.slice(0, n);
|
|
22
|
+
return _(r) && !r.includes(":") && E(e.slice(n + 1));
|
|
23
23
|
}, U = (e) => {
|
|
24
|
-
const
|
|
25
|
-
return !
|
|
26
|
-
}, W = (e) => U(e) !== null,
|
|
27
|
-
if (!W(
|
|
28
|
-
return
|
|
24
|
+
const n = /^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);
|
|
25
|
+
return !n || !V(n[2]) ? null : { authority: n[2], suffix: n[3] || "" };
|
|
26
|
+
}, W = (e) => U(e) !== null, p = (e, n) => {
|
|
27
|
+
if (!W(n) || e === "runtimeUrl" && n.includes("#")) throw new TypeError(`${e} must be an absolute HTTP(S) URL`);
|
|
28
|
+
return n;
|
|
29
29
|
}, $ = (e) => {
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
30
|
+
const n = U(e);
|
|
31
|
+
if (!n || n.suffix && n.suffix !== "/") throw new TypeError("parentOrigin must be an HTTP(S) origin");
|
|
32
32
|
return e.endsWith("/") ? e.slice(0, -1) : e;
|
|
33
33
|
};
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
`script=${encodeURIComponent(
|
|
34
|
+
function R(e) {
|
|
35
|
+
const n = e.runtimeUrl ? p("runtimeUrl", e.runtimeUrl) : w, r = p("scriptUrl", e.scriptUrl), i = e.cover === void 0 ? void 0 : p("cover", e.cover), c = e.parentOrigin === void 0 ? void 0 : $(e.parentOrigin), t = [
|
|
36
|
+
`script=${encodeURIComponent(r)}`,
|
|
37
37
|
"embedPlatform=web_player_sdk",
|
|
38
38
|
"sdkProtocol=1"
|
|
39
39
|
];
|
|
40
|
-
i &&
|
|
41
|
-
const
|
|
42
|
-
return `${
|
|
40
|
+
i && t.push(`cover=${encodeURIComponent(i)}`), c && t.push(`parentOrigin=${encodeURIComponent(c)}`), e.cshost && t.push(`cshost=${encodeURIComponent(e.cshost)}`), e.controls !== void 0 && t.push(`controls=${e.controls}`), e.debug !== void 0 && t.push(`debug=${e.debug}`);
|
|
41
|
+
const d = n.includes("?") ? "&" : "?";
|
|
42
|
+
return `${n}${d}${t.join("&")}`;
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const b = {
|
|
45
45
|
WPS_EVT_LOADED: "loaded",
|
|
46
46
|
WPS_EVT_READY: "ready",
|
|
47
47
|
WPS_EVT_STATE_CHANGE: "statechange",
|
|
@@ -51,65 +51,65 @@ const O = {
|
|
|
51
51
|
WPS_EVT_BUFFER_CHANGE: "bufferchange",
|
|
52
52
|
WPS_EVT_MILESTONE: "milestone",
|
|
53
53
|
WPS_EVT_EXIT_REQUESTED: "exitrequested"
|
|
54
|
-
},
|
|
54
|
+
}, O = (e) => {
|
|
55
55
|
if (typeof e != "string") return e;
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
-
return
|
|
56
|
+
const n = document.querySelector(e);
|
|
57
|
+
if (!n) throw new Error(`BranchVideo player container not found: ${e}`);
|
|
58
|
+
return n;
|
|
59
59
|
};
|
|
60
60
|
function y(e) {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const
|
|
61
|
+
const n = e.parentOrigin ?? window.location.origin, r = new URL(e.runtimeUrl || w, window.location.href).href, i = R({ ...e, parentOrigin: n, runtimeUrl: r }), c = new URL(r).origin, t = document.createElement("iframe");
|
|
62
|
+
t.src = i, t.allow = "autoplay; fullscreen", t.title = e.title || "BranchVideo player", e.className && (t.className = e.className), O(e.container).appendChild(t);
|
|
63
|
+
const d = /* @__PURE__ */ new Map(), f = [];
|
|
64
64
|
let l = "pending", u = !1;
|
|
65
|
-
const m = (s,
|
|
65
|
+
const m = (s, o) => {
|
|
66
66
|
if (!u) {
|
|
67
67
|
if (l === "pending") {
|
|
68
|
-
|
|
68
|
+
f.push({ eventName: s, data: o });
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
l !== "failed" &&
|
|
71
|
+
l !== "failed" && t.contentWindow?.postMessage({ eventName: s, data: o, timestamp: Date.now() }, c);
|
|
72
72
|
}
|
|
73
73
|
}, S = () => {
|
|
74
|
-
for (;
|
|
75
|
-
const s =
|
|
76
|
-
|
|
74
|
+
for (; f.length; ) {
|
|
75
|
+
const s = f.shift();
|
|
76
|
+
t.contentWindow?.postMessage({ ...s, timestamp: Date.now() }, c);
|
|
77
77
|
}
|
|
78
|
-
},
|
|
79
|
-
if (u || s.source !==
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
-
const a =
|
|
78
|
+
}, g = (s) => {
|
|
79
|
+
if (u || s.source !== t.contentWindow || s.origin !== c) return;
|
|
80
|
+
const o = s.data;
|
|
81
|
+
if (!o || typeof o.eventName != "string") return;
|
|
82
|
+
const a = b[o.eventName];
|
|
83
83
|
if (a) {
|
|
84
84
|
if (a === "ready") {
|
|
85
|
-
if (
|
|
86
|
-
l === "pending" && (l = "failed",
|
|
85
|
+
if (o.data?.protocolVersion !== 1) {
|
|
86
|
+
l === "pending" && (l = "failed", f.length = 0);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
if (l !== "pending") return;
|
|
90
90
|
l = "ready", S();
|
|
91
91
|
}
|
|
92
|
-
a === "error" && l === "pending" && (l = "failed",
|
|
92
|
+
a === "error" && l === "pending" && (l = "failed", f.length = 0), d.get(a)?.forEach((h) => h(o.data));
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
-
return window.addEventListener("message",
|
|
96
|
-
iframe:
|
|
95
|
+
return window.addEventListener("message", g), {
|
|
96
|
+
iframe: t,
|
|
97
97
|
play: () => m("WPS_CMD_PLAY"),
|
|
98
98
|
pause: () => m("WPS_CMD_PAUSE"),
|
|
99
99
|
seek: (s) => {
|
|
100
100
|
Number.isFinite(s) && m("WPS_CMD_SEEK", { position: Math.max(0, s) });
|
|
101
101
|
},
|
|
102
|
-
on: (s,
|
|
103
|
-
const a =
|
|
104
|
-
return a.add(
|
|
102
|
+
on: (s, o) => {
|
|
103
|
+
const a = d.get(s) || /* @__PURE__ */ new Set();
|
|
104
|
+
return a.add(o), d.set(s, a), () => a.delete(o);
|
|
105
105
|
},
|
|
106
106
|
destroy: () => {
|
|
107
|
-
u || (u = !0,
|
|
107
|
+
u || (u = !0, f.length = 0, d.clear(), window.removeEventListener("message", g), t.remove());
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
export {
|
|
112
112
|
w as DEFAULT_RUNTIME_PATH,
|
|
113
|
-
|
|
113
|
+
R as buildBranchVideoPlayerUrl,
|
|
114
114
|
y as createBranchVideoPlayer
|
|
115
115
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c.BranchVideoPlayerSDK={}))})(this,(function(c){"use strict";const f="/branch-video-runtime/player.html",E=e=>/^\d+$/.test(e)&&Number(e)>0&&Number(e)<=65535,w=e=>{const n=e.split(".");return n.length===4&&n.every(r=>/^\d+$/.test(r)&&Number(r)<=255)},V=e=>{if(!/^[0-9a-f:]+$/i.test(e))return!1;const n=e.split("::");if(n.length>2)return!1;const r=n.flatMap(i=>i?i.split(":"):[]);return r.every(i=>/^[0-9a-f]{1,4}$/i.test(i))?n.length===2?r.length<8:r.length===8:!1},_=e=>{const n=e.endsWith(".")?e.slice(0,-1):e;return/^[\d.]+$/.test(n)?w(n):!!n&&!n.includes("..")&&n.split(".").every(r=>/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(r))},y=e=>{if(!e||e.includes("@"))return!1;if(e.startsWith("[")){const i=e.indexOf("]"),l=e.slice(1,i),t=e.slice(i+1);return i<=1||!V(l)?!1:!t||t.startsWith(":")&&E(t.slice(1))}const n=e.lastIndexOf(":");if(n===-1)return _(e);const r=e.slice(0,n);return _(r)&&!r.includes(":")&&E(e.slice(n+1))},T=e=>{const n=/^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);return!n||!y(n[2])?null:{authority:n[2],suffix:n[3]||""}},b=e=>T(e)!==null,h=(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=T(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 U(e){const n=e.runtimeUrl?h("runtimeUrl",e.runtimeUrl):f,r=h("scriptUrl",e.scriptUrl),i=e.cover===void 0?void 0:h("cover",e.cover),l=e.parentOrigin===void 0?void 0:W(e.parentOrigin),t=[`script=${encodeURIComponent(r)}`,"embedPlatform=web_player_sdk","sdkProtocol=1"];i&&t.push(`cover=${encodeURIComponent(i)}`),l&&t.push(`parentOrigin=${encodeURIComponent(l)}`),e.cshost&&t.push(`cshost=${encodeURIComponent(e.cshost)}`),e.controls!==void 0&&t.push(`controls=${e.controls}`),e.debug!==void 0&&t.push(`debug=${e.debug}`);const u=n.includes("?")?"&":"?";return`${n}${u}${t.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"},R=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 O(e){const n=e.parentOrigin??window.location.origin,r=new URL(e.runtimeUrl||f,window.location.href).href,i=U({...e,parentOrigin:n,runtimeUrl:r}),l=new URL(r).origin,t=document.createElement("iframe");t.src=i,t.allow="autoplay; fullscreen",t.title=e.title||"BranchVideo player",e.className&&(t.className=e.className),R(e.container).appendChild(t);const u=new Map,m=[];let a="pending",p=!1;const g=(s,o)=>{if(!p){if(a==="pending"){m.push({eventName:s,data:o});return}a!=="failed"&&t.contentWindow?.postMessage({eventName:s,data:o,timestamp:Date.now()},l)}},N=()=>{for(;m.length;){const s=m.shift();t.contentWindow?.postMessage({...s,timestamp:Date.now()},l)}},P=s=>{if(p||s.source!==t.contentWindow||s.origin!==l)return;const o=s.data;if(!o||typeof o.eventName!="string")return;const d=$[o.eventName];if(d){if(d==="ready"){if(o.data?.protocolVersion!==1){a==="pending"&&(a="failed",m.length=0);return}if(a!=="pending")return;a="ready",N()}d==="error"&&a==="pending"&&(a="failed",m.length=0),u.get(d)?.forEach(S=>S(o.data))}};return window.addEventListener("message",P),{iframe:t,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,o)=>{const d=u.get(s)||new Set;return d.add(o),u.set(s,d),()=>d.delete(o)},destroy:()=>{p||(p=!0,m.length=0,u.clear(),window.removeEventListener("message",P),t.remove())}}}c.DEFAULT_RUNTIME_PATH=f,c.buildBranchVideoPlayerUrl=U,c.createBranchVideoPlayer=O,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|