@stormstreaming/stormstreamer
Version:
A JavaScript library containing core web video streamer functionality for embedding live-video streams on a website. Part of StormStreaming Suite.
1,250 lines (1,216 loc) • 139 kB
JavaScript
/*
* StormStreaming JavaScript Streamer
* Copyright © 2021-2024 Web-Anatomy s.c. All rights reserved.
* contact@stormstreaming.com
* https://stormstreaming.com
*
* Version: 0.9.0-beta.0
* Version: 11/28/2024, 9:22:54 AM
*
* LEGAL NOTICE:
* This software is subject to the terms and conditions defined in
* separate license conditions ('LICENSE.txt')
*
*/define(['exports'], (function (exports) { 'use strict';
class StormServerItem {
constructor(host, application, port = 443, isSSL = true) {
this.host = host;
this.application = application;
this.port = port;
this.isSSL = isSSL;
this.hasFaild = false;
}
getHost() {
return this.host;
}
getApplication() {
return this.application;
}
getPort() {
return this.port;
}
getIfSSL() {
return this.isSSL;
}
getIfFaild() {
return this.hasFaild;
}
setAsFaild(value) {
this.hasFaild = value;
}
getData() {
return {
serverURL: this.getHost(),
application: this.getHost(),
serverPort: this.getPort(),
isSSL: this.getIfSSL()
};
}
toString() {
return "host: " + this.host + " | application: " + this.application + " | port: " + this.port + " | isSSL: " + this.isSSL;
}
}
class StreamData {
constructor(streamConfig) {
this._serverList = new Array();
this._sourceList = new Array();
this._streamKey = null;
this.parse(streamConfig);
}
parse(streamConfig) {
var _a, _b, _c;
this._streamConfig = streamConfig;
if (!this._streamConfig) throw new Error("Stream configuration is missing. Please check stream config!");
if (this._streamConfig.serverList !== undefined && this._streamConfig.serverList !== null) {
if (this._streamConfig.serverList.length !== 0) {
for (let i = 0; i < this._streamConfig.serverList.length; i++) {
let host;
let application;
if (this._streamConfig.serverList[i].host != null) host = this._streamConfig.serverList[i].host;else throw new Error("Error while parsing server object (\"host\" field is missing). Please check player config!");
if (this._streamConfig.serverList[i].application != null) application = this._streamConfig.serverList[i].application;else throw new Error("Error while parsing server object (\"application\" field is missing). Please check player config!");
const port = (_a = this._streamConfig.serverList[i].port) !== null && _a !== void 0 ? _a : StreamData.DEFAULT_CONNECTION_PORT;
const isSSL = (_b = this._streamConfig.serverList[i].ssl) !== null && _b !== void 0 ? _b : StreamData.IS_SSL_BY_DEFAULT;
this._serverList.push(new StormServerItem(host, application, port, isSSL));
}
} else throw new Error("StormLibrary: Server list configuration is empty. Please check the config!");
} else throw new Error("StormLibrary: Server list configuration is missing. Please check the config!");
this._streamKey = (_c = this._streamConfig.streamKey) !== null && _c !== void 0 ? _c : this._streamKey;
}
getServerList() {
return this._serverList;
}
getSourceList() {
return this._sourceList;
}
get streamKey() {
return this._streamKey;
}
set streamKey(newValue) {
this._streamKey = newValue;
}
set serverList(serverList) {
this._serverList = serverList;
}
set sourceList(sourceList) {
this._sourceList = sourceList;
}
clearSourceList() {
this._sourceList = new Array();
}
clearServerList() {
this._serverList = new Array();
}
print(logger, force = false) {
if (StreamData.PRINT_ON_STARTUP || force) {
logger.info(this, "Server List:");
for (let i = 0; i < this._serverList.length; i++) {
logger.info(this, "=> [" + i + "] " + this._serverList[i].toString());
}
logger.info(this, "StreamKey: " + this._streamKey);
}
}
}
StreamData.PRINT_ON_STARTUP = true;
StreamData.DEFAULT_CONNECTION_PORT = 443;
StreamData.IS_SSL_BY_DEFAULT = true;
var ScalingType;
(function (ScalingType) {
ScalingType["FILL"] = "fill";
ScalingType["LETTER_BOX"] = "letterbox";
ScalingType["CROP"] = "crop";
ScalingType["ORIGINAL"] = "original";
})(ScalingType || (ScalingType = {}));
var SizeCalculationType;
(function (SizeCalculationType) {
SizeCalculationType["CLIENT_DIMENSIONS"] = "clientDimensions";
SizeCalculationType["BOUNDING_BOX"] = "boundingBox";
SizeCalculationType["FULL_BOX"] = "fullBox";
})(SizeCalculationType || (SizeCalculationType = {}));
class VideoData {
constructor(videoConfig) {
this._scalingMode = ScalingType.LETTER_BOX;
this._aspectRatio = "none";
this._videoWidthValue = 100;
this._isVideoWidthInPixels = false;
this._wasVideoWidthProvided = false;
this._videoHeightValue = 100;
this._isVideoHeightInPixels = false;
this._wasVideoHeightProvided = false;
this._resizeDebounce = 250;
this._parentSizeCalculationMethod = SizeCalculationType.CLIENT_DIMENSIONS;
this.parse(videoConfig);
}
parse(config) {
var _a, _b;
this.videoConfig = config;
if (this.videoConfig != null) {
if (this.videoConfig.aspectRatio != null) {
const aspectRatioRegexString = '^[0-9]*\\.?[0-9]+:[0-9]*\\.?[0-9]+$';
const aspectRatioRegex = new RegExp(aspectRatioRegexString);
let tempAspectRatio = this.videoConfig.aspectRatio;
if (aspectRatioRegex.test(tempAspectRatio)) {
this._aspectRatio = tempAspectRatio;
} else throw new Error("Parameter \"aspectRatio\" - must match \"number:number\" pattern ");
this._aspectRatio = this.videoConfig.aspectRatio;
}
if (this.videoConfig.scalingMode != null) {
let newScalingMode = this.videoConfig.scalingMode;
switch (newScalingMode.toLowerCase()) {
case "fill":
this._scalingMode = ScalingType.FILL;
break;
case "letterbox":
this._scalingMode = ScalingType.LETTER_BOX;
break;
case "crop":
this._scalingMode = ScalingType.CROP;
break;
case "original":
this._scalingMode = ScalingType.ORIGINAL;
break;
default:
throw new Error("Unknown video scaling mode. Please check player config!");
}
}
if (this.videoConfig.width !== undefined) {
if (this.videoConfig.width !== null) {
if (typeof this.videoConfig.width === "number") {
this._videoWidthValue = this.videoConfig.width;
this._isVideoWidthInPixels = true;
} else if (typeof this.videoConfig.width === "string") {
if (this.videoConfig.width.toLowerCase().endsWith('px')) {
this._videoWidthValue = parseInt(this.videoConfig.width);
this._isVideoWidthInPixels = true;
} else if (this.videoConfig.width.toLowerCase().endsWith('%')) {
this._videoWidthValue = parseInt(this.videoConfig.width);
this._isVideoWidthInPixels = false;
}
} else throw new Error("Unknown type for parameter \"width\" - it must be a number or a string! ");
this._wasVideoWidthProvided = true;
} else throw new Error("Parameter \"width\" cannot be empty");
}
if (this.videoConfig.height !== undefined) {
if (this.videoConfig.height !== null) {
if (typeof this.videoConfig.height === "number") {
this._videoHeightValue = this.videoConfig.height;
this._isVideoHeightInPixels = true;
} else if (typeof this.videoConfig.height === "string") {
if (this.videoConfig.height.toLowerCase().endsWith('px')) {
this._videoHeightValue = parseInt(this.videoConfig.height);
this._isVideoHeightInPixels = true;
} else if (this.videoConfig.height.toLowerCase().endsWith('%')) {
this._videoHeightValue = parseInt(this.videoConfig.height);
this._isVideoHeightInPixels = false;
}
} else throw new Error("Unknown type for parameter \"height\" - it must be a number or a string!");
this._wasVideoHeightProvided = true;
} else throw new Error("Parameter \"height\" cannot be empty");
}
if (this.videoConfig.sizeCalculationMethod !== undefined) {
if (this.videoConfig.sizeCalculationMethod !== null) {
switch (this.videoConfig.sizeCalculationMethod) {
case "clientDimensions":
this._parentSizeCalculationMethod = SizeCalculationType.CLIENT_DIMENSIONS;
break;
case "boundingBox":
this._parentSizeCalculationMethod = SizeCalculationType.BOUNDING_BOX;
break;
case "fullBox":
this._parentSizeCalculationMethod = SizeCalculationType.FULL_BOX;
break;
}
}
}
this._containerID = (_a = this.videoConfig.containerID) !== null && _a !== void 0 ? _a : null;
this._resizeDebounce = (_b = this.videoConfig.resizeDebounce) !== null && _b !== void 0 ? _b : this._resizeDebounce;
} else throw new Error("Missing video configuration. Please check player config!");
}
get scalingMode() {
return this._scalingMode;
}
get containerID() {
return this._containerID;
}
get videoWidthValue() {
return this._videoWidthValue;
}
get videoWidthInPixels() {
return this._isVideoWidthInPixels;
}
get videoWidthProvided() {
return this._wasVideoWidthProvided;
}
get videoHeightValue() {
return this._videoHeightValue;
}
get videoHeightInPixels() {
return this._isVideoHeightInPixels;
}
get videoHeightProvided() {
return this._wasVideoHeightProvided;
}
get aspectRatio() {
return this._aspectRatio;
}
get resizeDebounce() {
return this._resizeDebounce;
}
set resizeDebounce(newValue) {
this._resizeDebounce = newValue;
}
set videoWidthValue(newWidth) {
this._videoWidthValue = newWidth;
}
set videoWidthInPixels(value) {
this._isVideoWidthInPixels = value;
}
set videoHeightValue(newHeight) {
this._videoHeightValue = newHeight;
}
set videoHeightInPixels(value) {
this._isVideoHeightInPixels = value;
}
set containerID(newContainerID) {
this._containerID = newContainerID;
}
set scalingMode(newScalingMode) {
switch (newScalingMode.toLowerCase()) {
case "fill":
this._scalingMode = ScalingType.FILL;
break;
case "letterbox":
this._scalingMode = ScalingType.LETTER_BOX;
break;
case "crop":
this._scalingMode = ScalingType.CROP;
break;
case "original":
this._scalingMode = ScalingType.ORIGINAL;
break;
default:
throw new Error("Unknown video scaling mode. Please check player config!");
}
}
get parentSizeCalculationMethod() {
return this._parentSizeCalculationMethod;
}
print(logger) {
let scalingMode = "";
switch (this._scalingMode) {
case ScalingType.FILL:
scalingMode = "fill";
break;
case ScalingType.LETTER_BOX:
scalingMode = "letterbox";
break;
case ScalingType.CROP:
scalingMode = "crop";
break;
case ScalingType.ORIGINAL:
scalingMode = "original";
break;
}
logger.info(this, "VideoConfig :: containerID: " + this._containerID);
logger.info(this, "VideoConfig :: scalingMode: " + scalingMode);
logger.info(this, "VideoConfig :: width: " + this._videoWidthValue + (this._isVideoWidthInPixels ? "px" : "%") + (this._wasVideoWidthProvided ? " (provided)" : " (default)"));
logger.info(this, "VideoConfig :: height: " + this._videoHeightValue + (this._isVideoHeightInPixels ? "px" : "%") + (this._wasVideoHeightProvided ? " (provided)" : " (default)"));
logger.info(this, "VideoConfig :: aspectRatio: " + this._aspectRatio);
}
}
var LogType;
(function (LogType) {
LogType[LogType["TRACE"] = 0] = "TRACE";
LogType[LogType["INFO"] = 1] = "INFO";
LogType[LogType["SUCCESS"] = 2] = "SUCCESS";
LogType[LogType["WARNING"] = 3] = "WARNING";
LogType[LogType["ERROR"] = 4] = "ERROR";
})(LogType || (LogType = {}));
class DebugData {
constructor(debugConfig) {
this._consoleLogEnabled = false;
this._enabledConsoleTypes = [LogType.INFO, LogType.ERROR, LogType.SUCCESS, LogType.TRACE, LogType.WARNING];
this._consoleMonoColor = false;
this._containerLogEnabled = false;
this._enabledContainerTypes = [LogType.INFO, LogType.ERROR, LogType.SUCCESS, LogType.TRACE, LogType.WARNING];
this._containerLogMonoColor = false;
this.parse(debugConfig);
}
parse(debugConfig) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
this._debugConfig = debugConfig;
if (this._debugConfig) {
this._consoleLogEnabled = (_c = (_b = (_a = this._debugConfig) === null || _a === void 0 ? void 0 : _a.console) === null || _b === void 0 ? void 0 : _b.enabled) !== null && _c !== void 0 ? _c : this._consoleLogEnabled;
this._consoleMonoColor = (_f = (_e = (_d = this._debugConfig) === null || _d === void 0 ? void 0 : _d.console) === null || _e === void 0 ? void 0 : _e.monoColor) !== null && _f !== void 0 ? _f : this._consoleMonoColor;
this._enabledConsoleTypes = (_j = this.parseLogTypes((_h = (_g = this._debugConfig) === null || _g === void 0 ? void 0 : _g.console) === null || _h === void 0 ? void 0 : _h.logTypes)) !== null && _j !== void 0 ? _j : this._enabledConsoleTypes;
this._containerLogEnabled = (_m = (_l = (_k = this._debugConfig) === null || _k === void 0 ? void 0 : _k.container) === null || _l === void 0 ? void 0 : _l.enabled) !== null && _m !== void 0 ? _m : this._containerLogEnabled;
this._containerLogMonoColor = (_q = (_p = (_o = this._debugConfig) === null || _o === void 0 ? void 0 : _o.container) === null || _p === void 0 ? void 0 : _p.monoColor) !== null && _q !== void 0 ? _q : this._containerLogMonoColor;
this._enabledContainerTypes = (_t = this.parseLogTypes((_s = (_r = this._debugConfig) === null || _r === void 0 ? void 0 : _r.container) === null || _s === void 0 ? void 0 : _s.logTypes)) !== null && _t !== void 0 ? _t : this._enabledContainerTypes;
this._containerID = (_w = (_v = (_u = this._debugConfig) === null || _u === void 0 ? void 0 : _u.container) === null || _v === void 0 ? void 0 : _v.containerID) !== null && _w !== void 0 ? _w : this._containerID;
}
}
parseLogTypes(logTypes) {
return logTypes === null || logTypes === void 0 ? void 0 : logTypes.map(type => {
switch (type.toLowerCase()) {
case 'info':
return LogType.INFO;
case 'error':
return LogType.ERROR;
case 'warning':
return LogType.WARNING;
case 'success':
return LogType.SUCCESS;
case 'trace':
return LogType.TRACE;
default:
throw new Error(`Unsupported log type: ${type}`);
}
});
}
get consoleLogEnabled() {
return this._consoleLogEnabled;
}
set consoleLogEnabled(newValue) {
this._consoleLogEnabled = newValue;
}
get enabledConsoleTypes() {
return this._enabledConsoleTypes;
}
set enabledConsoleTypes(newValue) {
this._enabledConsoleTypes = new Array();
for (let i = 0; i < newValue.length; i++) {
switch (newValue[i].toLowerCase()) {
case "info":
this._enabledConsoleTypes.push(LogType.INFO);
break;
case "error":
this._enabledConsoleTypes.push(LogType.ERROR);
break;
case "warning":
this._enabledConsoleTypes.push(LogType.WARNING);
break;
case "success":
this._enabledConsoleTypes.push(LogType.SUCCESS);
break;
case "trace":
this._enabledConsoleTypes.push(LogType.TRACE);
break;
}
}
}
get containerLogEnabled() {
return this._containerLogEnabled;
}
set containerLogEnabled(newValue) {
this._consoleLogEnabled = newValue;
}
get consoleLogMonoColor() {
return this._consoleMonoColor;
}
set consoleLogMonoColor(newValue) {
this._consoleMonoColor = newValue;
}
get enabledContainerTypes() {
return this._enabledContainerTypes;
}
set enabledContainerTypes(newValue) {
this._enabledContainerTypes = new Array();
for (let i = 0; i < newValue.length; i++) {
switch (newValue[i].toLowerCase()) {
case "info":
this._enabledContainerTypes.push(LogType.INFO);
break;
case "error":
this._enabledContainerTypes.push(LogType.ERROR);
break;
case "warning":
this._enabledContainerTypes.push(LogType.WARNING);
break;
case "success":
this._enabledContainerTypes.push(LogType.SUCCESS);
break;
case "trace":
this._enabledContainerTypes.push(LogType.TRACE);
break;
}
}
}
get containerID() {
return this._containerID;
}
set containerID(object) {
this._containerID = object;
}
get containerLogMonoColor() {
return this._containerLogMonoColor;
}
set containerLogMonoColor(newValue) {
this._containerLogMonoColor = newValue;
}
print(logger, force = false) {
if (DebugData.PRINT_ON_STARTUP || force) {
let consoleLogTypes = "";
for (let i = 0; i < this._enabledConsoleTypes.length; i++) {
switch (this._enabledConsoleTypes[i]) {
case LogType.TRACE:
consoleLogTypes += "TRACE, ";
break;
case LogType.SUCCESS:
consoleLogTypes += "SUCCESS, ";
break;
case LogType.WARNING:
consoleLogTypes += "WARNING, ";
break;
case LogType.INFO:
consoleLogTypes += "INFO, ";
break;
case LogType.ERROR:
consoleLogTypes += "ERROR, ";
break;
}
}
logger.info(this, "Console:: enabled: " + this._consoleLogEnabled);
logger.info(this, "Console:: logTypes: " + consoleLogTypes);
logger.info(this, "Console:: monoColor: " + this._consoleMonoColor);
let containerLogTypes = "";
for (let i = 0; i < this._enabledContainerTypes.length; i++) {
switch (this._enabledContainerTypes[i]) {
case LogType.TRACE:
containerLogTypes += "TRACE, ";
break;
case LogType.SUCCESS:
containerLogTypes += "SUCCESS, ";
break;
case LogType.WARNING:
containerLogTypes += "WARNING, ";
break;
case LogType.INFO:
containerLogTypes += "INFO, ";
break;
case LogType.ERROR:
containerLogTypes += "ERROR, ";
break;
}
}
logger.info(this, "Container:: enabled: " + this._containerLogEnabled);
logger.info(this, "Container:: logTypes: " + containerLogTypes);
logger.info(this, "Container:: containerID: " + this._containerID);
logger.info(this, "Container:: monoColor: " + this._consoleMonoColor);
}
}
}
DebugData.PRINT_ON_STARTUP = true;
class AudioData {
constructor(volumeConfig) {
this._startVolume = 100;
this._isMuted = false;
this.parse(volumeConfig);
}
parse(config) {
var _a, _b, _c, _d;
this._audioConfig = config;
if (this._audioConfig) {
this._startVolume = (_b = (_a = this._audioConfig) === null || _a === void 0 ? void 0 : _a.startVolume) !== null && _b !== void 0 ? _b : this._startVolume;
this._isMuted = (_d = (_c = this._audioConfig) === null || _c === void 0 ? void 0 : _c.muted) !== null && _d !== void 0 ? _d : this._isMuted;
}
}
get startVolume() {
return this._startVolume;
}
set startVolume(newValue) {
this._startVolume = newValue;
}
get muted() {
return this._isMuted;
}
set muted(newValue) {
this._isMuted = newValue;
}
print(logger, force = false) {
if (AudioData.PRINT_ON_STARTUP || force) logger.info(this, "Audio :: startVolume: " + this._startVolume + " | isMuted: " + this._isMuted);
}
}
AudioData.PRINT_ON_STARTUP = true;
class StorageData {
constructor(storageConfig) {
this._enabled = true;
this._prefix = "storm";
this.parse(storageConfig);
}
parse(config) {
var _a, _b, _c, _d;
this._storageConfig = config;
this._enabled = (_b = (_a = this._storageConfig) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : this._enabled;
this._prefix = (_d = (_c = this._storageConfig) === null || _c === void 0 ? void 0 : _c.prefix) !== null && _d !== void 0 ? _d : this._prefix;
}
get enabled() {
return this._enabled;
}
set enabled(newValue) {
this._enabled = newValue;
}
get prefix() {
return this._prefix;
}
set prefix(newValue) {
this._prefix = newValue;
}
print(logger, force = false) {
if (StorageData.PRINT_ON_STARTUP || force) logger.info(this, "Storage :: startVolume: " + this._enabled + " | prefix: " + this._prefix);
}
}
StorageData.PRINT_ON_STARTUP = true;
class SettingsData {
constructor(config) {
this._restartOnError = true;
this._reconnectTime = 1;
this._autoStart = false;
this._autoConnect = true;
this.startOnDOMReady = false;
this.iOSOnDomReadyFix = true;
this._restartOnFocus = true;
this.parse(config);
}
parse(config) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
this._settingsConfig = config;
this._autoConnect = (_a = this._settingsConfig.autoConnect) !== null && _a !== void 0 ? _a : this._autoConnect;
this._autoStart = (_b = this._settingsConfig.autoStart) !== null && _b !== void 0 ? _b : this._autoStart;
this._restartOnFocus = (_c = this._settingsConfig.restartOnFocus) !== null && _c !== void 0 ? _c : this._restartOnFocus;
this._restartOnError = (_d = this._settingsConfig.restartOnError) !== null && _d !== void 0 ? _d : this._restartOnError;
this._reconnectTime = (_e = this._settingsConfig.reconnectTime) !== null && _e !== void 0 ? _e : this._reconnectTime;
this._videoData = new VideoData((_f = this._settingsConfig.video) !== null && _f !== void 0 ? _f : null);
this._audioData = new AudioData((_g = this._settingsConfig.audio) !== null && _g !== void 0 ? _g : null);
this._storageData = new StorageData((_h = this._settingsConfig.storage) !== null && _h !== void 0 ? _h : null);
this._debugData = new DebugData((_j = this._settingsConfig.debug) !== null && _j !== void 0 ? _j : null);
}
getAudioData() {
return this._audioData;
}
getVideoData() {
return this._videoData;
}
getStorageData() {
return this._storageData;
}
getIfRestartOnError() {
return this._restartOnError;
}
getReconnectTime() {
return this._reconnectTime;
}
get autoStart() {
return this._autoStart;
}
set autoStart(newValue) {
this._autoStart = newValue;
}
get autoConnect() {
return this._autoConnect;
}
get restartOnFocus() {
return this._restartOnFocus;
}
getDebugData() {
return this._debugData;
}
getIfStartOnDOMReadyEnabled() {
return this.startOnDOMReady;
}
getIfIOSOnDomStartFixEnabled() {
return this.iOSOnDomReadyFix;
}
print(logger, force = false) {
if (SettingsData.PRINT_ON_STARTUP || force) {
let enabledProtocols = "";
logger.info(this, "SettingsConfig :: autoConnect: " + this._autoConnect);
logger.info(this, "SettingsConfig :: autoStart: " + this._autoStart);
logger.info(this, "SettingsConfig :: restartOnError: " + this._restartOnError);
logger.info(this, "SettingsConfig :: reconnectTime: " + this._reconnectTime);
logger.info(this, "SettingsConfig :: enabledProtocols: " + enabledProtocols);
this._videoData.print(logger);
this._audioData.print(logger);
this._debugData.print(logger);
this._debugData.print(logger);
}
}
}
SettingsData.PRINT_ON_STARTUP = true;
class ConfigManager {
constructor(config) {
this.PRINT_ON_STARTUP = true;
this.demoMode = false;
this.parse(config);
}
parse(config) {
var _a, _b;
this.configTemplate = config;
if (this.configTemplate.stream == null) throw new Error("No stream field was provided. Please check your player config!");
this.streamData = new StreamData(this.configTemplate.stream);
this.settingsData = new SettingsData((_a = this.configTemplate.settings) !== null && _a !== void 0 ? _a : null);
this.demoMode = (_b = this.configTemplate.demoMode) !== null && _b !== void 0 ? _b : false;
}
getStreamData() {
return this.streamData;
}
getSettingsData() {
return this.settingsData;
}
getIfDemoMode() {
return this.demoMode;
}
print(logger, force = false) {
if (this.PRINT_ON_STARTUP || force) {
this.streamData.print(logger);
this.settingsData.print(logger);
}
}
}
class EventDispatcher {
constructor() {
this._isRemoved = false;
this._listeners = {};
}
addEventListener(eventName, listener, removable = true) {
if (!this._listeners[eventName]) this._listeners[eventName] = [];
let elementFound = false;
if (this._listeners[eventName] != undefined) {
if (this._listeners[eventName].length > 0) {
for (let i = 0; i < this._listeners[eventName].length; i++) {
let element = this._listeners[eventName][i];
if (element[1] == listener) {
elementFound = true;
break;
}
}
}
}
this._logger.success(this, "Registering a new event: " + eventName);
if (!elementFound) {
this._listeners[eventName].push([eventName, listener, removable]);
return true;
} else return false;
}
removeEventListener(eventName, listener) {
let elementFound = false;
if (this._listeners[eventName] != undefined) {
if (this._listeners[eventName].length > 0) {
for (let i = 0; i < this._listeners[eventName].length; i++) {
let element = this._listeners[eventName][i];
if (listener) {
if (element[1] == listener) {
if (element[2] == true) {
elementFound = true;
this._listeners[eventName].splice(i, 1);
break;
} else break;
}
} else {
elementFound = true;
if (element[2] == true) {
this._listeners[eventName].splice(i, 1);
}
}
}
}
}
this._logger.success(this, "Removing listener: " + eventName);
return elementFound;
}
removeAllEventListeners() {
this._logger.success(this, "Removing all listeners!");
for (const eventName in this._listeners) {
const typedEventName = eventName;
const branch = this._listeners[typedEventName];
if (branch && branch.length > 0) {
for (let i = branch.length - 1; i >= 0; i--) {
const element = branch[i];
if (element[2] === true) {
branch.splice(i, 1);
}
}
}
}
}
dispatchEvent(eventName, event) {
if (this._isRemoved) return;
if (this._listeners[eventName] != undefined) {
if (this._listeners[eventName].length > 0) {
for (let i = 0; i < this._listeners[eventName].length; i++) {
let element = this._listeners[eventName][i];
element[1].call(this, event);
}
}
}
}
}
class NumberUtilities {
static addLeadingZero(number) {
if (number < 10) {
return "0" + number;
} else {
return String(number);
}
}
static isNear(currentBuffer, target, targetMargin) {
return Math.abs(currentBuffer - target) <= targetMargin;
}
static generateUniqueString(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
}
NumberUtilities.parseValue = value => {
if (typeof value === 'string') {
const isPixels = value.toLowerCase().endsWith('px');
const numericValue = parseInt(value, 10);
return {
value: numericValue,
isPixels: isPixels
};
} else {
return {
value: value,
isPixels: true
};
}
};
class Logger {
constructor(config, stormStreamer) {
this.colorOrder = ["red", "green", "blue", "orange", "black", "violet"];
this._logMemory = [];
this._streamerInstanceID = -1;
this._debugConfig = config;
this._stormStreamer = stormStreamer;
this._streamerInstanceID = this._stormStreamer.getStreamerID();
let colorID = this.colorOrder.length < stormStreamer.getStreamerID() ? this.colorOrder.length - 1 : stormStreamer.getStreamerID();
this._monoColor = this.colorOrder[colorID];
}
info(objectName, message) {
let output = this.logData(objectName, message);
if (this._debugConfig.consoleLogEnabled) {
if (this._debugConfig.enabledConsoleTypes.indexOf(LogType.INFO) >= 0) {
let consoleColor = this._debugConfig.consoleLogMonoColor ? this._monoColor : Logger.INFO_COLOR;
console.log('%c ' + output, 'color: ' + consoleColor);
}
}
if (this._debugConfig.containerLogEnabled) {
if (this._debugConfig.enabledContainerTypes.indexOf(LogType.INFO) >= 0) {
let containerColor = this._debugConfig.containerLogMonoColor ? this._monoColor : Logger.INFO_COLOR;
this.writeToContainer(output, containerColor);
}
}
}
warning(objectName, message) {
let output = this.logData(objectName, message);
if (this._debugConfig.consoleLogEnabled) {
if (this._debugConfig.enabledConsoleTypes.indexOf(LogType.WARNING) >= 0) {
let consoleColor = this._debugConfig.consoleLogMonoColor ? this._monoColor : Logger.WARNING_COLOR;
console.log('%c ' + output, 'color: ' + consoleColor);
}
}
if (this._debugConfig.containerLogEnabled) {
if (this._debugConfig.enabledContainerTypes.indexOf(LogType.WARNING) >= 0) {
let containerColor = this._debugConfig.containerLogMonoColor ? this._monoColor : Logger.WARNING_COLOR;
this.writeToContainer(output, containerColor);
}
}
}
error(objectName, message) {
let output = this.logData(objectName, message);
if (this._debugConfig.consoleLogEnabled) {
if (this._debugConfig.enabledConsoleTypes.indexOf(LogType.ERROR) >= 0) {
let consoleColor = this._debugConfig.consoleLogMonoColor ? this._monoColor : Logger.ERROR_COLOR;
console.log('%c ' + output, 'color: ' + consoleColor);
}
}
if (this._debugConfig.containerLogEnabled) {
if (this._debugConfig.enabledContainerTypes.indexOf(LogType.ERROR) >= 0) {
let containerColor = this._debugConfig.containerLogMonoColor ? this._monoColor : Logger.ERROR_COLOR;
this.writeToContainer(output, containerColor);
}
}
}
success(objectName, message) {
let output = this.logData(objectName, message);
if (this._debugConfig.consoleLogEnabled) {
if (this._debugConfig.enabledConsoleTypes.indexOf(LogType.SUCCESS) >= 0) {
let consoleColor = this._debugConfig.consoleLogMonoColor ? this._monoColor : Logger.SUCCESS_COLOR;
console.log('%c ' + output, 'color: ' + consoleColor);
}
}
if (this._debugConfig.containerLogEnabled) {
if (this._debugConfig.enabledContainerTypes.indexOf(LogType.SUCCESS) >= 0) {
let containerColor = this._debugConfig.containerLogMonoColor ? this._monoColor : Logger.SUCCESS_COLOR;
this.writeToContainer(output, containerColor);
}
}
}
trace(objectName, message) {
let output = this.logData(objectName, message);
if (this._debugConfig.consoleLogEnabled) {
if (this._debugConfig.enabledConsoleTypes.indexOf(LogType.TRACE) >= 0) {
let consoleColor = this._debugConfig.consoleLogMonoColor ? this._monoColor : Logger.TRACE_COLOR;
console.log('%c ' + output, 'color: ' + consoleColor);
}
}
if (this._debugConfig.containerLogEnabled) {
if (this._debugConfig.enabledContainerTypes.indexOf(LogType.TRACE) >= 0) {
let containerColor = this._debugConfig.containerLogMonoColor ? this._monoColor : Logger.TRACE_COLOR;
this.writeToContainer(output, containerColor);
}
}
}
logData(_objectName, message) {
let date = new Date();
let hour = NumberUtilities.addLeadingZero(date.getHours());
let minutes = NumberUtilities.addLeadingZero(date.getMinutes());
let seconds = NumberUtilities.addLeadingZero(date.getSeconds());
let label = String(this._streamerInstanceID);
if (this._streamerInstanceID >= 0) label += "|" + this._streamerInstanceID;
let finalString = "[Storm-ID:" + label + "] [" + hour + ":" + minutes + ":" + seconds + "] :: " + message;
this._logMemory.push(finalString);
return finalString;
}
writeToContainer(message, color) {
let containerName = this._debugConfig.containerID;
if (containerName) {
let container = document.getElementById(containerName);
let log = document.createElement('span');
log.innerText = message;
log.style.color = color;
container.appendChild(log);
}
}
setPlayerID(playerID) {
this._streamerInstanceID = playerID;
}
getAllLogs() {
return this._logMemory;
}
}
Logger.INFO_COLOR = "blue";
Logger.WARNING_COLOR = "orange";
Logger.ERROR_COLOR = "red";
Logger.SUCCESS_COLOR = "green";
Logger.TRACE_COLOR = "black";
class ClientUser {
constructor() {
this.bandwidthCapabilities = 0;
}
setBandwidthCapabilities(newCapabilities) {
this.bandwidthCapabilities = newCapabilities;
}
getBandwidthCapabilities() {
return this.bandwidthCapabilities;
}
}
class UserCapabilities {
static hasWebSocketsSupport() {
return window.WebSocket != null;
}
static isMobile() {
const mobileCheckString = "Mobile|mini|Fennec|Android|iP(ad|od|hone)";
const mobileCheckRegExp = new RegExp(mobileCheckString);
return mobileCheckRegExp.test(navigator.userAgent);
}
static isCookieEnabled() {
let cookieEnabled = navigator.cookieEnabled ? true : false;
if (typeof navigator.cookieEnabled == 'undefined' && !cookieEnabled) {
document.cookie = 'testcookie';
cookieEnabled = document.cookie.indexOf('testcookie') != -1 ? true : false;
}
return cookieEnabled;
}
static getOSVersion() {
let osVersion = "Unknown version";
let os = UserCapabilities.getOS();
if (os != null) {
const windowsCheckString = "Windows";
const windowsCheckRegExp = new RegExp(windowsCheckString);
if (windowsCheckRegExp.test(os)) {
const windowsExecString = "Windows (.*)";
const windowsExecRegExp = new RegExp(windowsExecString);
osVersion = windowsExecRegExp.exec(os)[1] != null ? windowsExecRegExp.exec(os)[1] : osVersion;
os = 'Windows';
}
switch (os) {
case 'Mac OS':
case 'Mac OS X':
case 'Android':
const versionExecString = "(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([\\.\\_\\d]+)";
const versionExecRegExp = new RegExp(versionExecString);
osVersion = versionExecRegExp.exec(navigator.userAgent)[1];
break;
case 'iOS':
const iOSExecString = "OS (\\d+)_(\\d+)_?(\\d+)?";
const iOSExecRegExp = new RegExp(iOSExecString);
osVersion = iOSExecRegExp.exec(navigator.userAgent);
osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0);
break;
}
}
return osVersion;
}
static getBrowserName() {
return UserCapabilities.getFullBrowser().name;
}
static getBrowserVersion() {
return UserCapabilities.getFullBrowser().version;
}
static getFullBrowser() {
let nAgt = navigator.userAgent;
let browser = navigator.appName;
let version = '' + parseFloat(navigator.appVersion);
let majorVersion = parseInt(navigator.appVersion, 10);
let nameOffset, verOffset, ix;
if ((verOffset = nAgt.indexOf('Opera')) != -1) {
browser = 'Opera';
version = nAgt.substring(verOffset + 6);
if ((verOffset = nAgt.indexOf('Version')) != -1) {
version = nAgt.substring(verOffset + 8);
}
} else if ((verOffset = nAgt.indexOf('MSIE')) != -1) {
browser = 'Microsoft Internet Explorer';
version = nAgt.substring(verOffset + 5);
} else if (browser == 'Netscape' && nAgt.indexOf('Trident/') != -1) {
browser = 'Microsoft Internet Explorer';
version = nAgt.substring(verOffset + 5);
if ((verOffset = nAgt.indexOf('rv:')) != -1) {
version = nAgt.substring(verOffset + 3);
}
} else if ((verOffset = nAgt.indexOf('Chrome')) != -1) {
browser = 'Chrome';
if (nAgt.indexOf("FBAV") > -1 || nAgt.indexOf("FBAN") > -1) browser = 'Facebook';
if (nAgt.indexOf("OPR") > -1) browser = 'Opera';
if (nAgt.indexOf("SamsungBrowser") > -1) browser = 'Samsung';
version = nAgt.substring(verOffset + 7);
} else if ((verOffset = nAgt.indexOf('Safari')) != -1) {
browser = 'Safari';
version = nAgt.substring(verOffset + 7);
if ((verOffset = nAgt.indexOf('Version')) != -1) {
version = nAgt.substring(verOffset + 8);
}
if (nAgt.indexOf('CriOS') != -1) {
browser = 'Chrome';
}
if (nAgt.indexOf('FxiOS') != -1) {
browser = "Firefox";
}
} else if ((verOffset = nAgt.indexOf('Firefox')) != -1) {
browser = 'Firefox';
version = nAgt.substring(verOffset + 8);
} else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
browser = nAgt.substring(nameOffset, verOffset);
version = nAgt.substring(verOffset + 1);
if (browser.toLowerCase() == browser.toUpperCase()) {
browser = navigator.appName;
}
}
if ((ix = version.indexOf(';')) != -1) version = version.substring(0, ix);
if ((ix = version.indexOf(' ')) != -1) version = version.substring(0, ix);
if ((ix = version.indexOf(')')) != -1) version = version.substring(0, ix);
majorVersion = parseInt('' + version, 10);
if (isNaN(majorVersion)) {
version = '' + parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion, 10);
}
return {
"name": browser,
"fullVersion": version,
"version": majorVersion
};
}
static getOS() {
let os = "Unknown OS";
let oscodes = [{
"os": 'Windows 10',
"code": "(Windows 10.0|Windows NT 10.0)"
}, {
"os": 'Windows 8.1',
"code": "(Windows 8.1|Windows NT 6.3)"
}, {
"os": 'Windows 8',
"code": "(Windows 8|Windows NT 6.2)"
}, {
"os": 'Windows 7',
"code": "(Windows 7|Windows NT 6.1)"
}, {
"os": 'Windows Vista',
"code": "Windows NT 6.0"
}, {
"os": 'Windows Server 2003',
"code": "Windows NT 5.2"
}, {
"os": 'Windows XP',
"code": "(Windows NT 5.1|Windows XP)"
}, {
"os": 'Windows 2000',
"code": "(Windows NT 5.0|Windows 2000)"
}, {
"os": 'Windows ME',
"code": "(Win 9x 4.90|Windows ME)"
}, {
"os": 'Windows 98',
"code": "(Windows 98|Win98)"
}, {
"os": 'Windows 95',
"code": "(Windows 95|Win95|Windows_95)"
}, {
"os": 'Windows NT 4.0',
"code": "(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)"
}, {
"os": 'Windows CE',
"code": "Windows CE"
}, {
"os": 'Windows 3.11',
"code": "Win16"
}, {
"os": 'Android',
"code": "Android"
}, {
"os": 'Open BSD',
"code": "OpenBSD"
}, {
"os": 'Sun OS',
"code": "SunOS"
}, {
"os": 'Chrome OS',
"code": "CrOS"
}, {
"os": 'Linux',
"code": "(Linux|X11(?!.*CrOS))"
}, {
"os": 'iOS',
"code": "(iPhone|iPad|iPod)"
}, {
"os": 'Mac OS X',
"code": "Mac OS X"
}, {
"os": 'Mac OS',
"code": "(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)"
}, {
"os": 'QNX',
"code": "QNX"
}, {
"os": 'UNIX',
"code": "UNIX"
}, {
"os": 'BeOS',
"code": "BeOS"
}, {
"os": 'OS/2',
"code": "OS\\/2"
}, {
"os": 'Search Bot',
"code": "(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\\/Teoma|ia_archiver)"
}];
for (var id in oscodes) {
var cs = oscodes[id];
var re = new RegExp(cs.code);
if (re.test(navigator.userAgent)) {
os = cs.os;
break;
}
}
return os;
}
static hasWebRTCSupport() {
let isSupported = false;
try {
let webrtc = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || window.RTCPeerConnection;
isSupported = true;
} catch (error) {
isSupported = false;
}
return isSupported;
}
static hasHLSSupport(videoObject) {
if (videoObject !== null) {
return Boolean(videoObject.canPlayType('application/vnd.apple.mpegURL') || videoObject.canPlayType('audio/mpegurl'));
} else return false;
}
static hasMSESupport() {
const mediaSource = window.MediaSource = window.MediaSource || window.WebKitMediaSource;
window.SourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer;
return mediaSource && typeof mediaSource.isTypeSupported === 'function';
}
static hasMMSSupport() {
return window.ManagedMediaSource;
}
static isSSL() {
if (location.protocol === 'https:') return true;else return false;
}
}
class StorageManager {
constructor(main) {
var _a, _b, _c, _d, _e, _f;
this.LOG_ACTIVITY = false;
this.isEnabled = true;
this.prefix = "";
this.logger = main.getLogger();
this.isEnabled = (_c = (_b = (_a = main.getConfigManager()) === null || _a === void 0 ? void 0 : _a.getSettingsData()) === null || _b === void 0 ? void 0 : _b.getStorageData().enabled) !== null && _c !== void 0 ? _c : this.isEnabled;
this.prefix = (_f = (_e = (_d = main.getConfigManager()) === null || _d === void 0 ? void 0 : _d.getSettingsData()) === null || _e === void 0 ? void 0 : _e.getStorageData().prefix) !== null && _f !== void 0 ? _f : this.prefix;
if (this.LOG_ACTIVITY) this.logger.info(this, "Creating new StorageManager");
}
saveField(name, value) {
if (this.isEnabled == true) {
if (this.LOG_ACTIVITY) this.logger.info(this, "Saving data: " + name + " | " + value);
localStorage.setItem(this.prefix + name, value);
}
}
getField(name) {
if (this.isEnabled == true) {
const value = localStorage.getItem(this.prefix + name);
if (this.LOG_ACTIVITY) this.logger.info(this, "Grabbing data: " + name + " | " + value);
return value;
} else return null;
}
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
/**
* lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** `Object#toString` result references. */
var symbolTag = '[object Symbol]';
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = freeGlobal || freeSelf || Function('return this')();
/** Used for built-in method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString = objectProto.toString;
/* Built-in method references for those with the