@mottosports/motto-video-player 1.0.1-rc.28 → 1.0.1-rc.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.
package/dist/index.js CHANGED
@@ -1181,9 +1181,10 @@ var useShakePlayer = ({
1181
1181
  shakaConfig,
1182
1182
  drmConfig,
1183
1183
  onError,
1184
- onPlayerReady
1184
+ onPlayerReady,
1185
+ onBeforeLoad,
1186
+ playerRef
1185
1187
  }) => {
1186
- const playerRef = (0, import_react.useRef)(null);
1187
1188
  const initializePlayer = (0, import_react.useCallback)(async (video) => {
1188
1189
  try {
1189
1190
  import_shaka_player.default.polyfill.installAll();
@@ -1196,35 +1197,13 @@ var useShakePlayer = ({
1196
1197
  if (shakaConfig) {
1197
1198
  player.configure(shakaConfig);
1198
1199
  }
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
1200
  let manifestUrl = src.url;
1222
1201
  const isDRM = Boolean(src.drm);
1223
1202
  let cert = null;
1224
1203
  if (isDRM) {
1225
1204
  const isPlayReady = isPlayReadySupported();
1226
1205
  const isFairPlay = isAppleDevice();
1227
- if (isFairPlay && src.drm.fairplay?.certificate_url) {
1206
+ if (isAppleDevice() && src.drm.fairplay?.certificate_url) {
1228
1207
  const req = await fetch(src.drm.fairplay.certificate_url);
1229
1208
  cert = await req.arrayBuffer();
1230
1209
  manifestUrl = src.drm.fairplay.playlist_url;
@@ -1267,17 +1246,27 @@ var useShakePlayer = ({
1267
1246
  });
1268
1247
  }
1269
1248
  }
1249
+ player?.addEventListener("error", (event) => {
1250
+ const error = event.detail;
1251
+ if (error?.code === 7e3) {
1252
+ return;
1253
+ }
1254
+ console.error("Shaka Player Error:", error);
1255
+ onError?.(new Error(`Shaka Player Error: ${error.message || "Unknown error"}`));
1256
+ });
1257
+ onBeforeLoad?.();
1270
1258
  await player.load(manifestUrl);
1271
1259
  onPlayerReady?.(player);
1260
+ return player;
1272
1261
  } catch (error) {
1273
1262
  if (error?.code === 7e3) {
1274
1263
  return;
1275
1264
  }
1276
- console.error("Error loading source:", error);
1265
+ console.error("Error initializing Shaka Player:", error);
1277
1266
  onError?.(error);
1278
1267
  throw error;
1279
1268
  }
1280
- }, [src, onError]);
1269
+ }, [shakaConfig, drmConfig, src, onError, onPlayerReady, onBeforeLoad, playerRef]);
1281
1270
  const destroyPlayer = (0, import_react.useCallback)(async () => {
1282
1271
  if (playerRef.current) {
1283
1272
  try {
@@ -1288,11 +1277,9 @@ var useShakePlayer = ({
1288
1277
  playerRef.current = null;
1289
1278
  }
1290
1279
  }
1291
- }, []);
1280
+ }, [playerRef]);
1292
1281
  return {
1293
- playerRef,
1294
1282
  initializePlayer,
1295
- loadSource,
1296
1283
  destroyPlayer
1297
1284
  };
1298
1285
  };
@@ -1417,7 +1404,7 @@ var import_mux_data_shakaplayer = __toESM(require("@mux/mux-data-shakaplayer"));
1417
1404
  var import_shaka_player2 = __toESM(require("shaka-player/dist/shaka-player.ui"));
1418
1405
 
1419
1406
  // package.json
1420
- var version = "1.0.1-rc.28";
1407
+ var version = "1.0.1-rc.29";
1421
1408
 
1422
1409
  // src/hooks/useMuxAnalytics.ts
1423
1410
  var useMuxAnalytics = (playerRef, muxConfig, onMuxReady, onMuxDataUpdate) => {
@@ -3322,12 +3309,21 @@ var Player = (0, import_react12.forwardRef)(
3322
3309
  const containerRef = (0, import_react12.useRef)(null);
3323
3310
  const adContainerRef = (0, import_react12.useRef)(null);
3324
3311
  (0, import_react12.useImperativeHandle)(ref, () => videoRef.current, []);
3325
- const { playerRef, initializePlayer, loadSource, destroyPlayer } = useShakePlayer({
3312
+ const playerRef = (0, import_react12.useRef)(null);
3313
+ const {
3314
+ initializeMux,
3315
+ updateMuxData,
3316
+ handleMuxError,
3317
+ destroyMux
3318
+ } = useMuxAnalytics(playerRef, muxConfig, events?.onMuxReady, events?.onMuxDataUpdate);
3319
+ const { initializePlayer, destroyPlayer } = useShakePlayer({
3326
3320
  src,
3327
3321
  shakaConfig,
3328
3322
  drmConfig,
3329
3323
  onError: events?.onError,
3330
- onPlayerReady: events?.onPlayerReady
3324
+ onPlayerReady: events?.onPlayerReady,
3325
+ onBeforeLoad: initializeMux,
3326
+ playerRef
3331
3327
  });
3332
3328
  const {
3333
3329
  getAvailableQualities,
@@ -3346,12 +3342,6 @@ var Player = (0, import_react12.forwardRef)(
3346
3342
  skipForward,
3347
3343
  enabled: true
3348
3344
  });
3349
- const {
3350
- initializeMux,
3351
- updateMuxData,
3352
- handleMuxError,
3353
- destroyMux
3354
- } = useMuxAnalytics(playerRef, muxConfig, events?.onMuxReady, events?.onMuxDataUpdate);
3355
3345
  const { setupEventListeners, cleanupEventListeners } = useEventHandlers(videoRef, {
3356
3346
  onPlay: events?.onPlay,
3357
3347
  onPause: events?.onPause,
@@ -3430,8 +3420,6 @@ var Player = (0, import_react12.forwardRef)(
3430
3420
  const initialize = async () => {
3431
3421
  try {
3432
3422
  await initializePlayer(video);
3433
- initializeMux();
3434
- await loadSource();
3435
3423
  setupEventListeners();
3436
3424
  const cleanupQuality = setupQualityTracking();
3437
3425
  configureQuality();