@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.
@@ -1,6 +1,7 @@
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
5
  import type { PlayerMedia, TimeRangesLike } from '../react/media'
5
6
 
6
7
  /**
@@ -28,6 +29,8 @@ export type PlayerSnapshot = {
28
29
  error: { code: number, message: string } | null
29
30
  videoWidth: number
30
31
  videoHeight: number
32
+ /** A `<MediaPlayer expose>`'s chapters, empty for a bare element. */
33
+ chapters: MediaChapter[]
31
34
  }
32
35
 
33
36
  /**
@@ -41,7 +44,12 @@ export const PLAYER_EVENTS = [
41
44
  'seeking', 'seeked', 'progress', 'ratechange', 'volumechange', 'ended', 'waiting', 'stalled', 'suspend',
42
45
  'canplay', 'canplaythrough', 'emptied', 'resize', 'error',
43
46
  ] as const
44
- export type PlayerEvent = typeof PLAYER_EVENTS[number]
47
+ /**
48
+ * The events a `<MediaPlayer expose>` raises beside its media's: its chapters changed, and its viewer pressed
49
+ * fullscreen while a mirror made with `fullscreen: true` has it.
50
+ */
51
+ export const SERVED_EVENTS = ['chapterschange', 'fullscreenrequest'] as const
52
+ export type PlayerEvent = typeof PLAYER_EVENTS[number] | typeof SERVED_EVENTS[number]
45
53
 
46
54
  /** The properties an embedder may set. Everything else is read-only on a media, here as there. */
47
55
  export const WRITABLE = ['currentTime', 'volume', 'muted', 'playbackRate'] as const
@@ -82,8 +90,10 @@ export type PlayerUpdate = { event: PlayerEvent, snapshot: PlayerSnapshot }
82
90
  * has not mounted yet.
83
91
  */
84
92
  export type PlayerService = {
85
- subscribe: (id: string, port: MessagePort) => void
86
- set: (id: string, name: Writable, value: number | boolean) => void
93
+ /** With `fullscreen`, the mirror takes the player's fullscreen over, in that state, until its port goes. */
94
+ subscribe: (id: string, port: MessagePort, options?: { fullscreen?: boolean }) => void
95
+ /** `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
87
97
  call: (id: string, name: Callable) => Promise<void>
88
98
  }
89
99
 
@@ -114,7 +124,7 @@ const pairs = (ranges: TimeRangesLike | undefined): [number, number][] => {
114
124
  }
115
125
 
116
126
  /** A media as a snapshot. A NaN duration, which a bare element answers before it has metadata, is sent as 0. */
117
- export const snapshotOf = (media: PlayerMedia): PlayerSnapshot => ({
127
+ export const snapshotOf = (media: PlayerMedia, chapters: MediaChapter[] = []): PlayerSnapshot => ({
118
128
  currentTime: finite(media.currentTime),
119
129
  duration: finite(media.duration),
120
130
  paused: media.paused,
@@ -131,6 +141,7 @@ export const snapshotOf = (media: PlayerMedia): PlayerSnapshot => ({
131
141
  error: media.error ? { code: media.error.code, message: media.error.message } : null,
132
142
  videoWidth: media.videoWidth ?? 0,
133
143
  videoHeight: media.videoHeight ?? 0,
144
+ chapters,
134
145
  })
135
146
 
136
147
  // NaN only. A live media reports `duration: Infinity` and means it, so sending 0 for it would mirror
@@ -141,7 +152,7 @@ const finite = (value: number): number => Number.isNaN(value) ? 0 : value
141
152
  export const EMPTY_SNAPSHOT: PlayerSnapshot = {
142
153
  currentTime: 0, duration: 0, paused: true, ended: false, seeking: false, readyState: 0,
143
154
  volume: 1, muted: false, playbackRate: 1, src: '', currentSrc: '',
144
- buffered: [], seekable: [], error: null, videoWidth: 0, videoHeight: 0,
155
+ buffered: [], seekable: [], error: null, videoWidth: 0, videoHeight: 0, chapters: [],
145
156
  }
146
157
 
147
158
  /** Plain pairs back into the structural `TimeRanges` the player reads. */