@mottosports/motto-video-player 1.0.1-rc.28 → 1.0.1-rc.30

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.js CHANGED
@@ -1175,13 +1175,22 @@ var isPlayReadySupported = () => {
1175
1175
  return isWindows || isXbox || isEdge || isIE;
1176
1176
  };
1177
1177
 
1178
+ // src/hooks/useShakePlayer.ts
1179
+ var import_mux_data_shakaplayer = __toESM(require("@mux/mux-data-shakaplayer"));
1180
+
1181
+ // package.json
1182
+ var version = "1.0.1-rc.30";
1183
+
1178
1184
  // src/hooks/useShakePlayer.ts
1179
1185
  var useShakePlayer = ({
1180
1186
  src,
1181
1187
  shakaConfig,
1182
1188
  drmConfig,
1183
1189
  onError,
1184
- onPlayerReady
1190
+ onPlayerReady,
1191
+ muxConfig,
1192
+ onMuxReady,
1193
+ onMuxDataUpdate
1185
1194
  }) => {
1186
1195
  const playerRef = (0, import_react.useRef)(null);
1187
1196
  const initializePlayer = (0, import_react.useCallback)(async (video) => {
@@ -1196,35 +1205,13 @@ var useShakePlayer = ({
1196
1205
  if (shakaConfig) {
1197
1206
  player.configure(shakaConfig);
1198
1207
  }
1199
- player?.addEventListener("error", (event) => {
1200
- const error = event.detail;
1201
- if (error?.code === 7e3) {
1202
- return;
1203
- }
1204
- console.error("Shaka Player Error:", error);
1205
- onError?.(new Error(`Shaka Player Error: ${error.message || "Unknown error"}`));
1206
- });
1207
- return player;
1208
- } catch (error) {
1209
- if (error?.code === 7e3) {
1210
- return;
1211
- }
1212
- console.error("Error initializing Shaka Player:", error);
1213
- onError?.(error);
1214
- throw error;
1215
- }
1216
- }, [shakaConfig, drmConfig, src, onError, onPlayerReady]);
1217
- const loadSource = (0, import_react.useCallback)(async () => {
1218
- const player = playerRef.current;
1219
- if (!player) return;
1220
- try {
1221
1208
  let manifestUrl = src.url;
1222
1209
  const isDRM = Boolean(src.drm);
1223
1210
  let cert = null;
1224
1211
  if (isDRM) {
1225
1212
  const isPlayReady = isPlayReadySupported();
1226
1213
  const isFairPlay = isAppleDevice();
1227
- if (isFairPlay && src.drm.fairplay?.certificate_url) {
1214
+ if (isAppleDevice() && src.drm.fairplay?.certificate_url) {
1228
1215
  const req = await fetch(src.drm.fairplay.certificate_url);
1229
1216
  cert = await req.arrayBuffer();
1230
1217
  manifestUrl = src.drm.fairplay.playlist_url;
@@ -1267,17 +1254,53 @@ var useShakePlayer = ({
1267
1254
  });
1268
1255
  }
1269
1256
  }
1257
+ player?.addEventListener("error", (event) => {
1258
+ const error = event.detail;
1259
+ if (error?.code === 7e3) {
1260
+ return;
1261
+ }
1262
+ console.error("Shaka Player Error:", error);
1263
+ onError?.(new Error(`Shaka Player Error: ${error.message || "Unknown error"}`));
1264
+ });
1265
+ if (muxConfig) {
1266
+ try {
1267
+ const playerInitTime = import_mux_data_shakaplayer.default.utils.now();
1268
+ const muxOptions = {
1269
+ debug: muxConfig.debug || false,
1270
+ disableCookies: muxConfig.disableCookies || false,
1271
+ respectDoNotTrack: muxConfig.respectDoNotTrack || false,
1272
+ automaticErrorTracking: muxConfig.automaticErrorTracking !== false,
1273
+ ...muxConfig.beaconCollectionDomain && { beaconCollectionDomain: muxConfig.beaconCollectionDomain },
1274
+ ...muxConfig.errorTranslator && { errorTranslator: muxConfig.errorTranslator },
1275
+ data: {
1276
+ env_key: muxConfig.envKey,
1277
+ player_name: muxConfig?.metadata?.player_name,
1278
+ player_version: version,
1279
+ player_init_time: playerInitTime,
1280
+ video_title: muxConfig?.metadata?.video_title ?? "",
1281
+ video_id: muxConfig?.metadata?.video_id ?? "",
1282
+ viewer_user_id: muxConfig?.metadata?.viewer_user_id ?? "",
1283
+ ...muxConfig.metadata
1284
+ }
1285
+ };
1286
+ (0, import_mux_data_shakaplayer.default)(player, muxOptions, import_shaka_player.default);
1287
+ onMuxReady?.();
1288
+ } catch (error) {
1289
+ console.error("Failed to initialize Mux Analytics:", error);
1290
+ }
1291
+ }
1270
1292
  await player.load(manifestUrl);
1271
1293
  onPlayerReady?.(player);
1294
+ return player;
1272
1295
  } catch (error) {
1273
1296
  if (error?.code === 7e3) {
1274
1297
  return;
1275
1298
  }
1276
- console.error("Error loading source:", error);
1299
+ console.error("Error initializing Shaka Player:", error);
1277
1300
  onError?.(error);
1278
1301
  throw error;
1279
1302
  }
1280
- }, [src, onError]);
1303
+ }, [shakaConfig, drmConfig, src, onError, onPlayerReady, muxConfig, onMuxReady]);
1281
1304
  const destroyPlayer = (0, import_react.useCallback)(async () => {
1282
1305
  if (playerRef.current) {
1283
1306
  try {
@@ -1288,11 +1311,10 @@ var useShakePlayer = ({
1288
1311
  playerRef.current = null;
1289
1312
  }
1290
1313
  }
1291
- }, []);
1314
+ }, [playerRef]);
1292
1315
  return {
1293
1316
  playerRef,
1294
1317
  initializePlayer,
1295
- loadSource,
1296
1318
  destroyPlayer
1297
1319
  };
1298
1320
  };
