stormcloud-video-player 0.8.77 → 0.8.79

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.
Files changed (39) hide show
  1. package/dist/stormcloud-vp.min.js +1 -1
  2. package/lib/Player.cjs +2 -0
  3. package/lib/Player.cjs.map +1 -1
  4. package/lib/Player.d.cts +1 -1
  5. package/lib/StormcloudPlayer.cjs +230 -7
  6. package/lib/StormcloudPlayer.cjs.map +1 -1
  7. package/lib/index.cjs +230 -7
  8. package/lib/index.cjs.map +1 -1
  9. package/lib/index.d.ts +4 -1
  10. package/lib/index.js +231 -7
  11. package/lib/index.js.map +1 -1
  12. package/lib/player/AdBreakOrchestrator.cjs +5 -1
  13. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  14. package/lib/player/AdConfigManager.cjs +3 -1
  15. package/lib/player/AdConfigManager.cjs.map +1 -1
  16. package/lib/player/ContentHealthWatchdog.cjs +255 -0
  17. package/lib/player/ContentHealthWatchdog.cjs.map +1 -0
  18. package/lib/player/ContentHealthWatchdog.d.cts +40 -0
  19. package/lib/player/StormcloudVideoPlayer.cjs +230 -7
  20. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  21. package/lib/player/StormcloudVideoPlayer.d.cts +1 -0
  22. package/lib/players/HlsPlayer.cjs +230 -7
  23. package/lib/players/HlsPlayer.cjs.map +1 -1
  24. package/lib/players/index.cjs +230 -7
  25. package/lib/players/index.cjs.map +1 -1
  26. package/lib/props.cjs +2 -0
  27. package/lib/props.cjs.map +1 -1
  28. package/lib/sdk/hlsAdPlayer.cjs +16 -6
  29. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  30. package/lib/types.d.cts +2 -0
  31. package/lib/ui/StormcloudVideoPlayer.cjs +230 -7
  32. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  33. package/lib/utils/browserCompat.cjs +7 -0
  34. package/lib/utils/browserCompat.cjs.map +1 -1
  35. package/lib/utils/browserCompat.d.cts +2 -1
  36. package/lib/utils/tracking.cjs +5 -1
  37. package/lib/utils/tracking.cjs.map +1 -1
  38. package/lib/utils/tracking.d.cts +1 -1
  39. package/package.json +2 -2
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ function _class_call_check(instance, Constructor) {
3
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ function _defineProperties(target, props) {
6
+ for(var i = 0; i < props.length; i++){
7
+ var descriptor = props[i];
8
+ descriptor.enumerable = descriptor.enumerable || false;
9
+ descriptor.configurable = true;
10
+ if ("value" in descriptor) descriptor.writable = true;
11
+ Object.defineProperty(target, descriptor.key, descriptor);
12
+ }
13
+ }
14
+ function _create_class(Constructor, protoProps, staticProps) {
15
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
16
+ if (staticProps) _defineProperties(Constructor, staticProps);
17
+ return Constructor;
18
+ }
19
+ function _type_of(obj) {
20
+ "@swc/helpers - typeof";
21
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
22
+ }
23
+ var __defProp = Object.defineProperty;
24
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
25
+ var __getOwnPropNames = Object.getOwnPropertyNames;
26
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
27
+ var __export = function __export(target, all) {
28
+ for(var name in all)__defProp(target, name, {
29
+ get: all[name],
30
+ enumerable: true
31
+ });
32
+ };
33
+ var __copyProps = function __copyProps(to, from, except, desc) {
34
+ if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
35
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
36
+ try {
37
+ var _loop = function() {
38
+ var key = _step.value;
39
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
40
+ get: function get() {
41
+ return from[key];
42
+ },
43
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
44
+ });
45
+ };
46
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
47
+ } catch (err) {
48
+ _didIteratorError = true;
49
+ _iteratorError = err;
50
+ } finally{
51
+ try {
52
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
53
+ _iterator.return();
54
+ }
55
+ } finally{
56
+ if (_didIteratorError) {
57
+ throw _iteratorError;
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return to;
63
+ };
64
+ var __toCommonJS = function __toCommonJS(mod) {
65
+ return __copyProps(__defProp({}, "__esModule", {
66
+ value: true
67
+ }), mod);
68
+ };
69
+ // src/player/ContentHealthWatchdog.ts
70
+ var ContentHealthWatchdog_exports = {};
71
+ __export(ContentHealthWatchdog_exports, {
72
+ ContentHealthWatchdog: function ContentHealthWatchdog1() {
73
+ return ContentHealthWatchdog;
74
+ }
75
+ });
76
+ module.exports = __toCommonJS(ContentHealthWatchdog_exports);
77
+ var POLL_INTERVAL_MS = 2e3;
78
+ var STALL_THRESHOLD_MS = 12e3;
79
+ var POST_BREAK_GRACE_MS = 5e4;
80
+ var MAX_BREAK_SUPPRESSION_MS = 10 * 60 * 1e3;
81
+ var SELF_INFLICTED_PAUSE_WINDOW_MS = 5e3;
82
+ var HEALTHY_PLAYBACK_SECONDS = 5;
83
+ var MAX_NORMAL_ADVANCE_PER_TICK_S = 4;
84
+ var LIGHT_STEP_COOLDOWN_MS = 1e4;
85
+ var RELOAD_BASE_COOLDOWN_MS = 15e3;
86
+ var RELOAD_MAX_COOLDOWN_MS = 12e4;
87
+ var ContentHealthWatchdog = /*#__PURE__*/ function() {
88
+ function ContentHealthWatchdog(host) {
89
+ var _this = this;
90
+ _class_call_check(this, ContentHealthWatchdog);
91
+ this.host = host;
92
+ this.armed = false;
93
+ this.userPaused = false;
94
+ this.wasInBreak = false;
95
+ this.breakStartedAt = 0;
96
+ this.stuckBreakLogged = false;
97
+ this.graceUntil = 0;
98
+ this.lastPosition = 0;
99
+ this.lastProgressAt = 0;
100
+ this.lastRealPlaybackAt = 0;
101
+ this.healthySeconds = 0;
102
+ this.step = 0;
103
+ this.nextActionAt = 0;
104
+ this.lastActionAt = 0;
105
+ this.onPlaying = function() {
106
+ if (_this.host.isAdPlaying()) return;
107
+ _this.armed = true;
108
+ _this.userPaused = false;
109
+ };
110
+ this.onPause = function() {
111
+ if (_this.host.isBreakActive() || _this.host.isAdPlaying() || Date.now() - _this.lastActionAt < SELF_INFLICTED_PAUSE_WINDOW_MS) {
112
+ return;
113
+ }
114
+ _this.userPaused = true;
115
+ };
116
+ this.onPlay = function() {
117
+ _this.userPaused = false;
118
+ };
119
+ }
120
+ _create_class(ContentHealthWatchdog, [
121
+ {
122
+ key: "start",
123
+ value: function start() {
124
+ var _this = this;
125
+ if (this.intervalId !== void 0) return;
126
+ var video = this.host.video;
127
+ video.addEventListener("playing", this.onPlaying);
128
+ video.addEventListener("pause", this.onPause);
129
+ video.addEventListener("play", this.onPlay);
130
+ this.resetProgress(Date.now());
131
+ this.intervalId = window.setInterval(function() {
132
+ return _this.tick();
133
+ }, POLL_INTERVAL_MS);
134
+ }
135
+ },
136
+ {
137
+ key: "stop",
138
+ value: function stop() {
139
+ if (this.intervalId !== void 0) {
140
+ clearInterval(this.intervalId);
141
+ this.intervalId = void 0;
142
+ }
143
+ var video = this.host.video;
144
+ video.removeEventListener("playing", this.onPlaying);
145
+ video.removeEventListener("pause", this.onPause);
146
+ video.removeEventListener("play", this.onPlay);
147
+ this.armed = false;
148
+ this.step = 0;
149
+ }
150
+ },
151
+ {
152
+ key: "resetProgress",
153
+ value: function resetProgress(now) {
154
+ this.lastPosition = this.host.video.currentTime;
155
+ this.lastProgressAt = now;
156
+ }
157
+ },
158
+ {
159
+ key: "tick",
160
+ value: function tick() {
161
+ var now = Date.now();
162
+ var video = this.host.video;
163
+ var hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
164
+ if (!this.armed || this.userPaused || hidden || video.ended || !this.host.isLiveStream() || !this.host.hasHlsInstance()) {
165
+ this.resetProgress(now);
166
+ return;
167
+ }
168
+ var breakActive = this.host.isBreakActive() || this.host.isAdPlaying();
169
+ if (breakActive && !this.wasInBreak) {
170
+ this.wasInBreak = true;
171
+ this.breakStartedAt = now;
172
+ this.stuckBreakLogged = false;
173
+ }
174
+ if (breakActive && now - this.breakStartedAt < MAX_BREAK_SUPPRESSION_MS) {
175
+ this.resetProgress(now);
176
+ return;
177
+ }
178
+ if (breakActive && !this.stuckBreakLogged) {
179
+ this.stuckBreakLogged = true;
180
+ console.warn("[ContentWatchdog] Ad break state active for over ".concat(MAX_BREAK_SUPPRESSION_MS / 6e4, " min — monitoring content anyway"));
181
+ }
182
+ if (!breakActive && this.wasInBreak) {
183
+ this.wasInBreak = false;
184
+ this.graceUntil = now + POST_BREAK_GRACE_MS;
185
+ this.resetProgress(now);
186
+ return;
187
+ }
188
+ var currentTime = video.currentTime;
189
+ var delta = currentTime - this.lastPosition;
190
+ this.lastPosition = currentTime;
191
+ if (delta > 0.25 && delta <= MAX_NORMAL_ADVANCE_PER_TICK_S && !video.paused) {
192
+ this.lastProgressAt = now;
193
+ this.lastRealPlaybackAt = now;
194
+ this.healthySeconds += delta;
195
+ if (this.step > 0 && this.healthySeconds >= HEALTHY_PLAYBACK_SECONDS) {
196
+ console.log("[ContentWatchdog] Content playback recovered after ".concat(this.step, " recovery step(s)"));
197
+ this.step = 0;
198
+ this.nextActionAt = 0;
199
+ }
200
+ return;
201
+ }
202
+ if (now < this.graceUntil) {
203
+ this.lastProgressAt = now;
204
+ return;
205
+ }
206
+ if (now - this.lastProgressAt < STALL_THRESHOLD_MS || now < this.nextActionAt) {
207
+ return;
208
+ }
209
+ this.recover(now);
210
+ }
211
+ },
212
+ {
213
+ key: "recover",
214
+ value: function recover(now) {
215
+ var video = this.host.video;
216
+ var state = "t=".concat(video.currentTime.toFixed(2), " paused=").concat(video.paused, " readyState=").concat(video.readyState, " networkState=").concat(video.networkState, " error=").concat(video.error ? video.error.code : "none");
217
+ var stalledForS = ((now - (this.lastRealPlaybackAt || this.lastProgressAt)) / 1e3).toFixed(0);
218
+ var fullReloadOnly = this.host.requiresMediaPipelineResetAfterAds();
219
+ var action = fullReloadOnly || this.step >= 2 ? "reload" : this.step === 0 ? "recover_media_error" : "restart_load";
220
+ console.warn("[ContentWatchdog] Content stalled for ".concat(stalledForS, "s — ").concat(action, " (step ").concat(this.step + 1, ") — ").concat(state));
221
+ this.lastActionAt = now;
222
+ this.healthySeconds = 0;
223
+ if (action === "recover_media_error") {
224
+ this.host.recoverMediaError();
225
+ this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;
226
+ } else if (action === "restart_load") {
227
+ var liveSyncPos = this.host.getLiveSyncPosition();
228
+ var position = liveSyncPos != null && liveSyncPos > video.currentTime ? liveSyncPos : video.currentTime;
229
+ if (position !== video.currentTime) {
230
+ video.currentTime = position;
231
+ }
232
+ this.host.restartHlsLoad(position);
233
+ this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;
234
+ } else {
235
+ var reloadIndex = fullReloadOnly ? this.step : this.step - 2;
236
+ var cooldown = Math.min(RELOAD_BASE_COOLDOWN_MS * Math.pow(2, reloadIndex), RELOAD_MAX_COOLDOWN_MS);
237
+ this.host.reloadLiveStream();
238
+ this.nextActionAt = now + cooldown;
239
+ }
240
+ this.step++;
241
+ this.resetProgress(now);
242
+ if (video.paused) {
243
+ var _video_play;
244
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
245
+ }
246
+ }
247
+ }
248
+ ]);
249
+ return ContentHealthWatchdog;
250
+ }();
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ ContentHealthWatchdog: ContentHealthWatchdog
254
+ });
255
+ //# sourceMappingURL=ContentHealthWatchdog.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["d:\\project\\stormcloud-vp\\lib\\player\\ContentHealthWatchdog.cjs"],"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","ContentHealthWatchdog_exports","ContentHealthWatchdog","module","exports","POLL_INTERVAL_MS","STALL_THRESHOLD_MS","POST_BREAK_GRACE_MS","MAX_BREAK_SUPPRESSION_MS","SELF_INFLICTED_PAUSE_WINDOW_MS","HEALTHY_PLAYBACK_SECONDS","MAX_NORMAL_ADVANCE_PER_TICK_S","LIGHT_STEP_COOLDOWN_MS","RELOAD_BASE_COOLDOWN_MS","RELOAD_MAX_COOLDOWN_MS","host","armed","userPaused","wasInBreak","breakStartedAt","stuckBreakLogged","graceUntil","lastPosition","lastProgressAt","lastRealPlaybackAt","healthySeconds","step","nextActionAt","lastActionAt","onPlaying","isAdPlaying","onPause","isBreakActive","Date","now","onPlay","start","intervalId","video","addEventListener","resetProgress","window","setInterval","tick","stop","clearInterval","removeEventListener","currentTime","hidden","document","visibilityState","ended","isLiveStream","hasHlsInstance","breakActive","console","warn","delta","paused","log","recover","state","toFixed","readyState","networkState","error","code","stalledForS","fullReloadOnly","requiresMediaPipelineResetAfterAds","action","recoverMediaError","liveSyncPos","getLiveSyncPosition","position","restartHlsLoad","reloadIndex","cooldown","Math","min","pow","reloadLiveStream","play","catch"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,YAAYC,OAAOC,cAAc;AACrC,IAAIC,mBAAmBF,OAAOG,wBAAwB;AACtD,IAAIC,oBAAoBJ,OAAOK,mBAAmB;AAClD,IAAIC,eAAeN,OAAOO,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,kBAACC,QAAQC;IACtB,IAAK,IAAIC,QAAQD,IACfZ,UAAUW,QAAQE,MAAM;QAAEC,KAAKF,GAAG,CAACC,KAAK;QAAEE,YAAY;IAAK;AAC/D;AACA,IAAIC,cAAc,qBAACC,IAAIC,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R,iBAAiB,IAAI,CAAC1C,IAAI,GAAG,IAAI,CAACA,IAAI,GAAG;oBAC7D,IAAMmD,WAAWC,KAAKC,GAAG,CACvBlE,0BAA0BiE,KAAKE,GAAG,CAAC,GAAGJ,cACtC9D;oBAEF,IAAI,CAACC,IAAI,CAACkE,gBAAgB;oBAC1B,IAAI,CAACtD,YAAY,GAAGO,MAAM2C;gBAC5B;gBACA,IAAI,CAACnD,IAAI;gBACT,IAAI,CAACc,aAAa,CAACN;gBACnB,IAAII,MAAMoB,MAAM,EAAE;wBAChBpB;qBAAAA,cAAAA,MAAM4C,IAAI,gBAAV5C,kCAAAA,YAAc6C,KAAK,CAAC,YACpB;gBACF;YACF;;;;;AAEF,6DAA6D;AAC7D,KAAMhF,CAAAA,OAAOC,OAAO,GAAG;IACrBF,uBAAAA;AACF,CAAA","sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/player/ContentHealthWatchdog.ts\nvar ContentHealthWatchdog_exports = {};\n__export(ContentHealthWatchdog_exports, {\n ContentHealthWatchdog: () => ContentHealthWatchdog\n});\nmodule.exports = __toCommonJS(ContentHealthWatchdog_exports);\nvar POLL_INTERVAL_MS = 2e3;\nvar STALL_THRESHOLD_MS = 12e3;\nvar POST_BREAK_GRACE_MS = 5e4;\nvar MAX_BREAK_SUPPRESSION_MS = 10 * 60 * 1e3;\nvar SELF_INFLICTED_PAUSE_WINDOW_MS = 5e3;\nvar HEALTHY_PLAYBACK_SECONDS = 5;\nvar MAX_NORMAL_ADVANCE_PER_TICK_S = 4;\nvar LIGHT_STEP_COOLDOWN_MS = 1e4;\nvar RELOAD_BASE_COOLDOWN_MS = 15e3;\nvar RELOAD_MAX_COOLDOWN_MS = 12e4;\nvar ContentHealthWatchdog = class {\n constructor(host) {\n this.host = host;\n this.armed = false;\n this.userPaused = false;\n this.wasInBreak = false;\n this.breakStartedAt = 0;\n this.stuckBreakLogged = false;\n this.graceUntil = 0;\n this.lastPosition = 0;\n this.lastProgressAt = 0;\n this.lastRealPlaybackAt = 0;\n this.healthySeconds = 0;\n this.step = 0;\n this.nextActionAt = 0;\n this.lastActionAt = 0;\n this.onPlaying = () => {\n if (this.host.isAdPlaying()) return;\n this.armed = true;\n this.userPaused = false;\n };\n this.onPause = () => {\n if (this.host.isBreakActive() || this.host.isAdPlaying() || Date.now() - this.lastActionAt < SELF_INFLICTED_PAUSE_WINDOW_MS) {\n return;\n }\n this.userPaused = true;\n };\n this.onPlay = () => {\n this.userPaused = false;\n };\n }\n start() {\n if (this.intervalId !== void 0) return;\n const video = this.host.video;\n video.addEventListener(\"playing\", this.onPlaying);\n video.addEventListener(\"pause\", this.onPause);\n video.addEventListener(\"play\", this.onPlay);\n this.resetProgress(Date.now());\n this.intervalId = window.setInterval(() => this.tick(), POLL_INTERVAL_MS);\n }\n stop() {\n if (this.intervalId !== void 0) {\n clearInterval(this.intervalId);\n this.intervalId = void 0;\n }\n const video = this.host.video;\n video.removeEventListener(\"playing\", this.onPlaying);\n video.removeEventListener(\"pause\", this.onPause);\n video.removeEventListener(\"play\", this.onPlay);\n this.armed = false;\n this.step = 0;\n }\n resetProgress(now) {\n this.lastPosition = this.host.video.currentTime;\n this.lastProgressAt = now;\n }\n tick() {\n const now = Date.now();\n const video = this.host.video;\n const hidden = typeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n if (!this.armed || this.userPaused || hidden || video.ended || !this.host.isLiveStream() || !this.host.hasHlsInstance()) {\n this.resetProgress(now);\n return;\n }\n const breakActive = this.host.isBreakActive() || this.host.isAdPlaying();\n if (breakActive && !this.wasInBreak) {\n this.wasInBreak = true;\n this.breakStartedAt = now;\n this.stuckBreakLogged = false;\n }\n if (breakActive && now - this.breakStartedAt < MAX_BREAK_SUPPRESSION_MS) {\n this.resetProgress(now);\n return;\n }\n if (breakActive && !this.stuckBreakLogged) {\n this.stuckBreakLogged = true;\n console.warn(\n `[ContentWatchdog] Ad break state active for over ${MAX_BREAK_SUPPRESSION_MS / 6e4} min \\u2014 monitoring content anyway`\n );\n }\n if (!breakActive && this.wasInBreak) {\n this.wasInBreak = false;\n this.graceUntil = now + POST_BREAK_GRACE_MS;\n this.resetProgress(now);\n return;\n }\n const currentTime = video.currentTime;\n const delta = currentTime - this.lastPosition;\n this.lastPosition = currentTime;\n if (delta > 0.25 && delta <= MAX_NORMAL_ADVANCE_PER_TICK_S && !video.paused) {\n this.lastProgressAt = now;\n this.lastRealPlaybackAt = now;\n this.healthySeconds += delta;\n if (this.step > 0 && this.healthySeconds >= HEALTHY_PLAYBACK_SECONDS) {\n console.log(\n `[ContentWatchdog] Content playback recovered after ${this.step} recovery step(s)`\n );\n this.step = 0;\n this.nextActionAt = 0;\n }\n return;\n }\n if (now < this.graceUntil) {\n this.lastProgressAt = now;\n return;\n }\n if (now - this.lastProgressAt < STALL_THRESHOLD_MS || now < this.nextActionAt) {\n return;\n }\n this.recover(now);\n }\n recover(now) {\n const video = this.host.video;\n const state = `t=${video.currentTime.toFixed(2)} paused=${video.paused} readyState=${video.readyState} networkState=${video.networkState} error=${video.error ? video.error.code : \"none\"}`;\n const stalledForS = ((now - (this.lastRealPlaybackAt || this.lastProgressAt)) / 1e3).toFixed(0);\n const fullReloadOnly = this.host.requiresMediaPipelineResetAfterAds();\n const action = fullReloadOnly || this.step >= 2 ? \"reload\" : this.step === 0 ? \"recover_media_error\" : \"restart_load\";\n console.warn(\n `[ContentWatchdog] Content stalled for ${stalledForS}s \\u2014 ${action} (step ${this.step + 1}) \\u2014 ${state}`\n );\n this.lastActionAt = now;\n this.healthySeconds = 0;\n if (action === \"recover_media_error\") {\n this.host.recoverMediaError();\n this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;\n } else if (action === \"restart_load\") {\n const liveSyncPos = this.host.getLiveSyncPosition();\n const position = liveSyncPos != null && liveSyncPos > video.currentTime ? liveSyncPos : video.currentTime;\n if (position !== video.currentTime) {\n video.currentTime = position;\n }\n this.host.restartHlsLoad(position);\n this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;\n } else {\n const reloadIndex = fullReloadOnly ? this.step : this.step - 2;\n const cooldown = Math.min(\n RELOAD_BASE_COOLDOWN_MS * Math.pow(2, reloadIndex),\n RELOAD_MAX_COOLDOWN_MS\n );\n this.host.reloadLiveStream();\n this.nextActionAt = now + cooldown;\n }\n this.step++;\n this.resetProgress(now);\n if (video.paused) {\n video.play()?.catch(() => {\n });\n }\n }\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n ContentHealthWatchdog\n});\n"]}
@@ -0,0 +1,40 @@
1
+ interface ContentHealthWatchdogHost {
2
+ video: HTMLVideoElement;
3
+ isLiveStream(): boolean;
4
+ hasHlsInstance(): boolean;
5
+ isBreakActive(): boolean;
6
+ isAdPlaying(): boolean;
7
+ requiresMediaPipelineResetAfterAds(): boolean;
8
+ getLiveSyncPosition(): number | undefined;
9
+ recoverMediaError(): void;
10
+ restartHlsLoad(position: number): void;
11
+ reloadLiveStream(): void;
12
+ }
13
+ declare class ContentHealthWatchdog {
14
+ private readonly host;
15
+ private intervalId;
16
+ private armed;
17
+ private userPaused;
18
+ private wasInBreak;
19
+ private breakStartedAt;
20
+ private stuckBreakLogged;
21
+ private graceUntil;
22
+ private lastPosition;
23
+ private lastProgressAt;
24
+ private lastRealPlaybackAt;
25
+ private healthySeconds;
26
+ private step;
27
+ private nextActionAt;
28
+ private lastActionAt;
29
+ private readonly onPlaying;
30
+ private readonly onPause;
31
+ private readonly onPlay;
32
+ constructor(host: ContentHealthWatchdogHost);
33
+ start(): void;
34
+ stop(): void;
35
+ private resetProgress;
36
+ private tick;
37
+ private recover;
38
+ }
39
+
40
+ export { ContentHealthWatchdog, type ContentHealthWatchdogHost };
@@ -2252,6 +2252,9 @@ function requiresMediaPipelineResetAfterAds() {
2252
2252
  var browser = detectBrowser();
2253
2253
  return browser.name === "Samsung Tizen" && ((_browser_tizenVersion = browser.tizenVersion) !== null && _browser_tizenVersion !== void 0 ? _browser_tizenVersion : 0) >= 5;
2254
2254
  }
