@banou/media-player 0.10.28 → 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 +39 -0
- package/dist/chapters/index.d.ts +3 -0
- package/dist/chapters/index.js +2 -0
- package/dist/chapters-EBYXcEml.js +115 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +728 -814
- 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 +19 -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 +5 -1
- package/src/lib/chapters/index.ts +5 -0
- package/src/lib/index.tsx +1 -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/video-player.tsx +43 -2
- package/src/lib/remote/index.ts +99 -18
- package/src/lib/remote/protocol.ts +16 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode, Ref } from 'react';
|
|
2
|
+
import type { HostFullscreen } from '../video-player';
|
|
2
3
|
export type ChromeProps = {
|
|
3
4
|
ref?: Ref<HTMLDivElement> | ((element: HTMLDivElement | null) => void);
|
|
4
5
|
/** Absent means render no video element: the media belongs to someone else and arrives as children. */
|
|
@@ -9,7 +10,9 @@ export type ChromeProps = {
|
|
|
9
10
|
/** False draws no control bar at all, leaving the picture, the title and the overlay. */
|
|
10
11
|
controls?: boolean;
|
|
11
12
|
shortcuts?: 'window' | 'player';
|
|
13
|
+
/** Fullscreen kept by the host: a press calls its `request` instead of fullscreening the player. */
|
|
14
|
+
fullscreen?: HostFullscreen;
|
|
12
15
|
children?: ReactNode;
|
|
13
16
|
};
|
|
14
|
-
export declare const Chrome: ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, children }: ChromeProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare const Chrome: ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, fullscreen, children }: ChromeProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
15
18
|
export default Chrome;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RefObject } from 'react';
|
|
2
|
-
|
|
2
|
+
import type { HostFullscreen } from '../video-player';
|
|
3
|
+
export declare const ControlBar: ({ shortcuts, root, fullscreen: host }: {
|
|
3
4
|
shortcuts?: 'window' | 'player';
|
|
4
5
|
root: RefObject<HTMLDivElement | null>;
|
|
6
|
+
fullscreen?: HostFullscreen;
|
|
5
7
|
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
6
8
|
export default ControlBar;
|
|
@@ -5,6 +5,8 @@ export declare enum buttonSize {
|
|
|
5
5
|
md = "md",
|
|
6
6
|
lg = "lg"
|
|
7
7
|
}
|
|
8
|
+
/** Whether the host page keeps the player's fullscreen: the `fullscreen` prop, or a mirror that took it over. */
|
|
9
|
+
export declare const HostKeepsFullscreen: import("react").Context<boolean>;
|
|
8
10
|
interface TooltipDisplayProps {
|
|
9
11
|
id: string;
|
|
10
12
|
toolTipText: ReactNode;
|
|
@@ -20,6 +20,19 @@ export type MediaPlayerSource = {
|
|
|
20
20
|
size?: undefined;
|
|
21
21
|
readsDownload?: undefined;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Fullscreen kept by the host page rather than by the player, for a page that fullscreens an element of its own around
|
|
25
|
+
* the player, so that fullscreen outlasts the player in it.
|
|
26
|
+
*/
|
|
27
|
+
export type HostFullscreen = {
|
|
28
|
+
/** Whether the host shows the player fullscreen: the button shows it, and the `'player'` shortcuts follow it. */
|
|
29
|
+
active: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The viewer pressed fullscreen (the button, `f` or a double click): the host enters or leaves it. Called once per
|
|
32
|
+
* press, during that press's event, so the host's own `requestFullscreen` has the press's activation.
|
|
33
|
+
*/
|
|
34
|
+
request: () => void;
|
|
35
|
+
};
|
|
23
36
|
/** Shared by both arms: nothing here depends on who owns the media. */
|
|
24
37
|
type CommonOptions = {
|
|
25
38
|
/**
|
|
@@ -72,6 +85,12 @@ type CommonOptions = {
|
|
|
72
85
|
* is fullscreen, so Space and the arrow keys keep scrolling the page and pressing its buttons everywhere else.
|
|
73
86
|
*/
|
|
74
87
|
shortcuts?: 'window' | 'player';
|
|
88
|
+
/**
|
|
89
|
+
* Hand fullscreen to the host page: the player then never calls `requestFullscreen`, each press of its fullscreen
|
|
90
|
+
* calls `request` once, and the button and the `'player'` shortcuts follow `active`. Read by value, so it may be
|
|
91
|
+
* written inline. Without it the player fullscreens itself.
|
|
92
|
+
*/
|
|
93
|
+
fullscreen?: HostFullscreen;
|
|
75
94
|
/**
|
|
76
95
|
* The app's own content over the video: a download readout, a badge, a logo, anything the player
|
|
77
96
|
* itself has no opinion about.
|
package/dist/remote/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transport } from 'osra';
|
|
2
|
+
import type { MediaChapter } from '../engine';
|
|
2
3
|
import type { PlayerMedia } from '../react/media';
|
|
3
4
|
import type { Writable } from './protocol';
|
|
4
5
|
export type { PlayerEvent, PlayerSnapshot, PlayerUpdate } from './protocol';
|
|
5
|
-
export { DEFAULT_PLAYER_ID, PLAYER_CHANNEL, PLAYER_EVENTS } from './protocol';
|
|
6
|
+
export { DEFAULT_PLAYER_ID, PLAYER_CHANNEL, PLAYER_EVENTS, SERVED_EVENTS } from './protocol';
|
|
6
7
|
/**
|
|
7
8
|
* Where a player serves from, and to whom.
|
|
8
9
|
*
|
|
@@ -41,6 +42,18 @@ export type ExposePlayerOptions = {
|
|
|
41
42
|
* and a channel that closed in between would drop every embedder listening to the others.
|
|
42
43
|
*/
|
|
43
44
|
signal?: AbortSignal;
|
|
45
|
+
/** What `<MediaPlayer expose>` serves beside its media. A document serving a bare element leaves it out. */
|
|
46
|
+
player?: ServedPlayer;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The player around a served media, as `<MediaPlayer expose>` passes it: its chapters, sent with every snapshot and
|
|
50
|
+
* announced on its `chapterschange`, and its fullscreen, which a mirror made with `fullscreen: true` takes over. While
|
|
51
|
+
* one has it, `onHostFullscreen` is told the state that mirror sets, and null once none has it; the player then
|
|
52
|
+
* dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the mirror.
|
|
53
|
+
*/
|
|
54
|
+
export type ServedPlayer = EventTarget & {
|
|
55
|
+
readonly chapters: MediaChapter[];
|
|
56
|
+
onHostFullscreen: (active: boolean | null) => void;
|
|
44
57
|
};
|
|
45
58
|
/**
|
|
46
59
|
* Serve `media` to this document's embedder. Returns the teardown for THIS media.
|
|
@@ -72,6 +85,13 @@ type Mirrored = Omit<PlayerMedia, Writable>;
|
|
|
72
85
|
export type MediaPlayerHandle = {
|
|
73
86
|
readonly [K in keyof Mirrored]: Mirrored[K];
|
|
74
87
|
} & Readonly<Required<Pick<PlayerMedia, 'src' | 'currentSrc' | 'ended' | 'buffered' | 'seekable' | 'error' | 'videoWidth' | 'videoHeight'>>> & Required<Pick<PlayerMedia, Writable>> & {
|
|
88
|
+
/** The far player's chapters, empty for a bare element. A `chapterschange` event follows each change. */
|
|
89
|
+
readonly chapters: MediaChapter[];
|
|
90
|
+
/**
|
|
91
|
+
* With the `fullscreen` option, whether this page shows the far player fullscreen: its button and its `'player'`
|
|
92
|
+
* shortcuts follow it. Set it on every change. Without the option it stays here.
|
|
93
|
+
*/
|
|
94
|
+
fullscreen: boolean;
|
|
75
95
|
/**
|
|
76
96
|
* Settles once the far side has first answered with its state; reads before that answer the
|
|
77
97
|
* empty defaults. Stays pending for as long as nobody answers, and rejects with an AbortError on
|
|
@@ -129,6 +149,12 @@ export type MediaPlayerHandleOptions = {
|
|
|
129
149
|
channel?: string;
|
|
130
150
|
/** closes the mirror: `ready` rejects with an AbortError and nothing more is heard */
|
|
131
151
|
signal?: AbortSignal;
|
|
152
|
+
/**
|
|
153
|
+
* Take the far player's fullscreen over, when it is a `<MediaPlayer expose>`: its button, `f` and double click then
|
|
154
|
+
* call no `requestFullscreen` and fire one `fullscreenrequest` on the handle each, inside the press's activation,
|
|
155
|
+
* and show the handle's `fullscreen`. Released on `destroy()`. A bare element ignores it.
|
|
156
|
+
*/
|
|
157
|
+
fullscreen?: boolean;
|
|
132
158
|
};
|
|
133
159
|
/**
|
|
134
160
|
* Mirror a player another document is serving, as a media of this one.
|
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 };
|