@banou/media-player 0.10.54 → 0.10.55

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 (81) hide show
  1. package/dist/{ar-CWVutin3.js → ar-CSjwFY8l.js} +2 -0
  2. package/dist/{cs-CmwRGxyE.js → cs-Dk6IDwX9.js} +2 -0
  3. package/dist/{de-DLdKEf3t.js → de-G319tpSe.js} +2 -0
  4. package/dist/{el-Ckj-z6DX.js → el-CtRdEeUl.js} +2 -0
  5. package/dist/engine/index.d.ts +2 -0
  6. package/dist/engine/index.js +2 -2
  7. package/dist/engine/playback.d.ts +2 -0
  8. package/dist/engine/subtitle-convert.d.ts +8 -0
  9. package/dist/engine/subtitles.d.ts +2 -0
  10. package/dist/{engine-DZ6BX5XH.js → engine-tBJeFD6J.js} +285 -147
  11. package/dist/{es-419-zORhhU8D.js → es-419-BzuTB161.js} +2 -0
  12. package/dist/{fr-BtPmNkri.js → fr-BC0Ncjsm.js} +2 -0
  13. package/dist/{he-Bu79qEth.js → he-UutSGaSy.js} +2 -0
  14. package/dist/{hi-BsH3tSHa.js → hi-kNW0VH4d.js} +2 -0
  15. package/dist/{hu-BkYBW-YP.js → hu-UJBXN0lB.js} +2 -0
  16. package/dist/{id-nUaBCV4o.js → id-DYADKCdp.js} +2 -0
  17. package/dist/index.d.ts +4 -3
  18. package/dist/index.js +1188 -953
  19. package/dist/{it-CqPSHyFA.js → it-GodcqBoI.js} +2 -0
  20. package/dist/{ja-DTjvriHw.js → ja-r3FM4zNQ.js} +2 -0
  21. package/dist/{ko-dV8T7XOJ.js → ko-kNn9SZJT.js} +2 -0
  22. package/dist/labels.d.ts +2 -0
  23. package/dist/{ms-VZQ7BI0z.js → ms-B_95sgk7.js} +2 -0
  24. package/dist/{nl-Q6iDxbDz.js → nl-DUua8lM5.js} +2 -0
  25. package/dist/{pl-BN7bK74l.js → pl-DYN3cCvL.js} +2 -0
  26. package/dist/{pt-BR-CPFILeFW.js → pt-BR-CRH5nyyj.js} +2 -0
  27. package/dist/react/components/chrome.d.ts +3 -2
  28. package/dist/react/components/control-bar.d.ts +3 -2
  29. package/dist/react/hooks/use-playback.d.ts +1 -5
  30. package/dist/react/video-player.d.ts +29 -1
  31. package/dist/remote/index.d.ts +25 -2
  32. package/dist/remote/index.js +134 -68
  33. package/dist/remote/protocol.d.ts +22 -6
  34. package/dist/{ro-Bwcm-i3k.js → ro-lXdsKpft.js} +2 -0
  35. package/dist/{ru-D1FMz751.js → ru-Du_uJXdo.js} +2 -0
  36. package/dist/{sv-ci9K0Lkk.js → sv-CpEL6oGd.js} +2 -0
  37. package/dist/{th-DR-UBONQ.js → th-CQac_Jcd.js} +2 -0
  38. package/dist/{tr-BqhdfT22.js → tr-DLRAnIOh.js} +2 -0
  39. package/dist/{uk-8pkZqdni.js → uk-Cra5hJzT.js} +2 -0
  40. package/dist/{vi-3mKZ9G_M.js → vi-L2-IGJYQ.js} +2 -0
  41. package/dist/{zh-Hans-CDgigWKY.js → zh-Hans-Dp0UkPYn.js} +2 -0
  42. package/dist/{zh-Hant-3WSNI0ne.js → zh-Hant-CS16XV8X.js} +2 -0
  43. package/package.json +1 -1
  44. package/src/lib/engine/index.ts +3 -0
  45. package/src/lib/engine/playback.ts +4 -0
  46. package/src/lib/engine/subtitle-convert.ts +186 -0
  47. package/src/lib/engine/subtitles.ts +46 -7
  48. package/src/lib/index.tsx +7 -0
  49. package/src/lib/labels.ts +2 -0
  50. package/src/lib/locales/ar.json +2 -0
  51. package/src/lib/locales/cs.json +2 -0
  52. package/src/lib/locales/de.json +2 -0
  53. package/src/lib/locales/el.json +2 -0
  54. package/src/lib/locales/es-419.json +2 -0
  55. package/src/lib/locales/fr.json +2 -0
  56. package/src/lib/locales/he.json +2 -0
  57. package/src/lib/locales/hi.json +2 -0
  58. package/src/lib/locales/hu.json +2 -0
  59. package/src/lib/locales/id.json +2 -0
  60. package/src/lib/locales/it.json +2 -0
  61. package/src/lib/locales/ja.json +2 -0
  62. package/src/lib/locales/ko.json +2 -0
  63. package/src/lib/locales/ms.json +2 -0
  64. package/src/lib/locales/nl.json +2 -0
  65. package/src/lib/locales/pl.json +2 -0
  66. package/src/lib/locales/pt-BR.json +2 -0
  67. package/src/lib/locales/ro.json +2 -0
  68. package/src/lib/locales/ru.json +2 -0
  69. package/src/lib/locales/sv.json +2 -0
  70. package/src/lib/locales/th.json +2 -0
  71. package/src/lib/locales/tr.json +2 -0
  72. package/src/lib/locales/uk.json +2 -0
  73. package/src/lib/locales/vi.json +2 -0
  74. package/src/lib/locales/zh-Hans.json +2 -0
  75. package/src/lib/locales/zh-Hant.json +2 -0
  76. package/src/lib/react/components/chrome.tsx +4 -3
  77. package/src/lib/react/components/control-bar.tsx +51 -6
  78. package/src/lib/react/hooks/use-playback.ts +207 -15
  79. package/src/lib/react/video-player.tsx +116 -3
  80. package/src/lib/remote/index.ts +149 -12
  81. package/src/lib/remote/protocol.ts +32 -7
