@banou/media-player 0.10.39 → 0.10.41

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.
Files changed (72) hide show
  1. package/README.md +13 -0
  2. package/dist/{ar-CS4Yzfxw.js → ar-CWVutin3.js} +1 -0
  3. package/dist/{cs-CxBZ1aTx.js → cs-CmwRGxyE.js} +1 -0
  4. package/dist/{de-DphEdq0O.js → de-DLdKEf3t.js} +1 -0
  5. package/dist/{el-BVTNfAWK.js → el-Ckj-z6DX.js} +1 -0
  6. package/dist/engine/index.js +1 -1
  7. package/dist/{engine-DFqSQyNb.js → engine-wP5Udzzj.js} +1 -0
  8. package/dist/{es-419-D6gsvnn8.js → es-419-zORhhU8D.js} +1 -0
  9. package/dist/{fr-BqAzAJX0.js → fr-BtPmNkri.js} +1 -0
  10. package/dist/{he-DbFw1CdO.js → he-Bu79qEth.js} +1 -0
  11. package/dist/{hi-rBroV7g8.js → hi-BsH3tSHa.js} +1 -0
  12. package/dist/{hu-m-QKaaxF.js → hu-BkYBW-YP.js} +1 -0
  13. package/dist/{id-BYpApdK9.js → id-nUaBCV4o.js} +1 -0
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +263 -236
  16. package/dist/{it-NTcUh3Gr.js → it-CqPSHyFA.js} +1 -0
  17. package/dist/{ja-DSmX_bxj.js → ja-DTjvriHw.js} +1 -0
  18. package/dist/{ko-DyPzWasj.js → ko-dV8T7XOJ.js} +1 -0
  19. package/dist/labels.d.ts +1 -0
  20. package/dist/{ms-8pQbqM0D.js → ms-VZQ7BI0z.js} +1 -0
  21. package/dist/{nl-q7xvc3xW.js → nl-Q6iDxbDz.js} +1 -0
  22. package/dist/{pl-C6Ow4ra5.js → pl-BN7bK74l.js} +1 -0
  23. package/dist/{pt-BR-wudK3giz.js → pt-BR-CPFILeFW.js} +1 -0
  24. package/dist/react/player.d.ts +1 -0
  25. package/dist/react/source-feature.d.ts +9 -0
  26. package/dist/react/video-player.d.ts +9 -0
  27. package/dist/remote/index.d.ts +18 -0
  28. package/dist/remote/index.js +51 -34
  29. package/dist/remote/protocol.d.ts +11 -6
  30. package/dist/{ro-DBrd08Df.js → ro-Bwcm-i3k.js} +1 -0
  31. package/dist/{ru-D5kxBkik.js → ru-D1FMz751.js} +1 -0
  32. package/dist/{sv-DJC3tXfW.js → sv-ci9K0Lkk.js} +1 -0
  33. package/dist/{th-BNzU_FYo.js → th-DR-UBONQ.js} +1 -0
  34. package/dist/{tr-CW7R7N9k.js → tr-BqhdfT22.js} +1 -0
  35. package/dist/{uk-C66esN2W.js → uk-8pkZqdni.js} +1 -0
  36. package/dist/{vi-oOaDECwu.js → vi-3mKZ9G_M.js} +1 -0
  37. package/dist/{zh-Hans-IhL1Pl78.js → zh-Hans-CDgigWKY.js} +1 -0
  38. package/dist/{zh-Hant-C5YyFjEc.js → zh-Hant-3WSNI0ne.js} +1 -0
  39. package/package.json +2 -2
  40. package/src/lib/index.tsx +2 -1
  41. package/src/lib/labels.ts +1 -0
  42. package/src/lib/locales/ar.json +1 -0
  43. package/src/lib/locales/cs.json +1 -0
  44. package/src/lib/locales/de.json +1 -0
  45. package/src/lib/locales/el.json +1 -0
  46. package/src/lib/locales/es-419.json +1 -0
  47. package/src/lib/locales/fr.json +1 -0
  48. package/src/lib/locales/he.json +1 -0
  49. package/src/lib/locales/hi.json +1 -0
  50. package/src/lib/locales/hu.json +1 -0
  51. package/src/lib/locales/id.json +1 -0
  52. package/src/lib/locales/it.json +1 -0
  53. package/src/lib/locales/ja.json +1 -0
  54. package/src/lib/locales/ko.json +1 -0
  55. package/src/lib/locales/ms.json +1 -0
  56. package/src/lib/locales/nl.json +1 -0
  57. package/src/lib/locales/pl.json +1 -0
  58. package/src/lib/locales/pt-BR.json +1 -0
  59. package/src/lib/locales/ro.json +1 -0
  60. package/src/lib/locales/ru.json +1 -0
  61. package/src/lib/locales/sv.json +1 -0
  62. package/src/lib/locales/th.json +1 -0
  63. package/src/lib/locales/tr.json +1 -0
  64. package/src/lib/locales/uk.json +1 -0
  65. package/src/lib/locales/vi.json +1 -0
  66. package/src/lib/locales/zh-Hans.json +1 -0
  67. package/src/lib/locales/zh-Hant.json +1 -0
  68. package/src/lib/react/components/settings.tsx +19 -0
  69. package/src/lib/react/source-feature.ts +10 -0
  70. package/src/lib/react/video-player.tsx +40 -1
  71. package/src/lib/remote/index.ts +48 -3
  72. package/src/lib/remote/protocol.ts +18 -6
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normale)",
3
3
  "Audio": "Audio",
