@antmedia/web_player 2.8.0-SNAPSHOT

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 (41) hide show
  1. package/.project +17 -0
  2. package/.settings/.jsdtscope +7 -0
  3. package/.settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
  4. package/.settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
  5. package/LICENSE +201 -0
  6. package/README.md +1 -0
  7. package/api-extractor.json +38 -0
  8. package/codecov.yml +6 -0
  9. package/dist/_commonjsHelpers-ed042b00.js +10 -0
  10. package/dist/aframe-master-42bb78a9.js +7139 -0
  11. package/dist/browser/web_player.js +976 -0
  12. package/dist/dash.all.min-84806d51.js +36 -0
  13. package/dist/es/_commonjsHelpers-7d1333e8.js +7 -0
  14. package/dist/es/aframe-master-a6146619.js +7137 -0
  15. package/dist/es/dash.all.min-4a2772b6.js +34 -0
  16. package/dist/es/index.d.ts +227 -0
  17. package/dist/es/index.js +1 -0
  18. package/dist/es/video-js.min-8b4dfe88.js +3 -0
  19. package/dist/es/video.es-22056625.js +31061 -0
  20. package/dist/es/videojs-contrib-quality-levels.es-5f5b5f23.js +287 -0
  21. package/dist/es/videojs-hls-quality-selector.es-3c54e1cd.js +391 -0
  22. package/dist/es/videojs-webrtc-plugin-b9e4da27.js +3 -0
  23. package/dist/es/videojs-webrtc-plugin.es-f41400f7.js +7649 -0
  24. package/dist/es/web_player.js +1262 -0
  25. package/dist/index.d.ts +227 -0
  26. package/dist/index.js +7 -0
  27. package/dist/video-js.min-7e4ae47a.js +5 -0
  28. package/dist/video.es-72122d04.js +31067 -0
  29. package/dist/videojs-contrib-quality-levels.es-ef3cec9e.js +289 -0
  30. package/dist/videojs-hls-quality-selector.es-562309df.js +393 -0
  31. package/dist/videojs-webrtc-plugin-d30c3e7a.js +5 -0
  32. package/dist/videojs-webrtc-plugin.es-ac81d249.js +7651 -0
  33. package/dist/web_player.js +1265 -0
  34. package/karma.conf.cjs +74 -0
  35. package/package.json +68 -0
  36. package/rollup.config.browser.cjs +16 -0
  37. package/rollup.config.module.cjs +42 -0
  38. package/src/index.js +1 -0
  39. package/src/web_player.js +1133 -0
  40. package/test/embedded-player.test.js +864 -0
  41. package/tsconfig.json +24 -0
