@hanifhan1f/vidstack-react 1.12.33 → 1.12.35

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 (188) hide show
  1. package/dev/chunks/{vidstack-3rdEWplD.js → vidstack-B-DU-_xu.js} +55 -3
  2. package/dev/chunks/{vidstack-CniPzPQc.js → vidstack-C3VHrHPf.js} +155 -15
  3. package/dev/chunks/{vidstack-BOPSNTgH.js → vidstack-CjLj3q5w.js} +5 -57
  4. package/dev/chunks/{vidstack-BNwnoM-l.js → vidstack-DpWioszb.js} +1 -1
  5. package/dev/chunks/{vidstack-S_S6XDnL.js → vidstack-t48GJbb5.js} +1 -1
  6. package/dev/player/vidstack-default-components.js +4 -4
  7. package/dev/player/vidstack-default-layout.js +4 -4
  8. package/dev/player/vidstack-plyr-layout.js +3 -3
  9. package/dev/vidstack.js +5 -5
  10. package/package.json +1 -1
  11. package/player/layouts/default.d.ts +9 -1
  12. package/prod/chunks/{vidstack-BlPINAXN.js → vidstack-BI5-IK9v.js} +55 -3
  13. package/prod/chunks/{vidstack-CbejzCJs.js → vidstack-BgAMJr1Y.js} +155 -15
  14. package/prod/chunks/{vidstack-Bh7M8kL6.js → vidstack-DKWmxvB4.js} +5 -57
  15. package/prod/chunks/{vidstack-DhSvljmQ.js → vidstack-NR84X5HE.js} +1 -1
  16. package/prod/chunks/{vidstack-BS445j5D.js → vidstack-jSJ0Meez.js} +1 -1
  17. package/prod/player/vidstack-default-components.js +4 -4
  18. package/prod/player/vidstack-default-layout.js +4 -4
  19. package/prod/player/vidstack-plyr-layout.js +3 -3
  20. package/prod/vidstack.js +5 -5
  21. package/{dev/chunks/vidstack-DTow20pt.js → server/chunks/vidstack-CSX6ausI.js} +55 -3
  22. package/server/chunks/{vidstack-CoGzBr_V.js → vidstack-CePUWLrW.js} +5 -57
  23. package/{dev/chunks/vidstack-CvWDiSTs.js → server/chunks/vidstack-D7sOBYbw.js} +1 -1
  24. package/server/chunks/{vidstack-VGPw_CQP.js → vidstack-DqUb8JgU.js} +1 -1
  25. package/server/chunks/{vidstack-i9a2TQLO.js → vidstack-Dvh6BtYs.js} +155 -15
  26. package/server/player/vidstack-default-components.js +4 -4
  27. package/server/player/vidstack-default-layout.js +4 -4
  28. package/server/player/vidstack-plyr-layout.js +3 -3
  29. package/server/vidstack.js +5 -5
  30. package/dev/chunks/vidstack-B-FM4-oZ.js +0 -668
  31. package/dev/chunks/vidstack-B92UncBI.js +0 -61
  32. package/dev/chunks/vidstack-BDiAEW1N.js +0 -11691
  33. package/dev/chunks/vidstack-BPymmnxm.js +0 -551
  34. package/dev/chunks/vidstack-BSZY6sbC.js +0 -180
  35. package/dev/chunks/vidstack-BSpAxhO6.js +0 -643
  36. package/dev/chunks/vidstack-BVVxkUlq.js +0 -288
  37. package/dev/chunks/vidstack-BXgKy_7V.js +0 -11693
  38. package/dev/chunks/vidstack-BalWqr4j.js +0 -1422
  39. package/dev/chunks/vidstack-Bfi_jCvb.js +0 -476
  40. package/dev/chunks/vidstack-BoLZuw80.js +0 -34
  41. package/dev/chunks/vidstack-BrqDQG-r.js +0 -643
  42. package/dev/chunks/vidstack-C3QPOZNd.js +0 -476
  43. package/dev/chunks/vidstack-C7BwfK5c.js +0 -1537
  44. package/dev/chunks/vidstack-CEUjDh4x.js +0 -34
  45. package/dev/chunks/vidstack-CFOPpDTy.js +0 -476
  46. package/dev/chunks/vidstack-CFZ0rYJz.js +0 -34
  47. package/dev/chunks/vidstack-CKsUl4ll.js +0 -1384
  48. package/dev/chunks/vidstack-CM82l-7o.js +0 -551
  49. package/dev/chunks/vidstack-CQSHFVu7.js +0 -401
  50. package/dev/chunks/vidstack-CXrXBlpD.js +0 -11692
  51. package/dev/chunks/vidstack-CevuS08D.js +0 -1504
  52. package/dev/chunks/vidstack-CkRXb9Ia.js +0 -1537
  53. package/dev/chunks/vidstack-CqNX679o.js +0 -669
  54. package/dev/chunks/vidstack-Csfg08VS.js +0 -551
  55. package/dev/chunks/vidstack-CzU-uC5f.js +0 -189
  56. package/dev/chunks/vidstack-D2Bi2Td9.js +0 -1537
  57. package/dev/chunks/vidstack-D3ZXOE4d.js +0 -643
  58. package/dev/chunks/vidstack-D6_9yy0x.js +0 -643
  59. package/dev/chunks/vidstack-DJQOTrl6.js +0 -180
  60. package/dev/chunks/vidstack-DNbKNc4R.js +0 -288
  61. package/dev/chunks/vidstack-DOtIyh4c.js +0 -288
  62. package/dev/chunks/vidstack-DY2iivhG.js +0 -84
  63. package/dev/chunks/vidstack-DjqYvkVp.js +0 -84
  64. package/dev/chunks/vidstack-Dov8gjdq.js +0 -401
  65. package/dev/chunks/vidstack-DqaqkU4T.js +0 -9
  66. package/dev/chunks/vidstack-DwdhbP5c.js +0 -189
  67. package/dev/chunks/vidstack-DweQYzVw.js +0 -180
  68. package/dev/chunks/vidstack-FuCbl228.js +0 -226
  69. package/dev/chunks/vidstack-H9OdEKUQ.js +0 -375
  70. package/dev/chunks/vidstack-KntYDWMe.js +0 -668
  71. package/dev/chunks/vidstack-L5mw2iPb.js +0 -375
  72. package/dev/chunks/vidstack-NCBSBZE-.js +0 -61
  73. package/dev/chunks/vidstack-PREbBNMG.js +0 -125
  74. package/dev/chunks/vidstack-UWMPvwsa.js +0 -1537
  75. package/dev/chunks/vidstack-f6WXkmfP.js +0 -375
  76. package/dev/chunks/vidstack-gqKBE4xH.js +0 -376
  77. package/dev/chunks/vidstack-iRuTLfhk.js +0 -61
  78. package/dev/chunks/vidstack-lYFZKRUc.js +0 -401
  79. package/dev/chunks/vidstack-oOGofWSl.js +0 -668
  80. package/dev/chunks/vidstack-vh0BKYWJ.js +0 -84
  81. package/prod/chunks/vidstack-0Foyib2F.js +0 -34
  82. package/prod/chunks/vidstack-58ZavMvv.js +0 -159
  83. package/prod/chunks/vidstack-B0SSIHIv.js +0 -1537
  84. package/prod/chunks/vidstack-B9nEslvl.js +0 -11197
  85. package/prod/chunks/vidstack-BCBskRpc.js +0 -664
  86. package/prod/chunks/vidstack-BOObgZd8.js +0 -504
  87. package/prod/chunks/vidstack-BZVrgeRF.js +0 -9
  88. package/prod/chunks/vidstack-B_9VGrZQ.js +0 -504
  89. package/prod/chunks/vidstack-B_wD853-.js +0 -386
  90. package/prod/chunks/vidstack-BbPEqH3g.js +0 -11196
  91. package/prod/chunks/vidstack-Bm2UemPE.js +0 -470
  92. package/prod/chunks/vidstack-Bp_hAwzI.js +0 -61
  93. package/prod/chunks/vidstack-C4tNkfXj.js +0 -470
  94. package/prod/chunks/vidstack-C4tuISYG.js +0 -1504
  95. package/prod/chunks/vidstack-C5Rzkyfp.js +0 -375
  96. package/prod/chunks/vidstack-CKapDFwB.js +0 -376
  97. package/prod/chunks/vidstack-CNJwYQRW.js +0 -84
  98. package/prod/chunks/vidstack-CQll06Hv.js +0 -34
  99. package/prod/chunks/vidstack-CVzVtf1j.js +0 -61
  100. package/prod/chunks/vidstack-CYK75vJF.js +0 -1382
  101. package/prod/chunks/vidstack-CZNlvfmV.js +0 -288
  102. package/prod/chunks/vidstack-CiQEyk_l.js +0 -189
  103. package/prod/chunks/vidstack-CiTWSpv_.js +0 -34
  104. package/prod/chunks/vidstack-CikQpsuo.js +0 -1537
  105. package/prod/chunks/vidstack-CtxjO6HG.js +0 -84
  106. package/prod/chunks/vidstack-CzjHdPIT.js +0 -375
  107. package/prod/chunks/vidstack-D0XCUWbp.js +0 -159
  108. package/prod/chunks/vidstack-D3cSYtez.js +0 -663
  109. package/prod/chunks/vidstack-D91K36KQ.js +0 -206
  110. package/prod/chunks/vidstack-DJThTSEm.js +0 -125
  111. package/prod/chunks/vidstack-DTyDOhwS.js +0 -504
  112. package/prod/chunks/vidstack-DVMwXUgY.js +0 -189
  113. package/prod/chunks/vidstack-DXSNXDnS.js +0 -1384
  114. package/prod/chunks/vidstack-D_Sd7838.js +0 -663
  115. package/prod/chunks/vidstack-D_ijTIbV.js +0 -11198
  116. package/prod/chunks/vidstack-DdiGCJVp.js +0 -504
  117. package/prod/chunks/vidstack-DgGDsAKh.js +0 -375
  118. package/prod/chunks/vidstack-DgsBXr1J.js +0 -84
  119. package/prod/chunks/vidstack-DhC5F6c8.js +0 -470
  120. package/prod/chunks/vidstack-Djmla_FM.js +0 -545
  121. package/prod/chunks/vidstack-DpQw1Y33.js +0 -663
  122. package/prod/chunks/vidstack-DrEorv9m.js +0 -189
  123. package/prod/chunks/vidstack-Ma9rwtR0.js +0 -386
  124. package/prod/chunks/vidstack-VTpvHAdU.js +0 -1537
  125. package/prod/chunks/vidstack-dbLRgf2L.js +0 -159
  126. package/prod/chunks/vidstack-ehqxnvc9.js +0 -1537
  127. package/prod/chunks/vidstack-jIPoNqhj.js +0 -545
  128. package/prod/chunks/vidstack-lc8NHly9.js +0 -288
  129. package/prod/chunks/vidstack-rHvQ8f6c.js +0 -288
  130. package/prod/chunks/vidstack-rKV98aQH.js +0 -545
  131. package/prod/chunks/vidstack-uA7h-Bsq.js +0 -386
  132. package/prod/chunks/vidstack-xo_SmgiV.js +0 -84
  133. package/prod/chunks/vidstack-xvxeRtaN.js +0 -61
  134. package/server/chunks/vidstack--ufi23Q6.js +0 -1537
  135. package/server/chunks/vidstack-B3AXUfgF.js +0 -189
  136. package/server/chunks/vidstack-B4rJ1ZKK.js +0 -376
  137. package/server/chunks/vidstack-BJCx78pm.js +0 -386
  138. package/server/chunks/vidstack-BTdEfKqV.js +0 -84
  139. package/server/chunks/vidstack-BV_VpWlJ.js +0 -1537
  140. package/server/chunks/vidstack-BtitkRvR.js +0 -11198
  141. package/server/chunks/vidstack-BtqWstSj.js +0 -375
  142. package/server/chunks/vidstack-BweZhuNd.js +0 -1537
  143. package/server/chunks/vidstack-ByG5MvLs.js +0 -545
  144. package/server/chunks/vidstack-C-HdFsZi.js +0 -84
  145. package/server/chunks/vidstack-C0xOpWYR.js +0 -470
  146. package/server/chunks/vidstack-C481iXqe.js +0 -386
  147. package/server/chunks/vidstack-C4iWXMC-.js +0 -545
  148. package/server/chunks/vidstack-C5zFBMwg.js +0 -386
  149. package/server/chunks/vidstack-CEh38XpD.js +0 -288
  150. package/server/chunks/vidstack-CSiPajWY.js +0 -470
  151. package/server/chunks/vidstack-CbNRZgUA.js +0 -11197
  152. package/server/chunks/vidstack-CgXa6YO3.js +0 -61
  153. package/server/chunks/vidstack-CkMAeO-e.js +0 -34
  154. package/server/chunks/vidstack-Cm0qnRvu.js +0 -11196
  155. package/server/chunks/vidstack-Ct1NFlBa.js +0 -1537
  156. package/server/chunks/vidstack-CyFwkPiu.js +0 -470
  157. package/server/chunks/vidstack-D4t_SZbb.js +0 -1416
  158. package/server/chunks/vidstack-D7D9kiW6.js +0 -34
  159. package/server/chunks/vidstack-DH6N0AoF.js +0 -375
  160. package/server/chunks/vidstack-DJJmNib6.js +0 -504
  161. package/server/chunks/vidstack-DKr7br9D.js +0 -34
  162. package/server/chunks/vidstack-DM-5dPT-.js +0 -663
  163. package/server/chunks/vidstack-DOIUveQF.js +0 -504
  164. package/server/chunks/vidstack-DTn72IA8.js +0 -1504
  165. package/server/chunks/vidstack-DWfS9vAY.js +0 -84
  166. package/server/chunks/vidstack-DWt5LAKE.js +0 -375
  167. package/server/chunks/vidstack-DY51lx0R.js +0 -189
  168. package/server/chunks/vidstack-DbNoKLjz.js +0 -664
  169. package/server/chunks/vidstack-Dbs_rXUT.js +0 -663
  170. package/server/chunks/vidstack-DeS67_gx.js +0 -9
  171. package/server/chunks/vidstack-DiHlnSws.js +0 -1384
  172. package/server/chunks/vidstack-DnoqxmOs.js +0 -125
  173. package/server/chunks/vidstack-DsZKgA8y.js +0 -663
  174. package/server/chunks/vidstack-DtQSvsQr.js +0 -189
  175. package/server/chunks/vidstack-E7eUOyFt.js +0 -288
  176. package/server/chunks/vidstack-JkJEYEQM.js +0 -159
  177. package/server/chunks/vidstack-KhtuR229.js +0 -504
  178. package/server/chunks/vidstack-NXcLNXxO.js +0 -84
  179. package/server/chunks/vidstack-OKdxH1xx.js +0 -189
  180. package/server/chunks/vidstack-SkX-mSrw.js +0 -206
  181. package/server/chunks/vidstack-X1Hex9PH.js +0 -84
  182. package/server/chunks/vidstack-iVN8uBAv.js +0 -288
  183. package/server/chunks/vidstack-jlaBqZq5.js +0 -61
  184. package/server/chunks/vidstack-m8aA99tE.js +0 -159
  185. package/server/chunks/vidstack-rUHVQoo3.js +0 -61
  186. package/server/chunks/vidstack-rWs25cS9.js +0 -159
  187. package/server/chunks/vidstack-uyCXITen.js +0 -504
  188. package/server/chunks/vidstack-yf18YVAb.js +0 -545
