stormcloud-video-player 0.3.14 → 0.3.17

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 (36) hide show
  1. package/dist/stormcloud-vp.min.js +1 -10
  2. package/lib/index.cjs +8282 -6531
  3. package/lib/index.cjs.map +1 -1
  4. package/lib/index.d.cts +2 -0
  5. package/lib/index.d.ts +2 -0
  6. package/lib/index.js +8112 -6495
  7. package/lib/index.js.map +1 -1
  8. package/lib/player/StormcloudVideoPlayer.cjs +5575 -3981
  9. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  10. package/lib/player/StormcloudVideoPlayer.d.cts +1 -1
  11. package/lib/players/FilePlayer.cjs +556 -225
  12. package/lib/players/FilePlayer.cjs.map +1 -1
  13. package/lib/players/HlsPlayer.cjs +5845 -4163
  14. package/lib/players/HlsPlayer.cjs.map +1 -1
  15. package/lib/players/HlsPlayer.d.cts +1 -1
  16. package/lib/players/index.cjs +6142 -4371
  17. package/lib/players/index.cjs.map +1 -1
  18. package/lib/sdk/hlsAdPlayer.cjs +954 -699
  19. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  20. package/lib/sdk/hlsAdPlayer.d.cts +1 -1
  21. package/lib/sdk/ima.cjs +1034 -809
  22. package/lib/sdk/ima.cjs.map +1 -1
  23. package/lib/sdk/ima.d.cts +1 -1
  24. package/lib/{types-t9jEJXZy.d.cts → types-CryTJVCC.d.cts} +1 -0
  25. package/lib/ui/StormcloudVideoPlayer.cjs +6992 -5561
  26. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  27. package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
  28. package/lib/utils/browserCompat.cjs +241 -194
  29. package/lib/utils/browserCompat.cjs.map +1 -1
  30. package/lib/utils/polyfills.cjs +379 -214
  31. package/lib/utils/polyfills.cjs.map +1 -1
  32. package/lib/utils/tracking.cjs +559 -257
  33. package/lib/utils/tracking.cjs.map +1 -1
  34. package/lib/utils/tracking.d.cts +1 -1
  35. package/package.json +6 -1
  36. package/rollup.config.js +22 -0
