@banou/media-player 0.10.32 → 0.10.33
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 +5 -0
- package/dist/index.js +257 -251
- package/dist/react/components/chrome.d.ts +3 -1
- package/dist/react/components/skip-chapter.d.ts +5 -1
- package/dist/remote/index.d.ts +17 -4
- package/dist/remote/index.js +17 -5
- package/dist/remote/protocol.d.ts +4 -2
- package/package.json +1 -1
- package/src/lib/react/components/chrome.tsx +4 -2
- package/src/lib/react/components/skip-chapter.tsx +8 -2
- package/src/lib/react/video-player.tsx +12 -3
- package/src/lib/remote/index.ts +29 -6
- package/src/lib/remote/protocol.ts +6 -3
|
@@ -12,7 +12,9 @@ export type ChromeProps = {
|
|
|
12
12
|
shortcuts?: 'window' | 'player';
|
|
13
13
|
/** Fullscreen kept by the host: a press calls its `request` instead of fullscreening the player. */
|
|
14
14
|
fullscreen?: HostFullscreen;
|
|
15
|
+
/** False leaves the last ending out of the skip offer. */
|
|
16
|
+
endingOffered: boolean;
|
|
15
17
|
children?: ReactNode;
|
|
16
18
|
};
|
|
17
|
-
export declare const Chrome: ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, fullscreen, children }: ChromeProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare const Chrome: ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, fullscreen, endingOffered, children }: ChromeProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
18
20
|
export default Chrome;
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* of the pair: the classifier reads titles written by whoever muxed the file, so it is sometimes
|
|
6
6
|
* going to be wrong. Making the offer expire, and never acting on its own, is what makes being wrong
|
|
7
7
|
* cheap. See the classifier for what it matches and the sample it was measured against.
|
|
8
|
+
*
|
|
9
|
+
* `endingOffered` false leaves the last ending out, for an embedder that fills this corner itself.
|
|
8
10
|
*/
|
|
9
|
-
export declare const SkipChapter: (
|
|
11
|
+
export declare const SkipChapter: ({ endingOffered }: {
|
|
12
|
+
endingOffered: boolean;
|
|
13
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
10
14
|
export default SkipChapter;
|
package/dist/remote/index.d.ts
CHANGED
|
@@ -46,14 +46,17 @@ export type ExposePlayerOptions = {
|
|
|
46
46
|
player?: ServedPlayer;
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
49
|
-
* The player around a served media, as `<MediaPlayer expose>` passes it: its chapters
|
|
50
|
-
* announced on its `chapterschange`, and its fullscreen, which a mirror made
|
|
51
|
-
* one has it, `onHostFullscreen` is told the state that mirror sets, and null
|
|
52
|
-
* dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the
|
|
49
|
+
* The player around a served media, as `<MediaPlayer expose>` passes it: its chapters and whether it offers to skip its
|
|
50
|
+
* last ending, sent with every snapshot and announced on its `chapterschange`, and its fullscreen, which a mirror made
|
|
51
|
+
* with `fullscreen: true` takes over. While one has it, `onHostFullscreen` is told the state that mirror sets, and null
|
|
52
|
+
* once none has it; the player then dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the
|
|
53
|
+
* mirror. `onEndingOffered` is told what a mirror sets on `endingOffered`.
|
|
53
54
|
*/
|
|
54
55
|
export type ServedPlayer = EventTarget & {
|
|
55
56
|
readonly chapters: MediaChapter[];
|
|
57
|
+
readonly endingOffered: boolean;
|
|
56
58
|
onHostFullscreen: (active: boolean | null) => void;
|
|
59
|
+
onEndingOffered: (offered: boolean) => void;
|
|
57
60
|
};
|
|
58
61
|
/**
|
|
59
62
|
* Serve `media` to this document's embedder. Returns the teardown for THIS media.
|
|
@@ -92,6 +95,16 @@ export type MediaPlayerHandle = {
|
|
|
92
95
|
* shortcuts follow it. Set it on every change. Without the option it stays here.
|
|
93
96
|
*/
|
|
94
97
|
fullscreen: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Whether the far `<MediaPlayer expose>` offers to skip its last ending, as it last said. Set it to false to have
|
|
100
|
+
* that offer taken away, for a page with something of its own in that corner, and to true to have it back; a
|
|
101
|
+
* mirror's `destroy()` leaves it as it is, and a new player starts out offering.
|
|
102
|
+
*
|
|
103
|
+
* Unlike every other write here this one does NOT move the mirror: a read answers what the far player reports,
|
|
104
|
+
* from after its render, with a `chapterschange` event following each change. So a false here means the offer is
|
|
105
|
+
* off the far screen, and a player that cannot take it (a bare element, a version older than this) stays true.
|
|
106
|
+
*/
|
|
107
|
+
endingOffered: boolean;
|
|
95
108
|
/**
|
|
96
109
|
* Settles once the far side has first answered with its state; reads before that answer the
|
|
97
110
|
* empty defaults. Stays pending for as long as nobody answers, and rejects with an AbortError on
|
package/dist/remote/index.js
CHANGED
|
@@ -49,7 +49,7 @@ var t = [
|
|
|
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
|
-
}, l = (e, t = []) => ({
|
|
52
|
+
}, l = (e, t = [], n = !0) => ({
|
|
53
53
|
currentTime: u(e.currentTime),
|
|
54
54
|
duration: u(e.duration),
|
|
55
55
|
paused: e.paused,
|
|
@@ -69,7 +69,8 @@ var t = [
|
|
|
69
69
|
} : null,
|
|
70
70
|
videoWidth: e.videoWidth ?? 0,
|
|
71
71
|
videoHeight: e.videoHeight ?? 0,
|
|
72
|
-
chapters: t
|
|
72
|
+
chapters: t,
|
|
73
|
+
endingOffered: n
|
|
73
74
|
}), u = (e) => Number.isNaN(e) ? 0 : e, d = {
|
|
74
75
|
currentTime: 0,
|
|
75
76
|
duration: 0,
|
|
@@ -87,7 +88,8 @@ var t = [
|
|
|
87
88
|
error: null,
|
|
88
89
|
videoWidth: 0,
|
|
89
90
|
videoHeight: 0,
|
|
90
|
-
chapters: []
|
|
91
|
+
chapters: [],
|
|
92
|
+
endingOffered: !0
|
|
91
93
|
}, f = (e) => ({
|
|
92
94
|
length: e.length,
|
|
93
95
|
start: (t) => e[t]?.[0] ?? 0,
|
|
@@ -111,8 +113,8 @@ var t = [
|
|
|
111
113
|
T(e, r);
|
|
112
114
|
}
|
|
113
115
|
}, D = (e) => {
|
|
114
|
-
let t = m.get(e);
|
|
115
|
-
return t ? l(t,
|
|
116
|
+
let t = m.get(e), n = h.get(e);
|
|
117
|
+
return t ? l(t, n?.chapters, n?.endingOffered) : void 0;
|
|
116
118
|
}, O = (e, t) => {
|
|
117
119
|
let n = t === "fullscreenrequest" ? S.get(e) : v.get(e);
|
|
118
120
|
if (!n?.size) return;
|
|
@@ -143,6 +145,10 @@ var t = [
|
|
|
143
145
|
C.set(e, n), w(e);
|
|
144
146
|
return;
|
|
145
147
|
}
|
|
148
|
+
if (t === "endingOffered") {
|
|
149
|
+
typeof n == "boolean" && h.get(e)?.onEndingOffered(n);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
146
152
|
let i = m.get(e);
|
|
147
153
|
if (i && r.includes(t)) try {
|
|
148
154
|
i[t] = n;
|
|
@@ -315,6 +321,12 @@ var t = [
|
|
|
315
321
|
S = !!e, t.fullscreen && O(() => k.set(a, "fullscreen", S));
|
|
316
322
|
},
|
|
317
323
|
enumerable: !0
|
|
324
|
+
}), Object.defineProperty(c, "endingOffered", {
|
|
325
|
+
get: () => o.endingOffered,
|
|
326
|
+
set: (e) => {
|
|
327
|
+
O(() => k.set(a, "endingOffered", e));
|
|
328
|
+
},
|
|
329
|
+
enumerable: !0
|
|
318
330
|
});
|
|
319
331
|
let A = (e) => g.then(() => {
|
|
320
332
|
if (i.aborted) throw _();
|
|
@@ -30,6 +30,8 @@ export type PlayerSnapshot = {
|
|
|
30
30
|
videoHeight: number;
|
|
31
31
|
/** A `<MediaPlayer expose>`'s chapters, empty for a bare element. */
|
|
32
32
|
chapters: MediaChapter[];
|
|
33
|
+
/** Whether a `<MediaPlayer expose>` offers to skip its last ending. Set after its render, so false means the offer is off the screen. */
|
|
34
|
+
endingOffered: boolean;
|
|
33
35
|
};
|
|
34
36
|
/**
|
|
35
37
|
* The events a player raises that an embedder can hear, each carrying a fresh snapshot.
|
|
@@ -86,7 +88,7 @@ export type PlayerService = {
|
|
|
86
88
|
fullscreen?: boolean;
|
|
87
89
|
}) => void;
|
|
88
90
|
/** `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;
|
|
91
|
+
set: (id: string, name: Writable | 'fullscreen' | 'endingOffered', value: number | boolean) => void;
|
|
90
92
|
call: (id: string, name: Callable) => Promise<void>;
|
|
91
93
|
};
|
|
92
94
|
/**
|
|
@@ -96,7 +98,7 @@ export type PlayerService = {
|
|
|
96
98
|
*/
|
|
97
99
|
export declare const syncEventsFor: (snapshot: PlayerSnapshot) => PlayerEvent[];
|
|
98
100
|
/** A media as a snapshot. A NaN duration, which a bare element answers before it has metadata, is sent as 0. */
|
|
99
|
-
export declare const snapshotOf: (media: PlayerMedia, chapters?: MediaChapter[]) => PlayerSnapshot;
|
|
101
|
+
export declare const snapshotOf: (media: PlayerMedia, chapters?: MediaChapter[], endingOffered?: boolean) => PlayerSnapshot;
|
|
100
102
|
/** The snapshot an embedder holds before the player's document has said anything. */
|
|
101
103
|
export declare const EMPTY_SNAPSHOT: PlayerSnapshot;
|
|
102
104
|
/** Plain pairs back into the structural `TimeRanges` the player reads. */
|
package/package.json
CHANGED
|
@@ -137,10 +137,12 @@ export type ChromeProps = {
|
|
|
137
137
|
shortcuts?: 'window' | 'player'
|
|
138
138
|
/** Fullscreen kept by the host: a press calls its `request` instead of fullscreening the player. */
|
|
139
139
|
fullscreen?: HostFullscreen
|
|
140
|
+
/** False leaves the last ending out of the skip offer. */
|
|
141
|
+
endingOffered: boolean
|
|
140
142
|
children?: ReactNode
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
export const Chrome = ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, fullscreen, children }: ChromeProps) => {
|
|
145
|
+
export const Chrome = ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, fullscreen, endingOffered, children }: ChromeProps) => {
|
|
144
146
|
const player = usePlayer()
|
|
145
147
|
const hideUI = usePlayer((state) => state.hideUI)
|
|
146
148
|
const setHideUI = usePlayer((state) => state.setHideUI)
|
|
@@ -327,7 +329,7 @@ export const Chrome = ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shor
|
|
|
327
329
|
)}
|
|
328
330
|
{/* Not tied to `hideUI`: it says what to do next, and it is on screen for nine seconds. */}
|
|
329
331
|
<BurnInHint />
|
|
330
|
-
<SkipChapter />
|
|
332
|
+
<SkipChapter endingOffered={endingOffered} />
|
|
331
333
|
{passThrough?.armed && root.current
|
|
332
334
|
? (
|
|
333
335
|
<div
|
|
@@ -90,8 +90,10 @@ const style = css`
|
|
|
90
90
|
* of the pair: the classifier reads titles written by whoever muxed the file, so it is sometimes
|
|
91
91
|
* going to be wrong. Making the offer expire, and never acting on its own, is what makes being wrong
|
|
92
92
|
* cheap. See the classifier for what it matches and the sample it was measured against.
|
|
93
|
+
*
|
|
94
|
+
* `endingOffered` false leaves the last ending out, for an embedder that fills this corner itself.
|
|
93
95
|
*/
|
|
94
|
-
export const SkipChapter = () => {
|
|
96
|
+
export const SkipChapter = ({ endingOffered }: { endingOffered: boolean }) => {
|
|
95
97
|
const chapters = usePlayer((state) => state.chapters)
|
|
96
98
|
const currentTime = usePlayer((state) => state.currentTime)
|
|
97
99
|
const requestSeek = usePlayer((state) => state.requestSeek)
|
|
@@ -104,7 +106,11 @@ export const SkipChapter = () => {
|
|
|
104
106
|
const player = usePlayer()
|
|
105
107
|
const { format } = useLabels()
|
|
106
108
|
|
|
107
|
-
const kinds = useMemo(() =>
|
|
109
|
+
const kinds = useMemo(() => {
|
|
110
|
+
const all = classifyChapters(chapters)
|
|
111
|
+
const left = endingOffered ? -1 : all.lastIndexOf('ending')
|
|
112
|
+
return all.map((kind, index) => index === left ? undefined : kind)
|
|
113
|
+
}, [chapters, endingOffered])
|
|
108
114
|
|
|
109
115
|
/**
|
|
110
116
|
* The chapter worth offering to skip, from a second before it starts until it ends.
|
|
@@ -367,8 +367,14 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
|
|
|
367
367
|
// What `expose` serves beside the media, the same object for the player's life. Its `onHostFullscreen` is how a
|
|
368
368
|
// mirror made with `fullscreen: true` takes the fullscreen over.
|
|
369
369
|
const [embedderFullscreen, setEmbedderFullscreen] = useState<boolean | null>(null)
|
|
370
|
-
const [
|
|
371
|
-
|
|
370
|
+
const [endingOffered, setEndingOffered] = useState(true)
|
|
371
|
+
const [served] = useState<ServedPlayer & { chapters: MediaChapter[], endingOffered: boolean }>(
|
|
372
|
+
() => Object.assign(new EventTarget(), {
|
|
373
|
+
chapters: [],
|
|
374
|
+
endingOffered: true,
|
|
375
|
+
onHostFullscreen: setEmbedderFullscreen,
|
|
376
|
+
onEndingOffered: setEndingOffered,
|
|
377
|
+
}),
|
|
372
378
|
)
|
|
373
379
|
const exposeOptions = expose === true ? {} : expose || undefined
|
|
374
380
|
const latestExpose = useRef(exposeOptions)
|
|
@@ -392,10 +398,12 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
|
|
|
392
398
|
// by value, since a caller's inline `chapters` is a new array on every render
|
|
393
399
|
const playerChapters = usePlayer((state) => state.chapters)
|
|
394
400
|
const chaptersKey = JSON.stringify(playerChapters)
|
|
401
|
+
// after the commit, so a mirror that hears the ending is no longer offered finds the button already gone
|
|
395
402
|
useEffect(() => {
|
|
396
403
|
served.chapters = playerChapters
|
|
404
|
+
served.endingOffered = endingOffered
|
|
397
405
|
served.dispatchEvent(new Event('chapterschange'))
|
|
398
|
-
}, [chaptersKey])
|
|
406
|
+
}, [chaptersKey, endingOffered])
|
|
399
407
|
|
|
400
408
|
const fullscreen = options.fullscreen ?? (embedderFullscreen === null ? undefined : {
|
|
401
409
|
active: embedderFullscreen,
|
|
@@ -581,6 +589,7 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
|
|
|
581
589
|
controls={options.controls}
|
|
582
590
|
shortcuts={options.shortcuts}
|
|
583
591
|
fullscreen={fullscreen}
|
|
592
|
+
endingOffered={endingOffered}
|
|
584
593
|
>
|
|
585
594
|
{children}
|
|
586
595
|
</Chrome>
|
package/src/lib/remote/index.ts
CHANGED
|
@@ -83,14 +83,17 @@ export type ExposePlayerOptions = {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* The player around a served media, as `<MediaPlayer expose>` passes it: its chapters
|
|
87
|
-
* announced on its `chapterschange`, and its fullscreen, which a mirror made
|
|
88
|
-
* one has it, `onHostFullscreen` is told the state that mirror sets, and null
|
|
89
|
-
* dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the
|
|
86
|
+
* The player around a served media, as `<MediaPlayer expose>` passes it: its chapters and whether it offers to skip its
|
|
87
|
+
* last ending, sent with every snapshot and announced on its `chapterschange`, and its fullscreen, which a mirror made
|
|
88
|
+
* with `fullscreen: true` takes over. While one has it, `onHostFullscreen` is told the state that mirror sets, and null
|
|
89
|
+
* once none has it; the player then dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the
|
|
90
|
+
* mirror. `onEndingOffered` is told what a mirror sets on `endingOffered`.
|
|
90
91
|
*/
|
|
91
92
|
export type ServedPlayer = EventTarget & {
|
|
92
93
|
readonly chapters: MediaChapter[]
|
|
94
|
+
readonly endingOffered: boolean
|
|
93
95
|
onHostFullscreen: (active: boolean | null) => void
|
|
96
|
+
onEndingOffered: (offered: boolean) => void
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
/**
|
|
@@ -173,7 +176,8 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
|
|
|
173
176
|
}
|
|
174
177
|
const snapshotAt = (id: string) => {
|
|
175
178
|
const media = medias.get(id)
|
|
176
|
-
|
|
179
|
+
const around = players.get(id)
|
|
180
|
+
return media ? snapshotOf(media, around?.chapters, around?.endingOffered) : undefined
|
|
177
181
|
}
|
|
178
182
|
const announce = (id: string, event: PlayerEvent) => {
|
|
179
183
|
// a press of the fullscreen is for the mirrors that took it over: another one toggling too would undo it
|
|
@@ -223,6 +227,10 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
|
|
|
223
227
|
tellHost(id)
|
|
224
228
|
return
|
|
225
229
|
}
|
|
230
|
+
if (name === 'endingOffered') {
|
|
231
|
+
if (typeof value === 'boolean') players.get(id)?.onEndingOffered(value)
|
|
232
|
+
return
|
|
233
|
+
}
|
|
226
234
|
const media = medias.get(id)
|
|
227
235
|
if (!media || !WRITABLE.includes(name)) return
|
|
228
236
|
try { (media as unknown as Record<Writable, unknown>)[name] = value } catch {}
|
|
@@ -333,6 +341,16 @@ export type MediaPlayerHandle =
|
|
|
333
341
|
* shortcuts follow it. Set it on every change. Without the option it stays here.
|
|
334
342
|
*/
|
|
335
343
|
fullscreen: boolean
|
|
344
|
+
/**
|
|
345
|
+
* Whether the far `<MediaPlayer expose>` offers to skip its last ending, as it last said. Set it to false to have
|
|
346
|
+
* that offer taken away, for a page with something of its own in that corner, and to true to have it back; a
|
|
347
|
+
* mirror's `destroy()` leaves it as it is, and a new player starts out offering.
|
|
348
|
+
*
|
|
349
|
+
* Unlike every other write here this one does NOT move the mirror: a read answers what the far player reports,
|
|
350
|
+
* from after its render, with a `chapterschange` event following each change. So a false here means the offer is
|
|
351
|
+
* off the far screen, and a player that cannot take it (a bare element, a version older than this) stays true.
|
|
352
|
+
*/
|
|
353
|
+
endingOffered: boolean
|
|
336
354
|
/**
|
|
337
355
|
* Settles once the far side has first answered with its state; reads before that answer the
|
|
338
356
|
* empty defaults. Stays pending for as long as nobody answers, and rejects with an AbortError on
|
|
@@ -417,7 +435,7 @@ type Subscriber = {
|
|
|
417
435
|
|
|
418
436
|
type Link = {
|
|
419
437
|
attach: (subscriber: Subscriber) => () => void
|
|
420
|
-
set: (id: string, name: Writable | 'fullscreen', value: number | boolean) => Promise<unknown> | undefined
|
|
438
|
+
set: (id: string, name: Writable | 'fullscreen' | 'endingOffered', value: number | boolean) => Promise<unknown> | undefined
|
|
421
439
|
call: (id: string, name: Callable) => Promise<void>
|
|
422
440
|
}
|
|
423
441
|
|
|
@@ -628,6 +646,11 @@ export const mediaPlayer = (
|
|
|
628
646
|
},
|
|
629
647
|
enumerable: true,
|
|
630
648
|
})
|
|
649
|
+
Object.defineProperty(player, 'endingOffered', {
|
|
650
|
+
get: () => state.endingOffered,
|
|
651
|
+
set: (value: boolean) => { void after(() => link.set(playerId, 'endingOffered', value)) },
|
|
652
|
+
enumerable: true,
|
|
653
|
+
})
|
|
631
654
|
|
|
632
655
|
const call = (name: Callable) => ready.then(() => {
|
|
633
656
|
if (signal.aborted) throw abortError()
|
|
@@ -31,6 +31,8 @@ export type PlayerSnapshot = {
|
|
|
31
31
|
videoHeight: number
|
|
32
32
|
/** A `<MediaPlayer expose>`'s chapters, empty for a bare element. */
|
|
33
33
|
chapters: MediaChapter[]
|
|
34
|
+
/** Whether a `<MediaPlayer expose>` offers to skip its last ending. Set after its render, so false means the offer is off the screen. */
|
|
35
|
+
endingOffered: boolean
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|
|
@@ -93,7 +95,7 @@ export type PlayerService = {
|
|
|
93
95
|
/** With `fullscreen`, the mirror takes the player's fullscreen over, in that state, until its port goes. */
|
|
94
96
|
subscribe: (id: string, port: MessagePort, options?: { fullscreen?: boolean }) => void
|
|
95
97
|
/** `fullscreen` is the state shown by a player whose fullscreen a mirror has taken over, and is ignored otherwise. */
|
|
96
|
-
set: (id: string, name: Writable | 'fullscreen', value: number | boolean) => void
|
|
98
|
+
set: (id: string, name: Writable | 'fullscreen' | 'endingOffered', value: number | boolean) => void
|
|
97
99
|
call: (id: string, name: Callable) => Promise<void>
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -124,7 +126,7 @@ const pairs = (ranges: TimeRangesLike | undefined): [number, number][] => {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
/** A media as a snapshot. A NaN duration, which a bare element answers before it has metadata, is sent as 0. */
|
|
127
|
-
export const snapshotOf = (media: PlayerMedia, chapters: MediaChapter[] = []): PlayerSnapshot => ({
|
|
129
|
+
export const snapshotOf = (media: PlayerMedia, chapters: MediaChapter[] = [], endingOffered = true): PlayerSnapshot => ({
|
|
128
130
|
currentTime: finite(media.currentTime),
|
|
129
131
|
duration: finite(media.duration),
|
|
130
132
|
paused: media.paused,
|
|
@@ -142,6 +144,7 @@ export const snapshotOf = (media: PlayerMedia, chapters: MediaChapter[] = []): P
|
|
|
142
144
|
videoWidth: media.videoWidth ?? 0,
|
|
143
145
|
videoHeight: media.videoHeight ?? 0,
|
|
144
146
|
chapters,
|
|
147
|
+
endingOffered,
|
|
145
148
|
})
|
|
146
149
|
|
|
147
150
|
// NaN only. A live media reports `duration: Infinity` and means it, so sending 0 for it would mirror
|
|
@@ -152,7 +155,7 @@ const finite = (value: number): number => Number.isNaN(value) ? 0 : value
|
|
|
152
155
|
export const EMPTY_SNAPSHOT: PlayerSnapshot = {
|
|
153
156
|
currentTime: 0, duration: 0, paused: true, ended: false, seeking: false, readyState: 0,
|
|
154
157
|
volume: 1, muted: false, playbackRate: 1, src: '', currentSrc: '',
|
|
155
|
-
buffered: [], seekable: [], error: null, videoWidth: 0, videoHeight: 0, chapters: [],
|
|
158
|
+
buffered: [], seekable: [], error: null, videoWidth: 0, videoHeight: 0, chapters: [], endingOffered: true,
|
|
156
159
|
}
|
|
157
160
|
|
|
158
161
|
/** Plain pairs back into the structural `TimeRanges` the player reads. */
|