@@ -1413,19 +1435,14 @@ var useSkipControls = (videoRef, onSkipBack, onSkipForward) => {
1413
1435
 
1414
1436
  // src/hooks/useMuxAnalytics.ts
1415
1437
  var import_react4 = require("react");
1416
- var import_mux_data_shakaplayer = __toESM(require("@mux/mux-data-shakaplayer"));
1438
+ var import_mux_data_shakaplayer2 = __toESM(require("@mux/mux-data-shakaplayer"));
1417
1439
  var import_shaka_player2 = __toESM(require("shaka-player/dist/shaka-player.ui"));
1418
-
1419
- // package.json
1420
- var version = "1.0.1-rc.28";
1421
-
1422
- // src/hooks/useMuxAnalytics.ts
1423
1440
  var useMuxAnalytics = (playerRef, muxConfig, onMuxReady, onMuxDataUpdate) => {
1424
1441
  const shakaPlayerMuxRef = (0, import_react4.useRef)(null);
1425
1442
  const initializeMux = (0, import_react4.useCallback)(() => {
1426
1443
  if (!muxConfig || !playerRef.current) return;
1427
1444
  try {
1428
- const playerInitTime = import_mux_data_shakaplayer.default.utils.now();
1445
+ const playerInitTime = import_mux_data_shakaplayer2.default.utils.now();
1429
1446
  const muxOptions = {
1430
1447
  debug: muxConfig.debug || false,
1431
1448
  disableCookies: muxConfig.disableCookies || false,
@@ -1444,7 +1461,7 @@ var useMuxAnalytics = (playerRef, muxConfig, onMuxReady, onMuxDataUpdate) => {
1444
1461
  ...muxConfig.metadata
1445
1462
  }
1446
1463
  };
1447
- shakaPlayerMuxRef.current = (0, import_mux_data_shakaplayer.default)(playerRef.current, muxOptions, import_shaka_player2.default);
1464
+ shakaPlayerMuxRef.current = (0, import_mux_data_shakaplayer2.default)(playerRef.current, muxOptions, import_shaka_player2.default);
1448
1465
  onMuxReady?.();
1449
1466
  } catch (error) {
1450
1467
  console.error("Failed to initialize Mux Analytics:", error);
@@ -3322,13 +3339,22 @@ var Player = (0, import_react12.forwardRef)(
3322
3339
  const containerRef = (0, import_react12.useRef)(null);
3323
3340
  const adContainerRef = (0, import_react12.useRef)(null);
3324
3341
  (0, import_react12.useImperativeHandle)(ref, () => videoRef.current, []);
3325
- const { playerRef, initializePlayer, loadSource, destroyPlayer } = useShakePlayer({
3342
+ const { playerRef, initializePlayer, destroyPlayer } = useShakePlayer({
3326
3343
  src,
3327
3344
  shakaConfig,
3328
3345
  drmConfig,
3329
3346
  onError: events?.onError,
3330
- onPlayerReady: events?.onPlayerReady
3347
+ onPlayerReady: events?.onPlayerReady,
3348
+ muxConfig,
3349
+ onMuxReady: events?.onMuxReady,
3350
+ onMuxDataUpdate: events?.onMuxDataUpdate
3331
3351
  });
3352
+ const {
3353
+ initializeMux,
3354
+ updateMuxData,
3355
+ handleMuxError,
3356
+ destroyMux
3357
+ } = useMuxAnalytics(playerRef, muxConfig, events?.onMuxReady, events?.onMuxDataUpdate);
3332
3358
  const {
3333
3359
  getAvailableQualities,
3334
3360
  setQuality,
@@ -3346,12 +3372,6 @@ var Player = (0, import_react12.forwardRef)(
3346
3372
  skipForward,
3347
3373
  enabled: true
3348
3374
  });
3349
- const {
3350
- initializeMux,
3351
- updateMuxData,
3352
- handleMuxError,
3353
- destroyMux
3354
- } = useMuxAnalytics(playerRef, muxConfig, events?.onMuxReady, events?.onMuxDataUpdate);
3355
3375
  const { setupEventListeners, cleanupEventListeners } = useEventHandlers(videoRef, {
3356
3376
  onPlay: events?.onPlay,
3357
3377
  onPause: events?.onPause,
@@ -3430,8 +3450,6 @@ var Player = (0, import_react12.forwardRef)(
3430
3450
  const initialize = async () => {
3431
3451
  try {
3432
3452
  await initializePlayer(video);
3433
- initializeMux();
3434
- await loadSource();
3435
3453
  setupEventListeners();
3436
3454
  const cleanupQuality = setupQualityTracking();
3437
3455
  configureQuality();