2255
+ function prefersProgressiveAdMedia() {
2256
+ return detectBrowser().isSmartTV;
2257
+ }
2255
2258
  function getBrowserConfigOverrides() {
2256
2259
  var browser = detectBrowser();
2257
2260
  var overrides = {};
@@ -3095,6 +3098,7 @@ function createHlsAdPlayer(contentVideo, options) {
3095
3098
  var probe = adVideoElement !== null && adVideoElement !== void 0 ? adVideoElement : document.createElement("video");
3096
3099
  var pageIsHttps = typeof location !== "undefined" && location.protocol === "https:";
3097
3100
  var target = getMediaTargetQuality();
3101
+ var deprioritizeHls = prefersProgressiveAdMedia();
3098
3102
  var accepted = [];
3099
3103
  mediaFiles.forEach(function(file, index) {
3100
3104
  var isHls = isHlsMediaFile(file);
@@ -3125,19 +3129,24 @@ function createHlsAdPlayer(contentVideo, options) {
3125
3129
  var bitrateDiff = Math.abs((file.bitrate || 5e3) * 1e3 - target.bitrate);
3126
3130
  score = resolutionDiff * 2 + bitrateDiff / 1e3;
3127
3131
  }
3132
+ var deprioritizedHls = deprioritizeHls && isHls;
3128
3133
  accepted.push({
3129
3134
  file: file,
3130
3135
  score: score,
3131
- insecure: insecure
3136
+ insecure: insecure,
3137
+ deprioritizedHls: deprioritizedHls
3132
3138
  });
3133
3139
  logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
3134
3140
  reason: "accepted",
3135
- why: insecure ? "insecure_http_deprioritized" : "playable",
3141
+ why: insecure ? "insecure_http_deprioritized" : deprioritizedHls ? "hls_deprioritized_on_tv" : "playable",
3136
3142
  score: score
3137
3143
  }));
3138
3144
  });
