@scarlett-player/chromecast 0.4.0 → 0.5.0

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.
package/dist/index.cjs CHANGED
@@ -129,10 +129,13 @@ function chromecastPlugin() {
129
129
  const SessionState = window.cast.framework.SessionState;
130
130
  switch (event.sessionState) {
131
131
  case SessionState.SESSION_STARTED:
132
- case SessionState.SESSION_RESUMED:
133
132
  currentSession = castContext.getCurrentSession();
134
133
  onSessionConnected();
135
134
  break;
135
+ case SessionState.SESSION_RESUMED:
136
+ currentSession = castContext.getCurrentSession();
137
+ onSessionResumed();
138
+ break;
136
139
  case SessionState.SESSION_ENDED:
137
140
  onSessionDisconnected();
138
141
  currentSession = null;
@@ -161,6 +164,17 @@ function chromecastPlugin() {
161
164
  loadMediaOnCast(localSrcBeforeCast, localTimeBeforeCast);
162
165
  }
163
166
  };
167
+ const onSessionResumed = () => {
168
+ if (!currentSession) return;
169
+ const deviceName = currentSession.getCastDevice()?.friendlyName || "Chromecast";
170
+ api.setState("chromecastActive", true);
171
+ api.emit("chromecast:connected", { deviceName });
172
+ api.logger.info("Chromecast session resumed", { deviceName });
173
+ const video = api.container.querySelector("video");
174
+ if (video) {
175
+ video.pause();
176
+ }
177
+ };
164
178
  const onSessionDisconnected = () => {
165
179
  const castTime = remotePlayer?.currentTime || localTimeBeforeCast;
166
180
  api.setState("chromecastActive", false);
@@ -178,6 +192,14 @@ function chromecastPlugin() {
178
192
  if (!currentSession || !window.chrome?.cast) return;
179
193
  const contentType = src.includes(".m3u8") ? "application/x-mpegurl" : src.includes(".mpd") ? "application/dash+xml" : "video/mp4";
180
194
  const mediaInfo = new window.chrome.cast.media.MediaInfo(src, contentType);
195
+ const title = api.getState("title");
196
+ const poster = api.getState("poster");
197
+ if (title || poster) {
198
+ const metadata = new window.chrome.cast.media.GenericMediaMetadata();
199
+ if (title) metadata.title = title;
200
+ if (poster) metadata.images = [new window.chrome.cast.Image(poster)];
201
+ mediaInfo.metadata = metadata;
202
+ }
181
203
  const request = new window.chrome.cast.media.LoadRequest(mediaInfo);
182
204
  request.currentTime = startTime;
183
205
  request.autoplay = true;
@@ -228,19 +250,19 @@ function chromecastPlugin() {
228
250
  } catch {
229
251
  }
230
252
  }
231
- if (castContext && castStateHandler) {
253
+ if (castContext && castStateHandler && window.cast?.framework) {
232
254
  castContext.removeEventListener(
233
255
  window.cast.framework.CastContextEventType.CAST_STATE_CHANGED,
234
256
  castStateHandler
235
257
  );
236
258
  }
237
- if (castContext && sessionStateHandler) {
259
+ if (castContext && sessionStateHandler && window.cast?.framework) {
238
260
  castContext.removeEventListener(
239
261
  window.cast.framework.CastContextEventType.SESSION_STATE_CHANGED,
240
262
  sessionStateHandler
241
263
  );
242
264
  }
243
- if (remotePlayerController && remotePlayerHandler) {
265
+ if (remotePlayerController && remotePlayerHandler && window.cast?.framework) {
244
266
  remotePlayerController.removeEventListener(
245
267
  window.cast.framework.RemotePlayerEventType.ANY_CHANGE,
246
268
  remotePlayerHandler
package/dist/index.d.cts CHANGED
@@ -13,7 +13,17 @@ declare namespace ChromeCastMedia {
13
13
  contentId: string;
14
14
  contentType: string;
15
15
  streamType?: string;
16
- metadata?: object;
16
+ metadata?: GenericMediaMetadata;
17
+ }
18
+ interface GenericMediaMetadata {
19
+ title?: string;
20
+ subtitle?: string;
21
+ images?: ChromeCastImage[];
22
+ }
23
+ interface ChromeCastImage {
24
+ url: string;
25
+ width?: number;
26
+ height?: number;
17
27
  }
18
28
  interface LoadRequest {
19
29
  mediaInfo: MediaInfo;
@@ -133,7 +143,9 @@ declare global {
133
143
  DEFAULT_MEDIA_RECEIVER_APP_ID: string;
134
144
  MediaInfo: new (contentId: string, contentType: string) => ChromeCastMedia.MediaInfo;
135
145
  LoadRequest: new (mediaInfo: ChromeCastMedia.MediaInfo) => ChromeCastMedia.LoadRequest;
146
+ GenericMediaMetadata: new () => ChromeCastMedia.GenericMediaMetadata;
136
147
  };
148
+ Image: new (url: string) => ChromeCastMedia.ChromeCastImage;
137
149
  AutoJoinPolicy: {
138
150
  ORIGIN_SCOPED: string;
139
151
  TAB_AND_ORIGIN_SCOPED: string;
package/dist/index.d.ts CHANGED
@@ -13,7 +13,17 @@ declare namespace ChromeCastMedia {
13
13
  contentId: string;
14
14
  contentType: string;
15
15
  streamType?: string;
16
- metadata?: object;
16
+ metadata?: GenericMediaMetadata;
17
+ }
18
+ interface GenericMediaMetadata {
19
+ title?: string;
20
+ subtitle?: string;
21
+ images?: ChromeCastImage[];
22
+ }
23
+ interface ChromeCastImage {
24
+ url: string;
25
+ width?: number;
26
+ height?: number;
17
27
  }
18
28
  interface LoadRequest {
19
29
  mediaInfo: MediaInfo;
@@ -133,7 +143,9 @@ declare global {
133
143
  DEFAULT_MEDIA_RECEIVER_APP_ID: string;
134
144
  MediaInfo: new (contentId: string, contentType: string) => ChromeCastMedia.MediaInfo;
135
145
  LoadRequest: new (mediaInfo: ChromeCastMedia.MediaInfo) => ChromeCastMedia.LoadRequest;
146
+ GenericMediaMetadata: new () => ChromeCastMedia.GenericMediaMetadata;
136
147
  };
148
+ Image: new (url: string) => ChromeCastMedia.ChromeCastImage;
137
149
  AutoJoinPolicy: {
138
150
  ORIGIN_SCOPED: string;
139
151
  TAB_AND_ORIGIN_SCOPED: string;
package/dist/index.js CHANGED
@@ -99,10 +99,13 @@ function chromecastPlugin() {
99
99
  const SessionState = window.cast.framework.SessionState;
100
100
  switch (event.sessionState) {
101
101
  case SessionState.SESSION_STARTED:
102
- case SessionState.SESSION_RESUMED:
103
102
  currentSession = castContext.getCurrentSession();
104
103
  onSessionConnected();
105
104
  break;
105
+ case SessionState.SESSION_RESUMED:
106
+ currentSession = castContext.getCurrentSession();
107
+ onSessionResumed();
108
+ break;
106
109
  case SessionState.SESSION_ENDED:
107
110
  onSessionDisconnected();
108
111
  currentSession = null;
@@ -131,6 +134,17 @@ function chromecastPlugin() {
131
134
  loadMediaOnCast(localSrcBeforeCast, localTimeBeforeCast);
132
135
  }
133
136
  };
137
+ const onSessionResumed = () => {
138
+ if (!currentSession) return;
139
+ const deviceName = currentSession.getCastDevice()?.friendlyName || "Chromecast";
140
+ api.setState("chromecastActive", true);
141
+ api.emit("chromecast:connected", { deviceName });
142
+ api.logger.info("Chromecast session resumed", { deviceName });
143
+ const video = api.container.querySelector("video");
144
+ if (video) {
145
+ video.pause();
146
+ }
147
+ };
134
148
  const onSessionDisconnected = () => {
135
149
  const castTime = remotePlayer?.currentTime || localTimeBeforeCast;
136
150
  api.setState("chromecastActive", false);
@@ -148,6 +162,14 @@ function chromecastPlugin() {
148
162
  if (!currentSession || !window.chrome?.cast) return;
149
163
  const contentType = src.includes(".m3u8") ? "application/x-mpegurl" : src.includes(".mpd") ? "application/dash+xml" : "video/mp4";
150
164
  const mediaInfo = new window.chrome.cast.media.MediaInfo(src, contentType);
165
+ const title = api.getState("title");
166
+ const poster = api.getState("poster");
167
+ if (title || poster) {
168
+ const metadata = new window.chrome.cast.media.GenericMediaMetadata();
169
+ if (title) metadata.title = title;
170
+ if (poster) metadata.images = [new window.chrome.cast.Image(poster)];
171
+ mediaInfo.metadata = metadata;
172
+ }
151
173
  const request = new window.chrome.cast.media.LoadRequest(mediaInfo);
152
174
  request.currentTime = startTime;
153
175
  request.autoplay = true;
@@ -198,19 +220,19 @@ function chromecastPlugin() {
198
220
  } catch {
199
221
  }
200
222
  }
201
- if (castContext && castStateHandler) {
223
+ if (castContext && castStateHandler && window.cast?.framework) {
202
224
  castContext.removeEventListener(
203
225
  window.cast.framework.CastContextEventType.CAST_STATE_CHANGED,
204
226
  castStateHandler
205
227
  );
206
228
  }
207
- if (castContext && sessionStateHandler) {
229
+ if (castContext && sessionStateHandler && window.cast?.framework) {
208
230
  castContext.removeEventListener(
209
231
  window.cast.framework.CastContextEventType.SESSION_STATE_CHANGED,
210
232
  sessionStateHandler
211
233
  );
212
234
  }
213
- if (remotePlayerController && remotePlayerHandler) {
235
+ if (remotePlayerController && remotePlayerHandler && window.cast?.framework) {
214
236
  remotePlayerController.removeEventListener(
215
237
  window.cast.framework.RemotePlayerEventType.ANY_CHANGE,
216
238
  remotePlayerHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/chromecast",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Chromecast Plugin for Scarlett Player",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@scarlett-player/core": "^0.4.0"
20
+ "@scarlett-player/core": "^0.5.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "typescript": "^5.3.0",
@@ -25,7 +25,7 @@
25
25
  "vitest": "^1.6.0",
26
26
  "@vitest/coverage-v8": "^1.6.0",
27
27
  "jsdom": "^24.0.0",
28
- "@scarlett-player/core": "0.4.0"
28
+ "@scarlett-player/core": "0.5.0"
29
29
  },
30
30
  "keywords": [
31
31
  "video",