@shortkitsdk/web 0.3.1 → 0.3.2

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/shortkit.mjs CHANGED
@@ -33542,16 +33542,35 @@ class PlayerPool {
33542
33542
  player._skCurrentUrl = streamingUrl;
33543
33543
  }
33544
33544
  /**
33545
- * Promote a preload player to active: raise buffer limits and uncap ABR.
33546
- * Safe to call even if the HLS instance was already created with active config.
33545
+ * Promote a preload player to active: raise buffer limits, uncap ABR, and
33546
+ * force an immediate quality upgrade.
33547
+ *
33548
+ * Preload streams start at level 0 (lowest rendition) to conserve bandwidth.
33549
+ * When attachStream() is called again with isActive=true for the same URL it
33550
+ * early-returns, so the HLS instance keeps its startLevel:0 config. The
33551
+ * already-buffered low-quality segments play through before any higher-quality
33552
+ * segments arrive — causing a visible low-res start even on fast connections.
33553
+ *
33554
+ * Fix: lock HLS to the highest level, then seek-in-place to flush the
33555
+ * low-quality buffer so the player immediately re-fetches at high quality.
33556
+ * Re-enable ABR after a few seconds so slow connections self-correct.
33547
33557
  */
33548
33558
  promoteToActive(itemId) {
33549
33559
  const hls = this.hlsInstances.get(itemId);
33550
- if (hls) {
33551
- hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
33552
- hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
33553
- hls.autoLevelCapping = -1;
33554
- hls.nextAutoLevel = -1;
33560
+ if (!hls) return;
33561
+ hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
33562
+ hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
33563
+ hls.autoLevelCapping = -1;
33564
+ const top = hls.levels ? hls.levels.length - 1 : -1;
33565
+ if (top > 0 && hls.currentLevel < top) {
33566
+ hls.currentLevel = top;
33567
+ const player = this.assignments.get(itemId);
33568
+ if (player) {
33569
+ player.currentTime = player.currentTime;
33570
+ }
33571
+ setTimeout(() => {
33572
+ if (!hls.destroyed) hls.currentLevel = -1;
33573
+ }, 4e3);
33555
33574
  }
33556
33575
  }
33557
33576
  /** Pause, destroy HLS, and remove player from DOM and pool tracking. */
@@ -34584,6 +34603,7 @@ class EmbeddedFeedManager {
34584
34603
  this._setupScrollEnd();
34585
34604
  this._setupVisibilityHandler();
34586
34605
  this._setupCellHeightObserver();
34606
+ this._setupDebugPanel();
34587
34607
  if (startIndex > 0 && startIndex < items.length) {
34588
34608
  const targetEl = this.itemEls.get(items[startIndex].id);
34589
34609
  if (targetEl) targetEl.scrollIntoView({ behavior: "instant", block: "start" });
@@ -34606,6 +34626,11 @@ class EmbeddedFeedManager {
34606
34626
  this._resizeObserver = null;
34607
34627
  }
34608
34628
  if (this._visHandler) document.removeEventListener("visibilitychange", this._visHandler);
34629
+ if (this._debugKeyHandler) document.removeEventListener("keydown", this._debugKeyHandler);
34630
+ if (this._debugPanel) {
34631
+ this._debugPanel.remove();
34632
+ this._debugPanel = null;
34633
+ }
34609
34634
  this.container.innerHTML = "";
34610
34635
  this.itemEls.clear();
34611
34636
  this.items = [];
@@ -34939,12 +34964,55 @@ class EmbeddedFeedManager {
34939
34964
  this._stopTimeLoop(id);
34940
34965
  this._detachOverlay(id);
34941
34966
  }
34967
+ // --- Debug panel (toggle with 'D' key) ---
34968
+ _setupDebugPanel() {
34969
+ const panel = document.createElement("div");
34970
+ panel.id = "sk-debug-panel";
34971
+ panel.style.cssText = "position:fixed;top:12px;right:12px;z-index:99999;background:rgba(0,0,0,.85);color:#0f0;font:12px/1.5 monospace;padding:10px 14px;border-radius:8px;pointer-events:none;display:none;min-width:220px;";
34972
+ document.body.appendChild(panel);
34973
+ this._debugPanel = panel;
34974
+ this._debugVisible = false;
34975
+ this._debugKeyHandler = (e) => {
34976
+ if (e.key === "d" || e.key === "D") {
34977
+ this._debugVisible = !this._debugVisible;
34978
+ panel.style.display = this._debugVisible ? "block" : "none";
34979
+ }
34980
+ };
34981
+ document.addEventListener("keydown", this._debugKeyHandler);
34982
+ }
34983
+ _updateDebugPanel() {
34984
+ if (!this._debugVisible || !this._debugPanel) return;
34985
+ const hls = this.pool.hlsInstances.get(this.activeItemId);
34986
+ if (!hls || !hls.levels || !hls.levels.length) {
34987
+ this._debugPanel.innerHTML = "HLS: no levels loaded";
34988
+ return;
34989
+ }
34990
+ const level = hls.levels[hls.currentLevel] || {};
34991
+ const bw = hls.bandwidthEstimate ? (hls.bandwidthEstimate / 1e6).toFixed(2) : "?";
34992
+ const lines = [
34993
+ `<b style="color:#fff">HLS Debug</b>`,
34994
+ `Level: ${hls.currentLevel} / ${hls.levels.length - 1}`,
34995
+ `Resolution: ${level.width || "?"}x${level.height || "?"}`,
34996
+ `Bitrate: ${level.bitrate ? (level.bitrate / 1e3).toFixed(0) + " kbps" : "?"}`,
34997
+ `BW estimate: ${bw} Mbps`,
34998
+ `Auto cap: ${hls.autoLevelCapping}`,
34999
+ `Next level: ${hls.nextLevel}`,
35000
+ `<span style="color:#888">Levels:</span>`
35001
+ ];
35002
+ for (let i = 0; i < hls.levels.length; i++) {
35003
+ const l = hls.levels[i];
35004
+ const marker = i === hls.currentLevel ? ' <b style="color:#0ff">◀</b>' : "";
35005
+ lines.push(` ${i}: ${l.width}x${l.height} @ ${(l.bitrate / 1e3).toFixed(0)}k${marker}`);
35006
+ }
35007
+ this._debugPanel.innerHTML = lines.join("<br>");
35008
+ }
34942
35009
  // --- Time loop (state emission only, no DOM updates) ---
34943
35010
  _startTimeLoop(id, el, player) {
34944
35011
  this._stopTimeLoop(id);
34945
35012
  const tick = () => {
34946
35013
  if (this._destroyed) return;
34947
35014
  if (!player || player.paused) {
35015
+ this._updateDebugPanel();
34948
35016
  this.rafIds.set(id, requestAnimationFrame(tick));
34949
35017
  return;
34950
35018
  }
@@ -34970,6 +35038,7 @@ class EmbeddedFeedManager {
34970
35038
  player.play().catch(() => {
34971
35039
  });
34972
35040
  }
35041
+ this._updateDebugPanel();
34973
35042
  this.rafIds.set(id, requestAnimationFrame(tick));
34974
35043
  };
34975
35044
  this.rafIds.set(id, requestAnimationFrame(tick));
@@ -36035,11 +36104,20 @@ class WidgetPlayerPool {
36035
36104
  }
36036
36105
  promoteToActive(itemId) {
36037
36106
  const hls = this.hlsInstances.get(itemId);
36038
- if (hls) {
36039
- hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
36040
- hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
36041
- hls.autoLevelCapping = -1;
36042
- hls.nextAutoLevel = -1;
36107
+ if (!hls) return;
36108
+ hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
36109
+ hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
36110
+ hls.autoLevelCapping = -1;
36111
+ const top = hls.levels ? hls.levels.length - 1 : -1;
36112
+ if (top > 0 && hls.currentLevel < top) {
36113
+ hls.currentLevel = top;
36114
+ const player = this.assignments.get(itemId);
36115
+ if (player) {
36116
+ player.currentTime = player.currentTime;
36117
+ }
36118
+ setTimeout(() => {
36119
+ if (!hls.destroyed) hls.currentLevel = -1;
36120
+ }, 4e3);
36043
36121
  }
36044
36122
  }
36045
36123
  _destroyHls(itemId) {
@@ -601,16 +601,35 @@ class PlayerPool {
601
601
  player._skCurrentUrl = streamingUrl;
602
602
  }
603
603
  /**
604
- * Promote a preload player to active: raise buffer limits and uncap ABR.
605
- * Safe to call even if the HLS instance was already created with active config.
604
+ * Promote a preload player to active: raise buffer limits, uncap ABR, and
605
+ * force an immediate quality upgrade.
606
+ *
607
+ * Preload streams start at level 0 (lowest rendition) to conserve bandwidth.
608
+ * When attachStream() is called again with isActive=true for the same URL it
609
+ * early-returns, so the HLS instance keeps its startLevel:0 config. The
610
+ * already-buffered low-quality segments play through before any higher-quality
611
+ * segments arrive — causing a visible low-res start even on fast connections.
612
+ *
613
+ * Fix: lock HLS to the highest level, then seek-in-place to flush the
614
+ * low-quality buffer so the player immediately re-fetches at high quality.
615
+ * Re-enable ABR after a few seconds so slow connections self-correct.
606
616
  */
607
617
  promoteToActive(itemId) {
608
618
  const hls = this.hlsInstances.get(itemId);
609
- if (hls) {
610
- hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
611
- hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
612
- hls.autoLevelCapping = -1;
613
- hls.nextAutoLevel = -1;
619
+ if (!hls) return;
620
+ hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
621
+ hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
622
+ hls.autoLevelCapping = -1;
623
+ const top = hls.levels ? hls.levels.length - 1 : -1;
624
+ if (top > 0 && hls.currentLevel < top) {
625
+ hls.currentLevel = top;
626
+ const player = this.assignments.get(itemId);
627
+ if (player) {
628
+ player.currentTime = player.currentTime;
629
+ }
630
+ setTimeout(() => {
631
+ if (!hls.destroyed) hls.currentLevel = -1;
632
+ }, 4e3);
614
633
  }
615
634
  }
616
635
  /** Pause, destroy HLS, and remove player from DOM and pool tracking. */
@@ -1643,6 +1662,7 @@ class EmbeddedFeedManager {
1643
1662
  this._setupScrollEnd();
1644
1663
  this._setupVisibilityHandler();
1645
1664
  this._setupCellHeightObserver();
1665
+ this._setupDebugPanel();
1646
1666
  if (startIndex > 0 && startIndex < items.length) {
1647
1667
  const targetEl = this.itemEls.get(items[startIndex].id);
1648
1668
  if (targetEl) targetEl.scrollIntoView({ behavior: "instant", block: "start" });
@@ -1665,6 +1685,11 @@ class EmbeddedFeedManager {
1665
1685
  this._resizeObserver = null;
1666
1686
  }
1667
1687
  if (this._visHandler) document.removeEventListener("visibilitychange", this._visHandler);
1688
+ if (this._debugKeyHandler) document.removeEventListener("keydown", this._debugKeyHandler);
1689
+ if (this._debugPanel) {
1690
+ this._debugPanel.remove();
1691
+ this._debugPanel = null;
1692
+ }
1668
1693
  this.container.innerHTML = "";
1669
1694
  this.itemEls.clear();
1670
1695
  this.items = [];
@@ -1998,12 +2023,55 @@ class EmbeddedFeedManager {
1998
2023
  this._stopTimeLoop(id);
1999
2024
  this._detachOverlay(id);
2000
2025
  }
2026
+ // --- Debug panel (toggle with 'D' key) ---
2027
+ _setupDebugPanel() {
2028
+ const panel = document.createElement("div");
2029
+ panel.id = "sk-debug-panel";
2030
+ panel.style.cssText = "position:fixed;top:12px;right:12px;z-index:99999;background:rgba(0,0,0,.85);color:#0f0;font:12px/1.5 monospace;padding:10px 14px;border-radius:8px;pointer-events:none;display:none;min-width:220px;";
2031
+ document.body.appendChild(panel);
2032
+ this._debugPanel = panel;
2033
+ this._debugVisible = false;
2034
+ this._debugKeyHandler = (e) => {
2035
+ if (e.key === "d" || e.key === "D") {
2036
+ this._debugVisible = !this._debugVisible;
2037
+ panel.style.display = this._debugVisible ? "block" : "none";
2038
+ }
2039
+ };
2040
+ document.addEventListener("keydown", this._debugKeyHandler);
2041
+ }
2042
+ _updateDebugPanel() {
2043
+ if (!this._debugVisible || !this._debugPanel) return;
2044
+ const hls = this.pool.hlsInstances.get(this.activeItemId);
2045
+ if (!hls || !hls.levels || !hls.levels.length) {
2046
+ this._debugPanel.innerHTML = "HLS: no levels loaded";
2047
+ return;
2048
+ }
2049
+ const level = hls.levels[hls.currentLevel] || {};
2050
+ const bw = hls.bandwidthEstimate ? (hls.bandwidthEstimate / 1e6).toFixed(2) : "?";
2051
+ const lines = [
2052
+ `<b style="color:#fff">HLS Debug</b>`,
2053
+ `Level: ${hls.currentLevel} / ${hls.levels.length - 1}`,
2054
+ `Resolution: ${level.width || "?"}x${level.height || "?"}`,
2055
+ `Bitrate: ${level.bitrate ? (level.bitrate / 1e3).toFixed(0) + " kbps" : "?"}`,
2056
+ `BW estimate: ${bw} Mbps`,
2057
+ `Auto cap: ${hls.autoLevelCapping}`,
2058
+ `Next level: ${hls.nextLevel}`,
2059
+ `<span style="color:#888">Levels:</span>`
2060
+ ];
2061
+ for (let i = 0; i < hls.levels.length; i++) {
2062
+ const l = hls.levels[i];
2063
+ const marker = i === hls.currentLevel ? ' <b style="color:#0ff">◀</b>' : "";
2064
+ lines.push(` ${i}: ${l.width}x${l.height} @ ${(l.bitrate / 1e3).toFixed(0)}k${marker}`);
2065
+ }
2066
+ this._debugPanel.innerHTML = lines.join("<br>");
2067
+ }
2001
2068
  // --- Time loop (state emission only, no DOM updates) ---
2002
2069
  _startTimeLoop(id, el, player) {
2003
2070
  this._stopTimeLoop(id);
2004
2071
  const tick = () => {
2005
2072
  if (this._destroyed) return;
2006
2073
  if (!player || player.paused) {
2074
+ this._updateDebugPanel();
2007
2075
  this.rafIds.set(id, requestAnimationFrame(tick));
2008
2076
  return;
2009
2077
  }
@@ -2029,6 +2097,7 @@ class EmbeddedFeedManager {
2029
2097
  player.play().catch(() => {
2030
2098
  });
2031
2099
  }
2100
+ this._updateDebugPanel();
2032
2101
  this.rafIds.set(id, requestAnimationFrame(tick));
2033
2102
  };
2034
2103
  this.rafIds.set(id, requestAnimationFrame(tick));
@@ -3094,11 +3163,20 @@ class WidgetPlayerPool {
3094
3163
  }
3095
3164
  promoteToActive(itemId) {
3096
3165
  const hls = this.hlsInstances.get(itemId);
3097
- if (hls) {
3098
- hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
3099
- hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
3100
- hls.autoLevelCapping = -1;
3101
- hls.nextAutoLevel = -1;
3166
+ if (!hls) return;
3167
+ hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
3168
+ hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
3169
+ hls.autoLevelCapping = -1;
3170
+ const top = hls.levels ? hls.levels.length - 1 : -1;
3171
+ if (top > 0 && hls.currentLevel < top) {
3172
+ hls.currentLevel = top;
3173
+ const player = this.assignments.get(itemId);
3174
+ if (player) {
3175
+ player.currentTime = player.currentTime;
3176
+ }
3177
+ setTimeout(() => {
3178
+ if (!hls.destroyed) hls.currentLevel = -1;
3179
+ }, 4e3);
3102
3180
  }
3103
3181
  }
3104
3182
  _destroyHls(itemId) {
@@ -603,16 +603,35 @@
603
603
  player._skCurrentUrl = streamingUrl;
604
604
  }
605
605
  /**
606
- * Promote a preload player to active: raise buffer limits and uncap ABR.
607
- * Safe to call even if the HLS instance was already created with active config.
606
+ * Promote a preload player to active: raise buffer limits, uncap ABR, and
607
+ * force an immediate quality upgrade.
608
+ *
609
+ * Preload streams start at level 0 (lowest rendition) to conserve bandwidth.
610
+ * When attachStream() is called again with isActive=true for the same URL it
611
+ * early-returns, so the HLS instance keeps its startLevel:0 config. The
612
+ * already-buffered low-quality segments play through before any higher-quality
613
+ * segments arrive — causing a visible low-res start even on fast connections.
614
+ *
615
+ * Fix: lock HLS to the highest level, then seek-in-place to flush the
616
+ * low-quality buffer so the player immediately re-fetches at high quality.
617
+ * Re-enable ABR after a few seconds so slow connections self-correct.
608
618
  */
609
619
  promoteToActive(itemId) {
610
620
  const hls = this.hlsInstances.get(itemId);
611
- if (hls) {
612
- hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
613
- hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
614
- hls.autoLevelCapping = -1;
615
- hls.nextAutoLevel = -1;
621
+ if (!hls) return;
622
+ hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
623
+ hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
624
+ hls.autoLevelCapping = -1;
625
+ const top = hls.levels ? hls.levels.length - 1 : -1;
626
+ if (top > 0 && hls.currentLevel < top) {
627
+ hls.currentLevel = top;
628
+ const player = this.assignments.get(itemId);
629
+ if (player) {
630
+ player.currentTime = player.currentTime;
631
+ }
632
+ setTimeout(() => {
633
+ if (!hls.destroyed) hls.currentLevel = -1;
634
+ }, 4e3);
616
635
  }
617
636
  }
618
637
  /** Pause, destroy HLS, and remove player from DOM and pool tracking. */
@@ -1645,6 +1664,7 @@
1645
1664
  this._setupScrollEnd();
1646
1665
  this._setupVisibilityHandler();
1647
1666
  this._setupCellHeightObserver();
1667
+ this._setupDebugPanel();
1648
1668
  if (startIndex > 0 && startIndex < items.length) {
1649
1669
  const targetEl = this.itemEls.get(items[startIndex].id);
1650
1670
  if (targetEl) targetEl.scrollIntoView({ behavior: "instant", block: "start" });
@@ -1667,6 +1687,11 @@
1667
1687
  this._resizeObserver = null;
1668
1688
  }
1669
1689
  if (this._visHandler) document.removeEventListener("visibilitychange", this._visHandler);
1690
+ if (this._debugKeyHandler) document.removeEventListener("keydown", this._debugKeyHandler);
1691
+ if (this._debugPanel) {
1692
+ this._debugPanel.remove();
1693
+ this._debugPanel = null;
1694
+ }
1670
1695
  this.container.innerHTML = "";
1671
1696
  this.itemEls.clear();
1672
1697
  this.items = [];
@@ -2000,12 +2025,55 @@
2000
2025
  this._stopTimeLoop(id);
2001
2026
  this._detachOverlay(id);
2002
2027
  }
2028
+ // --- Debug panel (toggle with 'D' key) ---
2029
+ _setupDebugPanel() {
2030
+ const panel = document.createElement("div");
2031
+ panel.id = "sk-debug-panel";
2032
+ panel.style.cssText = "position:fixed;top:12px;right:12px;z-index:99999;background:rgba(0,0,0,.85);color:#0f0;font:12px/1.5 monospace;padding:10px 14px;border-radius:8px;pointer-events:none;display:none;min-width:220px;";
2033
+ document.body.appendChild(panel);
2034
+ this._debugPanel = panel;
2035
+ this._debugVisible = false;
2036
+ this._debugKeyHandler = (e) => {
2037
+ if (e.key === "d" || e.key === "D") {
2038
+ this._debugVisible = !this._debugVisible;
2039
+ panel.style.display = this._debugVisible ? "block" : "none";
2040
+ }
2041
+ };
2042
+ document.addEventListener("keydown", this._debugKeyHandler);
2043
+ }
2044
+ _updateDebugPanel() {
2045
+ if (!this._debugVisible || !this._debugPanel) return;
2046
+ const hls = this.pool.hlsInstances.get(this.activeItemId);
2047
+ if (!hls || !hls.levels || !hls.levels.length) {
2048
+ this._debugPanel.innerHTML = "HLS: no levels loaded";
2049
+ return;
2050
+ }
2051
+ const level = hls.levels[hls.currentLevel] || {};
2052
+ const bw = hls.bandwidthEstimate ? (hls.bandwidthEstimate / 1e6).toFixed(2) : "?";
2053
+ const lines = [
2054
+ `<b style="color:#fff">HLS Debug</b>`,
2055
+ `Level: ${hls.currentLevel} / ${hls.levels.length - 1}`,
2056
+ `Resolution: ${level.width || "?"}x${level.height || "?"}`,
2057
+ `Bitrate: ${level.bitrate ? (level.bitrate / 1e3).toFixed(0) + " kbps" : "?"}`,
2058
+ `BW estimate: ${bw} Mbps`,
2059
+ `Auto cap: ${hls.autoLevelCapping}`,
2060
+ `Next level: ${hls.nextLevel}`,
2061
+ `<span style="color:#888">Levels:</span>`
2062
+ ];
2063
+ for (let i = 0; i < hls.levels.length; i++) {
2064
+ const l = hls.levels[i];
2065
+ const marker = i === hls.currentLevel ? ' <b style="color:#0ff">◀</b>' : "";
2066
+ lines.push(` ${i}: ${l.width}x${l.height} @ ${(l.bitrate / 1e3).toFixed(0)}k${marker}`);
2067
+ }
2068
+ this._debugPanel.innerHTML = lines.join("<br>");
2069
+ }
2003
2070
  // --- Time loop (state emission only, no DOM updates) ---
2004
2071
  _startTimeLoop(id, el, player) {
2005
2072
  this._stopTimeLoop(id);
2006
2073
  const tick = () => {
2007
2074
  if (this._destroyed) return;
2008
2075
  if (!player || player.paused) {
2076
+ this._updateDebugPanel();
2009
2077
  this.rafIds.set(id, requestAnimationFrame(tick));
2010
2078
  return;
2011
2079
  }
@@ -2031,6 +2099,7 @@
2031
2099
  player.play().catch(() => {
2032
2100
  });
2033
2101
  }
2102
+ this._updateDebugPanel();
2034
2103
  this.rafIds.set(id, requestAnimationFrame(tick));
2035
2104
  };
2036
2105
  this.rafIds.set(id, requestAnimationFrame(tick));
@@ -3096,11 +3165,20 @@
3096
3165
  }
3097
3166
  promoteToActive(itemId) {
3098
3167
  const hls = this.hlsInstances.get(itemId);
3099
- if (hls) {
3100
- hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
3101
- hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
3102
- hls.autoLevelCapping = -1;
3103
- hls.nextAutoLevel = -1;
3168
+ if (!hls) return;
3169
+ hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
3170
+ hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
3171
+ hls.autoLevelCapping = -1;
3172
+ const top = hls.levels ? hls.levels.length - 1 : -1;
3173
+ if (top > 0 && hls.currentLevel < top) {
3174
+ hls.currentLevel = top;
3175
+ const player = this.assignments.get(itemId);
3176
+ if (player) {
3177
+ player.currentTime = player.currentTime;
3178
+ }
3179
+ setTimeout(() => {
3180
+ if (!hls.destroyed) hls.currentLevel = -1;
3181
+ }, 4e3);
3104
3182
  }
3105
3183
  }
3106
3184
  _destroyHls(itemId) {