@@ -0,0 +1,1265 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * loglevel - https://github.com/pimterry/loglevel
5
+ *
6
+ * Copyright (c) 2013 Tim Perry
7
+ * Licensed under the MIT license.
8
+ */
9
+ (function (root, definition) {
10
+ window.log = definition();
11
+ })(undefined, function () {
12
+ // Slightly dubious tricks to cut down minimized file size
13
+ var noop = function noop() {};
14
+ var undefinedType = "undefined";
15
+ var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
16
+ var logMethods = ["trace", "debug", "info", "warn", "error"];
17
+
18
+ // Cross-browser bind equivalent that works at least back to IE6
19
+ function bindMethod(obj, methodName) {
20
+ var method = obj[methodName];
21
+ if (typeof method.bind === 'function') {
22
+ return method.bind(obj);
23
+ } else {
24
+ try {
25
+ return Function.prototype.bind.call(method, obj);
26
+ } catch (e) {
27
+ // Missing bind shim or IE8 + Modernizr, fallback to wrapping
28
+ return function () {
29
+ return Function.prototype.apply.apply(method, [obj, arguments]);
30
+ };
31
+ }
32
+ }
33
+ }
34
+
35
+ // Trace() doesn't print the message in IE, so for that case we need to wrap it
36
+ function traceForIE() {
37
+ if (console.log) {
38
+ if (console.log.apply) {
39
+ console.log.apply(console, arguments);
40
+ } else {
41
+ // In old IE, native console methods themselves don't have apply().
42
+ Function.prototype.apply.apply(console.log, [console, arguments]);
43
+ }
44
+ }
45
+ if (console.trace) console.trace();
46
+ }
47
+
48
+ // Build the best logging method possible for this env
49
+ // Wherever possible we want to bind, not wrap, to preserve stack traces
50
+ function realMethod(methodName) {
51
+ if (methodName === 'debug') {
52
+ methodName = 'log';
53
+ }
54
+ if (typeof console === undefinedType) {
55
+ return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
56
+ } else if (methodName === 'trace' && isIE) {
57
+ return traceForIE;
58
+ } else if (console[methodName] !== undefined) {
59
+ return bindMethod(console, methodName);
60
+ } else if (console.log !== undefined) {
61
+ return bindMethod(console, 'log');
62
+ } else {
63
+ return noop;
64
+ }
65
+ }
66
+
67
+ // These private functions always need `this` to be set properly
68
+
69
+ function replaceLoggingMethods(level, loggerName) {
70
+ /*jshint validthis:true */
71
+ for (var i = 0; i < logMethods.length; i++) {
72
+ var methodName = logMethods[i];
73
+ this[methodName] = i < level ? noop : this.methodFactory(methodName, level, loggerName);
74
+ }
75
+
76
+ // Define log.log as an alias for log.debug
77
+ this.log = this.debug;
78
+ }
79
+
80
+ // In old IE versions, the console isn't present until you first open it.
81
+ // We build realMethod() replacements here that regenerate logging methods
82
+ function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
83
+ return function () {
84
+ if (typeof console !== undefinedType) {
85
+ replaceLoggingMethods.call(this, level, loggerName);
86
+ this[methodName].apply(this, arguments);
87
+ }
88
+ };
89
+ }
90
+
91
+ // By default, we use closely bound real methods wherever possible, and
92
+ // otherwise we wait for a console to appear, and then try again.
93
+ function defaultMethodFactory(methodName, level, loggerName) {
94
+ /*jshint validthis:true */
95
+ return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
96
+ }
97
+ function Logger(name, defaultLevel, factory) {
98
+ var self = this;
99
+ var currentLevel;
100
+ defaultLevel = defaultLevel == null ? "WARN" : defaultLevel;
101
+ var storageKey = "loglevel";
102
+ if (typeof name === "string") {
103
+ storageKey += ":" + name;
104
+ } else if (typeof name === "symbol") {
105
+ storageKey = undefined;
106
+ }
107
+ function persistLevelIfPossible(levelNum) {
108
+ var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
109
+ if (typeof window === undefinedType || !storageKey) return;
110
+
111
+ // Use localStorage if available
112
+ try {
113
+ window.localStorage[storageKey] = levelName;
114
+ return;
115
+ } catch (ignore) {}
116
+
117
+ // Use session cookie as fallback
118
+ try {
119
+ window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
120
+ } catch (ignore) {}
121
+ }
122
+ function getPersistedLevel() {
123
+ var storedLevel;
124
+ if (typeof window === undefinedType || !storageKey) return;
125
+ try {
126
+ storedLevel = window.localStorage[storageKey];
127
+ } catch (ignore) {}
128
+
129
+ // Fallback to cookies if local storage gives us nothing
130
+ if (typeof storedLevel === undefinedType) {
131
+ try {
132
+ var cookie = window.document.cookie;
133
+ var location = cookie.indexOf(encodeURIComponent(storageKey) + "=");
134
+ if (location !== -1) {
135
+ storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
136
+ }
137
+ } catch (ignore) {}
138
+ }
139
+
140
+ // If the stored level is not valid, treat it as if nothing was stored.
141
+ if (self.levels[storedLevel] === undefined) {
142
+ storedLevel = undefined;
143
+ }
144
+ return storedLevel;
145
+ }
146
+ function clearPersistedLevel() {
147
+ if (typeof window === undefinedType || !storageKey) return;
148
+
149
+ // Use localStorage if available
150
+ try {
151
+ window.localStorage.removeItem(storageKey);
152
+ return;
153
+ } catch (ignore) {}
154
+
155
+ // Use session cookie as fallback
156
+ try {
157
+ window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
158
+ } catch (ignore) {}
159
+ }
160
+
161
+ /*
162
+ *
163
+ * Public logger API - see https://github.com/pimterry/loglevel for details
164
+ *
165
+ */
166
+
167
+ self.name = name;
168
+ self.levels = {
169
+ "TRACE": 0,
170
+ "DEBUG": 1,
171
+ "INFO": 2,
172
+ "WARN": 3,
173
+ "ERROR": 4,
174
+ "SILENT": 5
175
+ };
176
+ self.methodFactory = factory || defaultMethodFactory;
177
+ self.getLevel = function () {
178
+ return currentLevel;
179
+ };
180
+ self.setLevel = function (level, persist) {
181
+ if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
182
+ level = self.levels[level.toUpperCase()];
183
+ }
184
+ if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
185
+ currentLevel = level;
186
+ if (persist !== false) {
187
+ // defaults to true
188
+ persistLevelIfPossible(level);
189
+ }
190
+ replaceLoggingMethods.call(self, level, name);
191
+ if (typeof console === undefinedType && level < self.levels.SILENT) {
192
+ return "No console available for logging";
193
+ }
194
+ } else {
195
+ throw "log.setLevel() called with invalid level: " + level;
196
+ }
197
+ };
198
+ self.setDefaultLevel = function (level) {
199
+ defaultLevel = level;
200
+ if (!getPersistedLevel()) {
201
+ self.setLevel(level, false);
202
+ }
203
+ };
204
+ self.resetLevel = function () {
205
+ self.setLevel(defaultLevel, false);
206
+ clearPersistedLevel();
207
+ };
208
+ self.enableAll = function (persist) {
209
+ self.setLevel(self.levels.TRACE, persist);
210
+ };
211
+ self.disableAll = function (persist) {
212
+ self.setLevel(self.levels.SILENT, persist);
213
+ };
214
+
215
+ // Initialize with the right level
216
+ var initialLevel = getPersistedLevel();
217
+ if (initialLevel == null) {
218
+ initialLevel = defaultLevel;
219
+ }
220
+ self.setLevel(initialLevel, false);
221
+ }
222
+
223
+ /*
224
+ *
225
+ * Top-level API
226
+ *
227
+ */
228
+
229
+ var defaultLogger = new Logger();
230
+ var _loggersByName = {};
231
+ defaultLogger.getLogger = function getLogger(name) {
232
+ if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
233
+ throw new TypeError("You must supply a name when creating a logger.");
234
+ }
235
+ var logger = _loggersByName[name];
236
+ if (!logger) {
237
+ logger = _loggersByName[name] = new Logger(name, defaultLogger.getLevel(), defaultLogger.methodFactory);
238
+ }
239
+ return logger;
240
+ };
241
+
242
+ // Grab the current global log variable in case of overwrite
243
+ var _log = typeof window !== undefinedType ? window.log : undefined;
244
+ defaultLogger.noConflict = function () {
245
+ if (typeof window !== undefinedType && window.log === defaultLogger) {
246
+ window.log = _log;
247
+ }
248
+ return defaultLogger;
249
+ };
250
+ defaultLogger.getLoggers = function getLoggers() {
251
+ return _loggersByName;
252
+ };
253
+
254
+ // ES6 default export, for compatibility
255
+ defaultLogger['default'] = defaultLogger;
256
+ return defaultLogger;
257
+ });
258
+ var Logger = window.log;
259
+ var Logger_1 = Logger;
260
+
261
+ //ask if adaptive m3u8 file
262
+
263
+ if (!String.prototype.endsWith) {
264
+ String.prototype.endsWith = function (searchString, position) {
265
+ var subjectString = this.toString();
266
+ if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
267
+ position = subjectString.length;
268
+ }
269
+ position -= searchString.length;
270
+ var lastIndex = subjectString.lastIndexOf(searchString, position);
271
+ return lastIndex !== -1 && lastIndex === position;
272
+ };
273
+ }
274
+ /**
275
+ *
276
+ * @param {string} sParam
277
+ * @param {string=} search
278
+ * @returns
279
+ */
280
+ function getUrlParameter(sParam, search) {
281
+ if (typeof search === undefined || search == null) {
282
+ search = window.location.search;
283
+ }
284
+ var sPageURL = decodeURIComponent(search.substring(1)),
285
+ sURLVariables = sPageURL.split('&'),
286
+ sParameterName,
287
+ i;
288
+ for (i = 0; i < sURLVariables.length; i++) {
289
+ sParameterName = sURLVariables[i].split('=');
290
+ if (sParameterName[0] === sParam) {
291
+ return sParameterName[1] === undefined ? true : sParameterName[1];
292
+ }
293
+ }
294
+ }
295
+ var getUrlParameter_1 = getUrlParameter;
296
+
297
+ const STATIC_VIDEO_HTML = "<video id='video-player' class='video-js vjs-default-skin vjs-big-play-centered' controls playsinline></video>";
298
+ class WebPlayer {
299
+ static DEFAULT_PLAY_ORDER = ["webrtc", "hls"];
300
+ static DEFAULT_PLAY_TYPE = ["mp4", "webm"];
301
+ static HLS_EXTENSION = "m3u8";
302
+ static WEBRTC_EXTENSION = "webrtc";
303
+ static DASH_EXTENSION = "mpd";
304
+
305
+ /**
306
+ * streamsFolder: streams folder. Optional. Default value is "streams"
307
+ */
308
+ static STREAMS_FOLDER = "streams";
309
+
310
+ /**
311
+ * Video HTML content. It's by default STATIC_VIDEO_HTML
312
+ */
313
+ videoHTMLContent;
314
+
315
+ /**
316
+ * video player Id. It's by default "video-player"
317
+ */
318
+ videoPlayerId;
319
+
320
+ /**
321
+ * "playOrder": the order which technologies is used in playing. Optional. Default value is "webrtc,hls".
322
+ * possible values are "hls,webrtc","webrtc","hls","vod","dash"
323
+ * It will be taken from url parameter "playOrder".
324
+ */
325
+ playOrder;
326
+
327
+ /**
328
+ * currentPlayType: current play type in playOrder
329
+ */
330
+ currentPlayType;
331
+
332
+ /**
333
+ * "is360": if true, player will be 360 degree player. Optional. Default value is false.
334
+ * It will be taken from url parameter "is360".
335
+ */
336
+ is360 = false;
337
+
338
+ /**
339
+ * "streamId": stream id. Mandatory. If it is not set, it will be taken from url parameter "id".
340
+ * It will be taken from url parameter "id".
341
+ */
342
+ streamId;
343
+
344
+ /**
345
+ * "playType": play type. Optional. It's used for vod. Default value is "mp4,webm".
346
+ * It can be "mp4,webm","webm,mp4","mp4","webm","mov" and it's used for vod.
347
+ * It will be taken from url parameter "playType".
348
+ */
349
+ playType;
350
+
351
+ /**
352
+ * "token": token. It's required when stream security for playback is enabled .
353
+ * It will be taken from url parameter "token".
354
+ */
355
+ token;
356
+
357
+ /**
358
+ * autoplay: if true, player will be started automatically. Optional. Default value is true.
359
+ * autoplay is false by default for mobile devices because of mobile browser's autoplay policy.
360
+ * It will be taken from url parameter "autoplay".
361
+ */
362
+ autoPlay = true;
363
+
364
+ /**
365
+ * mute: if true, player will be started muted. Optional. Default value is true.
366
+ * default value is true because of browser's autoplay policy.
367
+ * It will be taken from url parameter "mute".
368
+ */
369
+ mute = true;
370
+
371
+ /**
372
+ * targetLatency: target latency in seconds. Optional. Default value is 3.
373
+ * It will be taken from url parameter "targetLatency".
374
+ * It's used for dash(cmaf) playback.
375
+ */
376
+ targetLatency = 3;
377
+
378
+ /**
379
+ * subscriberId: subscriber id. Optional. It will be taken from url parameter "subscriberId".
380
+ */
381
+ subscriberId;
382
+
383
+ /**
384
+ * subscriberCode: subscriber code. Optional. It will be taken from url parameter "subscriberCode".
385
+ */
386
+ subscriberCode;
387
+
388
+ /**
389
+ * window: window object
390
+ */
391
+ window;
392
+
393
+ /**
394
+ * video player container element
395
+ */
396
+ containerElement;
397
+
398
+ /**
399
+ * player placeholder element
400
+ */
401
+ placeHolderElement;
402
+
403
+ /**
404
+ * videojs player
405
+ */
406
+ videojsPlayer;
407
+
408
+ /**
409
+ * dash player
410
+ */
411
+ dashPlayer;
412
+
413
+ /**
414
+ * Ice servers for webrtc
415
+ */
416
+ iceServers;
417
+
418
+ /**
419
+ * ice connection state
420
+ */
421
+ iceConnected;
422
+
423
+ /**
424
+ * flag to check if error callback is called
425
+ */
426
+ errorCalled;
427
+
428
+ /**
429
+ * scene for 360 degree player
430
+ */
431
+ aScene;
432
+
433
+ /**
434
+ * player listener
435
+ */
436
+ playerListener;
437
+
438
+ /**
439
+ * webRTCDataListener
440
+ */
441
+ webRTCDataListener;
442
+
443
+ /**
444
+ * Field to keep if tryNextMethod is already called
445
+ */
446
+ tryNextTechTimer;
447
+ constructor(configOrWindow, containerElement, placeHolderElement) {
448
+ WebPlayer.DEFAULT_PLAY_ORDER = ["webrtc", "hls"];
449
+ WebPlayer.DEFAULT_PLAY_TYPE = ["mp4", "webm"];
450
+ WebPlayer.HLS_EXTENSION = "m3u8";
451
+ WebPlayer.WEBRTC_EXTENSION = "webrtc";
452
+ WebPlayer.DASH_EXTENSION = "mpd";
453
+
454
+ /**
455
+ * streamsFolder: streams folder. Optional. Default value is "streams"
456
+ */
457
+ WebPlayer.STREAMS_FOLDER = "streams";
458
+ WebPlayer.VIDEO_PLAYER_ID = "video-player";
459
+
460
+ // Initialize default values
461
+ this.setDefaults();
462
+
463
+ // Check if the first argument is a config object or a Window object
464
+ if (!this.isWindow(configOrWindow)) {
465
+ // New config object mode
466
+ Logger_1.info("config object mode");
467
+ Object.assign(this, configOrWindow);
468
+ this.window = window;
469
+ } else {
470
+ // Backward compatibility mode
471
+ Logger_1.info("getting from url mode");
472
+ this.window = configOrWindow;
473
+
474
+ // Use getUrlParameter for backward compatibility
475
+ this.initializeFromUrlParams();
476
+ }
477
+ this.containerElement = containerElement;
478
+ this.placeHolderElement = placeHolderElement;
479
+ if (this.streamId == null) {
480
+ var message = "Stream id is not set.Please add your stream id to the url as a query parameter such as ?id={STREAM_ID} to the url";
481
+ Logger_1.error(message);
482
+ //TODO: we may need to show this message on directly page
483
+ alert(message);
484
+ throw new Error(message);
485
+ }
486
+ if (!this.httpBaseURL) {
487
+ let appName = this.window.location.pathname.substring(0, this.window.location.pathname.lastIndexOf("/") + 1);
488
+ let path = this.window.location.hostname + ":" + this.window.location.port + appName + this.streamId + ".webrtc";
489
+ this.websocketURL = "ws://" + path;
490
+ if (location.protocol.startsWith("https")) {
491
+ this.websocketURL = "wss://" + path;
492
+ }
493
+ this.httpBaseURL = location.protocol + "//" + this.window.location.hostname + ":" + this.window.location.port + appName;
494
+ } else if (!this.websocketURL) {
495
+ this.websocketURL = this.httpBaseURL.replace("http", "ws");
496
+ if (!this.websocketURL.endsWith("/")) {
497
+ this.websocketURL += "/";
498
+ }
499
+ this.websocketURL += this.streamId + ".webrtc";
500
+ }
501
+ this.dom = this.window.document;
502
+ this.containerElement.innerHTML = this.videoHTMLContent;
503
+ this.setPlayerVisible(false);
504
+ }
505
+ isWindow(configOrWindow) {
506
+ //accept that it's a window if it's a Window instance or it has location.href
507
+ //location.href is used in test environment
508
+ return configOrWindow instanceof Window || configOrWindow.location && configOrWindow.location.href;
509
+ }
510
+ initialize() {
511
+ return this.loadVideoJSComponents().then(() => {
512
+ return this.loadDashScript();
513
+ }).then(() => {
514
+ if (this.is360 && !window.AFRAME) {
515
+ return Promise.resolve().then(function () { return require('./aframe-master-42bb78a9.js'); }).then(function (n) { return n.aframeMaster; });
516
+ }
517
+ }).catch(e => {
518
+ Logger_1.error("Scripts are not loaded. The error is " + e);
519
+ throw e;
520
+ });
521
+ }
522
+ loadDashScript() {
523
+ if (this.playOrder.includes("dash") && !this.dashjsLoaded) {
524
+ return Promise.resolve().then(function () { return require('./dash.all.min-84806d51.js'); }).then(function (n) { return n.dash_all_min; }).then(dashjs => {
525
+ window.dashjs = dashjs.default;
526
+ this.dashjsLoaded = true;
527
+ console.log("dash.all.min.js is loaded");
528
+ });
529
+ } else {
530
+ return Promise.resolve();
531
+ }
532
+ }
533
+ setDefaults() {
534
+ this.playOrder = WebPlayer.DEFAULT_PLAY_ORDER;
535
+ this.currentPlayType = null;
536
+ this.is360 = false;
537
+ this.streamId = null;
538
+ this.playType = WebPlayer.DEFAULT_PLAY_TYPE;
539
+ this.token = null;
540
+ this.autoPlay = true;
541
+ this.mute = true;
542
+ this.targetLatency = 3;
543
+ this.subscriberId = null;
544
+ this.subscriberCode = null;
545
+ this.window = null;
546
+ this.containerElement = null;
547
+ this.placeHolderElement = null;
548
+ this.videojsPlayer = null;
549
+ this.dashPlayer = null;
550
+ this.iceServers = '[ { "urls": "stun:stun1.l.google.com:19302" } ]';
551
+ this.iceConnected = false;
552
+ this.errorCalled = false;
553
+ this.tryNextTechTimer = -1;
554
+ this.aScene = null;
555
+ this.playerListener = null;
556
+ this.webRTCDataListener = null;
557
+ this.websocketURL = null;
558
+ this.httpBaseURL = null;
559
+ this.videoHTMLContent = STATIC_VIDEO_HTML;
560
+ this.videoPlayerId = "video-player";
561
+ this.videojsLoaded = false;
562
+ this.dashjsLoaded = false;
563
+ }
564
+ initializeFromUrlParams() {
565
+ // Fetch parameters from URL and set to class properties
566
+ this.streamId = getUrlParameter_1("id", this.window.location.search) || this.streamId;
567
+ if (this.streamId == null) {
568
+ //check name variable for compatibility with older versions
569
+
570
+ this.streamId = getUrlParameter_1("name", this.window.location.search) || this.streamId;
571
+ if (this.streamId == null) {
572
+ Logger_1.warn("Please use id parameter instead of name parameter.");
573
+ }
574
+ }
575
+ this.is360 = getUrlParameter_1("is360", this.window.location.search) === "true" || this.is360;
576
+ this.playType = getUrlParameter_1("playType", this.window.location.search)?.split(',') || this.playType;
577
+ this.token = getUrlParameter_1("token", this.window.location.search) || this.token;
578
+ let autoPlayLocal = getUrlParameter_1("autoplay", this.window.location.search);
579
+ if (autoPlayLocal === "false") {
580
+ this.autoPlay = false;
581
+ } else {
582
+ this.autoPlay = true;
583
+ }
584
+ let muteLocal = getUrlParameter_1("mute", this.window.location.search);
585
+ if (muteLocal === "false") {
586
+ this.mute = false;
587
+ } else {
588
+ this.mute = true;
589
+ }
590
+ let localTargetLatency = getUrlParameter_1("targetLatency", this.window.location.search);
591
+ if (localTargetLatency != null) {
592
+ let latencyInNumber = Number(localTargetLatency);
593
+ if (!isNaN(latencyInNumber)) {
594
+ this.targetLatency = latencyInNumber;
595
+ } else {
596
+ Logger_1.warn("targetLatency parameter is not a number. It will be ignored.");
597
+ this.targetLatency = this.targetLatency || 3; // Default value or existing value
598
+ }
599
+ }
600
+ this.subscriberId = getUrlParameter_1("subscriberId", this.window.location.search) || this.subscriberId;
601
+ this.subscriberCode = getUrlParameter_1("subscriberCode", this.window.location.search) || this.subscriberCode;
602
+ let playOrder = getUrlParameter_1("playOrder", this.window.location.search);
603
+ this.playOrder = playOrder ? playOrder.split(',') : this.playOrder;
604
+ }
605
+ loadWebRTCComponents() {
606
+ if (this.playOrder.includes("webrtc")) {
607
+ return Promise.resolve().then(function () { return require('./videojs-webrtc-plugin-d30c3e7a.js'); }).then(css => {
608
+ Logger_1.info("videojs-webrtc-plugin.css is loaded");
609
+ const styleElement = this.dom.createElement('style');
610
+ styleElement.textContent = css.default.toString(); // Assuming css module exports a string
611
+ this.dom.head.appendChild(styleElement);
612
+ return Promise.resolve().then(function () { return require('./videojs-webrtc-plugin.es-ac81d249.js'); }).then(videojsWebrtcPluginLocal => {
613
+ Logger_1.info("videojs-webrtc-plugin is loaded");
614
+ });
615
+ });
616
+ } else {
617
+ return Promise.resolve();
618
+ }
619
+ }
620
+ /**
621
+ * load scripts dynamically
622
+ */
623
+ loadVideoJSComponents() {
624
+ if (this.playOrder.includes("hls") || this.playOrder.includes("vod") || this.playOrder.includes("webrtc")) {
625
+ //it means we're going to use videojs
626
+ //load videojs css
627
+ if (!this.videojsLoaded) {
628
+ return Promise.resolve().then(function () { return require('./video-js.min-7e4ae47a.js'); }).then(css => {
629
+ const styleElement = this.dom.createElement('style');
630
+ styleElement.textContent = css.default.toString(); // Assuming css module exports a string
631
+ this.dom.head.appendChild(styleElement);
632
+ }).then(() => {
633
+ return Promise.resolve().then(function () { return require('./video.es-72122d04.js'); }).then(function (n) { return n.video_es; });
634
+ }).then(videojs => {
635
+ window.videojs = videojs.default;
636
+ this.videojsLoaded = true;
637
+ }).then(() => {
638
+ return Promise.resolve().then(function () { return require('./videojs-contrib-quality-levels.es-ef3cec9e.js'); });
639
+ }).then(() => {
640
+ return Promise.resolve().then(function () { return require('./videojs-hls-quality-selector.es-562309df.js'); });
641
+ }).then(() => {
642
+ return this.loadWebRTCComponents();
643
+ });
644
+ } else {
645
+ return Promise.resolve();
646
+ }
647
+ } else {
648
+ return Promise.resolve();
649
+ }
650
+ }
651
+
652
+ /**
653
+ * enable 360 player
654
+ */
655
+ enable360Player() {
656
+ this.aScene = this.dom.createElement("a-scene");
657
+ var elementId = this.dom.getElementsByTagName("video")[0].id;
658
+ this.aScene.innerHTML = "<a-videosphere src=\"#" + elementId + "\" rotation=\"0 180 0\" style=\"background-color: antiquewhite\"></a-videosphere>";
659
+ this.dom.body.appendChild(this.aScene);
660
+ }
661
+
662
+ /**
663
+ * set player visibility
664
+ * @param {boolean} visible
665
+ */
666
+ setPlayerVisible(visible) {
667
+ this.containerElement.style.display = visible ? "block" : "none";
668
+ if (this.placeHolderElement) {
669
+ this.placeHolderElement.style.display = visible ? "none" : "block";
670
+ }
671
+ if (this.is360) {
672
+ if (visible) {
673
+ this.enable360Player();
674
+ } else if (this.aScene != null) {
675
+ var elements = this.dom.getElementsByTagName("a-scene");
676
+ while (elements.length > 0) {
677
+ this.dom.body.removeChild(elements[0]);
678
+ elements = this.dom.getElementsByTagName("a-scene");
679
+ }
680
+ this.aScene = null;
681
+ }
682
+ }
683
+ }
684
+ handleWebRTCInfoMessages(infos) {
685
+ if (infos["info"] == "ice_connection_state_changed") {
686
+ Logger_1.debug("ice connection state changed to " + infos["obj"].state);
687
+ if (infos["obj"].state == "completed" || infos["obj"].state == "connected") {
688
+ this.iceConnected = true;
689
+ } else if (infos["obj"].state == "failed" || infos["obj"].state == "disconnected" || infos["obj"].state == "closed") {
690
+ //
691
+ Logger_1.warn("Ice connection is not connected. tryNextTech to replay");
692
+ this.tryNextTech();
693
+ }
694
+ } else if (infos["info"] == "closed") {
695
+ //this means websocket is closed and it stops the playback - tryNextTech
696
+ Logger_1.warn("Websocket is closed. tryNextTech to replay");
697
+ this.tryNextTech();
698
+ } else if (infos["info"] == "resolutionChangeInfo") {
699
+ Logger_1.info("Resolution is changing");
700
+ this.videojsPlayer.pause();
701
+ setTimeout(() => {
702
+ this.videojsPlayer.play();
703
+ }, 1000);
704
+ }
705
+ }
706
+
707
+ /**
708
+ * Play the stream via videojs
709
+ * @param {*} streamUrl
710
+ * @param {*} extension
711
+ * @returns
712
+ */
713
+ playWithVideoJS(streamUrl, extension) {
714
+ var type;
715
+ if (extension == "mp4") {
716
+ type = "video/mp4";
717
+ } else if (extension == "webm") {
718
+ type = "video/webm";
719
+ } else if (extension == "mov") {
720
+ type = "video/mp4";
721
+ alert("Browsers do not support to play mov format");
722
+ } else if (extension == "avi") {
723
+ type = "video/mp4";
724
+ alert("Browsers do not support to play avi format");
725
+ } else if (extension == "m3u8") {
726
+ type = "application/x-mpegURL";
727
+ } else if (extension == "mpd") {
728
+ type = "application/dash+xml";
729
+ } else if (extension == "webrtc") {
730
+ type = "video/webrtc";
731
+ } else {
732
+ Logger_1.warn("Unknown extension: " + extension);
733
+ return;
734
+ }
735
+ var preview = this.streamId;
736
+ if (this.streamId.endsWith("_adaptive")) {
737
+ preview = streamId.substring(0, streamId.indexOf("_adaptive"));
738
+ }
739
+
740
+ //same videojs is being use for hls, vod and webrtc streams
741
+ this.videojsPlayer = videojs(this.videoPlayerId, {
742
+ poster: "previews/" + preview + ".png",
743
+ liveui: extension == "m3u8" ? true : false,
744
+ liveTracker: {
745
+ trackingThreshold: 0
746
+ },
747
+ html5: {
748
+ vhs: {
749
+ limitRenditionByPlayerDimensions: false
750
+ }
751
+ },
752
+ controls: true,
753
+ class: 'video-js vjs-default-skin vjs-big-play-centered',
754
+ muted: this.mute,
755
+ preload: "auto",
756
+ autoplay: this.autoPlay
757
+ });
758
+ this.videojsPlayer.on('error', e => {
759
+ Logger_1.warn("There is an error in playback: " + e);
760
+ // We need to add this kind of check. If we don't add this kind of checkpoint, it will create an infinite loop
761
+ if (!this.errorCalled) {
762
+ this.errorCalled = true;
763
+ setTimeout(() => {
764
+ this.tryNextTech();
765
+ this.errorCalled = false;
766
+ }, 2500);
767
+ }
768
+ });
769
+
770
+ //webrtc specific events
771
+ if (extension == "webrtc") {
772
+ this.videojsPlayer.on('webrtc-info', (event, infos) => {
773
+ //Logger.warn("info callback: " + JSON.stringify(infos));
774
+ this.handleWebRTCInfoMessages(infos);
775
+ });
776
+ this.videojsPlayer.on('webrtc-error', (event, errors) => {
777
+ //some of the possible errors, NotFoundError, SecurityError,PermissionDeniedError
778
+ Logger_1.warn("error callback: " + JSON.stringify(errors));
779
+ if (errors["error"] == "no_stream_exist" || errors["error"] == "WebSocketNotConnected" || errors["error"] == "not_initialized_yet" || errors["error"] == "data_store_not_available" || errors["error"] == "highResourceUsage" || errors["error"] == "unauthorized_access" || errors["error"] == "user_blocked") {
780
+ //handle high resource usage and not authroized errors && websocket disconnected
781
+ //Even if webrtc adaptor has auto reconnect scenario, we dispose the videojs immediately in tryNextTech
782
+ // so that reconnect scenario is managed here
783
+
784
+ this.tryNextTech();
785
+ } else if (errors["error"] == "notSetRemoteDescription") {
786
+ /*
787
+ * If getting codec incompatible or remote description error, it will redirect HLS player.
788
+ */
789
+ Logger_1.warn("notSetRemoteDescription error. Redirecting to HLS player.");
790
+ this.playIfExists("hls");
791
+ }
792
+ });
793
+ this.videojsPlayer.on("webrtc-data-received", (event, obj) => {
794
+ Logger_1.warn("webrtc-data-received: " + JSON.stringify(obj));
795
+ if (this.webRTCDataListener != null) {
796
+ this.webRTCDataListener(obj);
797
+ }
798
+ });
799
+ }
800
+
801
+ //hls specific calls
802
+ if (extension == "m3u8") {
803
+ videojs.Vhs.xhr.beforeRequest = options => {
804
+ let securityParams = this.getSecurityQueryParams();
805
+ if (!options.uri.includes(securityParams)) {
806
+ if (!options.uri.endsWith("?")) {
807
+ options.uri = options.uri + "?";
808
+ }
809
+ options.uri += securityParams;
810
+ }
811
+ Logger_1.debug("hls request: " + options.uri);
812
+ return options;
813
+ };
814
+ this.videojsPlayer.ready(() => {
815
+ // If it's already added to player, no need to add again
816
+ if (typeof this.videojsPlayer.hlsQualitySelector === "function") {
817
+ this.videojsPlayer.hlsQualitySelector({
818
+ displayCurrentQuality: true
819
+ });
820
+ }
821
+
822
+ // If there is no adaptive option in m3u8 no need to show quality selector
823
+ let qualityLevels = this.videojsPlayer.qualityLevels();
824
+ qualityLevels.on('addqualitylevel', function (event) {
825
+ let qualityLevel = event.qualityLevel;
826
+ if (qualityLevel.height) {
827
+ qualityLevel.enabled = true;
828
+ } else {
829
+ qualityLevels.removeQualityLevel(qualityLevel);
830
+ qualityLevel.enabled = false;
831
+ }
832
+ });
833
+ });
834
+ }
835
+
836
+ //videojs is being used to play mp4, webm, m3u8 and webrtc
837
+ //make the videoJS visible when ready is called except for webrtc
838
+ //webrtc fires ready event all cases so we use "play" event to make the player visible
839
+
840
+ //this setting is critical to play in mobile
841
+ if (extension == "mp4" || extension == "webm" || extension == "m3u8") {
842
+ this.makeVideoJSVisibleWhenReady();
843
+ }
844
+ this.videojsPlayer.on('ended', () => {
845
+ //reinit to play after it ends
846
+ Logger_1.warn("stream is ended");
847
+ this.setPlayerVisible(false);
848
+ //for webrtc, this event can be called by two reasons
849
+ //1. ice connection is not established, it means that there is a networking issug
850
+ //2. stream is ended
851
+ if (this.currentPlayType != "vod") {
852
+ //if it's vod, it means that stream is ended and no need to replay
853
+
854
+ if (this.iceConnected) {
855
+ //if iceConnected is true, it means that stream is really ended for webrtc
856
+
857
+ //initialize to play again if the publishing starts again
858
+ this.playIfExists(this.playOrder[0]);
859
+ } else if (this.currentPlayType == "hls") {
860
+ //if it's hls, it means that stream is ended
861
+
862
+ this.setPlayerVisible(false);
863
+ if (this.playOrder[0] = "hls") {
864
+ //do not play again if it's hls because it play last seconds again, let the server clear it
865
+ setTimeout(() => {
866
+ this.playIfExists(this.playOrder[0]);
867
+ }, 10000);
868
+ } else {
869
+ this.playIfExists(this.playOrder[0]);
870
+ }
871
+ //TODO: what if the stream is hls vod then it always re-play
872
+ } else {
873
+ //if iceConnected is false, it means that there is a networking issue for webrtc
874
+ this.tryNextTech();
875
+ }
876
+ }
877
+ if (this.playerListener != null) {
878
+ this.playerListener("ended");
879
+ }
880
+ });
881
+
882
+ //webrtc plugin sends play event. On the other hand, webrtc plugin sends ready event for every scenario.
883
+ //so no need to trust ready event for webrt play
884
+ this.videojsPlayer.on("play", () => {
885
+ this.setPlayerVisible(true);
886
+ if (this.playerListener != null) {
887
+ this.playerListener("play");
888
+ }
889
+ });
890
+ this.iceConnected = false;
891
+ this.videojsPlayer.src({
892
+ src: streamUrl,
893
+ type: type,
894
+ withCredentials: true,
895
+ iceServers: this.iceServers,
896
+ reconnect: false //webrtc adaptor has auto reconnect scenario, just disable it, we manage it here
897
+ });
898
+ if (this.autoPlay) {
899
+ this.videojsPlayer.play().catch(e => {
900
+ Logger_1.warn("Problem in playback. The error is " + e);
901
+ });
902
+ }
903
+ }
904
+ makeVideoJSVisibleWhenReady() {
905
+ this.videojsPlayer.ready(() => {
906
+ this.setPlayerVisible(true);
907
+ });
908
+ }
909
+
910
+ /**
911
+ * check if stream exists via http
912
+ * @param {*} streamsfolder
913
+ * @param {*} streamId
914
+ * @param {*} extension
915
+ * @returns
916
+ */
917
+ checkStreamExistsViaHttp(streamsfolder, streamId, extension) {
918
+ var streamPath = this.httpBaseURL;
919
+ if (!streamId.startsWith(streamsfolder)) {
920
+ streamPath += streamsfolder + "/";
921
+ }
922
+ streamPath += streamId;
923
+ if (extension != null && extension != "") {
924
+ //if there is extension, add it and try if _adaptive exists
925
+ streamPath += "_adaptive" + "." + extension;
926
+ }
927
+ streamPath = this.addSecurityParams(streamPath);
928
+ return fetch(streamPath, {
929
+ method: 'HEAD'
930
+ }).then(response => {
931
+ if (response.status == 200) {
932
+ // adaptive m3u8 & mpd exists,play it
933
+ return new Promise(function (resolve, reject) {
934
+ resolve(streamPath);
935
+ });
936
+ } else {
937
+ //adaptive not exists, try mpd or m3u8 exists.
938
+ streamPath = this.httpBaseURL + streamsfolder + "/" + streamId + "." + extension;
939
+ streamPath = this.addSecurityParams(streamPath);
940
+ return fetch(streamPath, {
941
+ method: 'HEAD'
942
+ }).then(response => {
943
+ if (response.status == 200) {
944
+ return new Promise(function (resolve, reject) {
945
+ resolve(streamPath);
946
+ });
947
+ } else {
948
+ Logger_1.warn("No stream found");
949
+ return new Promise(function (resolve, reject) {
950
+ reject("resource_is_not_available");
951
+ });
952
+ }
953
+ });
954
+ }
955
+ });
956
+ }
957
+ addSecurityParams(streamPath) {
958
+ var securityParams = this.getSecurityQueryParams();
959
+ if (securityParams != null && securityParams != "") {
960
+ streamPath += "?" + securityParams;
961
+ }
962
+ return streamPath;
963
+ }
964
+
965
+ /**
966
+ * try next tech if current tech is not working
967
+ */
968
+ tryNextTech() {
969
+ if (this.tryNextTechTimer == -1) {
970
+ this.destroyDashPlayer();
971
+ this.destroyVideoJSPlayer();
972
+ this.setPlayerVisible(false);
973
+ var index = this.playOrder.indexOf(this.currentPlayType);
974
+ if (index == -1 || index == this.playOrder.length - 1) {
975
+ index = 0;
976
+ } else {
977
+ index++;
978
+ }
979
+ this.tryNextTechTimer = setTimeout(() => {
980
+ this.tryNextTechTimer = -1;
981
+ this.playIfExists(this.playOrder[index]);
982
+ }, 3000);
983
+ } else {
984
+ Logger_1.debug("tryNextTech is already scheduled no need to schedule again");
985
+ }
986
+ }
987
+
988
+ /**
989
+ * play stream throgugh dash player
990
+ * @param {string"} streamUrl
991
+ */
992
+ playViaDash(streamUrl) {
993
+ this.destroyDashPlayer();
994
+ this.dashPlayer = dashjs.MediaPlayer().create();
995
+ this.dashPlayer.extend("RequestModifier", () => {
996
+ return {
997
+ modifyRequestHeader: function (xhr, {
998
+ url
999
+ }) {
1000
+ return xhr;
1001
+ },
1002
+ modifyRequestURL: url => {
1003
+ var modifiedUrl = "";
1004
+ var securityParams = this.getSecurityQueryParams();
1005
+ if (!url.includes(securityParams)) {
1006
+ if (!url.endsWith("?")) {
1007
+ url += "?";
1008
+ }
1009
+ modifiedUrl = url + securityParams;
1010
+ Logger_1.warn(modifiedUrl);
1011
+ return modifiedUrl;
1012
+ }
1013
+ return url;
1014
+ },
1015
+ modifyRequest(request) {}
1016
+ };
1017
+ });
1018
+ this.dashPlayer.updateSettings({
1019
+ streaming: {
1020
+ delay: {
1021
+ liveDelay: this.targetLatency
1022
+ },
1023
+ liveCatchup: {
1024
+ maxDrift: 0.5,
1025
+ playbackRate: 0.5,
1026
+ latencyThreshold: 60
1027
+ }
1028
+ }
1029
+ });
1030
+ this.dashPlayer.initialize(this.containerElement.firstChild, streamUrl, this.autoPlay);
1031
+ this.dashPlayer.setMute(this.mute);
1032
+ this.dashLatencyTimer = setInterval(() => {
1033
+ Logger_1.warn("live latency: " + this.dashPlayer.getCurrentLiveLatency());
1034
+ }, 2000);
1035
+ this.makeDashPlayerVisibleWhenInitialized();
1036
+ this.dashPlayer.on(dashjs.MediaPlayer.events.PLAYBACK_PLAYING, event => {
1037
+ Logger_1.warn("playback started");
1038
+ this.setPlayerVisible(true);
1039
+ if (this.playerListener != null) {
1040
+ this.playerListener("play");
1041
+ }
1042
+ });
1043
+ this.dashPlayer.on(dashjs.MediaPlayer.events.PLAYBACK_ENDED, () => {
1044
+ Logger_1.warn("playback ended");
1045
+ this.destroyDashPlayer();
1046
+ this.setPlayerVisible(false);
1047
+ //streaming can be started again so try to play again with preferred tech
1048
+ if (this.playOrder[0] = "dash") {
1049
+ //do not play again if it's dash because it play last seconds again, let the server clear it
1050
+ setTimeout(() => {
1051
+ this.playIfExists(this.playOrder[0]);
1052
+ }, 10000);
1053
+ } else {
1054
+ this.playIfExists(this.playOrder[0]);
1055
+ }
1056
+ if (this.playerListener != null) {
1057
+ this.playerListener("ended");
1058
+ }
1059
+ });
1060
+ this.dashPlayer.on(dashjs.MediaPlayer.events.PLAYBACK_ERROR, event => {
1061
+ this.tryNextTech();
1062
+ });
1063
+ this.dashPlayer.on(dashjs.MediaPlayer.events.ERROR, event => {
1064
+ this.tryNextTech();
1065
+ });
1066
+ }
1067
+ makeDashPlayerVisibleWhenInitialized() {
1068
+ this.dashPlayer.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, event => {
1069
+ Logger_1.warn("Stream initialized");
1070
+ //make the player visible in mobile devices
1071
+ this.setPlayerVisible(true);
1072
+ });
1073
+ }
1074
+
1075
+ /**
1076
+ * destroy the dash player
1077
+ */
1078
+ destroyDashPlayer() {
1079
+ if (this.dashPlayer) {
1080
+ this.dashPlayer.destroy();
1081
+ this.dashPlayer = null;
1082
+ clearInterval(this.dashLatencyTimer);
1083
+ }
1084
+ }
1085
+
1086
+ /**
1087
+ * destroy the videojs player
1088
+ */
1089
+ destroyVideoJSPlayer() {
1090
+ if (this.videojsPlayer) {
1091
+ this.videojsPlayer.dispose();
1092
+ this.videojsPlayer = null;
1093
+ }
1094
+ }
1095
+
1096
+ /**
1097
+ * Destory the player
1098
+ */
1099
+ destroy() {
1100
+ this.destroyVideoJSPlayer();
1101
+ this.destroyDashPlayer();
1102
+ }
1103
+
1104
+ /**
1105
+ * play the stream with the given tech
1106
+ * @param {string} tech
1107
+ */
1108
+ async playIfExists(tech) {
1109
+ this.currentPlayType = tech;
1110
+ this.destroyVideoJSPlayer();
1111
+ this.destroyDashPlayer();
1112
+ this.setPlayerVisible(false);
1113
+ this.containerElement.innerHTML = this.videoHTMLContent;
1114
+ Logger_1.warn("Try to play the stream " + this.streamId + " with " + this.currentPlayType);
1115
+ switch (this.currentPlayType) {
1116
+ case "hls":
1117
+ //TODO: Test case for hls
1118
+ //1. Play stream with adaptive m3u8 for live and VoD
1119
+ //2. Play stream with m3u8 for live and VoD
1120
+ //3. if files are not available check nextTech is being called
1121
+ return this.checkStreamExistsViaHttp(WebPlayer.STREAMS_FOLDER, this.streamId, WebPlayer.HLS_EXTENSION).then(streamPath => {
1122
+ this.playWithVideoJS(streamPath, WebPlayer.HLS_EXTENSION);
1123
+ Logger_1.warn("incoming stream path: " + streamPath);
1124
+ }).catch(error => {
1125
+ Logger_1.warn("HLS stream resource not available for stream:" + this.streamId + " error is " + error + ". Try next play tech");
1126
+ this.tryNextTech();
1127
+ });
1128
+ case "dash":
1129
+ return this.checkStreamExistsViaHttp(WebPlayer.STREAMS_FOLDER, this.streamId + "/" + this.streamId, WebPlayer.DASH_EXTENSION).then(streamPath => {
1130
+ this.playViaDash(streamPath);
1131
+ }).catch(error => {
1132
+ Logger_1.warn("DASH stream resource not available for stream:" + this.streamId + " error is " + error + ". Try next play tech");
1133
+ this.tryNextTech();
1134
+ });
1135
+ case "webrtc":
1136
+ return this.playWithVideoJS(this.addSecurityParams(this.websocketURL), WebPlayer.WEBRTC_EXTENSION);
1137
+ case "vod":
1138
+ //TODO: Test case for vod
1139
+ //1. Play stream with mp4 for VoD
1140
+ //2. Play stream with webm for VoD
1141
+ //3. Play stream with playOrder type
1142
+
1143
+ var lastIndexOfDot = this.streamId.lastIndexOf(".");
1144
+ var extension;
1145
+ if (lastIndexOfDot != -1) {
1146
+ //if there is a dot in the streamId, it means that this is extension, use it. make the extension empty
1147
+ this.playType[0] = "";
1148
+ extension = this.streamId.substring(lastIndexOfDot + 1);
1149
+ } else {
1150
+ //we need to give extension to playWithVideoJS
1151
+ extension = this.playType[0];
1152
+ }
1153
+ return this.checkStreamExistsViaHttp(WebPlayer.STREAMS_FOLDER, this.streamId, this.playType[0]).then(streamPath => {
1154
+ //we need to give extension to playWithVideoJS
1155
+ this.playWithVideoJS(streamPath, extension);
1156
+ }).catch(error => {
1157
+ Logger_1.warn("VOD stream resource not available for stream:" + this.streamId + " and play type " + this.playType[0] + ". Error is " + error);
1158
+ if (this.playType.length > 1) {
1159
+ Logger_1.warn("Try next play type which is " + this.playType[1] + ".");
1160
+ this.checkStreamExistsViaHttp(WebPlayer.STREAMS_FOLDER, this.streamId, this.playType[1]).then(streamPath => {
1161
+ this.playWithVideoJS(streamPath, this.playType[1]);
1162
+ }).catch(error => {
1163
+ Logger_1.warn("VOD stream resource not available for stream:" + this.streamId + " and play type error is " + error);
1164
+ });
1165
+ }
1166
+ });
1167
+ }
1168
+ }
1169
+
1170
+ /**
1171
+ *
1172
+ * @returns {String} query string for security
1173
+ */
1174
+ getSecurityQueryParams() {
1175
+ var queryString = "";
1176
+ if (this.token != null) {
1177
+ queryString += "&token=" + this.token;
1178
+ }
1179
+ if (this.subscriberId != null) {
1180
+ queryString += "&subscriberId=" + this.subscriberId;
1181
+ }
1182
+ if (this.subscriberCode != null) {
1183
+ queryString += "&subscriberCode=" + this.subscriberCode;
1184
+ }
1185
+ return queryString;
1186
+ }
1187
+
1188
+ /**
1189
+ * play the stream with videojs player or dash player
1190
+ */
1191
+ play() {
1192
+ if (this.streamId.startsWith(WebPlayer.STREAMS_FOLDER)) {
1193
+ //start videojs player because it directly try to play stream from streams folder
1194
+ var lastIndexOfDot = this.streamId.lastIndexOf(".");
1195
+ var extension = this.streamId.substring(lastIndexOfDot + 1);
1196
+ this.playOrder = ["vod"];
1197
+ if (!this.httpBaseURL.endsWith("/")) {
1198
+ this.httpBaseURL += "/";
1199
+ }
1200
+ this.containerElement.innerHTML = this.videoHTMLContent;
1201
+ if (extension == WebPlayer.DASH_EXTENSION) {
1202
+ this.playViaDash(this.httpBaseURL + this.addSecurityParams(this.streamId), extension);
1203
+ } else {
1204
+ this.playWithVideoJS(this.httpBaseURL + this.addSecurityParams(this.streamId), extension);
1205
+ }
1206
+ } else {
1207
+ this.playIfExists(this.playOrder[0]);
1208
+ }
1209
+ }
1210
+
1211
+ /**
1212
+ * mute or unmute the player
1213
+ * @param {boolean} mutestatus true to mute the player
1214
+ */
1215
+ mutePlayer(mutestatus) {
1216
+ this.mute = mutestatus;
1217
+ if (this.videojsPlayer) {
1218
+ this.videojsPlayer.muted(mutestatus);
1219
+ }
1220
+ if (this.dashPlayer) {
1221
+ this.dashPlayer.setMute(mutestatus);
1222
+ }
1223
+ }
1224
+
1225
+ /**
1226
+ *
1227
+ * @returns {boolean} true if player is muted
1228
+ */
1229
+ isMuted() {
1230
+ return this.mute;
1231
+ }
1232
+ addPlayerListener(playerListener) {
1233
+ this.playerListener = playerListener;
1234
+ }
1235
+
1236
+ /**
1237
+ * WebRTC data listener
1238
+ * @param {*} webRTCDataListener
1239
+ */
1240
+ addWebRTCDataListener(webRTCDataListener) {
1241
+ this.webRTCDataListener = webRTCDataListener;
1242
+ }
1243
+
1244
+ /**
1245
+ *
1246
+ * @param {*} data
1247
+ */
1248
+ sendWebRTCData(data) {
1249
+ try {
1250
+ if (this.videojsPlayer && this.currentPlayType == "webrtc") {
1251
+ this.videojsPlayer.sendDataViaWebRTC(data);
1252
+ return true;
1253
+ } else {
1254
+ Logger_1.warn("Player is not ready or playType is not WebRTC");
1255
+ }
1256
+ } catch (error) {
1257
+ // Handle the error here
1258
+ Logger_1.error("An error occurred while sending WebRTC data: ", error);
1259
+ }
1260
+ return false;
1261
+ }
1262
+ }
1263
+
1264
+ exports.STATIC_VIDEO_HTML = STATIC_VIDEO_HTML;
1265
+ exports.WebPlayer = WebPlayer;