@banou/media-player 0.10.27 → 0.10.29
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 +66 -1
- package/dist/chapters/index.d.ts +3 -0
- package/dist/chapters/index.js +2 -0
- package/dist/chapters-EBYXcEml.js +115 -0
- package/dist/engine/index.js +1 -1
- package/dist/engine/playback.d.ts +5 -0
- package/dist/{engine-AjFLuCdA.js → engine-DeEY2qao.js} +94 -92
- package/dist/index.d.ts +1 -1
- package/dist/index.js +875 -916
- package/dist/language/index.d.ts +25 -0
- package/dist/language/index.js +75 -0
- package/dist/react/components/chrome.d.ts +4 -1
- package/dist/react/components/control-bar.d.ts +3 -1
- package/dist/react/components/tooltip-display.d.ts +2 -0
- package/dist/react/video-player.d.ts +44 -0
- package/dist/remote/index.d.ts +27 -1
- package/dist/remote/index.js +163 -139
- package/dist/remote/protocol.d.ts +16 -4
- package/package.json +9 -1
- package/src/lib/chapters/index.ts +5 -0
- package/src/lib/engine/playback.ts +18 -6
- package/src/lib/index.tsx +1 -0
- package/src/lib/language/index.ts +129 -0
- package/src/lib/react/components/chrome.tsx +12 -3
- package/src/lib/react/components/control-bar.tsx +21 -6
- package/src/lib/react/components/tooltip-display.tsx +14 -2
- package/src/lib/react/hooks/use-playback.ts +50 -17
- package/src/lib/react/video-player.tsx +94 -8
- package/src/lib/remote/index.ts +99 -18
- package/src/lib/remote/protocol.ts +16 -5
package/dist/remote/index.js
CHANGED
|
@@ -23,16 +23,16 @@ var t = [
|
|
|
23
23
|
"emptied",
|
|
24
24
|
"resize",
|
|
25
25
|
"error"
|
|
26
|
-
], n = [
|
|
26
|
+
], n = ["chapterschange", "fullscreenrequest"], r = [
|
|
27
27
|
"currentTime",
|
|
28
28
|
"volume",
|
|
29
29
|
"muted",
|
|
30
30
|
"playbackRate"
|
|
31
|
-
],
|
|
31
|
+
], i = [
|
|
32
32
|
"play",
|
|
33
33
|
"pause",
|
|
34
34
|
"load"
|
|
35
|
-
],
|
|
35
|
+
], a = "banou-media-player", o = "default", s = (e) => [
|
|
36
36
|
"loadstart",
|
|
37
37
|
...e.readyState >= 1 ? ["loadedmetadata", "durationchange"] : [],
|
|
38
38
|
...e.readyState >= 2 ? ["loadeddata"] : [],
|
|
@@ -44,14 +44,14 @@ var t = [
|
|
|
44
44
|
e.paused ? "pause" : "playing",
|
|
45
45
|
...e.ended ? ["ended"] : [],
|
|
46
46
|
...e.error ? ["error"] : []
|
|
47
|
-
],
|
|
47
|
+
], c = (e) => {
|
|
48
48
|
if (!e) return [];
|
|
49
49
|
let t = [];
|
|
50
50
|
for (let n = 0; n < e.length; n++) t.push([e.start(n), e.end(n)]);
|
|
51
51
|
return t;
|
|
52
|
-
},
|
|
53
|
-
currentTime:
|
|
54
|
-
duration:
|
|
52
|
+
}, l = (e, t = []) => ({
|
|
53
|
+
currentTime: u(e.currentTime),
|
|
54
|
+
duration: u(e.duration),
|
|
55
55
|
paused: e.paused,
|
|
56
56
|
ended: e.ended ?? !1,
|
|
57
57
|
seeking: e.seeking,
|
|
@@ -61,15 +61,16 @@ var t = [
|
|
|
61
61
|
playbackRate: e.playbackRate ?? 1,
|
|
62
62
|
src: e.src ?? "",
|
|
63
63
|
currentSrc: e.currentSrc ?? "",
|
|
64
|
-
buffered:
|
|
65
|
-
seekable:
|
|
64
|
+
buffered: c(e.buffered),
|
|
65
|
+
seekable: c(e.seekable),
|
|
66
66
|
error: e.error ? {
|
|
67
67
|
code: e.error.code,
|
|
68
68
|
message: e.error.message
|
|
69
69
|
} : null,
|
|
70
70
|
videoWidth: e.videoWidth ?? 0,
|
|
71
|
-
videoHeight: e.videoHeight ?? 0
|
|
72
|
-
|
|
71
|
+
videoHeight: e.videoHeight ?? 0,
|
|
72
|
+
chapters: t
|
|
73
|
+
}), u = (e) => Number.isNaN(e) ? 0 : e, d = {
|
|
73
74
|
currentTime: 0,
|
|
74
75
|
duration: 0,
|
|
75
76
|
paused: !0,
|
|
@@ -85,108 +86,121 @@ var t = [
|
|
|
85
86
|
seekable: [],
|
|
86
87
|
error: null,
|
|
87
88
|
videoWidth: 0,
|
|
88
|
-
videoHeight: 0
|
|
89
|
-
|
|
89
|
+
videoHeight: 0,
|
|
90
|
+
chapters: []
|
|
91
|
+
}, f = (e) => ({
|
|
90
92
|
length: e.length,
|
|
91
93
|
start: (t) => e[t]?.[0] ?? 0,
|
|
92
94
|
end: (t) => e[t]?.[1] ?? 0
|
|
93
|
-
}),
|
|
94
|
-
|
|
95
|
+
}), p = 1e4, m = 1500, h = () => new DOMException("the far player did not start playing", "NotAllowedError"), g = 8, _ = 32, v = (e, t = {}) => {
|
|
96
|
+
E(t.origin);
|
|
95
97
|
let n = typeof window < "u" && window.parent !== window;
|
|
96
|
-
return !t.transport && !n ? () => {} :
|
|
97
|
-
},
|
|
98
|
-
let
|
|
99
|
-
if (
|
|
100
|
-
let
|
|
101
|
-
|
|
98
|
+
return !t.transport && !n ? () => {} : x(t).serve(e, t);
|
|
99
|
+
}, y = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new Map(), x = (a) => {
|
|
100
|
+
let o = a.channel ?? "banou-media-player", c = a.transport, u = `${o}|${a.origin ?? "*"}`, f = c ? y.get(c) ?? (y.set(c, /* @__PURE__ */ new Map()), y.get(c)) : b, p = f.get(u);
|
|
101
|
+
if (p) return p;
|
|
102
|
+
let m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), x = (e) => v.get(e) ?? v.set(e, /* @__PURE__ */ new Set()).get(e), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), w = (e) => h.get(e)?.onHostFullscreen(S.get(e)?.size ? C.get(e) ?? !1 : null), T = (e, t) => {
|
|
103
|
+
v.get(e)?.delete(t), S.get(e)?.delete(t) && w(e);
|
|
102
104
|
try {
|
|
103
105
|
t.onmessage = null, t.close();
|
|
104
106
|
} catch {}
|
|
105
|
-
},
|
|
106
|
-
for (let r of
|
|
107
|
+
}, E = (e, t, n = x(e)) => {
|
|
108
|
+
for (let r of [...n]) try {
|
|
107
109
|
r.postMessage(t);
|
|
108
110
|
} catch {
|
|
109
|
-
|
|
111
|
+
T(e, r);
|
|
110
112
|
}
|
|
111
|
-
},
|
|
112
|
-
let t =
|
|
113
|
-
return t ?
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
}, D = (e) => {
|
|
114
|
+
let t = m.get(e);
|
|
115
|
+
return t ? l(t, h.get(e)?.chapters) : void 0;
|
|
116
|
+
}, O = (e, t) => {
|
|
117
|
+
let n = t === "fullscreenrequest" ? S.get(e) : v.get(e);
|
|
118
|
+
if (!n?.size) return;
|
|
119
|
+
let r = D(e);
|
|
120
|
+
r && E(e, {
|
|
118
121
|
event: t,
|
|
119
|
-
snapshot:
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
subscribe: (e, t) => {
|
|
122
|
+
snapshot: r
|
|
123
|
+
}, n);
|
|
124
|
+
}, k = {
|
|
125
|
+
subscribe: (e, t, n) => {
|
|
123
126
|
if (typeof e != "string") throw TypeError("a player id must be a string");
|
|
124
127
|
if (typeof MessagePort < "u" && !(t instanceof MessagePort)) throw TypeError("subscribe takes a MessagePort");
|
|
125
|
-
if (!
|
|
126
|
-
let
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
let
|
|
130
|
-
|
|
128
|
+
if (!v.has(e) && v.size >= _) throw RangeError("too many players on this channel");
|
|
129
|
+
let r = x(e);
|
|
130
|
+
if (r.size >= g) throw RangeError("too many embedders for this player");
|
|
131
|
+
r.add(t);
|
|
132
|
+
let i = n?.fullscreen;
|
|
133
|
+
typeof i == "boolean" && ((S.get(e) ?? S.set(e, /* @__PURE__ */ new Set()).get(e)).add(t), C.set(e, i), w(e)), t.onmessage = () => T(e, t), t.start?.();
|
|
134
|
+
let a = D(e);
|
|
135
|
+
a && E(e, {
|
|
131
136
|
event: "loadstart",
|
|
132
|
-
snapshot:
|
|
133
|
-
}, t);
|
|
137
|
+
snapshot: a
|
|
138
|
+
}, [t]);
|
|
134
139
|
},
|
|
135
|
-
set: (e, t,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
set: (e, t, n) => {
|
|
141
|
+
if (t === "fullscreen") {
|
|
142
|
+
if (typeof n != "boolean" || !S.get(e)?.size) return;
|
|
143
|
+
C.set(e, n), w(e);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
let i = m.get(e);
|
|
147
|
+
if (i && r.includes(t)) try {
|
|
148
|
+
i[t] = n;
|
|
139
149
|
} catch {}
|
|
140
150
|
},
|
|
141
151
|
call: async (e, t) => {
|
|
142
|
-
let n =
|
|
143
|
-
if (n &&
|
|
152
|
+
let n = m.get(e);
|
|
153
|
+
if (n && i.includes(t)) try {
|
|
144
154
|
t === "play" ? await n.play() : t === "pause" ? n.pause() : n.load?.();
|
|
145
155
|
} finally {
|
|
146
|
-
|
|
156
|
+
O(e, "timeupdate");
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (let [e, t] of
|
|
153
|
-
m.clear(),
|
|
154
|
-
}, { once: !0 }), e(
|
|
155
|
-
transport:
|
|
159
|
+
}, A = new AbortController();
|
|
160
|
+
A.signal.addEventListener("abort", () => {
|
|
161
|
+
f.delete(u);
|
|
162
|
+
for (let [e, t] of v) for (let n of [...t]) T(e, n);
|
|
163
|
+
v.clear(), m.clear(), h.clear();
|
|
164
|
+
}, { once: !0 }), e(k, {
|
|
165
|
+
transport: a.transport ?? {
|
|
156
166
|
emit: window.parent,
|
|
157
|
-
receive:
|
|
167
|
+
receive: j(() => window.parent, a.origin)
|
|
158
168
|
},
|
|
159
|
-
origin:
|
|
160
|
-
key:
|
|
161
|
-
unregisterSignal:
|
|
169
|
+
origin: a.origin,
|
|
170
|
+
key: o,
|
|
171
|
+
unregisterSignal: A.signal
|
|
162
172
|
});
|
|
163
|
-
let
|
|
164
|
-
let
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
let M = { serve: (e, r) => {
|
|
174
|
+
let i = r.id ?? "default", a = r.player, o = [...t.map((t) => [e, t]), ...a ? n.map((e) => [a, e]) : []].map(([t, n]) => [
|
|
175
|
+
t,
|
|
176
|
+
n,
|
|
177
|
+
() => {
|
|
178
|
+
m.get(i) === e && O(i, n);
|
|
179
|
+
}
|
|
180
|
+
]);
|
|
181
|
+
for (let [e, t, n] of o) e.addEventListener(t, n);
|
|
182
|
+
let c = m.has(i), l = h.get(i);
|
|
183
|
+
l && l !== a && l.onHostFullscreen(null), m.set(i, e), a ? h.set(i, a) : h.delete(i), w(i), c && E(i, {
|
|
170
184
|
event: "emptied",
|
|
171
|
-
snapshot: { ...
|
|
185
|
+
snapshot: { ...d }
|
|
172
186
|
});
|
|
173
|
-
for (let
|
|
174
|
-
let
|
|
175
|
-
for (let [t, n] of
|
|
176
|
-
|
|
187
|
+
for (let e of s(D(i))) O(i, e);
|
|
188
|
+
let u = () => {
|
|
189
|
+
for (let [e, t, n] of o) e.removeEventListener(t, n);
|
|
190
|
+
m.get(i) === e && (m.delete(i), a && h.get(i) === a && (h.delete(i), a.onHostFullscreen(null)), E(i, {
|
|
177
191
|
event: "emptied",
|
|
178
|
-
snapshot: { ...
|
|
192
|
+
snapshot: { ...d }
|
|
179
193
|
}));
|
|
180
|
-
},
|
|
181
|
-
|
|
194
|
+
}, f = () => {
|
|
195
|
+
u(), A.abort();
|
|
182
196
|
};
|
|
183
|
-
return
|
|
197
|
+
return r.signal && (r.signal.aborted ? f() : r.signal.addEventListener("abort", f, { once: !0 })), u;
|
|
184
198
|
} };
|
|
185
|
-
return
|
|
186
|
-
},
|
|
187
|
-
let r = n.channel ?? "banou-media-player", i = `${r}|${n.origin ?? "*"}`, a =
|
|
199
|
+
return f.set(u, M), M;
|
|
200
|
+
}, S = /* @__PURE__ */ new WeakMap(), C = (t, n) => {
|
|
201
|
+
let r = n.channel ?? "banou-media-player", i = `${r}|${n.origin ?? "*"}`, a = S.get(t) ?? (S.set(t, /* @__PURE__ */ new Map()), S.get(t)), o = a.get(i);
|
|
188
202
|
if (o) return o;
|
|
189
|
-
let s =
|
|
203
|
+
let s = k(t, n.origin), c = /* @__PURE__ */ new Set(), l = new AbortController(), u, d = (e) => {
|
|
190
204
|
try {
|
|
191
205
|
e.port?.postMessage("close");
|
|
192
206
|
} catch {}
|
|
@@ -199,7 +213,9 @@ var t = [
|
|
|
199
213
|
let { port1: t, port2: n } = new MessageChannel();
|
|
200
214
|
e.port = t, t.onmessage = ({ data: t }) => {
|
|
201
215
|
l.signal.aborted || e.update(t);
|
|
202
|
-
}
|
|
216
|
+
};
|
|
217
|
+
let r = e.fullscreen;
|
|
218
|
+
await T(() => r ? u.subscribe(e.id, n, { fullscreen: r() }) : u.subscribe(e.id, n)).catch((t) => {
|
|
203
219
|
throw d(e), t;
|
|
204
220
|
});
|
|
205
221
|
}, p = () => {
|
|
@@ -236,37 +252,38 @@ var t = [
|
|
|
236
252
|
}
|
|
237
253
|
};
|
|
238
254
|
return a.set(i, m), m;
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
let
|
|
242
|
-
|
|
255
|
+
}, w = (e, t = {}) => {
|
|
256
|
+
E(t.origin);
|
|
257
|
+
let n = new AbortController(), i = t.signal ? AbortSignal.any([t.signal, n.signal]) : n.signal, a = t.id ?? "default", o = { ...d }, c = new EventTarget(), l = (e) => c.dispatchEvent(new Event(e)), u, p, g = new Promise((e, t) => {
|
|
258
|
+
u = e, p = t;
|
|
243
259
|
});
|
|
244
260
|
g.catch(() => {});
|
|
245
261
|
let _ = () => new DOMException("the remote player was closed", "AbortError"), v = /* @__PURE__ */ new Set(), y = () => {
|
|
246
262
|
for (let e of [...v]) e(_());
|
|
247
263
|
v.clear();
|
|
248
|
-
}, b = /* @__PURE__ */ new Map(), x = !1,
|
|
264
|
+
}, b = /* @__PURE__ */ new Map(), x = !1, S = !1, w = C(e, t).attach({
|
|
249
265
|
id: a,
|
|
266
|
+
fullscreen: t.fullscreen ? () => S : void 0,
|
|
250
267
|
reset: () => {
|
|
251
268
|
x = !1, y();
|
|
252
269
|
},
|
|
253
270
|
update: ({ event: e, snapshot: t }) => {
|
|
254
271
|
let n = !x;
|
|
255
|
-
x = !0
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
for (let e of
|
|
262
|
-
|
|
272
|
+
x = !0;
|
|
273
|
+
let r = JSON.stringify(o.chapters);
|
|
274
|
+
Object.assign(o, t);
|
|
275
|
+
for (let [e, t] of b) o[e] = t;
|
|
276
|
+
let i = n ? s(o) : [e];
|
|
277
|
+
!i.includes("chapterschange") && JSON.stringify(o.chapters) !== r && i.push("chapterschange");
|
|
278
|
+
for (let e of i) l(e);
|
|
279
|
+
n && u();
|
|
263
280
|
}
|
|
264
|
-
}),
|
|
265
|
-
|
|
281
|
+
}), T = () => {
|
|
282
|
+
w(), y(), p(_());
|
|
266
283
|
};
|
|
267
|
-
i.aborted ? queueMicrotask(
|
|
268
|
-
let
|
|
269
|
-
get: () => t ? t(
|
|
284
|
+
i.aborted ? queueMicrotask(T) : i.addEventListener("abort", T, { once: !0 });
|
|
285
|
+
let D = (e, t) => Object.defineProperty(c, e, {
|
|
286
|
+
get: () => t ? t(o[e]) : o[e],
|
|
270
287
|
enumerable: !0
|
|
271
288
|
});
|
|
272
289
|
for (let e of [
|
|
@@ -280,21 +297,28 @@ var t = [
|
|
|
280
297
|
"error",
|
|
281
298
|
"videoWidth",
|
|
282
299
|
"videoHeight"
|
|
283
|
-
])
|
|
284
|
-
|
|
285
|
-
let
|
|
286
|
-
for (let e of
|
|
287
|
-
get: () =>
|
|
300
|
+
]) D(e);
|
|
301
|
+
D("buffered", f), D("seekable", f), D("chapters");
|
|
302
|
+
let O = (e) => g.then(() => i.aborted ? void 0 : e()).catch(() => {}), k = C(e, t);
|
|
303
|
+
for (let e of r) Object.defineProperty(c, e, {
|
|
304
|
+
get: () => o[e],
|
|
288
305
|
set: (t) => {
|
|
289
|
-
|
|
290
|
-
await
|
|
306
|
+
o[e] = t, b.set(e, t), O(async () => {
|
|
307
|
+
await k.set(a, e, t), b.get(e) === t && b.delete(e);
|
|
291
308
|
});
|
|
292
309
|
},
|
|
293
310
|
enumerable: !0
|
|
294
311
|
});
|
|
295
|
-
|
|
312
|
+
Object.defineProperty(c, "fullscreen", {
|
|
313
|
+
get: () => S,
|
|
314
|
+
set: (e) => {
|
|
315
|
+
S = !!e, t.fullscreen && O(() => k.set(a, "fullscreen", S));
|
|
316
|
+
},
|
|
317
|
+
enumerable: !0
|
|
318
|
+
});
|
|
319
|
+
let A = (e) => g.then(() => {
|
|
296
320
|
if (i.aborted) throw _();
|
|
297
|
-
let t =
|
|
321
|
+
let t = k.call(a, e);
|
|
298
322
|
return new Promise((e, n) => {
|
|
299
323
|
v.add(n), t.then(() => {
|
|
300
324
|
v.delete(n), e();
|
|
@@ -303,17 +327,17 @@ var t = [
|
|
|
303
327
|
});
|
|
304
328
|
});
|
|
305
329
|
});
|
|
306
|
-
c.play = () => (
|
|
307
|
-
throw
|
|
330
|
+
c.play = () => (o.paused = !1, A("play").catch((e) => {
|
|
331
|
+
throw o.paused = !0, e;
|
|
308
332
|
}));
|
|
309
|
-
let
|
|
333
|
+
let j = () => new Promise((e) => {
|
|
310
334
|
let t = (t) => {
|
|
311
335
|
clearTimeout(r), c.removeEventListener("playing", n), c.removeEventListener("play", n), e(t);
|
|
312
336
|
}, n = () => t(!0);
|
|
313
337
|
c.addEventListener("playing", n), c.addEventListener("play", n);
|
|
314
|
-
let r = setTimeout(() => t(!
|
|
315
|
-
}),
|
|
316
|
-
let e = !
|
|
338
|
+
let r = setTimeout(() => t(!o.paused), m);
|
|
339
|
+
}), M = async () => {
|
|
340
|
+
let e = !o.paused, t;
|
|
317
341
|
try {
|
|
318
342
|
await c.play();
|
|
319
343
|
} catch (e) {
|
|
@@ -323,36 +347,36 @@ var t = [
|
|
|
323
347
|
started: !0,
|
|
324
348
|
refusal: t
|
|
325
349
|
} : {
|
|
326
|
-
started: await
|
|
350
|
+
started: await j(),
|
|
327
351
|
refusal: t
|
|
328
352
|
};
|
|
329
353
|
};
|
|
330
354
|
return c.autoplay = async () => {
|
|
331
|
-
let e = await
|
|
355
|
+
let e = await M();
|
|
332
356
|
if (e.started) return { muted: c.muted };
|
|
333
|
-
if (c.muted || i.aborted) throw e.refusal ??
|
|
357
|
+
if (c.muted || i.aborted) throw e.refusal ?? h();
|
|
334
358
|
c.muted = !0;
|
|
335
|
-
let t = await
|
|
359
|
+
let t = await M();
|
|
336
360
|
if (t.started) return { muted: !0 };
|
|
337
|
-
throw c.muted = !1, e.refusal ?? t.refusal ??
|
|
361
|
+
throw c.muted = !1, e.refusal ?? t.refusal ?? h();
|
|
338
362
|
}, c.pause = () => {
|
|
339
|
-
|
|
363
|
+
o.paused = !0, A("pause").catch(() => {});
|
|
340
364
|
}, c.load = () => {
|
|
341
|
-
|
|
365
|
+
A("load").catch(() => {});
|
|
342
366
|
}, Object.defineProperty(c, "ready", {
|
|
343
367
|
value: g,
|
|
344
368
|
enumerable: !1
|
|
345
|
-
}), c.destroy = () =>
|
|
346
|
-
},
|
|
369
|
+
}), c.destroy = () => n.abort(), c;
|
|
370
|
+
}, T = async (e) => {
|
|
347
371
|
let t;
|
|
348
372
|
try {
|
|
349
373
|
return await Promise.race([e(), new Promise((e, n) => {
|
|
350
|
-
t = setTimeout(() => n(/* @__PURE__ */ Error("the player did not answer")),
|
|
374
|
+
t = setTimeout(() => n(/* @__PURE__ */ Error("the player did not answer")), p);
|
|
351
375
|
})]);
|
|
352
376
|
} finally {
|
|
353
377
|
t && clearTimeout(t);
|
|
354
378
|
}
|
|
355
|
-
},
|
|
379
|
+
}, E = (e) => {
|
|
356
380
|
if (e === void 0 || e === "*") return;
|
|
357
381
|
if (e === "null") throw TypeError("an opaque origin (\"null\") cannot be spoken to; leave `origin` unset and the sender check stands alone");
|
|
358
382
|
let t;
|
|
@@ -362,47 +386,47 @@ var t = [
|
|
|
362
386
|
throw TypeError(`\`origin\` must be an origin like https://example.com, not ${e}`);
|
|
363
387
|
}
|
|
364
388
|
if (t.origin !== e) throw TypeError(`\`origin\` must be an origin like ${t.origin}, not ${e}`);
|
|
365
|
-
},
|
|
389
|
+
}, D = (e) => {
|
|
366
390
|
try {
|
|
367
391
|
return !!e && typeof e == "object" && e.window === e;
|
|
368
392
|
} catch {
|
|
369
393
|
return !1;
|
|
370
394
|
}
|
|
371
|
-
},
|
|
372
|
-
if (
|
|
395
|
+
}, O = (e) => {
|
|
396
|
+
if (D(e)) return !1;
|
|
373
397
|
try {
|
|
374
398
|
return !!e && typeof e == "object" && "contentWindow" in e;
|
|
375
399
|
} catch {
|
|
376
400
|
return !1;
|
|
377
401
|
}
|
|
378
|
-
},
|
|
379
|
-
if (
|
|
380
|
-
let n =
|
|
402
|
+
}, k = (e, t) => {
|
|
403
|
+
if (D(e)) {
|
|
404
|
+
let n = A(t);
|
|
381
405
|
return {
|
|
382
406
|
emit: (t, r) => {
|
|
383
407
|
e.postMessage(t, n.target(), r ?? []);
|
|
384
408
|
},
|
|
385
|
-
receive:
|
|
409
|
+
receive: j(() => e, t, n)
|
|
386
410
|
};
|
|
387
411
|
}
|
|
388
|
-
if (
|
|
412
|
+
if (O(e)) {
|
|
389
413
|
if (!e.contentWindow) throw TypeError("mediaPlayer: the iframe has no window yet; append it to a document first");
|
|
390
|
-
let n = () => e.contentWindow, r =
|
|
414
|
+
let n = () => e.contentWindow, r = A(t);
|
|
391
415
|
return {
|
|
392
416
|
emit: (e, t) => {
|
|
393
417
|
n()?.postMessage(e, r.target(), t ?? []);
|
|
394
418
|
},
|
|
395
|
-
receive:
|
|
419
|
+
receive: j(n, t, r)
|
|
396
420
|
};
|
|
397
421
|
}
|
|
398
422
|
return e;
|
|
399
|
-
},
|
|
423
|
+
}, A = (e) => {
|
|
400
424
|
let t = e && e !== "*" ? e : void 0;
|
|
401
425
|
return {
|
|
402
426
|
target: () => t && t !== "null" ? t : "*",
|
|
403
427
|
admits: (e) => t ? e === t : (e && (t = e), !0)
|
|
404
428
|
};
|
|
405
|
-
},
|
|
429
|
+
}, j = (e, t, n = A(t)) => (t) => {
|
|
406
430
|
let r = (r) => {
|
|
407
431
|
r.source === e() && n.admits(r.origin) && t(r.data, {
|
|
408
432
|
source: r.source,
|
|
@@ -413,4 +437,4 @@ var t = [
|
|
|
413
437
|
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
414
438
|
};
|
|
415
439
|
//#endregion
|
|
416
|
-
export {
|
|
440
|
+
export { o as DEFAULT_PLAYER_ID, a as PLAYER_CHANNEL, t as PLAYER_EVENTS, n as SERVED_EVENTS, v as exposePlayer, w as mediaPlayer };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MediaChapter } from '../engine';
|
|
1
2
|
import type { PlayerMedia, TimeRangesLike } from '../react/media';
|
|
2
3
|
/**
|
|
3
4
|
* Everything readable about a player, as one plain object.
|
|
@@ -27,6 +28,8 @@ export type PlayerSnapshot = {
|
|
|
27
28
|
} | null;
|
|
28
29
|
videoWidth: number;
|
|
29
30
|
videoHeight: number;
|
|
31
|
+
/** A `<MediaPlayer expose>`'s chapters, empty for a bare element. */
|
|
32
|
+
chapters: MediaChapter[];
|
|
30
33
|
};
|
|
31
34
|
/**
|
|
32
35
|
* The events a player raises that an embedder can hear, each carrying a fresh snapshot.
|
|
@@ -35,7 +38,12 @@ export type PlayerSnapshot = {
|
|
|
35
38
|
* attached to the mirror resets on those, and an entry costs nothing until it fires.
|
|
36
39
|
*/
|
|
37
40
|
export declare const PLAYER_EVENTS: readonly ['loadstart', 'loadedmetadata', 'loadeddata', 'durationchange', 'timeupdate', 'play', 'playing', 'pause', 'seeking', 'seeked', 'progress', 'ratechange', 'volumechange', 'ended', 'waiting', 'stalled', 'suspend', 'canplay', 'canplaythrough', 'emptied', 'resize', 'error'];
|
|
38
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The events a `<MediaPlayer expose>` raises beside its media's: its chapters changed, and its viewer pressed
|
|
43
|
+
* fullscreen while a mirror made with `fullscreen: true` has it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SERVED_EVENTS: readonly ['chapterschange', 'fullscreenrequest'];
|
|
46
|
+
export type PlayerEvent = typeof PLAYER_EVENTS[number] | typeof SERVED_EVENTS[number];
|
|
39
47
|
/** The properties an embedder may set. Everything else is read-only on a media, here as there. */
|
|
40
48
|
export declare const WRITABLE: readonly ['currentTime', 'volume', 'muted', 'playbackRate'];
|
|
41
49
|
export type Writable = typeof WRITABLE[number];
|
|
@@ -73,8 +81,12 @@ export type PlayerUpdate = {
|
|
|
73
81
|
* has not mounted yet.
|
|
74
82
|
*/
|
|
75
83
|
export type PlayerService = {
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
/** With `fullscreen`, the mirror takes the player's fullscreen over, in that state, until its port goes. */
|
|
85
|
+
subscribe: (id: string, port: MessagePort, options?: {
|
|
86
|
+
fullscreen?: boolean;
|
|
87
|
+
}) => void;
|
|
88
|
+
/** `fullscreen` is the state shown by a player whose fullscreen a mirror has taken over, and is ignored otherwise. */
|
|
89
|
+
set: (id: string, name: Writable | 'fullscreen', value: number | boolean) => void;
|
|
78
90
|
call: (id: string, name: Callable) => Promise<void>;
|
|
79
91
|
};
|
|
80
92
|
/**
|
|
@@ -84,7 +96,7 @@ export type PlayerService = {
|
|
|
84
96
|
*/
|
|
85
97
|
export declare const syncEventsFor: (snapshot: PlayerSnapshot) => PlayerEvent[];
|
|
86
98
|
/** A media as a snapshot. A NaN duration, which a bare element answers before it has metadata, is sent as 0. */
|
|
87
|
-
export declare const snapshotOf: (media: PlayerMedia) => PlayerSnapshot;
|
|
99
|
+
export declare const snapshotOf: (media: PlayerMedia, chapters?: MediaChapter[]) => PlayerSnapshot;
|
|
88
100
|
/** The snapshot an embedder holds before the player's document has said anything. */
|
|
89
101
|
export declare const EMPTY_SNAPSHOT: PlayerSnapshot;
|
|
90
102
|
/** Plain pairs back into the structural `TimeRanges` the player reads. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banou/media-player",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.29",
|
|
4
4
|
"description": "A video player for containers and codecs the browser cannot play natively, remuxed on the fly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"types": "./dist/remote/index.d.ts",
|
|
19
19
|
"import": "./dist/remote/index.js"
|
|
20
20
|
},
|
|
21
|
+
"./language": {
|
|
22
|
+
"types": "./dist/language/index.d.ts",
|
|
23
|
+
"import": "./dist/language/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./chapters": {
|
|
26
|
+
"types": "./dist/chapters/index.d.ts",
|
|
27
|
+
"import": "./dist/chapters/index.js"
|
|
28
|
+
},
|
|
21
29
|
"./volume-normalizer-worklet.js": "./dist/volume-normalizer-worklet.js",
|
|
22
30
|
"./noto-sans-jp.otf": "./src/lib/assets/noto-sans-jp.otf",
|
|
23
31
|
"./package.json": "./package.json"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The chapter classifier behind Skip Opening and Skip Ending, for a page that decides what a chapter is without
|
|
2
|
+
// loading the player: this entry imports no React, no engine and no worker.
|
|
3
|
+
export { classifyChapters } from '../utils/chapters'
|
|
4
|
+
export type { ChapterKind } from '../utils/chapters'
|
|
5
|
+
export type { MediaChapter } from '../engine'
|
|
@@ -58,6 +58,11 @@ export type PlaybackOptions = {
|
|
|
58
58
|
cjkFontUrl?: string
|
|
59
59
|
bufferSize?: number
|
|
60
60
|
audioStreamIndex?: number
|
|
61
|
+
/**
|
|
62
|
+
* Picks the audio stream from the file's own when `audioStreamIndex` names none, undefined for the default. A pick
|
|
63
|
+
* other than the default makes the remuxer again before anything plays, since libav fixes its stream when it is made.
|
|
64
|
+
*/
|
|
65
|
+
chooseAudioStream?: (streams: AudioStream[]) => number | undefined
|
|
61
66
|
onReady?: () => void
|
|
62
67
|
onError?: (error: unknown) => void
|
|
63
68
|
onRecovered?: () => void
|
|
@@ -159,19 +164,20 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
159
164
|
const {
|
|
160
165
|
videoElement, subtitleContainer, read, length, publicPath, libavWorkerUrl,
|
|
161
166
|
jassubWorkerUrl, jassubWasmUrl, jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize = DEFAULT_BUFFER_SIZE,
|
|
162
|
-
audioStreamIndex, onReady, onError, onRecovered, onSeek, onSubtitleStreams,
|
|
167
|
+
audioStreamIndex, chooseAudioStream, onReady, onError, onRecovered, onSeek, onSubtitleStreams,
|
|
163
168
|
onAudioStreams, onOutput,
|
|
164
169
|
} = options
|
|
165
170
|
|
|
166
|
-
const
|
|
171
|
+
const make = (streamIndex: number | undefined) => makeRemuxer({
|
|
167
172
|
publicPath,
|
|
168
173
|
workerUrl: libavWorkerUrl,
|
|
169
174
|
workerOptions: { type: 'module' },
|
|
170
175
|
bufferSize,
|
|
171
176
|
length,
|
|
172
|
-
audioStreamIndex,
|
|
177
|
+
audioStreamIndex: streamIndex,
|
|
173
178
|
read,
|
|
174
179
|
})
|
|
180
|
+
let remuxer = await make(audioStreamIndex)
|
|
175
181
|
|
|
176
182
|
const teardown: (() => void)[] = []
|
|
177
183
|
let destroyed = false
|
|
@@ -185,11 +191,17 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
185
191
|
teardown.push(() => terminateRemuxer(remuxer))
|
|
186
192
|
|
|
187
193
|
try {
|
|
188
|
-
|
|
194
|
+
let metadata = await remuxer.init()
|
|
195
|
+
const chosen = audioStreamIndex ?? chooseAudioStream?.(metadata.audioStreams ?? [])
|
|
196
|
+
if (audioStreamIndex === undefined && chosen !== undefined && chosen !== metadata.audioStreams?.[0]?.streamIndex) {
|
|
197
|
+
terminateRemuxer(remuxer)
|
|
198
|
+
remuxer = await make(chosen)
|
|
199
|
+
metadata = await remuxer.init()
|
|
200
|
+
}
|
|
189
201
|
|
|
190
202
|
const audioStreams = metadata.audioStreams ?? []
|
|
191
|
-
const selectedAudio = audioStreams.some((s) => s.streamIndex ===
|
|
192
|
-
?
|
|
203
|
+
const selectedAudio = audioStreams.some((s) => s.streamIndex === chosen)
|
|
204
|
+
? chosen!
|
|
193
205
|
: audioStreams[0]?.streamIndex ?? -1
|
|
194
206
|
onAudioStreams?.(audioStreams, selectedAudio)
|
|
195
207
|
|