4
+ "Autoplay next episode": "Riproduzione automatica dell’episodio successivo",
4
5
  "Copied": "Copiato",
5
6
  "Copy": "Copia",
6
7
  "Copy the errors": "Copia gli errori",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(標準)",
3
3
  "Audio": "音声",
4
+ "Autoplay next episode": "次のエピソードを自動再生",
4
5
  "Copied": "コピーしました",
5
6
  "Copy": "コピー",
6
7
  "Copy the errors": "エラーをコピー",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(보통)",
3
3
  "Audio": "오디오",
4
+ "Autoplay next episode": "다음 에피소드 자동 재생",
4
5
  "Copied": "복사됨",
5
6
  "Copy": "복사",
6
7
  "Copy the errors": "오류 복사",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Biasa)",
3
3
  "Audio": "Audio",
4
+ "Autoplay next episode": "Main episod seterusnya secara automatik",
4
5
  "Copied": "Disalin",
5
6
  "Copy": "Salin",
6
7
  "Copy the errors": "Salin ralat",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normaal)",
3
3
  "Audio": "Audio",
4
+ "Autoplay next episode": "Volgende aflevering automatisch afspelen",
4
5
  "Copied": "Gekopieerd",
5
6
  "Copy": "Kopiëren",
6
7
  "Copy the errors": "Fouten kopiëren",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normalna)",
3
3
  "Audio": "Dźwięk",
4
+ "Autoplay next episode": "Automatyczne odtwarzanie następnego odcinka",
4
5
  "Copied": "Skopiowano",
5
6
  "Copy": "Kopiuj",
6
7
  "Copy the errors": "Kopiuj błędy",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normal)",
3
3
  "Audio": "Áudio",
4
+ "Autoplay next episode": "Reprodução automática do próximo episódio",
4
5
  "Copied": "Copiado",
5
6
  "Copy": "Copiar",
6
7
  "Copy the errors": "Copiar os erros",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normală)",
3
3
  "Audio": "Audio",
4
+ "Autoplay next episode": "Redare automată a episodului următor",
4
5
  "Copied": "S-a copiat",
5
6
  "Copy": "Copiați",
6
7
  "Copy the errors": "Copiați erorile",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Обычная)",
3
3
  "Audio": "Аудио",
4
+ "Autoplay next episode": "Автовоспроизведение следующей серии",
4
5
  "Copied": "Скопировано",
5
6
  "Copy": "Копировать",
6
7
  "Copy the errors": "Копировать ошибки",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normal)",
3
3
  "Audio": "Ljud",
4
+ "Autoplay next episode": "Spela upp nästa avsnitt automatiskt",
4
5
  "Copied": "Kopierat",
5
6
  "Copy": "Kopiera",
6
7
  "Copy the errors": "Kopiera felen",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(ปกติ)",
3
3
  "Audio": "เสียง",
4
+ "Autoplay next episode": "เล่นตอนถัดไปอัตโนมัติ",
4
5
  "Copied": "คัดลอกแล้ว",
5
6
  "Copy": "คัดลอก",
6
7
  "Copy the errors": "คัดลอกข้อผิดพลาด",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Normal)",
3
3
  "Audio": "Ses",
