@edm-webplayer/webplayer-angular 0.1.89 → 0.1.91

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.
@@ -90,32 +90,13 @@ class PlyrPlayerComponent {
90
90
  liveInteractionBlocker;
91
91
  iosFullscreenCleanup;
92
92
  pendingStartTime;
93
+ autoplayConfig;
93
94
  onResize = () => {
94
95
  this.updateRecommendationBlockerSafeZone();
95
96
  };
96
- onRecommendationBlockerClick = (event) => {
97
- if (event) {
98
- try {
99
- event.preventDefault();
100
- }
101
- catch { }
102
- try {
103
- event.stopPropagation();
104
- }
105
- catch { }
106
- }
107
- };
108
- onTopBlockerPointerDown = (event) => {
109
- try {
110
- event.preventDefault();
111
- }
112
- catch { }
113
- try {
114
- event.stopPropagation();
115
- }
116
- catch { }
117
- };
118
- onTopBlockerClick = (event) => {
97
+ consumeEvent = (event) => {
98
+ if (!event)
99
+ return;
119
100
  try {
120
101
  event.preventDefault();
121
102
  }
@@ -195,6 +176,9 @@ class PlyrPlayerComponent {
195
176
  }
196
177
  return Math.max(this.overlayInteractionGapPx, this.getControlsSafeZone());
197
178
  }
179
+ getOverlayGuardHeight() {
180
+ return Math.max(48, Math.ceil(this.getOverlaySafeZone()));
181
+ }
198
182
  getOpenMenuHeight() {
199
183
  const container = this.plyr?.elements?.container;
200
184
  if (!container)
@@ -302,28 +286,32 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
302
286
  return null;
303
287
  const blocker = this.document.createElement("div");
304
288
  blocker.className = "plyr-recommendation-blocker";
305
- blocker.style.position = "absolute";
306
- blocker.style.top = "0";
307
- blocker.style.left = "0";
308
- blocker.style.width = "100%";
309
- blocker.style.height = "100%";
310
- blocker.style.zIndex = "9";
311
- blocker.style.pointerEvents = "none";
312
- blocker.style.display = "none";
313
- blocker.style.background = "rgba(0,0,0,0)";
314
- blocker.style.cursor = "pointer";
289
+ Object.assign(blocker.style, {
290
+ position: "absolute",
291
+ top: "0",
292
+ left: "0",
293
+ width: "100%",
294
+ height: "100%",
295
+ zIndex: "9",
296
+ pointerEvents: "none",
297
+ display: "none",
298
+ background: "rgba(0,0,0,0)",
299
+ cursor: "pointer",
300
+ });
315
301
  const activeZone = this.document.createElement("div");
316
302
  activeZone.className = "plyr-recommendation-blocker__zone";
317
- activeZone.style.position = "absolute";
318
- activeZone.style.top = "0";
319
- activeZone.style.left = "0";
320
- activeZone.style.width = "100%";
321
- activeZone.style.bottom = `20px`;
322
- activeZone.style.pointerEvents = "auto";
323
- activeZone.style.background = "rgba(0,0,0,0)";
324
- activeZone.style.cursor = "pointer";
325
- activeZone.addEventListener("pointerdown", this.onTopBlockerPointerDown);
326
- activeZone.addEventListener("click", this.onRecommendationBlockerClick);
303
+ Object.assign(activeZone.style, {
304
+ position: "absolute",
305
+ top: "0",
306
+ left: "0",
307
+ width: "100%",
308
+ bottom: `20px`,
309
+ pointerEvents: "auto",
310
+ background: "rgba(0,0,0,0)",
311
+ cursor: "pointer",
312
+ });
313
+ activeZone.addEventListener("pointerdown", this.consumeEvent);
314
+ activeZone.addEventListener("click", this.consumeEvent);
327
315
  blocker.appendChild(activeZone);
328
316
  wrapper.appendChild(blocker);
329
317
  this.recommendationBlocker = blocker;
@@ -363,18 +351,20 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
363
351
  }
364
352
  const blocker = this.document.createElement("div");
365
353
  blocker.className = "plyr-top-click-blocker";
366
- blocker.style.position = "absolute";
367
- blocker.style.top = "0";
368
- blocker.style.left = "0";
369
- blocker.style.right = "0";
370
- blocker.style.width = "100%";
371
- blocker.style.zIndex = "12";
372
- blocker.style.pointerEvents = "auto";
373
- blocker.style.background = "rgba(0,0,0,0)";
374
- blocker.style.touchAction = "none";
375
- blocker.style.cursor = "default";
376
- blocker.addEventListener("pointerdown", this.onTopBlockerPointerDown);
377
- blocker.addEventListener("click", this.onTopBlockerClick);
354
+ Object.assign(blocker.style, {
355
+ position: "absolute",
356
+ top: "0",
357
+ left: "0",
358
+ right: "0",
359
+ width: "100%",
360
+ zIndex: "12",
361
+ pointerEvents: "auto",
362
+ background: "rgba(0,0,0,0)",
363
+ touchAction: "none",
364
+ cursor: "default",
365
+ });
366
+ blocker.addEventListener("pointerdown", this.consumeEvent);
367
+ blocker.addEventListener("click", this.consumeEvent);
378
368
  wrapper.appendChild(blocker);
379
369
  this.topClickBlocker = blocker;
380
370
  this.updateTopClickBlockerSafeZone();
@@ -382,8 +372,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
382
372
  updateTopClickBlockerSafeZone() {
383
373
  if (!this.topClickBlocker)
384
374
  return;
385
- const height = Math.max(48, Math.ceil(this.getOverlaySafeZone()));
386
- this.topClickBlocker.style.height = `${height}px`;
375
+ this.topClickBlocker.style.height = `${this.getOverlayGuardHeight()}px`;
387
376
  this.topClickBlocker.style.pointerEvents = this.overlayBlockAll
388
377
  ? "auto"
389
378
  : "none";
@@ -501,12 +490,6 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
501
490
  isIframeProvider() {
502
491
  return this.config?.video_host === "youtube";
503
492
  }
504
- shouldDisableAutoplayForIOS() {
505
- if (this.config?.is_live) {
506
- return false;
507
- }
508
- return this.isIOSContext();
509
- }
510
493
  shouldResetProgressToBeginning() {
511
494
  const host = this.config?.video_host;
512
495
  if (host !== "youtube") {
@@ -594,59 +577,18 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
594
577
  }
595
578
  this.liveInteractionBlocker = null;
596
579
  }
597
- wantsAutoplay() {
598
- return !!(this.config?.autoplay || this.config?.is_live);
599
- }
600
- // Debug: disable qualquer tentativa de autoplay em todas as plataformas
601
- isAutoplayDisabledForDebug() {
602
- return true;
603
- }
604
- shouldPreventAutoplayFromResume() {
605
- return this.isIOSContext() && this.hasResumeProgress();
606
- }
607
- hasResumeProgress() {
608
- const rawTime = Number(this.config?.last_time);
609
- if (Number.isFinite(rawTime) && rawTime > 0.5) {
610
- return true;
611
- }
612
- const rawPercent = Number(this.config?.last_percent);
613
- if (Number.isFinite(rawPercent) && rawPercent > 0.01) {
614
- return true;
615
- }
616
- return false;
617
- }
618
- shouldAutoplay() {
619
- if (this.isAutoplayDisabledForDebug()) {
620
- return false;
621
- }
622
- if (this.config?.is_live) {
623
- return true;
624
- }
625
- if (this.shouldPreventAutoplayFromResume()) {
626
- return false;
627
- }
628
- if (this.shouldDisableAutoplayForIOS()) {
629
- return false;
630
- }
631
- return this.wantsAutoplay();
632
- }
633
- requiresMutedAutoplay() {
634
- if (this.isAutoplayDisabledForDebug()) {
635
- return false;
636
- }
637
- if (this.config?.is_live && this.isIOSDevice()) {
638
- return true;
639
- }
640
- if (!this.isIOSDevice() || this.shouldDisableAutoplayForIOS()) {
641
- return false;
642
- }
643
- return this.wantsAutoplay();
580
+ isLivePlayback() {
581
+ return !!this.config?.is_live;
644
582
  }
645
- shouldBlockIframeAutoplay() {
646
- return this.shouldDisableAutoplayForIOS();
583
+ getAutoplayConfig() {
584
+ const enabled = this.isLivePlayback();
585
+ const startMuted = enabled && this.isIOSDevice();
586
+ const blockIframe = !this.isLivePlayback() && this.isIOSContext();
587
+ this.autoplayConfig = { enabled, startMuted, blockIframe };
588
+ return this.autoplayConfig;
647
589
  }
648
- stopRestrictedIframeAutoplay() {
649
- if (!this.shouldBlockIframeAutoplay()) {
590
+ stopRestrictedIframeAutoplay(autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig()) {
591
+ if (!autoplayConfig.blockIframe) {
650
592
  return;
651
593
  }
652
594
  this.clearAutoplayUnlockListener();
@@ -725,7 +667,8 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
725
667
  const media = target ?? this.videoRef?.nativeElement ?? null;
726
668
  const prevVideoMuted = media?.muted ?? false;
727
669
  const prevPlyrMuted = !!this.plyr?.muted;
728
- const shouldForceUnmute = !this.shouldAutoplay();
670
+ const autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig();
671
+ const shouldForceUnmute = !autoplayConfig.enabled;
729
672
  try {
730
673
  if (media) {
731
674
  media.muted = true;
@@ -765,12 +708,11 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
765
708
  this.interactionUnmuteCleanup = undefined;
766
709
  }
767
710
  }
768
- ensureAutoplayUnlockListener() {
769
- if (typeof window === "undefined" ||
770
- this.interactionUnmuteCleanup ||
771
- !this.shouldAutoplay() ||
772
- this.shouldPreventAutoplayFromResume() ||
773
- this.isAutoplayDisabledForDebug()) {
711
+ ensureAutoplayUnlockListener(autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig()) {
712
+ if (typeof window === "undefined" || this.interactionUnmuteCleanup) {
713
+ return;
714
+ }
715
+ if (!autoplayConfig.enabled) {
774
716
  return;
775
717
  }
776
718
  const capture = true;
@@ -778,6 +720,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
778
720
  this.setPlayerMutedState(false);
779
721
  try {
780
722
  this.plyr?.play();
723
+ console.log("Autoplay unlocked via user interaction");
781
724
  }
782
725
  catch { }
783
726
  this.clearAutoplayUnlockListener();
@@ -822,9 +765,11 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
822
765
  iframe.setAttribute("allowfullscreen", "true");
823
766
  iframe.setAttribute("data-keepplaying", "true");
824
767
  }
825
- scheduleUserInteractionUnmute(video) {
826
- this.unmuteAfterDelay(video || undefined);
827
- this.ensureAutoplayUnlockListener();
768
+ scheduleUserInteractionUnmute(video, autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig()) {
769
+ if (!autoplayConfig.enabled)
770
+ return;
771
+ this.unmuteAfterDelay(video || undefined, undefined, 1, autoplayConfig);
772
+ this.ensureAutoplayUnlockListener(autoplayConfig);
828
773
  }
829
774
  requestStartTimeSeek(start, opts = {}) {
830
775
  if (!(start > 0)) {
@@ -936,11 +881,8 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
936
881
  }
937
882
  return null;
938
883
  }
939
- startAutoplayFlow(video) {
940
- if (!this.shouldAutoplay() ||
941
- !this.plyr ||
942
- this.shouldPreventAutoplayFromResume() ||
943
- this.isAutoplayDisabledForDebug())
884
+ startAutoplayFlow(video, autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig()) {
885
+ if (!autoplayConfig.enabled || !this.plyr)
944
886
  return;
945
887
  if (this.deferUntilStartTimeSettles(() => this.startAutoplayFlow(video))) {
946
888
  return;
@@ -951,7 +893,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
951
893
  let playResult;
952
894
  try {
953
895
  playResult = this.plyr.play();
954
- this.forceIframeAutoplayFallback();
896
+ this.forceIframeAutoplayFallback(autoplayConfig);
955
897
  }
956
898
  catch (error) {
957
899
  if (!muted) {
@@ -967,7 +909,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
967
909
  }
968
910
  catch { }
969
911
  }
970
- this.scheduleUserInteractionUnmute(media);
912
+ this.scheduleUserInteractionUnmute(media, autoplayConfig);
971
913
  return;
972
914
  }
973
915
  if (playResult &&
@@ -986,29 +928,26 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
986
928
  }
987
929
  catch { }
988
930
  }
989
- this.scheduleUserInteractionUnmute(media);
931
+ this.scheduleUserInteractionUnmute(media, autoplayConfig);
990
932
  });
991
933
  return;
992
934
  }
993
935
  if (muted) {
994
- this.scheduleUserInteractionUnmute(media);
936
+ this.scheduleUserInteractionUnmute(media, autoplayConfig);
995
937
  }
996
938
  else {
997
939
  this.clearAutoplayUnlockListener();
998
940
  }
999
941
  };
1000
- if (this.requiresMutedAutoplay()) {
942
+ if (autoplayConfig.startMuted) {
1001
943
  tryPlay(true);
1002
944
  }
1003
945
  else {
1004
946
  tryPlay(false);
1005
947
  }
1006
948
  }
1007
- forceIframeAutoplayFallback() {
1008
- if (!this.shouldAutoplay() ||
1009
- !this.isIframeProvider() ||
1010
- this.shouldPreventAutoplayFromResume() ||
1011
- this.isAutoplayDisabledForDebug()) {
949
+ forceIframeAutoplayFallback(autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig()) {
950
+ if (!this.isLivePlayback() || !autoplayConfig.enabled || !this.isIframeProvider()) {
1012
951
  return;
1013
952
  }
1014
953
  const embed = this.plyr?.embed;
@@ -1030,71 +969,79 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1030
969
  return;
1031
970
  }
1032
971
  if (this.isTouchDevice()) {
1033
- const HIDE_DELAY = 2000;
1034
- let hideTimeout = null;
1035
- const clearHideTimeout = () => {
1036
- if (hideTimeout) {
1037
- clearTimeout(hideTimeout);
1038
- hideTimeout = null;
1039
- }
1040
- };
1041
- const showControls = () => {
1042
- container.classList.remove("plyr--auto-hide-controls");
1043
- };
1044
- const hideControls = () => {
1045
- if (this.plyr?.playing) {
1046
- container.classList.add("plyr--auto-hide-controls");
1047
- }
1048
- };
1049
- const scheduleHide = () => {
1050
- clearHideTimeout();
1051
- if (!this.plyr?.playing)
1052
- return;
1053
- hideTimeout = setTimeout(() => hideControls(), HIDE_DELAY);
1054
- };
1055
- const onPlay = () => {
1056
- showControls();
1057
- this.overlayBlockAll = false;
1058
- };
1059
- const onPause = () => {
1060
- clearHideTimeout();
1061
- showControls();
1062
- this.overlayBlockAll = true;
1063
- this.updateTopClickBlockerSafeZone();
1064
- this.topClickBlocker?.setAttribute("data-state", "paused");
1065
- if (this.shouldEmitEndedOnPause()) {
1066
- this.endedLoggedOnPause = true;
1067
- console.log("event: ended");
1068
- }
1069
- };
1070
- const onEnded = () => {
1071
- clearHideTimeout();
1072
- showControls();
1073
- this.overlayBlockAll = true;
1074
- this.updateTopClickBlockerSafeZone();
1075
- this.topClickBlocker?.setAttribute("data-state", "ended");
1076
- };
1077
- const onUserInteraction = () => {
1078
- showControls();
1079
- scheduleHide();
1080
- };
1081
- this.plyr?.on?.("play", onPlay);
1082
- this.plyr?.on?.("pause", onPause);
1083
- this.plyr?.on?.("ended", onEnded);
1084
- container.addEventListener("touchstart", onUserInteraction);
1085
- container.addEventListener("click", onUserInteraction);
1086
- this.controlsVisibilityCleanup = () => {
1087
- clearHideTimeout();
1088
- this.plyr?.off?.("play", onPlay);
1089
- this.plyr?.off?.("pause", onPause);
1090
- this.plyr?.off?.("ended", onEnded);
1091
- container.removeEventListener("touchstart", onUserInteraction);
1092
- container.removeEventListener("click", onUserInteraction);
1093
- container.classList.remove("plyr--auto-hide-controls");
1094
- };
1095
- onPlay();
972
+ this.controlsVisibilityCleanup =
973
+ this.setupTouchControlsVisibility(container);
1096
974
  return;
1097
975
  }
976
+ this.controlsVisibilityCleanup =
977
+ this.setupDesktopControlsVisibility(container);
978
+ }
979
+ setupTouchControlsVisibility(container) {
980
+ const HIDE_DELAY = 2000;
981
+ let hideTimeout = null;
982
+ const clearHideTimeout = () => {
983
+ if (hideTimeout) {
984
+ clearTimeout(hideTimeout);
985
+ hideTimeout = null;
986
+ }
987
+ };
988
+ const showControls = () => {
989
+ container.classList.remove("plyr--auto-hide-controls");
990
+ };
991
+ const hideControls = () => {
992
+ if (this.plyr?.playing) {
993
+ container.classList.add("plyr--auto-hide-controls");
994
+ }
995
+ };
996
+ const scheduleHide = () => {
997
+ clearHideTimeout();
998
+ if (!this.plyr?.playing)
999
+ return;
1000
+ hideTimeout = setTimeout(() => hideControls(), HIDE_DELAY);
1001
+ };
1002
+ const onPlay = () => {
1003
+ showControls();
1004
+ this.overlayBlockAll = false;
1005
+ };
1006
+ const onPause = () => {
1007
+ clearHideTimeout();
1008
+ showControls();
1009
+ this.overlayBlockAll = true;
1010
+ this.updateTopClickBlockerSafeZone();
1011
+ this.topClickBlocker?.setAttribute("data-state", "paused");
1012
+ if (this.shouldEmitEndedOnPause()) {
1013
+ this.endedLoggedOnPause = true;
1014
+ console.log("event: ended");
1015
+ }
1016
+ };
1017
+ const onEnded = () => {
1018
+ clearHideTimeout();
1019
+ showControls();
1020
+ this.overlayBlockAll = true;
1021
+ this.updateTopClickBlockerSafeZone();
1022
+ this.topClickBlocker?.setAttribute("data-state", "ended");
1023
+ };
1024
+ const onUserInteraction = () => {
1025
+ showControls();
1026
+ scheduleHide();
1027
+ };
1028
+ this.plyr?.on?.("play", onPlay);
1029
+ this.plyr?.on?.("pause", onPause);
1030
+ this.plyr?.on?.("ended", onEnded);
1031
+ container.addEventListener("touchstart", onUserInteraction);
1032
+ container.addEventListener("click", onUserInteraction);
1033
+ onPlay();
1034
+ return () => {
1035
+ clearHideTimeout();
1036
+ this.plyr?.off?.("play", onPlay);
1037
+ this.plyr?.off?.("pause", onPause);
1038
+ this.plyr?.off?.("ended", onEnded);
1039
+ container.removeEventListener("touchstart", onUserInteraction);
1040
+ container.removeEventListener("click", onUserInteraction);
1041
+ container.classList.remove("plyr--auto-hide-controls");
1042
+ };
1043
+ }
1044
+ setupDesktopControlsVisibility(container) {
1098
1045
  let hovering = false;
1099
1046
  const toggleClass = () => {
1100
1047
  const playing = !!this.plyr?.playing;
@@ -1132,7 +1079,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1132
1079
  container.addEventListener("focusin", onFocusIn);
1133
1080
  container.addEventListener("focusout", onFocusOut);
1134
1081
  toggleClass();
1135
- this.controlsVisibilityCleanup = () => {
1082
+ return () => {
1136
1083
  this.plyr?.off?.("play", onPlay);
1137
1084
  this.plyr?.off?.("pause", onPause);
1138
1085
  this.plyr?.off?.("ended", onEnded);
@@ -1171,8 +1118,8 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1171
1118
  const speedOptions = [1, 1.25, 1.5, 2];
1172
1119
  const locale = this.resolveLocale();
1173
1120
  const captionsLanguage = this.resolveCaptionsLanguage(locale) ?? "pt";
1174
- const shouldAutoplay = this.shouldAutoplay();
1175
- const startMuted = this.requiresMutedAutoplay();
1121
+ const autoplayConfig = this.getAutoplayConfig();
1122
+ const { enabled: shouldAutoplay, startMuted } = autoplayConfig;
1176
1123
  try {
1177
1124
  this.videoRef.nativeElement.muted = startMuted;
1178
1125
  }
@@ -1186,7 +1133,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1186
1133
  this.videoRef.nativeElement.autoplay = shouldAutoplay;
1187
1134
  }
1188
1135
  catch { }
1189
- const isLive = !!this.config?.is_live;
1136
+ const isLive = this.isLivePlayback();
1190
1137
  const youtubePlayerVars = {
1191
1138
  rel: 0,
1192
1139
  modestbranding: 1,
@@ -1264,13 +1211,13 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1264
1211
  window.removeEventListener("resize", this.onResize);
1265
1212
  window.addEventListener("resize", this.onResize);
1266
1213
  this.bindProgressEvents();
1267
- this.loadSource(this.videoRef.nativeElement).then(() => {
1214
+ this.loadSource(this.videoRef.nativeElement, autoplayConfig).then(() => {
1268
1215
  this.setupStartTime();
1269
1216
  });
1270
1217
  // Dispara o evento ready quando o player estiver pronto
1271
1218
  this.plyr.on("ready", () => {
1272
1219
  this.ensureIframeAutoplayPermissions();
1273
- this.stopRestrictedIframeAutoplay();
1220
+ this.stopRestrictedIframeAutoplay(autoplayConfig);
1274
1221
  this.ready.emit();
1275
1222
  });
1276
1223
  }
@@ -1362,8 +1309,8 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1362
1309
  this.toggleRecommendationBlocker(true);
1363
1310
  });
1364
1311
  }
1365
- unmuteAfterDelay(video, delayMs = 2000, volume = 1) {
1366
- if (!this.shouldAutoplay())
1312
+ unmuteAfterDelay(video, delayMs = 2000, volume = 1, autoplayConfig = this.autoplayConfig ?? this.getAutoplayConfig()) {
1313
+ if (!autoplayConfig.enabled)
1367
1314
  return;
1368
1315
  setTimeout(() => {
1369
1316
  try {
@@ -1404,7 +1351,7 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1404
1351
  catch { }
1405
1352
  }
1406
1353
  }
1407
- loadSource(video) {
1354
+ loadSource(video, autoplayConfig) {
1408
1355
  return new Promise((resolve) => {
1409
1356
  if (!this.config) {
1410
1357
  return resolve();
@@ -1414,124 +1361,125 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1414
1361
  this.hls = undefined;
1415
1362
  }
1416
1363
  this.resetPlaybackRate(video);
1417
- if (this.config.video_host === "youtube") {
1418
- const onReady = () => {
1419
- this.plyr.off("ready", onReady);
1420
- this.ensureIframeAutoplayPermissions();
1421
- const start = this.resolveStartTime(this.config.last_time, this.config.last_percent, this.plyr.duration);
1422
- this.requestStartTimeSeek(start);
1423
- if (this.shouldAutoplay()) {
1424
- this.startAutoplayFlow();
1425
- }
1426
- else if (this.shouldBlockIframeAutoplay()) {
1427
- this.stopRestrictedIframeAutoplay();
1428
- }
1429
- if (this.shouldPreventAutoplayFromResume() || this.isAutoplayDisabledForDebug()) {
1430
- this.stopRestrictedIframeAutoplay();
1431
- }
1432
- if (this.shouldPreventAutoplayFromResume()) {
1433
- this.stopRestrictedIframeAutoplay();
1434
- }
1435
- parent.postMessage("playerIsReadyToPlay", "*");
1436
- parent.postMessage("duration:" + this.plyr.duration, "*");
1437
- console.log("event: current_time " + this.plyr.currentTime);
1438
- console.log("event: duration " + this.plyr.duration);
1439
- console.log("event: ready");
1440
- this.postCastEvent({
1441
- event: "ready",
1442
- duration: this.plyr.duration || 0,
1443
- currentTime: this.plyr.currentTime || 0,
1444
- });
1445
- if (this.config.is_live) {
1446
- this.plyr?.on("playing", function () {
1447
- console.log("event: playing_live");
1448
- parent.postMessage("event: playing_live", "*");
1449
- });
1450
- }
1451
- if (this.config.mirror) {
1452
- setTimeout(() => {
1453
- document
1454
- .querySelector(`.plyr__video-embed iframe`)
1455
- ?.classList.add("mirror");
1456
- }, 1000);
1457
- }
1458
- };
1459
- this.plyr.on("ready", onReady);
1460
- }
1461
- if (this.config.video_host === "youtube") {
1462
- this.plyr.source = {
1463
- type: "video",
1464
- sources: [{ src: this.config.video_id, provider: "youtube" }],
1465
- };
1466
- }
1467
- else if (this.config.video_host === "mp4") {
1468
- this.plyr.source = {
1469
- type: "video",
1470
- sources: [{ src: this.config.video_external_id, type: "video/mp4" }],
1471
- };
1472
- }
1473
- else if (this.config.video_host === "hls") {
1474
- let sourceX = "";
1475
- try {
1476
- sourceX = atob(this.config.video_id || "");
1477
- }
1478
- catch (e) {
1479
- sourceX = this.config.video_id || "";
1480
- }
1481
- const canNative = video.canPlayType("application/vnd.apple.mpegurl");
1482
- if (canNative) {
1483
- this.plyr.source = {
1484
- type: "video",
1485
- sources: [{ src: sourceX, type: "application/vnd.apple.mpegurl" }],
1486
- };
1487
- const onLoadedMeta = () => {
1488
- const dur = this.plyr.duration || video.duration || 0;
1489
- const start = this.resolveStartTime(this.config.last_time, this.config.last_percent, dur);
1490
- console.log(start);
1491
- this.requestStartTimeSeek(start, { video });
1492
- this.startAutoplayFlow(video);
1493
- video.removeEventListener("loadedmetadata", onLoadedMeta);
1494
- };
1495
- video.addEventListener("loadedmetadata", onLoadedMeta);
1496
- }
1497
- else if (Hls.isSupported()) {
1498
- this.hls = new Hls({ enableWorker: true, lowLatencyMode: true });
1499
- this.hls.attachMedia(video);
1500
- this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
1501
- this.hls.loadSource(sourceX);
1502
- });
1503
- this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
1504
- const dur = video.duration || 0;
1505
- const start = this.resolveStartTime(this.config.last_time, this.config.last_percent, dur);
1506
- this.requestStartTimeSeek(start, { video });
1507
- this.startAutoplayFlow(video);
1508
- });
1509
- this.hls.on(Hls.Events.ERROR, (_evt, data) => {
1510
- if (data?.fatal) {
1511
- switch (data.type) {
1512
- case Hls.ErrorTypes.NETWORK_ERROR:
1513
- this.hls.startLoad();
1514
- break;
1515
- case Hls.ErrorTypes.MEDIA_ERROR:
1516
- this.hls.recoverMediaError();
1517
- break;
1518
- default:
1519
- try {
1520
- this.hls.destroy();
1521
- }
1522
- catch { }
1523
- break;
1524
- }
1525
- }
1526
- });
1527
- }
1528
- else {
1529
- this.plyr.source = { type: "video", sources: [{ src: sourceX }] };
1530
- }
1364
+ const host = this.config.video_host;
1365
+ if (host === "youtube") {
1366
+ this.loadYoutubeSource(autoplayConfig);
1367
+ return resolve();
1368
+ }
1369
+ if (host === "mp4") {
1370
+ this.loadMp4Source();
1371
+ return resolve();
1372
+ }
1373
+ if (host === "hls") {
1374
+ this.loadHlsSource(video, autoplayConfig);
1375
+ return resolve();
1531
1376
  }
1532
1377
  resolve();
1533
1378
  });
1534
1379
  }
1380
+ loadYoutubeSource(autoplayConfig) {
1381
+ const onReady = () => {
1382
+ this.plyr.off("ready", onReady);
1383
+ this.ensureIframeAutoplayPermissions();
1384
+ this.applyStartTimeFromConfig(this.plyr.duration);
1385
+ if (autoplayConfig.enabled) {
1386
+ this.startAutoplayFlow(undefined, autoplayConfig);
1387
+ }
1388
+ else if (autoplayConfig.blockIframe) {
1389
+ this.stopRestrictedIframeAutoplay(autoplayConfig);
1390
+ }
1391
+ parent.postMessage("playerIsReadyToPlay", "*");
1392
+ parent.postMessage("duration:" + this.plyr.duration, "*");
1393
+ console.log("event: current_time " + this.plyr.currentTime);
1394
+ console.log("event: duration " + this.plyr.duration);
1395
+ console.log("event: ready");
1396
+ this.postCastEvent({
1397
+ event: "ready",
1398
+ duration: this.plyr.duration || 0,
1399
+ currentTime: this.plyr.currentTime || 0,
1400
+ });
1401
+ if (this.isLivePlayback()) {
1402
+ this.plyr?.on("playing", function () {
1403
+ console.log("event: playing_live");
1404
+ parent.postMessage("event: playing_live", "*");
1405
+ });
1406
+ }
1407
+ if (this.config?.mirror) {
1408
+ setTimeout(() => {
1409
+ document
1410
+ .querySelector(`.plyr__video-embed iframe`)
1411
+ ?.classList.add("mirror");
1412
+ }, 1000);
1413
+ }
1414
+ };
1415
+ this.plyr.on("ready", onReady);
1416
+ this.plyr.source = {
1417
+ type: "video",
1418
+ sources: [{ src: this.config?.video_id, provider: "youtube" }],
1419
+ };
1420
+ }
1421
+ loadMp4Source() {
1422
+ this.plyr.source = {
1423
+ type: "video",
1424
+ sources: [{ src: this.config?.video_external_id, type: "video/mp4" }],
1425
+ };
1426
+ }
1427
+ loadHlsSource(video, autoplayConfig) {
1428
+ let sourceX = "";
1429
+ try {
1430
+ sourceX = atob(this.config?.video_id || "");
1431
+ }
1432
+ catch (e) {
1433
+ sourceX = this.config?.video_id || "";
1434
+ }
1435
+ const canNative = video.canPlayType("application/vnd.apple.mpegurl");
1436
+ if (canNative) {
1437
+ this.plyr.source = {
1438
+ type: "video",
1439
+ sources: [{ src: sourceX, type: "application/vnd.apple.mpegurl" }],
1440
+ };
1441
+ const onLoadedMeta = () => {
1442
+ const dur = this.plyr.duration || video.duration || 0;
1443
+ console.log(this.applyStartTimeFromConfig(dur, video));
1444
+ this.startAutoplayFlow(video, autoplayConfig);
1445
+ video.removeEventListener("loadedmetadata", onLoadedMeta);
1446
+ };
1447
+ video.addEventListener("loadedmetadata", onLoadedMeta);
1448
+ return;
1449
+ }
1450
+ if (Hls.isSupported()) {
1451
+ this.hls = new Hls({ enableWorker: true, lowLatencyMode: true });
1452
+ this.hls.attachMedia(video);
1453
+ this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
1454
+ this.hls.loadSource(sourceX);
1455
+ });
1456
+ this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
1457
+ const dur = video.duration || 0;
1458
+ this.applyStartTimeFromConfig(dur, video);
1459
+ this.startAutoplayFlow(video, autoplayConfig);
1460
+ });
1461
+ this.hls.on(Hls.Events.ERROR, (_evt, data) => {
1462
+ if (data?.fatal) {
1463
+ switch (data.type) {
1464
+ case Hls.ErrorTypes.NETWORK_ERROR:
1465
+ this.hls.startLoad();
1466
+ break;
1467
+ case Hls.ErrorTypes.MEDIA_ERROR:
1468
+ this.hls.recoverMediaError();
1469
+ break;
1470
+ default:
1471
+ try {
1472
+ this.hls.destroy();
1473
+ }
1474
+ catch { }
1475
+ break;
1476
+ }
1477
+ }
1478
+ });
1479
+ return;
1480
+ }
1481
+ this.plyr.source = { type: "video", sources: [{ src: sourceX }] };
1482
+ }
1535
1483
  resolveStartTime(last_time, last_percent, duration, opts = {}) {
1536
1484
  if (this.shouldResetProgressToBeginning()) {
1537
1485
  return 0;
@@ -1581,6 +1529,11 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1581
1529
  }
1582
1530
  return 0;
1583
1531
  }
1532
+ applyStartTimeFromConfig(duration, video) {
1533
+ const start = this.resolveStartTime(this.config?.last_time, this.config?.last_percent, duration);
1534
+ this.requestStartTimeSeek(start, { video });
1535
+ return start;
1536
+ }
1584
1537
  postCastEvent(payload) {
1585
1538
  parent.postMessage(JSON.stringify(payload), "*");
1586
1539
  }
@@ -1626,8 +1579,8 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1626
1579
  }
1627
1580
  if (this.recommendationBlockerActiveZone) {
1628
1581
  try {
1629
- this.recommendationBlockerActiveZone.removeEventListener("pointerdown", this.onTopBlockerPointerDown);
1630
- this.recommendationBlockerActiveZone.removeEventListener("click", this.onRecommendationBlockerClick);
1582
+ this.recommendationBlockerActiveZone.removeEventListener("pointerdown", this.consumeEvent);
1583
+ this.recommendationBlockerActiveZone.removeEventListener("click", this.consumeEvent);
1631
1584
  }
1632
1585
  catch { }
1633
1586
  }
@@ -1635,8 +1588,8 @@ ${allPairs.map(([n, v]) => ` ${n}: ${v};`).join("\n")}
1635
1588
  this.recommendationBlockerActiveZone = null;
1636
1589
  if (this.topClickBlocker?.parentElement) {
1637
1590
  try {
1638
- this.topClickBlocker.removeEventListener("pointerdown", this.onTopBlockerPointerDown);
1639
- this.topClickBlocker.removeEventListener("click", this.onTopBlockerClick);
1591
+ this.topClickBlocker.removeEventListener("pointerdown", this.consumeEvent);
1592
+ this.topClickBlocker.removeEventListener("click", this.consumeEvent);
1640
1593
  this.topClickBlocker.parentElement.removeChild(this.topClickBlocker);
1641
1594
  }
1642
1595
  catch { }