@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,120 lines (1,098 loc) • 205 kB
JavaScript
/*
* StormStreaming JavaScript Library
* Copyright © 2021-2024 Web-Anatomy s.c. All rights reserved.
* contact@stormstreaming.com
* https://stormstreaming.com
*
* Version: 4.3.0
* Version: 7/23/2024, 12:24:38 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';
var RoleType;
(function (RoleType) {
RoleType[RoleType["STREAMER"] = 0] = "STREAMER";
RoleType[RoleType["PLAYER"] = 1] = "PLAYER";
})(RoleType || (RoleType = {}));
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 SecurityConfig {
constructor(config) {
this.PRINT_ON_STARTUP = true;
this.securityMethod = SecurityType.NONE;
this.token = "";
this.parse(config);
}
parse(config) {
if (config != null) {
if (config.type !== undefined && config.type !== null) {
switch (config.type) {
case "token":
this.securityMethod = SecurityType.TOKEN;
break;
case "none":
this.securityMethod = SecurityType.NONE;
break;
default:
this.securityMethod = SecurityType.NONE;
}
}
if (config.token !== undefined && config.token !== null) this.token = config.token;
} else this.securityMethod = SecurityType.NONE;
}
setConfig(config) {
this.parse = config;
}
getSecurityMethod() {
return this.securityMethod;
}
setSecurityMethod(newValue) {
switch (newValue) {
case "token":
this.securityMethod = SecurityType.TOKEN;
break;
case "none":
this.securityMethod = SecurityType.NONE;
break;
default:
this.securityMethod = SecurityType.NONE;
}
}
getToken() {
return this.token;
}
setToken(newValue) {
this.token = newValue;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.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);
}
}
}
class AbstractSourceItem {
constructor(type, info) {
this.type = type;
this.streamInfo = info;
}
getType() {
return this.type;
}
getStreamInfo() {
return this.streamInfo;
}
}
var ProtocolType;
(function (ProtocolType) {
ProtocolType["RTMP"] = "RTMP";
ProtocolType["RTSP"] = "RTSP";
ProtocolType["WEBRTC"] = "WebRTC";
ProtocolType["HLS"] = "HLS";
ProtocolType["WEB_SOCKETS"] = "WebSockets";
ProtocolType["MPEG_DASH"] = "MpegDash";
ProtocolType["STORM"] = "Storm";
})(ProtocolType || (ProtocolType = {}));
class StormSourceItem extends AbstractSourceItem {
constructor(streamKey, streamInfo, defaultSource) {
super(ProtocolType.STORM, streamInfo);
this.streamKey = streamKey;
this.defaultSource = defaultSource;
}
getStreamKey() {
return this.streamKey;
}
isDefaultSource() {
return this.defaultSource;
}
toString() {
return "type: Storm | streamKey: " + this.streamKey + " | streamInfo: " + this.streamInfo.toString();
}
}
class WebRTCSourceItem extends AbstractSourceItem {
constructor(streamKey, streamInfo, defaultSource) {
super(ProtocolType.WEBRTC, streamInfo);
this.streamKey = streamKey;
this.defaultSource = defaultSource;
}
getStreamKey() {
return this.streamKey;
}
isDefaultSource() {
return this.defaultSource;
}
toString() {
return "type: WebRTC | streamKey: " + this.streamKey;
}
}
class RTMPSourceItem extends AbstractSourceItem {
constructor(host, application, streamKey, port, streamInfo, defaultSource) {
super(ProtocolType.RTMP, streamInfo);
this.host = host;
this.application = application;
this.streamKey = streamKey;
this.port = port;
this.defaultSource = defaultSource;
}
getHost() {
return this.host;
}
getPort() {
return this.port;
}
getApplicationName() {
return this.application;
}
getStreamKey() {
return this.streamKey;
}
isDefaultSource() {
return this.defaultSource;
}
toString() {
return "type: RTMP | url: " + this.host + " | port: " + this.port;
}
}
var ConfigurationType;
(function (ConfigurationType) {
ConfigurationType[ConfigurationType["EMBEDDED"] = 0] = "EMBEDDED";
ConfigurationType[ConfigurationType["GATEWAY"] = 1] = "GATEWAY";
})(ConfigurationType || (ConfigurationType = {}));
class StreamInfo {
constructor(config) {
this.bitrate = 0;
if (config !== undefined && config !== null) {
this.label = "sd";
if (config.label !== undefined && config.label !== null) this.label = config.label;
if (config.width !== undefined && config.width !== null) this.width = config.width;
if (config.height !== undefined && config.height !== null) this.height = config.height;
if (config.fps !== undefined && config.fps !== null) this.fps = config.fps;
if (config.bitrate !== undefined && config.bitrate !== null) this.bitrate = config.bitrate;
}
}
getLabel() {
return this.label;
}
getWidth() {
return this.width;
}
getHeight() {
return this.height;
}
getFPS() {
return this.fps;
}
getBitrate() {
return this.bitrate;
}
toString() {
return "label: " + this.label + " | width: " + this.width + " | height: " + this.height + " | bitrate: " + this.bitrate;
}
}
class WebRTCStreamItem {
constructor(streamName, applicationName, host) {
this.streamName = streamName;
this.applicationName = applicationName;
this.host = host;
}
getStreamName() {
return this.streamName;
}
getApplicationName() {
return this.applicationName;
}
getHost() {
return this.host;
}
getType() {
return ProtocolType.WEBRTC;
}
}
class RTSPSourceItem extends AbstractSourceItem {
constructor(host, application, streamKey, port, streamInfo, defaultSource) {
super(ProtocolType.RTSP, streamInfo);
this.host = host;
this.application = application;
this.streamKey = streamKey;
this.port = port;
this.defaultSource = defaultSource;
}
getHost() {
return this.host;
}
getPort() {
return this.port;
}
getApplicationName() {
return this.application;
}
getStreamKey() {
return this.streamKey;
}
isDefaultSource() {
return this.defaultSource;
}
toString() {
return "type: RTMP | url: " + this.host + " | port: " + this.port;
}
}
class StreamConfig {
constructor(streamConfig, roleType, configurationType) {
this.PRINT_ON_STARTUP = true;
this.DEFAULT_STORM_PORT = 443;
this.IS_SSL_BY_DEFAULT = true;
this.serverList = new Array();
this.sourceList = new Array();
this.roleType = roleType;
this.configurationType = configurationType;
this.parse(streamConfig, roleType);
}
parse(streamConfig, roleType) {
this.streamConfig = streamConfig;
if (this.streamConfig !== undefined && this.streamConfig !== null) {
if (this.configurationType == ConfigurationType.EMBEDDED) {
if (roleType == RoleType.PLAYER) {
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;
let port = this.DEFAULT_STORM_PORT;
let isSSL = this.IS_SSL_BY_DEFAULT;
if (this.streamConfig.serverList[i].host !== undefined && this.streamConfig.serverList[i].host !== null) host = this.streamConfig.serverList[i].host;else throw new Error("Error while parsing server object (\"host\" filed is missing). Please check player config!");
if (this.streamConfig.serverList[i].application !== undefined && this.streamConfig.serverList[i].application !== null) application = this.streamConfig.serverList[i].application;else throw new Error("Error while parsing server object (\"application\" filed is missing). Please check player config!");
if (this.streamConfig.serverList[i].port !== undefined && this.streamConfig.serverList[i].port !== null) port = this.streamConfig.serverList[i].port;
if (this.streamConfig.serverList[i].ssl !== undefined && this.streamConfig.serverList[i].ssl !== null) isSSL = this.streamConfig.serverList[i].ssl;
this.serverList.push(new StormServerItem(host, application, port, isSSL));
}
} else throw new Error("Server list configuration is empty. Please check stream config!");
} else throw new Error("Server list configuration is missing. Please check stream config!");
if (this.streamConfig.sourceList !== undefined && this.streamConfig.sourceList !== null) {
if (this.streamConfig.sourceList.length !== 0) {
for (let i = 0; i < this.streamConfig.sourceList.length; i++) {
let protocol = "none";
let isDefault = false;
if (this.streamConfig.sourceList[i].protocol !== undefined && this.streamConfig.sourceList[i].protocol !== null) protocol = this.streamConfig.sourceList[i].protocol;else throw new Error("Error while parsing source object (\"protocol\" filed is missing). Please check player config!");
if (this.streamConfig.sourceList[i].default !== undefined && this.streamConfig.sourceList[i].default !== null) isDefault = this.streamConfig.sourceList[i].default;
switch (protocol.toLowerCase()) {
case "storm":
let streamKey = "";
let streamInfo = null;
if (this.streamConfig.sourceList[i].streamKey !== undefined && this.streamConfig.sourceList[i].streamKey !== null) streamKey = this.streamConfig.sourceList[i].streamKey;else throw new Error("Missing \"streamKey\" parameter in stream source element");
if (this.streamConfig.sourceList[i].streamInfo !== undefined && this.streamConfig.sourceList[i].streamInfo !== null) streamInfo = this.streamConfig.sourceList[i].streamInfo;else streamInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
this.sourceList.push(new StormSourceItem(streamKey, new StreamInfo(streamInfo), isDefault));
break;
case "rtmp":
let rtmpHost = "";
let rtmpApplication = "";
let rtmpStreamKey = "";
let rtmpPort = 1935;
let rtmpInfo = null;
if (this.streamConfig.sourceList[i].host !== undefined && this.streamConfig.sourceList[i].host !== null) rtmpHost = this.streamConfig.sourceList[i].host;else throw new Error("Missing \"host\" parameter in stream source element");
if (this.streamConfig.sourceList[i].application !== undefined && this.streamConfig.sourceList[i].application !== null) rtmpApplication = this.streamConfig.sourceList[i].application;else throw new Error("Missing \"application\" parameter in stream source element");
if (this.streamConfig.sourceList[i].streamKey !== undefined && this.streamConfig.sourceList[i].streamKey !== null) rtmpStreamKey = this.streamConfig.sourceList[i].streamKey;else throw new Error("Missing \"streamName\" parameter in stream source element");
if (this.streamConfig.sourceList[i].port !== undefined && this.streamConfig.sourceList[i].port !== null) rtmpPort = this.streamConfig.sourceList[i].port;
if (this.streamConfig.sourceList[i].streamInfo !== undefined && this.streamConfig.sourceList[i].streamInfo !== null) rtmpInfo = this.streamConfig.sourceList[i].streamInfo;else rtmpInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
this.sourceList.push(new RTMPSourceItem(rtmpHost, rtmpApplication, rtmpStreamKey, rtmpPort, new StreamInfo(rtmpInfo), isDefault));
break;
case "rtsp":
let rtspHost = "";
let rtspApplication = "";
let rtspStreamKey = "";
let rtspPort = 1935;
let rtspInfo = null;
if (this.streamConfig.sourceList[i].host !== undefined && this.streamConfig.sourceList[i].host !== null) rtspHost = this.streamConfig.sourceList[i].host;else throw new Error("Missing \"host\" parameter in stream source element");
if (this.streamConfig.sourceList[i].application !== undefined && this.streamConfig.sourceList[i].application !== null) rtspApplication = this.streamConfig.sourceList[i].application;else throw new Error("Missing \"application\" parameter in stream source element");
if (this.streamConfig.sourceList[i].streamKey !== undefined && this.streamConfig.sourceList[i].streamKey !== null) rtspStreamKey = this.streamConfig.sourceList[i].streamKey;else throw new Error("Missing \"streamName\" parameter in stream source element");
if (this.streamConfig.sourceList[i].port !== undefined && this.streamConfig.sourceList[i].port !== null) rtspPort = this.streamConfig.sourceList[i].port;
if (this.streamConfig.sourceList[i].streamInfo !== undefined && this.streamConfig.sourceList[i].streamInfo !== null) rtspInfo = this.streamConfig.sourceList[i].streamInfo;else rtspInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
this.sourceList.push(new RTSPSourceItem(rtspHost, rtspApplication, rtspStreamKey, rtspPort, new StreamInfo(rtspInfo), isDefault));
break;
case "webrtc":
let rtcStreamKey = "";
let rtcInfo = null;
if (this.streamConfig.sourceList[i].streamKey !== undefined && this.streamConfig.serverList[i].streamKey !== null) rtcStreamKey = this.streamConfig.sourceList[i].streamKey;else throw new Error("Missing \"streamName\" parameter in stream source element");
if (this.streamConfig.sourceList[i].streamInfo !== undefined && this.streamConfig.serverList[i].streamInfo !== null) rtcInfo = this.streamConfig.sourceList[i].streamKey;else rtcInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
this.sourceList.push(new WebRTCSourceItem(rtcStreamKey, new StreamInfo(rtcInfo), isDefault));
break;
default:
throw new Error("Error while parsing source object (unknown protocol). Please check player config!");
}
}
} else throw new Error("Source list configuration is missing. Please check player config!");
} else throw new Error("Source list configuration is missing. Please check player config!");
}
if (roleType == RoleType.STREAMER) {
if (this.streamConfig.publishData !== undefined && this.streamConfig.publishData !== null) {
if (this.streamConfig.publishData.protocol !== undefined && this.streamConfig.publishData.protocol !== null) {
switch (this.streamConfig.publishData.protocol.toLowerCase()) {
case "webrtc":
let streamName;
let applicationName;
let host;
if (this.streamConfig.publishData.streamName !== undefined && this.streamConfig.publishData.streamName !== null) streamName = this.streamConfig.publishData.streamName;else throw new Error("Stream data configuration is missing. Please check streamer config!");
if (this.streamConfig.publishData.application !== undefined && this.streamConfig.publishData.application !== null) applicationName = this.streamConfig.publishData.application;else throw new Error("Stream data configuration is missing. Please check streamer config!");
if (this.streamConfig.publishData.host !== undefined && this.streamConfig.publishData.host !== null) host = this.streamConfig.publishData.host;else throw new Error("Stream data configuration is missing. Please check streamer config!");
this.publishData = new WebRTCStreamItem(streamName, applicationName, host);
break;
default:
throw new Error("Unknown \"protocol\" field in stream data element. Please check player config!");
}
} else throw new Error("Missing \"protocol\" field in stream data element. Please check player config!");
} else throw new Error("Stream data configuration is missing. Please check player config!");
}
} else if (this.configurationType == ConfigurationType.GATEWAY) {
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;
let port = this.DEFAULT_STORM_PORT;
let isSSL = this.IS_SSL_BY_DEFAULT;
if (this.streamConfig.serverList[i].host !== undefined && this.streamConfig.serverList[i].host !== null) host = this.streamConfig.serverList[i].host;else throw new Error("Error while parsing server object (\"host\" filed is missing). Please check player config!");
if (this.streamConfig.serverList[i].application !== undefined && this.streamConfig.serverList[i].application !== null) application = this.streamConfig.serverList[i].application;else throw new Error("Error while parsing server object (\"application\" filed is missing). Please check player config!");
if (this.streamConfig.serverList[i].port !== undefined && this.streamConfig.serverList[i].port !== null) port = this.streamConfig.serverList[i].port;
if (this.streamConfig.serverList[i].ssl !== undefined && this.streamConfig.serverList[i].ssl !== null) isSSL = this.streamConfig.serverList[i].ssl;
this.serverList.push(new StormServerItem(host, application, port, isSSL));
}
} else throw new Error("Gateway server list configuration is empty. Please check player config!");
} else throw new Error("Gateway server list configuration is missing. Please check player config!");
if (this.streamConfig.streamKey !== undefined && this.streamConfig.streamKey !== null) this.streamKey = this.streamConfig.streamKey;else throw new Error("StreamKey for gateway was not defined! Please check stream config!");
} else throw new Error("Unknown configurationType was defined in stream config!");
if (this.streamConfig.security !== undefined && this.streamConfig.security !== null) this.securityConfig = new SecurityConfig(this.streamConfig.security);else this.securityConfig = new SecurityConfig(null);
} else throw new Error("Stream configuration is missing. Please check stream config!");
}
getServerList() {
return this.serverList;
}
getSourceList() {
return this.sourceList;
}
getGatewayStreamKey() {
return this.streamKey;
}
getType(source) {
if (source instanceof StormSourceItem) {
return "StormSourceItem";
} else if (source instanceof RTMPSourceItem) {
return "RTMPSourceItem";
} else {
return "Object";
}
}
addSourceStream(source) {
let newSourceItem;
switch (this.getType(source)) {
case "StormSourceItem":
newSourceItem = source;
break;
case "RTMPSourceItem":
newSourceItem = source;
break;
case "Object":
let sourceObject = source;
let protocol = "none";
let isDefault = false;
if (sourceObject.protocol !== undefined && sourceObject.protocol !== null) protocol = sourceObject.protocol;else throw new Error("Error while parsing source object (\"protocol\" filed is missing). Please check player config!");
if (sourceObject.default !== undefined && sourceObject.default !== null) isDefault = sourceObject.default;
switch (protocol.toLowerCase()) {
case "storm":
let streamKey = "";
let streamInfo = null;
if (sourceObject.streamKey !== undefined && sourceObject.streamKey !== null) streamKey = sourceObject.streamKey;else throw new Error("Missing \"streamKey\" parameter in stream source element");
if (sourceObject.streamInfo !== undefined && sourceObject.streamInfo !== null) streamInfo = sourceObject.streamInfo;else streamInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
newSourceItem = new StormSourceItem(streamKey, new StreamInfo(streamInfo), isDefault);
this.sourceList.push(newSourceItem);
break;
case "rtmp":
let rtmpHost = "";
let rtmpApplication = "";
let rtmpStreamKey = "";
let rtmpPort = 1935;
let rtmpInfo = null;
if (sourceObject.host !== undefined && sourceObject.host !== null) rtmpHost = sourceObject.host;else throw new Error("Missing \"host\" parameter in stream source element");
if (sourceObject.application !== undefined && sourceObject.application !== null) rtmpApplication = sourceObject.application;else throw new Error("Missing \"application\" parameter in stream source element");
if (sourceObject.streamKey !== undefined && sourceObject.streamKey !== null) rtmpStreamKey = sourceObject.streamKey;else throw new Error("Missing \"streamName\" parameter in stream source element");
if (sourceObject.port !== undefined && sourceObject.port !== null) rtmpPort = sourceObject.port;
if (sourceObject.streamInfo !== undefined && sourceObject.streamInfo !== null) rtmpInfo = sourceObject.streamInfo;else rtmpInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
newSourceItem = new RTMPSourceItem(rtmpHost, rtmpApplication, rtmpStreamKey, rtmpPort, new StreamInfo(rtmpInfo), isDefault);
this.sourceList.push(newSourceItem);
break;
case "webrtc":
let rtcStreamKey = "";
let rtcInfo = null;
if (sourceObject.streamKey !== undefined && sourceObject.streamKey !== null) rtcStreamKey = sourceObject.streamKey;else throw new Error("Missing \"streamName\" parameter in stream source element");
if (sourceObject.streamInfo !== undefined && sourceObject.streamInfo !== null) rtcInfo = sourceObject.streamKey;else rtcInfo = {
label: "",
width: 0,
height: 0,
fps: 0,
bitrate: 0
};
newSourceItem = new WebRTCSourceItem(rtcStreamKey, new StreamInfo(rtcInfo), isDefault);
this.sourceList.push(new WebRTCSourceItem(rtcStreamKey, new StreamInfo(rtcInfo), isDefault));
break;
default:
throw new Error("Error while parsing source object (unknown protocol). Please check player config!");
}
break;
default:
throw new Error("Incompatible type");
}
return newSourceItem;
}
getSecurityConfig() {
return this.securityConfig;
}
getPublishData() {
return this.publishData;
}
getConfigurationType() {
return this.configurationType;
}
setServerList(serverList) {
this.serverList = serverList;
}
clearSourceList() {
this.sourceList = new Array();
}
setSourceList(sourceList) {
this.sourceList = sourceList;
}
getRole() {
return this.roleType;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.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, "Stream List:");
for (let i = 0; i < this.sourceList.length; i++) {
logger.info(this, "=> [" + i + "] " + this.sourceList[i].toString());
}
this.securityConfig.print(logger);
}
}
}
class BufferConfig {
constructor(bufferConfig) {
this.PRINT_ON_STARTUP = true;
this.minValue = 0.1;
this.maxValue = 2.0;
this.startValue = 0.15;
this.targetValue = 0.1;
this.parse(bufferConfig);
}
parse(bufferConfig) {
this.bufferConfig = bufferConfig;
if (this.bufferConfig !== undefined && this.bufferConfig !== null) {
if (this.bufferConfig.minValue !== undefined && this.bufferConfig.minValue !== null) this.minValue = this.bufferConfig.minValue;
if (this.bufferConfig.maxValue !== undefined && this.bufferConfig.maxValue !== null) this.maxValue = this.bufferConfig.maxValue;
if (this.bufferConfig.startValue !== undefined && this.bufferConfig.startValue !== null) this.startValue = this.bufferConfig.startValue;
if (this.bufferConfig.targetValue !== undefined && this.bufferConfig.targetValue !== null) this.targetValue = this.bufferConfig.targetValue;
}
}
getMinValue() {
return this.minValue;
}
getMaxValue() {
return this.maxValue;
}
getStartValue() {
return this.startValue;
}
getTargetValue() {
return this.targetValue;
}
setMinValue(newValue) {
this.minValue = newValue;
}
setMaxValue(newValue) {
this.maxValue = newValue;
}
setTargetValue(newValue) {
this.targetValue = newValue;
}
setStartValue(newValue) {
this.startValue = newValue;
}
setConfig(config) {
this.bufferConfig = config;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) logger.info(this, "minValue: " + this.minValue + " | maxValue: " + this.maxValue + " | startValue: " + this.startValue + " | targetValue: " + this.targetValue);
}
}
class StorageConfig {
constructor(storageConfig) {
this.PRINT_ON_STARTUP = true;
this.storageEnabled = true;
this.prefix = "";
this.parse(storageConfig);
}
parse(storageConfig) {
this.storageConfig = storageConfig;
if (this.storageConfig !== undefined && this.storageConfig !== null) {
if (this.storageConfig.enabled !== undefined && this.storageConfig.enabled !== null) this.storageEnabled = this.storageConfig.enabled;
if (this.storageConfig.prefix !== undefined && this.storageConfig.prefix !== null) this.prefix = this.storageConfig.prefix;
}
}
isStorageEnabled() {
return this.storageEnabled;
}
setStorageEnabled(newValue) {
this.storageEnabled = newValue;
}
getPrefix() {
return this.prefix;
}
setPrefix(newValue) {
this.prefix = newValue;
}
setConfig(config) {
this.storageConfig = config;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) {
logger.info(this, "StorageConfig:: enabled: " + this.storageEnabled);
logger.info(this, "StorageConfig:: prefix: \"" + this.prefix + "\"");
}
}
}
var ScalingType;
(function (ScalingType) {
ScalingType[ScalingType["FILL"] = 0] = "FILL";
ScalingType[ScalingType["LETTER_BOX"] = 1] = "LETTER_BOX";
ScalingType[ScalingType["CROP"] = 2] = "CROP";
ScalingType[ScalingType["ORIGINAL"] = 3] = "ORIGINAL";
})(ScalingType || (ScalingType = {}));
class VideoConfig {
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.parse(videoConfig);
}
parse(config) {
this.videoConfig = config;
if (this.videoConfig !== undefined && this.videoConfig !== null) {
if (this.videoConfig.aspectRatio !== undefined && 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 !== undefined && 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.containerID !== undefined && this.videoConfig.containerID !== null) {
this.containerID = this.videoConfig.containerID;
if (document.getElementById(this.containerID) === null) {
throw new Error("No video object with id \"" + this.containerID + "\" was found for this player. Please check player config!");
}
} else throw new Error("No video object name was provided for this player. Please check player config!");
} else throw new Error("Missing video configuration. Please check player config!");
}
getScalingMode() {
return this.scalingMode;
}
setConfig(config) {
this.videoConfig = config;
}
getContainerID() {
return this.containerID;
}
getVideoWidthValue() {
return this.videoWidthValue;
}
getIfVideoWidthInPixels() {
return this.isVideoWidthInPixels;
}
getIfVideoWidthWasProvided() {
return this.wasVideoWidthProvided;
}
getVideoHeightValue() {
return this.videoHeightValue;
}
getIfVideoHeightInPixels() {
return this.isVideoHeightInPixels;
}
getIfVideoHeightWasProvided() {
return this.wasVideoHeightProvided;
}
getAspectRatio() {
return this.aspectRatio;
}
setVideoWidthValue(newWidth) {
this.videoWidthValue = newWidth;
}
setIfVideoWidthInPixels(value) {
this.isVideoWidthInPixels = value;
}
setVideoHeightValue(newHeight) {
this.videoHeightValue = newHeight;
}
setIfVideoHeightInPixels(value) {
this.isVideoHeightInPixels = value;
}
setContainerID(newContainerID) {
this.containerID = newContainerID;
}
setScalingMode(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!");
}
}
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)"));
}
}
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 DebugConfig {
constructor(debugConfig) {
this.PRINT_ON_STARTUP = true;
this.consoleEnabled = false;
this.consoleLogTypes = [LogType.INFO, LogType.ERROR, LogType.SUCCESS, LogType.TRACE, LogType.WARNING];
this.consoleMonoColor = false;
this.containerEnabled = false;
this.containerLogTypes = [LogType.INFO, LogType.ERROR, LogType.SUCCESS, LogType.TRACE, LogType.WARNING];
this.containerMonoColor = false;
this.parse(debugConfig);
}
parse(debugConfig) {
this.debugConfig = debugConfig;
if (this.debugConfig !== undefined && this.debugConfig !== null) {
if (this.debugConfig.console !== undefined && this.debugConfig.console != null) {
let consoleData = this.debugConfig.console;
if (consoleData.enabled !== undefined && consoleData.enabled !== null) this.consoleEnabled = consoleData.enabled;
if (consoleData.logTypes !== undefined && consoleData.logTypes !== null) {
if (consoleData.logTypes.length !== 0) {
this.consoleLogTypes = new Array();
for (let i = 0; i < consoleData.logTypes.length; i++) {
switch (consoleData.logTypes[i].toLowerCase()) {
case "info":
this.consoleLogTypes.push(LogType.INFO);
break;
case "error":
this.consoleLogTypes.push(LogType.ERROR);
break;
case "warning":
this.consoleLogTypes.push(LogType.WARNING);
break;
case "success":
this.consoleLogTypes.push(LogType.SUCCESS);
break;
case "trace":
this.consoleLogTypes.push(LogType.TRACE);
break;
}
}
}
}
if (consoleData.monoColor !== undefined && consoleData.monoColor !== null) this.consoleMonoColor = consoleData.monoColor;
}
if (this.debugConfig.container !== undefined && this.debugConfig.container != null) {
let containerData = this.debugConfig.container;
if (containerData.enabled !== undefined && containerData.enabled !== null) this.containerEnabled = containerData.enabled;
if (containerData.logTypes !== undefined && containerData.logTypes !== null) {
if (containerData.logTypes.length !== 0) {
this.containerLogTypes = new Array();
for (let i = 0; i < containerData.logTypes.length; i++) {
switch (containerData.logTypes[i].toLowerCase()) {
case "info":
this.containerLogTypes.push(LogType.INFO);
break;
case "error":
this.containerLogTypes.push(LogType.ERROR);
break;
case "warning":
this.containerLogTypes.push(LogType.WARNING);
break;
case "success":
this.containerLogTypes.push(LogType.SUCCESS);
break;
case "trace":
this.containerLogTypes.push(LogType.TRACE);
break;
}
}
}
}
if (containerData.monoColor !== undefined && containerData.monoColor !== null) this.containerMonoColor = containerData.monoColor;
if (containerData.containerID !== undefined && containerData.containerID !== null) this.containerID = containerData.containerID;
}
}
}
isConsoleEnabled() {
return this.consoleEnabled;
}
setConsoleEnabled(newValue) {
this.consoleEnabled = newValue;
}
getConsoleLogTypes() {
return this.consoleLogTypes;
}
setConsoleLogTypes(newValue) {
this.consoleLogTypes = new Array();
for (let i = 0; i < newValue.length; i++) {
switch (newValue[i].toLowerCase()) {
case "info":
this.consoleLogTypes.push(LogType.INFO);
break;
case "error":
this.consoleLogTypes.push(LogType.ERROR);
break;
case "warning":
this.consoleLogTypes.push(LogType.WARNING);
break;
case "success":
this.consoleLogTypes.push(LogType.SUCCESS);
break;
case "trace":
this.consoleLogTypes.push(LogType.TRACE);
break;
}
}
}
isContainerEnabled() {
return this.containerEnabled;
}
setContainerEnabled(newValue) {
this.consoleEnabled = newValue;
}
isConsoleMonoColor() {
return this.consoleMonoColor;
}
setConsoleMonoColor(newValue) {
this.consoleMonoColor = newValue;
}
getContainerLogTypes() {
return this.containerLogTypes;
}
setContainerLogTypes(newValue) {
this.containerLogTypes = new Array();
for (let i = 0; i < newValue.length; i++) {
switch (newValue[i].toLowerCase()) {
case "info":
this.containerLogTypes.push(LogType.INFO);
break;
case "error":
this.containerLogTypes.push(LogType.ERROR);
break;
case "warning":
this.containerLogTypes.push(LogType.WARNING);
break;
case "success":
this.containerLogTypes.push(LogType.SUCCESS);
break;
case "trace":
this.containerLogTypes.push(LogType.TRACE);
break;
}
}
}
getContainerID() {
return this.containerID;
}
setContainerID(object) {
this.containerID = object;
}
isContainerMonoColor() {
return this.containerMonoColor;
}
setContainerMonoColor(newValue) {
this.containerMonoColor = newValue;
}
setConfig(config) {
this.debugConfig = config;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) {
let consoleLogTypes = "";
for (let i = 0; i < this.consoleLogTypes.length; i++) {
switch (this.consoleLogTypes[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.consoleEnabled);
logger.info(this, "Console:: logTypes: " + consoleLogTypes);
logger.info(this, "Console:: monoColor: " + this.consoleMonoColor);
let containerLogTypes = "";
for (let i = 0; i < this.containerLogTypes.length; i++) {
switch (this.containerLogTypes[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.containerEnabled);
logger.info(this, "Container:: logTypes: " + containerLogTypes);
logger.info(this, "Container:: containerID: " + this.containerID);
logger.info(this, "Container:: monoColor: " + this.consoleMonoColor);
}
}
}
class AudioConfig {
constructor(volumeConfig) {
this.PRINT_ON_STARTUP = true;
this.startVolume = 100;
this.maxVolume = 100;
this.rememberValue = true;
this.parse(volumeConfig);
}
parse(config) {
this.volumeConfig = config;
if (this.volumeConfig !== undefined && this.volumeConfig !== null) {
if (this.volumeConfig.startVolume !== undefined && this.volumeConfig.startVolume !== null) this.startVolume = this.volumeConfig.startVolume;
if (this.volumeConfig.maxVolume !== undefined && this.volumeConfig.maxVolume !== null) this.maxVolume = this.volumeConfig.maxVolume;
if (this.volumeConfig.rememberValue !== undefined && this.volumeConfig.rememberValue !== null) this.rememberValue = this.volumeConfig.rememberValue;
}
}
getStartVolume() {
return this.startVolume;
}
setStartVolume(newValue) {
this.startVolume = newValue;
}
getMaxVolume() {
return this.maxVolume;
}
setMaxVolume(newValue) {
this.maxVolume = newValue;
}
isRememberValue() {
return this.rememberValue;
}
setRememberValue(newValue) {
this.rememberValue = newValue;
}
setConfig(config) {
this.volumeConfig = config;
}
print(logger) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.PRINT_ON_STARTUP || force) {
logger.info(this, "Audio :: startVolume: " + this.startVolume + " | maxVolume: " + this.maxVolume + " | rememberValue: " + this.rememberValue);
}
}
}
class SettingsConfi