@@ -1,30 +1,277 @@
1
1
  "use strict";
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_without_holes(arr) {
8
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
9
+ }
10
+ function _assert_this_initialized(self) {
11
+ if (self === void 0) {
12
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13
+ }
14
+ return self;
15
+ }
16
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
+ try {
18
+ var info = gen[key](arg);
19
+ var value = info.value;
20
+ } catch (error) {
21
+ reject(error);
22
+ return;
23
+ }
24
+ if (info.done) {
25
+ resolve(value);
26
+ } else {
27
+ Promise.resolve(value).then(_next, _throw);
28
+ }
29
+ }
30
+ function _async_to_generator(fn) {
31
+ return function() {
32
+ var self = this, args = arguments;
33
+ return new Promise(function(resolve, reject) {
34
+ var gen = fn.apply(self, args);
35
+ function _next(value) {
36
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
37
+ }
38
+ function _throw(err) {
39
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
40
+ }
41
+ _next(undefined);
42
+ });
43
+ };
44
+ }
45
+ function _call_super(_this, derived, args) {
46
+ derived = _get_prototype_of(derived);
47
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
48
+ }
49
+ function _class_call_check(instance, Constructor) {
50
+ if (!(instance instanceof Constructor)) {
51
+ throw new TypeError("Cannot call a class as a function");
52
+ }
53
+ }
54
+ function _defineProperties(target, props) {
55
+ for(var i = 0; i < props.length; i++){
56
+ var descriptor = props[i];
57
+ descriptor.enumerable = descriptor.enumerable || false;
58
+ descriptor.configurable = true;
59
+ if ("value" in descriptor) descriptor.writable = true;
60
+ Object.defineProperty(target, descriptor.key, descriptor);
61
+ }
62
+ }
63
+ function _create_class(Constructor, protoProps, staticProps) {
64
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
65
+ if (staticProps) _defineProperties(Constructor, staticProps);
66
+ return Constructor;
67
+ }
68
+ function _get_prototype_of(o) {
69
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
70
+ return o.__proto__ || Object.getPrototypeOf(o);
71
+ };
72
+ return _get_prototype_of(o);
73
+ }
74
+ function _inherits(subClass, superClass) {
75
+ if (typeof superClass !== "function" && superClass !== null) {
76
+ throw new TypeError("Super expression must either be null or a function");
77
+ }
78
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
79
+ constructor: {
80
+ value: subClass,
81
+ writable: true,
82
+ configurable: true
83
+ }
84
+ });
85
+ if (superClass) _set_prototype_of(subClass, superClass);
86
+ }
87
+ function _iterable_to_array(iter) {
88
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
89
+ }
90
+ function _non_iterable_spread() {
91
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
92
+ }
93
+ function _possible_constructor_return(self, call) {
94
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
95
+ return call;
96
+ }
97
+ return _assert_this_initialized(self);
98
+ }
99
+ function _set_prototype_of(o, p) {
100
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
101
+ o.__proto__ = p;
102
+ return o;
103
+ };
104
+ return _set_prototype_of(o, p);
105
+ }
106
+ function _to_consumable_array(arr) {
107
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
108
+ }
109
+ function _type_of(obj) {
110
+ "@swc/helpers - typeof";
111
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
112
+ }
113
+ function _unsupported_iterable_to_array(o, minLen) {
114
+ if (!o) return;
115
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
116
+ var n = Object.prototype.toString.call(o).slice(8, -1);
117
+ if (n === "Object" && o.constructor) n = o.constructor.name;
118
+ if (n === "Map" || n === "Set") return Array.from(n);
119
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
120
+ }
121
+ function _is_native_reflect_construct() {
122
+ try {
123
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
124
+ } catch (_) {}
125
+ return (_is_native_reflect_construct = function() {
126
+ return !!result;
127
+ })();
128
+ }
129
+ function _ts_generator(thisArg, body) {
130
+ var f, y, t, _ = {
131
+ label: 0,
132
+ sent: function() {
133
+ if (t[0] & 1) throw t[1];
134
+ return t[1];
135
+ },
136
+ trys: [],
137
+ ops: []
138
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
139
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
140
+ return this;
141
+ }), g;
142
+ function verb(n) {
143
+ return function(v) {
144
+ return step([
145
+ n,
146
+ v
147
+ ]);
148
+ };
149
+ }
150
+ function step(op) {
151
+ if (f) throw new TypeError("Generator is already executing.");
152
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
153
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
154
+ if (y = 0, t) op = [
155
+ op[0] & 2,
156
+ t.value
157
+ ];
158
+ switch(op[0]){
159
+ case 0:
160
+ case 1:
161
+ t = op;
162
+ break;
163
+ case 4:
164
+ _.label++;
165
+ return {
166
+ value: op[1],
167
+ done: false
168
+ };
169
+ case 5:
170
+ _.label++;
171
+ y = op[1];
172
+ op = [
173
+ 0
174
+ ];
175
+ continue;
176
+ case 7:
177
+ op = _.ops.pop();
178
+ _.trys.pop();
179
+ continue;
180
+ default:
181
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
182
+ _ = 0;
183
+ continue;
184
+ }
185
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
186
+ _.label = op[1];
187
+ break;
188
+ }
189
+ if (op[0] === 6 && _.label < t[1]) {
190
+ _.label = t[1];
191
+ t = op;
192
+ break;
193
+ }
194
+ if (t && _.label < t[2]) {
195
+ _.label = t[2];
196
+ _.ops.push(op);
197
+ break;
198
+ }
199
+ if (t[2]) _.ops.pop();
200
+ _.trys.pop();
201
+ continue;
202
+ }
203
+ op = body.call(thisArg, _);
204
+ } catch (e) {
205
+ op = [
206
+ 6,
207
+ e
208
+ ];
209
+ y = 0;
210
+ } finally{
211
+ f = t = 0;
212
+ }
213
+ if (op[0] & 5) throw op[1];
214
+ return {
215
+ value: op[0] ? op[1] : void 0,
216
+ done: true
217
+ };
218
+ }
219
+ }
2
220
  var __defProp = Object.defineProperty;