@@ -13,13 +13,13 @@
13
13
  import type { Message, ReceiveHandler, Remote, Transport } from 'osra'
14
14
  import type { MediaChapter } from '../engine'
15
15
  import type { PlayerMedia } from '../react/media'
16
- import type { Callable, PlayerEvent, PlayerService, PlayerSnapshot, PlayerUpdate, Writable } from './protocol'
16
+ import type { Callable, PlayerEvent, PlayerService, PlayerSnapshot, PlayerUpdate, RemoteExternalSubtitleTrack, Writable } from './protocol'
17
17
 
18
18
  import { expose } from 'osra'
19
19
 
20
20
  import { CALLABLE, DEFAULT_PLAYER_ID, EMPTY_SNAPSHOT, PLAYER_CHANNEL, PLAYER_EVENTS, SERVED_EVENTS, snapshotOf, syncEventsFor, toTimeRanges, WRITABLE } from './protocol'
21
21
 
22
- export type { PlayerEvent, PlayerSnapshot, PlayerUpdate } from './protocol'
22
+ export type { PlayerEvent, PlayerSnapshot, PlayerUpdate, RemoteExternalSubtitleTrack } from './protocol'
23
23
  export { DEFAULT_PLAYER_ID, PLAYER_CHANNEL, PLAYER_EVENTS, SERVED_EVENTS } from './protocol'
24
24
 
25
25
  /** How long a peer has to answer its handshake before the mirror stops waiting on it and moves on. */
@@ -100,6 +100,10 @@ export type ServedPlayer = EventTarget & {
100
100
  onHostFullscreen: (active: boolean | null) => void
101
101
  onEndingOffered: (offered: boolean) => void
102
102
  onAutoplayNext: (on: boolean | null) => void
103
+ onPreviousEpisode?: (step: boolean | string | null | undefined) => void
104
+ onNextEpisode?: (step: boolean | string | null | undefined) => void
105
+ onExternalSubtitles?: (tracks: RemoteExternalSubtitleTrack[] | null) => void
106
+ onProvideExternalSubtitle?: (trackId: string, content: string | null, error?: string) => void
103
107
  }
