UNPKG

@stormstreaming/stormlibrary

Version:

A JavaScript library containing core web video player functionality for embedding live-video streams on a website. Part of StormStreaming Suite.

14 lines 116 kB
/* * 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') * */var RoleType,SecurityType,ProtocolType,ConfigurationType,ScalingType,LogType,LibraryState;!function(e){e[e.STREAMER=0]="STREAMER",e[e.PLAYER=1]="PLAYER"}(RoleType=RoleType||{});class StormServerItem{constructor(e,t){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:443,s=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];this.host=e,this.application=t,this.port=i,this.isSSL=s,this.hasFaild=!1}getHost(){return this.host}getApplication(){return this.application}getPort(){return this.port}getIfSSL(){return this.isSSL}getIfFaild(){return this.hasFaild}setAsFaild(e){this.hasFaild=e}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}}!function(e){e[e.NONE=0]="NONE",e[e.TOKEN=1]="TOKEN"}(SecurityType=SecurityType||{});class SecurityConfig{constructor(e){this.PRINT_ON_STARTUP=!0,this.securityMethod=SecurityType.NONE,this.token="",this.parse(e)}parse(e){null!=e?(void 0!==e.type&&null!==e.type&&("token"===e.type?this.securityMethod=SecurityType.TOKEN:this.securityMethod=SecurityType.NONE),void 0!==e.token&&null!==e.token&&(this.token=e.token)):this.securityMethod=SecurityType.NONE}setConfig(e){this.parse=e}getSecurityMethod(){return this.securityMethod}setSecurityMethod(e){this.securityMethod="token"===e?SecurityType.TOKEN:SecurityType.NONE}getToken(){return this.token}setToken(e){this.token=e}print(t){if(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1]){let e="";switch(this.securityMethod){case SecurityType.NONE:e="none";break;case SecurityType.TOKEN:e="token"}t.info(this,"Security Method: "+e)}}}class AbstractSourceItem{constructor(e,t){this.type=e,this.streamInfo=t}getType(){return this.type}getStreamInfo(){return this.streamInfo}}!function(e){e.RTMP="RTMP",e.RTSP="RTSP",e.WEBRTC="WebRTC",e.HLS="HLS",e.WEB_SOCKETS="WebSockets",e.MPEG_DASH="MpegDash",e.STORM="Storm"}(ProtocolType=ProtocolType||{});class StormSourceItem extends AbstractSourceItem{constructor(e,t,i){super(ProtocolType.STORM,t),this.streamKey=e,this.defaultSource=i}getStreamKey(){return this.streamKey}isDefaultSource(){return this.defaultSource}toString(){return"type: Storm | streamKey: "+this.streamKey+" | streamInfo: "+this.streamInfo.toString()}}class WebRTCSourceItem extends AbstractSourceItem{constructor(e,t,i){super(ProtocolType.WEBRTC,t),this.streamKey=e,this.defaultSource=i}getStreamKey(){return this.streamKey}isDefaultSource(){return this.defaultSource}toString(){return"type: WebRTC | streamKey: "+this.streamKey}}class RTMPSourceItem extends AbstractSourceItem{constructor(e,t,i,s,o,r){super(ProtocolType.RTMP,o),this.host=e,this.application=t,this.streamKey=i,this.port=s,this.defaultSource=r}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}}!function(e){e[e.EMBEDDED=0]="EMBEDDED",e[e.GATEWAY=1]="GATEWAY"}(ConfigurationType=ConfigurationType||{});class StreamInfo{constructor(e){this.bitrate=0,null!=e&&(this.label="sd",void 0!==e.label&&null!==e.label&&(this.label=e.label),void 0!==e.width&&null!==e.width&&(this.width=e.width),void 0!==e.height&&null!==e.height&&(this.height=e.height),void 0!==e.fps&&null!==e.fps&&(this.fps=e.fps),void 0!==e.bitrate)&&null!==e.bitrate&&(this.bitrate=e.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(e,t,i){this.streamName=e,this.applicationName=t,this.host=i}getStreamName(){return this.streamName}getApplicationName(){return this.applicationName}getHost(){return this.host}getType(){return ProtocolType.WEBRTC}}class RTSPSourceItem extends AbstractSourceItem{constructor(e,t,i,s,o,r){super(ProtocolType.RTSP,o),this.host=e,this.application=t,this.streamKey=i,this.port=s,this.defaultSource=r}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(e,t,i){this.PRINT_ON_STARTUP=!0,this.DEFAULT_STORM_PORT=443,this.IS_SSL_BY_DEFAULT=!0,this.serverList=new Array,this.sourceList=new Array,this.roleType=t,this.configurationType=i,this.parse(e,t)}parse(e,t){if(this.streamConfig=e,void 0===this.streamConfig||null===this.streamConfig)throw new Error("Stream configuration is missing. Please check stream config!");if(this.configurationType==ConfigurationType.EMBEDDED){if(t==RoleType.PLAYER){if(void 0===this.streamConfig.serverList||null===this.streamConfig.serverList)throw new Error("Server list configuration is missing. Please check stream config!");if(0===this.streamConfig.serverList.length)throw new Error("Server list configuration is empty. Please check stream config!");for(let o=0;o<this.streamConfig.serverList.length;o++){let e,t,i=this.DEFAULT_STORM_PORT,s=this.IS_SSL_BY_DEFAULT;if(void 0===this.streamConfig.serverList[o].host||null===this.streamConfig.serverList[o].host)throw new Error('Error while parsing server object ("host" filed is missing). Please check player config!');if(e=this.streamConfig.serverList[o].host,void 0===this.streamConfig.serverList[o].application||null===this.streamConfig.serverList[o].application)throw new Error('Error while parsing server object ("application" filed is missing). Please check player config!');t=this.streamConfig.serverList[o].application,void 0!==this.streamConfig.serverList[o].port&&null!==this.streamConfig.serverList[o].port&&(i=this.streamConfig.serverList[o].port),void 0!==this.streamConfig.serverList[o].ssl&&null!==this.streamConfig.serverList[o].ssl&&(s=this.streamConfig.serverList[o].ssl),this.serverList.push(new StormServerItem(e,t,i,s))}if(void 0===this.streamConfig.sourceList||null===this.streamConfig.sourceList)throw new Error("Source list configuration is missing. Please check player config!");if(0===this.streamConfig.sourceList.length)throw new Error("Source list configuration is missing. Please check player config!");for(let p=0;p<this.streamConfig.sourceList.length;p++){let f="none",m=!1;if(void 0===this.streamConfig.sourceList[p].protocol||null===this.streamConfig.sourceList[p].protocol)throw new Error('Error while parsing source object ("protocol" filed is missing). Please check player config!');switch(f=this.streamConfig.sourceList[p].protocol,void 0!==this.streamConfig.sourceList[p].default&&null!==this.streamConfig.sourceList[p].default&&(m=this.streamConfig.sourceList[p].default),f.toLowerCase()){case"storm":let e="",t=null;if(void 0===this.streamConfig.sourceList[p].streamKey||null===this.streamConfig.sourceList[p].streamKey)throw new Error('Missing "streamKey" parameter in stream source element');e=this.streamConfig.sourceList[p].streamKey,t=void 0!==this.streamConfig.sourceList[p].streamInfo&&null!==this.streamConfig.sourceList[p].streamInfo?this.streamConfig.sourceList[p].streamInfo:{label:"",width:0,height:0,fps:0,bitrate:0},this.sourceList.push(new StormSourceItem(e,new StreamInfo(t),m));break;case"rtmp":let i="",s="",o="",r=1935,a=null;if(void 0===this.streamConfig.sourceList[p].host||null===this.streamConfig.sourceList[p].host)throw new Error('Missing "host" parameter in stream source element');if(i=this.streamConfig.sourceList[p].host,void 0===this.streamConfig.sourceList[p].application||null===this.streamConfig.sourceList[p].application)throw new Error('Missing "application" parameter in stream source element');if(s=this.streamConfig.sourceList[p].application,void 0===this.streamConfig.sourceList[p].streamKey||null===this.streamConfig.sourceList[p].streamKey)throw new Error('Missing "streamName" parameter in stream source element');o=this.streamConfig.sourceList[p].streamKey,void 0!==this.streamConfig.sourceList[p].port&&null!==this.streamConfig.sourceList[p].port&&(r=this.streamConfig.sourceList[p].port),a=void 0!==this.streamConfig.sourceList[p].streamInfo&&null!==this.streamConfig.sourceList[p].streamInfo?this.streamConfig.sourceList[p].streamInfo:{label:"",width:0,height:0,fps:0,bitrate:0},this.sourceList.push(new RTMPSourceItem(i,s,o,r,new StreamInfo(a),m));break;case"rtsp":let n="",h="",l="",c=1935,g=null;if(void 0===this.streamConfig.sourceList[p].host||null===this.streamConfig.sourceList[p].host)throw new Error('Missing "host" parameter in stream source element');if(n=this.streamConfig.sourceList[p].host,void 0===this.streamConfig.sourceList[p].application||null===this.streamConfig.sourceList[p].application)throw new Error('Missing "application" parameter in stream source element');if(h=this.streamConfig.sourceList[p].application,void 0===this.streamConfig.sourceList[p].streamKey||null===this.streamConfig.sourceList[p].streamKey)throw new Error('Missing "streamName" parameter in stream source element');l=this.streamConfig.sourceList[p].streamKey,void 0!==this.streamConfig.sourceList[p].port&&null!==this.streamConfig.sourceList[p].port&&(c=this.streamConfig.sourceList[p].port),g=void 0!==this.streamConfig.sourceList[p].streamInfo&&null!==this.streamConfig.sourceList[p].streamInfo?this.streamConfig.sourceList[p].streamInfo:{label:"",width:0,height:0,fps:0,bitrate:0},this.sourceList.push(new RTSPSourceItem(n,h,l,c,new StreamInfo(g),m));break;case"webrtc":let d="",u=null;if(void 0===this.streamConfig.sourceList[p].streamKey||null===this.streamConfig.serverList[p].streamKey)throw new Error('Missing "streamName" parameter in stream source element');d=this.streamConfig.sourceList[p].streamKey,u=void 0!==this.streamConfig.sourceList[p].streamInfo&&null!==this.streamConfig.serverList[p].streamInfo?this.streamConfig.sourceList[p].streamKey:{label:"",width:0,height:0,fps:0,bitrate:0},this.sourceList.push(new WebRTCSourceItem(d,new StreamInfo(u),m));break;default:throw new Error("Error while parsing source object (unknown protocol). Please check player config!")}}}if(t==RoleType.STREAMER){if(void 0===this.streamConfig.publishData||null===this.streamConfig.publishData)throw new Error("Stream data configuration is missing. Please check player config!");if(void 0===this.streamConfig.publishData.protocol||null===this.streamConfig.publishData.protocol)throw new Error('Missing "protocol" field in stream data element. Please check player config!');if("webrtc"!==this.streamConfig.publishData.protocol.toLowerCase())throw new Error('Unknown "protocol" field in stream data element. Please check player config!');{let e,t,i;if(void 0===this.streamConfig.publishData.streamName||null===this.streamConfig.publishData.streamName)throw new Error("Stream data configuration is missing. Please check streamer config!");if(e=this.streamConfig.publishData.streamName,void 0===this.streamConfig.publishData.application||null===this.streamConfig.publishData.application)throw new Error("Stream data configuration is missing. Please check streamer config!");if(t=this.streamConfig.publishData.application,void 0===this.streamConfig.publishData.host||null===this.streamConfig.publishData.host)throw new Error("Stream data configuration is missing. Please check streamer config!");i=this.streamConfig.publishData.host,this.publishData=new WebRTCStreamItem(e,t,i)}}}else{if(this.configurationType!=ConfigurationType.GATEWAY)throw new Error("Unknown configurationType was defined in stream config!");if(void 0===this.streamConfig.serverList||null===this.streamConfig.serverList)throw new Error("Gateway server list configuration is missing. Please check player config!");if(0===this.streamConfig.serverList.length)throw new Error("Gateway server list configuration is empty. Please check player config!");for(let o=0;o<this.streamConfig.serverList.length;o++){let e,t,i=this.DEFAULT_STORM_PORT,s=this.IS_SSL_BY_DEFAULT;if(void 0===this.streamConfig.serverList[o].host||null===this.streamConfig.serverList[o].host)throw new Error('Error while parsing server object ("host" filed is missing). Please check player config!');if(e=this.streamConfig.serverList[o].host,void 0===this.streamConfig.serverList[o].application||null===this.streamConfig.serverList[o].application)throw new Error('Error while parsing server object ("application" filed is missing). Please check player config!');t=this.streamConfig.serverList[o].application,void 0!==this.streamConfig.serverList[o].port&&null!==this.streamConfig.serverList[o].port&&(i=this.streamConfig.serverList[o].port),void 0!==this.streamConfig.serverList[o].ssl&&null!==this.streamConfig.serverList[o].ssl&&(s=this.streamConfig.serverList[o].ssl),this.serverList.push(new StormServerItem(e,t,i,s))}if(void 0===this.streamConfig.streamKey||null===this.streamConfig.streamKey)throw new Error("StreamKey for gateway was not defined! Please check stream config!");this.streamKey=this.streamConfig.streamKey}void 0!==this.streamConfig.security&&null!==this.streamConfig.security?this.securityConfig=new SecurityConfig(this.streamConfig.security):this.securityConfig=new SecurityConfig(null)}getServerList(){return this.serverList}getSourceList(){return this.sourceList}getGatewayStreamKey(){return this.streamKey}getType(e){return e instanceof StormSourceItem?"StormSourceItem":e instanceof RTMPSourceItem?"RTMPSourceItem":"Object"}addSourceStream(e){let g;switch(this.getType(e)){case"StormSourceItem":case"RTMPSourceItem":g=e;break;case"Object":var d=e;let l="none",c=!1;if(void 0===d.protocol||null===d.protocol)throw new Error('Error while parsing source object ("protocol" filed is missing). Please check player config!');switch(l=d.protocol,void 0!==d.default&&null!==d.default&&(c=d.default),l.toLowerCase()){case"storm":let e="",t=null;if(void 0===d.streamKey||null===d.streamKey)throw new Error('Missing "streamKey" parameter in stream source element');e=d.streamKey,t=void 0!==d.streamInfo&&null!==d.streamInfo?d.streamInfo:{label:"",width:0,height:0,fps:0,bitrate:0},g=new StormSourceItem(e,new StreamInfo(t),c),this.sourceList.push(g);break;case"rtmp":let i="",s="",o="",r=1935,a=null;if(void 0===d.host||null===d.host)throw new Error('Missing "host" parameter in stream source element');if(i=d.host,void 0===d.application||null===d.application)throw new Error('Missing "application" parameter in stream source element');if(s=d.application,void 0===d.streamKey||null===d.streamKey)throw new Error('Missing "streamName" parameter in stream source element');o=d.streamKey,void 0!==d.port&&null!==d.port&&(r=d.port),a=void 0!==d.streamInfo&&null!==d.streamInfo?d.streamInfo:{label:"",width:0,height:0,fps:0,bitrate:0},g=new RTMPSourceItem(i,s,o,r,new StreamInfo(a),c),this.sourceList.push(g);break;case"webrtc":let n="",h=null;if(void 0===d.streamKey||null===d.streamKey)throw new Error('Missing "streamName" parameter in stream source element');n=d.streamKey,h=void 0!==d.streamInfo&&null!==d.streamInfo?d.streamKey:{label:"",width:0,height:0,fps:0,bitrate:0},g=new WebRTCSourceItem(n,new StreamInfo(h),c),this.sourceList.push(new WebRTCSourceItem(n,new StreamInfo(h),c));break;default:throw new Error("Error while parsing source object (unknown protocol). Please check player config!")}break;default:throw new Error("Incompatible type")}return g}getSecurityConfig(){return this.securityConfig}getPublishData(){return this.publishData}getConfigurationType(){return this.configurationType}setServerList(e){this.serverList=e}clearSourceList(){this.sourceList=new Array}setSourceList(e){this.sourceList=e}getRole(){return this.roleType}print(t){if(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1]){t.info(this,"Server List:");for(let e=0;e<this.serverList.length;e++)t.info(this,"=> ["+e+"] "+this.serverList[e].toString());t.info(this,"Stream List:");for(let e=0;e<this.sourceList.length;e++)t.info(this,"=> ["+e+"] "+this.sourceList[e].toString());this.securityConfig.print(t)}}}class BufferConfig{constructor(e){this.PRINT_ON_STARTUP=!0,this.minValue=.1,this.maxValue=2,this.startValue=.15,this.targetValue=.1,this.parse(e)}parse(e){this.bufferConfig=e,void 0!==this.bufferConfig&&null!==this.bufferConfig&&(void 0!==this.bufferConfig.minValue&&null!==this.bufferConfig.minValue&&(this.minValue=this.bufferConfig.minValue),void 0!==this.bufferConfig.maxValue&&null!==this.bufferConfig.maxValue&&(this.maxValue=this.bufferConfig.maxValue),void 0!==this.bufferConfig.startValue&&null!==this.bufferConfig.startValue&&(this.startValue=this.bufferConfig.startValue),void 0!==this.bufferConfig.targetValue)&&null!==this.bufferConfig.targetValue&&(this.targetValue=this.bufferConfig.targetValue)}getMinValue(){return this.minValue}getMaxValue(){return this.maxValue}getStartValue(){return this.startValue}getTargetValue(){return this.targetValue}setMinValue(e){this.minValue=e}setMaxValue(e){this.maxValue=e}setTargetValue(e){this.targetValue=e}setStartValue(e){this.startValue=e}setConfig(e){this.bufferConfig=e}print(e){(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1])&&e.info(this,"minValue: "+this.minValue+" | maxValue: "+this.maxValue+" | startValue: "+this.startValue+" | targetValue: "+this.targetValue)}}class StorageConfig{constructor(e){this.PRINT_ON_STARTUP=!0,this.storageEnabled=!0,this.prefix="",this.parse(e)}parse(e){this.storageConfig=e,void 0!==this.storageConfig&&null!==this.storageConfig&&(void 0!==this.storageConfig.enabled&&null!==this.storageConfig.enabled&&(this.storageEnabled=this.storageConfig.enabled),void 0!==this.storageConfig.prefix)&&null!==this.storageConfig.prefix&&(this.prefix=this.storageConfig.prefix)}isStorageEnabled(){return this.storageEnabled}setStorageEnabled(e){this.storageEnabled=e}getPrefix(){return this.prefix}setPrefix(e){this.prefix=e}setConfig(e){this.storageConfig=e}print(e){(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1])&&(e.info(this,"StorageConfig:: enabled: "+this.storageEnabled),e.info(this,'StorageConfig:: prefix: "'+this.prefix+'"'))}}!function(e){e[e.FILL=0]="FILL",e[e.LETTER_BOX=1]="LETTER_BOX",e[e.CROP=2]="CROP",e[e.ORIGINAL=3]="ORIGINAL"}(ScalingType=ScalingType||{});class VideoConfig{constructor(e){this.scalingMode=ScalingType.LETTER_BOX,this.aspectRatio="none",this.videoWidthValue=100,this.isVideoWidthInPixels=!1,this.wasVideoWidthProvided=!1,this.videoHeightValue=100,this.isVideoHeightInPixels=!1,this.wasVideoHeightProvided=!1,this.parse(e)}parse(e){if(this.videoConfig=e,void 0===this.videoConfig||null===this.videoConfig)throw new Error("Missing video configuration. Please check player config!");if(void 0!==this.videoConfig.aspectRatio&&null!==this.videoConfig.aspectRatio){var e=new RegExp("^[0-9]*\\.?[0-9]+:[0-9]*\\.?[0-9]+$"),t=this.videoConfig.aspectRatio;if(!e.test(t))throw new Error('Parameter "aspectRatio" - must match "number:number" pattern ');this.aspectRatio=t,this.aspectRatio=this.videoConfig.aspectRatio}if(void 0!==this.videoConfig.scalingMode&&null!==this.videoConfig.scalingMode)switch(this.videoConfig.scalingMode.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(void 0!==this.videoConfig.width){if(null===this.videoConfig.width)throw new Error('Parameter "width" cannot be empty');if("number"==typeof this.videoConfig.width)this.videoWidthValue=this.videoConfig.width,this.isVideoWidthInPixels=!0;else{if("string"!=typeof this.videoConfig.width)throw new Error('Unknown type for parameter "width" - it must be a number or a string! ');this.videoConfig.width.toLowerCase().endsWith("px")?(this.videoWidthValue=parseInt(this.videoConfig.width),this.isVideoWidthInPixels=!0):this.videoConfig.width.toLowerCase().endsWith("%")&&(this.videoWidthValue=parseInt(this.videoConfig.width),this.isVideoWidthInPixels=!1)}this.wasVideoWidthProvided=!0}if(void 0!==this.videoConfig.height){if(null===this.videoConfig.height)throw new Error('Parameter "height" cannot be empty');if("number"==typeof this.videoConfig.height)this.videoHeightValue=this.videoConfig.height,this.isVideoHeightInPixels=!0;else{if("string"!=typeof this.videoConfig.height)throw new Error('Unknown type for parameter "height" - it must be a number or a string!');this.videoConfig.height.toLowerCase().endsWith("px")?(this.videoHeightValue=parseInt(this.videoConfig.height),this.isVideoHeightInPixels=!0):this.videoConfig.height.toLowerCase().endsWith("%")&&(this.videoHeightValue=parseInt(this.videoConfig.height),this.isVideoHeightInPixels=!1)}this.wasVideoHeightProvided=!0}if(void 0===this.videoConfig.containerID||null===this.videoConfig.containerID)throw new Error("No video object name was provided for this player. Please check player config!");if(this.containerID=this.videoConfig.containerID,null===document.getElementById(this.containerID))throw new Error('No video object with id "'+this.containerID+'" was found for this player. Please check player config!')}getScalingMode(){return this.scalingMode}setConfig(e){this.videoConfig=e}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(e){this.videoWidthValue=e}setIfVideoWidthInPixels(e){this.isVideoWidthInPixels=e}setVideoHeightValue(e){this.videoHeightValue=e}setIfVideoHeightInPixels(e){this.isVideoHeightInPixels=e}setContainerID(e){this.containerID=e}setScalingMode(e){switch(e.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(e){let t="";switch(this.scalingMode){case ScalingType.FILL:t="fill";break;case ScalingType.LETTER_BOX:t="letterbox";break;case ScalingType.CROP:t="crop";break;case ScalingType.ORIGINAL:t="original"}e.info(this,"VideoConfig :: containerID: "+this.containerID),e.info(this,"VideoConfig :: scalingMode: "+t),e.info(this,"VideoConfig :: width: "+this.videoWidthValue+(this.isVideoWidthInPixels?"px":"%")+(this.wasVideoWidthProvided?" (provided)":" (default)")),e.info(this,"VideoConfig :: height: "+this.videoHeightValue+(this.isVideoHeightInPixels?"px":"%")+(this.wasVideoHeightProvided?" (provided)":" (default)"))}}!function(e){e[e.TRACE=0]="TRACE",e[e.INFO=1]="INFO",e[e.SUCCESS=2]="SUCCESS",e[e.WARNING=3]="WARNING",e[e.ERROR=4]="ERROR"}(LogType=LogType||{});class DebugConfig{constructor(e){this.PRINT_ON_STARTUP=!0,this.consoleEnabled=!1,this.consoleLogTypes=[LogType.INFO,LogType.ERROR,LogType.SUCCESS,LogType.TRACE,LogType.WARNING],this.consoleMonoColor=!1,this.containerEnabled=!1,this.containerLogTypes=[LogType.INFO,LogType.ERROR,LogType.SUCCESS,LogType.TRACE,LogType.WARNING],this.containerMonoColor=!1,this.parse(e)}parse(e){if(this.debugConfig=e,void 0!==this.debugConfig&&null!==this.debugConfig){if(void 0!==this.debugConfig.console&&null!=this.debugConfig.console){var t=this.debugConfig.console;if(void 0!==t.enabled&&null!==t.enabled&&(this.consoleEnabled=t.enabled),void 0!==t.logTypes&&null!==t.logTypes&&0!==t.logTypes.length){this.consoleLogTypes=new Array;for(let e=0;e<t.logTypes.length;e++)switch(t.logTypes[e].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)}}void 0!==t.monoColor&&null!==t.monoColor&&(this.consoleMonoColor=t.monoColor)}if(void 0!==this.debugConfig.container&&null!=this.debugConfig.container){var i=this.debugConfig.container;if(void 0!==i.enabled&&null!==i.enabled&&(this.containerEnabled=i.enabled),void 0!==i.logTypes&&null!==i.logTypes&&0!==i.logTypes.length){this.containerLogTypes=new Array;for(let e=0;e<i.logTypes.length;e++)switch(i.logTypes[e].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)}}void 0!==i.monoColor&&null!==i.monoColor&&(this.containerMonoColor=i.monoColor),void 0!==i.containerID&&null!==i.containerID&&(this.containerID=i.containerID)}}}isConsoleEnabled(){return this.consoleEnabled}setConsoleEnabled(e){this.consoleEnabled=e}getConsoleLogTypes(){return this.consoleLogTypes}setConsoleLogTypes(t){this.consoleLogTypes=new Array;for(let e=0;e<t.length;e++)switch(t[e].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)}}isContainerEnabled(){return this.containerEnabled}setContainerEnabled(e){this.consoleEnabled=e}isConsoleMonoColor(){return this.consoleMonoColor}setConsoleMonoColor(e){this.consoleMonoColor=e}getContainerLogTypes(){return this.containerLogTypes}setContainerLogTypes(t){this.containerLogTypes=new Array;for(let e=0;e<t.length;e++)switch(t[e].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)}}getContainerID(){return this.containerID}setContainerID(e){this.containerID=e}isContainerMonoColor(){return this.containerMonoColor}setContainerMonoColor(e){this.containerMonoColor=e}setConfig(e){this.debugConfig=e}print(e){if(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1]){let t="";for(let e=0;e<this.consoleLogTypes.length;e++)switch(this.consoleLogTypes[e]){case LogType.TRACE:t+="TRACE, ";break;case LogType.SUCCESS:t+="SUCCESS, ";break;case LogType.WARNING:t+="WARNING, ";break;case LogType.INFO:t+="INFO, ";break;case LogType.ERROR:t+="ERROR, "}e.info(this,"Console:: enabled: "+this.consoleEnabled),e.info(this,"Console:: logTypes: "+t),e.info(this,"Console:: monoColor: "+this.consoleMonoColor);let i="";for(let e=0;e<this.containerLogTypes.length;e++)switch(this.containerLogTypes[e]){case LogType.TRACE:i+="TRACE, ";break;case LogType.SUCCESS:i+="SUCCESS, ";break;case LogType.WARNING:i+="WARNING, ";break;case LogType.INFO:i+="INFO, ";break;case LogType.ERROR:i+="ERROR, "}e.info(this,"Container:: enabled: "+this.containerEnabled),e.info(this,"Container:: logTypes: "+i),e.info(this,"Container:: containerID: "+this.containerID),e.info(this,"Container:: monoColor: "+this.consoleMonoColor)}}}class AudioConfig{constructor(e){this.PRINT_ON_STARTUP=!0,this.startVolume=100,this.maxVolume=100,this.rememberValue=!0,this.parse(e)}parse(e){this.volumeConfig=e,void 0!==this.volumeConfig&&null!==this.volumeConfig&&(void 0!==this.volumeConfig.startVolume&&null!==this.volumeConfig.startVolume&&(this.startVolume=this.volumeConfig.startVolume),void 0!==this.volumeConfig.maxVolume&&null!==this.volumeConfig.maxVolume&&(this.maxVolume=this.volumeConfig.maxVolume),void 0!==this.volumeConfig.rememberValue)&&null!==this.volumeConfig.rememberValue&&(this.rememberValue=this.volumeConfig.rememberValue)}getStartVolume(){return this.startVolume}setStartVolume(e){this.startVolume=e}getMaxVolume(){return this.maxVolume}setMaxVolume(e){this.maxVolume=e}isRememberValue(){return this.rememberValue}setRememberValue(e){this.rememberValue=e}setConfig(e){this.volumeConfig=e}print(e){(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1])&&e.info(this,"Audio :: startVolume: "+this.startVolume+" | maxVolume: "+this.maxVolume+" | rememberValue: "+this.rememberValue)}}class SettingsConfig{constructor(e){this.PRINT_ON_STARTUP=!0,this.restartOnError=!1,this.reconnectTime=3,this.autoStart=!1,this.autoConnect=!0,this.startOnDOMReady=!1,this.iOSOnDomReadyFix=!0,this.enabledProtocols=new Array(ProtocolType.STORM,ProtocolType.RTMP,ProtocolType.HLS),this.restartOnFocus=!0,this.parse(e)}parse(e){if(this.settingsConfig=e,void 0!==this.settingsConfig.autoConnect&&null!==this.settingsConfig.autoConnect&&(this.autoConnect=this.settingsConfig.autoConnect),void 0!==this.settingsConfig.autoStart&&null!==this.settingsConfig.autoStart&&(this.autoStart=this.settingsConfig.autoStart),void 0!==this.settingsConfig.restartOnFocus&&null!==this.settingsConfig.restartOnFocus&&(this.restartOnFocus=this.settingsConfig.restartOnFocus),void 0!==this.settingsConfig.restartOnError&&null!==this.settingsConfig.restartOnError&&(this.restartOnError=this.settingsConfig.restartOnError),void 0!==this.settingsConfig.reconnectTime&&null!==this.settingsConfig.reconnectTime&&(this.reconnectTime=this.settingsConfig.reconnectTime),void 0!==this.settingsConfig.enabledProtocols&&null!==this.settingsConfig.enabledProtocols){var t=this.settingsConfig.enabledProtocols;if(0===t.length)throw new Error('Missing "enabledProtocols" field. Please check your player config!');this.enabledProtocols=new Array;for(let e=0;e<t.length;e++)switch(t[e].toLowerCase()){case"storm":this.enabledProtocols.push(ProtocolType.STORM);break;case"hls":this.enabledProtocols.push(ProtocolType.HLS);break;case"webrtc":this.enabledProtocols.push(ProtocolType.WEBRTC);break;default:throw new Error('Unknown protocol "'+t[e]+'". Please check your player config!')}}void 0!==this.settingsConfig.buffer&&null!==this.settingsConfig.buffer?this.bufferConfig=new BufferConfig(this.settingsConfig.buffer):this.bufferConfig=new BufferConfig(null),void 0!==this.settingsConfig.storage&&null!==this.settingsConfig.storage?this.storageConfig=new StorageConfig(this.settingsConfig.storage):this.storageConfig=new StorageConfig(null),void 0!==this.settingsConfig.video&&null!==this.settingsConfig.video?this.videoConfig=new VideoConfig(this.settingsConfig.video):this.videoConfig=new VideoConfig(null),void 0!==this.settingsConfig.audio&&null!==this.settingsConfig.audio?this.audioConfig=new AudioConfig(this.settingsConfig.volume):this.audioConfig=new AudioConfig(null),void 0!==this.settingsConfig.debug&&null!==this.settingsConfig.debug?this.debugConfig=new DebugConfig(this.settingsConfig.debug):this.debugConfig=new DebugConfig(null)}getEnabledProtocols(){return this.enabledProtocols}getIfProtocolEnabled(e){return 0<=this.enabledProtocols.indexOf(e)}getBufferConfig(){return this.bufferConfig}getAudioConfig(){return this.audioConfig}getVideoConfig(){return this.videoConfig}getIfRestartOnError(){return this.restartOnError}getReconnectTime(){return this.reconnectTime}getIfAutoStart(){return this.autoStart}setAutoStart(e){this.autoStart=e}getIfAutoConnect(){return this.autoConnect}getIfRestartOnFocus(){return this.restartOnFocus}getDebugConfig(){return this.debugConfig}getStorageConfig(){return this.storageConfig}setConfig(e){this.settingsConfig=e}getIfStartOnDOMReadyEnabled(){return this.startOnDOMReady}getIfIOSOnDomStartFixEnabled(){return this.iOSOnDomReadyFix}print(e){if(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1]){let t="";for(let e=0;e<this.enabledProtocols.length;e++)switch(this.enabledProtocols[e]){case ProtocolType.WEB_SOCKETS:t+="WebSockets, ";break;case ProtocolType.HLS:t+="HLS, ";break;case ProtocolType.WEBRTC:t+="WebRTC, "}e.info(this,"SettingsConfig :: autoStart: "+this.autoStart),e.info(this,"SettingsConfig :: restartOnError: "+this.restartOnError),e.info(this,"SettingsConfig :: reconnectTime: "+this.reconnectTime),e.info(this,"SettingsConfig :: enabledProtocols: "+t),this.bufferConfig.print(e),this.videoConfig.print(e),this.audioConfig.print(e),this.storageConfig.print(e),this.debugConfig.print(e)}}}class ConfigManager{constructor(e){this.PRINT_ON_STARTUP=!0,this.roleType=RoleType.PLAYER,this.demoMode=!1,this.parse(e)}parse(e){if(this.config=e,void 0!==this.config.role&&null!==this.config.role)switch(this.config.role.toLowerCase()){case"player":this.roleType=RoleType.PLAYER;break;case"streamer":this.roleType=RoleType.STREAMER;break;default:throw new Error('Unknown config role:"'+this.config.role+'"')}if(void 0!==this.config.configurationType&&null!==this.config.configurationType)switch(this.config.configurationType.toLowerCase()){case"embedded":this.configurationType=ConfigurationType.EMBEDDED;break;case"gateway":this.configurationType=ConfigurationType.GATEWAY;break;default:throw new Error('Unknown config type:"'+this.configurationType+'"')}else this.configurationType=ConfigurationType.GATEWAY;if(void 0===this.config.stream||null===this.config.stream)throw new Error("No stream field was provided. Please check your player config!");this.stream=new StreamConfig(this.config.stream,this.roleType,this.configurationType),void 0!==this.config.settings&&null!==this.config.settings?this.settings=new SettingsConfig(this.config.settings):this.settings=new SettingsConfig(null),void 0!==this.config.demoMode&&null!==this.config.demoMode&&(this.demoMode=this.config.demoMode)}getConfigurationType(){return this.configurationType}getRole(){return this.roleType}getStream(){return this.stream}getSettings(){return this.settings}setConfig(e){this.config=e}getIfDemoMode(){return this.demoMode}print(e){(this.PRINT_ON_STARTUP||1<arguments.length&&void 0!==arguments[1]&&arguments[1])&&(this.stream.print(e),this.settings.print(e))}}class EventDispatcher{constructor(){this.listeners={}}addEventListener(t,i){var e=!(2<arguments.length&&void 0!==arguments[2])||arguments[2];this.listeners[t]||(this.listeners[t]=[]);let s=!1;if(null!=this.listeners[t]&&0<this.listeners[t].length)for(let e=0;e<this.listeners[t].length;e++)if(this.listeners[t][e][1]==i){s=!0;break}return this.logger.success(this,"Registering a new event: "+t),!s&&(this.listeners[t].push([t,i,e]),!0)}removeEventListener(t,i){let s=!1;if(null!=this.listeners[t]&&0<this.listeners[t].length)for(let e=0;e<this.listeners[t].length;e++){var o=this.listeners[t][e];if(i){if(o[1]==i){if(1!=o[2])break;s=!0,this.listeners[t].splice(e,1);break}}else s=!0,1==o[2]&&this.listeners[t].splice(e,1)}return this.logger.success(this,"Removing listener: "+t),s}removeAllEventListeners(){for(var e in this.logger.success(this,"Removing all listeners!"),this.listeners){var t=this.listeners[e];if(0<t.length)for(let e=0;e<t.length;e++)1==t[e][2]&&t.splice(e,1)}}dispatchEvent(t,i){if(null!=this.listeners[t]&&0<this.listeners[t].length)for(let e=0;e<this.listeners[t].length;e++)this.listeners[t][e][1].call(this,i)}}class NumberUtilities{static addLeadingZero(e){return e<10?"0"+e:String(e)}static generateUniqueString(t){let i="";var s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=s.length;for(let e=0;e<t;e++)i+=s.charAt(Math.floor(Math.random()*o));return i}}class Logger{constructor(e,t){this.colorOrder=["red","green","blue","orange","black","violet"],this.logMemory=[],this.libraryInstanceID=-1,this.playerInstanceID=-1,this.debugConfig=e,this.stormPlayer=t,this.libraryInstanceID=this.stormPlayer.getLibraryID();e=this.colorOrder.length<t.getLibraryID()?this.colorOrder.length-1:t.getLibraryID();this.monoColor=this.colorOrder[e]}info(e,t){e=this.logData(e,t);this.debugConfig.isConsoleEnabled()&&0<=this.debugConfig.getConsoleLogTypes().indexOf(LogType.INFO)&&(t=this.debugConfig.isConsoleMonoColor()?this.monoColor:Logger.INFO_COLOR,console.log("%c "+e,"color: "+t)),this.debugConfig.isContainerEnabled()&&0<=this.debugConfig.getContainerLogTypes().indexOf(LogType.INFO)&&(t=this.debugConfig.isContainerMonoColor()?this.monoColor:Logger.INFO_COLOR,this.writeToContainer(e,t))}warning(e,t){e=this.logData(e,t);this.debugConfig.isConsoleEnabled()&&0<=this.debugConfig.getConsoleLogTypes().indexOf(LogType.WARNING)&&(t=this.debugConfig.isConsoleMonoColor()?this.monoColor:Logger.WARNING_COLOR,console.log("%c "+e,"color: "+t)),this.debugConfig.isContainerEnabled()&&0<=this.debugConfig.getContainerLogTypes().indexOf(LogType.WARNING)&&(t=this.debugConfig.isContainerMonoColor()?this.monoColor:Logger.WARNING_COLOR,this.writeToContainer(e,t))}error(e,t){e=this.logData(e,t);this.debugConfig.isConsoleEnabled()&&0<=this.debugConfig.getConsoleLogTypes().indexOf(LogType.ERROR)&&(t=this.debugConfig.isConsoleMonoColor()?this.monoColor:Logger.ERROR_COLOR,console.log("%c "+e,"color: "+t)),this.debugConfig.isContainerEnabled()&&0<=this.debugConfig.getContainerLogTypes().indexOf(LogType.ERROR)&&(t=this.debugConfig.isContainerMonoColor()?this.monoColor:Logger.ERROR_COLOR,this.writeToContainer(e,t))}success(e,t){e=this.logData(e,t);this.debugConfig.isConsoleEnabled()&&0<=this.debugConfig.getConsoleLogTypes().indexOf(LogType.SUCCESS)&&(t=this.debugConfig.isConsoleMonoColor()?this.monoColor:Logger.SUCCESS_COLOR,console.log("%c "+e,"color: "+t)),this.debugConfig.isContainerEnabled()&&0<=this.debugConfig.getContainerLogTypes().indexOf(LogType.SUCCESS)&&(t=this.debugConfig.isContainerMonoColor()?this.monoColor:Logger.SUCCESS_COLOR,this.writeToContainer(e,t))}trace(e,t){e=this.logData(e,t);this.debugConfig.isConsoleEnabled()&&0<=this.debugConfig.getConsoleLogTypes().indexOf(LogType.TRACE)&&(t=this.debugConfig.isConsoleMonoColor()?this.monoColor:Logger.TRACE_COLOR,console.log("%c "+e,"color: "+t)),this.debugConfig.isContainerEnabled()&&0<=this.debugConfig.getContainerLogTypes().indexOf(LogType.TRACE)&&(t=this.debugConfig.isContainerMonoColor()?this.monoColor:Logger.TRACE_COLOR,this.writeToContainer(e,t))}logData(e,t){var i=new Date,s=NumberUtilities.addLeadingZero(i.getHours()),o=NumberUtilities.addLeadingZero(i.getMinutes()),i=NumberUtilities.addLeadingZero(i.getSeconds());let r=String(this.libraryInstanceID);0<=this.playerInstanceID&&(r+="|"+this.playerInstanceID);s="(Storm) [ID:"+r+"] ["+s+":"+o+":"+i+"] :: "+t;return this.logMemory.push(s),s}writeToContainer(e,t){var i=this.debugConfig.getContainerID(),i=document.getElementById(i),s=document.createElement("span");s.innerText=e,s.style.color=t,i.appendChild(s)}setPlayerID(e){this.playerInstanceID=e}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(e){this.bandwidthCapabilities=e}getBandwidthCapabilities(){return this.bandwidthCapabilities}}!function(e){e.NOT_INITIALIZED="notInitialized",e.INITIALIZED="initialized",e.STARTED="started",e.BUFFERING="buffering",e.PLAYING="playing",e.PAUSED="paused",e.STOPPED="stopped",e.DISCONNECTED="disconnected",e.DESTROYED="destroyed"}(LibraryState=LibraryState||{});var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var FUNC_ERROR_TEXT="Expected a function",NAN=NaN,symbolTag="[object Symbol]",reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,freeParseInt=parseInt,freeGlobal="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,freeSelf="object"==typeof self&&self&&self.Object===Object&&self,root=freeGlobal||freeSelf||Function("return this")(),objectProto=Object.prototype,objectToString=objectProto.toString,nativeMax=Math.max,nativeMin=Math.min,now=function(){return root.Date.now()};function debounce(s,i,e){var o,r,a,n,h,l,c=0,g=!1,d=!1,t=!0;if("function"!=typeof s)throw new TypeError(FUNC_ERROR_TEXT);function u(e){var t=o,i=r;return o=r=void 0,c=e,n=s.apply(i,t)}function f(e){var t=e-l;return void 0===l||i<=t||t<0||d&&a<=e-c}function m(){var e,t=now();if(f(t))return p(t);h=setTimeout(m,(e=i-((t=t)-l),d?nativeMin(e,a-(t-c)):e))}function p(e){return h=void 0,t&&o?u(e):(o=r=void 0,n)}function y(){var e=now(),t=f(e);if(o=arguments,r=this,l=e,t){if(void 0===h)return c=e=l,h=setTimeout(m,i),g?u(e):n;if(d)return h=setTimeout(m,i),u(l)}return void 0===h&&(h=setTimeout(m,i)),n}return i=toNumber(i)||0,isObject(e)&&(g=!!e.leading,d="maxWait"in e,a=d?nativeMax(toNumber(e.maxWait)||0,i):a,t="trailing"in e?!!e.trailing:t),y.cancel=function(){void 0!==h&&clearTimeout(h),o=l=r=h=void(c=0)},y.flush=function(){return void 0===h?n:p(now())},y}function isObject(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function isObjectLike(e){return!!e&&"object"==typeof e}function isSymbol(e){return"symbol"==typeof e||isObjectLike(e)&&objectToString.call(e)==symbolTag}function toNumber(e){if("number"==typeof e)return e;if(isSymbol(e))return NAN;if("string"!=typeof(e=isObject(e)?isObject(t="function"==typeof e.valueOf?e.valueOf():e)?t+"":t:e))return 0===e?e:+e;e=e.replace(reTrim,"");var t=reIsBinary.test(e);return t||reIsOctal.test(e)?freeParseInt(e.slice(2),t?2:8):reIsBadHex.test(e)?NAN:+e}var ConnectionState,PlayerType,PlaybackState,lodash_debounce=debounce,debounce$1=getDefaultExportFromCjs(debounce);class VideoContainer{constructor(e){this.LOG_ACTIVITY=!0,this.videoWidth=0,this.videoHeight=0,this.wasUnmuted=!1,this.isMuted=!1,this.currentVolume=100,this.forceMute=!1,this.isInFullScreenMode=!1,this.hadPlayed=!1,this.onResize=()=>{var e,t;null!=this.parentContainer&&(this.tempContainerWidth=this.parentContainer.getBoundingClientRect().width,this.tempContainerHeight=this.parentContainer.getBoundingClientRect().height,e=this.main.getConfigManager().getSettings().getVideoConfig().getIfVideoWidthInPixels(),t=this.main.getConfigManager().getSettings().getVideoConfig().getIfVideoHeightInPixels(),e&&t||(this.resizeVideo(),this.scaleVideo()))},this.main=e,this.containerID=e.getConfigManager().getSettings().getVideoConfig().getContainerID(),this.logger=e.getLogger(),this.initialize()}initialize(){const e=this;if(null==document.getElementById(this.containerID))throw new Error("No parent element for the storm library was defined!");if(this.parentContainer=document.getElementById(this.containerID),this.videoContainer=document.createElement("div"),null==this.parentContainer)throw new Error("No parent element for the storm library was defined!");this.parentContainer.appendChild(this.videoContainer),this.videoElement=document.createElement("video"),this.videoContainer.appendChild(this.videoElement),this.isInFullScreenMode=!1,this.videoContainer.setAttribute("id","stormLibrary_"+this.main.getLibraryID()),this.videoContainer.style.overflow="hidden",this.videoContainer.style.position="relative",this.videoContainer.classList.add("stormLibrary"),this.videoElement.style.objectFit="fill",this.resizeObserver=new ResizeObserver(debounce$1(()=>this.onResize(),250,{leading:!1,trailing:!0})),this.parentContainer.addEventListener("transitionend",()=>{this.onResize()}),this.configureVideoElement(),this.attachEvents(),this.resizeVideo(),this.scaleVideo(),this.resizeObserver.observe(this.parentContainer),this.main.addEventListener("metadataReceived",e=>{this.videoWidth=e.metadata.getVideoWidth(),this.videoHeight=e.metadata.getVideoHeight(),this.scaleVideo()}),document.addEventListener("fullscreenchange",function(){e.onFullScreenChange()},!1),document.addEventListener("webkitfullscreenchange",function(){e.onFullScreenChange()},!1),document.addEventListener("mozfullscreenchange",function(){e.onFullScreenChange()},!1),document.addEventListener("webkitendfullscreen",function(){e.onFullScreenChange()},!1),this.videoElement.addEventListener("webkitendfullscreen",function(){e.onFullScreenChange()},!1)}onFullScreenChange(){null==document.fullscreenElement?(this.isInFullScreenMode=!1,this.logger.info(this,"The library has exited FullScreen mode!"),this.main.dispatchEvent("fullScreenExit",{ref:this.main})):(this.isInFullScreenMode=!0,this.logger.info(this,"The library has entered FullScreen mode!"),this.main.dispatchEvent("fullScreenEnter",{ref:this.main}))}configureVideoElement(){var e=this.main.getConfigManager().getSettings().getIfAutoStart(),t=this.main.getConfigManager().getSettings().getAudioConfig().getStartVolume();this.main.getStorageManager().getField("playerVolume")?this.currentVolume=Number(this.main.getStorageManager().getField("playerVolume")):this.currentVolume=t,e&&!this.wasUnmuted&&(this.isMuted=!0,this.forceMute=!0),this.videoElement.setAttribute("playsinline","playsinline"),this.videoElement.setAttribute("webkit-playsinline","webkit-playsinline"),this.videoElement.muted=this.isMuted,this.videoElement.volume=this.currentVolume/100,this.main.dispatchEvent("videoElementCreate",{ref:this.main,videoElement:this.videoElement})}attachEvents(){let s=this;this.videoElement.onload=function(){},LibraryState.PLAYING,this.videoElement.onerror=function(e){},this.videoElement.onvolumechange=function(e){s.dispatchVolumeEvent()},this.videoElement.ontimeupdate=function(e){var t=s.videoElement.videoWidth,i=s.videoElement.videoHeight;0==t||0==i||t===s.videoWidth&&i===s.videoHeight||(s.videoWidth=t,s.videoHeight=i,s.scaleVideo())},this.videoElement.onended=function(e){}}resizeVideo(){var e=this.main.getConfigManager().getSettings().getVideoConfig().getIfVideoWidthInPixels(),t=this.main.getConfigManager().getSettings().getVideoConfig().getIfVideoHeightInPixels(),i=this.main.getConfigManager().getSettings().getVideoConfig().getVideoWidthValue(),s=this.main.getConfigManager().getSettings().getVideoConfig().getVideoHeightValue(),o=this.main.getConfigManager().getSettings().getVideoConfig().getAspectRatio();let r=0,a=0;var n=Number(o.split(":")[0]),h=Number(o.split(":")[1]);"none"==o?(e?r=i:null!=this.parentContainer&&(r=this.tempContainerWidth*i/100),t?a=s:null!=this.parentContainer&&(a=this.tempContainerHeight*s/100)):(e?r=i:null!=this.parentContainer&&(r=this.tempContainerWidth*i/100),a=r*h/n),this.containerWidth=r,this.containerHeight=a,null!==this.videoContainer&&(this.videoContainer.style.width=r+"px",this.videoContainer.style.height=a+"px")}scaleVideo(){if(this.scalingMode=this.main.getConfigManager().getSettings().getVideoConfig().getScalingMode(),null!==this.videoElement){let e=0,t=0,i=0,s=0;switch(this.scalingMode){case ScalingType.FILL:i=this.containerWidth,s=this.containerHeight;break;case ScalingType.CROP:i=this.containerWidth,(s=this.videoHeight*this.containerWidth/this.videoWidth)>=this.containerHeight?(e=0,t=(s-this.containerHeight)/2*-1):(s=this.containerHeight,i=this.videoWidth*this.containerHeight/this.videoHeight,t=0,e=(i-this.containerWidth)/2*-1);break;case ScalingType.LETTER_BOX:i=this.containerWidth,(!((s=this.videoHeight*this.containerWidth/this.videoWidth)<=this.containerHeight)||(e=0,t=(s-this.containerHeight)/2*-1,s>this.containerHeight))&&(s=this.containerHeight,i=this.videoWidth*this.containerHeight/this.videoHeight,t=0,e=(i-this.containerWidth)/2*-1);break;case ScalingType.ORIGINAL:i=this.videoWidth,s=this.videoHeight,e=(this.videoWidth-this.containerWidth)/-2,t=(this.videoHeight-this.containerHeight)/-2}this.videoElement.style.left=Math.floor(e)+"px",this.videoElement.style.top=Math.floor(t)+"px",this.videoElement.style.width=Math.ceil(i)+"px",this.videoElement.style.height=Math.ceil(s)+"px",this.videoElement.style.position="absolute"}}dispatchVolumeEvent(){var e=this.forceMute?"browser":"user",t={volume:100*this.videoElement.volume,isMuted:this.videoElement.muted,type:e};this.LOG_ACTIVITY&&this.logger.info(this,"VideoContainer :: Event: onVolumeChange: "+JSON.stringify(t)),this.main.dispatchEvent("volumeChange",{ref:this.main,mode:"mse",volume:100*this.videoElement.volume,muted:this.videoElement.muted,invokedBy:e})}play(){let t=this;this.videoElement.play().then(e=>function(){}).catch(function(e){"NotAllowedError"===e.name&&(t.videoElement.muted=!0,t.forceMute=!0,t.videoElement.setAttribute("playsinline","playsinline"),t.videoElement.setAttribute("webkit-playsinline","webkit-playsinline"),t.wasUnmuted=!1,t.isMuted=!0,t.dispatchVolumeEvent(),t.player)&&t.player.restart()})}mute(){this.isMuted=!0,null!==this.videoElement&&(this.videoElement.muted=this.isMuted)}unmute(){var e;this.wasUnmuted=!0,this.isMuted=!1,this.forceMute=!1,null!==this.videoElement&&(e=this.videoElement.paused,this.videoElement.muted=!1,e!=this.videoElement.paused?this.main.dispatchEvent("interactionRequired",{ref:this.main,mode:"mse"}):this.main.dispatchEvent("videoUnmuted",{ref:this.main}))}setVolume(e){this.isMuted=!1,this.wasUnmuted=!0,this.forceMute=!1,this.currentVolume=e,null!==this.videoElement&&(this.videoElement.volume=e/100),this.main.getStorageManager().saveField("playerVolume",String(e))}getVolume(){return null!==this.videoElement?100*this.videoElement.volume:100}getVideoObject(){return this.videoElement}destroy(){this.LOG_ACTIVITY&&this.logger.info(this,"VideoContainer :: s