3
221
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
222
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
223
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
224
+ var __export = function(target, all) {
225
+ for(var name in all)__defProp(target, name, {
226
+ get: all[name],
227
+ enumerable: true
228
+ });
229
+ };
230
+ var __copyProps = function(to, from, except, desc) {
231
+ if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
232
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
233
+ try {
234
+ var _loop = function() {
235
+ var key = _step.value;
236
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
237
+ get: function() {
238
+ return from[key];
239
+ },
240
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
241
+ });
242
+ };
243
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
244
+ } catch (err) {
245
+ _didIteratorError = true;
246
+ _iteratorError = err;
247
+ } finally{
248
+ try {
249
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
250
+ _iterator.return();
251
+ }
252
+ } finally{
253
+ if (_didIteratorError) {
254
+ throw _iteratorError;
255
+ }
256
+ }
257
+ }
258
+ }
259
+ return to;
9
260
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
261
+ var __toCommonJS = function(mod) {
262
+ return __copyProps(__defProp({}, "__esModule", {
263
+ value: true
264
+ }), mod);
17
265
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
266
  // src/players/FilePlayer.tsx
21
267
  var FilePlayer_exports = {};
22
268
  __export(FilePlayer_exports, {
23
- default: () => FilePlayer
269
+ default: function() {
270
+ return FilePlayer;
271
+ }
24
272
  });
25
273
  module.exports = __toCommonJS(FilePlayer_exports);
26
274
  var import_react = require("react");
27
-
28
275
  // src/patterns.ts
29
276
  var HLS_EXTENSIONS = /\.(m3u8)($|\?)/i;
30
277
  var HLS_PATHS = /\/hls\//i;
@@ -32,220 +279,304 @@ var DASH_EXTENSIONS = /\.(mpd)($|\?)/i;
32
279
  var VIDEO_EXTENSIONS = /\.(mp4|webm|ogg|avi|mov|wmv|flv|mkv)($|\?)/i;
33
280
  var AUDIO_EXTENSIONS = /\.(mp3|wav|ogg|aac|wma|flac|m4a)($|\?)/i;
34
281
  var canPlay = {
35
- hls: (url) => {
36
- if (!url || typeof url !== "string") return false;
37
- return HLS_EXTENSIONS.test(url) || HLS_PATHS.test(url);
38
- },
39
- dash: (url) => {
40
- if (!url || typeof url !== "string") return false;
41
- return DASH_EXTENSIONS.test(url);
42
- },
43
- video: (url) => {
44
- if (!url || typeof url !== "string") return false;
45
- return VIDEO_EXTENSIONS.test(url);
46
- },
47
- audio: (url) => {
48
- if (!url || typeof url !== "string") return false;
49
- return AUDIO_EXTENSIONS.test(url);
50
- },
51
- file: (url) => {
52
- if (!url || typeof url !== "string") return false;
53
- return VIDEO_EXTENSIONS.test(url) || AUDIO_EXTENSIONS.test(url);
54
- }
282
+ hls: function(url) {
283
+ if (!url || typeof url !== "string") return false;
284
+ return HLS_EXTENSIONS.test(url) || HLS_PATHS.test(url);
285
+ },
286
+ dash: function(url) {
287
+ if (!url || typeof url !== "string") return false;
288
+ return DASH_EXTENSIONS.test(url);
289
+ },
290
+ video: function(url) {
291
+ if (!url || typeof url !== "string") return false;
292
+ return VIDEO_EXTENSIONS.test(url);
293
+ },
294
+ audio: function(url) {
295
+ if (!url || typeof url !== "string") return false;
296
+ return AUDIO_EXTENSIONS.test(url);
297
+ },
298
+ file: function(url) {
299
+ if (!url || typeof url !== "string") return false;
300
+ return VIDEO_EXTENSIONS.test(url) || AUDIO_EXTENSIONS.test(url);
301
+ }
55
302
  };
56
-
57
303
  // src/players/FilePlayer.tsx
58
- var FilePlayer = class extends import_react.Component {
59
- constructor() {
60
- super(...arguments);
61
- this.mounted = false;
62
- this.ready = false;
63
- this.load = () => {
64
- var _a, _b;
65
- if (!this.props.videoElement || !this.props.src) return;
66
- const video = this.props.videoElement;
67
- const handleLoadedMetadata = () => {
68
- var _a2, _b2;
69
- if (this.mounted && !this.ready) {
70
- this.ready = true;
71
- (_b2 = (_a2 = this.props).onReady) == null ? void 0 : _b2.call(_a2);
72
- }
73
- };
74
- const handlePlay = () => {
75
- var _a2, _b2;
76
- if (this.mounted) {
77
- (_b2 = (_a2 = this.props).onPlay) == null ? void 0 : _b2.call(_a2);
78
- }
79
- };
80
- const handlePause = () => {
81
- var _a2, _b2;
82
- if (this.mounted) {
83
- (_b2 = (_a2 = this.props).onPause) == null ? void 0 : _b2.call(_a2);
84
- }
85
- };
86
- const handleEnded = () => {
87
- var _a2, _b2;
88
- if (this.mounted) {
89
- (_b2 = (_a2 = this.props).onEnded) == null ? void 0 : _b2.call(_a2);
90
- }
91
- };
92
- const handleError = (error) => {
93
- var _a2, _b2;
94
- if (this.mounted) {
95
- (_b2 = (_a2 = this.props).onError) == null ? void 0 : _b2.call(_a2, error);
96
- }
97
- };
98
- const handleLoadedData = () => {
99
- var _a2, _b2;
100
- if (this.mounted) {
101
- (_b2 = (_a2 = this.props).onLoaded) == null ? void 0 : _b2.call(_a2);
102
- }
103
- };
104
- video.addEventListener("loadedmetadata", handleLoadedMetadata);
105
- video.addEventListener("play", handlePlay);
106
- video.addEventListener("pause", handlePause);
107
- video.addEventListener("ended", handleEnded);
108
- video.addEventListener("error", handleError);
109
- video.addEventListener("loadeddata", handleLoadedData);
110
- video.src = this.props.src;
111
- if (this.props.autoplay !== void 0) video.autoplay = this.props.autoplay;
112
- if (this.props.muted !== void 0) video.muted = this.props.muted;
113
- if (this.props.loop !== void 0) video.loop = this.props.loop;
114
- if (this.props.controls !== void 0) video.controls = this.props.controls;
115
- if (this.props.playsInline !== void 0)
116
- video.playsInline = this.props.playsInline;
117
- if (this.props.preload !== void 0)
118
- video.preload = this.props.preload;
119
- if (this.props.poster !== void 0) video.poster = this.props.poster;
120
- (_b = (_a = this.props).onMount) == null ? void 0 : _b.call(_a, this);
121
- return () => {
122
- video.removeEventListener("loadedmetadata", handleLoadedMetadata);
123
- video.removeEventListener("play", handlePlay);
124
- video.removeEventListener("pause", handlePause);
125
- video.removeEventListener("ended", handleEnded);
126
- video.removeEventListener("error", handleError);
127
- video.removeEventListener("loadeddata", handleLoadedData);
128
- };
129
- };
130
- this.play = () => {
131
- var _a;
132
- if (this.props.videoElement) {
133
- const video = this.props.videoElement;
134
- const hasValidSource = video.src || video.currentSrc && video.currentSrc !== "" || video.readyState >= 1;
135
- if (hasValidSource) {
136
- (_a = video.play()) == null ? void 0 : _a.catch((error) => {
137
- var _a2, _b;
138
- console.error("[FilePlayer] Failed to play:", error);
139
- (_b = (_a2 = this.props).onError) == null ? void 0 : _b.call(_a2, error);
140
- });
141
- } else {
142
- console.warn("[FilePlayer] Cannot play: video has no valid source");
143
- }
144
- }
145
- };
146
- this.pause = () => {
147
- if (this.props.videoElement) {
148
- this.props.videoElement.pause();
149
- }
150
- };
151
- this.stop = () => {
152
- this.pause();
153
- if (this.props.videoElement) {
154
- this.props.videoElement.currentTime = 0;
155
- }
156
- };
157
- this.seekTo = (seconds, keepPlaying) => {
158
- if (this.props.videoElement) {
159
- this.props.videoElement.currentTime = seconds;
160
- if (!keepPlaying) {
161
- this.pause();
162
- }
163
- }
164
- };
165
- this.setVolume = (volume) => {
166
- if (this.props.videoElement) {
167
- this.props.videoElement.volume = Math.max(0, Math.min(1, volume));
168
- }
169
- };
170
- this.mute = () => {
171
- if (this.props.videoElement) {
172
- this.props.videoElement.muted = true;
173
- }
174
- };
175
- this.unmute = () => {
176
- if (this.props.videoElement) {
177
- this.props.videoElement.muted = false;
178
- }
179
- };
180
- this.setPlaybackRate = (rate) => {
181
- if (this.props.videoElement && rate > 0) {
182
- this.props.videoElement.playbackRate = rate;
183
- }
184
- };
185
- this.setLoop = (loop) => {
186
- if (this.props.videoElement) {
187
- this.props.videoElement.loop = loop;
188
- }
189
- };
190
- this.getDuration = () => {
191
- if (this.props.videoElement && isFinite(this.props.videoElement.duration)) {
192
- return this.props.videoElement.duration;
193
- }
194
- return null;
195
- };
196
- this.getCurrentTime = () => {
197
- if (this.props.videoElement && isFinite(this.props.videoElement.currentTime)) {
198
- return this.props.videoElement.currentTime;
199
- }
200
- return null;
201
- };
202
- this.getSecondsLoaded = () => {
203
- if (this.props.videoElement && this.props.videoElement.buffered.length > 0) {
204
- return this.props.videoElement.buffered.end(
205
- this.props.videoElement.buffered.length - 1
206
- );
207
- }
208
- return null;
209
- };
210
- this.getInternalPlayer = (key = "player") => {
211
- if (key === "video") return this.props.videoElement;
212
- return null;
213
- };
214
- this.enablePIP = async () => {
215
- if (this.props.videoElement && "requestPictureInPicture" in this.props.videoElement) {
216
- try {
217
- await this.props.videoElement.requestPictureInPicture();
218
- } catch (error) {
219
- console.warn("Picture-in-Picture failed:", error);
220
- }
221
- }
222
- };
223
- this.disablePIP = async () => {
224
- if (document.pictureInPictureElement) {
225
- try {
226
- await document.exitPictureInPicture();
227
- } catch (error) {
228
- console.warn("Exit Picture-in-Picture failed:", error);
229
- }
230
- }
231
- };
232
- }
233
- componentDidMount() {
234
- this.mounted = true;
235
- this.load();
236
- }
237
- componentWillUnmount() {
238
- this.mounted = false;
239
- }
240
- componentDidUpdate(prevProps) {
241
- if (prevProps.src !== this.props.src) {
242
- this.load();
304
+ var FilePlayer = /*#__PURE__*/ function(_import_react_Component) {
305
+ _inherits(FilePlayer, _import_react_Component);
306
+ function FilePlayer() {
307
+ _class_call_check(this, FilePlayer);
308
+ var _this;
309
+ var _this1, _arguments = arguments;
310
+ _this = _call_super(this, FilePlayer, _to_consumable_array(_arguments)), _this1 = _this;
311
+ _this1.mounted = false;
312
+ _this1.ready = false;
313
+ _this1.load = function() {
314
+ var _this_props_onMount, _this_props;
315
+ if (!_this1.props.videoElement || !_this1.props.src) return;
316
+ var video = _this1.props.videoElement;
317
+ var handleLoadedMetadata = function() {
318
+ if (_this1.mounted && !_this1.ready) {
319
+ var _this_props_onReady, _this_props;
320
+ _this1.ready = true;
321
+ (_this_props_onReady = (_this_props = _this1.props).onReady) === null || _this_props_onReady === void 0 ? void 0 : _this_props_onReady.call(_this_props);
322
+ }
323
+ };
324
+ var handlePlay = function() {
325
+ if (_this1.mounted) {
326
+ var _this_props_onPlay, _this_props;
327
+ (_this_props_onPlay = (_this_props = _this1.props).onPlay) === null || _this_props_onPlay === void 0 ? void 0 : _this_props_onPlay.call(_this_props);
328
+ }
329
+ };
330
+ var handlePause = function() {
331
+ if (_this1.mounted) {
332
+ var _this_props_onPause, _this_props;
333
+ (_this_props_onPause = (_this_props = _this1.props).onPause) === null || _this_props_onPause === void 0 ? void 0 : _this_props_onPause.call(_this_props);
334
+ }
335
+ };
336
+ var handleEnded = function() {
337
+ if (_this1.mounted) {
338
+ var _this_props_onEnded, _this_props;
339
+ (_this_props_onEnded = (_this_props = _this1.props).onEnded) === null || _this_props_onEnded === void 0 ? void 0 : _this_props_onEnded.call(_this_props);
340
+ }
341
+ };
342
+ var handleError = function(error) {
343
+ if (_this1.mounted) {
344
+ var _this_props_onError, _this_props;
345
+ (_this_props_onError = (_this_props = _this1.props).onError) === null || _this_props_onError === void 0 ? void 0 : _this_props_onError.call(_this_props, error);
346
+ }
347
+ };
348
+ var handleLoadedData = function() {
349
+ if (_this1.mounted) {
350
+ var _this_props_onLoaded, _this_props;
351
+ (_this_props_onLoaded = (_this_props = _this1.props).onLoaded) === null || _this_props_onLoaded === void 0 ? void 0 : _this_props_onLoaded.call(_this_props);
352
+ }
353
+ };
354
+ video.addEventListener("loadedmetadata", handleLoadedMetadata);
355
+ video.addEventListener("play", handlePlay);
356
+ video.addEventListener("pause", handlePause);
357
+ video.addEventListener("ended", handleEnded);
358
+ video.addEventListener("error", handleError);
359
+ video.addEventListener("loadeddata", handleLoadedData);
360
+ video.src = _this1.props.src;
361
+ if (_this1.props.autoplay !== void 0) video.autoplay = _this1.props.autoplay;
362
+ if (_this1.props.muted !== void 0) video.muted = _this1.props.muted;
363
+ if (_this1.props.loop !== void 0) video.loop = _this1.props.loop;
364
+ if (_this1.props.controls !== void 0) video.controls = _this1.props.controls;
365
+ if (_this1.props.playsInline !== void 0) video.playsInline = _this1.props.playsInline;
366
+ if (_this1.props.preload !== void 0) video.preload = _this1.props.preload;
367
+ if (_this1.props.poster !== void 0) video.poster = _this1.props.poster;
368
+ (_this_props_onMount = (_this_props = _this1.props).onMount) === null || _this_props_onMount === void 0 ? void 0 : _this_props_onMount.call(_this_props, _this1);
369
+ return function() {
370
+ video.removeEventListener("loadedmetadata", handleLoadedMetadata);
371
+ video.removeEventListener("play", handlePlay);
372
+ video.removeEventListener("pause", handlePause);
373
+ video.removeEventListener("ended", handleEnded);
374
+ video.removeEventListener("error", handleError);
375
+ video.removeEventListener("loadeddata", handleLoadedData);
376
+ };
377
+ };
378
+ _this1.play = function() {
379
+ if (_this1.props.videoElement) {
380
+ var video = _this1.props.videoElement;
381
+ var hasValidSource = video.src || video.currentSrc && video.currentSrc !== "" || video.readyState >= 1;
382
+ if (hasValidSource) {
383
+ var _video_play;
384
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function(error) {
385
+ var _this_props_onError, _this_props;
386
+ console.error("[FilePlayer] Failed to play:", error);
387
+ (_this_props_onError = (_this_props = _this1.props).onError) === null || _this_props_onError === void 0 ? void 0 : _this_props_onError.call(_this_props, error);
388
+ });
389
+ } else {
390
+ console.warn("[FilePlayer] Cannot play: video has no valid source");
391
+ }
392
+ }
393
+ };
394
+ _this1.pause = function() {
395
+ if (_this1.props.videoElement) {
396
+ _this1.props.videoElement.pause();
397
+ }
398
+ };
399
+ _this1.stop = function() {
400
+ _this1.pause();
401
+ if (_this1.props.videoElement) {
402
+ _this1.props.videoElement.currentTime = 0;
403
+ }
404
+ };
405
+ _this1.seekTo = function(seconds, keepPlaying) {
406
+ if (_this1.props.videoElement) {
407
+ _this1.props.videoElement.currentTime = seconds;
408
+ if (!keepPlaying) {
409
+ _this1.pause();
410
+ }
411
+ }
412
+ };
413
+ _this1.setVolume = function(volume) {
414
+ if (_this1.props.videoElement) {
415
+ _this1.props.videoElement.volume = Math.max(0, Math.min(1, volume));
416
+ }
417
+ };
418
+ _this1.mute = function() {
419
+ if (_this1.props.videoElement) {
420
+ _this1.props.videoElement.muted = true;
421
+ }
422
+ };
423
+ _this1.unmute = function() {
424
+ if (_this1.props.videoElement) {
425
+ _this1.props.videoElement.muted = false;
426
+ }
427
+ };
428
+ _this1.setPlaybackRate = function(rate) {
429
+ if (_this1.props.videoElement && rate > 0) {
430
+ _this1.props.videoElement.playbackRate = rate;
431
+ }
432
+ };
433
+ _this1.setLoop = function(loop) {
434
+ if (_this1.props.videoElement) {
435
+ _this1.props.videoElement.loop = loop;
436
+ }
437
+ };
438
+ _this1.getDuration = function() {
439
+ if (_this1.props.videoElement && isFinite(_this1.props.videoElement.duration)) {
440
+ return _this1.props.videoElement.duration;
441
+ }
442
+ return null;
443
+ };
444
+ _this1.getCurrentTime = function() {
445
+ if (_this1.props.videoElement && isFinite(_this1.props.videoElement.currentTime)) {
446
+ return _this1.props.videoElement.currentTime;
447
+ }
448
+ return null;
449
+ };
450
+ _this1.getSecondsLoaded = function() {
451
+ if (_this1.props.videoElement && _this1.props.videoElement.buffered.length > 0) {
452
+ return _this1.props.videoElement.buffered.end(_this1.props.videoElement.buffered.length - 1);
453
+ }
454
+ return null;
455
+ };
456
+ _this1.getInternalPlayer = function() {
457
+ var key = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "player";
458
+ if (key === "video") return _this1.props.videoElement;
459
+ return null;
460
+ };
461
+ _this1.enablePIP = function() {
462
+ return _async_to_generator(function() {
463
+ var error;
464
+ return _ts_generator(this, function(_state) {
465
+ switch(_state.label){
466
+ case 0:
467
+ if (!(_this1.props.videoElement && "requestPictureInPicture" in _this1.props.videoElement)) return [
468
+ 3,
469
+ 4
470
+ ];
471
+ _state.label = 1;
472
+ case 1:
473
+ _state.trys.push([
474
+ 1,
475
+ 3,
476
+ ,
477
+ 4
478
+ ]);
479
+ return [
480
+ 4,
481
+ _this1.props.videoElement.requestPictureInPicture()
482
+ ];
483
+ case 2:
484
+ _state.sent();
485
+ return [
486
+ 3,
487
+ 4
488
+ ];
489
+ case 3:
490
+ error = _state.sent();
491
+ console.warn("Picture-in-Picture failed:", error);
492
+ return [
493
+ 3,
494
+ 4
495
+ ];
496
+ case 4:
497
+ return [
498
+ 2
499
+ ];
500
+ }
501
+ });
502
+ })();
503
+ };
504
+ _this1.disablePIP = function() {
505
+ return _async_to_generator(function() {
506
+ var error;
507
+ return _ts_generator(this, function(_state) {
508
+ switch(_state.label){
509
+ case 0:
510
+ if (!document.pictureInPictureElement) return [
511
+ 3,
512
+ 4
513
+ ];
514
+ _state.label = 1;
515
+ case 1:
516
+ _state.trys.push([
517
+ 1,
518
+ 3,
519
+ ,
520
+ 4
521
+ ]);
522
+ return [
523
+ 4,
524
+ document.exitPictureInPicture()
525
+ ];
526
+ case 2:
527
+ _state.sent();
528
+ return [
529
+ 3,
530
+ 4
531
+ ];
532
+ case 3:
533
+ error = _state.sent();
534
+ console.warn("Exit Picture-in-Picture failed:", error);
535
+ return [
536
+ 3,
537
+ 4
538
+ ];
539
+ case 4:
540
+ return [
541
+ 2
542
+ ];
543
+ }
544
+ });
545
+ })();
546
+ };
547
+ return _this;
243
548
  }
244
- }
245
- render() {
246
- return null;
247
- }
248
- };
549
+ _create_class(FilePlayer, [
550
+ {
551
+ key: "componentDidMount",
552
+ value: function componentDidMount() {
553
+ this.mounted = true;
554
+ this.load();
555
+ }
556
+ },
557
+ {
558
+ key: "componentWillUnmount",
559
+ value: function componentWillUnmount() {
560
+ this.mounted = false;
561
+ }
562
+ },
563
+ {
564
+ key: "componentDidUpdate",
565
+ value: function componentDidUpdate(prevProps) {
566
+ if (prevProps.src !== this.props.src) {
567
+ this.load();
568
+ }
569
+ }
570
+ },
571
+ {
572
+ key: "render",
573
+ value: function render() {
574
+ return null;
575
+ }
576
+ }
577
+ ]);
578
+ return FilePlayer;
579
+ }(import_react.Component);
249
580
  FilePlayer.displayName = "FilePlayer";
250
581
  FilePlayer.canPlay = canPlay.file;
251
582
  //# sourceMappingURL=FilePlayer.cjs.map