104
108
 
105
109
  /**
@@ -172,10 +176,21 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
172
176
  // id, and the next one has to show the switch without the embedder writing it again.
173
177
  const autoplayNext = new Map<string, boolean>()
174
178
  const tellAutoplayNext = (id: string) => players.get(id)?.onAutoplayNext(autoplayNext.get(id) ?? null)
179
+ const previousEpisode = new Map<string, boolean | string | null>()
180
+ const tellPreviousEpisode = (id: string) => players.get(id)?.onPreviousEpisode?.(previousEpisode.has(id) ? previousEpisode.get(id) : undefined)
181
+ const nextEpisode = new Map<string, boolean | string | null>()
182
+ const tellNextEpisode = (id: string) => players.get(id)?.onNextEpisode?.(nextEpisode.has(id) ? nextEpisode.get(id) : undefined)
183
+ const externalSubtitles = new Map<string, RemoteExternalSubtitleTrack[]>()
184
+ const tellExternalSubtitles = (id: string) => players.get(id)?.onExternalSubtitles?.(externalSubtitles.get(id) ?? null)
175
185
  const drop = (id: string, port: MessagePort) => {
176
186
  ports.get(id)?.delete(port)
177
187
  if (hosts.get(id)?.delete(port)) tellHost(id)
178
- if (!ports.get(id)?.size && autoplayNext.delete(id)) tellAutoplayNext(id)
188
+ if (!ports.get(id)?.size) {
189
+ if (autoplayNext.delete(id)) tellAutoplayNext(id)
190
+ if (previousEpisode.delete(id)) tellPreviousEpisode(id)
191
+ if (nextEpisode.delete(id)) tellNextEpisode(id)
192
+ if (externalSubtitles.delete(id)) tellExternalSubtitles(id)
193
+ }
179
194
  try { port.onmessage = null; port.close() } catch {}
180
195
  }
181
196
  const post = (id: string, update: PlayerUpdate, to: Iterable<MessagePort> = listeners(id)) => {
@@ -190,14 +205,14 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
190
205
  const around = players.get(id)
191
206
  return media ? snapshotOf(media, around?.chapters, around?.endingOffered, around?.autoplayNext) : undefined
192
207
  }
193
- const announce = (id: string, event: PlayerEvent) => {
208
+ const announce = (id: string, event: PlayerEvent, detail?: { trackId: string }) => {
194
209
  // a press of the fullscreen is for the mirrors that took it over: another one toggling too would undo it
195
210
  const to = event === 'fullscreenrequest' ? hosts.get(id) : ports.get(id)
196
211
  // nobody listening is the ordinary case for a player nobody mirrors, and `timeupdate` alone is
197
212
  // four snapshots a second for the life of the document
198
213
  if (!to?.size) return
199
214
  const snapshot = snapshotAt(id)
200
- if (snapshot) post(id, { event, snapshot }, to)
215
+ if (snapshot) post(id, detail ? { event, snapshot, detail } : { event, snapshot }, to)
201
216
  }
202
217
 
203
218
  const service: PlayerService = {
@@ -249,10 +264,46 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
249
264
  tellAutoplayNext(id)
250
265
  return
251
266
  }
267
+ if (name === 'previousEpisode' || name === 'nextEpisode') {
268
+ if ((typeof value !== 'boolean' && typeof value !== 'string' && value !== null) || !ports.get(id)?.size) return
269
+ if (name === 'previousEpisode') {
270
+ previousEpisode.set(id, value)
271
+ tellPreviousEpisode(id)
272
+ } else {
273
+ nextEpisode.set(id, value)
274
+ tellNextEpisode(id)
275
+ }
276
+ return
277
+ }
252
278
  const media = medias.get(id)
253
279
  if (!media || !WRITABLE.includes(name)) return
254
280
  try { (media as unknown as Record<Writable, unknown>)[name] = value } catch {}
255
281
  },
282
+ setExternalSubtitles: (id, tracks) => {
283
+ if (typeof id !== 'string' || !ports.get(id)?.size || !Array.isArray(tracks)) return
284
+ const normalized: RemoteExternalSubtitleTrack[] = []
285
+ for (const item of tracks) {
286
+ if (!item || typeof item !== 'object') continue
287
+ const { id: trackId, language, label, format, content } = item as Partial<RemoteExternalSubtitleTrack>
288
+ if (typeof trackId !== 'string' || typeof language !== 'string' || typeof label !== 'string') continue
289
+ if (format !== 'srt' && format !== 'vtt' && format !== 'ass') continue
290
+ normalized.push({
291
+ id: trackId,
292
+ language,
293
+ label,
294
+ format,
295
+ ...(typeof content === 'string' ? { content } : {}),
296
+ })
297
+ }
298
+ externalSubtitles.set(id, normalized)
299
+ tellExternalSubtitles(id)
300
+ },
301
+ provideExternalSubtitle: (id, trackId, content, error) => {
302
+ if (typeof id !== 'string' || typeof trackId !== 'string' || !ports.get(id)?.size) return
303
+ if (content !== null && typeof content !== 'string') return
304
+ if (error !== undefined && typeof error !== 'string') return
305
+ players.get(id)?.onProvideExternalSubtitle?.(trackId, content, error)
306
+ },
256
307
  call: async (id, name) => {
257
308
  const media = medias.get(id)
258
309
  if (!media || !CALLABLE.includes(name)) return
@@ -300,23 +351,35 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
300
351
  const handlers = [
301
352
  ...PLAYER_EVENTS.map(event => [media, event] as const),
302
353
  ...around ? SERVED_EVENTS.map(event => [around, event] as const) : [],
303
- ].map(([target, event]) => [target, event, () => {
354
+ ].map(([target, event]) => [target, event, (ev: Event) => {
304
355
  if (medias.get(player) !== media) return
305
356
  // the viewer's flip is what the next player under this id starts in
306
357
  if (event === 'autoplaynextchange' && autoplayNext.has(player) && typeof around?.autoplayNext === 'boolean') {
307
358
  autoplayNext.set(player, around.autoplayNext)
308
359
  }
309
- announce(player, event)
360
+ const rawDetail = event === 'subtitleloadrequest' ? (ev as { detail?: unknown }).detail : undefined
361
+ const detail = rawDetail && typeof rawDetail === 'object' && typeof (rawDetail as { trackId?: unknown }).trackId === 'string'
362
+ ? { trackId: (rawDetail as { trackId: string }).trackId }
363
+ : undefined
364
+ announce(player, event, detail)
310
365
  }] as const)
311
366
  for (const [target, event, handler] of handlers) target.addEventListener(event, handler)
312
367
  const replaced = medias.has(player)
313
368
  const previous = players.get(player)
314
- if (previous && previous !== around) previous.onHostFullscreen(null)
369
+ if (previous && previous !== around) {
370
+ previous.onHostFullscreen(null)
371
+ previous.onPreviousEpisode?.(undefined)
372
+ previous.onNextEpisode?.(undefined)
373
+ previous.onExternalSubtitles?.(null)
374
+ }
315
375
  medias.set(player, media)
316
376
  if (around) players.set(player, around)
317
377
  else players.delete(player)
318
378
  tellHost(player)
319
379
  if (autoplayNext.has(player)) tellAutoplayNext(player)
380
+ if (previousEpisode.has(player)) tellPreviousEpisode(player)
381
+ if (nextEpisode.has(player)) tellNextEpisode(player)
382
+ if (externalSubtitles.has(player)) tellExternalSubtitles(player)
320
383
  // the switch, told the way an element tells it: what was there is gone, and here is the new
321
384
  // one's state, ready to be synced from
322
385
  if (replaced) post(player, { event: 'emptied', snapshot: { ...EMPTY_SNAPSHOT } })
@@ -328,6 +391,9 @@ const channelFor = (options: ExposePlayerOptions): Channel => {
328
391
  if (around && players.get(player) === around) {
329
392
  players.delete(player)
330
393
  around.onHostFullscreen(null)
394
+ around.onPreviousEpisode?.(undefined)
395
+ around.onNextEpisode?.(undefined)
396
+ around.onExternalSubtitles?.(null)
331
397
  }
332
398
  post(player, { event: 'emptied', snapshot: { ...EMPTY_SNAPSHOT } })
333
399
  }
@@ -389,6 +455,25 @@ export type MediaPlayerHandle =
389
455
  * this. Nothing but a boolean is sent.
390
456
  */