@@ -1,34 +0,0 @@
1
- "use client"
2
-
3
- import { scoped } from './vidstack-D_bWd66h.js';
4
- import { HTMLMediaProvider, HTMLAirPlayAdapter } from './vidstack-BXgKy_7V.js';
5
- import 'react';
6
- import '@floating-ui/dom';
7
-
8
- class AudioProvider extends HTMLMediaProvider {
9
- $$PROVIDER_TYPE = "AUDIO";
10
- get type() {
11
- return "audio";
12
- }
13
- airPlay;
14
- constructor(audio, ctx) {
15
- super(audio, ctx);
16
- scoped(() => {
17
- this.airPlay = new HTMLAirPlayAdapter(this.media, ctx);
18
- }, this.scope);
19
- }
20
- setup() {
21
- super.setup();
22
- if (this.type === "audio") this.ctx.notify("provider-setup", this);
23
- }
24
- /**
25
- * The native HTML `<audio>` element.
26
- *
27
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement}
28
- */
29
- get audio() {
30
- return this.media;
31
- }
32
- }
33
-
34
- export { AudioProvider };
@@ -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-CXrXBlpD.js';
5
- import { getCastSessionMedia, getCastContext, getCastSession, hasActiveCastSession, listenCastContextEvent, getCastErrorMessage } from './vidstack-DweQYzVw.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 };
@@ -1,34 +0,0 @@
1
- "use client"
2
-
3
- import { scoped } from './vidstack-D_bWd66h.js';
4
- import { HTMLMediaProvider, HTMLAirPlayAdapter } from './vidstack-BDiAEW1N.js';
5
- import 'react';
6
- import '@floating-ui/dom';
7
-
8
- class AudioProvider extends HTMLMediaProvider {
9
- $$PROVIDER_TYPE = "AUDIO";
10
- get type() {
11
- return "audio";
12
- }
13
- airPlay;
14
- constructor(audio, ctx) {
15
- super(audio, ctx);
16
- scoped(() => {
17
- this.airPlay = new HTMLAirPlayAdapter(this.media, ctx);
18
- }, this.scope);
19
- }
20
- setup() {
21
- super.setup();
22
- if (this.type === "audio") this.ctx.notify("provider-setup", this);
23
- }
24
- /**
25
- * The native HTML `<audio>` element.
26
- *
27
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement}
28
- */
29
- get audio() {
30
- return this.media;
31
- }
32
- }
33
-
34
- export { AudioProvider };