4
+ "Autoplay next episode": "Sonraki bölümü otomatik oynat",
4
5
  "Copied": "Kopyalandı",
5
6
  "Copy": "Kopyala",
6
7
  "Copy the errors": "Hataları kopyala",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Звичайна)",
3
3
  "Audio": "Аудіо",
4
+ "Autoplay next episode": "Автоматично вмикати наступну серію",
4
5
  "Copied": "Скопійовано",
5
6
  "Copy": "Копіювати",
6
7
  "Copy the errors": "Копіювати помилки",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(Mặc định)",
3
3
  "Audio": "Âm thanh",
4
+ "Autoplay next episode": "Tự động phát tập tiếp theo",
4
5
  "Copied": "Đã sao chép",
5
6
  "Copy": "Sao chép",
6
7
  "Copy the errors": "Sao chép lỗi",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(正常)",
3
3
  "Audio": "音频",
4
+ "Autoplay next episode": "自动播放下一集",
4
5
  "Copied": "已复制",
5
6
  "Copy": "复制",
6
7
  "Copy the errors": "复制错误信息",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "(Default)": "(正常)",
3
3
  "Audio": "音訊",
4
+ "Autoplay next episode": "自動播放下一集",
4
5
  "Copied": "已複製",
5
6
  "Copy": "複製",
6
7
  "Copy the errors": "複製錯誤訊息",
@@ -36,6 +36,7 @@ ${popoverStyle}
36
36
  width: 28px;
37
37
  height: 16px;
38
38
  margin-right: 6px;
39
+ margin-left: 8px;
39
40
  border-radius: 8px;
40
41
  background-color: rgba(255,255,255,.3);
41
42
  transition: background-color 0.15s ease-in-out;