391
457
  autoplayNext: boolean | null
458
+ /**
459
+ * Previous episode control shown by the far `<MediaPlayer expose>`. `true` shows with default label,
460
+ * a string shows with that tooltip title, and `false` or `null` hides it. Clicking emits `previousrequest`.
461
+ */
462
+ previousEpisode: boolean | string | null
463
+ /**
464
+ * Next episode control shown by the far `<MediaPlayer expose>`. `true` shows with default label,
465
+ * a string shows with that tooltip title, and `false` or `null` hides it. Clicking emits `nextrequest`.
466
+ */
467
+ nextEpisode: boolean | string | null
468
+ /**
469
+ * External subtitle tracks offered to the far `<MediaPlayer expose>`, persisted per player id while
470
+ * any mirror listens.
471
+ */
472
+ externalSubtitles: RemoteExternalSubtitleTrack[]
473
+ /** Updates the remote external subtitle tracks on the far player. */
474
+ setExternalSubtitles: (tracks: RemoteExternalSubtitleTrack[]) => void
475
+ /** Resolves or rejects a pending `subtitleloadrequest` emitted for `trackId`. */
476
+ provideExternalSubtitle: (trackId: string, content: string | null, error?: string) => void
392
477
  /**
393
478
  * Settles once the far side has first answered with its state; reads before that answer the
394
479
  * empty defaults. Stays pending for as long as nobody answers, and rejects with an AbortError on
@@ -473,7 +558,13 @@ type Subscriber = {
473
558
 
474
559
  type Link = {
475
560
  attach: (subscriber: Subscriber) => () => void
476
- set: (id: string, name: Writable | 'fullscreen' | 'endingOffered' | 'autoplayNext', value: number | boolean) => Promise<unknown> | undefined
561
+ set: (
562
+ id: string,
563
+ name: Writable | 'fullscreen' | 'endingOffered' | 'autoplayNext' | 'previousEpisode' | 'nextEpisode',
564
+ value: number | boolean | string | null,
565
+ ) => Promise<unknown> | undefined
566
+ setExternalSubtitles: (id: string, tracks: RemoteExternalSubtitleTrack[]) => Promise<unknown> | undefined
567
+ provideExternalSubtitle: (id: string, trackId: string, content: string | null, error?: string) => Promise<unknown> | undefined
477
568
  call: (id: string, name: Callable) => Promise<void>
478
569
  }
479
570
 
@@ -555,6 +646,8 @@ const linkTo = (target: HTMLIFrameElement | Window | Transport, options: MediaPl
555
646
  }
556
647
  },
557
648
  set: (id, name, value) => service?.set(id, name, value),
649
+ setExternalSubtitles: (id, tracks) => service?.setExternalSubtitles?.(id, tracks),
650
+ provideExternalSubtitle: (id, trackId, content, error) => service?.provideExternalSubtitle?.(id, trackId, content, error),
558
651
  call: async (id, name) => {
559
652
  if (!service) throw new DOMException('the remote player was closed', 'AbortError')
560
653
  await service.call(id, name)
@@ -597,7 +690,15 @@ export const mediaPlayer = (
597
690
  const playerId = options.id ?? DEFAULT_PLAYER_ID
598
691
  const state: PlayerSnapshot = { ...EMPTY_SNAPSHOT }
599
692
  const player = new EventTarget() as PlayerMedia & Record<string, unknown> & { ready: Promise<void>, destroy: () => void }
600
- const dispatch = (event: PlayerEvent) => player.dispatchEvent(new Event(event))
693
+ const dispatch = (event: PlayerEvent, detail?: { trackId: string }) => {
694
+ if (detail !== undefined) {
695
+ player.dispatchEvent(typeof CustomEvent === 'function'
696
+ ? new CustomEvent(event, { detail })
697
+ : Object.assign(new Event(event), { detail }))
698
+ return
699
+ }
700
+ player.dispatchEvent(new Event(event))
701
+ }
601
702
 
602
703
  let settleReady!: () => void
603
704
  let failReady!: (reason: unknown) => void
@@ -618,6 +719,9 @@ export const mediaPlayer = (
618
719
  // whether the far side has said anything about THIS player yet, which is what `ready` means
619
720
  let answered = false
620
721
  let fullscreen = false
722
+ let previousEpisode: boolean | string | null = null
723
+ let nextEpisode: boolean | string | null = null
724
+ let externalSubtitles: RemoteExternalSubtitleTrack[] = []
621
725
  let pauseCount = 0
622
726
  const pauseListeners = new Set<() => void>()
623
727
  const notePause = () => {
@@ -629,7 +733,7 @@ export const mediaPlayer = (
629
733
  id: playerId,
630
734
  fullscreen: options.fullscreen ? () => fullscreen : undefined,
631
735
  reset: () => { answered = false; settleAll() },
632
- update: ({ event, snapshot }) => {
736
+ update: ({ event, snapshot, detail }) => {
633
737
  const first = !answered
634
738
  answered = true
635
739
  const chapters = JSON.stringify(state.chapters)
@@ -644,7 +748,7 @@ export const mediaPlayer = (
644
748
  if (!events.includes('chapterschange') && JSON.stringify(state.chapters) !== chapters) events.push('chapterschange')
645
749
  if (!events.includes('autoplaynextchange') && state.autoplayNext !== autoplayNext) events.push('autoplaynextchange')
646
750
  if (!first && event === 'pause') notePause()
647
- for (const each of events) dispatch(each)
751
+ for (const each of events) dispatch(each, each === event ? detail : undefined)
648
752
  if (first) settleReady()
649
753
  },
650
754
  })
@@ -703,6 +807,39 @@ export const mediaPlayer = (
703
807
  set: (value: boolean | null) => { if (typeof value === 'boolean') void after(() => link.set(playerId, 'autoplayNext', value)) },
704
808
  enumerable: true,
705
809
  })
810
+ Object.defineProperty(player, 'previousEpisode', {
811
+ get: () => previousEpisode,
812
+ set: (value: boolean | string | null) => {
813
+ if (typeof value !== 'boolean' && typeof value !== 'string' && value !== null) return
814
+ previousEpisode = value
815
+ void after(() => link.set(playerId, 'previousEpisode', value))
816
+ },
817
+ enumerable: true,
818
+ })
819
+ Object.defineProperty(player, 'nextEpisode', {
820
+ get: () => nextEpisode,
821
+ set: (value: boolean | string | null) => {
822
+ if (typeof value !== 'boolean' && typeof value !== 'string' && value !== null) return
823
+ nextEpisode = value
824
+ void after(() => link.set(playerId, 'nextEpisode', value))
825
+ },
826
+ enumerable: true,
827
+ })
828
+ const updateExternalSubtitles = (tracks: RemoteExternalSubtitleTrack[]) => {
829
+ if (!Array.isArray(tracks)) return
830
+ const copy = tracks.map((track) => ({ ...track }))
831
+ externalSubtitles = copy
832
+ void after(() => link.setExternalSubtitles(playerId, copy))
833
+ }
834
+ Object.defineProperty(player, 'externalSubtitles', {
835
+ get: () => externalSubtitles,
836
+ set: updateExternalSubtitles,
837
+ enumerable: true,
838
+ })
839
+ player.setExternalSubtitles = updateExternalSubtitles
840
+ player.provideExternalSubtitle = (trackId: string, content: string | null, error?: string) => {
841
+ void after(() => link.provideExternalSubtitle(playerId, trackId, content, error))
842
+ }
706
843
 
707
844
  const call = (name: Callable) => ready.then(() => {
708
845
  if (signal.aborted) throw abortError()
@@ -1,9 +1,18 @@
1
1
  // What crosses between a player and whoever embeds it. Pure and osra-free so the snapshot and the
2
2
  // mirror's arithmetic can be tested on values; ./index.ts is the half that talks.
3
3
 
4
- import type { MediaChapter } from '../engine'
4
+ import type { ExternalSubtitleFormat, MediaChapter } from '../engine'
5
5
  import type { PlayerMedia, TimeRangesLike } from '../react/media'
6
6
 
7
+ /** External subtitle track description passed from an embedder to a framed player. */
8
+ export type RemoteExternalSubtitleTrack = {
9
+ id: string
10
+ language: string
11
+ label: string
12
+ format: ExternalSubtitleFormat
13
+ content?: string
14
+ }
15
+
7
16
  /**
8
17
  * Everything readable about a player, as one plain object.
9
18
  *
@@ -50,9 +59,17 @@ export const PLAYER_EVENTS = [
50
59
  ] as const
51
60
  /**
52
61
  * 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.
62
+ * fullscreen while a mirror made with `fullscreen: true` has it, its autoplay switch changed, the viewer
63
+ * clicked previous or next episode, or the player needs external subtitle content for a track id.
54
64
  */
