@hanifhan1f/vidstack-react 1.12.34 → 1.12.36

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 (176) hide show
  1. package/package.json +1 -1
  2. package/player/layouts/default.d.ts +9 -1
  3. package/dev/chunks/vidstack-3rdEWplD.js +0 -189
  4. package/dev/chunks/vidstack-B-FM4-oZ.js +0 -668
  5. package/dev/chunks/vidstack-B92UncBI.js +0 -61
  6. package/dev/chunks/vidstack-BDiAEW1N.js +0 -11691
  7. package/dev/chunks/vidstack-BNwnoM-l.js +0 -84
  8. package/dev/chunks/vidstack-BOPSNTgH.js +0 -668
  9. package/dev/chunks/vidstack-BPymmnxm.js +0 -551
  10. package/dev/chunks/vidstack-BSZY6sbC.js +0 -180
  11. package/dev/chunks/vidstack-BSpAxhO6.js +0 -643
  12. package/dev/chunks/vidstack-BVVxkUlq.js +0 -288
  13. package/dev/chunks/vidstack-BXgKy_7V.js +0 -11693
  14. package/dev/chunks/vidstack-BalWqr4j.js +0 -1422
  15. package/dev/chunks/vidstack-Bfi_jCvb.js +0 -476
  16. package/dev/chunks/vidstack-BoLZuw80.js +0 -34
  17. package/dev/chunks/vidstack-BrqDQG-r.js +0 -643
  18. package/dev/chunks/vidstack-C3QPOZNd.js +0 -476
  19. package/dev/chunks/vidstack-C7BwfK5c.js +0 -1537
  20. package/dev/chunks/vidstack-CEUjDh4x.js +0 -34
  21. package/dev/chunks/vidstack-CFOPpDTy.js +0 -476
  22. package/dev/chunks/vidstack-CFZ0rYJz.js +0 -34
  23. package/dev/chunks/vidstack-CKsUl4ll.js +0 -1384
  24. package/dev/chunks/vidstack-CM82l-7o.js +0 -551
  25. package/dev/chunks/vidstack-CQSHFVu7.js +0 -401
  26. package/dev/chunks/vidstack-CXrXBlpD.js +0 -11692
  27. package/dev/chunks/vidstack-CevuS08D.js +0 -1504
  28. package/dev/chunks/vidstack-CkRXb9Ia.js +0 -1537
  29. package/dev/chunks/vidstack-CniPzPQc.js +0 -1537
  30. package/dev/chunks/vidstack-CqNX679o.js +0 -669
  31. package/dev/chunks/vidstack-Csfg08VS.js +0 -551
  32. package/dev/chunks/vidstack-CvWDiSTs.js +0 -84
  33. package/dev/chunks/vidstack-CzU-uC5f.js +0 -189
  34. package/dev/chunks/vidstack-D2Bi2Td9.js +0 -1537
  35. package/dev/chunks/vidstack-D3ZXOE4d.js +0 -643
  36. package/dev/chunks/vidstack-D6_9yy0x.js +0 -643
  37. package/dev/chunks/vidstack-DJQOTrl6.js +0 -180
  38. package/dev/chunks/vidstack-DNbKNc4R.js +0 -288
  39. package/dev/chunks/vidstack-DOtIyh4c.js +0 -288
  40. package/dev/chunks/vidstack-DTow20pt.js +0 -189
  41. package/dev/chunks/vidstack-DY2iivhG.js +0 -84
  42. package/dev/chunks/vidstack-DjqYvkVp.js +0 -84
  43. package/dev/chunks/vidstack-Dov8gjdq.js +0 -401
  44. package/dev/chunks/vidstack-DqaqkU4T.js +0 -9
  45. package/dev/chunks/vidstack-DwdhbP5c.js +0 -189
  46. package/dev/chunks/vidstack-DweQYzVw.js +0 -180
  47. package/dev/chunks/vidstack-FuCbl228.js +0 -226
  48. package/dev/chunks/vidstack-H9OdEKUQ.js +0 -375
  49. package/dev/chunks/vidstack-KntYDWMe.js +0 -668
  50. package/dev/chunks/vidstack-L5mw2iPb.js +0 -375
  51. package/dev/chunks/vidstack-NCBSBZE-.js +0 -61
  52. package/dev/chunks/vidstack-PREbBNMG.js +0 -125
  53. package/dev/chunks/vidstack-S_S6XDnL.js +0 -375
  54. package/dev/chunks/vidstack-UWMPvwsa.js +0 -1537
  55. package/dev/chunks/vidstack-f6WXkmfP.js +0 -375
  56. package/dev/chunks/vidstack-gqKBE4xH.js +0 -376
  57. package/dev/chunks/vidstack-iRuTLfhk.js +0 -61
  58. package/dev/chunks/vidstack-lYFZKRUc.js +0 -401
  59. package/dev/chunks/vidstack-oOGofWSl.js +0 -668
  60. package/dev/chunks/vidstack-vh0BKYWJ.js +0 -84
  61. package/prod/chunks/vidstack-0Foyib2F.js +0 -34
  62. package/prod/chunks/vidstack-58ZavMvv.js +0 -159
  63. package/prod/chunks/vidstack-B0SSIHIv.js +0 -1537
  64. package/prod/chunks/vidstack-B9nEslvl.js +0 -11197
  65. package/prod/chunks/vidstack-BCBskRpc.js +0 -664
  66. package/prod/chunks/vidstack-BOObgZd8.js +0 -504
  67. package/prod/chunks/vidstack-BS445j5D.js +0 -84
  68. package/prod/chunks/vidstack-BZVrgeRF.js +0 -9
  69. package/prod/chunks/vidstack-B_9VGrZQ.js +0 -504
  70. package/prod/chunks/vidstack-B_wD853-.js +0 -386
  71. package/prod/chunks/vidstack-BbPEqH3g.js +0 -11196
  72. package/prod/chunks/vidstack-Bh7M8kL6.js +0 -663
  73. package/prod/chunks/vidstack-BlPINAXN.js +0 -189
  74. package/prod/chunks/vidstack-Bm2UemPE.js +0 -470
  75. package/prod/chunks/vidstack-Bp_hAwzI.js +0 -61
  76. package/prod/chunks/vidstack-C4tNkfXj.js +0 -470
  77. package/prod/chunks/vidstack-C4tuISYG.js +0 -1504
  78. package/prod/chunks/vidstack-C5Rzkyfp.js +0 -375
  79. package/prod/chunks/vidstack-CKapDFwB.js +0 -376
  80. package/prod/chunks/vidstack-CNJwYQRW.js +0 -84
  81. package/prod/chunks/vidstack-CQll06Hv.js +0 -34
  82. package/prod/chunks/vidstack-CVzVtf1j.js +0 -61
  83. package/prod/chunks/vidstack-CYK75vJF.js +0 -1382
  84. package/prod/chunks/vidstack-CZNlvfmV.js +0 -288
  85. package/prod/chunks/vidstack-CbejzCJs.js +0 -1537
  86. package/prod/chunks/vidstack-CiQEyk_l.js +0 -189
  87. package/prod/chunks/vidstack-CiTWSpv_.js +0 -34
  88. package/prod/chunks/vidstack-CikQpsuo.js +0 -1537
  89. package/prod/chunks/vidstack-CtxjO6HG.js +0 -84
  90. package/prod/chunks/vidstack-CzjHdPIT.js +0 -375
  91. package/prod/chunks/vidstack-D0XCUWbp.js +0 -159
  92. package/prod/chunks/vidstack-D3cSYtez.js +0 -663
  93. package/prod/chunks/vidstack-D91K36KQ.js +0 -206
  94. package/prod/chunks/vidstack-DJThTSEm.js +0 -125
  95. package/prod/chunks/vidstack-DTyDOhwS.js +0 -504
  96. package/prod/chunks/vidstack-DVMwXUgY.js +0 -189
  97. package/prod/chunks/vidstack-DXSNXDnS.js +0 -1384
  98. package/prod/chunks/vidstack-D_Sd7838.js +0 -663
  99. package/prod/chunks/vidstack-D_ijTIbV.js +0 -11198
  100. package/prod/chunks/vidstack-DdiGCJVp.js +0 -504
  101. package/prod/chunks/vidstack-DgGDsAKh.js +0 -375
  102. package/prod/chunks/vidstack-DgsBXr1J.js +0 -84
  103. package/prod/chunks/vidstack-DhC5F6c8.js +0 -470
  104. package/prod/chunks/vidstack-DhSvljmQ.js +0 -375
  105. package/prod/chunks/vidstack-Djmla_FM.js +0 -545
  106. package/prod/chunks/vidstack-DpQw1Y33.js +0 -663
  107. package/prod/chunks/vidstack-DrEorv9m.js +0 -189
  108. package/prod/chunks/vidstack-Ma9rwtR0.js +0 -386
  109. package/prod/chunks/vidstack-VTpvHAdU.js +0 -1537
  110. package/prod/chunks/vidstack-dbLRgf2L.js +0 -159
  111. package/prod/chunks/vidstack-ehqxnvc9.js +0 -1537
  112. package/prod/chunks/vidstack-jIPoNqhj.js +0 -545
  113. package/prod/chunks/vidstack-lc8NHly9.js +0 -288
  114. package/prod/chunks/vidstack-rHvQ8f6c.js +0 -288
  115. package/prod/chunks/vidstack-rKV98aQH.js +0 -545
  116. package/prod/chunks/vidstack-uA7h-Bsq.js +0 -386
  117. package/prod/chunks/vidstack-xo_SmgiV.js +0 -84
  118. package/prod/chunks/vidstack-xvxeRtaN.js +0 -61
  119. package/server/chunks/vidstack--ufi23Q6.js +0 -1537
  120. package/server/chunks/vidstack-B3AXUfgF.js +0 -189
  121. package/server/chunks/vidstack-B4rJ1ZKK.js +0 -376
  122. package/server/chunks/vidstack-BJCx78pm.js +0 -386
  123. package/server/chunks/vidstack-BTdEfKqV.js +0 -84
  124. package/server/chunks/vidstack-BV_VpWlJ.js +0 -1537
  125. package/server/chunks/vidstack-BtitkRvR.js +0 -11198
  126. package/server/chunks/vidstack-BtqWstSj.js +0 -375
  127. package/server/chunks/vidstack-BweZhuNd.js +0 -1537
  128. package/server/chunks/vidstack-ByG5MvLs.js +0 -545
  129. package/server/chunks/vidstack-C-HdFsZi.js +0 -84
  130. package/server/chunks/vidstack-C0xOpWYR.js +0 -470
  131. package/server/chunks/vidstack-C481iXqe.js +0 -386
  132. package/server/chunks/vidstack-C4iWXMC-.js +0 -545
  133. package/server/chunks/vidstack-C5zFBMwg.js +0 -386
  134. package/server/chunks/vidstack-CEh38XpD.js +0 -288
  135. package/server/chunks/vidstack-CSiPajWY.js +0 -470
  136. package/server/chunks/vidstack-CbNRZgUA.js +0 -11197
  137. package/server/chunks/vidstack-CgXa6YO3.js +0 -61
  138. package/server/chunks/vidstack-CkMAeO-e.js +0 -34
  139. package/server/chunks/vidstack-Cm0qnRvu.js +0 -11196
  140. package/server/chunks/vidstack-CoGzBr_V.js +0 -663
  141. package/server/chunks/vidstack-Ct1NFlBa.js +0 -1537
  142. package/server/chunks/vidstack-CyFwkPiu.js +0 -470
  143. package/server/chunks/vidstack-D4t_SZbb.js +0 -1416
  144. package/server/chunks/vidstack-D7D9kiW6.js +0 -34
  145. package/server/chunks/vidstack-DH6N0AoF.js +0 -375
  146. package/server/chunks/vidstack-DJJmNib6.js +0 -504
  147. package/server/chunks/vidstack-DKr7br9D.js +0 -34
  148. package/server/chunks/vidstack-DM-5dPT-.js +0 -663
  149. package/server/chunks/vidstack-DOIUveQF.js +0 -504
  150. package/server/chunks/vidstack-DTn72IA8.js +0 -1504
  151. package/server/chunks/vidstack-DWfS9vAY.js +0 -84
  152. package/server/chunks/vidstack-DWt5LAKE.js +0 -375
  153. package/server/chunks/vidstack-DY51lx0R.js +0 -189
  154. package/server/chunks/vidstack-DbNoKLjz.js +0 -664
  155. package/server/chunks/vidstack-Dbs_rXUT.js +0 -663
  156. package/server/chunks/vidstack-DeS67_gx.js +0 -9
  157. package/server/chunks/vidstack-DiHlnSws.js +0 -1384
  158. package/server/chunks/vidstack-DnoqxmOs.js +0 -125
  159. package/server/chunks/vidstack-DsZKgA8y.js +0 -663
  160. package/server/chunks/vidstack-DtQSvsQr.js +0 -189
  161. package/server/chunks/vidstack-E7eUOyFt.js +0 -288
  162. package/server/chunks/vidstack-JkJEYEQM.js +0 -159
  163. package/server/chunks/vidstack-KhtuR229.js +0 -504
  164. package/server/chunks/vidstack-NXcLNXxO.js +0 -84
  165. package/server/chunks/vidstack-OKdxH1xx.js +0 -189
  166. package/server/chunks/vidstack-SkX-mSrw.js +0 -206
  167. package/server/chunks/vidstack-VGPw_CQP.js +0 -375
  168. package/server/chunks/vidstack-X1Hex9PH.js +0 -84
  169. package/server/chunks/vidstack-i9a2TQLO.js +0 -1537
  170. package/server/chunks/vidstack-iVN8uBAv.js +0 -288
  171. package/server/chunks/vidstack-jlaBqZq5.js +0 -61
  172. package/server/chunks/vidstack-m8aA99tE.js +0 -159
  173. package/server/chunks/vidstack-rUHVQoo3.js +0 -61
  174. package/server/chunks/vidstack-rWs25cS9.js +0 -159
  175. package/server/chunks/vidstack-uyCXITen.js +0 -504
  176. package/server/chunks/vidstack-yf18YVAb.js +0 -545
