@shortkitsdk/web 0.3.2 → 0.3.3

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.cjs CHANGED
@@ -33544,35 +33544,16 @@ class PlayerPool {
33544
33544
  player._skCurrentUrl = streamingUrl;
33545
33545
  }
33546
33546
  /**
33547
- * Promote a preload player to active: raise buffer limits, uncap ABR, and
33548
- * force an immediate quality upgrade.
33549
- *
33550
- * Preload streams start at level 0 (lowest rendition) to conserve bandwidth.
33551
- * When attachStream() is called again with isActive=true for the same URL it
33552
- * early-returns, so the HLS instance keeps its startLevel:0 config. The
33553
- * already-buffered low-quality segments play through before any higher-quality
33554
- * segments arrive — causing a visible low-res start even on fast connections.
33555
- *
33556
- * Fix: lock HLS to the highest level, then seek-in-place to flush the
33557
- * low-quality buffer so the player immediately re-fetches at high quality.
33558
- * Re-enable ABR after a few seconds so slow connections self-correct.
33547
+ * Promote a preload player to active: raise buffer limits and uncap ABR.
33548
+ * Safe to call even if the HLS instance was already created with active config.
33559
33549
  */
33560
33550
  promoteToActive(itemId) {
33561
33551
  const hls = this.hlsInstances.get(itemId);
33562
- if (!hls) return;
33563
- hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
33564
- hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
33565
- hls.autoLevelCapping = -1;
33566
- const top = hls.levels ? hls.levels.length - 1 : -1;
33567
- if (top > 0 && hls.currentLevel < top) {
33568
- hls.currentLevel = top;
33569
- const player = this.assignments.get(itemId);
33570
- if (player) {
33571
- player.currentTime = player.currentTime;
33572
- }
33573
- setTimeout(() => {
33574
- if (!hls.destroyed) hls.currentLevel = -1;
33575
- }, 4e3);
33552
+ if (hls) {
33553
+ hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
33554
+ hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
33555
+ hls.autoLevelCapping = -1;
33556
+ hls.nextAutoLevel = -1;
33576
33557
  }
33577
33558
  }
33578
33559
  /** Pause, destroy HLS, and remove player from DOM and pool tracking. */
@@ -34605,7 +34586,6 @@ class EmbeddedFeedManager {
34605
34586
  this._setupScrollEnd();
34606
34587
  this._setupVisibilityHandler();
34607
34588
  this._setupCellHeightObserver();
34608
- this._setupDebugPanel();
34609
34589
  if (startIndex > 0 && startIndex < items.length) {
34610
34590
  const targetEl = this.itemEls.get(items[startIndex].id);
34611
34591
  if (targetEl) targetEl.scrollIntoView({ behavior: "instant", block: "start" });
@@ -34628,11 +34608,6 @@ class EmbeddedFeedManager {
34628
34608
  this._resizeObserver = null;
34629
34609
  }
34630
34610
  if (this._visHandler) document.removeEventListener("visibilitychange", this._visHandler);
34631
- if (this._debugKeyHandler) document.removeEventListener("keydown", this._debugKeyHandler);
34632
- if (this._debugPanel) {
34633
- this._debugPanel.remove();
34634
- this._debugPanel = null;
34635
- }
34636
34611
  this.container.innerHTML = "";
34637
34612
  this.itemEls.clear();
34638
34613
  this.items = [];
@@ -34966,55 +34941,12 @@ class EmbeddedFeedManager {
34966
34941
  this._stopTimeLoop(id);
34967
34942
  this._detachOverlay(id);
34968
34943
  }
34969
- // --- Debug panel (toggle with 'D' key) ---
34970
- _setupDebugPanel() {
34971
- const panel = document.createElement("div");
34972
- panel.id = "sk-debug-panel";
34973
- 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;";
34974
- document.body.appendChild(panel);
34975
- this._debugPanel = panel;
34976
- this._debugVisible = false;
34977
- this._debugKeyHandler = (e) => {
34978
- if (e.key === "d" || e.key === "D") {
34979
- this._debugVisible = !this._debugVisible;
34980
- panel.style.display = this._debugVisible ? "block" : "none";
34981
- }
34982
- };
34983
- document.addEventListener("keydown", this._debugKeyHandler);
34984
- }
34985
- _updateDebugPanel() {
34986
- if (!this._debugVisible || !this._debugPanel) return;
34987
- const hls = this.pool.hlsInstances.get(this.activeItemId);
34988
- if (!hls || !hls.levels || !hls.levels.length) {
34989
- this._debugPanel.innerHTML = "HLS: no levels loaded";
34990
- return;
34991
- }
34992
- const level = hls.levels[hls.currentLevel] || {};
34993
- const bw = hls.bandwidthEstimate ? (hls.bandwidthEstimate / 1e6).toFixed(2) : "?";
34994
- const lines = [
34995
- `<b style="color:#fff">HLS Debug</b>`,
34996
- `Level: ${hls.currentLevel} / ${hls.levels.length - 1}`,
34997
- `Resolution: ${level.width || "?"}x${level.height || "?"}`,
34998
- `Bitrate: ${level.bitrate ? (level.bitrate / 1e3).toFixed(0) + " kbps" : "?"}`,
34999
- `BW estimate: ${bw} Mbps`,
35000
- `Auto cap: ${hls.autoLevelCapping}`,
35001
- `Next level: ${hls.nextLevel}`,
35002
- `<span style="color:#888">Levels:</span>`
35003
- ];
35004
- for (let i = 0; i < hls.levels.length; i++) {
35005
- const l = hls.levels[i];
35006
- const marker = i === hls.currentLevel ? ' <b style="color:#0ff">◀</b>' : "";
35007
- lines.push(` ${i}: ${l.width}x${l.height} @ ${(l.bitrate / 1e3).toFixed(0)}k${marker}`);
35008
- }
35009
- this._debugPanel.innerHTML = lines.join("<br>");
35010
- }
35011
34944
  // --- Time loop (state emission only, no DOM updates) ---
35012
34945
  _startTimeLoop(id, el, player) {
35013
34946
  this._stopTimeLoop(id);
35014
34947
  const tick = () => {
35015
34948
  if (this._destroyed) return;
35016
34949
  if (!player || player.paused) {
35017
- this._updateDebugPanel();
35018
34950
  this.rafIds.set(id, requestAnimationFrame(tick));
35019
34951
  return;
35020
34952
  }
@@ -35040,7 +34972,6 @@ class EmbeddedFeedManager {
35040
34972
  player.play().catch(() => {
35041
34973
  });
35042
34974
  }
35043
- this._updateDebugPanel();
35044
34975
  this.rafIds.set(id, requestAnimationFrame(tick));
35045
34976
  };
35046
34977
  this.rafIds.set(id, requestAnimationFrame(tick));
@@ -36106,20 +36037,11 @@ class WidgetPlayerPool {
36106
36037
  }
36107
36038
  promoteToActive(itemId) {
36108
36039
  const hls = this.hlsInstances.get(itemId);
36109
- if (!hls) return;
36110
- hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
36111
- hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
36112
- hls.autoLevelCapping = -1;
36113
- const top = hls.levels ? hls.levels.length - 1 : -1;
36114
- if (top > 0 && hls.currentLevel < top) {
36115
- hls.currentLevel = top;
36116
- const player = this.assignments.get(itemId);
36117
- if (player) {
36118
- player.currentTime = player.currentTime;
36119
- }
36120
- setTimeout(() => {
36121
- if (!hls.destroyed) hls.currentLevel = -1;
36122
- }, 4e3);
36040
+ if (hls) {
36041
+ hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
36042
+ hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
36043
+ hls.autoLevelCapping = -1;
36044
+ hls.nextAutoLevel = -1;
36123
36045
  }
36124
36046
  }
36125
36047
  _destroyHls(itemId) {
package/dist/shortkit.js CHANGED
@@ -33546,35 +33546,16 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
33546
33546
  player._skCurrentUrl = streamingUrl;
33547
33547
  }
33548
33548
  /**
33549
- * Promote a preload player to active: raise buffer limits, uncap ABR, and
33550
- * force an immediate quality upgrade.
33551
- *
33552
- * Preload streams start at level 0 (lowest rendition) to conserve bandwidth.
33553
- * When attachStream() is called again with isActive=true for the same URL it
33554
- * early-returns, so the HLS instance keeps its startLevel:0 config. The
33555
- * already-buffered low-quality segments play through before any higher-quality
33556
- * segments arrive — causing a visible low-res start even on fast connections.
33557
- *
33558
- * Fix: lock HLS to the highest level, then seek-in-place to flush the
33559
- * low-quality buffer so the player immediately re-fetches at high quality.
33560
- * Re-enable ABR after a few seconds so slow connections self-correct.
33549
+ * Promote a preload player to active: raise buffer limits and uncap ABR.
33550
+ * Safe to call even if the HLS instance was already created with active config.
33561
33551
  */
33562
33552
  promoteToActive(itemId) {
33563
33553
  const hls = this.hlsInstances.get(itemId);
33564
- if (!hls) return;
33565
- hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
33566
- hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
33567
- hls.autoLevelCapping = -1;
33568
- const top = hls.levels ? hls.levels.length - 1 : -1;
33569
- if (top > 0 && hls.currentLevel < top) {
33570
- hls.currentLevel = top;
33571
- const player = this.assignments.get(itemId);
33572
- if (player) {
33573
- player.currentTime = player.currentTime;
33574
- }
33575
- setTimeout(() => {
33576
- if (!hls.destroyed) hls.currentLevel = -1;
33577
- }, 4e3);
33554
+ if (hls) {
33555
+ hls.config.maxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
33556
+ hls.config.maxMaxBufferLength = PlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
33557
+ hls.autoLevelCapping = -1;
33558
+ hls.nextAutoLevel = -1;
33578
33559
  }
33579
33560
  }
33580
33561
  /** Pause, destroy HLS, and remove player from DOM and pool tracking. */
@@ -34607,7 +34588,6 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
34607
34588
  this._setupScrollEnd();
34608
34589
  this._setupVisibilityHandler();
34609
34590
  this._setupCellHeightObserver();
34610
- this._setupDebugPanel();
34611
34591
  if (startIndex > 0 && startIndex < items.length) {
34612
34592
  const targetEl = this.itemEls.get(items[startIndex].id);
34613
34593
  if (targetEl) targetEl.scrollIntoView({ behavior: "instant", block: "start" });
@@ -34630,11 +34610,6 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
34630
34610
  this._resizeObserver = null;
34631
34611
  }
34632
34612
  if (this._visHandler) document.removeEventListener("visibilitychange", this._visHandler);
34633
- if (this._debugKeyHandler) document.removeEventListener("keydown", this._debugKeyHandler);
34634
- if (this._debugPanel) {
34635
- this._debugPanel.remove();
34636
- this._debugPanel = null;
34637
- }
34638
34613
  this.container.innerHTML = "";
34639
34614
  this.itemEls.clear();
34640
34615
  this.items = [];
@@ -34968,55 +34943,12 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
34968
34943
  this._stopTimeLoop(id);
34969
34944
  this._detachOverlay(id);
34970
34945
  }
34971
- // --- Debug panel (toggle with 'D' key) ---
34972
- _setupDebugPanel() {
34973
- const panel = document.createElement("div");
34974
- panel.id = "sk-debug-panel";
34975
- 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;";
34976
- document.body.appendChild(panel);
34977
- this._debugPanel = panel;
34978
- this._debugVisible = false;
34979
- this._debugKeyHandler = (e) => {
34980
- if (e.key === "d" || e.key === "D") {
34981
- this._debugVisible = !this._debugVisible;
34982
- panel.style.display = this._debugVisible ? "block" : "none";
34983
- }
34984
- };
34985
- document.addEventListener("keydown", this._debugKeyHandler);
34986
- }
34987
- _updateDebugPanel() {
34988
- if (!this._debugVisible || !this._debugPanel) return;
34989
- const hls = this.pool.hlsInstances.get(this.activeItemId);
34990
- if (!hls || !hls.levels || !hls.levels.length) {
34991
- this._debugPanel.innerHTML = "HLS: no levels loaded";
34992
- return;
34993
- }
34994
- const level = hls.levels[hls.currentLevel] || {};
34995
- const bw = hls.bandwidthEstimate ? (hls.bandwidthEstimate / 1e6).toFixed(2) : "?";
34996
- const lines = [
34997
- `<b style="color:#fff">HLS Debug</b>`,
34998
- `Level: ${hls.currentLevel} / ${hls.levels.length - 1}`,
34999
- `Resolution: ${level.width || "?"}x${level.height || "?"}`,
35000
- `Bitrate: ${level.bitrate ? (level.bitrate / 1e3).toFixed(0) + " kbps" : "?"}`,
35001
- `BW estimate: ${bw} Mbps`,
35002
- `Auto cap: ${hls.autoLevelCapping}`,
35003
- `Next level: ${hls.nextLevel}`,
35004
- `<span style="color:#888">Levels:</span>`
35005
- ];
35006
- for (let i = 0; i < hls.levels.length; i++) {
35007
- const l = hls.levels[i];
35008
- const marker = i === hls.currentLevel ? ' <b style="color:#0ff">◀</b>' : "";
35009
- lines.push(` ${i}: ${l.width}x${l.height} @ ${(l.bitrate / 1e3).toFixed(0)}k${marker}`);
35010
- }
35011
- this._debugPanel.innerHTML = lines.join("<br>");
35012
- }
35013
34946
  // --- Time loop (state emission only, no DOM updates) ---
35014
34947
  _startTimeLoop(id, el, player) {
35015
34948
  this._stopTimeLoop(id);
35016
34949
  const tick = () => {
35017
34950
  if (this._destroyed) return;
35018
34951
  if (!player || player.paused) {
35019
- this._updateDebugPanel();
35020
34952
  this.rafIds.set(id, requestAnimationFrame(tick));
35021
34953
  return;
35022
34954
  }
@@ -35042,7 +34974,6 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
35042
34974
  player.play().catch(() => {
35043
34975
  });
35044
34976
  }
35045
- this._updateDebugPanel();
35046
34977
  this.rafIds.set(id, requestAnimationFrame(tick));
35047
34978
  };
35048
34979
  this.rafIds.set(id, requestAnimationFrame(tick));
@@ -36108,20 +36039,11 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
36108
36039
  }
36109
36040
  promoteToActive(itemId) {
36110
36041
  const hls = this.hlsInstances.get(itemId);
36111
- if (!hls) return;
36112
- hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
36113
- hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
36114
- hls.autoLevelCapping = -1;
36115
- const top = hls.levels ? hls.levels.length - 1 : -1;
36116
- if (top > 0 && hls.currentLevel < top) {
36117
- hls.currentLevel = top;
36118
- const player = this.assignments.get(itemId);
36119
- if (player) {
36120
- player.currentTime = player.currentTime;
36121
- }
36122
- setTimeout(() => {
36123
- if (!hls.destroyed) hls.currentLevel = -1;
36124
- }, 4e3);
36042
+ if (hls) {
36043
+ hls.config.maxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxBufferLength;
36044
+ hls.config.maxMaxBufferLength = WidgetPlayerPool.ACTIVE_HLS_CONFIG.maxMaxBufferLength;
36045
+ hls.autoLevelCapping = -1;
36046
+ hls.nextAutoLevel = -1;
36125
36047
  }
36126
36048
  }
36127
36049
  _destroyHls(itemId) {