55
- export const SERVED_EVENTS = ['chapterschange', 'fullscreenrequest', 'autoplaynextchange'] as const
65
+ export const SERVED_EVENTS = [
66
+ 'chapterschange',
67
+ 'fullscreenrequest',
68
+ 'autoplaynextchange',
69
+ 'previousrequest',
70
+ 'nextrequest',
71
+ 'subtitleloadrequest',
72
+ ] as const
56
73
  export type PlayerEvent = typeof PLAYER_EVENTS[number] | typeof SERVED_EVENTS[number]
57
74
 
58
75
  /** The properties an embedder may set. Everything else is read-only on a media, here as there. */
@@ -76,8 +93,8 @@ export const PLAYER_CHANNEL = 'banou-media-player'
76
93
  */
77
94
  export const DEFAULT_PLAYER_ID = 'default'
78
95
 
79
- /** What rides the event port: the event's name and the state right after it. */
80
- export type PlayerUpdate = { event: PlayerEvent, snapshot: PlayerSnapshot }
96
+ /** What rides the event port: the event's name, the state right after it, and any event payload. */
97
+ export type PlayerUpdate = { event: PlayerEvent, snapshot: PlayerSnapshot, detail?: { trackId: string } }
81
98
 
82
99
  /**
83
100
  * What the player's document serves, one document at a time, addressed by player id. Internal: an
@@ -98,10 +115,18 @@ export type PlayerService = {
98
115
  subscribe: (id: string, port: MessagePort, options?: { fullscreen?: boolean }) => void
99
116
  /**
100
117
  * `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.
118
+ * `autoplayNext`, `previousEpisode` and `nextEpisode` are kept for the id while a mirror listens to it, and told to each player served under it.
102
119
  */
103
- set: (id: string, name: Writable | 'fullscreen' | 'endingOffered' | 'autoplayNext', value: number | boolean) => void
120
+ set: (
121
+ id: string,
122
+ name: Writable | 'fullscreen' | 'endingOffered' | 'autoplayNext' | 'previousEpisode' | 'nextEpisode',
123
+ value: number | boolean | string | null,
124
+ ) => void
104
125
  call: (id: string, name: Callable) => Promise<void>
126
+ /** Sets the remote external subtitle tracks shown by the player served under `id`. */
127
+ setExternalSubtitles: (id: string, tracks: RemoteExternalSubtitleTrack[]) => void
128
+ /** Delivers loaded subtitle content (or an error when `content` is null) for a pending `subtitleloadrequest`. */
129
+ provideExternalSubtitle: (id: string, trackId: string, content: string | null, error?: string) => void
105
130
  }
106
131
 
107
132
  /**