@stormstreaming/stormlibrary
Version:
A JavaScript library containing core web video player functionality for embedding live-video streams on a website. Part of StormStreaming Suite.
1,229 lines (1,208 loc) • 268 kB
JavaScript
/*
* StormStreaming JavaScript Library
* Copyright © 2021-2025 Web-Anatomy s.c. All rights reserved.
* contact@stormstreaming.com
* https://stormstreaming.com
*
* Version: 5.0.4
* Version: 2/4/2026, 1:57:23 PM
*
* 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) {
let port = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 443;
let isSSL = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 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;
}
}
var SecurityType;
(function (SecurityType) {
SecurityType[SecurityType["NONE"] = 0] = "NONE";
SecurityType[SecurityType["TOKEN"] = 1] = "TOKEN";
})(SecurityType || (SecurityType = {}));
class SecurityData {
constructor(config) {
this._securityMethod = SecurityType.NONE;
this.parse(config);
}
parse(config) {
var _a, _b, _c;
this._securityConfig = config;
if (this._securityConfig) {
const type = (_a = this._securityConfig.type) !== null && _a !== void 0 ? _a : null;
if (type) {
switch (type) {
case "token":
this._securityMethod = SecurityType.TOKEN;
break;
case "none":
this._securityMethod = SecurityType.NONE;
break;
default:
this._securityMethod = SecurityType.NONE;
}
}
this._token = (_b = this._securityConfig.token) !== null && _b !== void 0 ? _b : null;
this._secret = (_c = this._securityConfig.secret) !== null && _c !== void 0 ? _c : null;
} else this._securityMethod = SecurityType.NONE;
}
get securityType() {
return this._securityMethod;
}
set securityType(newValue) {
switch (newValue) {
case "token":
this._securityMethod = SecurityType.TOKEN;
break;
case "none":
this._securityMethod = SecurityType.NONE;
break;
default:
this._securityMethod = SecurityType.NONE;
}
}
get token() {
return this._token;
}
get secret() {
return this._secret;
}
set token(newValue) {
this._token = newValue;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (SecurityData.PRINT_ON_STARTUP || force) {
let securityMethodName = "";
switch (this._securityMethod) {
case SecurityType.NONE:
securityMethodName = "none";
break;
case SecurityType.TOKEN:
securityMethodName = "token";
break;
}
logger.info(this, "Security Method: " + securityMethodName);
}
}
}
SecurityData.PRINT_ON_STARTUP = true;
class StreamData {
constructor(streamConfig) {
this._serverList = new Array();
this._sourceList = new Array();
this._streamKey = null;
this.parse(streamConfig);
}
parse(streamConfig) {
var _a, _b, _c, _d;
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;
this._securityData = new SecurityData((_d = this._streamConfig.security) !== null && _d !== void 0 ? _d : null);
}
getServerList() {
return this._serverList;
}
getSourceList() {
return this._sourceList;
}
get streamKey() {
return this._streamKey;
}
set streamKey(newValue) {
this._streamKey = newValue;
}
getSecurityData() {
return this._securityData;
}
set serverList(serverList) {
this._serverList = serverList;
}
set sourceList(sourceList) {
this._sourceList = sourceList;
}
clearSourceList() {
this._sourceList = new Array();
}
clearServerList() {
this._serverList = new Array();
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 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);
this._securityData.print(logger);
}
}
}
StreamData.PRINT_ON_STARTUP = true;
StreamData.DEFAULT_CONNECTION_PORT = 443;
StreamData.IS_SSL_BY_DEFAULT = true;
var ProtocolType;
(function (ProtocolType) {
ProtocolType["RTMP"] = "RTMP";
ProtocolType["RTSP"] = "RTSP";
ProtocolType["WEBRTC"] = "WebRTC";
ProtocolType["HLS"] = "HLS";
ProtocolType["STORM"] = "Storm";
})(ProtocolType || (ProtocolType = {}));
let BufferData$1 = class BufferData {
constructor(bufferConfig) {
this.PRINT_ON_STARTUP = true;
this._minValue = 0.2;
this._maxValue = 2;
this._startValue = 0.5;
this._targetValue = 0.7;
this.parse(bufferConfig);
}
parse(bufferConfig) {
var _a, _b, _c, _d;
this._bufferConfig = bufferConfig;
if (this._bufferConfig) {
this._minValue = (_a = this._bufferConfig.minValue) !== null && _a !== void 0 ? _a : this._minValue;
this._maxValue = (_b = this._bufferConfig.maxValue) !== null && _b !== void 0 ? _b : this._maxValue;
this._startValue = (_c = this._bufferConfig.startValue) !== null && _c !== void 0 ? _c : this._startValue;
this._targetValue = (_d = this._bufferConfig.targetValue) !== null && _d !== void 0 ? _d : this._targetValue;
}
}
get minValue() {
return this._minValue;
}
get maxValue() {
return this._maxValue;
}
get startValue() {
return this._startValue;
}
get targetValue() {
return this._targetValue;
}
set minValue(newValue) {
this._minValue = newValue;
}
set maxValue(newValue) {
this._maxValue = newValue;
}
set targetValue(newValue) {
this._targetValue = newValue;
}
set startValue(newValue) {
this._startValue = newValue;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) logger.info(this, "BufferConfig :: minValue: " + this.minValue + " | maxValue: " + this.maxValue + " | startValue: " + this.startValue + " | targetValue: " + this.targetValue);
}
};
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._playbackController = false;
this._qualityController = false;
this._stageController = false;
this._playerUnit = 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, _x, _y, _z, _0, _1, _2, _3, _4;
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;
this._playbackController = (_y = (_x = this._debugConfig) === null || _x === void 0 ? void 0 : _x.playbackController) !== null && _y !== void 0 ? _y : this._playbackController;
this._qualityController = (_0 = (_z = this._debugConfig) === null || _z === void 0 ? void 0 : _z.qualityController) !== null && _0 !== void 0 ? _0 : this._qualityController;
this._stageController = (_2 = (_1 = this._debugConfig) === null || _1 === void 0 ? void 0 : _1.stageController) !== null && _2 !== void 0 ? _2 : this._stageController;
this._playerUnit = (_4 = (_3 = this._debugConfig) === null || _3 === void 0 ? void 0 : _3.playerUnit) !== null && _4 !== void 0 ? _4 : this._playerUnit;
}
}
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: ".concat(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;
}
get playbackControllerDebug() {
return this._playbackController;
}
get qualityControllerDebug() {
return this._qualityController;
}
get stageControllerDebug() {
return this._stageController;
}
get playerUnitDebug() {
return this._playerUnit;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 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) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 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) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (StorageData.PRINT_ON_STARTUP || force) logger.info(this, "Storage :: startVolume: " + this._enabled + " | prefix: " + this._prefix);
}
}
StorageData.PRINT_ON_STARTUP = true;
exports.QualityControlMode = void 0;
(function (QualityControlMode) {
QualityControlMode["PASSIVE"] = "PASSIVE";
QualityControlMode["RESOLUTION_AWARE"] = "RESOLUTION_AWARE";
QualityControlMode["UNKNOWN"] = "UNKNOWN";
QualityControlMode["HIGHEST_QUALITY"] = "HIGHEST_QUALITY";
QualityControlMode["LOWEST_QUALITY"] = "LOWEST_QUALITY";
})(exports.QualityControlMode || (exports.QualityControlMode = {}));
class QualityData {
constructor(qualityData) {
this.PRINT_ON_STARTUP = true;
this._qualityControlMode = exports.QualityControlMode.PASSIVE;
this._initialUpgradeTimeout = 30;
this._maxUpgradeTimeout = 3600;
this.parse(qualityData);
}
parse(qualityData) {
var _a, _b, _c;
this._qualityConfig = qualityData;
if (this._qualityConfig) {
this._qualityControlMode = (_a = this._qualityConfig.controlMode) !== null && _a !== void 0 ? _a : this._qualityControlMode;
this._initialUpgradeTimeout = (_b = this._qualityConfig.initialUpgradeTimeout) !== null && _b !== void 0 ? _b : this._initialUpgradeTimeout;
this._maxUpgradeTimeout = (_c = this._qualityConfig.maxUpgradeTimeout) !== null && _c !== void 0 ? _c : this._maxUpgradeTimeout;
}
}
get qualityControlMode() {
return this._qualityControlMode;
}
set qualityControlMode(newMode) {
this._qualityControlMode = newMode;
}
get initialUpgradeTimeout() {
return this._initialUpgradeTimeout;
}
set initialUpgradeTimeout(newValue) {
this._initialUpgradeTimeout = newValue;
}
get maxUpgradeTimeout() {
return this._maxUpgradeTimeout;
}
set maxUpgradeTimeout(newValue) {
this._maxUpgradeTimeout = newValue;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) logger.info(this, "QualityControl :: mode: " + this.qualityControlMode + " | initialUpgradeTime: " + this._initialUpgradeTimeout + " | maxUpgradeTime: " + this._maxUpgradeTimeout);
}
}
class SettingsData {
constructor(config) {
this._restartOnError = true;
this._reconnectTime = 1;
this._autoStart = false;
this._autoConnect = true;
this.startOnDOMReady = false;
this.iOSOnDomReadyFix = true;
this._enabledProtocols = new Array(ProtocolType.STORM, ProtocolType.RTMP, ProtocolType.HLS, ProtocolType.WEBRTC);
this._restartOnFocus = true;
this.parse(config);
}
parse(config) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
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;
if ((_f = this._settingsConfig.enabledProtocols) === null || _f === void 0 ? void 0 : _f.length) {
this._enabledProtocols = this._settingsConfig.enabledProtocols.map(protocolName => {
const normalized = protocolName.toLowerCase();
switch (normalized) {
case "storm":
return ProtocolType.STORM;
case "hls":
return ProtocolType.HLS;
case "webrtc":
return ProtocolType.WEBRTC;
case "rtmp":
return ProtocolType.RTMP;
case "rtsp":
return ProtocolType.RTSP;
default:
throw new Error("Unknown protocol \"".concat(protocolName, "\". Please check your config!"));
}
});
}
this._bufferData = new BufferData$1((_g = this._settingsConfig.buffer) !== null && _g !== void 0 ? _g : null);
this._videoData = new VideoData((_h = this._settingsConfig.video) !== null && _h !== void 0 ? _h : null);
this._audioData = new AudioData((_j = this._settingsConfig.audio) !== null && _j !== void 0 ? _j : null);
this._storageData = new StorageData((_k = this._settingsConfig.storage) !== null && _k !== void 0 ? _k : null);
this._debugData = new DebugData((_l = this._settingsConfig.debug) !== null && _l !== void 0 ? _l : null);
this._qualityData = new QualityData((_m = this._settingsConfig.quality) !== null && _m !== void 0 ? _m : null);
}
get enabledProtocols() {
return this._enabledProtocols;
}
set enabledProtocols(newValue) {
this._enabledProtocols = newValue;
}
getBufferData() {
return this._bufferData;
}
getAudioData() {
return this._audioData;
}
getVideoData() {
return this._videoData;
}
getStorageData() {
return this._storageData;
}
getQualityData() {
return this._qualityData;
}
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) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (SettingsData.PRINT_ON_STARTUP || force) {
let enabledProtocols = "";
for (let i = 0; i < this._enabledProtocols.length; i++) {
switch (this._enabledProtocols[i]) {
case ProtocolType.STORM:
enabledProtocols += "STORM, ";
break;
case ProtocolType.RTMP:
enabledProtocols += "RTMP, ";
break;
case ProtocolType.RTSP:
enabledProtocols += "RTSP, ";
break;
case ProtocolType.HLS:
enabledProtocols += "HLS, ";
break;
case ProtocolType.WEBRTC:
enabledProtocols += "WebRTC, ";
break;
}
}
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._bufferData.print(logger);
this._qualityData.print(logger);
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) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) {
this.streamData.print(logger);
this.settingsData.print(logger);
}
}
}
class EventDispatcher {
constructor() {
this.DEBUG_OUTPUT = false;
this._isRemoved = false;
this._listeners = {};
}
addEventListener(eventName, listener) {
let removable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 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 formatTime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor(seconds % 3600 / 60);
const secs = seconds % 60;
const formattedHours = (hours < 10 ? '0' : '') + hours;
const formattedMinutes = (minutes < 10 ? '0' : '') + minutes;
const formattedSeconds = (secs < 10 ? '0' : '') + secs;
return "".concat(formattedHours, ":").concat(formattedMinutes, ":").concat(formattedSeconds);
}
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;
}
static fibonacci(n) {
let a = 0,
b = 1,
c = 0;
if (n <= 0) return 0;
for (let i = 2; i <= n; i++) {
c = a + b;
a = b;
b = c;
}
return b;
}
}
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, stormLibrary) {
this.colorOrder = ["red", "green", "blue", "orange", "black", "violet"];
this.logMemory = [];
this.libraryInstanceID = -1;
this.playerInstanceID = -1;
this.debugConfig = config;
this._stormPlayer = stormLibrary;
this.libraryInstanceID = this._stormPlayer.getLibraryID();
let colorID = this.colorOrder.length < stormLibrary.getLibraryID() ? this.colorOrder.length - 1 : stormLibrary.getLibraryID();
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.libraryInstanceID);
if (this.playerInstanceID >= 0) label += "|" + this.playerInstanceID;
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);
}
}
decoratedLog(text, scheme) {
const EMOJI_MAP = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"];
const COLOR_SCHEMES = {
'dark-blue': '#4c9fee',
'dark-green': '#4bcb64',
'dark-orange': '#daa33a',
'dark-red': '#f86464',
'dark-pink': '#f864e8',
'dark-yellow': '#e1f864'
};
const id = this._stormPlayer.getLibraryID();
const keyCaps = id >= 0 && id < EMOJI_MAP.length ? EMOJI_MAP[id] : "[".concat(id, "]");
const color = COLOR_SCHEMES[scheme];
if (!color) return;
const style = "background: black; color: ".concat(color, "; border: 1px solid ").concat(color, "; padding: 5px 5px 5px 0px");
console.log("%c \u25B6\uFE0F".concat(keyCaps, " ").concat(text), style);
}
setPlayerID(playerID) {
this.playerInstanceID = 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 UserCapabilities {
static hasWebSocketsSupport() {
re