3139
3145
  accepted.sort(function(a, b) {
3140
3146
  if (a.insecure !== b.insecure) return a.insecure ? 1 : -1;
3147
+ if (a.deprioritizedHls !== b.deprioritizedHls) {
3148
+ return a.deprioritizedHls ? 1 : -1;
3149
+ }
3141
3150
  return a.score - b.score;
3142
3151
  });
3143
3152
  return accepted.map(function(entry) {
@@ -4810,8 +4819,8 @@ function createHlsAdPlayer(contentVideo, options) {
4810
4819
  console.warn("[HlsAdPlayer] Error preparing ad video for new source:", error);
4811
4820
  }
4812
4821
  }
4813
- function recreateAdVideoElement() {
4814
- console.log("[HlsAdPlayer] Recreating ad video element (single-decoder platform)");
4822
+ function recreateAdVideoElement(reason) {
4823
+ console.log("[HlsAdPlayer] Recreating ad video element (".concat(reason, ")"));
4815
4824
  teardownAdEventListeners();
4816
4825
  prepareVideoElementForNewSource();
4817
4826
  if (adVideoElement) {
@@ -4855,8 +4864,9 @@ function createHlsAdPlayer(contentVideo, options) {
4855
4864
  }
4856
4865
  function resetVideoElementForNextSource() {
4857
4866
  clearStallWatchdog();
4858
- if (requiresMediaPipelineResetAfterAds()) {
4859
- recreateAdVideoElement();
4867
+ var previousSourceUsedHlsJs = adHls !== void 0;
4868
+ if (requiresMediaPipelineResetAfterAds() || previousSourceUsedHlsJs) {
4869
+ recreateAdVideoElement(previousSourceUsedHlsJs ? "after hls.js source" : "single-decoder platform");
4860
4870
  setupAdEventListeners();
4861
4871
  } else {
4862
4872
  prepareVideoElementForNewSource();
@@ -6072,14 +6082,16 @@ function ingestPlayerTracking(licenseKey, channel, body) {
6072
6082
  // src/utils/tracking.ts
6073
6083
  var cachedBrowserId = null;
6074
6084
  function buildAnalyticsContext(config) {
6075
- var _config_contentNetwork, _config_channelName, _config_programTitle;
6085
+ var _config_contentNetwork, _config_channelName, _config_programTitle, _config_src;
6076
6086
  var context = {};
6077
6087
  var contentNetwork = (_config_contentNetwork = config.contentNetwork) === null || _config_contentNetwork === void 0 ? void 0 : _config_contentNetwork.trim();
6078
6088
  var contentChannel = (_config_channelName = config.channelName) === null || _config_channelName === void 0 ? void 0 : _config_channelName.trim();
6079
6089
  var contentTitle = (_config_programTitle = config.programTitle) === null || _config_programTitle === void 0 ? void 0 : _config_programTitle.trim();
6090
+ var hlsUrl = (_config_src = config.src) === null || _config_src === void 0 ? void 0 : _config_src.trim();
6080
6091
  if (contentNetwork) context.contentNetwork = contentNetwork;
6081
6092
  if (contentChannel) context.contentChannel = contentChannel;
6082
6093
  if (contentTitle) context.contentTitle = contentTitle;
6094
+ if (hlsUrl) context.hlsUrl = hlsUrl;
6083
6095
  if (config.debugAdTiming) {
6084
6096
  context.debugAdTiming = true;
6085
6097
  }
@@ -6585,6 +6597,8 @@ function sendAdImpressionTracking(_0, _1) {
6585
6597
  content_channel: context.contentChannel
6586
6598
  } : {}, context.contentTitle ? {
6587
6599
  content_title: context.contentTitle
6600
+ } : {}, context.hlsUrl ? {
6601
+ hls_url: context.hlsUrl
6588
6602
  } : {})
6589
6603
  ]
6590
6604
  })
@@ -12338,6 +12352,181 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
12338
12352
  ]);
12339
12353
  return AdBreakOrchestrator;
12340
12354
  }();
12355
+ // src/player/ContentHealthWatchdog.ts
12356
+ var POLL_INTERVAL_MS = 2e3;
12357
+ var STALL_THRESHOLD_MS = 12e3;
12358
+ var POST_BREAK_GRACE_MS = 5e4;
12359
+ var MAX_BREAK_SUPPRESSION_MS = 10 * 60 * 1e3;
12360
+ var SELF_INFLICTED_PAUSE_WINDOW_MS = 5e3;
12361
+ var HEALTHY_PLAYBACK_SECONDS = 5;
12362
+ var MAX_NORMAL_ADVANCE_PER_TICK_S = 4;
12363
+ var LIGHT_STEP_COOLDOWN_MS = 1e4;
12364
+ var RELOAD_BASE_COOLDOWN_MS = 15e3;
12365
+ var RELOAD_MAX_COOLDOWN_MS = 12e4;
12366
+ var ContentHealthWatchdog = /*#__PURE__*/ function() {
12367
+ function ContentHealthWatchdog(host) {
12368
+ var _this = this;
12369
+ _class_call_check(this, ContentHealthWatchdog);
12370
+ this.host = host;
12371
+ this.armed = false;
12372
+ this.userPaused = false;
12373
+ this.wasInBreak = false;
12374
+ this.breakStartedAt = 0;
12375
+ this.stuckBreakLogged = false;
12376
+ this.graceUntil = 0;
12377
+ this.lastPosition = 0;
12378
+ this.lastProgressAt = 0;
12379
+ this.lastRealPlaybackAt = 0;
12380
+ this.healthySeconds = 0;
12381
+ this.step = 0;
12382
+ this.nextActionAt = 0;
12383
+ this.lastActionAt = 0;
12384
+ this.onPlaying = function() {
12385
+ if (_this.host.isAdPlaying()) return;
12386
+ _this.armed = true;
12387
+ _this.userPaused = false;
12388
+ };
12389
+ this.onPause = function() {
12390
+ if (_this.host.isBreakActive() || _this.host.isAdPlaying() || Date.now() - _this.lastActionAt < SELF_INFLICTED_PAUSE_WINDOW_MS) {
12391
+ return;
12392
+ }
12393
+ _this.userPaused = true;
12394
+ };
12395
+ this.onPlay = function() {
12396
+ _this.userPaused = false;
12397
+ };
12398
+ }
12399
+ _create_class(ContentHealthWatchdog, [
12400
+ {
12401
+ key: "start",
12402
+ value: function start() {
12403
+ var _this = this;
12404
+ if (this.intervalId !== void 0) return;
12405
+ var video = this.host.video;
12406
+ video.addEventListener("playing", this.onPlaying);
12407
+ video.addEventListener("pause", this.onPause);
12408
+ video.addEventListener("play", this.onPlay);
12409
+ this.resetProgress(Date.now());
12410
+ this.intervalId = window.setInterval(function() {
12411
+ return _this.tick();
12412
+ }, POLL_INTERVAL_MS);
12413
+ }
12414
+ },
12415
+ {
12416
+ key: "stop",
12417
+ value: function stop() {
12418
+ if (this.intervalId !== void 0) {
12419
+ clearInterval(this.intervalId);
12420
+ this.intervalId = void 0;
12421
+ }
12422
+ var video = this.host.video;
12423
+ video.removeEventListener("playing", this.onPlaying);
12424
+ video.removeEventListener("pause", this.onPause);
12425
+ video.removeEventListener("play", this.onPlay);
12426
+ this.armed = false;
12427
+ this.step = 0;
12428
+ }
12429
+ },
12430
+ {
12431
+ key: "resetProgress",
12432
+ value: function resetProgress(now) {
12433
+ this.lastPosition = this.host.video.currentTime;
12434
+ this.lastProgressAt = now;
12435
+ }
12436
+ },
12437
+ {
12438
+ key: "tick",
12439
+ value: function tick() {
12440
+ var now = Date.now();
12441
+ var video = this.host.video;
12442
+ var hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
12443
+ if (!this.armed || this.userPaused || hidden || video.ended || !this.host.isLiveStream() || !this.host.hasHlsInstance()) {
12444
+ this.resetProgress(now);
12445
+ return;
12446
+ }
12447
+ var breakActive = this.host.isBreakActive() || this.host.isAdPlaying();
12448
+ if (breakActive && !this.wasInBreak) {
12449
+ this.wasInBreak = true;
12450
+ this.breakStartedAt = now;
12451
+ this.stuckBreakLogged = false;
12452
+ }
12453
+ if (breakActive && now - this.breakStartedAt < MAX_BREAK_SUPPRESSION_MS) {
12454
+ this.resetProgress(now);
12455
+ return;
12456
+ }
12457
+ if (breakActive && !this.stuckBreakLogged) {
12458
+ this.stuckBreakLogged = true;
12459
+ console.warn("[ContentWatchdog] Ad break state active for over ".concat(MAX_BREAK_SUPPRESSION_MS / 6e4, " min — monitoring content anyway"));
12460
+ }
12461
+ if (!breakActive && this.wasInBreak) {
12462
+ this.wasInBreak = false;
12463
+ this.graceUntil = now + POST_BREAK_GRACE_MS;
12464
+ this.resetProgress(now);
12465
+ return;
12466
+ }
12467
+ var currentTime = video.currentTime;
12468
+ var delta = currentTime - this.lastPosition;
12469
+ this.lastPosition = currentTime;
12470
+ if (delta > 0.25 && delta <= MAX_NORMAL_ADVANCE_PER_TICK_S && !video.paused) {
12471
+ this.lastProgressAt = now;
12472
+ this.lastRealPlaybackAt = now;
12473
+ this.healthySeconds += delta;
12474
+ if (this.step > 0 && this.healthySeconds >= HEALTHY_PLAYBACK_SECONDS) {
12475
+ console.log("[ContentWatchdog] Content playback recovered after ".concat(this.step, " recovery step(s)"));
12476
+ this.step = 0;
12477
+ this.nextActionAt = 0;
12478
+ }
12479
+ return;
12480
+ }
12481
+ if (now < this.graceUntil) {
12482
+ this.lastProgressAt = now;
12483
+ return;
12484
+ }
12485
+ if (now - this.lastProgressAt < STALL_THRESHOLD_MS || now < this.nextActionAt) {
12486
+ return;
12487
+ }
12488
+ this.recover(now);
12489
+ }
12490
+ },
12491
+ {
12492
+ key: "recover",
12493
+ value: function recover(now) {
12494
+ var video = this.host.video;
12495
+ var state = "t=".concat(video.currentTime.toFixed(2), " paused=").concat(video.paused, " readyState=").concat(video.readyState, " networkState=").concat(video.networkState, " error=").concat(video.error ? video.error.code : "none");
12496
+ var stalledForS = ((now - (this.lastRealPlaybackAt || this.lastProgressAt)) / 1e3).toFixed(0);
12497
+ var fullReloadOnly = this.host.requiresMediaPipelineResetAfterAds();
12498
+ var action = fullReloadOnly || this.step >= 2 ? "reload" : this.step === 0 ? "recover_media_error" : "restart_load";
12499
+ console.warn("[ContentWatchdog] Content stalled for ".concat(stalledForS, "s — ").concat(action, " (step ").concat(this.step + 1, ") — ").concat(state));
12500
+ this.lastActionAt = now;
12501
+ this.healthySeconds = 0;
12502
+ if (action === "recover_media_error") {
12503
+ this.host.recoverMediaError();
12504
+ this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;
12505
+ } else if (action === "restart_load") {
12506
+ var liveSyncPos = this.host.getLiveSyncPosition();
12507
+ var position = liveSyncPos != null && liveSyncPos > video.currentTime ? liveSyncPos : video.currentTime;
12508
+ if (position !== video.currentTime) {
12509
+ video.currentTime = position;
12510
+ }
12511
+ this.host.restartHlsLoad(position);
12512
+ this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;
12513
+ } else {
12514
+ var reloadIndex = fullReloadOnly ? this.step : this.step - 2;
12515
+ var cooldown = Math.min(RELOAD_BASE_COOLDOWN_MS * Math.pow(2, reloadIndex), RELOAD_MAX_COOLDOWN_MS);
12516
+ this.host.reloadLiveStream();
12517
+ this.nextActionAt = now + cooldown;
12518
+ }
12519
+ this.step++;
12520
+ this.resetProgress(now);
12521
+ if (video.paused) {
12522
+ var _video_play;
12523
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
12524
+ }
12525
+ }
12526
+ }
12527
+ ]);
12528
+ return ContentHealthWatchdog;
12529
+ }();
12341
12530
  // src/player/StormcloudVideoPlayer.ts
12342
12531
  var StormcloudVideoPlayer = /*#__PURE__*/ function() {
12343
12532
  function StormcloudVideoPlayer(config) {
@@ -12468,6 +12657,36 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
12468
12657
  return _this.palNonce.sendAdTouch(event);
12469
12658
  }
12470
12659
  }, this.timing, this.adConfig, this.cueManager, this.placeholder);
12660
+ this.contentWatchdog = new ContentHealthWatchdog({
12661
+ video: this.video,
12662
+ isLiveStream: function isLiveStream() {
12663
+ return _this.hlsEngine.isLiveStream;
12664
+ },
12665
+ hasHlsInstance: function hasHlsInstance() {
12666
+ return !!_this.hlsEngine.hls;
12667
+ },
12668
+ isBreakActive: function isBreakActive() {
12669
+ return _this.adBreak.inAdBreak || _this.adBreak.isBreakActive();
12670
+ },
12671
+ isAdPlaying: function isAdPlaying() {
12672
+ return _this.adPlayer.isAdPlaying();
12673
+ },
12674
+ requiresMediaPipelineResetAfterAds: function requiresMediaPipelineResetAfterAds1() {
12675
+ return requiresMediaPipelineResetAfterAds();
12676
+ },
12677
+ getLiveSyncPosition: function getLiveSyncPosition() {
12678
+ return _this.hlsEngine.getLiveSyncPosition();
12679
+ },
12680
+ recoverMediaError: function recoverMediaError() {
12681
+ return _this.hlsEngine.recoverMediaError();
12682
+ },
12683
+ restartHlsLoad: function restartHlsLoad(position) {
12684
+ return _this.hlsEngine.restartLoadAt(position);
12685
+ },
12686
+ reloadLiveStream: function reloadLiveStream() {
12687
+ return _this.hlsEngine.reloadLiveStream();
12688
+ }
12689
+ });
12471
12690
  }
12472
12691
  _create_class(StormcloudVideoPlayer, [
12473
12692
  {
@@ -12788,6 +13007,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
12788
13007
  }
12789
13008
  };
12790
13009
  this.video.addEventListener("emptied", this.emptiedHandler);
13010
+ if (this.config.contentStallWatchdog !== false) {
13011
+ this.contentWatchdog.start();
13012
+ }
12791
13013
  }
12792
13014
  },
12793
13015
  {
@@ -13272,6 +13494,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
13272
13494
  key: "destroy",
13273
13495
  value: function destroy() {
13274
13496
  var _this_adPlayer;
13497
+ this.contentWatchdog.stop();
13275
13498
  this.adBreak.cancelScheduledRequest();
13276
13499
  this.timing.destroy();
13277
13500
  this.adBreak.clearPendingAdBreak();