@@ -1,476 +0,0 @@
1
- "use client"
2
-
3
- import { listenEvent, effect, untrack, createScope, keysOf, onDispose, DOMEvent, peek } from './vidstack-D_bWd66h.js';
4
- import { ListSymbol, TimeRange, RAFLoop } from './vidstack-BXgKy_7V.js';
5
- import { getCastSessionMedia, getCastContext, getCastSession, hasActiveCastSession, listenCastContextEvent, getCastErrorMessage } from './vidstack-BSZY6sbC.js';
6
- import 'react';
7
- import '@floating-ui/dom';
8
-
9
- class GoogleCastMediaInfoBuilder {
10
- #info;
11
- constructor(src) {
12
- this.#info = new chrome.cast.media.MediaInfo(src.src, src.type);
13
- }
14
- build() {
15
- return this.#info;
16
- }
17
- setStreamType(streamType) {
18
- if (streamType.includes("live")) {
19
- this.#info.streamType = chrome.cast.media.StreamType.LIVE;
20
- } else {
21
- this.#info.streamType = chrome.cast.media.StreamType.BUFFERED;
22
- }
23
- return this;
24
- }
25
- setTracks(tracks) {
26
- this.#info.tracks = tracks.map(this.#buildCastTrack);
27
- return this;
28
- }
29
- setMetadata(title, poster) {
30
- this.#info.metadata = new chrome.cast.media.GenericMediaMetadata();
31
- this.#info.metadata.title = title;
32
- this.#info.metadata.images = [{ url: poster }];
33
- return this;
34
- }
35
- #buildCastTrack(track, trackId) {
36
- const castTrack = new chrome.cast.media.Track(trackId, chrome.cast.media.TrackType.TEXT);
37
- castTrack.name = track.label;
38
- castTrack.trackContentId = track.src;
39
- castTrack.trackContentType = "text/vtt";
40
- castTrack.language = track.language;
41
- castTrack.subtype = track.kind.toUpperCase();
42
- return castTrack;
43
- }
44
- }
45
-
46
- class GoogleCastTracksManager {
47
- #cast;
48
- #ctx;
49
- #onNewLocalTracks;
50
- constructor(cast, ctx, onNewLocalTracks) {
51
- this.#cast = cast;
52
- this.#ctx = ctx;
53
- this.#onNewLocalTracks = onNewLocalTracks;
54
- }
55
- setup() {
56
- const syncRemoteActiveIds = this.syncRemoteActiveIds.bind(this);
57
- listenEvent(this.#ctx.audioTracks, "change", syncRemoteActiveIds);
58
- listenEvent(this.#ctx.textTracks, "mode-change", syncRemoteActiveIds);
59
- effect(this.#syncLocalTracks.bind(this));
60
- }
61
- getLocalTextTracks() {
62
- return this.#ctx.$state.textTracks().filter((track) => track.src && track.type === "vtt");
63
- }
64
- #getLocalAudioTracks() {
65
- return this.#ctx.$state.audioTracks();
66
- }
67
- #getRemoteTracks(type) {
68
- const tracks = this.#cast.mediaInfo?.tracks ?? [];
69
- return type ? tracks.filter((track) => track.type === type) : tracks;
70
- }
71
- #getRemoteActiveIds() {
72
- const activeIds = [], activeLocalAudioTrack = this.#getLocalAudioTracks().find((track) => track.selected), activeLocalTextTracks = this.getLocalTextTracks().filter((track) => track.mode === "showing");
73
- if (activeLocalAudioTrack) {
74
- const remoteAudioTracks = this.#getRemoteTracks(chrome.cast.media.TrackType.AUDIO), remoteAudioTrack = this.#findRemoteTrack(remoteAudioTracks, activeLocalAudioTrack);
75
- if (remoteAudioTrack) activeIds.push(remoteAudioTrack.trackId);
76
- }
77
- if (activeLocalTextTracks?.length) {
78
- const remoteTextTracks = this.#getRemoteTracks(chrome.cast.media.TrackType.TEXT);
79
- if (remoteTextTracks.length) {
80
- for (const localTrack of activeLocalTextTracks) {
81
- const remoteTextTrack = this.#findRemoteTrack(remoteTextTracks, localTrack);
82
- if (remoteTextTrack) activeIds.push(remoteTextTrack.trackId);
83
- }
84
- }
85
- }
86
- return activeIds;
87
- }
88
- #syncLocalTracks() {
89
- const localTextTracks = this.getLocalTextTracks();
90
- if (!this.#cast.isMediaLoaded) return;
91
- const remoteTextTracks = this.#getRemoteTracks(chrome.cast.media.TrackType.TEXT);
92
- for (const localTrack of localTextTracks) {
93
- const hasRemoteTrack = this.#findRemoteTrack(remoteTextTracks, localTrack);
94
- if (!hasRemoteTrack) {
95
- untrack(() => this.#onNewLocalTracks?.());
96
- break;
97
- }
98
- }
99
- }
100
- syncRemoteTracks(event) {
101
- if (!this.#cast.isMediaLoaded) return;
102
- const localAudioTracks = this.#getLocalAudioTracks(), localTextTracks = this.getLocalTextTracks(), remoteAudioTracks = this.#getRemoteTracks(chrome.cast.media.TrackType.AUDIO), remoteTextTracks = this.#getRemoteTracks(chrome.cast.media.TrackType.TEXT);
103
- for (const remoteAudioTrack of remoteAudioTracks) {
104
- const hasLocalTrack = this.#findLocalTrack(localAudioTracks, remoteAudioTrack);
105
- if (hasLocalTrack) continue;
106
- const localAudioTrack = {
107
- id: remoteAudioTrack.trackId.toString(),
108
- label: remoteAudioTrack.name,
109
- language: remoteAudioTrack.language,
110
- kind: remoteAudioTrack.subtype ?? "main",
111
- selected: false
112
- };
113
- this.#ctx.audioTracks[ListSymbol.add](localAudioTrack, event);
114
- }
115
- for (const remoteTextTrack of remoteTextTracks) {
116
- const hasLocalTrack = this.#findLocalTrack(localTextTracks, remoteTextTrack);
117
- if (hasLocalTrack) continue;
118
- const localTextTrack = {
119
- id: remoteTextTrack.trackId.toString(),
120
- src: remoteTextTrack.trackContentId,
121
- label: remoteTextTrack.name,
122
- language: remoteTextTrack.language,
123
- kind: remoteTextTrack.subtype.toLowerCase()
124
- };
125
- this.#ctx.textTracks.add(localTextTrack, event);
126
- }
127
- }
128
- syncRemoteActiveIds(event) {
129
- if (!this.#cast.isMediaLoaded) return;
130
- const activeIds = this.#getRemoteActiveIds(), editRequest = new chrome.cast.media.EditTracksInfoRequest(activeIds);
131
- this.#editTracksInfo(editRequest).catch((error) => {
132
- {
133
- this.#ctx.logger?.errorGroup("[vidstack] failed to edit cast tracks info").labelledLog("Edit Request", editRequest).labelledLog("Error", error).dispatch();
134
- }
135
- });
136
- }
137
- #editTracksInfo(request) {
138
- const media = getCastSessionMedia();
139
- return new Promise((resolve, reject) => media?.editTracksInfo(request, resolve, reject));
140
- }
141
- #findLocalTrack(localTracks, remoteTrack) {
142
- return localTracks.find((localTrack) => this.#isMatch(localTrack, remoteTrack));
143
- }
144
- #findRemoteTrack(remoteTracks, localTrack) {
145
- return remoteTracks.find((remoteTrack) => this.#isMatch(localTrack, remoteTrack));
146
- }
147
- // Note: we can't rely on id matching because they will differ between local/remote. A local
148
- // track id might not even exist.
149
- #isMatch(localTrack, remoteTrack) {
150
- return remoteTrack.name === localTrack.label && remoteTrack.language === localTrack.language && remoteTrack.subtype.toLowerCase() === localTrack.kind.toLowerCase();
151
- }
152
- }
153
-
154
- class GoogleCastProvider {
155
- $$PROVIDER_TYPE = "GOOGLE_CAST";
156
- scope = createScope();
157
- #player;
158
- #ctx;
159
- #tracks;
160
- #currentSrc = null;
161
- #state = "disconnected";
162
- #currentTime = 0;
163
- #played = 0;
164
- #seekableRange = new TimeRange(0, 0);
165
- #timeRAF = new RAFLoop(this.#onAnimationFrame.bind(this));
166
- #playerEventHandlers;
167
- #reloadInfo = null;
168
- #isIdle = false;
169
- constructor(player, ctx) {
170
- this.#player = player;
171
- this.#ctx = ctx;
172
- this.#tracks = new GoogleCastTracksManager(player, ctx, this.#onNewLocalTracks.bind(this));
173
- }
174
- get type() {
175
- return "google-cast";
176
- }
177
- get currentSrc() {
178
- return this.#currentSrc;
179
- }
180
- /**
181
- * The Google Cast remote player.
182
- *
183
- * @see {@link https://developers.google.com/cast/docs/reference/web_sender/cast.framework.RemotePlayer}
184
- */
185
- get player() {
186
- return this.#player;
187
- }
188
- /**
189
- * @see {@link https://developers.google.com/cast/docs/reference/web_sender/cast.framework.CastContext}
190
- */
191
- get cast() {
192
- return getCastContext();
193
- }
194
- /**
195
- * @see {@link https://developers.google.com/cast/docs/reference/web_sender/cast.framework.CastSession}
196
- */
197
- get session() {
198
- return getCastSession();
199
- }
200
- /**
201
- * @see {@link https://developers.google.com/cast/docs/reference/web_sender/chrome.cast.media.Media}
202
- */
203
- get media() {
204
- return getCastSessionMedia();
205
- }
206
- /**
207
- * Whether the current Google Cast session belongs to this provider.
208
- */
209
- get hasActiveSession() {
210
- return hasActiveCastSession(this.#currentSrc);
211
- }
212
- setup() {
213
- this.#attachCastContextEventListeners();
214
- this.#attachCastPlayerEventListeners();
215
- this.#tracks.setup();
216
- this.#ctx.notify("provider-setup", this);
217
- }
218
- #attachCastContextEventListeners() {
219
- listenCastContextEvent(
220
- cast.framework.CastContextEventType.CAST_STATE_CHANGED,
221
- this.#onCastStateChange.bind(this)
222
- );
223
- }
224
- #attachCastPlayerEventListeners() {
225
- const Event2 = cast.framework.RemotePlayerEventType, handlers = {
226
- [Event2.IS_CONNECTED_CHANGED]: this.#onCastStateChange,
227
- [Event2.IS_MEDIA_LOADED_CHANGED]: this.#onMediaLoadedChange,
228
- [Event2.CAN_CONTROL_VOLUME_CHANGED]: this.#onCanControlVolumeChange,
229
- [Event2.CAN_SEEK_CHANGED]: this.#onCanSeekChange,
230
- [Event2.DURATION_CHANGED]: this.#onDurationChange,
231
- [Event2.IS_MUTED_CHANGED]: this.#onVolumeChange,
232
- [Event2.VOLUME_LEVEL_CHANGED]: this.#onVolumeChange,
233
- [Event2.IS_PAUSED_CHANGED]: this.#onPausedChange,
234
- [Event2.LIVE_SEEKABLE_RANGE_CHANGED]: this.#onProgress,
235
- [Event2.PLAYER_STATE_CHANGED]: this.#onPlayerStateChange
236
- };
237
- this.#playerEventHandlers = handlers;
238
- const handler = this.#onRemotePlayerEvent.bind(this);
239
- for (const type of keysOf(handlers)) {
240
- this.#player.controller.addEventListener(type, handler);
241
- }
242
- onDispose(() => {
243
- for (const type of keysOf(handlers)) {
244
- this.#player.controller.removeEventListener(type, handler);
245
- }
246
- });
247
- }
248
- async play() {
249
- if (!this.#player.isPaused && !this.#isIdle) return;
250
- if (this.#isIdle) {
251
- await this.#reload(false, 0);
252
- return;
253
- }
254
- this.#player.controller?.playOrPause();
255
- }
256
- async pause() {
257
- if (this.#player.isPaused) return;
258
- this.#player.controller?.playOrPause();
259
- }
260
- getMediaStatus(request) {
261
- return new Promise((resolve, reject) => {
262
- this.media?.getStatus(request, resolve, reject);
263
- });
264
- }
265
- setMuted(muted) {
266
- const hasChanged = muted && !this.#player.isMuted || !muted && this.#player.isMuted;
267
- if (hasChanged) this.#player.controller?.muteOrUnmute();
268
- }
269
- setCurrentTime(time) {
270
- this.#player.currentTime = time;
271
- this.#ctx.notify("seeking", time);
272
- this.#player.controller?.seek();
273
- }
274
- setVolume(volume) {
275
- this.#player.volumeLevel = volume;
276
- this.#player.controller?.setVolumeLevel();
277
- }
278
- async loadSource(src) {
279
- if (this.#reloadInfo?.src !== src) this.#reloadInfo = null;
280
- if (hasActiveCastSession(src)) {
281
- this.#resumeSession();
282
- this.#currentSrc = src;
283
- return;
284
- }
285
- this.#ctx.notify("load-start");
286
- const loadRequest = this.#buildLoadRequest(src), errorCode = await this.session.loadMedia(loadRequest);
287
- if (errorCode) {
288
- this.#currentSrc = null;
289
- this.#ctx.notify("error", Error(getCastErrorMessage(errorCode)));
290
- return;
291
- }
292
- this.#currentSrc = src;
293
- }
294
- destroy() {
295
- this.#reset();
296
- this.#endSession();
297
- }
298
- #reset() {
299
- if (!this.#reloadInfo) {
300
- this.#played = 0;
301
- this.#seekableRange = new TimeRange(0, 0);
302
- }
303
- this.#timeRAF.stop();
304
- this.#currentTime = 0;
305
- this.#reloadInfo = null;
306
- }
307
- #resumeSession() {
308
- const resumeSessionEvent = new DOMEvent("resume-session", { detail: this.session });
309
- this.#onMediaLoadedChange(resumeSessionEvent);
310
- const { muted, volume, savedState } = this.#ctx.$state, localState = savedState();
311
- this.setCurrentTime(Math.max(this.#player.currentTime, localState?.currentTime ?? 0));
312
- this.setMuted(muted());
313
- this.setVolume(volume());
314
- if (localState?.paused === false) this.play();
315
- }
316
- #endSession() {
317
- this.cast.endCurrentSession(true);
318
- const { remotePlaybackLoader } = this.#ctx.$state;
319
- remotePlaybackLoader.set(null);
320
- }
321
- #disconnectFromReceiver() {
322
- const { savedState } = this.#ctx.$state;
323
- savedState.set({
324
- paused: this.#player.isPaused,
325
- currentTime: this.#player.currentTime
326
- });
327
- this.#endSession();
328
- }
329
- #onAnimationFrame() {
330
- this.#onCurrentTimeChange();
331
- }
332
- #onRemotePlayerEvent(event) {
333
- this.#playerEventHandlers[event.type].call(this, event);
334
- }
335
- #onCastStateChange(data) {
336
- const castState = this.cast.getCastState(), state = castState === cast.framework.CastState.CONNECTED ? "connected" : castState === cast.framework.CastState.CONNECTING ? "connecting" : "disconnected";
337
- if (this.#state === state) return;
338
- const detail = { type: "google-cast", state }, trigger = this.#createEvent(data);
339
- this.#state = state;
340
- this.#ctx.notify("remote-playback-change", detail, trigger);
341
- if (state === "disconnected") {
342
- this.#disconnectFromReceiver();
343
- }
344
- }
345
- #onMediaLoadedChange(event) {
346
- const hasLoaded = !!this.#player.isMediaLoaded;
347
- if (!hasLoaded) return;
348
- const src = peek(this.#ctx.$state.source);
349
- Promise.resolve().then(() => {
350
- if (src !== peek(this.#ctx.$state.source) || !this.#player.isMediaLoaded) return;
351
- this.#reset();
352
- const duration = this.#player.duration;
353
- this.#seekableRange = new TimeRange(0, duration);
354
- const detail = {
355
- provider: this,
356
- duration,
357
- buffered: new TimeRange(0, 0),
358
- seekable: this.#getSeekableRange()
359
- }, trigger = this.#createEvent(event);
360
- this.#ctx.notify("loaded-metadata", void 0, trigger);
361
- this.#ctx.notify("loaded-data", void 0, trigger);
362
- this.#ctx.notify("can-play", detail, trigger);
363
- this.#onCanControlVolumeChange();
364
- this.#onCanSeekChange(event);
365
- const { volume, muted } = this.#ctx.$state;
366
- this.setVolume(volume());
367
- this.setMuted(muted());
368
- this.#timeRAF.start();
369
- this.#tracks.syncRemoteTracks(trigger);
370
- this.#tracks.syncRemoteActiveIds(trigger);
371
- });
372
- }
373
- #onCanControlVolumeChange() {
374
- this.#ctx.$state.canSetVolume.set(this.#player.canControlVolume);
375
- }
376
- #onCanSeekChange(event) {
377
- const trigger = this.#createEvent(event);
378
- this.#ctx.notify("stream-type-change", this.#getStreamType(), trigger);
379
- }
380
- #getStreamType() {
381
- const streamType = this.#player.mediaInfo?.streamType;
382
- return streamType === chrome.cast.media.StreamType.LIVE ? this.#player.canSeek ? "live:dvr" : "live" : "on-demand";
383
- }
384
- #onCurrentTimeChange() {
385
- if (this.#reloadInfo) return;
386
- const currentTime = this.#player.currentTime;
387
- if (currentTime === this.#currentTime) return;
388
- this.#ctx.notify("time-change", currentTime);
389
- if (currentTime > this.#played) {
390
- this.#played = currentTime;
391
- this.#onProgress();
392
- }
393
- if (this.#ctx.$state.seeking()) {
394
- this.#ctx.notify("seeked", currentTime);
395
- }
396
- this.#currentTime = currentTime;
397
- }
398
- #onDurationChange(event) {
399
- if (!this.#player.isMediaLoaded || this.#reloadInfo) return;
400
- const duration = this.#player.duration, trigger = this.#createEvent(event);
401
- this.#seekableRange = new TimeRange(0, duration);
402
- this.#ctx.notify("duration-change", duration, trigger);
403
- }
404
- #onVolumeChange(event) {
405
- if (!this.#player.isMediaLoaded) return;
406
- const detail = {
407
- muted: this.#player.isMuted,
408
- volume: this.#player.volumeLevel
409
- }, trigger = this.#createEvent(event);
410
- this.#ctx.notify("volume-change", detail, trigger);
411
- }
412
- #onPausedChange(event) {
413
- const trigger = this.#createEvent(event);
414
- if (this.#player.isPaused) {
415
- this.#ctx.notify("pause", void 0, trigger);
416
- } else {
417
- this.#ctx.notify("play", void 0, trigger);
418
- }
419
- }
420
- #onProgress(event) {
421
- const detail = {
422
- seekable: this.#getSeekableRange(),
423
- buffered: new TimeRange(0, this.#played)
424
- }, trigger = event ? this.#createEvent(event) : void 0;
425
- this.#ctx.notify("progress", detail, trigger);
426
- }
427
- #onPlayerStateChange(event) {
428
- const state = this.#player.playerState, PlayerState = chrome.cast.media.PlayerState;
429
- this.#isIdle = state === PlayerState.IDLE;
430
- if (state === PlayerState.PAUSED) return;
431
- const trigger = this.#createEvent(event);
432
- switch (state) {
433
- case PlayerState.PLAYING:
434
- this.#ctx.notify("playing", void 0, trigger);
435
- break;
436
- case PlayerState.BUFFERING:
437
- this.#ctx.notify("waiting", void 0, trigger);
438
- break;
439
- case PlayerState.IDLE:
440
- this.#timeRAF.stop();
441
- this.#ctx.notify("pause");
442
- this.#ctx.notify("end");
443
- break;
444
- }
445
- }
446
- #getSeekableRange() {
447
- return this.#player.liveSeekableRange ? new TimeRange(this.#player.liveSeekableRange.start, this.#player.liveSeekableRange.end) : this.#seekableRange;
448
- }
449
- #createEvent(detail) {
450
- return detail instanceof Event ? detail : new DOMEvent(detail.type, { detail });
451
- }
452
- #buildMediaInfo(src) {
453
- const { streamType, title, poster } = this.#ctx.$state;
454
- return new GoogleCastMediaInfoBuilder(src).setMetadata(title(), poster()).setStreamType(streamType()).setTracks(this.#tracks.getLocalTextTracks()).build();
455
- }
456
- #buildLoadRequest(src) {
457
- const mediaInfo = this.#buildMediaInfo(src), request = new chrome.cast.media.LoadRequest(mediaInfo), savedState = this.#ctx.$state.savedState();
458
- request.autoplay = (this.#reloadInfo?.paused ?? savedState?.paused) === false;
459
- request.currentTime = this.#reloadInfo?.time ?? savedState?.currentTime ?? 0;
460
- return request;
461
- }
462
- async #reload(paused, time) {
463
- const src = peek(this.#ctx.$state.source);
464
- this.#reloadInfo = { src, paused, time };
465
- await this.loadSource(src);
466
- }
467
- #onNewLocalTracks() {
468
- this.#reload(this.#player.isPaused, this.#player.currentTime).catch((error) => {
469
- {
470
- this.#ctx.logger?.errorGroup("[vidstack] cast failed to load new local tracks").labelledLog("Error", error).dispatch();
471
- }
472
- });
473
- }
474
- }
475
-
476
- export { GoogleCastProvider };