@@ -124,6 +125,7 @@ export const SettingsAction = () => {
124
125
  const selectAudioTrack = usePlayer((state) => state.selectAudioTrack)
125
126
  const quality = usePlayer((state) => state.quality)
126
127
  const volumeNormalizer = usePlayer((state) => state.volumeNormalizer)
128
+ const autoplayNext = usePlayer((state) => state.autoplayNext)
127
129
 
128
130
  const [popoverContent, setPopoverContent] = useState(PopoverContent.Default)
129
131
  const { open, toggle, containerRef, pending, failed, runSelect } = useTrackMenu({
@@ -180,7 +182,24 @@ export const SettingsAction = () => {
180
182
  so audio needs two tracks. Subtitles is NOT here: it has its own button in the bar,
181
183
  because it is the control in this player that gets reached for most and it does not
182
184
  belong two clicks deep next to playback speed.
185
+
186
+ Autoplay comes first: a host's next episode card sits over the lower right of the picture, where
187
+ the menu's last rows are.
183
188
  */}
189
+ {autoplayNext
190
+ ? (
191
+ <div
192
+ role='switch'
193
+ aria-checked={autoplayNext.enabled}
194
+ onClick={() => autoplayNext.setEnabled(!autoplayNext.enabled)}
195
+ >
196
+ <div>{format(LABELS.autoplayNext)}</div>
197
+ <div>
198
+ <span className={autoplayNext.enabled ? 'switch on' : 'switch'} />
199
+ </div>
200
+ </div>
201
+ )
202
+ : null}
184
203
  {audioTracks.length > 1
185
204
  ? (
186
205
  <div onClick={changePopoverContent(PopoverContent.Audio)}>
@@ -107,6 +107,12 @@ export type VolumeNormalizerControl = {
107
107
  setEnabled: (enabled: boolean) => void
108
108
  }
109
109
 
110
+ /** The settings menu's "Autoplay next episode" switch, for a host or an embedder that offers one (see `autoplayNext`). */
111
+ export type AutoplayNextControl = {
112
+ enabled: boolean
113
+ setEnabled: (enabled: boolean) => void
114
+ }
115
+
110
116
  /**
111
117
  * Everything about the source that the chrome reads, carried on the player store next to the built-in
112
118
  * playback state so a component never has to know which of two channels owns a field.
@@ -225,6 +231,9 @@ export type SourceState = {
225
231
  /** null when the player offers no volume normalizer: a media it does not own, or no `normalizerWorkletUrl`. */
226
232
  volumeNormalizer: VolumeNormalizerControl | null
227
233
 
234
+ /** null when neither the host nor an embedder offers the switch. */
235
+ autoplayNext: AutoplayNextControl | null
236
+
228
237
  /**
229
238
  * Move the playhead, letting the pipeline get the data there first.
230
239
  *
@@ -302,6 +311,7 @@ const initialState: SourceState = {
302
311
  pictureInPictureMode: null,
303
312
  burnedInSubtitles: false,
304
313
  volumeNormalizer: null,
314
+ autoplayNext: null,
305
315
  playbackError: null,
306
316
  playbackErrors: [],
307
317
  ready: false,
@@ -70,6 +70,16 @@ type CommonOptions = {
70
70
  title?: string
71
71
  autoplay?: boolean
72
72
 
73
+ /**
74
+ * The settings menu's "Autoplay next episode" switch, for a host that plays the next episode itself: the player plays
75
+ * nothing next. Without it, and with no embedder setting it through `expose`, there is no switch. The player keeps the
76
+ * switch's state from here and from the viewer's clicks; nothing is saved, so a host that wants it to stick saves
77
+ * what `onAutoplayNextChange` reports and passes it back. A value an embedder sets wins over this one.
78
+ */
79
+ autoplayNext?: boolean
80
+ /** The viewer flipped the switch, to `autoplayNext`: what a host saves to pass back as `autoplayNext`. */
81
+ onAutoplayNextChange?: (autoplayNext: boolean) => void
82
+
73
83
  /**
74
84
  * Named spans of the timeline, drawn as segments on the seekbar.
75
85
  *
@@ -388,12 +398,20 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
388
398
  // mirror made with `fullscreen: true` takes the fullscreen over.
389
399
  const [embedderFullscreen, setEmbedderFullscreen] = useState<boolean | null>(null)
390
400
  const [endingOffered, setEndingOffered] = useState(true)
391
- const [served] = useState<ServedPlayer & { chapters: MediaChapter[], endingOffered: boolean }>(
401
+ const [embedderAutoplayNext, setEmbedderAutoplayNext] = useState<boolean | null>(null)
402
+ const [autoplayNext, setAutoplayNext] = useState(options.autoplayNext)
403
+ const [served] = useState<ServedPlayer & { chapters: MediaChapter[], endingOffered: boolean, autoplayNext: boolean | null }>(
392
404
  () => Object.assign(new EventTarget(), {
393
405
  chapters: [],
394
406
  endingOffered: true,
407
+ autoplayNext: null,
395
408
  onHostFullscreen: setEmbedderFullscreen,
396
409
  onEndingOffered: setEndingOffered,
410
+ // each write applies, even one equal to the last: the viewer may have flipped the switch since
411
+ onAutoplayNext: (on: boolean | null) => {
412
+ setEmbedderAutoplayNext(on)
413
+ if (on !== null) setAutoplayNext(on)
414
+ },
397
415
  }),
398
416
  )
399
417
  const exposeOptions = expose === true ? {} : expose || undefined
@@ -425,6 +443,15 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
425
443
  served.dispatchEvent(new Event('chapterschange'))
426
444
  }, [chaptersKey, endingOffered])
427
445
 
446
+ const autoplayNextProp = options.autoplayNext
447
+ useEffect(() => { if (embedderAutoplayNext === null) setAutoplayNext(autoplayNextProp) }, [autoplayNextProp, embedderAutoplayNext])
448
+ const onAutoplayNextChange = useRef(options.onAutoplayNextChange)
449
+ onAutoplayNextChange.current = options.onAutoplayNextChange
450
+ useEffect(() => {
451
+ served.autoplayNext = autoplayNext ?? null
452
+ served.dispatchEvent(new Event('autoplaynextchange'))
453
+ }, [autoplayNext])
454
+
428
455
  const fullscreen = options.fullscreen ?? (embedderFullscreen === null ? undefined : {
429
456
  active: embedderFullscreen,
430
457
  request: () => served.dispatchEvent(new Event('fullscreenrequest')),
@@ -536,6 +563,18 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
536
563
  setSourceState({ volumeNormalizer })
537
564
  }, [setSourceState, volumeNormalizer])
538
565
 
566
+ useEffect(() => {
567
+ setSourceState({
568
+ autoplayNext: autoplayNext === undefined ? null : {
569
+ enabled: autoplayNext,
570
+ setEnabled: (enabled) => {
571
+ setAutoplayNext(enabled)
572
+ onAutoplayNextChange.current?.(enabled)
573
+ },
574
+ },
575
+ })
576
+ }, [setSourceState, autoplayNext])
577
+
539
578
  // its own effect: it changes on every hover of the control, and nothing else here does
540
579
  useEffect(() => {
541
580
  setSourceState({ passThroughPictureInPicture })
@@ -88,12 +88,18 @@ export type ExposePlayerOptions = {
88
88
  * with `fullscreen: true` takes over. While one has it, `onHostFullscreen` is told the state that mirror sets, and null
89
89
  * once none has it; the player then dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the
90
90
  * mirror. `onEndingOffered` is told what a mirror sets on `endingOffered`.
91
+ *
92
+ * `autoplayNext` is the state of its "Autoplay next episode" switch, null while it shows none, and it raises
93
+ * `autoplaynextchange` after each change. `onAutoplayNext` is told the state a mirror last set for its id, at serve
94
+ * and on each write, and null once no mirror listens to the id any more.
91
95
  */
92
96
  export type ServedPlayer = EventTarget & {
93
97
  readonly chapters: MediaChapter[]
94
98
  readonly endingOffered: boolean
99
+ readonly autoplayNext: boolean | null
95
100
  onHostFullscreen: (active: boolean | null) => void
96
101
  onEndingOffered: (offered: boolean) => void
102
+ onAutoplayNext: (on: boolean | null) => void
97
103
  }
98
104
 
99
105
  /**
@@ -162,9 +168,14 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
162
168
  const hosts = new Map<string, Set<MessagePort>>()
163
169
  const hostActive = new Map<string, boolean>()
164
170
  const tellHost = (id: string) => players.get(id)?.onHostFullscreen(hosts.get(id)?.size ? hostActive.get(id) ?? false : null)
171
+ // Kept per id rather than per player, since a document that puts up a player per file serves each under the same
172
+ // id, and the next one has to show the switch without the embedder writing it again.
173
+ const autoplayNext = new Map<string, boolean>()
174
+ const tellAutoplayNext = (id: string) => players.get(id)?.onAutoplayNext(autoplayNext.get(id) ?? null)
165
175
  const drop = (id: string, port: MessagePort) => {
166
176
  ports.get(id)?.delete(port)
167
177
  if (hosts.get(id)?.delete(port)) tellHost(id)
178
+ if (!ports.get(id)?.size && autoplayNext.delete(id)) tellAutoplayNext(id)
168
179
  try { port.onmessage = null; port.close() } catch {}
169
180
  }
170
181
  const post = (id: string, update: PlayerUpdate, to: Iterable<MessagePort> = listeners(id)) => {
@@ -177,7 +188,7 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
177
188
  const snapshotAt = (id: string) => {
178
189
  const media = medias.get(id)
179
190
  const around = players.get(id)
180
- return media ? snapshotOf(media, around?.chapters, around?.endingOffered) : undefined
191
+ return media ? snapshotOf(media, around?.chapters, around?.endingOffered, around?.autoplayNext) : undefined
181
192
  }
182
193
  const announce = (id: string, event: PlayerEvent) => {
183
194
  // a press of the fullscreen is for the mirrors that took it over: another one toggling too would undo it
@@ -231,6 +242,13 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
231
242
  if (typeof value === 'boolean') players.get(id)?.onEndingOffered(value)
232
243
  return
233
244
  }
245
+ if (name === 'autoplayNext') {
246
+ // only for an id a mirror listens to, which bounds the map, and is what clears it again
247
+ if (typeof value !== 'boolean' || !ports.get(id)?.size) return
248
+ autoplayNext.set(id, value)
249
+ tellAutoplayNext(id)
250
+ return
251
+ }
234
252
  const media = medias.get(id)
235
253
  if (!media || !WRITABLE.includes(name)) return
236
254
  try { (media as unknown as Record<Writable, unknown>)[name] = value } catch {}
@@ -282,7 +300,14 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
282
300
  const handlers = [
283
301
  ...PLAYER_EVENTS.map(event => [media, event] as const),
284
302
  ...around ? SERVED_EVENTS.map(event => [around, event] as const) : [],
285
- ].map(([target, event]) => [target, event, () => { if (medias.get(player) === media) announce(player, event) }] as const)
303
+ ].map(([target, event]) => [target, event, () => {
304
+ if (medias.get(player) !== media) return
305
+ // the viewer's flip is what the next player under this id starts in
306
+ if (event === 'autoplaynextchange' && autoplayNext.has(player) && typeof around?.autoplayNext === 'boolean') {
307
+ autoplayNext.set(player, around.autoplayNext)
308
+ }
309
+ announce(player, event)
310
+ }] as const)
286
311
  for (const [target, event, handler] of handlers) target.addEventListener(event, handler)
287
312
  const replaced = medias.has(player)
288
313
  const previous = players.get(player)
@@ -291,6 +316,7 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
291
316
  if (around) players.set(player, around)
292
317
  else players.delete(player)
293
318
  tellHost(player)
319
+ if (autoplayNext.has(player)) tellAutoplayNext(player)
294
320
  // the switch, told the way an element tells it: what was there is gone, and here is the new
295
321
  // one's state, ready to be synced from
296
322
  if (replaced) post(player, { event: 'emptied', snapshot: { ...EMPTY_SNAPSHOT } })
@@ -351,6 +377,18 @@ export type MediaPlayerHandle =
351
377
  * off the far screen, and a player that cannot take it (a bare element, a version older than this) stays true.
352
378
  */
353
379
  endingOffered: boolean
380
+ /**
381
+ * The far `<MediaPlayer expose>`'s "Autoplay next episode" switch, as it last said: null while it shows none. Set a
382
+ * boolean to have it show the switch in that state, for a page that plays the next episode itself and keeps the
383
+ * setting; the player plays nothing next and saves nothing. The far document keeps what was set for this player's
384
+ * id while any mirror of it is open, and shows it on every player it serves under that id, so a page that puts up
385
+ * a player per file needs to set it once. A viewer's flip there is kept the same way.
386
+ *
387
+ * Like `endingOffered`, a write does NOT move the mirror: a read answers what the far player reports, with an
388
+ * `autoplaynextchange` event following each change, so it stays null for a bare element or a version older than
389
+ * this. Nothing but a boolean is sent.
390
+ */
391
+ autoplayNext: boolean | null
354
392
  /**
355
393
  * Settles once the far side has first answered with its state; reads before that answer the
356
394
  * empty defaults. Stays pending for as long as nobody answers, and rejects with an AbortError on
@@ -435,7 +473,7 @@ type Subscriber = {
435
473
 
436
474
  type Link = {
437
475
  attach: (subscriber: Subscriber) => () => void
438
- set: (id: string, name: Writable | 'fullscreen' | 'endingOffered', value: number | boolean) => Promise<unknown> | undefined
476
+ set: (id: string, name: Writable | 'fullscreen' | 'endingOffered' | 'autoplayNext', value: number | boolean) => Promise<unknown> | undefined
439
477
  call: (id: string, name: Callable) => Promise<void>
440
478
  }
441
479
 
@@ -589,6 +627,7 @@ export const mediaPlayer = (
589
627
  const first = !answered
590
628
  answered = true
591
629
  const chapters = JSON.stringify(state.chapters)
630
+ const autoplayNext = state.autoplayNext
592
631
  Object.assign(state, snapshot)
593
632
  // a write the far side has not taken yet is the caller's intent, and outranks what the far
594
633
  // side is still reporting, first snapshot or any later one
@@ -597,6 +636,7 @@ export const mediaPlayer = (
597
636
  const events = first ? syncEventsFor(state) : [event]
598
637
  // told for any update that changes them: a catch-up or a switch's `emptied` brings chapters with no word of them
599
638
  if (!events.includes('chapterschange') && JSON.stringify(state.chapters) !== chapters) events.push('chapterschange')
639
+ if (!events.includes('autoplaynextchange') && state.autoplayNext !== autoplayNext) events.push('autoplaynextchange')
600
640
  for (const each of events) dispatch(each)
601
641
  if (first) settleReady()
602
642
  },
@@ -651,6 +691,11 @@ export const mediaPlayer = (
651
691
  set: (value: boolean) => { void after(() => link.set(playerId, 'endingOffered', value)) },
652
692
  enumerable: true,
653
693
  })
694
+ Object.defineProperty(player, 'autoplayNext', {
695
+ get: () => state.autoplayNext,
696
+ set: (value: boolean | null) => { if (typeof value === 'boolean') void after(() => link.set(playerId, 'autoplayNext', value)) },
697
+ enumerable: true,
698
+ })
654
699
 
655
700
  const call = (name: Callable) => ready.then(() => {
656
701
  if (signal.aborted) throw abortError()
@@ -33,6 +33,8 @@ export type PlayerSnapshot = {
33
33
  chapters: MediaChapter[]
34
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
35
  endingOffered: boolean
36
+ /** The state of a `<MediaPlayer expose>`'s "Autoplay next episode" switch, null while it shows none or for a bare element. */
37
+ autoplayNext: boolean | null
36
38
  }
37
39
 
38
40
  /**
@@ -47,10 +49,10 @@ export const PLAYER_EVENTS = [
47
49
  'canplay', 'canplaythrough', 'emptied', 'resize', 'error',
48
50
  ] as const
49
51
  /**
50
- * The events a `<MediaPlayer expose>` raises beside its media's: its chapters changed, and its viewer pressed
51
- * fullscreen while a mirror made with `fullscreen: true` has it.
52
+ * The events a `<MediaPlayer expose>` raises beside its media's: its chapters changed, its viewer pressed
53
+ * fullscreen while a mirror made with `fullscreen: true` has it, and its autoplay switch changed.
52
54
  */
53
- export const SERVED_EVENTS = ['chapterschange', 'fullscreenrequest'] as const
55
+ export const SERVED_EVENTS = ['chapterschange', 'fullscreenrequest', 'autoplaynextchange'] as const
54
56
  export type PlayerEvent = typeof PLAYER_EVENTS[number] | typeof SERVED_EVENTS[number]
55
57
 
56
58
  /** The properties an embedder may set. Everything else is read-only on a media, here as there. */
@@ -94,8 +96,11 @@ export type PlayerUpdate = { event: PlayerEvent, snapshot: PlayerSnapshot }
94
96
  export type PlayerService = {
95
97
  /** With `fullscreen`, the mirror takes the player's fullscreen over, in that state, until its port goes. */
96
98
  subscribe: (id: string, port: MessagePort, options?: { fullscreen?: boolean }) => void
97
- /** `fullscreen` is the state shown by a player whose fullscreen a mirror has taken over, and is ignored otherwise. */
98
- set: (id: string, name: Writable | 'fullscreen' | 'endingOffered', value: number | boolean) => void
99
+ /**
100
+ * `fullscreen` is the state shown by a player whose fullscreen a mirror has taken over, and is ignored otherwise.
101
+ * `autoplayNext` is kept for the id while a mirror listens to it, and told to each player served under it.
102
+ */
103
+ set: (id: string, name: Writable | 'fullscreen' | 'endingOffered' | 'autoplayNext', value: number | boolean) => void
99
104
  call: (id: string, name: Callable) => Promise<void>
100
105
  }
101
106
 
@@ -126,7 +131,12 @@ const pairs = (ranges: TimeRangesLike | undefined): [number, number][] => {
126
131
  }
127
132
 
128
133
  /** A media as a snapshot. A NaN duration, which a bare element answers before it has metadata, is sent as 0. */
129
- export const snapshotOf = (media: PlayerMedia, chapters: MediaChapter[] = [], endingOffered = true): PlayerSnapshot => ({
134
+ export const snapshotOf = (
135
+ media: PlayerMedia,
136
+ chapters: MediaChapter[] = [],
137
+ endingOffered = true,
138
+ autoplayNext: boolean | null = null,
139
+ ): PlayerSnapshot => ({
130
140
  currentTime: finite(media.currentTime),
131
141
  duration: finite(media.duration),
132
142
  paused: media.paused,
@@ -145,6 +155,7 @@ export const snapshotOf = (media: PlayerMedia, chapters: MediaChapter[] = [], en
145
155
  videoHeight: media.videoHeight ?? 0,
146
156
  chapters,
147
157
  endingOffered,
158
+ autoplayNext,
148
159
  })
149
160
 
150
161
  // NaN only. A live media reports `duration: Infinity` and means it, so sending 0 for it would mirror
@@ -156,6 +167,7 @@ export const EMPTY_SNAPSHOT: PlayerSnapshot = {
156
167
  currentTime: 0, duration: 0, paused: true, ended: false, seeking: false, readyState: 0,
157
168
  volume: 1, muted: false, playbackRate: 1, src: '', currentSrc: '',
158
169
  buffered: [], seekable: [], error: null, videoWidth: 0, videoHeight: 0, chapters: [], endingOffered: true,
170
+ autoplayNext: null,
159
171
  }
160
172
 
161
173
  /** Plain pairs back into the structural `TimeRanges` the player reads. */