@epicgames-ps/lib-pixelstreamingfrontend-ue5.5 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib-pixelstreamingfrontend.esm.js +1 -1
- package/dist/lib-pixelstreamingfrontend.js +1 -1
- package/package.json +3 -2
- package/src/PixelStreaming/PixelStreaming.ts +2 -3
- package/src/UI/OnScreenKeyboard.ts +1 -2
- package/src/Util/EventEmitter.ts +2 -2
- package/src/WebRtcPlayer/WebRtcPlayerController.ts +37 -34
- package/types/PixelStreaming/PixelStreaming.d.ts +1 -2
- package/types/UI/OnScreenKeyboard.d.ts +1 -2
- package/types/Util/EventEmitter.d.ts +2 -2
- package/types/WebRtcPlayer/WebRtcPlayerController.d.ts +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("sdp")):"function"==typeof define&&define.amd?define(["sdp"],t):"object"==typeof exports?exports["lib-pixelstreamingfrontend"]=t(require("sdp")):e["lib-pixelstreamingfrontend"]=t(e.sdp)}(this,(e=>(()=>{"use strict";var t={187:e=>{var t,s="object"==typeof Reflect?Reflect:null,n=s&&"function"==typeof s.apply?s.apply:function(e,t,s){return Function.prototype.apply.call(e,t,s)};t=s&&"function"==typeof s.ownKeys?s.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise((function(s,n){function r(s){e.removeListener(t,i),n(s)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",r),s([].slice.call(arguments))}p(e,t,i,{once:!0}),"error"!==t&&function(e,t,s){"function"==typeof e.on&&p(e,"error",t,{once:!0})}(e,r)}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var o=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function d(e,t,s,n){var r,i,o,d;if(a(s),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,s.listener?s.listener:s),i=e._events),o=i[t]),void 0===o)o=i[t]=s,++e._eventsCount;else if("function"==typeof o?o=i[t]=n?[s,o]:[o,s]:n?o.unshift(s):o.push(s),(r=l(e))>0&&o.length>r&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=o.length,d=c,console&&console.warn&&console.warn(d)}return e}function c(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function h(e,t,s){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:s},r=c.bind(n);return r.listener=s,n.wrapFn=r,r}function u(e,t,s){var n=e._events;if(void 0===n)return[];var r=n[t];return void 0===r?[]:"function"==typeof r?s?[r.listener||r]:[r]:s?function(e){for(var t=new Array(e.length),s=0;s<t.length;++s)t[s]=e[s].listener||e[s];return t}(r):m(r,r.length)}function g(e){var t=this._events;if(void 0!==t){var s=t[e];if("function"==typeof s)return 1;if(void 0!==s)return s.length}return 0}function m(e,t){for(var s=new Array(t),n=0;n<t;++n)s[n]=e[n];return s}function p(e,t,s,n){if("function"==typeof e.on)n.once?e.once(t,s):e.on(t,s);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function r(i){n.once&&e.removeEventListener(t,r),s(i)}))}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return l(this)},i.prototype.emit=function(e){for(var t=[],s=1;s<arguments.length;s++)t.push(arguments[s]);var r="error"===e,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var l=i[e];if(void 0===l)return!1;if("function"==typeof l)n(l,this,t);else{var d=l.length,c=m(l,d);for(s=0;s<d;++s)n(c[s],this,t)}return!0},i.prototype.addListener=function(e,t){return d(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return d(this,e,t,!0)},i.prototype.once=function(e,t){return a(t),this.on(e,h(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,h(this,e,t)),this},i.prototype.removeListener=function(e,t){var s,n,r,i,o;if(a(t),void 0===(n=this._events))return this;if(void 0===(s=n[e]))return this;if(s===t||s.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,s.listener||t));else if("function"!=typeof s){for(r=-1,i=s.length-1;i>=0;i--)if(s[i]===t||s[i].listener===t){o=s[i].listener,r=i;break}if(r<0)return this;0===r?s.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(s,r),1===s.length&&(n[e]=s[0]),void 0!==n.removeListener&&this.emit("removeListener",e,o||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,s,n;if(void 0===(s=this._events))return this;if(void 0===s.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==s[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete s[e]),this;if(0===arguments.length){var r,i=Object.keys(s);for(n=0;n<i.length;++n)"removeListener"!==(r=i[n])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=s[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},i.prototype.listeners=function(e){return u(this,e,!0)},i.prototype.rawListeners=function(e){return u(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):g.call(e,t)},i.prototype.listenerCount=g,i.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},366:t=>{t.exports=e}},s={};function n(e){var r=s[e];if(void 0!==r)return r.exports;var i=s[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{AfkLogic:()=>Fe,AfkTimedOutEvent:()=>W,AfkWarningActivateEvent:()=>G,AfkWarningDeactivateEvent:()=>H,AfkWarningUpdateEvent:()=>z,AggregatedStats:()=>We,CandidatePairStats:()=>_e,CandidateStat:()=>Be,Config:()=>xe,ControlSchemeType:()=>Ae,DataChannelCloseEvent:()=>J,DataChannelErrorEvent:()=>Y,DataChannelLatencyTestResponseEvent:()=>ge,DataChannelLatencyTestResultEvent:()=>me,DataChannelOpenEvent:()=>j,DataChannelStats:()=>Ue,EncoderSettings:()=>Je,EventEmitter:()=>ye,Flags:()=>Ee,HideFreezeFrameEvent:()=>le,InboundAudioStats:()=>Oe,InboundVideoStats:()=>Ie,InitialSettings:()=>Xe,InitialSettingsEvent:()=>pe,LatencyTestResultEvent:()=>ue,LatencyTestResults:()=>Ze,LoadFreezeFrameEvent:()=>ae,Logger:()=>s,MessageDirection:()=>Qe,MessageReceive:()=>e,MessageSend:()=>t,MessageStreamerList:()=>u,NumericParameters:()=>we,OptionParameters:()=>ke,OutBoundVideoStats:()=>Ge,PixelStreaming:()=>Ot,PlayStreamErrorEvent:()=>re,PlayStreamEvent:()=>ie,PlayStreamRejectedEvent:()=>oe,PlayerCountEvent:()=>Te,SettingBase:()=>O,SettingFlag:()=>I,SettingNumber:()=>U,SettingOption:()=>_,SettingText:()=>B,SettingsChangedEvent:()=>ve,SignallingProtocol:()=>x,StatsReceivedEvent:()=>de,StreamLoadingEvent:()=>ee,StreamPreConnectEvent:()=>te,StreamPreDisconnectEvent:()=>se,StreamReconnectEvent:()=>ne,StreamerIDChangedMessageEvent:()=>he,StreamerListMessageEvent:()=>ce,TextParameters:()=>Re,UnquantizedAndDenormalizeUnsigned:()=>wt,VideoEncoderAvgQPEvent:()=>V,VideoInitializedEvent:()=>Z,WebRTCSettings:()=>Ye,WebRtcAutoConnectEvent:()=>K,WebRtcConnectedEvent:()=>q,WebRtcConnectingEvent:()=>Q,WebRtcDisconnectedEvent:()=>X,WebRtcFailedEvent:()=>$,WebRtcPlayerController:()=>Rt,WebRtcSdpEvent:()=>N,WebSocketTransport:()=>l,WebXRController:()=>xt,XrFrameEvent:()=>fe,XrSessionEndedEvent:()=>Ce,XrSessionStartedEvent:()=>Se});var e={};n.r(e),n.d(e,{MessageAnswer:()=>p,MessageAuthRequired:()=>c,MessageConfig:()=>h,MessageIceCandidate:()=>S,MessageOffer:()=>v,MessageOnScreenKeyboard:()=>f,MessagePeerDataChannels:()=>C,MessagePlayerCount:()=>m,MessageRecv:()=>d,MessageRecvTypes:()=>i,MessageStreamerIDChanged:()=>g,MessageStreamerList:()=>u});var t={};n.r(t),n.d(t,{MessageIceCandidate:()=>L,MessageListStreamers:()=>y,MessagePong:()=>w,MessageSFURecvDataChannelReady:()=>k,MessageSend:()=>T,MessageSendTypes:()=>o,MessageSubscribe:()=>E,MessageUnsubscribe:()=>M,MessageWebRTCAnswer:()=>R,MessageWebRTCDatachannelRequest:()=>P,MessageWebRTCOffer:()=>b});class s{static GetStackTrace(){const e=new Error;let t="No Stack Available for this browser";return e.stack&&(t=e.stack.toString().replace(/Error/g,"")),t}static SetLoggerVerbosity(e){null!=this.verboseLogLevel&&(this.verboseLogLevel=e)}static Log(e,t,s){s>this.verboseLogLevel||this.CommonLog("Log",null,t)}static Info(e,t,s){s>this.verboseLogLevel||this.CommonLog("Info",null,t)}static Error(e,t){this.CommonLog("Error",e,t)}static Warning(e,t){this.CommonLog("Warning",null,t)}static CommonLog(e,t,s){t?console.log(`[${e}] - ${s}\nCaller: ${t}`):console.log(`[${e}] - ${s}`)}}s.verboseLogLevel=5;var i,o,a=n(187);class l{constructor(){this.WS_OPEN_STATE=1,this.events=new a.EventEmitter}sendMessage(e){this.webSocket.send(e.payload())}connect(e){s.Log(s.GetStackTrace(),e,6);try{return this.webSocket=new WebSocket(e),this.webSocket.onopen=e=>this.handleOnOpen(),this.webSocket.onerror=e=>this.handleOnError(),this.webSocket.onclose=e=>this.handleOnClose(e),this.webSocket.onmessage=e=>this.handleOnMessage(e),this.webSocket.onmessagebinary=e=>this.handleOnMessageBinary(e),!0}catch(e){return s.Error(e,e),!1}}disconnect(){this.webSocket.close()}isConnected(){return this.webSocket&&this.webSocket.readyState!=WebSocket.CLOSED}handleOnMessageBinary(e){e&&e.data&&e.data.text().then((e=>{const t=new MessageEvent("messageFromBinary",{data:e});this.handleOnMessage(t)})).catch((e=>{s.Error(s.GetStackTrace(),`Failed to parse binary blob from websocket, reason: ${e}`)}))}handleOnMessage(e){if(e.data&&e.data instanceof Blob)return void this.handleOnMessageBinary(e);const t=JSON.parse(e.data);s.Log(s.GetStackTrace(),"received => \n"+JSON.stringify(JSON.parse(e.data),void 0,4),6),this.onMessage(t)}handleOnOpen(){s.Log(s.GetStackTrace(),"Connected to the signalling server via WebSocket",6),this.events.emit("open")}handleOnError(){this.events.emit("error")}handleOnClose(e){s.Log(s.GetStackTrace(),"Disconnected to the signalling server via WebSocket: "+JSON.stringify(e.code)+" - "+e.reason),this.events.emit("close",e)}close(){var e;null===(e=this.webSocket)||void 0===e||e.close()}}!function(e){e.CONFIG="config",e.STREAMER_LIST="streamerList",e.STREAMER_ID_CHANGED="streamerIDChanged",e.PLAYER_COUNT="playerCount",e.OFFER="offer",e.ANSWER="answer",e.ICE_CANDIDATE="iceCandidate",e.PEER_DATA_CHANNELS="peerDataChannels",e.PING="ping",e.WARNING="warning"}(i||(i={}));class d{}class c extends d{}class h extends d{}class u extends d{}class g extends d{}class m extends d{}class p extends d{}class v extends d{}class S extends d{}class C extends d{}class f{}!function(e){e.LIST_STREAMERS="listStreamers",e.SUBSCRIBE="subscribe",e.UNSUBSCRIBE="unsubscribe",e.ICE_CANDIDATE="iceCandidate",e.OFFER="offer",e.ANSWER="answer",e.DATACHANNELREQUEST="dataChannelRequest",e.SFURECVDATACHANNELREADY="peerDataChannelsReady",e.PONG="pong"}(o||(o={}));class T{sendFilter(e,t){return t}payload(){return s.Log(s.GetStackTrace(),"Sending => \n"+JSON.stringify(this,this.sendFilter,4),6),JSON.stringify(this,this.sendFilter)}}class y extends T{constructor(){super(),this.type=o.LIST_STREAMERS}}class E extends T{constructor(e){super(),this.type=o.SUBSCRIBE,this.streamerId=e}}class M extends T{constructor(){super(),this.type=o.UNSUBSCRIBE}}class w extends T{constructor(e){super(),this.type=o.PONG,this.time=e}}class b extends T{constructor(e,t){super(),this.type=o.OFFER,this.minBitrate=0,this.maxBitrate=0,e&&(this.type=e.type,this.sdp=e.sdp,this.minBitrate=t.minBitrateBps,this.maxBitrate=t.maxBitrateBps)}sendFilter(e,t){if("minBitrate"!=e&&"maxBitrate"!=e||!(t<=0))return t}}class R extends T{constructor(e,t){super(),this.type=o.ANSWER,this.minBitrate=0,this.maxBitrate=0,e&&(this.type=e.type,this.sdp=e.sdp,this.minBitrate=t.minBitrateBps,this.maxBitrate=t.maxBitrateBps)}sendFilter(e,t){if("minBitrate"!=e&&"maxBitrate"!=e||!(t<=0))return t}}class P extends T{constructor(){super(),this.type=o.DATACHANNELREQUEST}}class k extends T{constructor(){super(),this.type=o.SFURECVDATACHANNELREADY}}class L extends T{constructor(e){super(),this.type=o.ICE_CANDIDATE,this.candidate=e}}class x{constructor(e){this.transport=e,this.transportEvents=new a.EventEmitter,this.messageHandlers=new a.EventEmitter,e.events.addListener("open",(()=>this.transportEvents.emit("open"))),e.events.addListener("error",(()=>this.transportEvents.emit("error"))),e.events.addListener("close",(e=>this.transportEvents.emit("close",e))),e.onMessage=t=>{if(t.type==i.PING){const t=new w((new Date).getTime());e.sendMessage(t)}this.messageHandlers.emit(t.type,t)}}connect(e){return this.transport.connect(e)}disconnect(){this.transport.disconnect()}isConnected(){return this.transport.isConnected()}sendMessage(e){this.transport.sendMessage(e)}requestStreamerList(){const e=new y;this.transport.sendMessage(e)}sendSubscribe(e){const t=new E(e);this.transport.sendMessage(t)}sendUnsubscribe(){const e=new M;this.transport.sendMessage(e)}sendWebRtcOffer(e,t){const s=new b(e,t);this.transport.sendMessage(s)}sendWebRtcAnswer(e,t){const s=new R(e,t);this.transport.sendMessage(s)}sendWebRtcDatachannelRequest(){const e=new P;this.transport.sendMessage(e)}sendSFURecvDataChannelReady(){const e=new k;this.transport.sendMessage(e)}sendIceCandidate(e){const t=new L(e);this.transport.sendMessage(t)}}class A{constructor(e){this.videoElementProvider=e,this.audioElement=document.createElement("Audio"),this.videoElementProvider.setAudioElement(this.audioElement)}handleOnTrack(e){s.Log(s.GetStackTrace(),"handleOnTrack "+JSON.stringify(e.streams),6);const t=this.videoElementProvider.getVideoElement();if(e.track&&s.Log(s.GetStackTrace(),"Got track - "+e.track.kind+" id="+e.track.id+" readyState="+e.track.readyState,6),"audio"!=e.track.kind)return"video"==e.track.kind&&t.srcObject!==e.streams[0]?(t.srcObject=e.streams[0],void s.Log(s.GetStackTrace(),"Set video source from video track ontrack.")):void 0;this.CreateAudioTrack(e.streams[0])}CreateAudioTrack(e){const t=this.videoElementProvider.getVideoElement();t.srcObject!=e&&t.srcObject&&t.srcObject!==e&&(this.audioElement.srcObject=e,s.Log(s.GetStackTrace(),"Created new audio element to play separate audio stream."))}}class F{constructor(e){this.freezeFrameHeight=0,this.freezeFrameWidth=0,this.rootDiv=e,this.rootElement=document.createElement("div"),this.rootElement.id="freezeFrame",this.rootElement.style.display="none",this.rootElement.style.pointerEvents="none",this.rootElement.style.position="absolute",this.rootElement.style.zIndex="20",this.imageElement=document.createElement("img"),this.imageElement.style.position="absolute",this.rootElement.appendChild(this.imageElement),this.rootDiv.appendChild(this.rootElement)}setElementForShow(){this.rootElement.style.display="block"}setElementForHide(){this.rootElement.style.display="none"}updateImageElementSource(e){const t=btoa(e.reduce(((e,t)=>e+String.fromCharCode(t)),""));this.imageElement.src="data:image/jpeg;base64,"+t}setDimensionsFromElementAndResize(){this.freezeFrameHeight=this.imageElement.naturalHeight,this.freezeFrameWidth=this.imageElement.naturalWidth,this.resize()}resize(){if(0!==this.freezeFrameWidth&&0!==this.freezeFrameHeight){let e=0,t=0,s=0,n=0;const r=this.rootDiv.clientWidth/this.rootDiv.clientHeight,i=this.freezeFrameWidth/this.freezeFrameHeight;r<i?(e=this.rootDiv.clientWidth,t=Math.floor(this.rootDiv.clientWidth/i),s=Math.floor(.5*(this.rootDiv.clientHeight-t)),n=0):(e=Math.floor(this.rootDiv.clientHeight*i),t=this.rootDiv.clientHeight,s=0,n=Math.floor(.5*(this.rootDiv.clientWidth-e))),this.rootElement.style.width=this.rootDiv.offsetWidth+"px",this.rootElement.style.height=this.rootDiv.offsetHeight+"px",this.rootElement.style.left="0px",this.rootElement.style.top="0px",this.imageElement.style.width=e+"px",this.imageElement.style.height=t+"px",this.imageElement.style.left=n+"px",this.imageElement.style.top=s+"px"}}}class D{constructor(e){this.receiving=!1,this.size=0,this.jpeg=void 0,this.valid=!1,this.freezeFrameDelay=50,this.freezeFrame=new F(e)}showFreezeFrame(){this.valid&&this.freezeFrame.setElementForShow()}hideFreezeFrame(){this.valid=!1,this.freezeFrame.setElementForHide()}updateFreezeFrameAndShow(e,t){this.freezeFrame.updateImageElementSource(e),this.freezeFrame.imageElement.onload=()=>{this.freezeFrame.setDimensionsFromElementAndResize(),t()}}processFreezeFrameMessage(e,t){this.receiving||(this.receiving=!0,this.valid=!1,this.size=0,this.jpeg=void 0),this.size=new DataView(e.slice(1,5).buffer).getInt32(0,!0);const n=e.slice(5);if(this.jpeg){const e=new Uint8Array(this.jpeg.length+n.length);e.set(this.jpeg,0),e.set(n,this.jpeg.length),this.jpeg=e}else this.jpeg=n,this.receiving=!0,s.Log(s.GetStackTrace(),`received first chunk of freeze frame: ${this.jpeg.length}/${this.size}`,6);this.jpeg.length===this.size?(this.receiving=!1,this.valid=!0,s.Log(s.GetStackTrace(),`received complete freeze frame ${this.size}`,6),this.updateFreezeFrameAndShow(this.jpeg,t)):this.jpeg.length>this.size&&(s.Error(s.GetStackTrace(),`received bigger freeze frame than advertised: ${this.jpeg.length}/${this.size}`),this.jpeg=void 0,this.receiving=!1)}}class O{constructor(e,t,s,n,r=(()=>{})){this.onChange=r,this.onChangeEmit=()=>{},this.id=e,this.description=s,this.label=t,this.value=n}set label(e){this._label=e,this.onChangeEmit(this._value)}get label(){return this._label}get value(){return this._value}set value(e){this._value=e,this.onChange(this._value,this),this.onChangeEmit(this._value)}}class I extends O{constructor(e,t,s,n,r,i=(()=>{})){super(e,t,s,n,i);const o=new URLSearchParams(window.location.search);if(r&&o.has(this.id)){const e=this.getUrlParamFlag();this.flag=e}else this.flag=n;this.useUrlParams=r}getUrlParamFlag(){const e=new URLSearchParams(window.location.search);return!!e.has(this.id)&&"false"!==e.get(this.id)&&"False"!==e.get(this.id)}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);!0===this.flag?e.set(this.id,"true"):e.set(this.id,"false"),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}enable(){this.flag=!0}get flag(){return!!this.value}set flag(e){this.value=e}}class U extends O{constructor(e,t,s,n,r,i,o,a=(()=>{})){super(e,t,s,i,a),this._min=n,this._max=r;const l=new URLSearchParams(window.location.search);if(o&&l.has(this.id)){const e=Number.parseFloat(l.get(this.id));this.number=Number.isNaN(e)?i:e}else this.number=i;this.useUrlParams=o}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);e.set(this.id,this.number.toString()),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}set number(e){this.value=this.clamp(e)}get number(){return this.value}clamp(e){return Math.max(Math.min(this._max,e),this._min)}get min(){return this._min}get max(){return this._max}addOnChangedListener(e){this.onChange=e}}class B extends O{constructor(e,t,s,n,r,i=(()=>{})){super(e,t,s,n,i);const o=new URLSearchParams(window.location.search);if(r&&o.has(this.id)){const e=this.getUrlParamText();this.text=e}else this.text=n;this.useUrlParams=r}getUrlParamText(){var e;const t=new URLSearchParams(window.location.search);return t.has(this.id)&&null!==(e=t.get(this.id))&&void 0!==e?e:""}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);e.set(this.id,this.text),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}get text(){return this.value}set text(e){this.value=e}}class _ extends O{constructor(e,t,s,n,r,i,o=(()=>{})){super(e,t,s,[n],o),this.options=r;const a=new URLSearchParams(window.location.search),l=i&&a.has(this.id)?this.getUrlParamText():n;this.selected=l,this.useUrlParams=i}getUrlParamText(){var e;const t=new URLSearchParams(window.location.search);return t.has(this.id)&&null!==(e=t.get(this.id))&&void 0!==e?e:""}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);e.set(this.id,this.selected),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}addOnChangedListener(e){this.onChange=e}get options(){return this._options}set options(e){this._options=e,this.onChangeEmit(this.selected)}get selected(){return this.value}set selected(e){let t=this.options.filter((t=>-1!==t.indexOf(e)));t.length?this.value=t[0]:(t=this.options.filter((t=>-1!==t.indexOf(e.split(" ")[0]))),t.length&&(this.value=t[0]))}}class G extends Event{constructor(e){super("afkWarningActivate"),this.data=e}}class z extends Event{constructor(e){super("afkWarningUpdate"),this.data=e}}class H extends Event{constructor(){super("afkWarningDeactivate")}}class W extends Event{constructor(){super("afkTimedOut")}}class V extends Event{constructor(e){super("videoEncoderAvgQP"),this.data=e}}class N extends Event{constructor(){super("webRtcSdp")}}class K extends Event{constructor(){super("webRtcAutoConnect")}}class Q extends Event{constructor(){super("webRtcConnecting")}}class q extends Event{constructor(){super("webRtcConnected")}}class $ extends Event{constructor(){super("webRtcFailed")}}class X extends Event{constructor(e){super("webRtcDisconnected"),this.data=e}}class j extends Event{constructor(e){super("dataChannelOpen"),this.data=e}}class J extends Event{constructor(e){super("dataChannelClose"),this.data=e}}class Y extends Event{constructor(e){super("dataChannelError"),this.data=e}}class Z extends Event{constructor(){super("videoInitialized")}}class ee extends Event{constructor(){super("streamLoading")}}class te extends Event{constructor(){super("streamConnect")}}class se extends Event{constructor(){super("streamDisconnect")}}class ne extends Event{constructor(){super("streamReconnect")}}class re extends Event{constructor(e){super("playStreamError"),this.data=e}}class ie extends Event{constructor(){super("playStream")}}class oe extends Event{constructor(e){super("playStreamRejected"),this.data=e}}class ae extends Event{constructor(e){super("loadFreezeFrame"),this.data=e}}class le extends Event{constructor(){super("hideFreezeFrame")}}class de extends Event{constructor(e){super("statsReceived"),this.data=e}}class ce extends Event{constructor(e){super("streamerListMessage"),this.data=e}}class he extends Event{constructor(e){super("StreamerIDChangedMessage"),this.data=e}}class ue extends Event{constructor(e){super("latencyTestResult"),this.data=e}}class ge extends Event{constructor(e){super("dataChannelLatencyTestResponse"),this.data=e}}class me extends Event{constructor(e){super("dataChannelLatencyTestResult"),this.data=e}}class pe extends Event{constructor(e){super("initialSettings"),this.data=e}}class ve extends Event{constructor(e){super("settingsChanged"),this.data=e}}class Se extends Event{constructor(){super("xrSessionStarted")}}class Ce extends Event{constructor(){super("xrSessionEnded")}}class fe extends Event{constructor(e){super("xrFrame"),this.data=e}}class Te extends Event{constructor(e){super("playerCount"),this.data=e}}class ye extends EventTarget{dispatchEvent(e){return super.dispatchEvent(e)}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}}class Ee{}Ee.AutoConnect="AutoConnect",Ee.AutoPlayVideo="AutoPlayVideo",Ee.AFKDetection="TimeoutIfIdle",Ee.BrowserSendOffer="OfferToReceive",Ee.HoveringMouseMode="HoveringMouse",Ee.ForceMonoAudio="ForceMonoAudio",Ee.ForceTURN="ForceTURN",Ee.FakeMouseWithTouches="FakeMouseWithTouches",Ee.IsQualityController="ControlsQuality",Ee.MatchViewportResolution="MatchViewportRes",Ee.StartVideoMuted="StartVideoMuted",Ee.SuppressBrowserKeys="SuppressBrowserKeys",Ee.UseMic="UseMic",Ee.KeyboardInput="KeyboardInput",Ee.MouseInput="MouseInput",Ee.TouchInput="TouchInput",Ee.GamepadInput="GamepadInput",Ee.XRControllerInput="XRControllerInput",Ee.WaitForStreamer="WaitForStreamer";const Me=e=>Object.getOwnPropertyNames(Ee).some((t=>Ee[t]===e));class we{}we.AFKTimeoutSecs="AFKTimeout",we.MinQP="MinQP",we.MaxQP="MaxQP",we.WebRTCFPS="WebRTCFPS",we.WebRTCMinBitrate="WebRTCMinBitrate",we.WebRTCMaxBitrate="WebRTCMaxBitrate",we.MaxReconnectAttempts="MaxReconnectAttempts",we.StreamerAutoJoinInterval="StreamerAutoJoinInterval";const be=e=>Object.getOwnPropertyNames(we).some((t=>we[t]===e));class Re{}Re.SignallingServerUrl="ss";const Pe=e=>Object.getOwnPropertyNames(Re).some((t=>Re[t]===e));class ke{}ke.PreferredCodec="PreferredCodec",ke.StreamerId="StreamerId";const Le=e=>Object.getOwnPropertyNames(ke).some((t=>ke[t]===e));class xe{constructor(e={}){this.flags=new Map,this.numericParameters=new Map,this.textParameters=new Map,this.optionParameters=new Map;const{initialSettings:t,useUrlParams:s}=e;this._useUrlParams=!!s,this.populateDefaultSettings(this._useUrlParams,t)}get useUrlParams(){return this._useUrlParams}populateDefaultSettings(e,t){this.textParameters.set(Re.SignallingServerUrl,new B(Re.SignallingServerUrl,"Signalling url","Url of the signalling server",t&&t.hasOwnProperty(Re.SignallingServerUrl)?t[Re.SignallingServerUrl]:("https:"===location.protocol?"wss://":"ws://")+window.location.hostname+("80"===window.location.port||""===window.location.port?"":`:${window.location.port}`),e)),this.optionParameters.set(ke.StreamerId,new _(ke.StreamerId,"Streamer ID","The ID of the streamer to stream.",t&&t.hasOwnProperty(ke.StreamerId)?t[ke.StreamerId]:"",[],e)),this.optionParameters.set(ke.PreferredCodec,new _(ke.PreferredCodec,"Preferred Codec","The preferred codec to be used during codec negotiation","H264 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f",t&&t.hasOwnProperty(ke.PreferredCodec)?[t[ke.PreferredCodec]]:function(){const e=[];if(!RTCRtpReceiver.getCapabilities)return e.push("Only available on Chrome"),e;const t=/(VP\d|H26\d|AV1).*/;return RTCRtpReceiver.getCapabilities("video").codecs.forEach((s=>{const n=s.mimeType.split("/")[1]+" "+(s.sdpFmtpLine||"");null!==t.exec(n)&&e.push(n)})),e}(),e)),this.flags.set(Ee.AutoConnect,new I(Ee.AutoConnect,"Auto connect to stream","Whether we should attempt to auto connect to the signalling server or show a click to start prompt.",!(!t||!t.hasOwnProperty(Ee.AutoConnect))&&t[Ee.AutoConnect],e)),this.flags.set(Ee.AutoPlayVideo,new I(Ee.AutoPlayVideo,"Auto play video","When video is ready automatically start playing it as opposed to showing a play button.",!t||!t.hasOwnProperty(Ee.AutoPlayVideo)||t[Ee.AutoPlayVideo],e)),this.flags.set(Ee.BrowserSendOffer,new I(Ee.BrowserSendOffer,"Browser send offer","Browser will initiate the WebRTC handshake by sending the offer to the streamer",!(!t||!t.hasOwnProperty(Ee.BrowserSendOffer))&&t[Ee.BrowserSendOffer],e)),this.flags.set(Ee.UseMic,new I(Ee.UseMic,"Use microphone","Make browser request microphone access and open an input audio track.",!(!t||!t.hasOwnProperty(Ee.UseMic))&&t[Ee.UseMic],e)),this.flags.set(Ee.StartVideoMuted,new I(Ee.StartVideoMuted,"Start video muted","Video will start muted if true.",!(!t||!t.hasOwnProperty(Ee.StartVideoMuted))&&t[Ee.StartVideoMuted],e)),this.flags.set(Ee.SuppressBrowserKeys,new I(Ee.SuppressBrowserKeys,"Suppress browser keys","Suppress certain browser keys that we use in UE, for example F5 to show shader complexity instead of refresh the page.",!t||!t.hasOwnProperty(Ee.SuppressBrowserKeys)||t[Ee.SuppressBrowserKeys],e)),this.flags.set(Ee.IsQualityController,new I(Ee.IsQualityController,"Is quality controller?","True if this peer controls stream quality",!t||!t.hasOwnProperty(Ee.IsQualityController)||t[Ee.IsQualityController],e)),this.flags.set(Ee.ForceMonoAudio,new I(Ee.ForceMonoAudio,"Force mono audio","Force browser to request mono audio in the SDP",!(!t||!t.hasOwnProperty(Ee.ForceMonoAudio))&&t[Ee.ForceMonoAudio],e)),this.flags.set(Ee.ForceTURN,new I(Ee.ForceTURN,"Force TURN","Only generate TURN/Relayed ICE candidates.",!(!t||!t.hasOwnProperty(Ee.ForceTURN))&&t[Ee.ForceTURN],e)),this.flags.set(Ee.AFKDetection,new I(Ee.AFKDetection,"AFK if idle","Timeout the experience if user is AFK for a period.",!(!t||!t.hasOwnProperty(Ee.AFKDetection))&&t[Ee.AFKDetection],e)),this.flags.set(Ee.MatchViewportResolution,new I(Ee.MatchViewportResolution,"Match viewport resolution","Pixel Streaming will be instructed to dynamically resize the video stream to match the size of the video element.",!(!t||!t.hasOwnProperty(Ee.MatchViewportResolution))&&t[Ee.MatchViewportResolution],e)),this.flags.set(Ee.HoveringMouseMode,new I(Ee.HoveringMouseMode,"Control Scheme: Locked Mouse","Either locked mouse, where the pointer is consumed by the video and locked to it, or hovering mouse, where the mouse is not consumed.",!(!t||!t.hasOwnProperty(Ee.HoveringMouseMode))&&t[Ee.HoveringMouseMode],e,((e,t)=>{t.label=`Control Scheme: ${e?"Hovering":"Locked"} Mouse`}))),this.flags.set(Ee.FakeMouseWithTouches,new I(Ee.FakeMouseWithTouches,"Fake mouse with touches","A single finger touch is converted into a mouse event. This allows a non-touch application to be controlled partially via a touch device.",!t||!t.hasOwnProperty(Ee.FakeMouseWithTouches)||t[Ee.FakeMouseWithTouches],e)),this.flags.set(Ee.KeyboardInput,new I(Ee.KeyboardInput,"Keyboard input","If enabled, send keyboard events to streamer",!t||!t.hasOwnProperty(Ee.KeyboardInput)||t[Ee.KeyboardInput],e)),this.flags.set(Ee.MouseInput,new I(Ee.MouseInput,"Mouse input","If enabled, send mouse events to streamer",!t||!t.hasOwnProperty(Ee.MouseInput)||t[Ee.MouseInput],e)),this.flags.set(Ee.TouchInput,new I(Ee.TouchInput,"Touch input","If enabled, send touch events to streamer",!t||!t.hasOwnProperty(Ee.TouchInput)||t[Ee.TouchInput],e)),this.flags.set(Ee.GamepadInput,new I(Ee.GamepadInput,"Gamepad input","If enabled, send gamepad events to streamer",!t||!t.hasOwnProperty(Ee.GamepadInput)||t[Ee.GamepadInput],e)),this.flags.set(Ee.XRControllerInput,new I(Ee.XRControllerInput,"XR controller input","If enabled, send XR controller events to streamer",!t||!t.hasOwnProperty(Ee.XRControllerInput)||t[Ee.XRControllerInput],e)),this.flags.set(Ee.WaitForStreamer,new I(Ee.WaitForStreamer,"Wait for streamer","Will continue trying to connect to the first streamer available.",!t||!t.hasOwnProperty(Ee.WaitForStreamer)||t[Ee.WaitForStreamer],e)),this.numericParameters.set(we.AFKTimeoutSecs,new U(we.AFKTimeoutSecs,"AFK timeout","The time (in seconds) it takes for the application to time out if AFK timeout is enabled.",0,600,t&&t.hasOwnProperty(we.AFKTimeoutSecs)?t[we.AFKTimeoutSecs]:120,e)),this.numericParameters.set(we.MaxReconnectAttempts,new U(we.MaxReconnectAttempts,"Max Reconnects","Maximum number of reconnects the application will attempt when a streamer disconnects.",0,999,t&&t.hasOwnProperty(we.MaxReconnectAttempts)?t[we.MaxReconnectAttempts]:3,e)),this.numericParameters.set(we.MinQP,new U(we.MinQP,"Min QP","The lower bound for the quantization parameter (QP) of the encoder. 0 = Best quality, 51 = worst quality.",0,51,t&&t.hasOwnProperty(we.MinQP)?t[we.MinQP]:0,e)),this.numericParameters.set(we.MaxQP,new U(we.MaxQP,"Max QP","The upper bound for the quantization parameter (QP) of the encoder. 0 = Best quality, 51 = worst quality.",0,51,t&&t.hasOwnProperty(we.MaxQP)?t[we.MaxQP]:51,e)),this.numericParameters.set(we.WebRTCFPS,new U(we.WebRTCFPS,"Max FPS","The maximum FPS that WebRTC will try to transmit frames at.",1,999,t&&t.hasOwnProperty(we.WebRTCFPS)?t[we.WebRTCFPS]:60,e)),this.numericParameters.set(we.WebRTCMinBitrate,new U(we.WebRTCMinBitrate,"Min Bitrate (kbps)","The minimum bitrate that WebRTC should use.",0,5e5,t&&t.hasOwnProperty(we.WebRTCMinBitrate)?t[we.WebRTCMinBitrate]:0,e)),this.numericParameters.set(we.WebRTCMaxBitrate,new U(we.WebRTCMaxBitrate,"Max Bitrate (kbps)","The maximum bitrate that WebRTC should use.",0,5e5,t&&t.hasOwnProperty(we.WebRTCMaxBitrate)?t[we.WebRTCMaxBitrate]:0,e)),this.numericParameters.set(we.StreamerAutoJoinInterval,new U(we.StreamerAutoJoinInterval,"Streamer Auto Join Interval (ms)","Delay between retries when waiting for an available streamer.",500,9e5,t&&t.hasOwnProperty(we.StreamerAutoJoinInterval)?t[we.StreamerAutoJoinInterval]:3e3,e))}_addOnNumericSettingChangedListener(e,t){this.numericParameters.has(e)&&this.numericParameters.get(e).addOnChangedListener(t)}_addOnOptionSettingChangedListener(e,t){this.optionParameters.has(e)&&this.optionParameters.get(e).addOnChangedListener(t)}getNumericSettingValue(e){if(this.numericParameters.has(e))return this.numericParameters.get(e).number;throw new Error(`There is no numeric setting with the id of ${e}`)}getTextSettingValue(e){if(this.textParameters.has(e))return this.textParameters.get(e).value;throw new Error(`There is no numeric setting with the id of ${e}`)}setNumericSetting(e,t){if(!this.numericParameters.has(e))throw new Error(`There is no numeric setting with the id of ${e}`);this.numericParameters.get(e).number=t}_addOnSettingChangedListener(e,t){this.flags.has(e)&&(this.flags.get(e).onChange=t)}_addOnTextSettingChangedListener(e,t){this.textParameters.has(e)&&(this.textParameters.get(e).onChange=t)}getSettingOption(e){return this.optionParameters.get(e)}isFlagEnabled(e){return this.flags.get(e).flag}setFlagEnabled(e,t){this.flags.has(e)?this.flags.get(e).flag=t:s.Warning(s.GetStackTrace(),`Cannot toggle flag called ${e} - it does not exist in the Config.flags map.`)}setTextSetting(e,t){this.textParameters.has(e)?this.textParameters.get(e).text=t:s.Warning(s.GetStackTrace(),`Cannot set text setting called ${e} - it does not exist in the Config.textParameters map.`)}setOptionSettingOptions(e,t){this.optionParameters.has(e)?this.optionParameters.get(e).options=t:s.Warning(s.GetStackTrace(),`Cannot set text setting called ${e} - it does not exist in the Config.optionParameters map.`)}setOptionSettingValue(e,t){if(this.optionParameters.has(e)){const s=this.optionParameters.get(e),n=s.options;n.includes(t)||(n.push(t),s.options=n),s.selected=t}else s.Warning(s.GetStackTrace(),`Cannot set text setting called ${e} - it does not exist in the Config.enumParameters map.`)}setFlagLabel(e,t){this.flags.has(e)?this.flags.get(e).label=t:s.Warning(s.GetStackTrace(),`Cannot set label for flag called ${e} - it does not exist in the Config.flags map.`)}setSettings(e){for(const t of Object.keys(e))Me(t)?this.setFlagEnabled(t,e[t]):be(t)?this.setNumericSetting(t,e[t]):Pe(t)?this.setTextSetting(t,e[t]):Le(t)&&this.setOptionSettingValue(t,e[t])}getSettings(){const e={};for(const[t,s]of this.flags.entries())e[t]=s.flag;for(const[t,s]of this.numericParameters.entries())e[t]=s.number;for(const[t,s]of this.textParameters.entries())e[t]=s.text;for(const[t,s]of this.optionParameters.entries())e[t]=s.selected;return e}getFlags(){return Array.from(this.flags.values())}getTextSettings(){return Array.from(this.textParameters.values())}getNumericSettings(){return Array.from(this.numericParameters.values())}getOptionSettings(){return Array.from(this.optionParameters.values())}_registerOnChangeEvents(e){for(const t of this.flags.keys()){const s=this.flags.get(t);s&&(s.onChangeEmit=t=>e.dispatchEvent(new ve({id:s.id,type:"flag",value:t,target:s})))}for(const t of this.numericParameters.keys()){const s=this.numericParameters.get(t);s&&(s.onChangeEmit=t=>e.dispatchEvent(new ve({id:s.id,type:"number",value:t,target:s})))}for(const t of this.textParameters.keys()){const s=this.textParameters.get(t);s&&(s.onChangeEmit=t=>e.dispatchEvent(new ve({id:s.id,type:"text",value:t,target:s})))}for(const t of this.optionParameters.keys()){const s=this.optionParameters.get(t);s&&(s.onChangeEmit=t=>e.dispatchEvent(new ve({id:s.id,type:"option",value:t,target:s})))}}}var Ae;!function(e){e[e.LockedMouse=0]="LockedMouse",e[e.HoveringMouse=1]="HoveringMouse"}(Ae||(Ae={}));class Fe{constructor(e,t,s){this.closeTimeout=10,this.active=!1,this.countdownActive=!1,this.warnTimer=void 0,this.countDown=0,this.countDownTimer=void 0,this.config=e,this.pixelStreaming=t,this.onDismissAfk=s,this.onAFKTimedOutCallback=()=>{console.log("AFK timed out, did you want to override this callback?")}}onAfkClick(){clearInterval(this.countDownTimer),(this.active||this.countdownActive)&&(this.startAfkWarningTimer(),this.pixelStreaming.dispatchEvent(new H))}startAfkWarningTimer(){this.config.getNumericSettingValue(we.AFKTimeoutSecs)>0&&this.config.isFlagEnabled(Ee.AFKDetection)?this.active=!0:this.active=!1,this.resetAfkWarningTimer()}stopAfkWarningTimer(){this.active=!1,this.countdownActive=!1,clearTimeout(this.warnTimer),clearInterval(this.countDownTimer)}pauseAfkWarningTimer(){this.active=!1}resetAfkWarningTimer(){this.active&&this.config.isFlagEnabled(Ee.AFKDetection)&&(clearTimeout(this.warnTimer),this.warnTimer=setTimeout((()=>this.activateAfkEvent()),1e3*this.config.getNumericSettingValue(we.AFKTimeoutSecs)))}activateAfkEvent(){this.pauseAfkWarningTimer(),this.pixelStreaming.dispatchEvent(new G({countDown:this.countDown,dismissAfk:this.onDismissAfk})),this.countDown=this.closeTimeout,this.countdownActive=!0,this.pixelStreaming.dispatchEvent(new z({countDown:this.countDown})),this.config.isFlagEnabled(Ee.HoveringMouseMode)||document.exitPointerLock&&document.exitPointerLock(),this.countDownTimer=setInterval((()=>{this.countDown--,0==this.countDown?(this.pixelStreaming.dispatchEvent(new W),this.onAFKTimedOutCallback(),s.Log(s.GetStackTrace(),"You have been disconnected due to inactivity"),this.stopAfkWarningTimer()):this.pixelStreaming.dispatchEvent(new z({countDown:this.countDown}))}),1e3)}}class De{constructor(){this.isReceivingFreezeFrame=!1}getDataChannelInstance(){return this}createDataChannel(e,t,s){this.peerConnection=e,this.label=t,this.datachannelOptions=s,null==s&&(this.datachannelOptions={},this.datachannelOptions.ordered=!0),this.dataChannel=this.peerConnection.createDataChannel(this.label,this.datachannelOptions),this.setupDataChannel()}setupDataChannel(){this.dataChannel.binaryType="arraybuffer",this.dataChannel.onopen=e=>this.handleOnOpen(e),this.dataChannel.onclose=e=>this.handleOnClose(e),this.dataChannel.onmessage=e=>this.handleOnMessage(e),this.dataChannel.onerror=e=>this.handleOnError(e)}handleOnOpen(e){var t;s.Log(s.GetStackTrace(),`Data Channel (${this.label}) opened.`,7),this.onOpen(null===(t=this.dataChannel)||void 0===t?void 0:t.label,e)}handleOnClose(e){var t;s.Log(s.GetStackTrace(),`Data Channel (${this.label}) closed.`,7),this.onClose(null===(t=this.dataChannel)||void 0===t?void 0:t.label,e)}handleOnMessage(e){s.Log(s.GetStackTrace(),`Data Channel (${this.label}) message: ${e}`,8)}handleOnError(e){var t;s.Log(s.GetStackTrace(),`Data Channel (${this.label}) error: ${e}`,7),this.onError(null===(t=this.dataChannel)||void 0===t?void 0:t.label,e)}onOpen(e,t){}onClose(e,t){}onError(e,t){}}class Oe{}class Ie{}class Ue{}class Be{}class _e{}class Ge{}class ze{}class He{}class We{constructor(){this.inboundVideoStats=new Ie,this.inboundAudioStats=new Oe,this.candidatePair=new _e,this.DataChannelStats=new Ue,this.outBoundVideoStats=new Ge,this.sessionStats=new ze,this.streamStats=new He,this.codecs=new Map}processStats(e){this.localCandidates=new Array,this.remoteCandidates=new Array,e.forEach((e=>{switch(e.type){case"candidate-pair":this.handleCandidatePair(e);break;case"certificate":case"media-source":case"media-playout":case"outbound-rtp":case"peer-connection":case"remote-inbound-rtp":case"transport":break;case"codec":this.handleCodec(e);break;case"data-channel":this.handleDataChannel(e);break;case"inbound-rtp":this.handleInBoundRTP(e);break;case"local-candidate":this.handleLocalCandidate(e);break;case"remote-candidate":this.handleRemoteCandidate(e);break;case"remote-outbound-rtp":this.handleRemoteOutBound(e);break;case"track":this.handleTrack(e);break;case"stream":this.handleStream(e);break;default:s.Error(s.GetStackTrace(),"unhandled Stat Type"),s.Log(s.GetStackTrace(),e)}}))}handleStream(e){this.streamStats=e}handleCandidatePair(e){this.candidatePair.bytesReceived=e.bytesReceived,this.candidatePair.bytesSent=e.bytesSent,this.candidatePair.localCandidateId=e.localCandidateId,this.candidatePair.remoteCandidateId=e.remoteCandidateId,this.candidatePair.nominated=e.nominated,this.candidatePair.readable=e.readable,this.candidatePair.selected=e.selected,this.candidatePair.writable=e.writable,this.candidatePair.state=e.state,this.candidatePair.currentRoundTripTime=e.currentRoundTripTime}handleDataChannel(e){this.DataChannelStats.bytesReceived=e.bytesReceived,this.DataChannelStats.bytesSent=e.bytesSent,this.DataChannelStats.dataChannelIdentifier=e.dataChannelIdentifier,this.DataChannelStats.id=e.id,this.DataChannelStats.label=e.label,this.DataChannelStats.messagesReceived=e.messagesReceived,this.DataChannelStats.messagesSent=e.messagesSent,this.DataChannelStats.protocol=e.protocol,this.DataChannelStats.state=e.state,this.DataChannelStats.timestamp=e.timestamp}handleLocalCandidate(e){const t=new Be;t.label="local-candidate",t.address=e.address,t.port=e.port,t.protocol=e.protocol,t.candidateType=e.candidateType,t.id=e.id,this.localCandidates.push(t)}handleRemoteCandidate(e){const t=new Be;t.label="local-candidate",t.address=e.address,t.port=e.port,t.protocol=e.protocol,t.id=e.id,t.candidateType=e.candidateType,this.remoteCandidates.push(t)}handleInBoundRTP(e){switch(e.kind){case"video":this.inboundVideoStats=e,null!=this.lastVideoStats&&(this.inboundVideoStats.bitrate=8*(this.inboundVideoStats.bytesReceived-this.lastVideoStats.bytesReceived)/(this.inboundVideoStats.timestamp-this.lastVideoStats.timestamp),this.inboundVideoStats.bitrate=Math.floor(this.inboundVideoStats.bitrate)),this.lastVideoStats=Object.assign({},this.inboundVideoStats);break;case"audio":this.inboundAudioStats=e,null!=this.lastAudioStats&&(this.inboundAudioStats.bitrate=8*(this.inboundAudioStats.bytesReceived-this.lastAudioStats.bytesReceived)/(this.inboundAudioStats.timestamp-this.lastAudioStats.timestamp),this.inboundAudioStats.bitrate=Math.floor(this.inboundAudioStats.bitrate)),this.lastAudioStats=Object.assign({},this.inboundAudioStats);break;default:s.Log(s.GetStackTrace(),"Kind is not handled")}}handleRemoteOutBound(e){"video"===e.kind&&(this.outBoundVideoStats.bytesSent=e.bytesSent,this.outBoundVideoStats.id=e.id,this.outBoundVideoStats.localId=e.localId,this.outBoundVideoStats.packetsSent=e.packetsSent,this.outBoundVideoStats.remoteTimestamp=e.remoteTimestamp,this.outBoundVideoStats.timestamp=e.timestamp)}handleTrack(e){"track"!==e.type||"video_label"!==e.trackIdentifier&&"video"!==e.kind||(this.inboundVideoStats.framesDropped=e.framesDropped,this.inboundVideoStats.framesReceived=e.framesReceived,this.inboundVideoStats.frameHeight=e.frameHeight,this.inboundVideoStats.frameWidth=e.frameWidth)}handleCodec(e){const t=e.id,s=`${e.mimeType.replace("video/","").replace("audio/","")}${e.sdpFmtpLine?` ${e.sdpFmtpLine}`:""}`;this.codecs.set(t,s)}handleSessionStatistics(e,t,s){const n=Date.now()-e;this.sessionStats.runTime=new Date(n).toISOString().substr(11,8).toString();const r=null===t?"Not sent yet":t?"true":"false";this.sessionStats.controlsStreamInput=r,this.sessionStats.videoEncoderAvgQP=s}isNumber(e){return"number"==typeof e&&isFinite(e)}}var Ve=n(366);class Ne{static isVideoTransciever(e){return this.canTransceiverReceiveVideo(e)||this.canTransceiverSendVideo(e)}static canTransceiverReceiveVideo(e){return!!e&&("sendrecv"===e.direction||"recvonly"===e.direction)&&e.receiver&&e.receiver.track&&"video"===e.receiver.track.kind}static canTransceiverSendVideo(e){return!!e&&("sendrecv"===e.direction||"sendonly"===e.direction)&&e.sender&&e.sender.track&&"video"===e.sender.track.kind}static isAudioTransciever(e){return this.canTransceiverReceiveAudio(e)||this.canTransceiverSendAudio(e)}static canTransceiverReceiveAudio(e){return!!e&&("sendrecv"===e.direction||"recvonly"===e.direction)&&e.receiver&&e.receiver.track&&"audio"===e.receiver.track.kind}static canTransceiverSendAudio(e){return!!e&&("sendrecv"===e.direction||"sendonly"===e.direction)&&e.sender&&e.sender.track&&"audio"===e.sender.track.kind}}var Ke,Qe,qe=function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};class $e{constructor(e,t,s){this.config=t,this.createPeerConnection(e,s)}createPeerConnection(e,t){this.config.isFlagEnabled(Ee.ForceTURN)&&(e.iceTransportPolicy="relay",s.Log(s.GetStackTrace(),"Forcing TURN usage by setting ICE Transport Policy in peer connection config.")),this.peerConnection=new RTCPeerConnection(e),this.peerConnection.onsignalingstatechange=e=>this.handleSignalStateChange(e),this.peerConnection.oniceconnectionstatechange=e=>this.handleIceConnectionStateChange(e),this.peerConnection.onicegatheringstatechange=e=>this.handleIceGatheringStateChange(e),this.peerConnection.ontrack=e=>this.handleOnTrack(e),this.peerConnection.onicecandidate=e=>this.handleIceCandidate(e),this.peerConnection.ondatachannel=e=>this.handleDataChannel(e),this.aggregatedStats=new We,this.preferredCodec=t,this.updateCodecSelection=!0}createOffer(e,t){return qe(this,void 0,void 0,(function*(){s.Log(s.GetStackTrace(),"Create Offer",6);const n="localhost"===location.hostname||"127.0.0.1"===location.hostname,r="https:"===location.protocol;let i=t.isFlagEnabled(Ee.UseMic);!i||n||r||(i=!1,s.Error(s.GetStackTrace(),"Microphone access in the browser will not work if you are not on HTTPS or localhost. Disabling mic access."),s.Error(s.GetStackTrace(),"For testing you can enable HTTP microphone access Chrome by visiting chrome://flags/ and enabling 'unsafely-treat-insecure-origin-as-secure'")),this.setupTransceiversAsync(i).finally((()=>{var t;null===(t=this.peerConnection)||void 0===t||t.createOffer(e).then((e=>{var t;this.showTextOverlayConnecting(),e.sdp=this.mungeSDP(e.sdp,i),null===(t=this.peerConnection)||void 0===t||t.setLocalDescription(e),this.onSendWebRTCOffer(e)})).catch((()=>{this.showTextOverlaySetupFailure()}))}))}))}receiveOffer(e,t){var n;return qe(this,void 0,void 0,(function*(){s.Log(s.GetStackTrace(),"Receive Offer",6),null===(n=this.peerConnection)||void 0===n||n.setRemoteDescription(e).then((()=>{const e="localhost"===location.hostname||"127.0.0.1"===location.hostname,n="https:"===location.protocol;let r=t.isFlagEnabled(Ee.UseMic);!r||e||n||(r=!1,s.Error(s.GetStackTrace(),"Microphone access in the browser will not work if you are not on HTTPS or localhost. Disabling mic access."),s.Error(s.GetStackTrace(),"For testing you can enable HTTP microphone access Chrome by visiting chrome://flags/ and enabling 'unsafely-treat-insecure-origin-as-secure'")),this.setupTransceiversAsync(r).finally((()=>{var e;null===(e=this.peerConnection)||void 0===e||e.createAnswer().then((e=>{var t;return e.sdp=this.mungeSDP(e.sdp,r),null===(t=this.peerConnection)||void 0===t?void 0:t.setLocalDescription(e)})).then((()=>{var e;this.onSendWebRTCAnswer(null===(e=this.peerConnection)||void 0===e?void 0:e.currentLocalDescription)})).catch((()=>{s.Error(s.GetStackTrace(),"createAnswer() failed")}))}))})),this.config.setOptionSettingOptions(ke.PreferredCodec,this.parseAvailableCodecs(e).filter((e=>this.config.getSettingOption(ke.PreferredCodec).options.includes(e))))}))}receiveAnswer(e){var t;null===(t=this.peerConnection)||void 0===t||t.setRemoteDescription(e),this.config.setOptionSettingOptions(ke.PreferredCodec,this.parseAvailableCodecs(e).filter((e=>this.config.getSettingOption(ke.PreferredCodec).options.includes(e))))}generateStats(){var e;null===(e=this.peerConnection)||void 0===e||e.getStats(null).then((e=>{this.aggregatedStats.processStats(e),this.onVideoStats(this.aggregatedStats),this.updateCodecSelection&&this.aggregatedStats.inboundVideoStats.codecId&&this.config.setOptionSettingValue(ke.PreferredCodec,this.aggregatedStats.codecs.get(this.aggregatedStats.inboundVideoStats.codecId))}))}close(){this.peerConnection&&(this.peerConnection.close(),this.peerConnection=null)}mungeSDP(e,t){let s=e.replace(/(a=fmtp:\d+ .*level-asymmetry-allowed=.*)\r\n/gm,"$1;x-google-start-bitrate=10000;x-google-max-bitrate=100000\r\n"),n="maxaveragebitrate=510000;";return t&&(n+="sprop-maxcapturerate=48000;"),n+=this.config.isFlagEnabled(Ee.ForceMonoAudio)?"stereo=0;":"stereo=1;",n+="useinbandfec=1",s=s.replace("useinbandfec=1",n),s}handleOnIce(e){var t;s.Log(s.GetStackTrace(),"peerconnection handleOnIce",6),this.config.isFlagEnabled(Ee.ForceTURN)&&e.candidate.indexOf("relay")<0?s.Info(s.GetStackTrace(),`Dropping candidate because it was not TURN relay. | Type= ${e.type} | Protocol= ${e.protocol} | Address=${e.address} | Port=${e.port} |`,6):null===(t=this.peerConnection)||void 0===t||t.addIceCandidate(e)}handleSignalStateChange(e){s.Log(s.GetStackTrace(),"signaling state change: "+e,6)}handleIceConnectionStateChange(e){s.Log(s.GetStackTrace(),"ice connection state change: "+e,6),this.onIceConnectionStateChange(e)}handleIceGatheringStateChange(e){s.Log(s.GetStackTrace(),"ice gathering state change: "+JSON.stringify(e),6)}handleOnTrack(e){this.onTrack(e)}handleIceCandidate(e){this.onPeerIceCandidate(e)}handleDataChannel(e){this.onDataChannel(e)}onTrack(e){}onIceConnectionStateChange(e){}onPeerIceCandidate(e){}onDataChannel(e){}setupTransceiversAsync(e){var t,s,n,r,i,o,a,l,d;return qe(this,void 0,void 0,(function*(){const c=(null===(t=this.peerConnection)||void 0===t?void 0:t.getTransceivers().length)>0;if(null===(s=this.peerConnection)||void 0===s||s.addTransceiver("video",{direction:"recvonly"}),RTCRtpReceiver.getCapabilities&&""!=this.preferredCodec)for(const e of null!==(r=null===(n=this.peerConnection)||void 0===n?void 0:n.getTransceivers())&&void 0!==r?r:[])if(e&&e.receiver&&e.receiver.track&&"video"===e.receiver.track.kind&&e.setCodecPreferences){const t=this.preferredCodec.split(" "),s=[{mimeType:"video/"+t[0],clockRate:9e4,sdpFmtpLine:t[1]?t[1]:""}];this.config.getSettingOption(ke.PreferredCodec).options.filter((e=>e!=this.preferredCodec)).forEach((e=>{const t=e.split(" ");s.push({mimeType:"video/"+t[0],clockRate:9e4,sdpFmtpLine:t[1]?t[1]:""})}));for(const e of s)""===e.sdpFmtpLine&&delete e.sdpFmtpLine;e.setCodecPreferences(s)}if(e){const e={video:!1,audio:{autoGainControl:!1,channelCount:1,echoCancellation:!1,latency:0,noiseSuppression:!1,sampleRate:48e3,sampleSize:16,volume:1}},t=yield navigator.mediaDevices.getUserMedia(e);if(t)if(c){for(const e of null!==(a=null===(o=this.peerConnection)||void 0===o?void 0:o.getTransceivers())&&void 0!==a?a:[])if(Ne.canTransceiverReceiveAudio(e))for(const s of t.getTracks())s.kind&&"audio"==s.kind&&(e.sender.replaceTrack(s),e.direction="sendrecv")}else for(const e of t.getTracks())e.kind&&"audio"==e.kind&&(null===(l=this.peerConnection)||void 0===l||l.addTransceiver(e,{direction:"sendrecv"}));else null===(d=this.peerConnection)||void 0===d||d.addTransceiver("audio",{direction:"recvonly"})}else null===(i=this.peerConnection)||void 0===i||i.addTransceiver("audio",{direction:"recvonly"})}))}onVideoStats(e){}onSendWebRTCOffer(e){}onSendWebRTCAnswer(e){}showTextOverlayConnecting(){}showTextOverlaySetupFailure(){}parseAvailableCodecs(e){if(!RTCRtpReceiver.getCapabilities)return["Only available on Chrome"];const t=[],s=(0,Ve.splitSections)(e.sdp);return s.shift(),s.forEach((e=>{const{codecs:s}=(0,Ve.parseRtpParameters)(e),n=/(VP\d|H26\d|AV1).*/;s.forEach((e=>{const s=e.name+" "+Object.keys(e.parameters||{}).map((t=>t+"="+e.parameters[t])).join(";");if(null!==n.exec(s)){"VP9"==e.name&&(e.parameters={"profile-id":"0"});const s=e.name+" "+Object.keys(e.parameters||{}).map((t=>t+"="+e.parameters[t])).join(";");t.push(s)}}))})),t}}class Xe{constructor(){this.PixelStreamingSettings=new je,this.EncoderSettings=new Je,this.WebRTCSettings=new Ye}ueCompatible(){null!=this.WebRTCSettings.MaxFPS&&(this.WebRTCSettings.FPS=this.WebRTCSettings.MaxFPS)}}class je{}class Je{}class Ye{}class Ze{constructor(){this.ReceiptTimeMs=null,this.TransmissionTimeMs=null,this.PreCaptureTimeMs=null,this.PostCaptureTimeMs=null,this.PreEncodeTimeMs=null,this.PostEncodeTimeMs=null,this.EncodeMs=null,this.CaptureToSendMs=null,this.testStartTimeMs=0,this.browserReceiptTimeMs=0,this.latencyExcludingDecode=0,this.testDuration=0,this.networkLatency=0,this.browserSendLatency=0,this.frameDisplayDeltaTimeMs=0,this.endToEndLatency=0,this.encodeLatency=0}setFrameDisplayDeltaTime(e){0==this.frameDisplayDeltaTimeMs&&(this.frameDisplayDeltaTimeMs=Math.round(e))}processFields(){null!=this.EncodeMs||null==this.PreEncodeTimeMs&&null==this.PostEncodeTimeMs||(s.Log(s.GetStackTrace(),`Setting Encode Ms \n ${this.PostEncodeTimeMs} \n ${this.PreEncodeTimeMs}`,6),this.EncodeMs=this.PostEncodeTimeMs-this.PreEncodeTimeMs),null!=this.CaptureToSendMs||null==this.PreCaptureTimeMs&&null==this.PostCaptureTimeMs||(s.Log(s.GetStackTrace(),`Setting CaptureToSendMs Ms \n ${this.PostCaptureTimeMs} \n ${this.PreCaptureTimeMs}`,6),this.CaptureToSendMs=this.PostCaptureTimeMs-this.PreCaptureTimeMs)}}class et{static setExtensionFromBytes(e,t){t.receiving||(t.mimetype="",t.extension="",t.receiving=!0,t.valid=!1,t.size=0,t.data=[],t.timestampStart=(new Date).getTime(),s.Log(s.GetStackTrace(),"Received first chunk of file",6));const n=new TextDecoder("utf-16").decode(e.slice(1));s.Log(s.GetStackTrace(),n,6),t.extension=n}static setMimeTypeFromBytes(e,t){t.receiving||(t.mimetype="",t.extension="",t.receiving=!0,t.valid=!1,t.size=0,t.data=[],t.timestampStart=(new Date).getTime(),s.Log(s.GetStackTrace(),"Received first chunk of file",6));const n=new TextDecoder("utf-16").decode(e.slice(1));s.Log(s.GetStackTrace(),n,6),t.mimetype=n}static setContentsFromBytes(e,t){if(!t.receiving)return;t.size=Math.ceil(new DataView(e.slice(1,5).buffer).getInt32(0,!0)/16379);const n=e.slice(5);if(t.data.push(n),s.Log(s.GetStackTrace(),`Received file chunk: ${t.data.length}/${t.size}`,6),t.data.length===t.size){t.receiving=!1,t.valid=!0,s.Log(s.GetStackTrace(),"Received complete file",6);const e=(new Date).getTime()-t.timestampStart,n=Math.round(16*t.size*1024/e);s.Log(s.GetStackTrace(),`Average transfer bitrate: ${n}kb/s over ${e/1e3} seconds`,6);const r=new Blob(t.data,{type:t.mimetype}),i=document.createElement("a");i.setAttribute("href",URL.createObjectURL(r)),i.setAttribute("download",`transfer.${t.extension}`),document.body.append(i),i.remove()}else t.data.length>t.size&&(t.receiving=!1,s.Error(s.GetStackTrace(),`Received bigger file than advertised: ${t.data.length}/${t.size}`))}}class tt{constructor(){this.mimetype="",this.extension="",this.receiving=!1,this.size=0,this.data=[],this.valid=!1}}class st{}st.mainButton=0,st.auxiliaryButton=1,st.secondaryButton=2,st.fourthButton=3,st.fifthButton=4;class nt{}nt.primaryButton=1,nt.secondaryButton=2,nt.auxiliaryButton=4,nt.fourthButton=8,nt.fifthButton=16;class rt{constructor(){this.unregisterCallbacks=[]}addUnregisterCallback(e){this.unregisterCallbacks.push(e)}unregisterAll(){for(const e of this.unregisterCallbacks)e();this.unregisterCallbacks=[]}}class it{constructor(e,t,s){this.touchEventListenerTracker=new rt,this.toStreamerMessagesProvider=e,this.videoElementProvider=t,this.coordinateConverter=s;const n=e=>this.onTouchStart(e),r=e=>this.onTouchEnd(e),i=e=>this.onTouchMove(e);document.addEventListener("touchstart",n,{passive:!1}),document.addEventListener("touchend",r,{passive:!1}),document.addEventListener("touchmove",i,{passive:!1}),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchstart",n))),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchend",r))),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchmove",i)))}unregisterTouchEvents(){this.touchEventListenerTracker.unregisterAll()}setVideoElementParentClientRect(e){this.videoElementParentClientRect=e}onTouchStart(e){if(this.videoElementProvider.isVideoReady()&&e.target===this.videoElementProvider.getVideoElement()){if(null==this.fakeTouchFinger){const t=e.changedTouches[0];this.fakeTouchFinger=new ot(t.identifier,t.clientX-this.videoElementParentClientRect.left,t.clientY-this.videoElementParentClientRect.top);const s=this.videoElementProvider.getVideoParentElement(),n=new MouseEvent("mouseenter",t);s.dispatchEvent(n);const r=this.coordinateConverter.normalizeAndQuantizeUnsigned(this.fakeTouchFinger.x,this.fakeTouchFinger.y);this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([st.mainButton,r.x,r.y])}e.preventDefault()}}onTouchEnd(e){if(!this.videoElementProvider.isVideoReady()||null==this.fakeTouchFinger)return;const t=this.videoElementProvider.getVideoParentElement(),s=this.toStreamerMessagesProvider.toStreamerHandlers;for(let n=0;n<e.changedTouches.length;n++){const r=e.changedTouches[n];if(r.identifier===this.fakeTouchFinger.id){const e=r.clientX-this.videoElementParentClientRect.left,n=r.clientY-this.videoElementParentClientRect.top,i=this.coordinateConverter.normalizeAndQuantizeUnsigned(e,n);s.get("MouseUp")([st.mainButton,i.x,i.y]);const o=new MouseEvent("mouseleave",r);t.dispatchEvent(o),this.fakeTouchFinger=null;break}}e.preventDefault()}onTouchMove(e){if(!this.videoElementProvider.isVideoReady()||null==this.fakeTouchFinger)return;const t=this.toStreamerMessagesProvider.toStreamerHandlers;for(let s=0;s<e.touches.length;s++){const n=e.touches[s];if(n.identifier===this.fakeTouchFinger.id){const e=n.clientX-this.videoElementParentClientRect.left,s=n.clientY-this.videoElementParentClientRect.top,r=this.coordinateConverter.normalizeAndQuantizeUnsigned(e,s),i=this.coordinateConverter.normalizeAndQuantizeSigned(e-this.fakeTouchFinger.x,s-this.fakeTouchFinger.y);t.get("MouseMove")([r.x,r.y,i.x,i.y]),this.fakeTouchFinger.x=e,this.fakeTouchFinger.y=s;break}}e.preventDefault()}}class ot{constructor(e,t,s){this.id=e,this.x=t,this.y=s}}class at{}at.backSpace=8,at.shift=16,at.control=17,at.alt=18,at.rightShift=253,at.rightControl=254,at.rightAlt=255;class lt{constructor(e,t,s){this.keyboardEventListenerTracker=new rt,this.CodeToKeyCode={Escape:27,Digit0:48,Digit1:49,Digit2:50,Digit3:51,Digit4:52,Digit5:53,Digit6:54,Digit7:55,Digit8:56,Digit9:57,Minus:173,Equal:187,Backspace:8,Tab:9,KeyQ:81,KeyW:87,KeyE:69,KeyR:82,KeyT:84,KeyY:89,KeyU:85,KeyI:73,KeyO:79,KeyP:80,BracketLeft:219,BracketRight:221,Enter:13,ControlLeft:17,KeyA:65,KeyS:83,KeyD:68,KeyF:70,KeyG:71,KeyH:72,KeyJ:74,KeyK:75,KeyL:76,Semicolon:186,Quote:222,Backquote:192,ShiftLeft:16,Backslash:220,KeyZ:90,KeyX:88,KeyC:67,KeyV:86,KeyB:66,KeyN:78,KeyM:77,Comma:188,Period:190,Slash:191,ShiftRight:253,AltLeft:18,Space:32,CapsLock:20,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,Pause:19,ScrollLock:145,NumpadDivide:111,NumpadMultiply:106,NumpadSubtract:109,NumpadAdd:107,NumpadDecimal:110,Numpad9:105,Numpad8:104,Numpad7:103,Numpad6:102,Numpad5:101,Numpad4:100,Numpad3:99,Numpad2:98,Numpad1:97,Numpad0:96,NumLock:144,ControlRight:254,AltRight:255,Home:36,End:35,ArrowUp:38,ArrowLeft:37,ArrowRight:39,ArrowDown:40,PageUp:33,PageDown:34,Insert:45,Delete:46,ContextMenu:93},this.toStreamerMessagesProvider=e,this.config=t,this.activeKeysProvider=s}registerKeyBoardEvents(){const e=e=>this.handleOnCompositionEnd(e),t=e=>this.handleOnKeyDown(e),s=e=>this.handleOnKeyUp(e),n=e=>this.handleOnKeyPress(e);document.addEventListener("compositionend",e),document.addEventListener("keydown",t),document.addEventListener("keyup",s),document.addEventListener("keypress",n),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("compositionend",e))),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("keydown",t))),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("keyup",s))),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("keypress",n)))}unregisterKeyBoardEvents(){this.keyboardEventListenerTracker.unregisterAll()}handleOnKeyDown(e){const t=this.getKeycode(e);t&&229!==t&&(s.Log(s.GetStackTrace(),`key down ${t}, repeat = ${e.repeat}`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("KeyDown")([this.getKeycode(e),e.repeat?1:0]),this.activeKeysProvider.getActiveKeys().push(t),t===at.backSpace&&document.dispatchEvent(new KeyboardEvent("keypress",{charCode:at.backSpace})),this.config.isFlagEnabled(Ee.SuppressBrowserKeys)&&this.isKeyCodeBrowserKey(t)&&e.preventDefault())}handleOnKeyUp(e){const t=this.getKeycode(e);t&&(s.Log(s.GetStackTrace(),`key up ${t}`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("KeyUp")([t]),this.config.isFlagEnabled(Ee.SuppressBrowserKeys)&&this.isKeyCodeBrowserKey(t)&&e.preventDefault())}handleOnKeyPress(e){if(!("charCode"in e))return void s.Warning(s.GetStackTrace(),"KeyboardEvent.charCode is deprecated in this browser, cannot send key press.");const t=e.charCode;s.Log(s.GetStackTrace(),`key press ${t}`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("KeyPress")([t])}handleOnCompositionEnd(e){e.data&&e.data.length&&e.data.split("").forEach((e=>{this.handleOnKeyDown(new KeyboardEvent("keydown",{keyCode:e.toUpperCase().charCodeAt(0),charCode:e.charCodeAt(0)})),this.handleOnKeyPress(new KeyboardEvent("keypress",{keyCode:e.toUpperCase().charCodeAt(0),charCode:e.charCodeAt(0)})),this.handleOnKeyUp(new KeyboardEvent("keyup",{keyCode:e.toUpperCase().charCodeAt(0),charCode:e.charCodeAt(0)}))}))}getKeycode(e){if(!("keyCode"in e)){const t=e;return t.code in this.CodeToKeyCode?this.CodeToKeyCode[t.code]:(s.Warning(s.GetStackTrace(),`Keyboard code of ${t.code} is not supported in our mapping, ignoring this key.`),null)}return e.keyCode===at.shift&&"ShiftRight"===e.code?at.rightShift:e.keyCode===at.control&&"ControlRight"===e.code?at.rightControl:e.keyCode===at.alt&&"AltRight"===e.code?at.rightAlt:e.keyCode}isKeyCodeBrowserKey(e){return e>=112&&e<=123||9===e}}class dt{constructor(e,t,s){this.x=0,this.y=0,this.updateMouseMovePositionEvent=e=>{this.updateMouseMovePosition(e)},this.mouseEventListenerTracker=new rt,this.videoElementProvider=e,this.mouseController=t,this.activeKeysProvider=s;const n=this.videoElementProvider.getVideoParentElement();this.x=n.getBoundingClientRect().width/2,this.y=n.getBoundingClientRect().height/2,this.coord=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(this.x,this.y)}unregisterMouseEvents(){this.mouseEventListenerTracker.unregisterAll()}lockStateChange(){const e=this.videoElementProvider.getVideoParentElement(),t=this.mouseController.toStreamerMessagesProvider.toStreamerHandlers;if(document.pointerLockElement===e||document.mozPointerLockElement===e)s.Log(s.GetStackTrace(),"Pointer locked",6),document.addEventListener("mousemove",this.updateMouseMovePositionEvent,!1),this.mouseEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("mousemove",this.updateMouseMovePositionEvent,!1)));else{s.Log(s.GetStackTrace(),"The pointer lock status is now unlocked",6),document.removeEventListener("mousemove",this.updateMouseMovePositionEvent,!1);let e=this.activeKeysProvider.getActiveKeys();const n=new Set(e),r=[];n.forEach((e=>{r[e]})),r.forEach((e=>{t.get("KeyUp")([e])})),e=[]}}updateMouseMovePosition(e){if(!this.videoElementProvider.isVideoReady())return;const t=this.mouseController.toStreamerMessagesProvider.toStreamerHandlers,s=this.videoElementProvider.getVideoParentElement().clientWidth,n=this.videoElementProvider.getVideoParentElement().clientHeight;this.x+=e.movementX,this.y+=e.movementY,this.x>s&&(this.x-=s),this.y>n&&(this.y-=n),this.x<0&&(this.x=s+this.x),this.y<0&&(this.y=n-this.y),this.coord=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(this.x,this.y);const r=this.mouseController.coordinateConverter.normalizeAndQuantizeSigned(e.movementX,e.movementY);t.get("MouseMove")([this.coord.x,this.coord.y,r.x,r.y])}handleMouseDown(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([e.button,this.coord.x,this.coord.y])}handleMouseUp(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseUp")([e.button,this.coord.x,this.coord.y])}handleMouseWheel(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseWheel")([e.wheelDelta,this.coord.x,this.coord.y])}handleMouseDouble(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDouble")([e.button,this.coord.x,this.coord.y])}handlePressMouseButtons(e){this.videoElementProvider.isVideoReady()&&this.mouseController.pressMouseButtons(e.buttons,this.x,this.y)}handleReleaseMouseButtons(e){this.videoElementProvider.isVideoReady()&&this.mouseController.releaseMouseButtons(e.buttons,this.x,this.y)}}class ct{constructor(e){this.mouseController=e}unregisterMouseEvents(){}updateMouseMovePosition(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;s.Log(s.GetStackTrace(),"MouseMove",6);const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY),n=this.mouseController.coordinateConverter.normalizeAndQuantizeSigned(e.movementX,e.movementY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseMove")([t.x,t.y,n.x,n.y]),e.preventDefault()}handleMouseDown(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;s.Log(s.GetStackTrace(),"onMouse Down",6);const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([e.button,t.x,t.y]),e.preventDefault()}handleMouseUp(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;s.Log(s.GetStackTrace(),"onMouse Up",6);const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseUp")([e.button,t.x,t.y]),e.preventDefault()}handleContextMenu(e){this.mouseController.videoElementProvider.isVideoReady()&&e.preventDefault()}handleMouseWheel(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseWheel")([e.wheelDelta,t.x,t.y]),e.preventDefault()}handleMouseDouble(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDouble")([e.button,t.x,t.y])}handlePressMouseButtons(e){this.mouseController.videoElementProvider.isVideoReady()&&(s.Log(s.GetStackTrace(),"onMouse press",6),this.mouseController.pressMouseButtons(e.buttons,e.offsetX,e.offsetY))}handleReleaseMouseButtons(e){this.mouseController.videoElementProvider.isVideoReady()&&(s.Log(s.GetStackTrace(),"onMouse release",6),this.mouseController.releaseMouseButtons(e.buttons,e.offsetX,e.offsetY))}}class ht{constructor(e,t,s,n){this.mouseEventListenerTracker=new rt,this.toStreamerMessagesProvider=e,this.coordinateConverter=s,this.videoElementProvider=t,this.activeKeysProvider=n,this.registerMouseEnterAndLeaveEvents()}unregisterMouseEvents(){this.mouseEventListenerTracker.unregisterAll()}registerLockedMouseEvents(e){const t=this.videoElementProvider.getVideoParentElement(),s=new dt(this.videoElementProvider,e,this.activeKeysProvider);if(t.requestPointerLock=t.requestPointerLock||t.mozRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock,t.requestPointerLock){const e=()=>{t.requestPointerLock()};t.addEventListener("click",e),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("click",e)))}const n=()=>s.lockStateChange();document.addEventListener("pointerlockchange",n,!1),document.addEventListener("mozpointerlockchange",n,!1),this.mouseEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("pointerlockchange",n,!1))),this.mouseEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("mozpointerlockchange",n,!1)));const r=e=>s.handleMouseDown(e),i=e=>s.handleMouseUp(e),o=e=>s.handleMouseWheel(e),a=e=>s.handleMouseDouble(e);t.addEventListener("mousedown",r),t.addEventListener("mouseup",i),t.addEventListener("wheel",o),t.addEventListener("dblclick",a),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mousedown",r))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mouseup",i))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("wheel",o))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("dblclick",a))),this.mouseEventListenerTracker.addUnregisterCallback((()=>s.unregisterMouseEvents())),this.mouseEventListenerTracker.addUnregisterCallback((()=>{!document.exitPointerLock||document.pointerLockElement!==t&&document.mozPointerLockElement!==t||document.exitPointerLock()}))}registerHoveringMouseEvents(e){const t=this.videoElementProvider.getVideoParentElement(),s=new ct(e),n=e=>s.updateMouseMovePosition(e),r=e=>s.handleMouseDown(e),i=e=>s.handleMouseUp(e),o=e=>s.handleContextMenu(e),a=e=>s.handleMouseWheel(e),l=e=>s.handleMouseDouble(e);t.addEventListener("mousemove",n),t.addEventListener("mousedown",r),t.addEventListener("mouseup",i),t.addEventListener("contextmenu",o),t.addEventListener("wheel",a),t.addEventListener("dblclick",l),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mousemove",n))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mousedown",r))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mouseup",i))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("contextmenu",o))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("wheel",a))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("dblclick",l))),this.mouseEventListenerTracker.addUnregisterCallback((()=>s.unregisterMouseEvents()))}registerMouseEnterAndLeaveEvents(){const e=this.videoElementProvider.getVideoParentElement(),t=e=>{this.videoElementProvider.isVideoReady()&&(s.Log(s.GetStackTrace(),"Mouse Entered",6),this.sendMouseEnter(),this.pressMouseButtons(e.buttons,e.x,e.y))},n=e=>{this.videoElementProvider.isVideoReady()&&(s.Log(s.GetStackTrace(),"Mouse Left",6),this.sendMouseLeave(),this.releaseMouseButtons(e.buttons,e.x,e.y))};e.addEventListener("mouseenter",t),e.addEventListener("mouseleave",n),this.mouseEventListenerTracker.addUnregisterCallback((()=>e.removeEventListener("mouseenter",t))),this.mouseEventListenerTracker.addUnregisterCallback((()=>e.removeEventListener("mouseleave",n)))}releaseMouseButtons(e,t,s){const n=this.coordinateConverter.normalizeAndQuantizeUnsigned(t,s);e&nt.primaryButton&&this.sendMouseUp(st.mainButton,n.x,n.y),e&nt.secondaryButton&&this.sendMouseUp(st.secondaryButton,n.x,n.y),e&nt.auxiliaryButton&&this.sendMouseUp(st.auxiliaryButton,n.x,n.y),e&nt.fourthButton&&this.sendMouseUp(st.fourthButton,n.x,n.y),e&nt.fifthButton&&this.sendMouseUp(st.fifthButton,n.x,n.y)}pressMouseButtons(e,t,s){if(!this.videoElementProvider.isVideoReady())return;const n=this.coordinateConverter.normalizeAndQuantizeUnsigned(t,s);e&nt.primaryButton&&this.sendMouseDown(st.mainButton,n.x,n.y),e&nt.secondaryButton&&this.sendMouseDown(st.secondaryButton,n.x,n.y),e&nt.auxiliaryButton&&this.sendMouseDown(st.auxiliaryButton,n.x,n.y),e&nt.fourthButton&&this.sendMouseDown(st.fourthButton,n.x,n.y),e&nt.fifthButton&&this.sendMouseDown(st.fifthButton,n.x,n.y)}sendMouseEnter(){this.videoElementProvider.isVideoReady()&&this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseEnter")()}sendMouseLeave(){this.videoElementProvider.isVideoReady()&&this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseLeave")()}sendMouseDown(e,t,n){this.videoElementProvider.isVideoReady()&&(s.Log(s.GetStackTrace(),`mouse button ${e} down at (${t}, ${n})`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([e,t,n]))}sendMouseUp(e,t,n){if(!this.videoElementProvider.isVideoReady())return;s.Log(s.GetStackTrace(),`mouse button ${e} up at (${t}, ${n})`,6);const r=this.coordinateConverter.normalizeAndQuantizeUnsigned(t,n);this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseUp")([e,r.x,r.y])}}class ut{constructor(e,t,n){this.fingers=[9,8,7,6,5,4,3,2,1,0],this.fingerIds=new Map,this.maxByteValue=255,this.touchEventListenerTracker=new rt,this.toStreamerMessagesProvider=e,this.videoElementProvider=t,this.coordinateConverter=n,this.videoElementParent=t.getVideoElement();const r=e=>this.onTouchStart(e),i=e=>this.onTouchEnd(e),o=e=>this.onTouchMove(e);this.videoElementParent.addEventListener("touchstart",r),this.videoElementParent.addEventListener("touchend",i),this.videoElementParent.addEventListener("touchmove",o),this.touchEventListenerTracker.addUnregisterCallback((()=>this.videoElementParent.removeEventListener("touchstart",r))),this.touchEventListenerTracker.addUnregisterCallback((()=>this.videoElementParent.removeEventListener("touchend",i))),this.touchEventListenerTracker.addUnregisterCallback((()=>this.videoElementParent.removeEventListener("touchmove",o))),s.Log(s.GetStackTrace(),"Touch Events Registered",6);const a=e=>{e.preventDefault()};document.addEventListener("touchmove",a),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchmove",a)))}unregisterTouchEvents(){this.touchEventListenerTracker.unregisterAll()}rememberTouch(e){const t=this.fingers.pop();void 0===t&&s.Log(s.GetStackTrace(),"exhausted touch identifiers",6),this.fingerIds.set(e.identifier,t)}forgetTouch(e){this.fingers.push(this.fingerIds.get(e.identifier)),this.fingers.sort((function(e,t){return t-e})),this.fingerIds.delete(e.identifier)}onTouchStart(e){if(this.videoElementProvider.isVideoReady()){for(let t=0;t<e.changedTouches.length;t++)this.rememberTouch(e.changedTouches[t]);s.Log(s.GetStackTrace(),"touch start",6),this.emitTouchData("TouchStart",e.changedTouches),e.preventDefault()}}onTouchEnd(e){if(this.videoElementProvider.isVideoReady()){s.Log(s.GetStackTrace(),"touch end",6),this.emitTouchData("TouchEnd",e.changedTouches);for(let t=0;t<e.changedTouches.length;t++)this.forgetTouch(e.changedTouches[t]);e.preventDefault()}}onTouchMove(e){this.videoElementProvider.isVideoReady()&&(s.Log(s.GetStackTrace(),"touch move",6),this.emitTouchData("TouchMove",e.touches),e.preventDefault())}emitTouchData(e,t){if(!this.videoElementProvider.isVideoReady())return;const n=this.videoElementProvider.getVideoParentElement().getBoundingClientRect(),r=this.toStreamerMessagesProvider.toStreamerHandlers;for(let i=0;i<t.length;i++){const o=1,a=t[i],l=a.clientX-n.left,d=a.clientY-n.top;s.Log(s.GetStackTrace(),`F${this.fingerIds.get(a.identifier)}=(${l}, ${d})`,6);const c=this.coordinateConverter.normalizeAndQuantizeUnsigned(l,d);switch(e){case"TouchStart":r.get("TouchStart")([o,c.x,c.y,this.fingerIds.get(a.identifier),this.maxByteValue*a.force,c.inRange?1:0]);break;case"TouchEnd":r.get("TouchEnd")([o,c.x,c.y,this.fingerIds.get(a.identifier),this.maxByteValue*a.force,c.inRange?1:0]);break;case"TouchMove":r.get("TouchMove")([o,c.x,c.y,this.fingerIds.get(a.identifier),this.maxByteValue*a.force,c.inRange?1:0])}}}}class gt{constructor(e){this.gamePadEventListenerTracker=new rt,this.toStreamerMessagesProvider=e,this.requestAnimationFrame=(window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.requestAnimationFrame).bind(window);const t=window;if(window.addEventListener("beforeunload",(e=>this.onBeforeUnload(e))),"GamepadEvent"in t){const e=e=>this.gamePadConnectHandler(e),t=e=>this.gamePadDisconnectHandler(e);window.addEventListener("gamepadconnected",e),window.addEventListener("gamepaddisconnected",t),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("gamepadconnected",e))),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("gamepaddisconnected",t)))}else if("WebKitGamepadEvent"in t){const e=e=>this.gamePadConnectHandler(e),t=e=>this.gamePadDisconnectHandler(e);window.addEventListener("webkitgamepadconnected",e),window.addEventListener("webkitgamepaddisconnected",t),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("webkitgamepadconnected",e))),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("webkitgamepaddisconnected",t)))}if(this.controllers=[],navigator.getGamepads)for(const e of navigator.getGamepads())e&&this.gamePadConnectHandler(new GamepadEvent("gamepadconnected",{gamepad:e}))}unregisterGamePadEvents(){this.gamePadEventListenerTracker.unregisterAll();for(const e of this.controllers)void 0!==e.id&&this.onGamepadDisconnected(e.id);this.controllers=[],this.onGamepadConnected=()=>{},this.onGamepadDisconnected=()=>{}}gamePadConnectHandler(e){s.Log(s.GetStackTrace(),"Gamepad connect handler",6);const t=e.gamepad,n={currentState:t,prevState:t,id:void 0};this.controllers.push(n),this.controllers[t.index].currentState=t,this.controllers[t.index].prevState=t,s.Log(s.GetStackTrace(),"gamepad: "+t.id+" connected",6),window.requestAnimationFrame((()=>this.updateStatus())),this.onGamepadConnected()}gamePadDisconnectHandler(e){s.Log(s.GetStackTrace(),"Gamepad disconnect handler",6),s.Log(s.GetStackTrace(),"gamepad: "+e.gamepad.id+" disconnected",6);const t=this.controllers[e.gamepad.index];delete this.controllers[e.gamepad.index],this.controllers=this.controllers.filter((e=>void 0!==e)),this.onGamepadDisconnected(t.id)}scanGamePads(){const e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[];for(let t=0;t<e.length;t++)e[t]&&e[t].index in this.controllers&&(this.controllers[e[t].index].currentState=e[t])}updateStatus(){this.scanGamePads();const e=this.toStreamerMessagesProvider.toStreamerHandlers;for(const t of this.controllers){const s=void 0===t.id?this.controllers.indexOf(t):t.id,n=t.currentState;for(let n=0;n<t.currentState.buttons.length;n++){const r=t.currentState.buttons[n],i=t.prevState.buttons[n];r.pressed?n==Ke.LeftTrigger?e.get("GamepadAnalog")([s,5,r.value]):n==Ke.RightTrigger?e.get("GamepadAnalog")([s,6,r.value]):e.get("GamepadButtonPressed")([s,n,i.pressed?1:0]):!r.pressed&&i.pressed&&(n==Ke.LeftTrigger?e.get("GamepadAnalog")([s,5,0]):n==Ke.RightTrigger?e.get("GamepadAnalog")([s,6,0]):e.get("GamepadButtonReleased")([s,n,0]))}for(let t=0;t<n.axes.length;t+=2){const r=parseFloat(n.axes[t].toFixed(4)),i=-parseFloat(n.axes[t+1].toFixed(4));e.get("GamepadAnalog")([s,t+1,r]),e.get("GamepadAnalog")([s,t+2,i])}this.controllers[s].prevState=n}this.controllers.length>0&&this.requestAnimationFrame((()=>this.updateStatus()))}onGamepadResponseReceived(e){for(const t of this.controllers)if(void 0===t.id){t.id=e;break}}onGamepadConnected(){}onGamepadDisconnected(e){}onBeforeUnload(e){for(const e of this.controllers)this.onGamepadDisconnected(e.id)}}!function(e){e[e.RightClusterBottomButton=0]="RightClusterBottomButton",e[e.RightClusterRightButton=1]="RightClusterRightButton",e[e.RightClusterLeftButton=2]="RightClusterLeftButton",e[e.RightClusterTopButton=3]="RightClusterTopButton",e[e.LeftShoulder=4]="LeftShoulder",e[e.RightShoulder=5]="RightShoulder",e[e.LeftTrigger=6]="LeftTrigger",e[e.RightTrigger=7]="RightTrigger",e[e.SelectOrBack=8]="SelectOrBack",e[e.StartOrForward=9]="StartOrForward",e[e.LeftAnalogPress=10]="LeftAnalogPress",e[e.RightAnalogPress=11]="RightAnalogPress",e[e.LeftClusterTopButton=12]="LeftClusterTopButton",e[e.LeftClusterBottomButton=13]="LeftClusterBottomButton",e[e.LeftClusterLeftButton=14]="LeftClusterLeftButton",e[e.LeftClusterRightButton=15]="LeftClusterRightButton",e[e.CentreButton=16]="CentreButton",e[e.LeftStickHorizontal=0]="LeftStickHorizontal",e[e.LeftStickVertical=1]="LeftStickVertical",e[e.RightStickHorizontal=2]="RightStickHorizontal",e[e.RightStickVertical=3]="RightStickVertical"}(Ke||(Ke={}));class mt{constructor(e,t,s){this.activeKeys=new pt,this.toStreamerMessagesProvider=e,this.videoElementProvider=t,this.coordinateConverter=s}registerKeyBoard(e){s.Log(s.GetStackTrace(),"Register Keyboard Events",7);const t=new lt(this.toStreamerMessagesProvider,e,this.activeKeys);return t.registerKeyBoardEvents(),t}registerMouse(e){s.Log(s.GetStackTrace(),"Register Mouse Events",7);const t=new ht(this.toStreamerMessagesProvider,this.videoElementProvider,this.coordinateConverter,this.activeKeys);switch(e){case Ae.LockedMouse:t.registerLockedMouseEvents(t);break;case Ae.HoveringMouse:t.registerHoveringMouseEvents(t);break;default:s.Info(s.GetStackTrace(),"unknown Control Scheme Type Defaulting to Locked Mouse Events"),t.registerLockedMouseEvents(t)}return t}registerTouch(e,t){if(s.Log(s.GetStackTrace(),"Registering Touch",6),e){const e=new it(this.toStreamerMessagesProvider,this.videoElementProvider,this.coordinateConverter);return e.setVideoElementParentClientRect(t),e}return new ut(this.toStreamerMessagesProvider,this.videoElementProvider,this.coordinateConverter)}registerGamePad(){return s.Log(s.GetStackTrace(),"Register Game Pad",7),new gt(this.toStreamerMessagesProvider)}}class pt{constructor(){this.activeKeys=[],this.activeKeys=[]}getActiveKeys(){return this.activeKeys}}class vt{constructor(e,t){this.lastTimeResized=(new Date).getTime(),this.videoElement=document.createElement("video"),this.config=t,this.videoElement.id="streamingVideo",this.videoElement.disablePictureInPicture=!0,this.videoElement.playsInline=!0,this.videoElement.style.width="100%",this.videoElement.style.height="100%",this.videoElement.style.position="absolute",this.videoElement.style.pointerEvents="all",e.appendChild(this.videoElement),this.onResizePlayerCallback=()=>{console.log("Resolution changed, restyling player, did you forget to override this function?")},this.onMatchViewportResolutionCallback=()=>{console.log("Resolution changed and match viewport resolution is turned on, did you forget to override this function?")},this.videoElement.onclick=()=>{null!=this.audioElement&&this.audioElement.paused&&this.audioElement.play(),this.videoElement.paused&&this.videoElement.play()},this.videoElement.onloadedmetadata=()=>{this.onVideoInitialized()},window.addEventListener("resize",(()=>this.resizePlayerStyle()),!0),window.addEventListener("orientationchange",(()=>this.onOrientationChange()))}setAudioElement(e){this.audioElement=e}play(){return this.videoElement.muted=this.config.isFlagEnabled(Ee.StartVideoMuted),this.videoElement.autoplay=this.config.isFlagEnabled(Ee.AutoPlayVideo),this.videoElement.play()}isPaused(){return this.videoElement.paused}isVideoReady(){return void 0!==this.videoElement.readyState&&this.videoElement.readyState>0}hasVideoSource(){return void 0!==this.videoElement.srcObject&&null!==this.videoElement.srcObject}getVideoElement(){return this.videoElement}getVideoParentElement(){return this.videoElement.parentElement}setVideoEnabled(e){this.videoElement.srcObject.getTracks().forEach((t=>t.enabled=e))}onVideoInitialized(){}onOrientationChange(){clearTimeout(this.orientationChangeTimeout),this.orientationChangeTimeout=window.setTimeout((()=>{this.resizePlayerStyle()}),500)}resizePlayerStyle(){const e=this.getVideoParentElement();e&&(this.updateVideoStreamSize(),e.classList.contains("fixed-size")||this.resizePlayerStyleToFillParentElement(),this.onResizePlayerCallback())}resizePlayerStyleToFillParentElement(){this.getVideoParentElement().setAttribute("style","top: 0px; left: 0px; width: 100%; height: 100%; cursor: default;")}updateVideoStreamSize(){if(this.config.isFlagEnabled(Ee.MatchViewportResolution))if((new Date).getTime()-this.lastTimeResized>300){const e=this.getVideoParentElement();if(!e)return;this.onMatchViewportResolutionCallback(e.clientWidth,e.clientHeight),this.lastTimeResized=(new Date).getTime()}else s.Log(s.GetStackTrace(),"Resizing too often - skipping",6),clearTimeout(this.resizeTimeoutHandle),this.resizeTimeoutHandle=window.setTimeout((()=>this.updateVideoStreamSize()),100)}}class St{constructor(){this.toStreamerHandlers=new Map,this.fromStreamerHandlers=new Map,this.toStreamerMessages=new Map,this.fromStreamerMessages=new Map}populateDefaultProtocol(){this.toStreamerMessages.set("IFrameRequest",{id:0,structure:[]}),this.toStreamerMessages.set("RequestQualityControl",{id:1,structure:[]}),this.toStreamerMessages.set("FpsRequest",{id:2,structure:[]}),this.toStreamerMessages.set("AverageBitrateRequest",{id:3,structure:[]}),this.toStreamerMessages.set("StartStreaming",{id:4,structure:[]}),this.toStreamerMessages.set("StopStreaming",{id:5,structure:[]}),this.toStreamerMessages.set("LatencyTest",{id:6,structure:["string"]}),this.toStreamerMessages.set("RequestInitialSettings",{id:7,structure:[]}),this.toStreamerMessages.set("TestEcho",{id:8,structure:[]}),this.toStreamerMessages.set("DataChannelLatencyTest",{id:9,structure:[]}),this.toStreamerMessages.set("UIInteraction",{id:50,structure:["string"]}),this.toStreamerMessages.set("Command",{id:51,structure:["string"]}),this.toStreamerMessages.set("KeyDown",{id:60,structure:["uint8","uint8"]}),this.toStreamerMessages.set("KeyUp",{id:61,structure:["uint8"]}),this.toStreamerMessages.set("KeyPress",{id:62,structure:["uint16"]}),this.toStreamerMessages.set("MouseEnter",{id:70,structure:[]}),this.toStreamerMessages.set("MouseLeave",{id:71,structure:[]}),this.toStreamerMessages.set("MouseDown",{id:72,structure:["uint8","uint16","uint16"]}),this.toStreamerMessages.set("MouseUp",{id:73,structure:["uint8","uint16","uint16"]}),this.toStreamerMessages.set("MouseMove",{id:74,structure:["uint16","uint16","int16","int16"]}),this.toStreamerMessages.set("MouseWheel",{id:75,structure:["int16","uint16","uint16"]}),this.toStreamerMessages.set("MouseDouble",{id:76,structure:["uint8","uint16","uint16"]}),this.toStreamerMessages.set("TouchStart",{id:80,structure:["uint8","uint16","uint16","uint8","uint8","uint8"]}),this.toStreamerMessages.set("TouchEnd",{id:81,structure:["uint8","uint16","uint16","uint8","uint8","uint8"]}),this.toStreamerMessages.set("TouchMove",{id:82,structure:["uint8","uint16","uint16","uint8","uint8","uint8"]}),this.toStreamerMessages.set("GamepadConnected",{id:93,structure:[]}),this.toStreamerMessages.set("GamepadButtonPressed",{id:90,structure:["uint8","uint8","uint8"]}),this.toStreamerMessages.set("GamepadButtonReleased",{id:91,structure:["uint8","uint8","uint8"]}),this.toStreamerMessages.set("GamepadAnalog",{id:92,structure:["uint8","uint8","double"]}),this.toStreamerMessages.set("GamepadDisconnected",{id:94,structure:["uint8"]}),this.fromStreamerMessages.set(0,"QualityControlOwnership"),this.fromStreamerMessages.set(1,"Response"),this.fromStreamerMessages.set(2,"Command"),this.fromStreamerMessages.set(3,"FreezeFrame"),this.fromStreamerMessages.set(4,"UnfreezeFrame"),this.fromStreamerMessages.set(5,"VideoEncoderAvgQP"),this.fromStreamerMessages.set(6,"LatencyTest"),this.fromStreamerMessages.set(7,"InitialSettings"),this.fromStreamerMessages.set(8,"FileExtension"),this.fromStreamerMessages.set(9,"FileMimeType"),this.fromStreamerMessages.set(10,"FileContents"),this.fromStreamerMessages.set(11,"TestEcho"),this.fromStreamerMessages.set(12,"InputControlOwnership"),this.fromStreamerMessages.set(13,"GamepadResponse"),this.fromStreamerMessages.set(14,"DataChannelLatencyTest"),this.fromStreamerMessages.set(255,"Protocol")}registerMessageHandler(e,t,n){switch(e){case Qe.ToStreamer:this.toStreamerHandlers.set(t,n);break;case Qe.FromStreamer:this.fromStreamerHandlers.set(t,n);break;default:s.Log(s.GetStackTrace(),`Unknown message direction ${e}`)}}}!function(e){e[e.ToStreamer=0]="ToStreamer",e[e.FromStreamer=1]="FromStreamer"}(Qe||(Qe={}));class Ct{constructor(){this.responseEventListeners=new Map}addResponseEventListener(e,t){this.responseEventListeners.set(e,t)}removeResponseEventListener(e){this.responseEventListeners.delete(e)}onResponse(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.Response",6);const t=new TextDecoder("utf-16").decode(e.slice(1));s.Log(s.GetStackTrace(),t,6),this.responseEventListeners.forEach((e=>{e(t)}))}}class ft{constructor(e,t){this.dataChannelSender=e,this.toStreamerMessagesMapProvider=t}sendMessageToStreamer(e,t){void 0===t&&(t=[]);const n=this.toStreamerMessagesMapProvider.toStreamerMessages.get(e);if(void 0===n)return void s.Error(s.GetStackTrace(),`Attempted to send a message to the streamer with message type: ${e}, but the frontend hasn't been configured to send such a message. Check you've added the message type in your cpp`);if(n.structure&&t&&n.structure.length!==t.length)return void s.Error(s.GetStackTrace(),`Provided message data doesn't match expected layout. Expected [ ${n.structure.map((e=>{switch(e){case"uint8":case"uint16":case"int16":case"float":case"double":return"number";case"string":return"string"}})).toString()} ] but received [ ${t.map((e=>typeof e)).toString()} ]`);let r=0;const i=new TextEncoder;t.forEach(((e,t)=>{switch(n.structure[t]){case"uint8":r+=1;break;case"uint16":case"int16":r+=2;break;case"float":r+=4;break;case"double":r+=8;break;case"string":r+=2,r+=2*i.encode(e).length}}));const o=new DataView(new ArrayBuffer(r+1));o.setUint8(0,n.id);let a=1;t.forEach(((e,t)=>{switch(n.structure[t]){case"uint8":o.setUint8(a,e),a+=1;break;case"uint16":o.setUint16(a,e,!0),a+=2;break;case"int16":o.setInt16(a,e,!0),a+=2;break;case"float":o.setFloat32(a,e,!0),a+=4;break;case"double":o.setFloat64(a,e,!0),a+=8;break;case"string":o.setUint16(a,e.length,!0),a+=2;for(let t=0;t<e.length;t++)o.setUint16(a,e.charCodeAt(t),!0),a+=2}})),this.dataChannelSender.canSend()?this.dataChannelSender.sendData(o.buffer):s.Info(s.GetStackTrace(),`Data channel cannot send yet, skipping sending message: ${e} - ${new Uint8Array(o.buffer)}`)}}class Tt{constructor(e){this.sendMessageController=e}SendRequestQualityControl(){this.sendMessageController.sendMessageToStreamer("RequestQualityControl")}SendMaxFpsRequest(){this.sendMessageController.sendMessageToStreamer("FpsRequest")}SendAverageBitrateRequest(){this.sendMessageController.sendMessageToStreamer("AverageBitrateRequest")}SendStartStreaming(){this.sendMessageController.sendMessageToStreamer("StartStreaming")}SendStopStreaming(){this.sendMessageController.sendMessageToStreamer("StopStreaming")}SendRequestInitialSettings(){this.sendMessageController.sendMessageToStreamer("RequestInitialSettings")}}class yt{constructor(e){this.dataChannelProvider=e}canSend(){return void 0!==this.dataChannelProvider.getDataChannelInstance().dataChannel&&"open"==this.dataChannelProvider.getDataChannelInstance().dataChannel.readyState}sendData(e){const t=this.dataChannelProvider.getDataChannelInstance();"open"==t.dataChannel.readyState?(t.dataChannel.send(e),s.Log(s.GetStackTrace(),`Message Sent: ${new Uint8Array(e)}`,6),this.resetAfkWarningTimerOnDataSend()):s.Error(s.GetStackTrace(),`Message Failed: ${new Uint8Array(e)}`)}resetAfkWarningTimerOnDataSend(){}}class Et{constructor(e){this.videoElementProvider=e,this.normalizeAndQuantizeUnsignedFunc=()=>{throw new Error("Normalize and quantize unsigned, method not implemented.")},this.normalizeAndQuantizeSignedFunc=()=>{throw new Error("Normalize and unquantize signed, method not implemented.")},this.denormalizeAndUnquantizeUnsignedFunc=()=>{throw new Error("Denormalize and unquantize unsigned, method not implemented.")}}normalizeAndQuantizeUnsigned(e,t){return this.normalizeAndQuantizeUnsignedFunc(e,t)}unquantizeAndDenormalizeUnsigned(e,t){return this.denormalizeAndUnquantizeUnsignedFunc(e,t)}normalizeAndQuantizeSigned(e,t){return this.normalizeAndQuantizeSignedFunc(e,t)}setupNormalizeAndQuantize(){if(this.videoElementParent=this.videoElementProvider.getVideoParentElement(),this.videoElement=this.videoElementProvider.getVideoElement(),this.videoElementParent&&this.videoElement){const e=this.videoElementParent.clientHeight/this.videoElementParent.clientWidth,t=this.videoElement.videoHeight/this.videoElement.videoWidth;e>t?(s.Log(s.GetStackTrace(),"Setup Normalize and Quantize for playerAspectRatio > videoAspectRatio",6),this.ratio=e/t,this.normalizeAndQuantizeUnsignedFunc=(e,t)=>this.normalizeAndQuantizeUnsignedPlayerBigger(e,t),this.normalizeAndQuantizeSignedFunc=(e,t)=>this.normalizeAndQuantizeSignedPlayerBigger(e,t),this.denormalizeAndUnquantizeUnsignedFunc=(e,t)=>this.denormalizeAndUnquantizeUnsignedPlayerBigger(e,t)):(s.Log(s.GetStackTrace(),"Setup Normalize and Quantize for playerAspectRatio <= videoAspectRatio",6),this.ratio=t/e,this.normalizeAndQuantizeUnsignedFunc=(e,t)=>this.normalizeAndQuantizeUnsignedPlayerSmaller(e,t),this.normalizeAndQuantizeSignedFunc=(e,t)=>this.normalizeAndQuantizeSignedPlayerSmaller(e,t),this.denormalizeAndUnquantizeUnsignedFunc=(e,t)=>this.denormalizeAndUnquantizeUnsignedPlayerSmaller(e,t))}}normalizeAndQuantizeUnsignedPlayerBigger(e,t){const s=e/this.videoElementParent.clientWidth,n=this.ratio*(t/this.videoElementParent.clientHeight-.5)+.5;return s<0||s>1||n<0||n>1?new Mt(!1,65535,65535):new Mt(!0,65536*s,65536*n)}denormalizeAndUnquantizeUnsignedPlayerBigger(e,t){const s=e/65536,n=(t/65536-.5)/this.ratio+.5;return new wt(s*this.videoElementParent.clientWidth,n*this.videoElementParent.clientHeight)}normalizeAndQuantizeSignedPlayerBigger(e,t){const s=e/(.5*this.videoElementParent.clientWidth),n=this.ratio*t/(.5*this.videoElementParent.clientHeight);return new bt(32767*s,32767*n)}normalizeAndQuantizeUnsignedPlayerSmaller(e,t){const s=this.ratio*(e/this.videoElementParent.clientWidth-.5)+.5,n=t/this.videoElementParent.clientHeight;return s<0||s>1||n<0||n>1?new Mt(!1,65535,65535):new Mt(!0,65536*s,65536*n)}denormalizeAndUnquantizeUnsignedPlayerSmaller(e,t){const s=(e/65536-.5)/this.ratio+.5,n=t/65536;return new wt(s*this.videoElementParent.clientWidth,n*this.videoElementParent.clientHeight)}normalizeAndQuantizeSignedPlayerSmaller(e,t){const s=this.ratio*e/(.5*this.videoElementParent.clientWidth),n=t/(.5*this.videoElementParent.clientHeight);return new bt(32767*s,32767*n)}}class Mt{constructor(e,t,s){this.inRange=e,this.x=t,this.y=s}}class wt{constructor(e,t){this.x=e,this.y=t}}class bt{constructor(e,t){this.x=e,this.y=t}}class Rt{constructor(e,t){this.shouldShowPlayOverlay=!0,this.autoJoinTimer=void 0,this.config=e,this.pixelStreaming=t,this.responseController=new Ct,this.file=new tt,this.sdpConstraints={offerToReceiveAudio:!0,offerToReceiveVideo:!0},this.afkController=new Fe(this.config,this.pixelStreaming,this.onAfkTriggered.bind(this)),this.afkController.onAFKTimedOutCallback=()=>{this.closeSignalingServer("You have been disconnected due to inactivity")},this.freezeFrameController=new D(this.pixelStreaming.videoElementParent),this.videoPlayer=new vt(this.pixelStreaming.videoElementParent,this.config),this.videoPlayer.onVideoInitialized=()=>this.handleVideoInitialized(),this.videoPlayer.onMatchViewportResolutionCallback=(e,t)=>{const s={"Resolution.Width":e,"Resolution.Height":t};this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify(s)])},this.videoPlayer.onResizePlayerCallback=()=>{this.setUpMouseAndFreezeFrame()},this.streamController=new A(this.videoPlayer),this.coordinateConverter=new Et(this.videoPlayer),this.sendrecvDataChannelController=new De,this.recvDataChannelController=new De,this.registerDataChannelEventEmitters(this.sendrecvDataChannelController),this.registerDataChannelEventEmitters(this.recvDataChannelController),this.dataChannelSender=new yt(this.sendrecvDataChannelController),this.dataChannelSender.resetAfkWarningTimerOnDataSend=()=>this.afkController.resetAfkWarningTimer(),this.streamMessageController=new St,this.transport=new l,this.protocol=new x(this.transport),this.protocol.messageHandlers.addListener(i.CONFIG,(e=>this.handleOnConfigMessage(e))),this.protocol.messageHandlers.addListener(i.STREAMER_LIST,(e=>this.handleStreamerListMessage(e))),this.protocol.messageHandlers.addListener(i.STREAMER_ID_CHANGED,(e=>this.handleStreamerIDChangedMessage(e))),this.protocol.messageHandlers.addListener(i.PLAYER_COUNT,(e=>{const t=e;this.pixelStreaming._onPlayerCount(t.count)})),this.protocol.messageHandlers.addListener(i.ANSWER,(e=>this.handleWebRtcAnswer(e))),this.protocol.messageHandlers.addListener(i.OFFER,(e=>this.handleWebRtcOffer(e))),this.protocol.messageHandlers.addListener(i.PEER_DATA_CHANNELS,(e=>this.handleWebRtcSFUPeerDatachannels(e))),this.protocol.messageHandlers.addListener(i.ICE_CANDIDATE,(e=>{const t=e;this.handleIceCandidate(t.candidate)})),this.protocol.transportEvents.addListener("open",(()=>{this.config.isFlagEnabled(Ee.BrowserSendOffer)||this.protocol.sendMessage(new y)})),this.protocol.transportEvents.addListener("error",(()=>{s.Error(s.GetStackTrace(),"Got a transport error.")})),this.protocol.transportEvents.addListener("close",(e=>{const t=this.shouldReconnect&&1001!=e.code&&this.config.getNumericSettingValue(we.MaxReconnectAttempts)>0,s=this.disconnectMessage?this.disconnectMessage:e.reason;this.pixelStreaming._onDisconnect(s,!t&&!this.isReconnecting),this.afkController.stopAfkWarningTimer(),this.statsTimerHandle&&void 0!==this.statsTimerHandle&&window.clearInterval(this.statsTimerHandle),this.setVideoEncoderAvgQP(0),this.setTouchInputEnabled(!1),this.setMouseInputEnabled(!1),this.setKeyboardInputEnabled(!1),this.setGamePadInputEnabled(!1),t&&setTimeout((()=>{this.isReconnecting=!0,this.reconnectAttempt++,this.tryReconnect(e.reason)}),2e3)})),this.sendMessageController=new ft(this.dataChannelSender,this.streamMessageController),this.toStreamerMessagesController=new Tt(this.sendMessageController),this.registerMessageHandlers(),this.streamMessageController.populateDefaultProtocol(),this.inputClassesFactory=new mt(this.streamMessageController,this.videoPlayer,this.coordinateConverter),this.isUsingSFU=!1,this.isQualityController=!1,this.preferredCodec="",this.shouldReconnect=!0,this.isReconnecting=!1,this.reconnectAttempt=0,this.config._addOnOptionSettingChangedListener(ke.StreamerId,(e=>{""!==e&&(this.peerConnectionController.peerConnection.close(),this.peerConnectionController.createPeerConnection(this.peerConfig,this.preferredCodec),this.subscribedStream=e,this.protocol.sendMessage(new E(e)))})),this.setVideoEncoderAvgQP(-1),this.signallingUrlBuilder=()=>{let e=this.config.getTextSettingValue(Re.SignallingServerUrl);return this.config.isFlagEnabled(Ee.BrowserSendOffer)&&(e+="?"+Ee.BrowserSendOffer+"=true"),e}}requestUnquantizedAndDenormalizeUnsigned(e,t){return this.coordinateConverter.unquantizeAndDenormalizeUnsigned(e,t)}handleOnMessage(e){const t=new Uint8Array(e.data);s.Log(s.GetStackTrace(),"Message incoming:"+t,6);const n=this.streamMessageController.fromStreamerMessages.get(t[0]);this.streamMessageController.fromStreamerHandlers.get(n)(e.data)}registerMessageHandlers(){this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"QualityControlOwnership",(e=>this.onQualityControlOwnership(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"Response",(e=>this.responseController.onResponse(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"Command",(e=>{this.onCommand(e)})),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"FreezeFrame",(e=>this.onFreezeFrameMessage(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"UnfreezeFrame",(()=>this.invalidateFreezeFrameAndEnableVideo())),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"VideoEncoderAvgQP",(e=>this.handleVideoEncoderAvgQP(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"LatencyTest",(e=>this.handleLatencyTestResult(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"DataChannelLatencyTest",(e=>this.handleDataChannelLatencyTestResponse(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"InitialSettings",(e=>this.handleInitialSettings(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"FileExtension",(e=>this.onFileExtension(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"FileMimeType",(e=>this.onFileMimeType(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"FileContents",(e=>this.onFileContents(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"TestEcho",(()=>{})),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"InputControlOwnership",(e=>this.onInputControlOwnership(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"GamepadResponse",(e=>this.onGamepadResponse(e))),this.streamMessageController.registerMessageHandler(Qe.FromStreamer,"Protocol",(e=>this.onProtocolMessage(e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"IFrameRequest",(()=>this.sendMessageController.sendMessageToStreamer("IFrameRequest"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"RequestQualityControl",(()=>this.sendMessageController.sendMessageToStreamer("RequestQualityControl"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"FpsRequest",(()=>this.sendMessageController.sendMessageToStreamer("FpsRequest"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"AverageBitrateRequest",(()=>this.sendMessageController.sendMessageToStreamer("AverageBitrateRequest"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"StartStreaming",(()=>this.sendMessageController.sendMessageToStreamer("StartStreaming"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"StopStreaming",(()=>this.sendMessageController.sendMessageToStreamer("StopStreaming"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"LatencyTest",(e=>this.sendMessageController.sendMessageToStreamer("LatencyTest",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"RequestInitialSettings",(()=>this.sendMessageController.sendMessageToStreamer("RequestInitialSettings"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"TestEcho",(()=>{})),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"UIInteraction",(e=>this.sendMessageController.sendMessageToStreamer("UIInteraction",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"Command",(e=>this.sendMessageController.sendMessageToStreamer("Command",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"TextboxEntry",(e=>this.sendMessageController.sendMessageToStreamer("TextboxEntry",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"KeyDown",(e=>this.sendMessageController.sendMessageToStreamer("KeyDown",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"KeyUp",(e=>this.sendMessageController.sendMessageToStreamer("KeyUp",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"KeyPress",(e=>this.sendMessageController.sendMessageToStreamer("KeyPress",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseEnter",(e=>this.sendMessageController.sendMessageToStreamer("MouseEnter",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseLeave",(e=>this.sendMessageController.sendMessageToStreamer("MouseLeave",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseDown",(e=>this.sendMessageController.sendMessageToStreamer("MouseDown",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseUp",(e=>this.sendMessageController.sendMessageToStreamer("MouseUp",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseMove",(e=>this.sendMessageController.sendMessageToStreamer("MouseMove",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseWheel",(e=>this.sendMessageController.sendMessageToStreamer("MouseWheel",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"MouseDouble",(e=>this.sendMessageController.sendMessageToStreamer("MouseDouble",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"TouchStart",(e=>this.sendMessageController.sendMessageToStreamer("TouchStart",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"TouchEnd",(e=>this.sendMessageController.sendMessageToStreamer("TouchEnd",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"TouchMove",(e=>this.sendMessageController.sendMessageToStreamer("TouchMove",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"GamepadConnected",(()=>this.sendMessageController.sendMessageToStreamer("GamepadConnected"))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"GamepadButtonPressed",(e=>this.sendMessageController.sendMessageToStreamer("GamepadButtonPressed",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"GamepadButtonReleased",(e=>this.sendMessageController.sendMessageToStreamer("GamepadButtonReleased",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"GamepadAnalog",(e=>this.sendMessageController.sendMessageToStreamer("GamepadAnalog",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"GamepadDisconnected",(e=>this.sendMessageController.sendMessageToStreamer("GamepadDisconnected",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRHMDTransform",(e=>this.sendMessageController.sendMessageToStreamer("XRHMDTransform",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRControllerTransform",(e=>this.sendMessageController.sendMessageToStreamer("XRControllerTransform",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRSystem",(e=>this.sendMessageController.sendMessageToStreamer("XRSystem",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRButtonTouched",(e=>this.sendMessageController.sendMessageToStreamer("XRButtonTouched",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRButtonPressed",(e=>this.sendMessageController.sendMessageToStreamer("XRButtonPressed",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRButtonReleased",(e=>this.sendMessageController.sendMessageToStreamer("XRButtonReleased",e))),this.streamMessageController.registerMessageHandler(Qe.ToStreamer,"XRAnalog",(e=>this.sendMessageController.sendMessageToStreamer("XRAnalog",e)))}onCommand(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.Command",6);const t=new TextDecoder("utf-16").decode(e.slice(1));s.Log(s.GetStackTrace(),"Data Channel Command: "+t,6);const n=JSON.parse(t);"onScreenKeyboard"===n.command&&this.pixelStreaming._activateOnScreenKeyboard(n)}onProtocolMessage(e){try{const t=new TextDecoder("utf-16").decode(e.slice(1)),n=JSON.parse(t);Object.prototype.hasOwnProperty.call(n,"Direction")||s.Error(s.GetStackTrace(),"Malformed protocol received. Ensure the protocol message contains a direction");const r=n.Direction;delete n.Direction,s.Log(s.GetStackTrace(),`Received new ${r==Qe.FromStreamer?"FromStreamer":"ToStreamer"} protocol. Updating existing protocol...`),Object.keys(n).forEach((e=>{const t=n[e];switch(r){case Qe.ToStreamer:if(!Object.prototype.hasOwnProperty.call(t,"id"))return void s.Error(s.GetStackTrace(),`ToStreamer->${e} protocol definition was malformed as it didn't contain at least an id\n\n Definition was: ${JSON.stringify(t,null,2)}`);if("UIInteraction"===e||"Command"===e||"LatencyTest"===e)return;this.streamMessageController.toStreamerHandlers.get(e)?this.streamMessageController.toStreamerMessages.set(e,t):s.Error(s.GetStackTrace(),`There was no registered handler for "${e}" - try adding one using registerMessageHandler(MessageDirection.ToStreamer, "${e}", myHandler)`);break;case Qe.FromStreamer:if(!Object.prototype.hasOwnProperty.call(t,"id"))return void s.Error(s.GetStackTrace(),`FromStreamer->${e} protocol definition was malformed as it didn't contain at least an id\n\n Definition was: ${JSON.stringify(t,null,2)}`);this.streamMessageController.fromStreamerHandlers.get(e)?this.streamMessageController.fromStreamerMessages.set(t.id,e):s.Error(s.GetStackTrace(),`There was no registered handler for "${t}" - try adding one using registerMessageHandler(MessageDirection.FromStreamer, "${e}", myHandler)`);break;default:s.Error(s.GetStackTrace(),`Unknown direction: ${r}`)}})),this.toStreamerMessagesController.SendRequestInitialSettings(),this.toStreamerMessagesController.SendRequestQualityControl()}catch(e){s.Log(s.GetStackTrace(),e)}}onInputControlOwnership(e){const t=new Uint8Array(e);s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.InputControlOwnership",6);const n=new Boolean(t[1]).valueOf();s.Log(s.GetStackTrace(),`Received input controller message - will your input control the stream: ${n}`),this.pixelStreaming._onInputControlOwnership(n)}onGamepadResponse(e){const t=new TextDecoder("utf-16").decode(e.slice(1)),s=JSON.parse(t);this.gamePadController.onGamepadResponseReceived(s.controllerId)}onAfkTriggered(){this.afkController.onAfkClick(),this.videoPlayer.isPaused()&&this.videoPlayer.hasVideoSource()&&this.playStream()}setAfkEnabled(e){e?this.onAfkTriggered():this.afkController.stopAfkWarningTimer()}tryReconnect(e){this.protocol?(this.isReconnecting=!0,this.protocol.isConnected()?(this.closeSignalingServer(`${e} Restarting stream...`),setTimeout((()=>{this.tryReconnect(e)}),3e3)):(this.pixelStreaming._onWebRtcAutoConnect(),this.connectToSignallingServer())):s.Log(s.GetStackTrace(),"This player has no protocol connection.")}loadFreezeFrameOrShowPlayOverlay(){this.pixelStreaming.dispatchEvent(new ae({shouldShowPlayOverlay:this.shouldShowPlayOverlay,isValid:this.freezeFrameController.valid,jpegData:this.freezeFrameController.jpeg})),!0===this.shouldShowPlayOverlay?(s.Log(s.GetStackTrace(),"showing play overlay"),this.resizePlayerStyle()):(s.Log(s.GetStackTrace(),"showing freeze frame"),this.freezeFrameController.showFreezeFrame()),setTimeout((()=>{this.videoPlayer.setVideoEnabled(!1)}),this.freezeFrameController.freezeFrameDelay)}onFreezeFrameMessage(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.FreezeFrame",6);const t=new Uint8Array(e);this.freezeFrameController.processFreezeFrameMessage(t,(()=>this.loadFreezeFrameOrShowPlayOverlay()))}invalidateFreezeFrameAndEnableVideo(){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.FreezeFrame",6),setTimeout((()=>{this.pixelStreaming.dispatchEvent(new le),this.freezeFrameController.hideFreezeFrame()}),this.freezeFrameController.freezeFrameDelay),this.videoPlayer.getVideoElement()&&this.videoPlayer.setVideoEnabled(!0)}onFileExtension(e){const t=new Uint8Array(e);et.setExtensionFromBytes(t,this.file)}onFileMimeType(e){const t=new Uint8Array(e);et.setMimeTypeFromBytes(t,this.file)}onFileContents(e){const t=new Uint8Array(e);et.setContentsFromBytes(t,this.file)}playStream(){if(!this.videoPlayer.getVideoElement()){const e="Could not play video stream because the video player was not initialized correctly.";return this.pixelStreaming.dispatchEvent(new re({message:e})),s.Error(s.GetStackTrace(),e),void this.closeSignalingServer("Stream not initialized correctly")}if(this.videoPlayer.hasVideoSource()){if(this.setTouchInputEnabled(this.config.isFlagEnabled(Ee.TouchInput)),this.pixelStreaming.dispatchEvent(new ie),this.streamController.audioElement.srcObject){const e=this.config.isFlagEnabled(Ee.StartVideoMuted);this.streamController.audioElement.muted=e,e?this.playVideo():this.streamController.audioElement.play().then((()=>{this.playVideo()})).catch((e=>{s.Log(s.GetStackTrace(),e),s.Log(s.GetStackTrace(),"Browser does not support autoplaying video without interaction - to resolve this we are going to show the play button overlay."),this.pixelStreaming.dispatchEvent(new oe({reason:e}))}))}else this.playVideo();this.shouldShowPlayOverlay=!1,this.freezeFrameController.showFreezeFrame()}else s.Warning(s.GetStackTrace(),"Cannot play stream, the video element has no srcObject to play.")}playVideo(){this.videoPlayer.play().catch((e=>{this.streamController.audioElement.srcObject&&this.streamController.audioElement.pause(),s.Log(s.GetStackTrace(),e),s.Log(s.GetStackTrace(),"Browser does not support autoplaying video without interaction - to resolve this we are going to show the play button overlay."),this.pixelStreaming.dispatchEvent(new oe({reason:e}))}))}autoPlayVideoOrSetUpPlayOverlay(){this.config.isFlagEnabled(Ee.AutoPlayVideo)&&this.playStream(),this.resizePlayerStyle()}connectToSignallingServer(){this.locallyClosed=!1,this.shouldReconnect=!0,this.disconnectMessage=null;const e=this.signallingUrlBuilder();this.protocol.connect(e)}startSession(e){if(this.peerConfig=e,this.config.isFlagEnabled(Ee.ForceTURN)&&!this.checkTurnServerAvailability(e))return s.Info(s.GetStackTrace(),"No turn server was found in the Peer Connection Options. TURN cannot be forced, closing connection. Please use STUN instead"),void this.closeSignalingServer("TURN cannot be forced, closing connection. Please use STUN instead.");this.peerConnectionController=new $e(this.peerConfig,this.config,this.preferredCodec),this.peerConnectionController.onVideoStats=e=>this.handleVideoStats(e),this.peerConnectionController.onSendWebRTCOffer=e=>this.handleSendWebRTCOffer(e),this.peerConnectionController.onSendWebRTCAnswer=e=>this.handleSendWebRTCAnswer(e),this.peerConnectionController.onPeerIceCandidate=e=>this.handleSendIceCandidate(e),this.peerConnectionController.onDataChannel=e=>this.handleDataChannel(e),this.peerConnectionController.showTextOverlayConnecting=()=>this.pixelStreaming._onWebRtcConnecting(),this.peerConnectionController.showTextOverlaySetupFailure=()=>this.pixelStreaming._onWebRtcFailed();let t=!1;this.peerConnectionController.onIceConnectionStateChange=()=>{!t&&["connected","completed"].includes(this.peerConnectionController.peerConnection.iceConnectionState)&&(this.pixelStreaming._onWebRtcConnected(),t=!0)},this.peerConnectionController.onTrack=e=>this.streamController.handleOnTrack(e),this.config.isFlagEnabled(Ee.BrowserSendOffer)&&(this.sendrecvDataChannelController.createDataChannel(this.peerConnectionController.peerConnection,"cirrus",this.datachannelOptions),this.sendrecvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e),this.peerConnectionController.createOffer(this.sdpConstraints,this.config))}checkTurnServerAvailability(e){if(!e.iceServers)return s.Info(s.GetStackTrace(),"A turn sever was not found"),!1;for(const t of e.iceServers)for(const e of t.urls)if(e.includes("turn"))return s.Log(s.GetStackTrace(),`A turn sever was found at ${e}`),!0;return s.Info(s.GetStackTrace(),"A turn sever was not found"),!1}handleOnConfigMessage(e){this.resizePlayerStyle(),this.startSession(e.peerConnectionOptions)}handleStreamerListMessage(e){s.Log(s.GetStackTrace(),`Got streamer list ${e.ids}`,6);let t=null;const n=this.config.getSettingOption(ke.StreamerId);n.selected.toString().trim()&&(t=n.selected);const r=[...e.ids];r.unshift(""),this.config.setOptionSettingOptions(ke.StreamerId,r);let i=null;const o=this.config.isFlagEnabled(Ee.WaitForStreamer),a=this.config.getNumericSettingValue(we.MaxReconnectAttempts),l=this.config.getNumericSettingValue(we.StreamerAutoJoinInterval),d=this.config.useUrlParams,c=new URLSearchParams(window.location.search);d&&c.has(ke.StreamerId)?t=c.get(ke.StreamerId):this.subscribedStream&&(t=this.subscribedStream),t&&e.ids.includes(t)?i=t:t&&o||1!=e.ids.length||(i=e.ids[0]),i?(this.isReconnecting=!1,this.reconnectAttempt=0,this.config.setOptionSettingValue(ke.StreamerId,i)):o&&(this.reconnectAttempt<a?(this.isReconnecting=!0,this.reconnectAttempt++,setTimeout((()=>{this.protocol.requestStreamerList()}),l)):(this.reconnectAttempt=0,this.isReconnecting=!1,this.shouldReconnect=!1)),this.pixelStreaming.dispatchEvent(new ce({messageStreamerList:e,autoSelectedStreamerId:i,wantedStreamerId:t}))}handleStreamerIDChangedMessage(e){const t=e.newID,s=this.config.getSettingOption(ke.StreamerId),n=s.onChange;s.onChange=()=>{};const r=s.options;for(let e=0;e<r.length;++e)if(r[e]==this.subscribedStream){r[e]=t;break}s.options=r,s.selected=t,s.onChange=n,this.subscribedStream=e.newID,this.pixelStreaming.dispatchEvent(new he({newID:t}))}handleWebRtcAnswer(e){s.Log(s.GetStackTrace(),`Got answer sdp ${e.sdp}`,6);const t={sdp:e.sdp,type:"answer"};this.peerConnectionController.receiveAnswer(t),this.handlePostWebrtcNegotiation()}handleWebRtcOffer(e){s.Log(s.GetStackTrace(),`Got offer sdp ${e.sdp}`,6),this.isUsingSFU=!!e.sfu&&e.sfu,this.isUsingSFU&&(this.peerConnectionController.preferredCodec="");const t={sdp:e.sdp,type:"offer"};this.peerConnectionController.receiveOffer(t,this.config),this.handlePostWebrtcNegotiation()}handleWebRtcSFUPeerDatachannels(e){const t={ordered:!0,negotiated:!0,id:e.sendStreamId},s=e.sendStreamId!=e.recvStreamId;if(this.sendrecvDataChannelController.createDataChannel(this.peerConnectionController.peerConnection,s?"send-datachannel":"datachannel",t),s){const t={ordered:!0,negotiated:!0,id:e.recvStreamId};this.recvDataChannelController.createDataChannel(this.peerConnectionController.peerConnection,"recv-datachannel",t),this.recvDataChannelController.handleOnOpen=()=>this.protocol.sendSFURecvDataChannelReady(),this.recvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e)}else this.sendrecvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e)}handlePostWebrtcNegotiation(){this.afkController.startAfkWarningTimer(),this.pixelStreaming._onWebRtcSdp(),this.statsTimerHandle&&void 0!==this.statsTimerHandle&&window.clearInterval(this.statsTimerHandle),this.statsTimerHandle=window.setInterval((()=>this.getStats()),1e3),this.setMouseInputEnabled(this.config.isFlagEnabled(Ee.MouseInput)),this.setKeyboardInputEnabled(this.config.isFlagEnabled(Ee.KeyboardInput)),this.setGamePadInputEnabled(this.config.isFlagEnabled(Ee.GamepadInput))}handleIceCandidate(e){s.Log(s.GetStackTrace(),"Web RTC Controller: onWebRtcIce",6);const t=new RTCIceCandidate(e);this.peerConnectionController.handleOnIce(t)}handleSendIceCandidate(e){s.Log(s.GetStackTrace(),"OnIceCandidate",6),e.candidate&&e.candidate.candidate&&this.protocol.sendIceCandidate(e.candidate)}handleDataChannel(e){s.Log(s.GetStackTrace(),"Data channel created for us by browser as we are a receiving peer.",6),this.sendrecvDataChannelController.dataChannel=e.channel,this.sendrecvDataChannelController.setupDataChannel(),this.sendrecvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e)}handleSendWebRTCOffer(e){s.Log(s.GetStackTrace(),"Sending the offer to the Server",6);const t={minBitrateBps:1e3*this.config.getNumericSettingValue(we.WebRTCMinBitrate),maxBitrateBps:1e3*this.config.getNumericSettingValue(we.WebRTCMaxBitrate)};this.protocol.sendWebRtcOffer(e,t)}handleSendWebRTCAnswer(e){s.Log(s.GetStackTrace(),"Sending the answer to the Server",6);const t={minBitrateBps:1e3*this.config.getNumericSettingValue(we.WebRTCMinBitrate),maxBitrateBps:1e3*this.config.getNumericSettingValue(we.WebRTCMaxBitrate)};this.protocol.sendWebRtcAnswer(e,t),this.isUsingSFU&&this.protocol.sendWebRtcDatachannelRequest()}setUpMouseAndFreezeFrame(){this.videoElementParentClientRect=this.videoPlayer.getVideoParentElement().getBoundingClientRect(),this.coordinateConverter.setupNormalizeAndQuantize(),this.freezeFrameController.freezeFrame.resize()}closeSignalingServer(e){var t;this.locallyClosed=!0,this.shouldReconnect=!1,this.disconnectMessage=e,null===(t=this.protocol)||void 0===t||t.disconnect()}closePeerConnection(){var e;null===(e=this.peerConnectionController)||void 0===e||e.close()}close(){this.closeSignalingServer(""),this.closePeerConnection()}getStats(){this.peerConnectionController.generateStats()}sendLatencyTest(){this.latencyStartTime=Date.now(),this.streamMessageController.toStreamerHandlers.get("LatencyTest")([JSON.stringify({StartTime:this.latencyStartTime})])}sendDataChannelLatencyTest(e){this.streamMessageController.toStreamerHandlers.get("DataChannelLatencyTest")([JSON.stringify(e)])}sendEncoderMinQP(e){s.Log(s.GetStackTrace(),`MinQP=${e}\n`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"Encoder.MinQP":e})])}sendEncoderMaxQP(e){s.Log(s.GetStackTrace(),`MaxQP=${e}\n`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"Encoder.MaxQP":e})])}sendWebRTCMinBitrate(e){s.Log(s.GetStackTrace(),`WebRTC Min Bitrate=${e}`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.MinBitrate":e})])}sendWebRTCMaxBitrate(e){s.Log(s.GetStackTrace(),`WebRTC Max Bitrate=${e}`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.MaxBitrate":e})])}sendWebRTCFps(e){s.Log(s.GetStackTrace(),`WebRTC FPS=${e}`,6),null!=e&&(this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.Fps":e})]),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.MaxFps":e})]))}sendShowFps(){s.Log(s.GetStackTrace(),"---- Sending show stat to UE ----",6),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"stat.fps":""})])}sendIframeRequest(){s.Log(s.GetStackTrace(),"---- Sending Request for an IFrame ----",6),this.streamMessageController.toStreamerHandlers.get("IFrameRequest")()}emitUIInteraction(e){s.Log(s.GetStackTrace(),"---- Sending custom UIInteraction message ----",6),this.streamMessageController.toStreamerHandlers.get("UIInteraction")([JSON.stringify(e)])}emitCommand(e){s.Log(s.GetStackTrace(),"---- Sending custom Command message ----",6),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify(e)])}emitConsoleCommand(e){s.Log(s.GetStackTrace(),"---- Sending custom Command:ConsoleCommand message ----",6),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({ConsoleCommand:e})])}sendRequestQualityControlOwnership(){s.Log(s.GetStackTrace(),"---- Sending Request to Control Quality ----",6),this.toStreamerMessagesController.SendRequestQualityControl()}handleLatencyTestResult(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.latencyTest",6);const t=new TextDecoder("utf-16").decode(e.slice(1)),n=new Ze;Object.assign(n,JSON.parse(t)),n.processFields(),n.testStartTimeMs=this.latencyStartTime,n.browserReceiptTimeMs=Date.now(),n.latencyExcludingDecode=~~(n.browserReceiptTimeMs-n.testStartTimeMs),n.testDuration=~~(n.TransmissionTimeMs-n.ReceiptTimeMs),n.networkLatency=~~(n.latencyExcludingDecode-n.testDuration),n.frameDisplayDeltaTimeMs&&n.browserReceiptTimeMs&&(n.endToEndLatency=(n.frameDisplayDeltaTimeMs,n.networkLatency,~~+n.CaptureToSendMs)),this.pixelStreaming._onLatencyTestResult(n)}handleDataChannelLatencyTestResponse(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.dataChannelLatencyResponse",6);const t=new TextDecoder("utf-16").decode(e.slice(1)),n=JSON.parse(t);this.pixelStreaming._onDataChannelLatencyTestResponse(n)}handleInitialSettings(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.InitialSettings",6);const t=new TextDecoder("utf-16").decode(e.slice(1)),n=JSON.parse(t),r=new Xe;n.Encoder&&(r.EncoderSettings=n.Encoder),n.WebRTC&&(r.WebRTCSettings=n.WebRTC),n.PixelStreaming&&(r.PixelStreamingSettings=n.PixelStreaming),n.ConfigOptions&&void 0!==n.ConfigOptions.DefaultToHover&&this.config.setFlagEnabled(Ee.HoveringMouseMode,!!n.ConfigOptions.DefaultToHover),r.ueCompatible(),s.Log(s.GetStackTrace(),t,6),this.pixelStreaming._onInitialSettings(r)}handleVideoEncoderAvgQP(e){s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.VideoEncoderAvgQP",6);const t=Number(new TextDecoder("utf-16").decode(e.slice(1)));this.setVideoEncoderAvgQP(t)}handleVideoInitialized(){this.pixelStreaming._onVideoInitialized(),this.autoPlayVideoOrSetUpPlayOverlay(),this.resizePlayerStyle(),this.videoPlayer.updateVideoStreamSize()}onQualityControlOwnership(e){const t=new Uint8Array(e);s.Log(s.GetStackTrace(),"DataChannelReceiveMessageType.QualityControlOwnership",6),this.isQualityController=new Boolean(t[1]).valueOf(),s.Log(s.GetStackTrace(),`Received quality controller message, will control quality: ${this.isQualityController}`),this.pixelStreaming._onQualityControlOwnership(this.isQualityController)}handleVideoStats(e){this.pixelStreaming._onVideoStats(e)}resizePlayerStyle(){this.videoPlayer.resizePlayerStyle()}setPreferredCodec(e){this.preferredCodec=e,this.peerConnectionController&&(this.peerConnectionController.preferredCodec=e,this.peerConnectionController.updateCodecSelection=!1)}setVideoEncoderAvgQP(e){this.videoAvgQp=e,this.pixelStreaming._onVideoEncoderAvgQP(this.videoAvgQp)}setKeyboardInputEnabled(e){var t;null===(t=this.keyboardController)||void 0===t||t.unregisterKeyBoardEvents(),e&&(this.keyboardController=this.inputClassesFactory.registerKeyBoard(this.config))}setMouseInputEnabled(e){var t;if(null===(t=this.mouseController)||void 0===t||t.unregisterMouseEvents(),e){const e=this.config.isFlagEnabled(Ee.HoveringMouseMode)?Ae.HoveringMouse:Ae.LockedMouse;this.mouseController=this.inputClassesFactory.registerMouse(e)}}setTouchInputEnabled(e){var t;null===(t=this.touchController)||void 0===t||t.unregisterTouchEvents(),e&&(this.touchController=this.inputClassesFactory.registerTouch(this.config.isFlagEnabled(Ee.FakeMouseWithTouches),this.videoElementParentClientRect))}setGamePadInputEnabled(e){var t;null===(t=this.gamePadController)||void 0===t||t.unregisterGamePadEvents(),e&&(this.gamePadController=this.inputClassesFactory.registerGamePad(),this.gamePadController.onGamepadConnected=()=>{this.streamMessageController.toStreamerHandlers.get("GamepadConnected")()},this.gamePadController.onGamepadDisconnected=e=>{this.streamMessageController.toStreamerHandlers.get("GamepadDisconnected")([e])})}registerDataChannelEventEmitters(e){e.onOpen=(e,t)=>this.pixelStreaming.dispatchEvent(new j({label:e,event:t})),e.onClose=(e,t)=>this.pixelStreaming.dispatchEvent(new J({label:e,event:t})),e.onError=(e,t)=>this.pixelStreaming.dispatchEvent(new Y({label:e,event:t}))}registerMessageHandler(e,t,n){t===Qe.FromStreamer&&void 0===n&&s.Warning(s.GetStackTrace(),`Unable to register handler for ${e} as no handler was passed`),this.streamMessageController.registerMessageHandler(t,e,(s=>void 0===n&&t===Qe.ToStreamer?this.sendMessageController.sendMessageToStreamer(e,s):n(s)))}}class Pt{static vertexShader(){return"\n\t\tattribute vec2 a_position;\n\t\tattribute vec2 a_texCoord;\n\n\t\t// input\n\t\tuniform vec2 u_resolution;\n\t\tuniform vec4 u_offset;\n\n\t\t//\n\t\tvarying vec2 v_texCoord;\n\n\t\tvoid main() {\n\t\t // convert the rectangle from pixels to 0.0 to 1.0\n\t\t vec2 zeroToOne = a_position / u_resolution;\n\n\t\t // convert from 0->1 to 0->2\n\t\t vec2 zeroToTwo = zeroToOne * 2.0;\n\n\t\t // convert from 0->2 to -1->+1 (clipspace)\n\t\t vec2 clipSpace = zeroToTwo - 1.0;\n\n\t\t gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n\t\t // pass the texCoord to the fragment shader\n\t\t // The GPU will interpolate this value between points.\n\t\t v_texCoord = (a_texCoord * u_offset.xy) + u_offset.zw;\n\t\t}\n\t\t"}static fragmentShader(){return"\n\t\tprecision mediump float;\n\n\t\t// our texture\n\t\tuniform sampler2D u_image;\n\n\t\t// the texCoords passed in from the vertex shader.\n\t\tvarying vec2 v_texCoord;\n\n\t\tvoid main() {\n\t\t gl_FragColor = texture2D(u_image, v_texCoord);\n\t\t}\n\t\t"}}class kt{static deepCopyGamepad(e){return JSON.parse(JSON.stringify({buttons:e.buttons.map((e=>JSON.parse(JSON.stringify({pressed:e.pressed,touched:e.touched})))),axes:e.axes}))}}class Lt{constructor(e){this.toStreamerMessagesProvider=e,this.controllers=[]}updateStatus(e,t,s){if(e.gamepad){const n=t.getPose(e.gripSpace,s);if(!n)return;let r=0;e.profiles.includes("htc-vive")?r=1:e.profiles.includes("oculus-touch")&&(r=2),this.toStreamerMessagesProvider.toStreamerHandlers.get("XRSystem")([r]);let i=2;switch(e.handedness){case"left":i=0;break;case"right":i=1}const o=n.transform.matrix,a=[];for(let e=0;e<16;e++)a[e]=new Float32Array([o[e]])[0];this.toStreamerMessagesProvider.toStreamerHandlers.get("XRControllerTransform")([a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15],i]),void 0===this.controllers[i]&&(this.controllers[i]={prevState:void 0,currentState:void 0,id:void 0},this.controllers[i].prevState=kt.deepCopyGamepad(e.gamepad)),this.controllers[i].currentState=kt.deepCopyGamepad(e.gamepad);const l=this.controllers[i],d=l.currentState,c=l.prevState;for(let e=0;e<d.buttons.length;e++){const t=d.buttons[e],s=c.buttons[e];t.pressed?this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonPressed")([i,e,s.pressed?1:0]):!t.pressed&&s.pressed&&this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonReleased")([i,e,0]),t.touched&&!t.pressed?this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonPressed")([i,3,s.touched?1:0]):!t.touched&&s.touched&&this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonReleased")([i,3,0])}for(let e=0;e<d.axes.length;e++)this.toStreamerMessagesProvider.toStreamerHandlers.get("XRAnalog")([i,e,d.axes[e]]);this.controllers[i].prevState=d}}}class xt{constructor(e){this.xrSession=null,this.webRtcController=e,this.xrControllers=[],this.xrGamepadController=new Lt(this.webRtcController.streamMessageController),this.onSessionEnded=new EventTarget,this.onSessionStarted=new EventTarget,this.onFrame=new EventTarget}xrClicked(){this.xrSession?this.xrSession.end():navigator.xr.requestSession("immersive-vr").then((e=>{this.onXrSessionStarted(e)}))}onXrSessionEnded(){s.Log(s.GetStackTrace(),"XR Session ended"),this.xrSession=null,this.onSessionEnded.dispatchEvent(new Event("xrSessionEnded"))}onXrSessionStarted(e){s.Log(s.GetStackTrace(),"XR Session started"),this.xrSession=e,this.xrSession.addEventListener("end",(()=>{this.onXrSessionEnded()}));const t=document.createElement("canvas");this.gl=t.getContext("webgl2",{xrCompatible:!0}),this.xrSession.updateRenderState({baseLayer:new XRWebGLLayer(this.xrSession,this.gl)});const n=this.gl.createShader(this.gl.VERTEX_SHADER);this.gl.shaderSource(n,Pt.vertexShader()),this.gl.compileShader(n);const r=this.gl.createShader(this.gl.FRAGMENT_SHADER);this.gl.shaderSource(r,Pt.fragmentShader()),this.gl.compileShader(r);const i=this.gl.createProgram();this.gl.attachShader(i,n),this.gl.attachShader(i,r),this.gl.linkProgram(i),this.gl.useProgram(i),this.positionLocation=this.gl.getAttribLocation(i,"a_position"),this.texcoordLocation=this.gl.getAttribLocation(i,"a_texCoord"),this.positionBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.positionLocation);const o=this.gl.createTexture();this.gl.bindTexture(this.gl.TEXTURE_2D,o),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.texcoordBuffer=this.gl.createBuffer(),this.resolutionLocation=this.gl.getUniformLocation(i,"u_resolution"),this.offsetLocation=this.gl.getUniformLocation(i,"u_offset"),e.requestReferenceSpace("local").then((e=>{this.xrRefSpace=e,this.xrSession.requestAnimationFrame(((e,t)=>this.onXrFrame(e,t)))})),this.onSessionStarted.dispatchEvent(new Event("xrSessionStarted"))}onXrFrame(e,t){const s=t.getViewerPose(this.xrRefSpace);if(s){const e=s.transform.matrix,t=[];for(let s=0;s<16;s++)t[s]=new Float32Array([e[s]])[0];this.webRtcController.streamMessageController.toStreamerHandlers.get("XRHMDTransform")([t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15]]);const n=this.xrSession.renderState.baseLayer;this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,n.framebuffer),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.webRtcController.videoPlayer.getVideoElement()),this.render(this.webRtcController.videoPlayer.getVideoElement())}this.webRtcController.config.isFlagEnabled(Ee.XRControllerInput)&&this.xrSession.inputSources.forEach(((e,s,n)=>{this.xrGamepadController.updateStatus(e,t,this.xrRefSpace)}),this),this.xrSession.requestAnimationFrame(((e,t)=>this.onXrFrame(e,t))),this.onFrame.dispatchEvent(new fe({time:e,frame:t}))}render(e){if(!this.gl)return;const t=this.xrSession.renderState.baseLayer;let s,n,r,i,o;this.gl.viewport(0,0,t.framebufferWidth,t.framebufferHeight),this.gl.uniform4f(this.offsetLocation,1,1,0,0),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,e.videoWidth,0,0,e.videoHeight,0,e.videoHeight,e.videoWidth,0,e.videoWidth,e.videoHeight]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.texcoordBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),s=2,n=this.gl.FLOAT,r=!1,i=0,o=0,this.gl.vertexAttribPointer(this.positionLocation,s,n,r,i,o),this.gl.enableVertexAttribArray(this.texcoordLocation),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.texcoordBuffer),s=2,n=this.gl.FLOAT,r=!1,i=0,o=0,this.gl.vertexAttribPointer(this.texcoordLocation,s,n,r,i,o),this.gl.uniform2f(this.resolutionLocation,e.videoWidth,e.videoHeight);const a=this.gl.TRIANGLES;o=0,this.gl.drawArrays(a,o,6)}static isSessionSupported(e){return navigator.xr?navigator.xr.isSessionSupported(e):new Promise((()=>!1))}}class At{constructor(e){this.editTextButton=null,this.hiddenInput=null,"ontouchstart"in document.documentElement&&this.createOnScreenKeyboardHelpers(e)}unquantizeAndDenormalizeUnsigned(e,t){return null}createOnScreenKeyboardHelpers(e){this.hiddenInput||(this.hiddenInput=document.createElement("input"),this.hiddenInput.id="hiddenInput",this.hiddenInput.maxLength=0,e.appendChild(this.hiddenInput)),this.editTextButton||(this.editTextButton=document.createElement("button"),this.editTextButton.id="editTextButton",this.editTextButton.innerHTML="edit text",e.appendChild(this.editTextButton),this.editTextButton.classList.add("hiddenState"),this.editTextButton.addEventListener("touchend",(e=>{this.hiddenInput.focus(),e.preventDefault()})))}showOnScreenKeyboard(e){if(e.showOnScreenKeyboard){this.editTextButton.classList.remove("hiddenState");const t=this.unquantizeAndDenormalizeUnsigned(e.x,e.y);this.editTextButton.style.top=t.y.toString()+"px",this.editTextButton.style.left=(t.x-40).toString()+"px"}else this.editTextButton.classList.add("hiddenState"),this.hiddenInput.blur()}}class Ft{constructor(e){this.seq=e.Seq,this.playerSentTimestamp=Date.now(),this.requestFillerSize=e.Filler?e.Filler.length:0}update(e){this.playerReceivedTimestamp=Date.now(),this.streamerReceivedTimestamp=e.ReceivedTimestamp,this.streamerSentTimestamp=e.SentTimestamp,this.responseFillerSize=e.Filler?e.Filler.length:0}}class Dt{constructor(e,t){this.sink=e,this.callback=t,this.records=new Map,this.seq=0}start(e){return!this.isRunning()&&(this.startTime=Date.now(),this.records.clear(),this.interval=setInterval((()=>{Date.now()-this.startTime>=e.duration?this.stop():this.sendRequest(e.requestSize,e.responseSize)}).bind(this),Math.floor(1e3/e.rps)),!0)}stop(){this.interval&&(clearInterval(this.interval),this.interval=void 0,this.callback(this.produceResult()))}produceResult(){const e=new Map(this.records);return{records:e,dataChannelRtt:Math.ceil(Array.from(this.records.values()).reduce(((e,t)=>e+(t.playerReceivedTimestamp-t.playerSentTimestamp)),0)/this.records.size),playerToStreamerTime:Math.ceil(Array.from(this.records.values()).reduce(((e,t)=>e+(t.streamerReceivedTimestamp-t.playerSentTimestamp)),0)/this.records.size),streamerToPlayerTime:Math.ceil(Array.from(this.records.values()).reduce(((e,t)=>e+(t.playerReceivedTimestamp-t.streamerSentTimestamp)),0)/this.records.size),exportLatencyAsCSV:()=>{let t="Timestamp;RTT;PlayerToStreamer;StreamerToPlayer;\n";return e.forEach((e=>{t+=e.playerSentTimestamp+";",t+=e.playerReceivedTimestamp-e.playerSentTimestamp+";",t+=e.streamerReceivedTimestamp-e.playerSentTimestamp+";",t+=e.playerReceivedTimestamp-e.streamerSentTimestamp+";",t+="\n"})),t}}}isRunning(){return!!this.interval}receive(e){if(!this.isRunning())return;if(!e)return void s.Error(s.GetStackTrace(),"Undefined response from server");let t=this.records.get(e.Seq);t&&t.update(e)}sendRequest(e,t){let s=this.createRequest(e,t),n=new Ft(s);this.records.set(n.seq,n),this.sink(s)}createRequest(e,t){return{Seq:this.seq++,FillResponseSize:t,Filler:e?"A".repeat(e):""}}}class Ot{constructor(e,t){this.allowConsoleCommands=!1,this.config=e,(null==t?void 0:t.videoElementParent)&&(this._videoElementParent=t.videoElementParent),this._eventEmitter=new ye,this.configureSettings(),this.setWebRtcPlayerController(new Rt(this.config,this)),this.onScreenKeyboardHelper=new At(this.videoElementParent),this.onScreenKeyboardHelper.unquantizeAndDenormalizeUnsigned=(e,t)=>this._webRtcController.requestUnquantizedAndDenormalizeUnsigned(e,t),this._activateOnScreenKeyboard=e=>this.onScreenKeyboardHelper.showOnScreenKeyboard(e),this._webXrController=new xt(this._webRtcController)}get videoElementParent(){return this._videoElementParent||(this._videoElementParent=document.createElement("div"),this._videoElementParent.id="videoElementParent"),this._videoElementParent}configureSettings(){this.config._addOnSettingChangedListener(Ee.IsQualityController,(e=>{!0!==e||this._webRtcController.isQualityController||this._webRtcController.sendRequestQualityControlOwnership()})),this.config._addOnSettingChangedListener(Ee.AFKDetection,(e=>{this._webRtcController.setAfkEnabled(e)})),this.config._addOnSettingChangedListener(Ee.MatchViewportResolution,(()=>{this._webRtcController.videoPlayer.updateVideoStreamSize()})),this.config._addOnSettingChangedListener(Ee.HoveringMouseMode,(e=>{this.config.setFlagLabel(Ee.HoveringMouseMode,`Control Scheme: ${e?"Hovering":"Locked"} Mouse`),this._webRtcController.setMouseInputEnabled(this.config.isFlagEnabled(Ee.MouseInput))})),this.config._addOnSettingChangedListener(Ee.KeyboardInput,(e=>{this._webRtcController.setKeyboardInputEnabled(e)})),this.config._addOnSettingChangedListener(Ee.MouseInput,(e=>{this._webRtcController.setMouseInputEnabled(e)})),this.config._addOnSettingChangedListener(Ee.TouchInput,(e=>{this._webRtcController.setTouchInputEnabled(e)})),this.config._addOnSettingChangedListener(Ee.GamepadInput,(e=>{this._webRtcController.setGamePadInputEnabled(e)})),this.config._addOnNumericSettingChangedListener(we.MinQP,(e=>{s.Log(s.GetStackTrace(),"-------- Sending MinQP --------",7),this._webRtcController.sendEncoderMinQP(e),s.Log(s.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(we.MaxQP,(e=>{s.Log(s.GetStackTrace(),"-------- Sending encoder settings --------",7),this._webRtcController.sendEncoderMaxQP(e),s.Log(s.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(we.WebRTCMinBitrate,(e=>{s.Log(s.GetStackTrace(),"-------- Sending web rtc settings --------",7),this._webRtcController.sendWebRTCMinBitrate(1e3*e),s.Log(s.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(we.WebRTCMaxBitrate,(e=>{s.Log(s.GetStackTrace(),"-------- Sending web rtc settings --------",7),this._webRtcController.sendWebRTCMaxBitrate(1e3*e),s.Log(s.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(we.WebRTCFPS,(e=>{s.Log(s.GetStackTrace(),"-------- Sending web rtc settings --------",7),this._webRtcController.sendWebRTCFps(e),s.Log(s.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnOptionSettingChangedListener(ke.PreferredCodec,(e=>{this._webRtcController&&this._webRtcController.setPreferredCodec(e)})),this.config._registerOnChangeEvents(this._eventEmitter)}_activateOnScreenKeyboard(e){throw new Error("Method not implemented.")}_onInputControlOwnership(e){this._inputController=e}setWebRtcPlayerController(e){this._webRtcController=e,this._webRtcController.setPreferredCodec(this.config.getSettingOption(ke.PreferredCodec).selected),this._webRtcController.resizePlayerStyle(),this.checkForAutoConnect()}connect(){this._eventEmitter.dispatchEvent(new te),this._webRtcController.connectToSignallingServer()}reconnect(){this._eventEmitter.dispatchEvent(new ne),this._webRtcController.tryReconnect("Reconnecting...")}disconnect(){this._eventEmitter.dispatchEvent(new se),this._webRtcController.close()}play(){this._onStreamLoading(),this._webRtcController.playStream()}checkForAutoConnect(){this.config.isFlagEnabled(Ee.AutoConnect)&&(this._onWebRtcAutoConnect(),this._webRtcController.connectToSignallingServer())}unmuteMicrophone(e=!1){if(!this.config.isFlagEnabled("UseMic"))return e?(this.config.setFlagEnabled("UseMic",!0),void this.reconnect()):void s.Warning(s.GetStackTrace(),"Trying to unmute mic, but PixelStreaming was initialized with no microphone track. Call with forceEnable == true to re-connect with a mic track.");this.setMicrophoneMuted(!1)}muteMicrophone(){this.config.isFlagEnabled("UseMic")?this.setMicrophoneMuted(!0):s.Info(s.GetStackTrace(),"Trying to mute mic, but PixelStreaming has no microphone track, so sending sound is already disabled.")}setMicrophoneMuted(e){var t,s,n,r;for(const i of null!==(r=null===(n=null===(s=null===(t=this._webRtcController)||void 0===t?void 0:t.peerConnectionController)||void 0===s?void 0:s.peerConnection)||void 0===n?void 0:n.getTransceivers())&&void 0!==r?r:[])Ne.canTransceiverSendAudio(i)&&(i.sender.track.enabled=!e)}_onWebRtcAutoConnect(){this._eventEmitter.dispatchEvent(new K)}_onWebRtcSdp(){this._eventEmitter.dispatchEvent(new N)}_onStreamLoading(){this._eventEmitter.dispatchEvent(new ee)}_onDisconnect(e,t){this._eventEmitter.dispatchEvent(new X({eventString:e,allowClickToReconnect:t}))}_onWebRtcConnecting(){this._eventEmitter.dispatchEvent(new Q)}_onWebRtcConnected(){this._eventEmitter.dispatchEvent(new q)}_onWebRtcFailed(){this._eventEmitter.dispatchEvent(new $)}_onVideoInitialized(){this._eventEmitter.dispatchEvent(new Z),this._videoStartTime=Date.now()}_onLatencyTestResult(e){this._eventEmitter.dispatchEvent(new ue({latencyTimings:e}))}_onDataChannelLatencyTestResponse(e){this._eventEmitter.dispatchEvent(new ge({response:e}))}_onVideoStats(e){this._videoStartTime&&void 0!==this._videoStartTime||(this._videoStartTime=Date.now()),e.handleSessionStatistics(this._videoStartTime,this._inputController,this._webRtcController.videoAvgQp),this._eventEmitter.dispatchEvent(new de({aggregatedStats:e}))}_onVideoEncoderAvgQP(e){this._eventEmitter.dispatchEvent(new V({avgQP:e}))}_onInitialSettings(e){var t;this._eventEmitter.dispatchEvent(new pe({settings:e})),e.PixelStreamingSettings&&(this.allowConsoleCommands=null!==(t=e.PixelStreamingSettings.AllowPixelStreamingCommands)&&void 0!==t&&t,!1===this.allowConsoleCommands&&s.Info(s.GetStackTrace(),"-AllowPixelStreamingCommands=false, sending arbitrary console commands from browser to UE is disabled."));const n=this.config.useUrlParams,r=new URLSearchParams(window.location.search);s.Info(s.GetStackTrace(),`using URL parameters ${n}`),e.EncoderSettings&&(this.config.setNumericSetting(we.MinQP,n&&r.has(we.MinQP)?Number.parseFloat(r.get(we.MinQP)):e.EncoderSettings.MinQP),this.config.setNumericSetting(we.MaxQP,n&&r.has(we.MaxQP)?Number.parseFloat(r.get(we.MaxQP)):e.EncoderSettings.MaxQP)),e.WebRTCSettings&&(this.config.setNumericSetting(we.WebRTCMinBitrate,n&&r.has(we.WebRTCMinBitrate)?Number.parseFloat(r.get(we.WebRTCMinBitrate)):e.WebRTCSettings.MinBitrate/1e3),this.config.setNumericSetting(we.WebRTCMaxBitrate,n&&r.has(we.WebRTCMaxBitrate)?Number.parseFloat(r.get(we.WebRTCMaxBitrate)):e.WebRTCSettings.MaxBitrate/1e3),this.config.setNumericSetting(we.WebRTCFPS,n&&r.has(we.WebRTCFPS)?Number.parseFloat(r.get(we.WebRTCFPS)):e.WebRTCSettings.FPS))}_onQualityControlOwnership(e){this.config.setFlagEnabled(Ee.IsQualityController,e)}_onPlayerCount(e){this._eventEmitter.dispatchEvent(new Te({count:e}))}requestLatencyTest(){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.sendLatencyTest(),!0)}requestDataChannelLatencyTest(e){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._dataChannelLatencyTestController||(this._dataChannelLatencyTestController=new Dt(this._webRtcController.sendDataChannelLatencyTest.bind(this._webRtcController),(e=>{this._eventEmitter.dispatchEvent(new me({result:e}))})),this.addEventListener("dataChannelLatencyTestResponse",(({data:{response:e}})=>{this._dataChannelLatencyTestController.receive(e)}))),this._dataChannelLatencyTestController.start(e))}requestShowFps(){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.sendShowFps(),!0)}requestIframe(){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.sendIframeRequest(),!0)}emitUIInteraction(e){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.emitUIInteraction(e),!0)}emitCommand(e){return!(!this._webRtcController.videoPlayer.isVideoReady()||!this.allowConsoleCommands&&"ConsoleCommand"in e||(this._webRtcController.emitCommand(e),0))}emitConsoleCommand(e){return!(!this.allowConsoleCommands||!this._webRtcController.videoPlayer.isVideoReady()||(this._webRtcController.emitConsoleCommand(e),0))}addResponseEventListener(e,t){this._webRtcController.responseController.addResponseEventListener(e,t)}removeResponseEventListener(e){this._webRtcController.responseController.removeResponseEventListener(e)}dispatchEvent(e){return this._eventEmitter.dispatchEvent(e)}addEventListener(e,t){this._eventEmitter.addEventListener(e,t)}removeEventListener(e,t){this._eventEmitter.removeEventListener(e,t)}toggleXR(){this.webXrController.xrClicked()}setSignallingUrlBuilder(e){this._webRtcController.signallingUrlBuilder=e}get signallingProtocol(){return this._webRtcController.protocol}get webXrController(){return this._webXrController}registerMessageHandler(e,t,n){t!==Qe.FromStreamer||void 0!==n?t===Qe.ToStreamer&&void 0===n?this._webRtcController.streamMessageController.registerMessageHandler(t,e,(t=>this._webRtcController.sendMessageController.sendMessageToStreamer(e,t))):this._webRtcController.streamMessageController.registerMessageHandler(t,e,(e=>n(e))):s.Warning(s.GetStackTrace(),`Unable to register an undefined handler for ${e}`)}get toStreamerHandlers(){return this._webRtcController.streamMessageController.toStreamerHandlers}isReconnecting(){return this._webRtcController.isReconnecting}}})(),r})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("sdp")):"function"==typeof define&&define.amd?define(["sdp"],t):"object"==typeof exports?exports["lib-pixelstreamingfrontend"]=t(require("sdp")):e["lib-pixelstreamingfrontend"]=t(e.sdp)}(this,(e=>(()=>{"use strict";var t={187:e=>{var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise((function(n,r){function s(n){e.removeListener(t,i),r(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",s),n([].slice.call(arguments))}p(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&p(e,"error",t,{once:!0})}(e,s)}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function o(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var s,i,a,c;if(o(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),a=i[t]),void 0===a)a=i[t]=n,++e._eventsCount;else if("function"==typeof a?a=i[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),(s=l(e))>0&&a.length>s&&!a.warned){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,c=d,console&&console.warn&&console.warn(c)}return e}function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function h(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},s=d.bind(r);return s.listener=n,r.wrapFn=s,s}function u(e,t,n){var r=e._events;if(void 0===r)return[];var s=r[t];return void 0===s?[]:"function"==typeof s?n?[s.listener||s]:[s]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(s):m(s,s.length)}function g(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function p(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function s(i){r.once&&e.removeEventListener(t,s),n(i)}))}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return l(this)},i.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var s="error"===e,i=this._events;if(void 0!==i)s=s&&void 0===i.error;else if(!s)return!1;if(s){var a;if(t.length>0&&(a=t[0]),a instanceof Error)throw a;var o=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var l=i[e];if(void 0===l)return!1;if("function"==typeof l)r(l,this,t);else{var c=l.length,d=m(l,c);for(n=0;n<c;++n)r(d[n],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return o(t),this.on(e,h(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return o(t),this.prependListener(e,h(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,s,i,a;if(o(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){a=n[i].listener,s=i;break}if(s<0)return this;0===s?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,s),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,a||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var s,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(s=i[r])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return u(this,e,!0)},i.prototype.rawListeners=function(e){return u(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):g.call(e,t)},i.prototype.listenerCount=g,i.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},366:t=>{t.exports=e}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return(()=>{r.r(s),r.d(s,{AfkLogic:()=>Dt,AfkTimedOutEvent:()=>He,AfkWarningActivateEvent:()=>We,AfkWarningDeactivateEvent:()=>_e,AfkWarningUpdateEvent:()=>ze,AggregatedStats:()=>Ht,CandidatePairStats:()=>Gt,CandidateStat:()=>Vt,Config:()=>xt,ControlSchemeType:()=>Ot,DataChannelCloseEvent:()=>Ze,DataChannelErrorEvent:()=>et,DataChannelLatencyTestResponseEvent:()=>pt,DataChannelLatencyTestResultEvent:()=>ft,DataChannelOpenEvent:()=>Ye,DataChannelStats:()=>Bt,EncoderSettings:()=>Zt,EventEmitter:()=>bt,Flags:()=>Et,HideFreezeFrameEvent:()=>dt,InboundAudioStats:()=>Ut,InboundVideoStats:()=>Nt,InitialSettings:()=>Jt,InitialSettingsEvent:()=>vt,LatencyTestResultEvent:()=>mt,LatencyTestResults:()=>tn,LoadFreezeFrameEvent:()=>ct,Logger:()=>n,MessageDirection:()=>Qt,MessageHelpers:()=>t,MessageRegistry:()=>Le,Messages:()=>e,NumericParameters:()=>Mt,OptionParameters:()=>Ft,OutBoundVideoStats:()=>Wt,PixelStreaming:()=>Nn,PlayStreamErrorEvent:()=>at,PlayStreamEvent:()=>ot,PlayStreamRejectedEvent:()=>lt,PlayerCountEvent:()=>Tt,SettingBase:()=>Ue,SettingFlag:()=>Ne,SettingNumber:()=>Be,SettingOption:()=>Ge,SettingText:()=>Ve,SettingsChangedEvent:()=>yt,SignallingProtocol:()=>xe,StatsReceivedEvent:()=>ht,StreamLoadingEvent:()=>nt,StreamPreConnectEvent:()=>rt,StreamPreDisconnectEvent:()=>st,StreamReconnectEvent:()=>it,StreamerIDChangedMessageEvent:()=>gt,StreamerListMessageEvent:()=>ut,TextParameters:()=>Pt,UnquantizedAndDenormalizeUnsigned:()=>Rn,VideoEncoderAvgQPEvent:()=>$e,VideoInitializedEvent:()=>tt,WebRTCSettings:()=>en,WebRtcAutoConnectEvent:()=>je,WebRtcConnectedEvent:()=>qe,WebRtcConnectingEvent:()=>Qe,WebRtcDisconnectedEvent:()=>Je,WebRtcFailedEvent:()=>Xe,WebRtcPlayerController:()=>Ln,WebRtcSdpEvent:()=>Ke,WebSocketTransport:()=>l,WebXRController:()=>On,XrFrameEvent:()=>Ct,XrSessionEndedEvent:()=>wt,XrSessionStartedEvent:()=>St});var e={};r.r(e),r.d(e,{answer:()=>se,base_message:()=>re,config:()=>ae,dataChannelRequest:()=>oe,disconnectPlayer:()=>le,endpointId:()=>ce,iceCandidate:()=>he,iceCandidateData:()=>de,identify:()=>ue,layerPreference:()=>ge,listStreamers:()=>me,offer:()=>pe,peerConnectionOptions:()=>ie,peerDataChannelsReady:()=>fe,ping:()=>ve,playerConnected:()=>ye,playerCount:()=>Se,playerDisconnected:()=>we,pong:()=>Ce,stats:()=>Te,streamerDataChannels:()=>be,streamerDisconnected:()=>Ee,streamerIdChanged:()=>Pe,streamerList:()=>ke,subscribe:()=>Me,unsubscribe:()=>Re});var t={};r.r(t),r.d(t,{createMessage:()=>Fe,validateMessage:()=>Ie});class n{static GetStackTrace(){const e=new Error;let t="No Stack Available for this browser";return e.stack&&(t=e.stack.toString().replace(/Error/g,"")),t}static SetLoggerVerbosity(e){null!=this.verboseLogLevel&&(this.verboseLogLevel=e)}static Log(e,t,n){n>this.verboseLogLevel||this.CommonLog("Log",null,t)}static Info(e,t,n){n>this.verboseLogLevel||this.CommonLog("Info",null,t)}static Error(e,t){this.CommonLog("Error",e,t)}static Warning(e,t){this.CommonLog("Warning",null,t)}static CommonLog(e,t,n){t?console.log(`[${e}] - ${n}\nCaller: ${t}`):console.log(`[${e}] - ${n}`)}}n.verboseLogLevel=5;var i,a,o=r(187);class l{constructor(){this.WS_OPEN_STATE=1,this.events=new o.EventEmitter}sendMessage(e){this.webSocket.send(JSON.stringify(e))}connect(e){n.Log(n.GetStackTrace(),e,6);try{return this.webSocket=new WebSocket(e),this.webSocket.onopen=e=>this.handleOnOpen(),this.webSocket.onerror=e=>this.handleOnError(),this.webSocket.onclose=e=>this.handleOnClose(e),this.webSocket.onmessage=e=>this.handleOnMessage(e),this.webSocket.onmessagebinary=e=>this.handleOnMessageBinary(e),!0}catch(e){return n.Error(e,e),!1}}disconnect(){this.webSocket.close()}isConnected(){return this.webSocket&&this.webSocket.readyState!=WebSocket.CLOSED}handleOnMessageBinary(e){e&&e.data&&e.data.text().then((e=>{const t=new MessageEvent("messageFromBinary",{data:e});this.handleOnMessage(t)})).catch((e=>{n.Error(n.GetStackTrace(),`Failed to parse binary blob from websocket, reason: ${e}`)}))}handleOnMessage(e){if(e.data&&e.data instanceof Blob)return void this.handleOnMessageBinary(e);let t;n.Log(n.GetStackTrace(),"received => \n"+JSON.stringify(JSON.parse(e.data),void 0,4),6);try{t=JSON.parse(e.data)}catch(t){return void n.Error(n.GetStackTrace(),`Error parsing message string ${e.data}.\n${t}`)}this.onMessage(t)}handleOnOpen(){n.Log(n.GetStackTrace(),"Connected to the signalling server via WebSocket",6),this.events.emit("open")}handleOnError(){this.events.emit("error")}handleOnClose(e){n.Log(n.GetStackTrace(),"Disconnected to the signalling server via WebSocket: "+JSON.stringify(e.code)+" - "+e.reason),this.events.emit("close",e)}close(){var e;null===(e=this.webSocket)||void 0===e||e.close()}}function c(e,t,n){let r,s,i=n;for(let n of e.fields){let e=n.localName;if(n.oneof){const a=i[n.oneof];if(null==(null==a?void 0:a.oneofKind))continue;if(r=a[e],s=t[n.oneof],s.oneofKind=a.oneofKind,null==r){delete s[e];continue}}else if(r=i[e],s=t,null==r)continue;switch(n.repeat&&(s[e].length=r.length),n.kind){case"scalar":case"enum":if(n.repeat)for(let t=0;t<r.length;t++)s[e][t]=r[t];else s[e]=r;break;case"message":let t=n.T();if(n.repeat)for(let n=0;n<r.length;n++)s[e][n]=t.create(r[n]);else void 0===s[e]?s[e]=t.create(r):t.mergePartial(s[e],r);break;case"map":switch(n.V.kind){case"scalar":case"enum":Object.assign(s[e],r);break;case"message":let t=n.V.T();for(let n of Object.keys(r))s[e][n]=t.create(r[n])}}}}!function(e){e.symbol=Symbol.for("protobuf-ts/unknown"),e.onRead=(n,r,s,i,a)=>{(t(r)?r[e.symbol]:r[e.symbol]=[]).push({no:s,wireType:i,data:a})},e.onWrite=(t,n,r)=>{for(let{no:t,wireType:s,data:i}of e.list(n))r.tag(t,s).raw(i)},e.list=(n,r)=>{if(t(n)){let t=n[e.symbol];return r?t.filter((e=>e.no==r)):t}return[]},e.last=(t,n)=>e.list(t,n).slice(-1)[0];const t=t=>t&&Array.isArray(t[e.symbol])}(i||(i={})),function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"}(a||(a={}));const d=Symbol.for("protobuf-ts/message-type");function h(e){let t=!1;const n=[];for(let r=0;r<e.length;r++){let s=e.charAt(r);"_"==s?t=!0:/\d/.test(s)?(n.push(s),t=!0):t?(n.push(s.toUpperCase()),t=!1):0==r?n.push(s.toLowerCase()):n.push(s)}return n.join("")}var u,g,m;function p(e){var t,n,r,s;return e.localName=null!==(t=e.localName)&&void 0!==t?t:h(e.name),e.jsonName=null!==(n=e.jsonName)&&void 0!==n?n:h(e.name),e.repeat=null!==(r=e.repeat)&&void 0!==r?r:m.NO,e.opt=null!==(s=e.opt)&&void 0!==s?s:!e.repeat&&!e.oneof&&"message"==e.kind,e}function f(e){if("object"!=typeof e||null===e||!e.hasOwnProperty("oneofKind"))return!1;switch(typeof e.oneofKind){case"string":return void 0!==e[e.oneofKind]&&2==Object.keys(e).length;case"undefined":return 1==Object.keys(e).length;default:return!1}}!function(e){e[e.DOUBLE=1]="DOUBLE",e[e.FLOAT=2]="FLOAT",e[e.INT64=3]="INT64",e[e.UINT64=4]="UINT64",e[e.INT32=5]="INT32",e[e.FIXED64=6]="FIXED64",e[e.FIXED32=7]="FIXED32",e[e.BOOL=8]="BOOL",e[e.STRING=9]="STRING",e[e.BYTES=12]="BYTES",e[e.UINT32=13]="UINT32",e[e.SFIXED32=15]="SFIXED32",e[e.SFIXED64=16]="SFIXED64",e[e.SINT32=17]="SINT32",e[e.SINT64=18]="SINT64"}(u||(u={})),function(e){e[e.BIGINT=0]="BIGINT",e[e.STRING=1]="STRING",e[e.NUMBER=2]="NUMBER"}(g||(g={})),function(e){e[e.NO=0]="NO",e[e.PACKED=1]="PACKED",e[e.UNPACKED=2]="UNPACKED"}(m||(m={}));class v{constructor(e){var t;this.fields=null!==(t=e.fields)&&void 0!==t?t:[]}prepare(){if(this.data)return;const e=[],t=[],n=[];for(let r of this.fields)if(r.oneof)n.includes(r.oneof)||(n.push(r.oneof),e.push(r.oneof),t.push(r.oneof));else switch(t.push(r.localName),r.kind){case"scalar":case"enum":r.opt&&!r.repeat||e.push(r.localName);break;case"message":r.repeat&&e.push(r.localName);break;case"map":e.push(r.localName)}this.data={req:e,known:t,oneofs:Object.values(n)}}is(e,t,n=!1){if(t<0)return!0;if(null==e||"object"!=typeof e)return!1;this.prepare();let r=Object.keys(e),s=this.data;if(r.length<s.req.length||s.req.some((e=>!r.includes(e))))return!1;if(!n&&r.some((e=>!s.known.includes(e))))return!1;if(t<1)return!0;for(const r of s.oneofs){const s=e[r];if(!f(s))return!1;if(void 0===s.oneofKind)continue;const i=this.fields.find((e=>e.localName===s.oneofKind));if(!i)return!1;if(!this.field(s[s.oneofKind],i,n,t))return!1}for(const r of this.fields)if(void 0===r.oneof&&!this.field(e[r.localName],r,n,t))return!1;return!0}field(e,t,n,r){let s=t.repeat;switch(t.kind){case"scalar":return void 0===e?t.opt:s?this.scalars(e,t.T,r,t.L):this.scalar(e,t.T,t.L);case"enum":return void 0===e?t.opt:s?this.scalars(e,u.INT32,r):this.scalar(e,u.INT32);case"message":return void 0===e||(s?this.messages(e,t.T(),n,r):this.message(e,t.T(),n,r));case"map":if("object"!=typeof e||null===e)return!1;if(r<2)return!0;if(!this.mapKeys(e,t.K,r))return!1;switch(t.V.kind){case"scalar":return this.scalars(Object.values(e),t.V.T,r,t.V.L);case"enum":return this.scalars(Object.values(e),u.INT32,r);case"message":return this.messages(Object.values(e),t.V.T(),n,r)}}return!0}message(e,t,n,r){return n?t.isAssignable(e,r):t.is(e,r)}messages(e,t,n,r){if(!Array.isArray(e))return!1;if(r<2)return!0;if(n){for(let n=0;n<e.length&&n<r;n++)if(!t.isAssignable(e[n],r-1))return!1}else for(let n=0;n<e.length&&n<r;n++)if(!t.is(e[n],r-1))return!1;return!0}scalar(e,t,n){let r=typeof e;switch(t){case u.UINT64:case u.FIXED64:case u.INT64:case u.SFIXED64:case u.SINT64:switch(n){case g.BIGINT:return"bigint"==r;case g.NUMBER:return"number"==r&&!isNaN(e);default:return"string"==r}case u.BOOL:return"boolean"==r;case u.STRING:return"string"==r;case u.BYTES:return e instanceof Uint8Array;case u.DOUBLE:case u.FLOAT:return"number"==r&&!isNaN(e);default:return"number"==r&&Number.isInteger(e)}}scalars(e,t,n,r){if(!Array.isArray(e))return!1;if(n<2)return!0;if(Array.isArray(e))for(let s=0;s<e.length&&s<n;s++)if(!this.scalar(e[s],t,r))return!1;return!0}mapKeys(e,t,n){let r=Object.keys(e);switch(t){case u.INT32:case u.FIXED32:case u.SFIXED32:case u.SINT32:case u.UINT32:return this.scalars(r.slice(0,n).map((e=>parseInt(e))),t,n);case u.BOOL:return this.scalars(r.slice(0,n).map((e=>"true"==e||"false"!=e&&e)),t,n);default:return this.scalars(r,t,n,g.STRING)}}}function y(e){let t=typeof e;if("object"==t){if(Array.isArray(e))return"array";if(null===e)return"null"}return t}let S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),w=[];for(let e=0;e<S.length;e++)w[S[e].charCodeAt(0)]=e;function C(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,0==(128&r))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(15&n)<<28,t=(112&n)>>4,0==(128&n))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,0==(128&r))return this.assertBounds(),[e,t]}throw new Error("invalid varint")}function T(e,t,n){for(let r=0;r<28;r+=7){const s=e>>>r,i=!(s>>>7==0&&0==t),a=255&(i?128|s:s);if(n.push(a),!i)return}const r=e>>>28&15|(7&t)<<4,s=!(t>>3==0);if(n.push(255&(s?128|r:r)),s){for(let e=3;e<31;e+=7){const r=t>>>e,s=!(r>>>7==0),i=255&(s?128|r:r);if(n.push(i),!s)return}n.push(t>>>31&1)}}w["-".charCodeAt(0)]=S.indexOf("+"),w["_".charCodeAt(0)]=S.indexOf("/");const b=4294967296;function E(e){let t="-"==e[0];t&&(e=e.slice(1));const n=1e6;let r=0,s=0;function i(t,i){const a=Number(e.slice(t,i));s*=n,r=r*n+a,r>=b&&(s+=r/b|0,r%=b)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),[t,r,s]}function k(e,t){if(t>>>0<=2097151)return""+(b*t+(e>>>0));let n=(e>>>24|t<<8)>>>0&16777215,r=t>>16&65535,s=(16777215&e)+6777216*n+6710656*r,i=n+8147497*r,a=2*r,o=1e7;function l(e,t){let n=e?String(e):"";return t?"0000000".slice(n.length)+n:n}return s>=o&&(i+=Math.floor(s/o),s%=o),i>=o&&(a+=Math.floor(i/o),i%=o),l(a,0)+l(i,a)+l(s,1)}function M(e,t){if(e>=0){for(;e>127;)t.push(127&e|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(127&e|128),e>>=7;t.push(1)}}function R(){let e=this.buf[this.pos++],t=127&e;if(0==(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<7,0==(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<14,0==(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<21,0==(128&e))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(15&e)<<28;for(let t=5;0!=(128&e)&&t<10;t++)e=this.buf[this.pos++];if(0!=(128&e))throw new Error("invalid varint");return this.assertBounds(),t>>>0}let P;function L(e){if(!e)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}!function(){const e=new DataView(new ArrayBuffer(8)),t=void 0!==globalThis.BigInt&&"function"==typeof e.getBigInt64&&"function"==typeof e.getBigUint64&&"function"==typeof e.setBigInt64&&"function"==typeof e.setBigUint64;P=t?{MIN:BigInt("-9223372036854775808"),MAX:BigInt("9223372036854775807"),UMIN:BigInt("0"),UMAX:BigInt("18446744073709551615"),C:BigInt,V:e}:void 0}();const F=/^-?[0-9]+$/,I=4294967296,x=2147483648;class O{constructor(e,t){this.lo=0|e,this.hi=0|t}isZero(){return 0==this.lo&&0==this.hi}toNumber(){let e=this.hi*I+(this.lo>>>0);if(!Number.isSafeInteger(e))throw new Error("cannot convert to safe number");return e}}class D extends O{static from(e){if(P)switch(typeof e){case"string":if("0"==e)return this.ZERO;if(""==e)throw new Error("string is no integer");e=P.C(e);case"number":if(0===e)return this.ZERO;e=P.C(e);case"bigint":if(!e)return this.ZERO;if(e<P.UMIN)throw new Error("signed value for ulong");if(e>P.UMAX)throw new Error("ulong too large");return P.V.setBigUint64(0,e,!0),new D(P.V.getInt32(0,!0),P.V.getInt32(4,!0))}else switch(typeof e){case"string":if("0"==e)return this.ZERO;if(e=e.trim(),!F.test(e))throw new Error("string is no integer");let[t,n,r]=E(e);if(t)throw new Error("signed value for ulong");return new D(n,r);case"number":if(0==e)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");if(e<0)throw new Error("signed value for ulong");return new D(e,e/I)}throw new Error("unknown value "+typeof e)}toString(){return P?this.toBigInt().toString():k(this.lo,this.hi)}toBigInt(){return L(P),P.V.setInt32(0,this.lo,!0),P.V.setInt32(4,this.hi,!0),P.V.getBigUint64(0,!0)}}D.ZERO=new D(0,0);class A extends O{static from(e){if(P)switch(typeof e){case"string":if("0"==e)return this.ZERO;if(""==e)throw new Error("string is no integer");e=P.C(e);case"number":if(0===e)return this.ZERO;e=P.C(e);case"bigint":if(!e)return this.ZERO;if(e<P.MIN)throw new Error("signed long too small");if(e>P.MAX)throw new Error("signed long too large");return P.V.setBigInt64(0,e,!0),new A(P.V.getInt32(0,!0),P.V.getInt32(4,!0))}else switch(typeof e){case"string":if("0"==e)return this.ZERO;if(e=e.trim(),!F.test(e))throw new Error("string is no integer");let[t,n,r]=E(e);if(t){if(r>x||r==x&&0!=n)throw new Error("signed long too small")}else if(r>=x)throw new Error("signed long too large");let s=new A(n,r);return t?s.negate():s;case"number":if(0==e)return this.ZERO;if(!Number.isSafeInteger(e))throw new Error("number is no integer");return e>0?new A(e,e/I):new A(-e,-e/I).negate()}throw new Error("unknown value "+typeof e)}isNegative(){return 0!=(this.hi&x)}negate(){let e=~this.hi,t=this.lo;return t?t=1+~t:e+=1,new A(t,e)}toString(){if(P)return this.toBigInt().toString();if(this.isNegative()){let e=this.negate();return"-"+k(e.lo,e.hi)}return k(this.lo,this.hi)}toBigInt(){return L(P),P.V.setInt32(0,this.lo,!0),P.V.setInt32(4,this.hi,!0),P.V.getBigInt64(0,!0)}}function U(e,t){if(!e)throw new Error(t)}function N(e){if("number"!=typeof e)throw new Error("invalid int 32: "+typeof e);if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new Error("invalid int 32: "+e)}function B(e){if("number"!=typeof e)throw new Error("invalid uint 32: "+typeof e);if(!Number.isInteger(e)||e>4294967295||e<0)throw new Error("invalid uint 32: "+e)}function V(e){if("number"!=typeof e)throw new Error("invalid float 32: "+typeof e);if(Number.isFinite(e)&&(e>34028234663852886e22||e<-34028234663852886e22))throw new Error("invalid float 32: "+e)}function G(e,t){switch(t){case g.BIGINT:return e.toBigInt();case g.NUMBER:return e.toNumber();default:return e.toString()}}A.ZERO=new A(0,0);class W{constructor(e){this.info=e}prepare(){var e;if(void 0===this.fMap){this.fMap={};const t=null!==(e=this.info.fields)&&void 0!==e?e:[];for(const e of t)this.fMap[e.name]=e,this.fMap[e.jsonName]=e,this.fMap[e.localName]=e}}assert(e,t,n){if(!e){let e=y(n);throw"number"!=e&&"boolean"!=e||(e=n.toString()),new Error(`Cannot parse JSON ${e} for ${this.info.typeName}#${t}`)}}read(e,t,n){this.prepare();const r=[];for(const[i,a]of Object.entries(e)){const e=this.fMap[i];if(!e){if(!n.ignoreUnknownFields)throw new Error(`Found unknown field while reading ${this.info.typeName} from JSON format. JSON key: ${i}`);continue}const o=e.localName;let l;if(e.oneof){if(null===a&&("enum"!==e.kind||"google.protobuf.NullValue"!==e.T()[0]))continue;if(r.includes(e.oneof))throw new Error(`Multiple members of the oneof group "${e.oneof}" of ${this.info.typeName} are present in JSON.`);r.push(e.oneof),l=t[e.oneof]={oneofKind:o}}else l=t;if("map"==e.kind){if(null===a)continue;this.assert(null!==(s=a)&&"object"==typeof s&&!Array.isArray(s),e.name,a);const t=l[o];for(const[r,s]of Object.entries(a)){let i;switch(this.assert(null!==s,e.name+" map value",null),e.V.kind){case"message":i=e.V.T().internalJsonRead(s,n);break;case"enum":if(i=this.enum(e.V.T(),s,e.name,n.ignoreUnknownFields),!1===i)continue;break;case"scalar":i=this.scalar(s,e.V.T,e.V.L,e.name)}this.assert(void 0!==i,e.name+" map value",s);let a=r;e.K==u.BOOL&&(a="true"==a||"false"!=a&&a),a=this.scalar(a,e.K,g.STRING,e.name).toString(),t[a]=i}}else if(e.repeat){if(null===a)continue;this.assert(Array.isArray(a),e.name,a);const t=l[o];for(const r of a){let s;switch(this.assert(null!==r,e.name,null),e.kind){case"message":s=e.T().internalJsonRead(r,n);break;case"enum":if(s=this.enum(e.T(),r,e.name,n.ignoreUnknownFields),!1===s)continue;break;case"scalar":s=this.scalar(r,e.T,e.L,e.name)}this.assert(void 0!==s,e.name,a),t.push(s)}}else switch(e.kind){case"message":if(null===a&&"google.protobuf.Value"!=e.T().typeName){this.assert(void 0===e.oneof,e.name+" (oneof member)",null);continue}l[o]=e.T().internalJsonRead(a,n,l[o]);break;case"enum":let t=this.enum(e.T(),a,e.name,n.ignoreUnknownFields);if(!1===t)continue;l[o]=t;break;case"scalar":l[o]=this.scalar(a,e.T,e.L,e.name)}}var s}enum(e,t,n,r){if("google.protobuf.NullValue"==e[0]&&U(null===t||"NULL_VALUE"===t,`Unable to parse field ${this.info.typeName}#${n}, enum ${e[0]} only accepts null.`),null===t)return 0;switch(typeof t){case"number":return U(Number.isInteger(t),`Unable to parse field ${this.info.typeName}#${n}, enum can only be integral number, got ${t}.`),t;case"string":let s=t;e[2]&&t.substring(0,e[2].length)===e[2]&&(s=t.substring(e[2].length));let i=e[1][s];return(void 0!==i||!r)&&(U("number"==typeof i,`Unable to parse field ${this.info.typeName}#${n}, enum ${e[0]} has no value for "${t}".`),i)}U(!1,`Unable to parse field ${this.info.typeName}#${n}, cannot parse enum value from ${typeof t}".`)}scalar(e,t,n,r){let s;try{switch(t){case u.DOUBLE:case u.FLOAT:if(null===e)return 0;if("NaN"===e)return Number.NaN;if("Infinity"===e)return Number.POSITIVE_INFINITY;if("-Infinity"===e)return Number.NEGATIVE_INFINITY;if(""===e){s="empty string";break}if("string"==typeof e&&e.trim().length!==e.length){s="extra whitespace";break}if("string"!=typeof e&&"number"!=typeof e)break;let r=Number(e);if(Number.isNaN(r)){s="not a number";break}if(!Number.isFinite(r)){s="too large or small";break}return t==u.FLOAT&&V(r),r;case u.INT32:case u.FIXED32:case u.SFIXED32:case u.SINT32:case u.UINT32:if(null===e)return 0;let i;if("number"==typeof e?i=e:""===e?s="empty string":"string"==typeof e&&(e.trim().length!==e.length?s="extra whitespace":i=Number(e)),void 0===i)break;return t==u.UINT32?B(i):N(i),i;case u.INT64:case u.SFIXED64:case u.SINT64:if(null===e)return G(A.ZERO,n);if("number"!=typeof e&&"string"!=typeof e)break;return G(A.from(e),n);case u.FIXED64:case u.UINT64:if(null===e)return G(D.ZERO,n);if("number"!=typeof e&&"string"!=typeof e)break;return G(D.from(e),n);case u.BOOL:if(null===e)return!1;if("boolean"!=typeof e)break;return e;case u.STRING:if(null===e)return"";if("string"!=typeof e){s="extra whitespace";break}try{encodeURIComponent(e)}catch(s){s="invalid UTF8";break}return e;case u.BYTES:if(null===e||""===e)return new Uint8Array(0);if("string"!=typeof e)break;return function(e){let t=3*e.length/4;"="==e[e.length-2]?t-=2:"="==e[e.length-1]&&(t-=1);let n,r=new Uint8Array(t),s=0,i=0,a=0;for(let t=0;t<e.length;t++){if(n=w[e.charCodeAt(t)],void 0===n)switch(e[t]){case"=":i=0;case"\n":case"\r":case"\t":case" ":continue;default:throw Error("invalid base64 string.")}switch(i){case 0:a=n,i=1;break;case 1:r[s++]=a<<2|(48&n)>>4,a=n,i=2;break;case 2:r[s++]=(15&a)<<4|(60&n)>>2,a=n,i=3;break;case 3:r[s++]=(3&a)<<6|n,i=0}}if(1==i)throw Error("invalid base64 string.");return r.subarray(0,s)}(e)}}catch(e){s=e.message}this.assert(!1,r+(s?" - "+s:""),e)}}class z{constructor(e){var t;this.fields=null!==(t=e.fields)&&void 0!==t?t:[]}write(e,t){const n={},r=e;for(const e of this.fields){if(!e.oneof){let s=this.field(e,r[e.localName],t);void 0!==s&&(n[t.useProtoFieldName?e.name:e.jsonName]=s);continue}const s=r[e.oneof];if(s.oneofKind!==e.localName)continue;const i="scalar"==e.kind||"enum"==e.kind?Object.assign(Object.assign({},t),{emitDefaultValues:!0}):t;let a=this.field(e,s[e.localName],i);U(void 0!==a),n[t.useProtoFieldName?e.name:e.jsonName]=a}return n}field(e,t,n){let r;if("map"==e.kind){U("object"==typeof t&&null!==t);const s={};switch(e.V.kind){case"scalar":for(const[n,r]of Object.entries(t)){const t=this.scalar(e.V.T,r,e.name,!1,!0);U(void 0!==t),s[n.toString()]=t}break;case"message":const r=e.V.T();for(const[i,a]of Object.entries(t)){const t=this.message(r,a,e.name,n);U(void 0!==t),s[i.toString()]=t}break;case"enum":const i=e.V.T();for(const[r,a]of Object.entries(t)){U(void 0===a||"number"==typeof a);const t=this.enum(i,a,e.name,!1,!0,n.enumAsInteger);U(void 0!==t),s[r.toString()]=t}}(n.emitDefaultValues||Object.keys(s).length>0)&&(r=s)}else if(e.repeat){U(Array.isArray(t));const s=[];switch(e.kind){case"scalar":for(let n=0;n<t.length;n++){const r=this.scalar(e.T,t[n],e.name,e.opt,!0);U(void 0!==r),s.push(r)}break;case"enum":const r=e.T();for(let i=0;i<t.length;i++){U(void 0===t[i]||"number"==typeof t[i]);const a=this.enum(r,t[i],e.name,e.opt,!0,n.enumAsInteger);U(void 0!==a),s.push(a)}break;case"message":const i=e.T();for(let r=0;r<t.length;r++){const a=this.message(i,t[r],e.name,n);U(void 0!==a),s.push(a)}}(n.emitDefaultValues||s.length>0||n.emitDefaultValues)&&(r=s)}else switch(e.kind){case"scalar":r=this.scalar(e.T,t,e.name,e.opt,n.emitDefaultValues);break;case"enum":r=this.enum(e.T(),t,e.name,e.opt,n.emitDefaultValues,n.enumAsInteger);break;case"message":r=this.message(e.T(),t,e.name,n)}return r}enum(e,t,n,r,s,i){if("google.protobuf.NullValue"==e[0])return s||r?null:void 0;if(void 0!==t){if(0!==t||s||r)return U("number"==typeof t),U(Number.isInteger(t)),i||!e[1].hasOwnProperty(t)?t:e[2]?e[2]+e[1][t]:e[1][t]}else U(r)}message(e,t,n,r){return void 0===t?r.emitDefaultValues?null:void 0:e.internalJsonWrite(t,r)}scalar(e,t,n,r,s){if(void 0===t)return void U(r);const i=s||r;switch(e){case u.INT32:case u.SFIXED32:case u.SINT32:return 0===t?i?0:void 0:(N(t),t);case u.FIXED32:case u.UINT32:return 0===t?i?0:void 0:(B(t),t);case u.FLOAT:V(t);case u.DOUBLE:return 0===t?i?0:void 0:(U("number"==typeof t),Number.isNaN(t)?"NaN":t===Number.POSITIVE_INFINITY?"Infinity":t===Number.NEGATIVE_INFINITY?"-Infinity":t);case u.STRING:return""===t?i?"":void 0:(U("string"==typeof t),t);case u.BOOL:return!1===t?!i&&void 0:(U("boolean"==typeof t),t);case u.UINT64:case u.FIXED64:U("number"==typeof t||"string"==typeof t||"bigint"==typeof t);let e=D.from(t);if(e.isZero()&&!i)return;return e.toString();case u.INT64:case u.SFIXED64:case u.SINT64:U("number"==typeof t||"string"==typeof t||"bigint"==typeof t);let n=A.from(t);if(n.isZero()&&!i)return;return n.toString();case u.BYTES:return U(t instanceof Uint8Array),t.byteLength?function(e){let t,n="",r=0,s=0;for(let i=0;i<e.length;i++)switch(t=e[i],r){case 0:n+=S[t>>2],s=(3&t)<<4,r=1;break;case 1:n+=S[s|t>>4],s=(15&t)<<2,r=2;break;case 2:n+=S[s|t>>6],n+=S[63&t],r=0}return r&&(n+=S[s],n+="=",1==r&&(n+="=")),n}(t):i?"":void 0}}}function _(e,t=g.STRING){switch(e){case u.BOOL:return!1;case u.UINT64:case u.FIXED64:return G(D.ZERO,t);case u.INT64:case u.SFIXED64:case u.SINT64:return G(A.ZERO,t);case u.DOUBLE:case u.FLOAT:return 0;case u.BYTES:return new Uint8Array(0);case u.STRING:return"";default:return 0}}class H{constructor(e){this.info=e}prepare(){var e;if(!this.fieldNoToField){const t=null!==(e=this.info.fields)&&void 0!==e?e:[];this.fieldNoToField=new Map(t.map((e=>[e.no,e])))}}read(e,t,n,r){this.prepare();const s=void 0===r?e.len:e.pos+r;for(;e.pos<s;){const[r,s]=e.tag(),o=this.fieldNoToField.get(r);if(!o){let a=n.readUnknownField;if("throw"==a)throw new Error(`Unknown field ${r} (wire type ${s}) for ${this.info.typeName}`);let o=e.skip(s);!1!==a&&(!0===a?i.onRead:a)(this.info.typeName,t,r,s,o);continue}let l=t,c=o.repeat,d=o.localName;switch(o.oneof&&(l=l[o.oneof],l.oneofKind!==d&&(l=t[o.oneof]={oneofKind:d})),o.kind){case"scalar":case"enum":let t="enum"==o.kind?u.INT32:o.T,r="scalar"==o.kind?o.L:void 0;if(c){let n=l[d];if(s==a.LengthDelimited&&t!=u.STRING&&t!=u.BYTES){let s=e.uint32()+e.pos;for(;e.pos<s;)n.push(this.scalar(e,t,r))}else n.push(this.scalar(e,t,r))}else l[d]=this.scalar(e,t,r);break;case"message":if(c){let t=l[d],r=o.T().internalBinaryRead(e,e.uint32(),n);t.push(r)}else l[d]=o.T().internalBinaryRead(e,e.uint32(),n,l[d]);break;case"map":let[i,h]=this.mapEntry(o,e,n);l[d][i]=h}}}mapEntry(e,t,n){let r,s,i=t.uint32(),a=t.pos+i;for(;t.pos<a;){let[i,a]=t.tag();switch(i){case 1:r=e.K==u.BOOL?t.bool().toString():this.scalar(t,e.K,g.STRING);break;case 2:switch(e.V.kind){case"scalar":s=this.scalar(t,e.V.T,e.V.L);break;case"enum":s=t.int32();break;case"message":s=e.V.T().internalBinaryRead(t,t.uint32(),n)}break;default:throw new Error(`Unknown field ${i} (wire type ${a}) in map entry for ${this.info.typeName}#${e.name}`)}}if(void 0===r){let t=_(e.K);r=e.K==u.BOOL?t.toString():t}if(void 0===s)switch(e.V.kind){case"scalar":s=_(e.V.T,e.V.L);break;case"enum":s=0;break;case"message":s=e.V.T().create()}return[r,s]}scalar(e,t,n){switch(t){case u.INT32:return e.int32();case u.STRING:return e.string();case u.BOOL:return e.bool();case u.DOUBLE:return e.double();case u.FLOAT:return e.float();case u.INT64:return G(e.int64(),n);case u.UINT64:return G(e.uint64(),n);case u.FIXED64:return G(e.fixed64(),n);case u.FIXED32:return e.fixed32();case u.BYTES:return e.bytes();case u.UINT32:return e.uint32();case u.SFIXED32:return e.sfixed32();case u.SFIXED64:return G(e.sfixed64(),n);case u.SINT32:return e.sint32();case u.SINT64:return G(e.sint64(),n)}}}class ${constructor(e){this.info=e}prepare(){if(!this.fields){const e=this.info.fields?this.info.fields.concat():[];this.fields=e.sort(((e,t)=>e.no-t.no))}}write(e,t,n){this.prepare();for(const r of this.fields){let s,i,a=r.repeat,o=r.localName;if(r.oneof){const t=e[r.oneof];if(t.oneofKind!==o)continue;s=t[o],i=!0}else s=e[o],i=!1;switch(r.kind){case"scalar":case"enum":let e="enum"==r.kind?u.INT32:r.T;if(a)if(U(Array.isArray(s)),a==m.PACKED)this.packed(t,e,r.no,s);else for(const n of s)this.scalar(t,e,r.no,n,!0);else void 0===s?U(r.opt):this.scalar(t,e,r.no,s,i||r.opt);break;case"message":if(a){U(Array.isArray(s));for(const e of s)this.message(t,n,r.T(),r.no,e)}else this.message(t,n,r.T(),r.no,s);break;case"map":U("object"==typeof s&&null!==s);for(const[e,i]of Object.entries(s))this.mapEntry(t,n,r,e,i)}}let r=n.writeUnknownFields;!1!==r&&(!0===r?i.onWrite:r)(this.info.typeName,e,t)}mapEntry(e,t,n,r,s){e.tag(n.no,a.LengthDelimited),e.fork();let i=r;switch(n.K){case u.INT32:case u.FIXED32:case u.UINT32:case u.SFIXED32:case u.SINT32:i=Number.parseInt(r);break;case u.BOOL:U("true"==r||"false"==r),i="true"==r}switch(this.scalar(e,n.K,1,i,!0),n.V.kind){case"scalar":this.scalar(e,n.V.T,2,s,!0);break;case"enum":this.scalar(e,u.INT32,2,s,!0);break;case"message":this.message(e,t,n.V.T(),2,s)}e.join()}message(e,t,n,r,s){void 0!==s&&(n.internalBinaryWrite(s,e.tag(r,a.LengthDelimited).fork(),t),e.join())}scalar(e,t,n,r,s){let[i,a,o]=this.scalarInfo(t,r);o&&!s||(e.tag(n,i),e[a](r))}packed(e,t,n,r){if(!r.length)return;U(t!==u.BYTES&&t!==u.STRING),e.tag(n,a.LengthDelimited),e.fork();let[,s]=this.scalarInfo(t);for(let t=0;t<r.length;t++)e[s](r[t]);e.join()}scalarInfo(e,t){let n,r=a.Varint,s=void 0===t,i=0===t;switch(e){case u.INT32:n="int32";break;case u.STRING:i=s||!t.length,r=a.LengthDelimited,n="string";break;case u.BOOL:i=!1===t,n="bool";break;case u.UINT32:n="uint32";break;case u.DOUBLE:r=a.Bit64,n="double";break;case u.FLOAT:r=a.Bit32,n="float";break;case u.INT64:i=s||A.from(t).isZero(),n="int64";break;case u.UINT64:i=s||D.from(t).isZero(),n="uint64";break;case u.FIXED64:i=s||D.from(t).isZero(),r=a.Bit64,n="fixed64";break;case u.BYTES:i=s||!t.byteLength,r=a.LengthDelimited,n="bytes";break;case u.FIXED32:r=a.Bit32,n="fixed32";break;case u.SFIXED32:r=a.Bit32,n="sfixed32";break;case u.SFIXED64:i=s||A.from(t).isZero(),r=a.Bit64,n="sfixed64";break;case u.SINT32:n="sint32";break;case u.SINT64:i=s||A.from(t).isZero(),n="sint64"}return[r,n,s||i]}}const K={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0},j={ignoreUnknownFields:!1},Q=Object.values;function q(e,t,n){if(t===n)return!0;if(e!==u.BYTES)return!1;let r=t,s=n;if(r.length!==s.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!=s[e])return!1;return!0}function X(e,t,n){if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!q(e,t[r],n[r]))return!1;return!0}function J(e,t,n){if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e.equals(t[r],n[r]))return!1;return!0}const Y={writeUnknownFields:!0,writerFactory:()=>new Z};class Z{constructor(e){this.stack=[],this.textEncoder=null!=e?e:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(B(e);e>127;)this.buf.push(127&e|128),e>>>=7;return this.buf.push(e),this}int32(e){return N(e),M(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){V(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){B(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){N(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return N(e),M(e=(e<<1^e>>31)>>>0,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=A.from(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=D.from(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=A.from(e);return T(t.lo,t.hi,this.buf),this}sint64(e){let t=A.from(e),n=t.hi>>31;return T(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=D.from(e);return T(t.lo,t.hi,this.buf),this}}const ee={readUnknownField:!0,readerFactory:e=>new te(e)};class te{constructor(e,t){this.varint64=C,this.uint32=R,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=null!=t?t:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0})}tag(){let e=this.uint32(),t=e>>>3,n=7&e;if(t<=0||n<0||n>5)throw new Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e){let t=this.pos;switch(e){case a.Varint:for(;128&this.buf[this.pos++];);break;case a.Bit64:this.pos+=4;case a.Bit32:this.pos+=4;break;case a.LengthDelimited:let t=this.uint32();this.pos+=t;break;case a.StartGroup:let n;for(;(n=this.tag()[1])!==a.EndGroup;)this.skip(n);break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(t,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let e=this.uint32();return e>>>1^-(1&e)}int64(){return new A(...this.varint64())}uint64(){return new D(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(1&e);return e=(e>>>1|(1&t)<<31)^n,t=t>>>1^n,new A(e,t)}bool(){let[e,t]=this.varint64();return 0!==e||0!==t}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return new D(this.sfixed32(),this.sfixed32())}sfixed64(){return new A(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}}class ne{constructor(e,t,n){this.defaultCheckDepth=16,this.typeName=e,this.fields=t.map(p),this.options=null!=n?n:{},this.messagePrototype=Object.defineProperty({},d,{value:this}),this.refTypeCheck=new v(this),this.refJsonReader=new W(this),this.refJsonWriter=new z(this),this.refBinReader=new H(this),this.refBinWriter=new $(this)}create(e){let t=function(e){const t=e.messagePrototype?Object.create(e.messagePrototype):Object.defineProperty({},d,{value:e});for(let n of e.fields){let e=n.localName;if(!n.opt)if(n.oneof)t[n.oneof]={oneofKind:void 0};else if(n.repeat)t[e]=[];else switch(n.kind){case"scalar":t[e]=_(n.T,n.L);break;case"enum":t[e]=0;break;case"map":t[e]={}}}return t}(this);return void 0!==e&&c(this,t,e),t}clone(e){let t=this.create();return c(this,t,e),t}equals(e,t){return function(e,t,n){if(t===n)return!0;if(!t||!n)return!1;for(let r of e.fields){let e=r.localName,s=r.oneof?t[r.oneof][e]:t[e],i=r.oneof?n[r.oneof][e]:n[e];switch(r.kind){case"enum":case"scalar":let e="enum"==r.kind?u.INT32:r.T;if(!(r.repeat?X(e,s,i):q(e,s,i)))return!1;break;case"map":if(!("message"==r.V.kind?J(r.V.T(),Q(s),Q(i)):X("enum"==r.V.kind?u.INT32:r.V.T,Q(s),Q(i))))return!1;break;case"message":let t=r.T();if(!(r.repeat?J(t,s,i):t.equals(s,i)))return!1}}return!0}(this,e,t)}is(e,t=this.defaultCheckDepth){return this.refTypeCheck.is(e,t,!1)}isAssignable(e,t=this.defaultCheckDepth){return this.refTypeCheck.is(e,t,!0)}mergePartial(e,t){c(this,e,t)}fromBinary(e,t){let n=function(e){return e?Object.assign(Object.assign({},ee),e):ee}(t);return this.internalBinaryRead(n.readerFactory(e),e.byteLength,n)}fromJson(e,t){return this.internalJsonRead(e,function(e){return e?Object.assign(Object.assign({},j),e):j}(t))}fromJsonString(e,t){let n=JSON.parse(e);return this.fromJson(n,t)}toJson(e,t){return this.internalJsonWrite(e,function(e){return e?Object.assign(Object.assign({},K),e):K}(t))}toJsonString(e,t){var n;let r=this.toJson(e,t);return JSON.stringify(r,null,null!==(n=null==t?void 0:t.prettySpaces)&&void 0!==n?n:0)}toBinary(e,t){let n=function(e){return e?Object.assign(Object.assign({},Y),e):Y}(t);return this.internalBinaryWrite(e,n.writerFactory(),n).finish()}internalJsonRead(e,t,n){if(null!==e&&"object"==typeof e&&!Array.isArray(e)){let r=null!=n?n:this.create();return this.refJsonReader.read(e,r,t),r}throw new Error(`Unable to parse message ${this.typeName} from JSON ${y(e)}.`)}internalJsonWrite(e,t){return this.refJsonWriter.write(e,t)}internalBinaryWrite(e,t,n){return this.refBinWriter.write(e,t,n),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create();return this.refBinReader.read(e,s,n,t),s}}const re=new class extends ne{constructor(){super("base_message",[{no:1,name:"type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();if(1===t)s.type=e.string();else{let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},se=new class extends ne{constructor(){super("answer",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"sdp",kind:"scalar",T:9},{no:3,name:"playerId",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.sdp="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.sdp=e.string();break;case 3:s.playerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.sdp&&t.tag(2,a.LengthDelimited).string(e.sdp),void 0!==e.playerId&&t.tag(3,a.LengthDelimited).string(e.playerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ie=new class extends ne{constructor(){super("peerConnectionOptions",[])}create(e){const t=globalThis.Object.create(this.messagePrototype);return void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){return null!=r?r:this.create()}internalBinaryWrite(e,t,n){let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ae=new class extends ne{constructor(){super("config",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"peerConnectionOptions",kind:"message",T:()=>ie},{no:3,name:"protocolVersion",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.peerConnectionOptions=ie.internalBinaryRead(e,e.uint32(),n,s.peerConnectionOptions);break;case 3:s.protocolVersion=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),e.peerConnectionOptions&&ie.internalBinaryWrite(e.peerConnectionOptions,t.tag(2,a.LengthDelimited).fork(),n).join(),void 0!==e.protocolVersion&&t.tag(3,a.LengthDelimited).string(e.protocolVersion);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},oe=new class extends ne{constructor(){super("dataChannelRequest",[{no:1,name:"type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();if(1===t)s.type=e.string();else{let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},le=new class extends ne{constructor(){super("disconnectPlayer",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"playerId",kind:"scalar",T:9},{no:3,name:"reason",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.playerId="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.playerId=e.string();break;case 3:s.reason=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.playerId&&t.tag(2,a.LengthDelimited).string(e.playerId),void 0!==e.reason&&t.tag(3,a.LengthDelimited).string(e.reason);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ce=new class extends ne{constructor(){super("endpointId",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"id",kind:"scalar",T:9},{no:3,name:"protocolVersion",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.id="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.id=e.string();break;case 3:s.protocolVersion=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.id&&t.tag(2,a.LengthDelimited).string(e.id),void 0!==e.protocolVersion&&t.tag(3,a.LengthDelimited).string(e.protocolVersion);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},de=new class extends ne{constructor(){super("iceCandidateData",[{no:1,name:"candidate",kind:"scalar",T:9},{no:2,name:"sdpMid",kind:"scalar",T:9},{no:3,name:"sdpMLineIndex",kind:"scalar",T:5},{no:4,name:"usernameFragment",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.candidate="",t.sdpMid="",t.sdpMLineIndex=0,void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.candidate=e.string();break;case 2:s.sdpMid=e.string();break;case 3:s.sdpMLineIndex=e.int32();break;case 4:s.usernameFragment=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.candidate&&t.tag(1,a.LengthDelimited).string(e.candidate),""!==e.sdpMid&&t.tag(2,a.LengthDelimited).string(e.sdpMid),0!==e.sdpMLineIndex&&t.tag(3,a.Varint).int32(e.sdpMLineIndex),void 0!==e.usernameFragment&&t.tag(4,a.LengthDelimited).string(e.usernameFragment);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},he=new class extends ne{constructor(){super("iceCandidate",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"candidate",kind:"message",T:()=>de},{no:3,name:"playerId",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.candidate=de.internalBinaryRead(e,e.uint32(),n,s.candidate);break;case 3:s.playerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),e.candidate&&de.internalBinaryWrite(e.candidate,t.tag(2,a.LengthDelimited).fork(),n).join(),void 0!==e.playerId&&t.tag(3,a.LengthDelimited).string(e.playerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ue=new class extends ne{constructor(){super("identify",[{no:1,name:"type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();if(1===t)s.type=e.string();else{let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ge=new class extends ne{constructor(){super("layerPreference",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"spatialLayer",kind:"scalar",T:5},{no:3,name:"temporalLayer",kind:"scalar",T:5},{no:4,name:"playerId",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.spatialLayer=0,t.temporalLayer=0,t.playerId="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.spatialLayer=e.int32();break;case 3:s.temporalLayer=e.int32();break;case 4:s.playerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),0!==e.spatialLayer&&t.tag(2,a.Varint).int32(e.spatialLayer),0!==e.temporalLayer&&t.tag(3,a.Varint).int32(e.temporalLayer),""!==e.playerId&&t.tag(4,a.LengthDelimited).string(e.playerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},me=new class extends ne{constructor(){super("listStreamers",[{no:1,name:"type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();if(1===t)s.type=e.string();else{let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},pe=new class extends ne{constructor(){super("offer",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"sdp",kind:"scalar",T:9},{no:3,name:"playerId",kind:"scalar",opt:!0,T:9},{no:4,name:"sfu",kind:"scalar",opt:!0,T:8}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.sdp="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.sdp=e.string();break;case 3:s.playerId=e.string();break;case 4:s.sfu=e.bool();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.sdp&&t.tag(2,a.LengthDelimited).string(e.sdp),void 0!==e.playerId&&t.tag(3,a.LengthDelimited).string(e.playerId),void 0!==e.sfu&&t.tag(4,a.Varint).bool(e.sfu);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},fe=new class extends ne{constructor(){super("peerDataChannelsReady",[{no:1,name:"type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();if(1===t)s.type=e.string();else{let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ve=new class extends ne{constructor(){super("ping",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"time",kind:"scalar",T:5}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.time=0,void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.time=e.int32();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),0!==e.time&&t.tag(2,a.Varint).int32(e.time);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ye=new class extends ne{constructor(){super("playerConnected",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"dataChannel",kind:"scalar",T:8},{no:3,name:"sfu",kind:"scalar",T:8},{no:4,name:"sendOffer",kind:"scalar",T:8},{no:5,name:"playerId",kind:"scalar",opt:!0,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.dataChannel=!1,t.sfu=!1,t.sendOffer=!1,void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.dataChannel=e.bool();break;case 3:s.sfu=e.bool();break;case 4:s.sendOffer=e.bool();break;case 5:s.playerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),!1!==e.dataChannel&&t.tag(2,a.Varint).bool(e.dataChannel),!1!==e.sfu&&t.tag(3,a.Varint).bool(e.sfu),!1!==e.sendOffer&&t.tag(4,a.Varint).bool(e.sendOffer),void 0!==e.playerId&&t.tag(5,a.LengthDelimited).string(e.playerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Se=new class extends ne{constructor(){super("playerCount",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"count",kind:"scalar",T:5}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.count=0,void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.count=e.int32();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),0!==e.count&&t.tag(2,a.Varint).int32(e.count);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},we=new class extends ne{constructor(){super("playerDisconnected",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"playerId",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.playerId="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.playerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.playerId&&t.tag(2,a.LengthDelimited).string(e.playerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Ce=new class extends ne{constructor(){super("pong",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"time",kind:"scalar",T:5}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.time=0,void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.time=e.int32();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),0!==e.time&&t.tag(2,a.Varint).int32(e.time);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Te=new class extends ne{constructor(){super("stats",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"data",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.data="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.data=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.data&&t.tag(2,a.LengthDelimited).string(e.data);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},be=new class extends ne{constructor(){super("streamerDataChannels",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"sendStreamId",kind:"scalar",T:5},{no:3,name:"recvStreamId",kind:"scalar",T:5},{no:4,name:"playerId",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.sendStreamId=0,t.recvStreamId=0,t.playerId="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.sendStreamId=e.int32();break;case 3:s.recvStreamId=e.int32();break;case 4:s.playerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),0!==e.sendStreamId&&t.tag(2,a.Varint).int32(e.sendStreamId),0!==e.recvStreamId&&t.tag(3,a.Varint).int32(e.recvStreamId),""!==e.playerId&&t.tag(4,a.LengthDelimited).string(e.playerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Ee=new class extends ne{constructor(){super("streamerDisconnected",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"streamerId",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.streamerId="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.streamerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.streamerId&&t.tag(2,a.LengthDelimited).string(e.streamerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},ke=new class extends ne{constructor(){super("streamerList",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"ids",kind:"scalar",repeat:2,T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.ids=[],void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.ids.push(e.string());break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);for(let n=0;n<e.ids.length;n++)t.tag(2,a.LengthDelimited).string(e.ids[n]);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Me=new class extends ne{constructor(){super("subscribe",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"streamerId",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.streamerId="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.streamerId=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.streamerId&&t.tag(2,a.LengthDelimited).string(e.streamerId);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Re=new class extends ne{constructor(){super("unsubscribe",[{no:1,name:"type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();if(1===t)s.type=e.string();else{let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Pe=new class extends ne{constructor(){super("streamerIdChanged",[{no:1,name:"type",kind:"scalar",T:9},{no:2,name:"newID",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.type="",t.newID="",void 0!==e&&c(this,t,e),t}internalBinaryRead(e,t,n,r){let s=null!=r?r:this.create(),a=e.pos+t;for(;e.pos<a;){let[t,r]=e.tag();switch(t){case 1:s.type=e.string();break;case 2:s.newID=e.string();break;default:let a=n.readUnknownField;if("throw"===a)throw new globalThis.Error(`Unknown field ${t} (wire type ${r}) for ${this.typeName}`);let o=e.skip(r);!1!==a&&(!0===a?i.onRead:a)(this.typeName,s,t,r,o)}}return s}internalBinaryWrite(e,t,n){""!==e.type&&t.tag(1,a.LengthDelimited).string(e.type),""!==e.newID&&t.tag(2,a.LengthDelimited).string(e.newID);let r=n.writeUnknownFields;return!1!==r&&(1==r?i.onWrite:r)(this.typeName,e,t),t}},Le={answer:se,config:ae,dataChannelRequest:oe,disconnectPlayer:le,endpointId:ce,iceCandidate:he,identify:ue,layerPreference:ge,listStreamers:me,offer:pe,peerDataChannelsReady:fe,ping:ve,playerConnected:ye,playerCount:Se,playerDisconnected:we,pong:Ce,stats:Te,streamerDataChannels:be,streamerDisconnected:Ee,streamerList:ke,subscribe:Me,unsubscribe:Re};function Fe(e,t){const n=e.create();return n.type=e.typeName,t&&e.mergePartial(n,t),n}function Ie(e){let t=!0;if(!e.type)return n.Error(n.GetStackTrace(),`Parsed message has no type. Rejected. ${JSON.stringify(e)}`),null;const r=Le[e.type];if(!r)return n.Error(n.GetStackTrace(),`Message is of an unknown type: "${r}". Rejected.`),null;if(r.fields)for(let s of r.fields)s.opt||e.hasOwnProperty(s.name)||(n.Error(n.GetStackTrace(),`Message "${e.type}"" is missing required field "${s.name}". Rejected.`),t=!1);for(const s in e)r.fields.find((e=>e.name===s))||(n.Error(n.GetStackTrace(),`Message "${e.type}" contains unknown field "${s}". Rejected.`),t=!1);return t?r:null}class xe{constructor(e){this.transport=e,this.transportEvents=new o.EventEmitter,this.messageHandlers=new o.EventEmitter,e.events.addListener("open",(()=>this.transportEvents.emit("open"))),e.events.addListener("error",(()=>this.transportEvents.emit("error"))),e.events.addListener("close",(e=>this.transportEvents.emit("close",e))),e.onMessage=t=>{if(t.type==ve.typeName){const t=Fe(Ce,{time:(new Date).getTime()});e.sendMessage(t)}this.messageHandlers.emit(t.type,t)}}connect(e){return this.transport.connect(e)}disconnect(){this.transport.disconnect()}isConnected(){return this.transport.isConnected()}sendMessage(e){this.transport.sendMessage(e)}requestStreamerList(){const e=Fe(me);this.transport.sendMessage(e)}sendSubscribe(e){const t=Fe(Me,{streamerid:e});this.transport.sendMessage(t)}sendUnsubscribe(){const e=Fe(Re);this.transport.sendMessage(e)}sendWebRtcOffer(e){const t=Fe(pe,e);this.transport.sendMessage(t)}sendWebRtcAnswer(e){const t=Fe(se,e);this.transport.sendMessage(t)}sendWebRtcDatachannelRequest(){const e=Fe(oe);this.transport.sendMessage(e)}sendSFURecvDataChannelReady(){const e=Fe(fe);this.transport.sendMessage(e)}sendIceCandidate(e){const t=Fe(he,{candidate:e});this.transport.sendMessage(t)}}class Oe{constructor(e){this.videoElementProvider=e,this.audioElement=document.createElement("Audio"),this.videoElementProvider.setAudioElement(this.audioElement)}handleOnTrack(e){n.Log(n.GetStackTrace(),"handleOnTrack "+JSON.stringify(e.streams),6);const t=this.videoElementProvider.getVideoElement();if(e.track&&n.Log(n.GetStackTrace(),"Got track - "+e.track.kind+" id="+e.track.id+" readyState="+e.track.readyState,6),"audio"!=e.track.kind)return"video"==e.track.kind&&t.srcObject!==e.streams[0]?(t.srcObject=e.streams[0],void n.Log(n.GetStackTrace(),"Set video source from video track ontrack.")):void 0;this.CreateAudioTrack(e.streams[0])}CreateAudioTrack(e){const t=this.videoElementProvider.getVideoElement();t.srcObject!=e&&t.srcObject&&t.srcObject!==e&&(this.audioElement.srcObject=e,n.Log(n.GetStackTrace(),"Created new audio element to play separate audio stream."))}}class De{constructor(e){this.freezeFrameHeight=0,this.freezeFrameWidth=0,this.rootDiv=e,this.rootElement=document.createElement("div"),this.rootElement.id="freezeFrame",this.rootElement.style.display="none",this.rootElement.style.pointerEvents="none",this.rootElement.style.position="absolute",this.rootElement.style.zIndex="20",this.imageElement=document.createElement("img"),this.imageElement.style.position="absolute",this.rootElement.appendChild(this.imageElement),this.rootDiv.appendChild(this.rootElement)}setElementForShow(){this.rootElement.style.display="block"}setElementForHide(){this.rootElement.style.display="none"}updateImageElementSource(e){const t=btoa(e.reduce(((e,t)=>e+String.fromCharCode(t)),""));this.imageElement.src="data:image/jpeg;base64,"+t}setDimensionsFromElementAndResize(){this.freezeFrameHeight=this.imageElement.naturalHeight,this.freezeFrameWidth=this.imageElement.naturalWidth,this.resize()}resize(){if(0!==this.freezeFrameWidth&&0!==this.freezeFrameHeight){let e=0,t=0,n=0,r=0;const s=this.rootDiv.clientWidth/this.rootDiv.clientHeight,i=this.freezeFrameWidth/this.freezeFrameHeight;s<i?(e=this.rootDiv.clientWidth,t=Math.floor(this.rootDiv.clientWidth/i),n=Math.floor(.5*(this.rootDiv.clientHeight-t)),r=0):(e=Math.floor(this.rootDiv.clientHeight*i),t=this.rootDiv.clientHeight,n=0,r=Math.floor(.5*(this.rootDiv.clientWidth-e))),this.rootElement.style.width=this.rootDiv.offsetWidth+"px",this.rootElement.style.height=this.rootDiv.offsetHeight+"px",this.rootElement.style.left="0px",this.rootElement.style.top="0px",this.imageElement.style.width=e+"px",this.imageElement.style.height=t+"px",this.imageElement.style.left=r+"px",this.imageElement.style.top=n+"px"}}}class Ae{constructor(e){this.receiving=!1,this.size=0,this.jpeg=void 0,this.valid=!1,this.freezeFrameDelay=50,this.freezeFrame=new De(e)}showFreezeFrame(){this.valid&&this.freezeFrame.setElementForShow()}hideFreezeFrame(){this.valid=!1,this.freezeFrame.setElementForHide()}updateFreezeFrameAndShow(e,t){this.freezeFrame.updateImageElementSource(e),this.freezeFrame.imageElement.onload=()=>{this.freezeFrame.setDimensionsFromElementAndResize(),t()}}processFreezeFrameMessage(e,t){this.receiving||(this.receiving=!0,this.valid=!1,this.size=0,this.jpeg=void 0),this.size=new DataView(e.slice(1,5).buffer).getInt32(0,!0);const r=e.slice(5);if(this.jpeg){const e=new Uint8Array(this.jpeg.length+r.length);e.set(this.jpeg,0),e.set(r,this.jpeg.length),this.jpeg=e}else this.jpeg=r,this.receiving=!0,n.Log(n.GetStackTrace(),`received first chunk of freeze frame: ${this.jpeg.length}/${this.size}`,6);this.jpeg.length===this.size?(this.receiving=!1,this.valid=!0,n.Log(n.GetStackTrace(),`received complete freeze frame ${this.size}`,6),this.updateFreezeFrameAndShow(this.jpeg,t)):this.jpeg.length>this.size&&(n.Error(n.GetStackTrace(),`received bigger freeze frame than advertised: ${this.jpeg.length}/${this.size}`),this.jpeg=void 0,this.receiving=!1)}}class Ue{constructor(e,t,n,r,s=(()=>{})){this.onChange=s,this.onChangeEmit=()=>{},this.id=e,this.description=n,this.label=t,this.value=r}set label(e){this._label=e,this.onChangeEmit(this._value)}get label(){return this._label}get value(){return this._value}set value(e){this._value=e,this.onChange(this._value,this),this.onChangeEmit(this._value)}}class Ne extends Ue{constructor(e,t,n,r,s,i=(()=>{})){super(e,t,n,r,i);const a=new URLSearchParams(window.location.search);if(s&&a.has(this.id)){const e=this.getUrlParamFlag();this.flag=e}else this.flag=r;this.useUrlParams=s}getUrlParamFlag(){const e=new URLSearchParams(window.location.search);return!!e.has(this.id)&&"false"!==e.get(this.id)&&"False"!==e.get(this.id)}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);!0===this.flag?e.set(this.id,"true"):e.set(this.id,"false"),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}enable(){this.flag=!0}get flag(){return!!this.value}set flag(e){this.value=e}}class Be extends Ue{constructor(e,t,n,r,s,i,a,o=(()=>{})){super(e,t,n,i,o),this._min=r,this._max=s;const l=new URLSearchParams(window.location.search);if(a&&l.has(this.id)){const e=Number.parseFloat(l.get(this.id));this.number=Number.isNaN(e)?i:e}else this.number=i;this.useUrlParams=a}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);e.set(this.id,this.number.toString()),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}set number(e){this.value=this.clamp(e)}get number(){return this.value}clamp(e){return Math.max(Math.min(this._max,e),this._min)}get min(){return this._min}get max(){return this._max}addOnChangedListener(e){this.onChange=e}}class Ve extends Ue{constructor(e,t,n,r,s,i=(()=>{})){super(e,t,n,r,i);const a=new URLSearchParams(window.location.search);if(s&&a.has(this.id)){const e=this.getUrlParamText();this.text=e}else this.text=r;this.useUrlParams=s}getUrlParamText(){var e;const t=new URLSearchParams(window.location.search);return t.has(this.id)&&null!==(e=t.get(this.id))&&void 0!==e?e:""}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);e.set(this.id,this.text),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}get text(){return this.value}set text(e){this.value=e}}class Ge extends Ue{constructor(e,t,n,r,s,i,a=(()=>{})){super(e,t,n,[r],a),this.options=s;const o=new URLSearchParams(window.location.search),l=i&&o.has(this.id)?this.getUrlParamText():r;this.selected=l,this.useUrlParams=i}getUrlParamText(){var e;const t=new URLSearchParams(window.location.search);return t.has(this.id)&&null!==(e=t.get(this.id))&&void 0!==e?e:""}updateURLParams(){if(this.useUrlParams){const e=new URLSearchParams(window.location.search);e.set(this.id,this.selected),window.history.replaceState({},"",""!==e.toString()?`${location.pathname}?${e}`:`${location.pathname}`)}}addOnChangedListener(e){this.onChange=e}get options(){return this._options}set options(e){this._options=e,this.onChangeEmit(this.selected)}get selected(){return this.value}set selected(e){let t=this.options.filter((t=>-1!==t.indexOf(e)));t.length?this.value=t[0]:(t=this.options.filter((t=>-1!==t.indexOf(e.split(" ")[0]))),t.length&&(this.value=t[0]))}}class We extends Event{constructor(e){super("afkWarningActivate"),this.data=e}}class ze extends Event{constructor(e){super("afkWarningUpdate"),this.data=e}}class _e extends Event{constructor(){super("afkWarningDeactivate")}}class He extends Event{constructor(){super("afkTimedOut")}}class $e extends Event{constructor(e){super("videoEncoderAvgQP"),this.data=e}}class Ke extends Event{constructor(){super("webRtcSdp")}}class je extends Event{constructor(){super("webRtcAutoConnect")}}class Qe extends Event{constructor(){super("webRtcConnecting")}}class qe extends Event{constructor(){super("webRtcConnected")}}class Xe extends Event{constructor(){super("webRtcFailed")}}class Je extends Event{constructor(e){super("webRtcDisconnected"),this.data=e}}class Ye extends Event{constructor(e){super("dataChannelOpen"),this.data=e}}class Ze extends Event{constructor(e){super("dataChannelClose"),this.data=e}}class et extends Event{constructor(e){super("dataChannelError"),this.data=e}}class tt extends Event{constructor(){super("videoInitialized")}}class nt extends Event{constructor(){super("streamLoading")}}class rt extends Event{constructor(){super("streamConnect")}}class st extends Event{constructor(){super("streamDisconnect")}}class it extends Event{constructor(){super("streamReconnect")}}class at extends Event{constructor(e){super("playStreamError"),this.data=e}}class ot extends Event{constructor(){super("playStream")}}class lt extends Event{constructor(e){super("playStreamRejected"),this.data=e}}class ct extends Event{constructor(e){super("loadFreezeFrame"),this.data=e}}class dt extends Event{constructor(){super("hideFreezeFrame")}}class ht extends Event{constructor(e){super("statsReceived"),this.data=e}}class ut extends Event{constructor(e){super("streamerListMessage"),this.data=e}}class gt extends Event{constructor(e){super("StreamerIDChangedMessage"),this.data=e}}class mt extends Event{constructor(e){super("latencyTestResult"),this.data=e}}class pt extends Event{constructor(e){super("dataChannelLatencyTestResponse"),this.data=e}}class ft extends Event{constructor(e){super("dataChannelLatencyTestResult"),this.data=e}}class vt extends Event{constructor(e){super("initialSettings"),this.data=e}}class yt extends Event{constructor(e){super("settingsChanged"),this.data=e}}class St extends Event{constructor(){super("xrSessionStarted")}}class wt extends Event{constructor(){super("xrSessionEnded")}}class Ct extends Event{constructor(e){super("xrFrame"),this.data=e}}class Tt extends Event{constructor(e){super("playerCount"),this.data=e}}class bt extends EventTarget{dispatchEvent(e){return super.dispatchEvent(e)}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}}class Et{}Et.AutoConnect="AutoConnect",Et.AutoPlayVideo="AutoPlayVideo",Et.AFKDetection="TimeoutIfIdle",Et.BrowserSendOffer="OfferToReceive",Et.HoveringMouseMode="HoveringMouse",Et.ForceMonoAudio="ForceMonoAudio",Et.ForceTURN="ForceTURN",Et.FakeMouseWithTouches="FakeMouseWithTouches",Et.IsQualityController="ControlsQuality",Et.MatchViewportResolution="MatchViewportRes",Et.StartVideoMuted="StartVideoMuted",Et.SuppressBrowserKeys="SuppressBrowserKeys",Et.UseMic="UseMic",Et.KeyboardInput="KeyboardInput",Et.MouseInput="MouseInput",Et.TouchInput="TouchInput",Et.GamepadInput="GamepadInput",Et.XRControllerInput="XRControllerInput",Et.WaitForStreamer="WaitForStreamer";const kt=e=>Object.getOwnPropertyNames(Et).some((t=>Et[t]===e));class Mt{}Mt.AFKTimeoutSecs="AFKTimeout",Mt.MinQP="MinQP",Mt.MaxQP="MaxQP",Mt.WebRTCFPS="WebRTCFPS",Mt.WebRTCMinBitrate="WebRTCMinBitrate",Mt.WebRTCMaxBitrate="WebRTCMaxBitrate",Mt.MaxReconnectAttempts="MaxReconnectAttempts",Mt.StreamerAutoJoinInterval="StreamerAutoJoinInterval";const Rt=e=>Object.getOwnPropertyNames(Mt).some((t=>Mt[t]===e));class Pt{}Pt.SignallingServerUrl="ss";const Lt=e=>Object.getOwnPropertyNames(Pt).some((t=>Pt[t]===e));class Ft{}Ft.PreferredCodec="PreferredCodec",Ft.StreamerId="StreamerId";const It=e=>Object.getOwnPropertyNames(Ft).some((t=>Ft[t]===e));class xt{constructor(e={}){this.flags=new Map,this.numericParameters=new Map,this.textParameters=new Map,this.optionParameters=new Map;const{initialSettings:t,useUrlParams:n}=e;this._useUrlParams=!!n,this.populateDefaultSettings(this._useUrlParams,t)}get useUrlParams(){return this._useUrlParams}populateDefaultSettings(e,t){this.textParameters.set(Pt.SignallingServerUrl,new Ve(Pt.SignallingServerUrl,"Signalling url","Url of the signalling server",t&&t.hasOwnProperty(Pt.SignallingServerUrl)?t[Pt.SignallingServerUrl]:("https:"===location.protocol?"wss://":"ws://")+window.location.hostname+("80"===window.location.port||""===window.location.port?"":`:${window.location.port}`),e)),this.optionParameters.set(Ft.StreamerId,new Ge(Ft.StreamerId,"Streamer ID","The ID of the streamer to stream.",t&&t.hasOwnProperty(Ft.StreamerId)?t[Ft.StreamerId]:"",[],e)),this.optionParameters.set(Ft.PreferredCodec,new Ge(Ft.PreferredCodec,"Preferred Codec","The preferred codec to be used during codec negotiation","H264 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f",t&&t.hasOwnProperty(Ft.PreferredCodec)?[t[Ft.PreferredCodec]]:function(){const e=[];if(!RTCRtpReceiver.getCapabilities)return e.push("Only available on Chrome"),e;const t=/(VP\d|H26\d|AV1).*/;return RTCRtpReceiver.getCapabilities("video").codecs.forEach((n=>{const r=n.mimeType.split("/")[1]+" "+(n.sdpFmtpLine||"");null!==t.exec(r)&&e.push(r)})),e}(),e)),this.flags.set(Et.AutoConnect,new Ne(Et.AutoConnect,"Auto connect to stream","Whether we should attempt to auto connect to the signalling server or show a click to start prompt.",!(!t||!t.hasOwnProperty(Et.AutoConnect))&&t[Et.AutoConnect],e)),this.flags.set(Et.AutoPlayVideo,new Ne(Et.AutoPlayVideo,"Auto play video","When video is ready automatically start playing it as opposed to showing a play button.",!t||!t.hasOwnProperty(Et.AutoPlayVideo)||t[Et.AutoPlayVideo],e)),this.flags.set(Et.BrowserSendOffer,new Ne(Et.BrowserSendOffer,"Browser send offer","Browser will initiate the WebRTC handshake by sending the offer to the streamer",!(!t||!t.hasOwnProperty(Et.BrowserSendOffer))&&t[Et.BrowserSendOffer],e)),this.flags.set(Et.UseMic,new Ne(Et.UseMic,"Use microphone","Make browser request microphone access and open an input audio track.",!(!t||!t.hasOwnProperty(Et.UseMic))&&t[Et.UseMic],e)),this.flags.set(Et.StartVideoMuted,new Ne(Et.StartVideoMuted,"Start video muted","Video will start muted if true.",!(!t||!t.hasOwnProperty(Et.StartVideoMuted))&&t[Et.StartVideoMuted],e)),this.flags.set(Et.SuppressBrowserKeys,new Ne(Et.SuppressBrowserKeys,"Suppress browser keys","Suppress certain browser keys that we use in UE, for example F5 to show shader complexity instead of refresh the page.",!t||!t.hasOwnProperty(Et.SuppressBrowserKeys)||t[Et.SuppressBrowserKeys],e)),this.flags.set(Et.IsQualityController,new Ne(Et.IsQualityController,"Is quality controller?","True if this peer controls stream quality",!t||!t.hasOwnProperty(Et.IsQualityController)||t[Et.IsQualityController],e)),this.flags.set(Et.ForceMonoAudio,new Ne(Et.ForceMonoAudio,"Force mono audio","Force browser to request mono audio in the SDP",!(!t||!t.hasOwnProperty(Et.ForceMonoAudio))&&t[Et.ForceMonoAudio],e)),this.flags.set(Et.ForceTURN,new Ne(Et.ForceTURN,"Force TURN","Only generate TURN/Relayed ICE candidates.",!(!t||!t.hasOwnProperty(Et.ForceTURN))&&t[Et.ForceTURN],e)),this.flags.set(Et.AFKDetection,new Ne(Et.AFKDetection,"AFK if idle","Timeout the experience if user is AFK for a period.",!(!t||!t.hasOwnProperty(Et.AFKDetection))&&t[Et.AFKDetection],e)),this.flags.set(Et.MatchViewportResolution,new Ne(Et.MatchViewportResolution,"Match viewport resolution","Pixel Streaming will be instructed to dynamically resize the video stream to match the size of the video element.",!(!t||!t.hasOwnProperty(Et.MatchViewportResolution))&&t[Et.MatchViewportResolution],e)),this.flags.set(Et.HoveringMouseMode,new Ne(Et.HoveringMouseMode,"Control Scheme: Locked Mouse","Either locked mouse, where the pointer is consumed by the video and locked to it, or hovering mouse, where the mouse is not consumed.",!(!t||!t.hasOwnProperty(Et.HoveringMouseMode))&&t[Et.HoveringMouseMode],e,((e,t)=>{t.label=`Control Scheme: ${e?"Hovering":"Locked"} Mouse`}))),this.flags.set(Et.FakeMouseWithTouches,new Ne(Et.FakeMouseWithTouches,"Fake mouse with touches","A single finger touch is converted into a mouse event. This allows a non-touch application to be controlled partially via a touch device.",!t||!t.hasOwnProperty(Et.FakeMouseWithTouches)||t[Et.FakeMouseWithTouches],e)),this.flags.set(Et.KeyboardInput,new Ne(Et.KeyboardInput,"Keyboard input","If enabled, send keyboard events to streamer",!t||!t.hasOwnProperty(Et.KeyboardInput)||t[Et.KeyboardInput],e)),this.flags.set(Et.MouseInput,new Ne(Et.MouseInput,"Mouse input","If enabled, send mouse events to streamer",!t||!t.hasOwnProperty(Et.MouseInput)||t[Et.MouseInput],e)),this.flags.set(Et.TouchInput,new Ne(Et.TouchInput,"Touch input","If enabled, send touch events to streamer",!t||!t.hasOwnProperty(Et.TouchInput)||t[Et.TouchInput],e)),this.flags.set(Et.GamepadInput,new Ne(Et.GamepadInput,"Gamepad input","If enabled, send gamepad events to streamer",!t||!t.hasOwnProperty(Et.GamepadInput)||t[Et.GamepadInput],e)),this.flags.set(Et.XRControllerInput,new Ne(Et.XRControllerInput,"XR controller input","If enabled, send XR controller events to streamer",!t||!t.hasOwnProperty(Et.XRControllerInput)||t[Et.XRControllerInput],e)),this.flags.set(Et.WaitForStreamer,new Ne(Et.WaitForStreamer,"Wait for streamer","Will continue trying to connect to the first streamer available.",!t||!t.hasOwnProperty(Et.WaitForStreamer)||t[Et.WaitForStreamer],e)),this.numericParameters.set(Mt.AFKTimeoutSecs,new Be(Mt.AFKTimeoutSecs,"AFK timeout","The time (in seconds) it takes for the application to time out if AFK timeout is enabled.",0,600,t&&t.hasOwnProperty(Mt.AFKTimeoutSecs)?t[Mt.AFKTimeoutSecs]:120,e)),this.numericParameters.set(Mt.MaxReconnectAttempts,new Be(Mt.MaxReconnectAttempts,"Max Reconnects","Maximum number of reconnects the application will attempt when a streamer disconnects.",0,999,t&&t.hasOwnProperty(Mt.MaxReconnectAttempts)?t[Mt.MaxReconnectAttempts]:3,e)),this.numericParameters.set(Mt.MinQP,new Be(Mt.MinQP,"Min QP","The lower bound for the quantization parameter (QP) of the encoder. 0 = Best quality, 51 = worst quality.",0,51,t&&t.hasOwnProperty(Mt.MinQP)?t[Mt.MinQP]:0,e)),this.numericParameters.set(Mt.MaxQP,new Be(Mt.MaxQP,"Max QP","The upper bound for the quantization parameter (QP) of the encoder. 0 = Best quality, 51 = worst quality.",0,51,t&&t.hasOwnProperty(Mt.MaxQP)?t[Mt.MaxQP]:51,e)),this.numericParameters.set(Mt.WebRTCFPS,new Be(Mt.WebRTCFPS,"Max FPS","The maximum FPS that WebRTC will try to transmit frames at.",1,999,t&&t.hasOwnProperty(Mt.WebRTCFPS)?t[Mt.WebRTCFPS]:60,e)),this.numericParameters.set(Mt.WebRTCMinBitrate,new Be(Mt.WebRTCMinBitrate,"Min Bitrate (kbps)","The minimum bitrate that WebRTC should use.",0,5e5,t&&t.hasOwnProperty(Mt.WebRTCMinBitrate)?t[Mt.WebRTCMinBitrate]:0,e)),this.numericParameters.set(Mt.WebRTCMaxBitrate,new Be(Mt.WebRTCMaxBitrate,"Max Bitrate (kbps)","The maximum bitrate that WebRTC should use.",0,5e5,t&&t.hasOwnProperty(Mt.WebRTCMaxBitrate)?t[Mt.WebRTCMaxBitrate]:0,e)),this.numericParameters.set(Mt.StreamerAutoJoinInterval,new Be(Mt.StreamerAutoJoinInterval,"Streamer Auto Join Interval (ms)","Delay between retries when waiting for an available streamer.",500,9e5,t&&t.hasOwnProperty(Mt.StreamerAutoJoinInterval)?t[Mt.StreamerAutoJoinInterval]:3e3,e))}_addOnNumericSettingChangedListener(e,t){this.numericParameters.has(e)&&this.numericParameters.get(e).addOnChangedListener(t)}_addOnOptionSettingChangedListener(e,t){this.optionParameters.has(e)&&this.optionParameters.get(e).addOnChangedListener(t)}getNumericSettingValue(e){if(this.numericParameters.has(e))return this.numericParameters.get(e).number;throw new Error(`There is no numeric setting with the id of ${e}`)}getTextSettingValue(e){if(this.textParameters.has(e))return this.textParameters.get(e).value;throw new Error(`There is no numeric setting with the id of ${e}`)}setNumericSetting(e,t){if(!this.numericParameters.has(e))throw new Error(`There is no numeric setting with the id of ${e}`);this.numericParameters.get(e).number=t}_addOnSettingChangedListener(e,t){this.flags.has(e)&&(this.flags.get(e).onChange=t)}_addOnTextSettingChangedListener(e,t){this.textParameters.has(e)&&(this.textParameters.get(e).onChange=t)}getSettingOption(e){return this.optionParameters.get(e)}isFlagEnabled(e){return this.flags.get(e).flag}setFlagEnabled(e,t){this.flags.has(e)?this.flags.get(e).flag=t:n.Warning(n.GetStackTrace(),`Cannot toggle flag called ${e} - it does not exist in the Config.flags map.`)}setTextSetting(e,t){this.textParameters.has(e)?this.textParameters.get(e).text=t:n.Warning(n.GetStackTrace(),`Cannot set text setting called ${e} - it does not exist in the Config.textParameters map.`)}setOptionSettingOptions(e,t){this.optionParameters.has(e)?this.optionParameters.get(e).options=t:n.Warning(n.GetStackTrace(),`Cannot set text setting called ${e} - it does not exist in the Config.optionParameters map.`)}setOptionSettingValue(e,t){if(this.optionParameters.has(e)){const n=this.optionParameters.get(e),r=n.options;r.includes(t)||(r.push(t),n.options=r),n.selected=t}else n.Warning(n.GetStackTrace(),`Cannot set text setting called ${e} - it does not exist in the Config.enumParameters map.`)}setFlagLabel(e,t){this.flags.has(e)?this.flags.get(e).label=t:n.Warning(n.GetStackTrace(),`Cannot set label for flag called ${e} - it does not exist in the Config.flags map.`)}setSettings(e){for(const t of Object.keys(e))kt(t)?this.setFlagEnabled(t,e[t]):Rt(t)?this.setNumericSetting(t,e[t]):Lt(t)?this.setTextSetting(t,e[t]):It(t)&&this.setOptionSettingValue(t,e[t])}getSettings(){const e={};for(const[t,n]of this.flags.entries())e[t]=n.flag;for(const[t,n]of this.numericParameters.entries())e[t]=n.number;for(const[t,n]of this.textParameters.entries())e[t]=n.text;for(const[t,n]of this.optionParameters.entries())e[t]=n.selected;return e}getFlags(){return Array.from(this.flags.values())}getTextSettings(){return Array.from(this.textParameters.values())}getNumericSettings(){return Array.from(this.numericParameters.values())}getOptionSettings(){return Array.from(this.optionParameters.values())}_registerOnChangeEvents(e){for(const t of this.flags.keys()){const n=this.flags.get(t);n&&(n.onChangeEmit=t=>e.dispatchEvent(new yt({id:n.id,type:"flag",value:t,target:n})))}for(const t of this.numericParameters.keys()){const n=this.numericParameters.get(t);n&&(n.onChangeEmit=t=>e.dispatchEvent(new yt({id:n.id,type:"number",value:t,target:n})))}for(const t of this.textParameters.keys()){const n=this.textParameters.get(t);n&&(n.onChangeEmit=t=>e.dispatchEvent(new yt({id:n.id,type:"text",value:t,target:n})))}for(const t of this.optionParameters.keys()){const n=this.optionParameters.get(t);n&&(n.onChangeEmit=t=>e.dispatchEvent(new yt({id:n.id,type:"option",value:t,target:n})))}}}var Ot;!function(e){e[e.LockedMouse=0]="LockedMouse",e[e.HoveringMouse=1]="HoveringMouse"}(Ot||(Ot={}));class Dt{constructor(e,t,n){this.closeTimeout=10,this.active=!1,this.countdownActive=!1,this.warnTimer=void 0,this.countDown=0,this.countDownTimer=void 0,this.config=e,this.pixelStreaming=t,this.onDismissAfk=n,this.onAFKTimedOutCallback=()=>{console.log("AFK timed out, did you want to override this callback?")}}onAfkClick(){clearInterval(this.countDownTimer),(this.active||this.countdownActive)&&(this.startAfkWarningTimer(),this.pixelStreaming.dispatchEvent(new _e))}startAfkWarningTimer(){this.config.getNumericSettingValue(Mt.AFKTimeoutSecs)>0&&this.config.isFlagEnabled(Et.AFKDetection)?this.active=!0:this.active=!1,this.resetAfkWarningTimer()}stopAfkWarningTimer(){this.active=!1,this.countdownActive=!1,clearTimeout(this.warnTimer),clearInterval(this.countDownTimer)}pauseAfkWarningTimer(){this.active=!1}resetAfkWarningTimer(){this.active&&this.config.isFlagEnabled(Et.AFKDetection)&&(clearTimeout(this.warnTimer),this.warnTimer=setTimeout((()=>this.activateAfkEvent()),1e3*this.config.getNumericSettingValue(Mt.AFKTimeoutSecs)))}activateAfkEvent(){this.pauseAfkWarningTimer(),this.pixelStreaming.dispatchEvent(new We({countDown:this.countDown,dismissAfk:this.onDismissAfk})),this.countDown=this.closeTimeout,this.countdownActive=!0,this.pixelStreaming.dispatchEvent(new ze({countDown:this.countDown})),this.config.isFlagEnabled(Et.HoveringMouseMode)||document.exitPointerLock&&document.exitPointerLock(),this.countDownTimer=setInterval((()=>{this.countDown--,0==this.countDown?(this.pixelStreaming.dispatchEvent(new He),this.onAFKTimedOutCallback(),n.Log(n.GetStackTrace(),"You have been disconnected due to inactivity"),this.stopAfkWarningTimer()):this.pixelStreaming.dispatchEvent(new ze({countDown:this.countDown}))}),1e3)}}class At{constructor(){this.isReceivingFreezeFrame=!1}getDataChannelInstance(){return this}createDataChannel(e,t,n){this.peerConnection=e,this.label=t,this.datachannelOptions=n,null==n&&(this.datachannelOptions={},this.datachannelOptions.ordered=!0),this.dataChannel=this.peerConnection.createDataChannel(this.label,this.datachannelOptions),this.setupDataChannel()}setupDataChannel(){this.dataChannel.binaryType="arraybuffer",this.dataChannel.onopen=e=>this.handleOnOpen(e),this.dataChannel.onclose=e=>this.handleOnClose(e),this.dataChannel.onmessage=e=>this.handleOnMessage(e),this.dataChannel.onerror=e=>this.handleOnError(e)}handleOnOpen(e){var t;n.Log(n.GetStackTrace(),`Data Channel (${this.label}) opened.`,7),this.onOpen(null===(t=this.dataChannel)||void 0===t?void 0:t.label,e)}handleOnClose(e){var t;n.Log(n.GetStackTrace(),`Data Channel (${this.label}) closed.`,7),this.onClose(null===(t=this.dataChannel)||void 0===t?void 0:t.label,e)}handleOnMessage(e){n.Log(n.GetStackTrace(),`Data Channel (${this.label}) message: ${e}`,8)}handleOnError(e){var t;n.Log(n.GetStackTrace(),`Data Channel (${this.label}) error: ${e}`,7),this.onError(null===(t=this.dataChannel)||void 0===t?void 0:t.label,e)}onOpen(e,t){}onClose(e,t){}onError(e,t){}}class Ut{}class Nt{}class Bt{}class Vt{}class Gt{}class Wt{}class zt{}class _t{}class Ht{constructor(){this.inboundVideoStats=new Nt,this.inboundAudioStats=new Ut,this.candidatePair=new Gt,this.DataChannelStats=new Bt,this.outBoundVideoStats=new Wt,this.sessionStats=new zt,this.streamStats=new _t,this.codecs=new Map}processStats(e){this.localCandidates=new Array,this.remoteCandidates=new Array,e.forEach((e=>{switch(e.type){case"candidate-pair":this.handleCandidatePair(e);break;case"certificate":case"media-source":case"media-playout":case"outbound-rtp":case"peer-connection":case"remote-inbound-rtp":case"transport":break;case"codec":this.handleCodec(e);break;case"data-channel":this.handleDataChannel(e);break;case"inbound-rtp":this.handleInBoundRTP(e);break;case"local-candidate":this.handleLocalCandidate(e);break;case"remote-candidate":this.handleRemoteCandidate(e);break;case"remote-outbound-rtp":this.handleRemoteOutBound(e);break;case"track":this.handleTrack(e);break;case"stream":this.handleStream(e);break;default:n.Error(n.GetStackTrace(),"unhandled Stat Type"),n.Log(n.GetStackTrace(),e)}}))}handleStream(e){this.streamStats=e}handleCandidatePair(e){this.candidatePair.bytesReceived=e.bytesReceived,this.candidatePair.bytesSent=e.bytesSent,this.candidatePair.localCandidateId=e.localCandidateId,this.candidatePair.remoteCandidateId=e.remoteCandidateId,this.candidatePair.nominated=e.nominated,this.candidatePair.readable=e.readable,this.candidatePair.selected=e.selected,this.candidatePair.writable=e.writable,this.candidatePair.state=e.state,this.candidatePair.currentRoundTripTime=e.currentRoundTripTime}handleDataChannel(e){this.DataChannelStats.bytesReceived=e.bytesReceived,this.DataChannelStats.bytesSent=e.bytesSent,this.DataChannelStats.dataChannelIdentifier=e.dataChannelIdentifier,this.DataChannelStats.id=e.id,this.DataChannelStats.label=e.label,this.DataChannelStats.messagesReceived=e.messagesReceived,this.DataChannelStats.messagesSent=e.messagesSent,this.DataChannelStats.protocol=e.protocol,this.DataChannelStats.state=e.state,this.DataChannelStats.timestamp=e.timestamp}handleLocalCandidate(e){const t=new Vt;t.label="local-candidate",t.address=e.address,t.port=e.port,t.protocol=e.protocol,t.candidateType=e.candidateType,t.id=e.id,this.localCandidates.push(t)}handleRemoteCandidate(e){const t=new Vt;t.label="local-candidate",t.address=e.address,t.port=e.port,t.protocol=e.protocol,t.id=e.id,t.candidateType=e.candidateType,this.remoteCandidates.push(t)}handleInBoundRTP(e){switch(e.kind){case"video":this.inboundVideoStats=e,null!=this.lastVideoStats&&(this.inboundVideoStats.bitrate=8*(this.inboundVideoStats.bytesReceived-this.lastVideoStats.bytesReceived)/(this.inboundVideoStats.timestamp-this.lastVideoStats.timestamp),this.inboundVideoStats.bitrate=Math.floor(this.inboundVideoStats.bitrate)),this.lastVideoStats=Object.assign({},this.inboundVideoStats);break;case"audio":this.inboundAudioStats=e,null!=this.lastAudioStats&&(this.inboundAudioStats.bitrate=8*(this.inboundAudioStats.bytesReceived-this.lastAudioStats.bytesReceived)/(this.inboundAudioStats.timestamp-this.lastAudioStats.timestamp),this.inboundAudioStats.bitrate=Math.floor(this.inboundAudioStats.bitrate)),this.lastAudioStats=Object.assign({},this.inboundAudioStats);break;default:n.Log(n.GetStackTrace(),"Kind is not handled")}}handleRemoteOutBound(e){"video"===e.kind&&(this.outBoundVideoStats.bytesSent=e.bytesSent,this.outBoundVideoStats.id=e.id,this.outBoundVideoStats.localId=e.localId,this.outBoundVideoStats.packetsSent=e.packetsSent,this.outBoundVideoStats.remoteTimestamp=e.remoteTimestamp,this.outBoundVideoStats.timestamp=e.timestamp)}handleTrack(e){"track"!==e.type||"video_label"!==e.trackIdentifier&&"video"!==e.kind||(this.inboundVideoStats.framesDropped=e.framesDropped,this.inboundVideoStats.framesReceived=e.framesReceived,this.inboundVideoStats.frameHeight=e.frameHeight,this.inboundVideoStats.frameWidth=e.frameWidth)}handleCodec(e){const t=e.id,n=`${e.mimeType.replace("video/","").replace("audio/","")}${e.sdpFmtpLine?` ${e.sdpFmtpLine}`:""}`;this.codecs.set(t,n)}handleSessionStatistics(e,t,n){const r=Date.now()-e;this.sessionStats.runTime=new Date(r).toISOString().substr(11,8).toString();const s=null===t?"Not sent yet":t?"true":"false";this.sessionStats.controlsStreamInput=s,this.sessionStats.videoEncoderAvgQP=n}isNumber(e){return"number"==typeof e&&isFinite(e)}}var $t=r(366);class Kt{static isVideoTransciever(e){return this.canTransceiverReceiveVideo(e)||this.canTransceiverSendVideo(e)}static canTransceiverReceiveVideo(e){return!!e&&("sendrecv"===e.direction||"recvonly"===e.direction)&&e.receiver&&e.receiver.track&&"video"===e.receiver.track.kind}static canTransceiverSendVideo(e){return!!e&&("sendrecv"===e.direction||"sendonly"===e.direction)&&e.sender&&e.sender.track&&"video"===e.sender.track.kind}static isAudioTransciever(e){return this.canTransceiverReceiveAudio(e)||this.canTransceiverSendAudio(e)}static canTransceiverReceiveAudio(e){return!!e&&("sendrecv"===e.direction||"recvonly"===e.direction)&&e.receiver&&e.receiver.track&&"audio"===e.receiver.track.kind}static canTransceiverSendAudio(e){return!!e&&("sendrecv"===e.direction||"sendonly"===e.direction)&&e.sender&&e.sender.track&&"audio"===e.sender.track.kind}}var jt,Qt,qt=function(e,t,n,r){return new(n||(n=Promise))((function(s,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function o(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,o)}l((r=r.apply(e,t||[])).next())}))};class Xt{constructor(e,t,n){this.config=t,this.createPeerConnection(e,n)}createPeerConnection(e,t){this.config.isFlagEnabled(Et.ForceTURN)&&(e.iceTransportPolicy="relay",n.Log(n.GetStackTrace(),"Forcing TURN usage by setting ICE Transport Policy in peer connection config.")),this.peerConnection=new RTCPeerConnection(e),this.peerConnection.onsignalingstatechange=e=>this.handleSignalStateChange(e),this.peerConnection.oniceconnectionstatechange=e=>this.handleIceConnectionStateChange(e),this.peerConnection.onicegatheringstatechange=e=>this.handleIceGatheringStateChange(e),this.peerConnection.ontrack=e=>this.handleOnTrack(e),this.peerConnection.onicecandidate=e=>this.handleIceCandidate(e),this.peerConnection.ondatachannel=e=>this.handleDataChannel(e),this.aggregatedStats=new Ht,this.preferredCodec=t,this.updateCodecSelection=!0}createOffer(e,t){return qt(this,void 0,void 0,(function*(){n.Log(n.GetStackTrace(),"Create Offer",6);const r="localhost"===location.hostname||"127.0.0.1"===location.hostname,s="https:"===location.protocol;let i=t.isFlagEnabled(Et.UseMic);!i||r||s||(i=!1,n.Error(n.GetStackTrace(),"Microphone access in the browser will not work if you are not on HTTPS or localhost. Disabling mic access."),n.Error(n.GetStackTrace(),"For testing you can enable HTTP microphone access Chrome by visiting chrome://flags/ and enabling 'unsafely-treat-insecure-origin-as-secure'")),this.setupTransceiversAsync(i).finally((()=>{var t;null===(t=this.peerConnection)||void 0===t||t.createOffer(e).then((e=>{var t;this.showTextOverlayConnecting(),e.sdp=this.mungeSDP(e.sdp,i),null===(t=this.peerConnection)||void 0===t||t.setLocalDescription(e),this.onSendWebRTCOffer(e)})).catch((()=>{this.showTextOverlaySetupFailure()}))}))}))}receiveOffer(e,t){var r;return qt(this,void 0,void 0,(function*(){n.Log(n.GetStackTrace(),"Receive Offer",6),null===(r=this.peerConnection)||void 0===r||r.setRemoteDescription(e).then((()=>{const e="localhost"===location.hostname||"127.0.0.1"===location.hostname,r="https:"===location.protocol;let s=t.isFlagEnabled(Et.UseMic);!s||e||r||(s=!1,n.Error(n.GetStackTrace(),"Microphone access in the browser will not work if you are not on HTTPS or localhost. Disabling mic access."),n.Error(n.GetStackTrace(),"For testing you can enable HTTP microphone access Chrome by visiting chrome://flags/ and enabling 'unsafely-treat-insecure-origin-as-secure'")),this.setupTransceiversAsync(s).finally((()=>{var e;null===(e=this.peerConnection)||void 0===e||e.createAnswer().then((e=>{var t;return e.sdp=this.mungeSDP(e.sdp,s),null===(t=this.peerConnection)||void 0===t?void 0:t.setLocalDescription(e)})).then((()=>{var e;this.onSendWebRTCAnswer(null===(e=this.peerConnection)||void 0===e?void 0:e.currentLocalDescription)})).catch((()=>{n.Error(n.GetStackTrace(),"createAnswer() failed")}))}))})),this.config.setOptionSettingOptions(Ft.PreferredCodec,this.parseAvailableCodecs(e).filter((e=>this.config.getSettingOption(Ft.PreferredCodec).options.includes(e))))}))}receiveAnswer(e){var t;null===(t=this.peerConnection)||void 0===t||t.setRemoteDescription(e),this.config.setOptionSettingOptions(Ft.PreferredCodec,this.parseAvailableCodecs(e).filter((e=>this.config.getSettingOption(Ft.PreferredCodec).options.includes(e))))}generateStats(){var e;null===(e=this.peerConnection)||void 0===e||e.getStats(null).then((e=>{this.aggregatedStats.processStats(e),this.onVideoStats(this.aggregatedStats),this.updateCodecSelection&&this.aggregatedStats.inboundVideoStats.codecId&&this.config.setOptionSettingValue(Ft.PreferredCodec,this.aggregatedStats.codecs.get(this.aggregatedStats.inboundVideoStats.codecId))}))}close(){this.peerConnection&&(this.peerConnection.close(),this.peerConnection=null)}mungeSDP(e,t){let n=e.replace(/(a=fmtp:\d+ .*level-asymmetry-allowed=.*)\r\n/gm,"$1;x-google-start-bitrate=10000;x-google-max-bitrate=100000\r\n"),r="maxaveragebitrate=510000;";return t&&(r+="sprop-maxcapturerate=48000;"),r+=this.config.isFlagEnabled(Et.ForceMonoAudio)?"stereo=0;":"stereo=1;",r+="useinbandfec=1",n=n.replace("useinbandfec=1",r),n}handleOnIce(e){var t;n.Log(n.GetStackTrace(),"peerconnection handleOnIce",6),this.config.isFlagEnabled(Et.ForceTURN)&&e.candidate.indexOf("relay")<0?n.Info(n.GetStackTrace(),`Dropping candidate because it was not TURN relay. | Type= ${e.type} | Protocol= ${e.protocol} | Address=${e.address} | Port=${e.port} |`,6):null===(t=this.peerConnection)||void 0===t||t.addIceCandidate(e)}handleSignalStateChange(e){n.Log(n.GetStackTrace(),"signaling state change: "+e,6)}handleIceConnectionStateChange(e){n.Log(n.GetStackTrace(),"ice connection state change: "+e,6),this.onIceConnectionStateChange(e)}handleIceGatheringStateChange(e){n.Log(n.GetStackTrace(),"ice gathering state change: "+JSON.stringify(e),6)}handleOnTrack(e){this.onTrack(e)}handleIceCandidate(e){this.onPeerIceCandidate(e)}handleDataChannel(e){this.onDataChannel(e)}onTrack(e){}onIceConnectionStateChange(e){}onPeerIceCandidate(e){}onDataChannel(e){}setupTransceiversAsync(e){var t,n,r,s,i,a,o,l,c;return qt(this,void 0,void 0,(function*(){const d=(null===(t=this.peerConnection)||void 0===t?void 0:t.getTransceivers().length)>0;if(null===(n=this.peerConnection)||void 0===n||n.addTransceiver("video",{direction:"recvonly"}),RTCRtpReceiver.getCapabilities&&""!=this.preferredCodec)for(const e of null!==(s=null===(r=this.peerConnection)||void 0===r?void 0:r.getTransceivers())&&void 0!==s?s:[])if(e&&e.receiver&&e.receiver.track&&"video"===e.receiver.track.kind&&e.setCodecPreferences){const t=this.preferredCodec.split(" "),n=[{mimeType:"video/"+t[0],clockRate:9e4,sdpFmtpLine:t[1]?t[1]:""}];this.config.getSettingOption(Ft.PreferredCodec).options.filter((e=>e!=this.preferredCodec)).forEach((e=>{const t=e.split(" ");n.push({mimeType:"video/"+t[0],clockRate:9e4,sdpFmtpLine:t[1]?t[1]:""})}));for(const e of n)""===e.sdpFmtpLine&&delete e.sdpFmtpLine;e.setCodecPreferences(n)}if(e){const e={video:!1,audio:{autoGainControl:!1,channelCount:1,echoCancellation:!1,latency:0,noiseSuppression:!1,sampleRate:48e3,sampleSize:16,volume:1}},t=yield navigator.mediaDevices.getUserMedia(e);if(t)if(d){for(const e of null!==(o=null===(a=this.peerConnection)||void 0===a?void 0:a.getTransceivers())&&void 0!==o?o:[])if(Kt.canTransceiverReceiveAudio(e))for(const n of t.getTracks())n.kind&&"audio"==n.kind&&(e.sender.replaceTrack(n),e.direction="sendrecv")}else for(const e of t.getTracks())e.kind&&"audio"==e.kind&&(null===(l=this.peerConnection)||void 0===l||l.addTransceiver(e,{direction:"sendrecv"}));else null===(c=this.peerConnection)||void 0===c||c.addTransceiver("audio",{direction:"recvonly"})}else null===(i=this.peerConnection)||void 0===i||i.addTransceiver("audio",{direction:"recvonly"})}))}onVideoStats(e){}onSendWebRTCOffer(e){}onSendWebRTCAnswer(e){}showTextOverlayConnecting(){}showTextOverlaySetupFailure(){}parseAvailableCodecs(e){if(!RTCRtpReceiver.getCapabilities)return["Only available on Chrome"];const t=[],n=(0,$t.splitSections)(e.sdp);return n.shift(),n.forEach((e=>{const{codecs:n}=(0,$t.parseRtpParameters)(e),r=/(VP\d|H26\d|AV1).*/;n.forEach((e=>{const n=e.name+" "+Object.keys(e.parameters||{}).map((t=>t+"="+e.parameters[t])).join(";");if(null!==r.exec(n)){"VP9"==e.name&&(e.parameters={"profile-id":"0"});const n=e.name+" "+Object.keys(e.parameters||{}).map((t=>t+"="+e.parameters[t])).join(";");t.push(n)}}))})),t}}class Jt{constructor(){this.PixelStreamingSettings=new Yt,this.EncoderSettings=new Zt,this.WebRTCSettings=new en}ueCompatible(){null!=this.WebRTCSettings.MaxFPS&&(this.WebRTCSettings.FPS=this.WebRTCSettings.MaxFPS)}}class Yt{}class Zt{}class en{}class tn{constructor(){this.ReceiptTimeMs=null,this.TransmissionTimeMs=null,this.PreCaptureTimeMs=null,this.PostCaptureTimeMs=null,this.PreEncodeTimeMs=null,this.PostEncodeTimeMs=null,this.EncodeMs=null,this.CaptureToSendMs=null,this.testStartTimeMs=0,this.browserReceiptTimeMs=0,this.latencyExcludingDecode=0,this.testDuration=0,this.networkLatency=0,this.browserSendLatency=0,this.frameDisplayDeltaTimeMs=0,this.endToEndLatency=0,this.encodeLatency=0}setFrameDisplayDeltaTime(e){0==this.frameDisplayDeltaTimeMs&&(this.frameDisplayDeltaTimeMs=Math.round(e))}processFields(){null!=this.EncodeMs||null==this.PreEncodeTimeMs&&null==this.PostEncodeTimeMs||(n.Log(n.GetStackTrace(),`Setting Encode Ms \n ${this.PostEncodeTimeMs} \n ${this.PreEncodeTimeMs}`,6),this.EncodeMs=this.PostEncodeTimeMs-this.PreEncodeTimeMs),null!=this.CaptureToSendMs||null==this.PreCaptureTimeMs&&null==this.PostCaptureTimeMs||(n.Log(n.GetStackTrace(),`Setting CaptureToSendMs Ms \n ${this.PostCaptureTimeMs} \n ${this.PreCaptureTimeMs}`,6),this.CaptureToSendMs=this.PostCaptureTimeMs-this.PreCaptureTimeMs)}}class nn{static setExtensionFromBytes(e,t){t.receiving||(t.mimetype="",t.extension="",t.receiving=!0,t.valid=!1,t.size=0,t.data=[],t.timestampStart=(new Date).getTime(),n.Log(n.GetStackTrace(),"Received first chunk of file",6));const r=new TextDecoder("utf-16").decode(e.slice(1));n.Log(n.GetStackTrace(),r,6),t.extension=r}static setMimeTypeFromBytes(e,t){t.receiving||(t.mimetype="",t.extension="",t.receiving=!0,t.valid=!1,t.size=0,t.data=[],t.timestampStart=(new Date).getTime(),n.Log(n.GetStackTrace(),"Received first chunk of file",6));const r=new TextDecoder("utf-16").decode(e.slice(1));n.Log(n.GetStackTrace(),r,6),t.mimetype=r}static setContentsFromBytes(e,t){if(!t.receiving)return;t.size=Math.ceil(new DataView(e.slice(1,5).buffer).getInt32(0,!0)/16379);const r=e.slice(5);if(t.data.push(r),n.Log(n.GetStackTrace(),`Received file chunk: ${t.data.length}/${t.size}`,6),t.data.length===t.size){t.receiving=!1,t.valid=!0,n.Log(n.GetStackTrace(),"Received complete file",6);const e=(new Date).getTime()-t.timestampStart,r=Math.round(16*t.size*1024/e);n.Log(n.GetStackTrace(),`Average transfer bitrate: ${r}kb/s over ${e/1e3} seconds`,6);const s=new Blob(t.data,{type:t.mimetype}),i=document.createElement("a");i.setAttribute("href",URL.createObjectURL(s)),i.setAttribute("download",`transfer.${t.extension}`),document.body.append(i),i.remove()}else t.data.length>t.size&&(t.receiving=!1,n.Error(n.GetStackTrace(),`Received bigger file than advertised: ${t.data.length}/${t.size}`))}}class rn{constructor(){this.mimetype="",this.extension="",this.receiving=!1,this.size=0,this.data=[],this.valid=!1}}class sn{}sn.mainButton=0,sn.auxiliaryButton=1,sn.secondaryButton=2,sn.fourthButton=3,sn.fifthButton=4;class an{}an.primaryButton=1,an.secondaryButton=2,an.auxiliaryButton=4,an.fourthButton=8,an.fifthButton=16;class on{constructor(){this.unregisterCallbacks=[]}addUnregisterCallback(e){this.unregisterCallbacks.push(e)}unregisterAll(){for(const e of this.unregisterCallbacks)e();this.unregisterCallbacks=[]}}class ln{constructor(e,t,n){this.touchEventListenerTracker=new on,this.toStreamerMessagesProvider=e,this.videoElementProvider=t,this.coordinateConverter=n;const r=e=>this.onTouchStart(e),s=e=>this.onTouchEnd(e),i=e=>this.onTouchMove(e);document.addEventListener("touchstart",r,{passive:!1}),document.addEventListener("touchend",s,{passive:!1}),document.addEventListener("touchmove",i,{passive:!1}),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchstart",r))),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchend",s))),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchmove",i)))}unregisterTouchEvents(){this.touchEventListenerTracker.unregisterAll()}setVideoElementParentClientRect(e){this.videoElementParentClientRect=e}onTouchStart(e){if(this.videoElementProvider.isVideoReady()&&e.target===this.videoElementProvider.getVideoElement()){if(null==this.fakeTouchFinger){const t=e.changedTouches[0];this.fakeTouchFinger=new cn(t.identifier,t.clientX-this.videoElementParentClientRect.left,t.clientY-this.videoElementParentClientRect.top);const n=this.videoElementProvider.getVideoParentElement(),r=new MouseEvent("mouseenter",t);n.dispatchEvent(r);const s=this.coordinateConverter.normalizeAndQuantizeUnsigned(this.fakeTouchFinger.x,this.fakeTouchFinger.y);this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([sn.mainButton,s.x,s.y])}e.preventDefault()}}onTouchEnd(e){if(!this.videoElementProvider.isVideoReady()||null==this.fakeTouchFinger)return;const t=this.videoElementProvider.getVideoParentElement(),n=this.toStreamerMessagesProvider.toStreamerHandlers;for(let r=0;r<e.changedTouches.length;r++){const s=e.changedTouches[r];if(s.identifier===this.fakeTouchFinger.id){const e=s.clientX-this.videoElementParentClientRect.left,r=s.clientY-this.videoElementParentClientRect.top,i=this.coordinateConverter.normalizeAndQuantizeUnsigned(e,r);n.get("MouseUp")([sn.mainButton,i.x,i.y]);const a=new MouseEvent("mouseleave",s);t.dispatchEvent(a),this.fakeTouchFinger=null;break}}e.preventDefault()}onTouchMove(e){if(!this.videoElementProvider.isVideoReady()||null==this.fakeTouchFinger)return;const t=this.toStreamerMessagesProvider.toStreamerHandlers;for(let n=0;n<e.touches.length;n++){const r=e.touches[n];if(r.identifier===this.fakeTouchFinger.id){const e=r.clientX-this.videoElementParentClientRect.left,n=r.clientY-this.videoElementParentClientRect.top,s=this.coordinateConverter.normalizeAndQuantizeUnsigned(e,n),i=this.coordinateConverter.normalizeAndQuantizeSigned(e-this.fakeTouchFinger.x,n-this.fakeTouchFinger.y);t.get("MouseMove")([s.x,s.y,i.x,i.y]),this.fakeTouchFinger.x=e,this.fakeTouchFinger.y=n;break}}e.preventDefault()}}class cn{constructor(e,t,n){this.id=e,this.x=t,this.y=n}}class dn{}dn.backSpace=8,dn.shift=16,dn.control=17,dn.alt=18,dn.rightShift=253,dn.rightControl=254,dn.rightAlt=255;class hn{constructor(e,t,n){this.keyboardEventListenerTracker=new on,this.CodeToKeyCode={Escape:27,Digit0:48,Digit1:49,Digit2:50,Digit3:51,Digit4:52,Digit5:53,Digit6:54,Digit7:55,Digit8:56,Digit9:57,Minus:173,Equal:187,Backspace:8,Tab:9,KeyQ:81,KeyW:87,KeyE:69,KeyR:82,KeyT:84,KeyY:89,KeyU:85,KeyI:73,KeyO:79,KeyP:80,BracketLeft:219,BracketRight:221,Enter:13,ControlLeft:17,KeyA:65,KeyS:83,KeyD:68,KeyF:70,KeyG:71,KeyH:72,KeyJ:74,KeyK:75,KeyL:76,Semicolon:186,Quote:222,Backquote:192,ShiftLeft:16,Backslash:220,KeyZ:90,KeyX:88,KeyC:67,KeyV:86,KeyB:66,KeyN:78,KeyM:77,Comma:188,Period:190,Slash:191,ShiftRight:253,AltLeft:18,Space:32,CapsLock:20,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,Pause:19,ScrollLock:145,NumpadDivide:111,NumpadMultiply:106,NumpadSubtract:109,NumpadAdd:107,NumpadDecimal:110,Numpad9:105,Numpad8:104,Numpad7:103,Numpad6:102,Numpad5:101,Numpad4:100,Numpad3:99,Numpad2:98,Numpad1:97,Numpad0:96,NumLock:144,ControlRight:254,AltRight:255,Home:36,End:35,ArrowUp:38,ArrowLeft:37,ArrowRight:39,ArrowDown:40,PageUp:33,PageDown:34,Insert:45,Delete:46,ContextMenu:93},this.toStreamerMessagesProvider=e,this.config=t,this.activeKeysProvider=n}registerKeyBoardEvents(){const e=e=>this.handleOnCompositionEnd(e),t=e=>this.handleOnKeyDown(e),n=e=>this.handleOnKeyUp(e),r=e=>this.handleOnKeyPress(e);document.addEventListener("compositionend",e),document.addEventListener("keydown",t),document.addEventListener("keyup",n),document.addEventListener("keypress",r),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("compositionend",e))),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("keydown",t))),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("keyup",n))),this.keyboardEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("keypress",r)))}unregisterKeyBoardEvents(){this.keyboardEventListenerTracker.unregisterAll()}handleOnKeyDown(e){const t=this.getKeycode(e);t&&229!==t&&(n.Log(n.GetStackTrace(),`key down ${t}, repeat = ${e.repeat}`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("KeyDown")([this.getKeycode(e),e.repeat?1:0]),this.activeKeysProvider.getActiveKeys().push(t),t===dn.backSpace&&document.dispatchEvent(new KeyboardEvent("keypress",{charCode:dn.backSpace})),this.config.isFlagEnabled(Et.SuppressBrowserKeys)&&this.isKeyCodeBrowserKey(t)&&e.preventDefault())}handleOnKeyUp(e){const t=this.getKeycode(e);t&&(n.Log(n.GetStackTrace(),`key up ${t}`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("KeyUp")([t]),this.config.isFlagEnabled(Et.SuppressBrowserKeys)&&this.isKeyCodeBrowserKey(t)&&e.preventDefault())}handleOnKeyPress(e){if(!("charCode"in e))return void n.Warning(n.GetStackTrace(),"KeyboardEvent.charCode is deprecated in this browser, cannot send key press.");const t=e.charCode;n.Log(n.GetStackTrace(),`key press ${t}`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("KeyPress")([t])}handleOnCompositionEnd(e){e.data&&e.data.length&&e.data.split("").forEach((e=>{this.handleOnKeyDown(new KeyboardEvent("keydown",{keyCode:e.toUpperCase().charCodeAt(0),charCode:e.charCodeAt(0)})),this.handleOnKeyPress(new KeyboardEvent("keypress",{keyCode:e.toUpperCase().charCodeAt(0),charCode:e.charCodeAt(0)})),this.handleOnKeyUp(new KeyboardEvent("keyup",{keyCode:e.toUpperCase().charCodeAt(0),charCode:e.charCodeAt(0)}))}))}getKeycode(e){if(!("keyCode"in e)){const t=e;return t.code in this.CodeToKeyCode?this.CodeToKeyCode[t.code]:(n.Warning(n.GetStackTrace(),`Keyboard code of ${t.code} is not supported in our mapping, ignoring this key.`),null)}return e.keyCode===dn.shift&&"ShiftRight"===e.code?dn.rightShift:e.keyCode===dn.control&&"ControlRight"===e.code?dn.rightControl:e.keyCode===dn.alt&&"AltRight"===e.code?dn.rightAlt:e.keyCode}isKeyCodeBrowserKey(e){return e>=112&&e<=123||9===e}}class un{constructor(e,t,n){this.x=0,this.y=0,this.updateMouseMovePositionEvent=e=>{this.updateMouseMovePosition(e)},this.mouseEventListenerTracker=new on,this.videoElementProvider=e,this.mouseController=t,this.activeKeysProvider=n;const r=this.videoElementProvider.getVideoParentElement();this.x=r.getBoundingClientRect().width/2,this.y=r.getBoundingClientRect().height/2,this.coord=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(this.x,this.y)}unregisterMouseEvents(){this.mouseEventListenerTracker.unregisterAll()}lockStateChange(){const e=this.videoElementProvider.getVideoParentElement(),t=this.mouseController.toStreamerMessagesProvider.toStreamerHandlers;if(document.pointerLockElement===e||document.mozPointerLockElement===e)n.Log(n.GetStackTrace(),"Pointer locked",6),document.addEventListener("mousemove",this.updateMouseMovePositionEvent,!1),this.mouseEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("mousemove",this.updateMouseMovePositionEvent,!1)));else{n.Log(n.GetStackTrace(),"The pointer lock status is now unlocked",6),document.removeEventListener("mousemove",this.updateMouseMovePositionEvent,!1);let e=this.activeKeysProvider.getActiveKeys();const r=new Set(e),s=[];r.forEach((e=>{s[e]})),s.forEach((e=>{t.get("KeyUp")([e])})),e=[]}}updateMouseMovePosition(e){if(!this.videoElementProvider.isVideoReady())return;const t=this.mouseController.toStreamerMessagesProvider.toStreamerHandlers,n=this.videoElementProvider.getVideoParentElement().clientWidth,r=this.videoElementProvider.getVideoParentElement().clientHeight;this.x+=e.movementX,this.y+=e.movementY,this.x>n&&(this.x-=n),this.y>r&&(this.y-=r),this.x<0&&(this.x=n+this.x),this.y<0&&(this.y=r-this.y),this.coord=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(this.x,this.y);const s=this.mouseController.coordinateConverter.normalizeAndQuantizeSigned(e.movementX,e.movementY);t.get("MouseMove")([this.coord.x,this.coord.y,s.x,s.y])}handleMouseDown(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([e.button,this.coord.x,this.coord.y])}handleMouseUp(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseUp")([e.button,this.coord.x,this.coord.y])}handleMouseWheel(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseWheel")([e.wheelDelta,this.coord.x,this.coord.y])}handleMouseDouble(e){this.videoElementProvider.isVideoReady()&&this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDouble")([e.button,this.coord.x,this.coord.y])}handlePressMouseButtons(e){this.videoElementProvider.isVideoReady()&&this.mouseController.pressMouseButtons(e.buttons,this.x,this.y)}handleReleaseMouseButtons(e){this.videoElementProvider.isVideoReady()&&this.mouseController.releaseMouseButtons(e.buttons,this.x,this.y)}}class gn{constructor(e){this.mouseController=e}unregisterMouseEvents(){}updateMouseMovePosition(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;n.Log(n.GetStackTrace(),"MouseMove",6);const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY),r=this.mouseController.coordinateConverter.normalizeAndQuantizeSigned(e.movementX,e.movementY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseMove")([t.x,t.y,r.x,r.y]),e.preventDefault()}handleMouseDown(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;n.Log(n.GetStackTrace(),"onMouse Down",6);const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([e.button,t.x,t.y]),e.preventDefault()}handleMouseUp(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;n.Log(n.GetStackTrace(),"onMouse Up",6);const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseUp")([e.button,t.x,t.y]),e.preventDefault()}handleContextMenu(e){this.mouseController.videoElementProvider.isVideoReady()&&e.preventDefault()}handleMouseWheel(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseWheel")([e.wheelDelta,t.x,t.y]),e.preventDefault()}handleMouseDouble(e){if(!this.mouseController.videoElementProvider.isVideoReady())return;const t=this.mouseController.coordinateConverter.normalizeAndQuantizeUnsigned(e.offsetX,e.offsetY);this.mouseController.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDouble")([e.button,t.x,t.y])}handlePressMouseButtons(e){this.mouseController.videoElementProvider.isVideoReady()&&(n.Log(n.GetStackTrace(),"onMouse press",6),this.mouseController.pressMouseButtons(e.buttons,e.offsetX,e.offsetY))}handleReleaseMouseButtons(e){this.mouseController.videoElementProvider.isVideoReady()&&(n.Log(n.GetStackTrace(),"onMouse release",6),this.mouseController.releaseMouseButtons(e.buttons,e.offsetX,e.offsetY))}}class mn{constructor(e,t,n,r){this.mouseEventListenerTracker=new on,this.toStreamerMessagesProvider=e,this.coordinateConverter=n,this.videoElementProvider=t,this.activeKeysProvider=r,this.registerMouseEnterAndLeaveEvents()}unregisterMouseEvents(){this.mouseEventListenerTracker.unregisterAll()}registerLockedMouseEvents(e){const t=this.videoElementProvider.getVideoParentElement(),n=new un(this.videoElementProvider,e,this.activeKeysProvider);if(t.requestPointerLock=t.requestPointerLock||t.mozRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock,t.requestPointerLock){const e=()=>{t.requestPointerLock()};t.addEventListener("click",e),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("click",e)))}const r=()=>n.lockStateChange();document.addEventListener("pointerlockchange",r,!1),document.addEventListener("mozpointerlockchange",r,!1),this.mouseEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("pointerlockchange",r,!1))),this.mouseEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("mozpointerlockchange",r,!1)));const s=e=>n.handleMouseDown(e),i=e=>n.handleMouseUp(e),a=e=>n.handleMouseWheel(e),o=e=>n.handleMouseDouble(e);t.addEventListener("mousedown",s),t.addEventListener("mouseup",i),t.addEventListener("wheel",a),t.addEventListener("dblclick",o),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mousedown",s))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mouseup",i))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("wheel",a))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("dblclick",o))),this.mouseEventListenerTracker.addUnregisterCallback((()=>n.unregisterMouseEvents())),this.mouseEventListenerTracker.addUnregisterCallback((()=>{!document.exitPointerLock||document.pointerLockElement!==t&&document.mozPointerLockElement!==t||document.exitPointerLock()}))}registerHoveringMouseEvents(e){const t=this.videoElementProvider.getVideoParentElement(),n=new gn(e),r=e=>n.updateMouseMovePosition(e),s=e=>n.handleMouseDown(e),i=e=>n.handleMouseUp(e),a=e=>n.handleContextMenu(e),o=e=>n.handleMouseWheel(e),l=e=>n.handleMouseDouble(e);t.addEventListener("mousemove",r),t.addEventListener("mousedown",s),t.addEventListener("mouseup",i),t.addEventListener("contextmenu",a),t.addEventListener("wheel",o),t.addEventListener("dblclick",l),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mousemove",r))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mousedown",s))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("mouseup",i))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("contextmenu",a))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("wheel",o))),this.mouseEventListenerTracker.addUnregisterCallback((()=>t.removeEventListener("dblclick",l))),this.mouseEventListenerTracker.addUnregisterCallback((()=>n.unregisterMouseEvents()))}registerMouseEnterAndLeaveEvents(){const e=this.videoElementProvider.getVideoParentElement(),t=e=>{this.videoElementProvider.isVideoReady()&&(n.Log(n.GetStackTrace(),"Mouse Entered",6),this.sendMouseEnter(),this.pressMouseButtons(e.buttons,e.x,e.y))},r=e=>{this.videoElementProvider.isVideoReady()&&(n.Log(n.GetStackTrace(),"Mouse Left",6),this.sendMouseLeave(),this.releaseMouseButtons(e.buttons,e.x,e.y))};e.addEventListener("mouseenter",t),e.addEventListener("mouseleave",r),this.mouseEventListenerTracker.addUnregisterCallback((()=>e.removeEventListener("mouseenter",t))),this.mouseEventListenerTracker.addUnregisterCallback((()=>e.removeEventListener("mouseleave",r)))}releaseMouseButtons(e,t,n){const r=this.coordinateConverter.normalizeAndQuantizeUnsigned(t,n);e&an.primaryButton&&this.sendMouseUp(sn.mainButton,r.x,r.y),e&an.secondaryButton&&this.sendMouseUp(sn.secondaryButton,r.x,r.y),e&an.auxiliaryButton&&this.sendMouseUp(sn.auxiliaryButton,r.x,r.y),e&an.fourthButton&&this.sendMouseUp(sn.fourthButton,r.x,r.y),e&an.fifthButton&&this.sendMouseUp(sn.fifthButton,r.x,r.y)}pressMouseButtons(e,t,n){if(!this.videoElementProvider.isVideoReady())return;const r=this.coordinateConverter.normalizeAndQuantizeUnsigned(t,n);e&an.primaryButton&&this.sendMouseDown(sn.mainButton,r.x,r.y),e&an.secondaryButton&&this.sendMouseDown(sn.secondaryButton,r.x,r.y),e&an.auxiliaryButton&&this.sendMouseDown(sn.auxiliaryButton,r.x,r.y),e&an.fourthButton&&this.sendMouseDown(sn.fourthButton,r.x,r.y),e&an.fifthButton&&this.sendMouseDown(sn.fifthButton,r.x,r.y)}sendMouseEnter(){this.videoElementProvider.isVideoReady()&&this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseEnter")()}sendMouseLeave(){this.videoElementProvider.isVideoReady()&&this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseLeave")()}sendMouseDown(e,t,r){this.videoElementProvider.isVideoReady()&&(n.Log(n.GetStackTrace(),`mouse button ${e} down at (${t}, ${r})`,6),this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseDown")([e,t,r]))}sendMouseUp(e,t,r){if(!this.videoElementProvider.isVideoReady())return;n.Log(n.GetStackTrace(),`mouse button ${e} up at (${t}, ${r})`,6);const s=this.coordinateConverter.normalizeAndQuantizeUnsigned(t,r);this.toStreamerMessagesProvider.toStreamerHandlers.get("MouseUp")([e,s.x,s.y])}}class pn{constructor(e,t,r){this.fingers=[9,8,7,6,5,4,3,2,1,0],this.fingerIds=new Map,this.maxByteValue=255,this.touchEventListenerTracker=new on,this.toStreamerMessagesProvider=e,this.videoElementProvider=t,this.coordinateConverter=r,this.videoElementParent=t.getVideoElement();const s=e=>this.onTouchStart(e),i=e=>this.onTouchEnd(e),a=e=>this.onTouchMove(e);this.videoElementParent.addEventListener("touchstart",s),this.videoElementParent.addEventListener("touchend",i),this.videoElementParent.addEventListener("touchmove",a),this.touchEventListenerTracker.addUnregisterCallback((()=>this.videoElementParent.removeEventListener("touchstart",s))),this.touchEventListenerTracker.addUnregisterCallback((()=>this.videoElementParent.removeEventListener("touchend",i))),this.touchEventListenerTracker.addUnregisterCallback((()=>this.videoElementParent.removeEventListener("touchmove",a))),n.Log(n.GetStackTrace(),"Touch Events Registered",6);const o=e=>{e.preventDefault()};document.addEventListener("touchmove",o),this.touchEventListenerTracker.addUnregisterCallback((()=>document.removeEventListener("touchmove",o)))}unregisterTouchEvents(){this.touchEventListenerTracker.unregisterAll()}rememberTouch(e){const t=this.fingers.pop();void 0===t&&n.Log(n.GetStackTrace(),"exhausted touch identifiers",6),this.fingerIds.set(e.identifier,t)}forgetTouch(e){this.fingers.push(this.fingerIds.get(e.identifier)),this.fingers.sort((function(e,t){return t-e})),this.fingerIds.delete(e.identifier)}onTouchStart(e){if(this.videoElementProvider.isVideoReady()){for(let t=0;t<e.changedTouches.length;t++)this.rememberTouch(e.changedTouches[t]);n.Log(n.GetStackTrace(),"touch start",6),this.emitTouchData("TouchStart",e.changedTouches),e.preventDefault()}}onTouchEnd(e){if(this.videoElementProvider.isVideoReady()){n.Log(n.GetStackTrace(),"touch end",6),this.emitTouchData("TouchEnd",e.changedTouches);for(let t=0;t<e.changedTouches.length;t++)this.forgetTouch(e.changedTouches[t]);e.preventDefault()}}onTouchMove(e){this.videoElementProvider.isVideoReady()&&(n.Log(n.GetStackTrace(),"touch move",6),this.emitTouchData("TouchMove",e.touches),e.preventDefault())}emitTouchData(e,t){if(!this.videoElementProvider.isVideoReady())return;const r=this.videoElementProvider.getVideoParentElement().getBoundingClientRect(),s=this.toStreamerMessagesProvider.toStreamerHandlers;for(let i=0;i<t.length;i++){const a=1,o=t[i],l=o.clientX-r.left,c=o.clientY-r.top;n.Log(n.GetStackTrace(),`F${this.fingerIds.get(o.identifier)}=(${l}, ${c})`,6);const d=this.coordinateConverter.normalizeAndQuantizeUnsigned(l,c);switch(e){case"TouchStart":s.get("TouchStart")([a,d.x,d.y,this.fingerIds.get(o.identifier),this.maxByteValue*o.force,d.inRange?1:0]);break;case"TouchEnd":s.get("TouchEnd")([a,d.x,d.y,this.fingerIds.get(o.identifier),this.maxByteValue*o.force,d.inRange?1:0]);break;case"TouchMove":s.get("TouchMove")([a,d.x,d.y,this.fingerIds.get(o.identifier),this.maxByteValue*o.force,d.inRange?1:0])}}}}class fn{constructor(e){this.gamePadEventListenerTracker=new on,this.toStreamerMessagesProvider=e,this.requestAnimationFrame=(window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.requestAnimationFrame).bind(window);const t=window;if(window.addEventListener("beforeunload",(e=>this.onBeforeUnload(e))),"GamepadEvent"in t){const e=e=>this.gamePadConnectHandler(e),t=e=>this.gamePadDisconnectHandler(e);window.addEventListener("gamepadconnected",e),window.addEventListener("gamepaddisconnected",t),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("gamepadconnected",e))),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("gamepaddisconnected",t)))}else if("WebKitGamepadEvent"in t){const e=e=>this.gamePadConnectHandler(e),t=e=>this.gamePadDisconnectHandler(e);window.addEventListener("webkitgamepadconnected",e),window.addEventListener("webkitgamepaddisconnected",t),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("webkitgamepadconnected",e))),this.gamePadEventListenerTracker.addUnregisterCallback((()=>window.removeEventListener("webkitgamepaddisconnected",t)))}if(this.controllers=[],navigator.getGamepads)for(const e of navigator.getGamepads())e&&this.gamePadConnectHandler(new GamepadEvent("gamepadconnected",{gamepad:e}))}unregisterGamePadEvents(){this.gamePadEventListenerTracker.unregisterAll();for(const e of this.controllers)void 0!==e.id&&this.onGamepadDisconnected(e.id);this.controllers=[],this.onGamepadConnected=()=>{},this.onGamepadDisconnected=()=>{}}gamePadConnectHandler(e){n.Log(n.GetStackTrace(),"Gamepad connect handler",6);const t=e.gamepad,r={currentState:t,prevState:t,id:void 0};this.controllers.push(r),this.controllers[t.index].currentState=t,this.controllers[t.index].prevState=t,n.Log(n.GetStackTrace(),"gamepad: "+t.id+" connected",6),window.requestAnimationFrame((()=>this.updateStatus())),this.onGamepadConnected()}gamePadDisconnectHandler(e){n.Log(n.GetStackTrace(),"Gamepad disconnect handler",6),n.Log(n.GetStackTrace(),"gamepad: "+e.gamepad.id+" disconnected",6);const t=this.controllers[e.gamepad.index];delete this.controllers[e.gamepad.index],this.controllers=this.controllers.filter((e=>void 0!==e)),this.onGamepadDisconnected(t.id)}scanGamePads(){const e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[];for(let t=0;t<e.length;t++)e[t]&&e[t].index in this.controllers&&(this.controllers[e[t].index].currentState=e[t])}updateStatus(){this.scanGamePads();const e=this.toStreamerMessagesProvider.toStreamerHandlers;for(const t of this.controllers){const n=void 0===t.id?this.controllers.indexOf(t):t.id,r=t.currentState;for(let r=0;r<t.currentState.buttons.length;r++){const s=t.currentState.buttons[r],i=t.prevState.buttons[r];s.pressed?r==jt.LeftTrigger?e.get("GamepadAnalog")([n,5,s.value]):r==jt.RightTrigger?e.get("GamepadAnalog")([n,6,s.value]):e.get("GamepadButtonPressed")([n,r,i.pressed?1:0]):!s.pressed&&i.pressed&&(r==jt.LeftTrigger?e.get("GamepadAnalog")([n,5,0]):r==jt.RightTrigger?e.get("GamepadAnalog")([n,6,0]):e.get("GamepadButtonReleased")([n,r,0]))}for(let t=0;t<r.axes.length;t+=2){const s=parseFloat(r.axes[t].toFixed(4)),i=-parseFloat(r.axes[t+1].toFixed(4));e.get("GamepadAnalog")([n,t+1,s]),e.get("GamepadAnalog")([n,t+2,i])}this.controllers[n].prevState=r}this.controllers.length>0&&this.requestAnimationFrame((()=>this.updateStatus()))}onGamepadResponseReceived(e){for(const t of this.controllers)if(void 0===t.id){t.id=e;break}}onGamepadConnected(){}onGamepadDisconnected(e){}onBeforeUnload(e){for(const e of this.controllers)this.onGamepadDisconnected(e.id)}}!function(e){e[e.RightClusterBottomButton=0]="RightClusterBottomButton",e[e.RightClusterRightButton=1]="RightClusterRightButton",e[e.RightClusterLeftButton=2]="RightClusterLeftButton",e[e.RightClusterTopButton=3]="RightClusterTopButton",e[e.LeftShoulder=4]="LeftShoulder",e[e.RightShoulder=5]="RightShoulder",e[e.LeftTrigger=6]="LeftTrigger",e[e.RightTrigger=7]="RightTrigger",e[e.SelectOrBack=8]="SelectOrBack",e[e.StartOrForward=9]="StartOrForward",e[e.LeftAnalogPress=10]="LeftAnalogPress",e[e.RightAnalogPress=11]="RightAnalogPress",e[e.LeftClusterTopButton=12]="LeftClusterTopButton",e[e.LeftClusterBottomButton=13]="LeftClusterBottomButton",e[e.LeftClusterLeftButton=14]="LeftClusterLeftButton",e[e.LeftClusterRightButton=15]="LeftClusterRightButton",e[e.CentreButton=16]="CentreButton",e[e.LeftStickHorizontal=0]="LeftStickHorizontal",e[e.LeftStickVertical=1]="LeftStickVertical",e[e.RightStickHorizontal=2]="RightStickHorizontal",e[e.RightStickVertical=3]="RightStickVertical"}(jt||(jt={}));class vn{constructor(e,t,n){this.activeKeys=new yn,this.toStreamerMessagesProvider=e,this.videoElementProvider=t,this.coordinateConverter=n}registerKeyBoard(e){n.Log(n.GetStackTrace(),"Register Keyboard Events",7);const t=new hn(this.toStreamerMessagesProvider,e,this.activeKeys);return t.registerKeyBoardEvents(),t}registerMouse(e){n.Log(n.GetStackTrace(),"Register Mouse Events",7);const t=new mn(this.toStreamerMessagesProvider,this.videoElementProvider,this.coordinateConverter,this.activeKeys);switch(e){case Ot.LockedMouse:t.registerLockedMouseEvents(t);break;case Ot.HoveringMouse:t.registerHoveringMouseEvents(t);break;default:n.Info(n.GetStackTrace(),"unknown Control Scheme Type Defaulting to Locked Mouse Events"),t.registerLockedMouseEvents(t)}return t}registerTouch(e,t){if(n.Log(n.GetStackTrace(),"Registering Touch",6),e){const e=new ln(this.toStreamerMessagesProvider,this.videoElementProvider,this.coordinateConverter);return e.setVideoElementParentClientRect(t),e}return new pn(this.toStreamerMessagesProvider,this.videoElementProvider,this.coordinateConverter)}registerGamePad(){return n.Log(n.GetStackTrace(),"Register Game Pad",7),new fn(this.toStreamerMessagesProvider)}}class yn{constructor(){this.activeKeys=[],this.activeKeys=[]}getActiveKeys(){return this.activeKeys}}class Sn{constructor(e,t){this.lastTimeResized=(new Date).getTime(),this.videoElement=document.createElement("video"),this.config=t,this.videoElement.id="streamingVideo",this.videoElement.disablePictureInPicture=!0,this.videoElement.playsInline=!0,this.videoElement.style.width="100%",this.videoElement.style.height="100%",this.videoElement.style.position="absolute",this.videoElement.style.pointerEvents="all",e.appendChild(this.videoElement),this.onResizePlayerCallback=()=>{console.log("Resolution changed, restyling player, did you forget to override this function?")},this.onMatchViewportResolutionCallback=()=>{console.log("Resolution changed and match viewport resolution is turned on, did you forget to override this function?")},this.videoElement.onclick=()=>{null!=this.audioElement&&this.audioElement.paused&&this.audioElement.play(),this.videoElement.paused&&this.videoElement.play()},this.videoElement.onloadedmetadata=()=>{this.onVideoInitialized()},window.addEventListener("resize",(()=>this.resizePlayerStyle()),!0),window.addEventListener("orientationchange",(()=>this.onOrientationChange()))}setAudioElement(e){this.audioElement=e}play(){return this.videoElement.muted=this.config.isFlagEnabled(Et.StartVideoMuted),this.videoElement.autoplay=this.config.isFlagEnabled(Et.AutoPlayVideo),this.videoElement.play()}isPaused(){return this.videoElement.paused}isVideoReady(){return void 0!==this.videoElement.readyState&&this.videoElement.readyState>0}hasVideoSource(){return void 0!==this.videoElement.srcObject&&null!==this.videoElement.srcObject}getVideoElement(){return this.videoElement}getVideoParentElement(){return this.videoElement.parentElement}setVideoEnabled(e){this.videoElement.srcObject.getTracks().forEach((t=>t.enabled=e))}onVideoInitialized(){}onOrientationChange(){clearTimeout(this.orientationChangeTimeout),this.orientationChangeTimeout=window.setTimeout((()=>{this.resizePlayerStyle()}),500)}resizePlayerStyle(){const e=this.getVideoParentElement();e&&(this.updateVideoStreamSize(),e.classList.contains("fixed-size")||this.resizePlayerStyleToFillParentElement(),this.onResizePlayerCallback())}resizePlayerStyleToFillParentElement(){this.getVideoParentElement().setAttribute("style","top: 0px; left: 0px; width: 100%; height: 100%; cursor: default;")}updateVideoStreamSize(){if(this.config.isFlagEnabled(Et.MatchViewportResolution))if((new Date).getTime()-this.lastTimeResized>300){const e=this.getVideoParentElement();if(!e)return;this.onMatchViewportResolutionCallback(e.clientWidth,e.clientHeight),this.lastTimeResized=(new Date).getTime()}else n.Log(n.GetStackTrace(),"Resizing too often - skipping",6),clearTimeout(this.resizeTimeoutHandle),this.resizeTimeoutHandle=window.setTimeout((()=>this.updateVideoStreamSize()),100)}}class wn{constructor(){this.toStreamerHandlers=new Map,this.fromStreamerHandlers=new Map,this.toStreamerMessages=new Map,this.fromStreamerMessages=new Map}populateDefaultProtocol(){this.toStreamerMessages.set("IFrameRequest",{id:0,structure:[]}),this.toStreamerMessages.set("RequestQualityControl",{id:1,structure:[]}),this.toStreamerMessages.set("FpsRequest",{id:2,structure:[]}),this.toStreamerMessages.set("AverageBitrateRequest",{id:3,structure:[]}),this.toStreamerMessages.set("StartStreaming",{id:4,structure:[]}),this.toStreamerMessages.set("StopStreaming",{id:5,structure:[]}),this.toStreamerMessages.set("LatencyTest",{id:6,structure:["string"]}),this.toStreamerMessages.set("RequestInitialSettings",{id:7,structure:[]}),this.toStreamerMessages.set("TestEcho",{id:8,structure:[]}),this.toStreamerMessages.set("DataChannelLatencyTest",{id:9,structure:[]}),this.toStreamerMessages.set("UIInteraction",{id:50,structure:["string"]}),this.toStreamerMessages.set("Command",{id:51,structure:["string"]}),this.toStreamerMessages.set("KeyDown",{id:60,structure:["uint8","uint8"]}),this.toStreamerMessages.set("KeyUp",{id:61,structure:["uint8"]}),this.toStreamerMessages.set("KeyPress",{id:62,structure:["uint16"]}),this.toStreamerMessages.set("MouseEnter",{id:70,structure:[]}),this.toStreamerMessages.set("MouseLeave",{id:71,structure:[]}),this.toStreamerMessages.set("MouseDown",{id:72,structure:["uint8","uint16","uint16"]}),this.toStreamerMessages.set("MouseUp",{id:73,structure:["uint8","uint16","uint16"]}),this.toStreamerMessages.set("MouseMove",{id:74,structure:["uint16","uint16","int16","int16"]}),this.toStreamerMessages.set("MouseWheel",{id:75,structure:["int16","uint16","uint16"]}),this.toStreamerMessages.set("MouseDouble",{id:76,structure:["uint8","uint16","uint16"]}),this.toStreamerMessages.set("TouchStart",{id:80,structure:["uint8","uint16","uint16","uint8","uint8","uint8"]}),this.toStreamerMessages.set("TouchEnd",{id:81,structure:["uint8","uint16","uint16","uint8","uint8","uint8"]}),this.toStreamerMessages.set("TouchMove",{id:82,structure:["uint8","uint16","uint16","uint8","uint8","uint8"]}),this.toStreamerMessages.set("GamepadConnected",{id:93,structure:[]}),this.toStreamerMessages.set("GamepadButtonPressed",{id:90,structure:["uint8","uint8","uint8"]}),this.toStreamerMessages.set("GamepadButtonReleased",{id:91,structure:["uint8","uint8","uint8"]}),this.toStreamerMessages.set("GamepadAnalog",{id:92,structure:["uint8","uint8","double"]}),this.toStreamerMessages.set("GamepadDisconnected",{id:94,structure:["uint8"]}),this.fromStreamerMessages.set(0,"QualityControlOwnership"),this.fromStreamerMessages.set(1,"Response"),this.fromStreamerMessages.set(2,"Command"),this.fromStreamerMessages.set(3,"FreezeFrame"),this.fromStreamerMessages.set(4,"UnfreezeFrame"),this.fromStreamerMessages.set(5,"VideoEncoderAvgQP"),this.fromStreamerMessages.set(6,"LatencyTest"),this.fromStreamerMessages.set(7,"InitialSettings"),this.fromStreamerMessages.set(8,"FileExtension"),this.fromStreamerMessages.set(9,"FileMimeType"),this.fromStreamerMessages.set(10,"FileContents"),this.fromStreamerMessages.set(11,"TestEcho"),this.fromStreamerMessages.set(12,"InputControlOwnership"),this.fromStreamerMessages.set(13,"GamepadResponse"),this.fromStreamerMessages.set(14,"DataChannelLatencyTest"),this.fromStreamerMessages.set(255,"Protocol")}registerMessageHandler(e,t,r){switch(e){case Qt.ToStreamer:this.toStreamerHandlers.set(t,r);break;case Qt.FromStreamer:this.fromStreamerHandlers.set(t,r);break;default:n.Log(n.GetStackTrace(),`Unknown message direction ${e}`)}}}!function(e){e[e.ToStreamer=0]="ToStreamer",e[e.FromStreamer=1]="FromStreamer"}(Qt||(Qt={}));class Cn{constructor(){this.responseEventListeners=new Map}addResponseEventListener(e,t){this.responseEventListeners.set(e,t)}removeResponseEventListener(e){this.responseEventListeners.delete(e)}onResponse(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.Response",6);const t=new TextDecoder("utf-16").decode(e.slice(1));n.Log(n.GetStackTrace(),t,6),this.responseEventListeners.forEach((e=>{e(t)}))}}class Tn{constructor(e,t){this.dataChannelSender=e,this.toStreamerMessagesMapProvider=t}sendMessageToStreamer(e,t){void 0===t&&(t=[]);const r=this.toStreamerMessagesMapProvider.toStreamerMessages.get(e);if(void 0===r)return void n.Error(n.GetStackTrace(),`Attempted to send a message to the streamer with message type: ${e}, but the frontend hasn't been configured to send such a message. Check you've added the message type in your cpp`);if(r.structure&&t&&r.structure.length!==t.length)return void n.Error(n.GetStackTrace(),`Provided message data doesn't match expected layout. Expected [ ${r.structure.map((e=>{switch(e){case"uint8":case"uint16":case"int16":case"float":case"double":return"number";case"string":return"string"}})).toString()} ] but received [ ${t.map((e=>typeof e)).toString()} ]`);let s=0;const i=new TextEncoder;t.forEach(((e,t)=>{switch(r.structure[t]){case"uint8":s+=1;break;case"uint16":case"int16":s+=2;break;case"float":s+=4;break;case"double":s+=8;break;case"string":s+=2,s+=2*i.encode(e).length}}));const a=new DataView(new ArrayBuffer(s+1));a.setUint8(0,r.id);let o=1;t.forEach(((e,t)=>{switch(r.structure[t]){case"uint8":a.setUint8(o,e),o+=1;break;case"uint16":a.setUint16(o,e,!0),o+=2;break;case"int16":a.setInt16(o,e,!0),o+=2;break;case"float":a.setFloat32(o,e,!0),o+=4;break;case"double":a.setFloat64(o,e,!0),o+=8;break;case"string":a.setUint16(o,e.length,!0),o+=2;for(let t=0;t<e.length;t++)a.setUint16(o,e.charCodeAt(t),!0),o+=2}})),this.dataChannelSender.canSend()?this.dataChannelSender.sendData(a.buffer):n.Info(n.GetStackTrace(),`Data channel cannot send yet, skipping sending message: ${e} - ${new Uint8Array(a.buffer)}`)}}class bn{constructor(e){this.sendMessageController=e}SendRequestQualityControl(){this.sendMessageController.sendMessageToStreamer("RequestQualityControl")}SendMaxFpsRequest(){this.sendMessageController.sendMessageToStreamer("FpsRequest")}SendAverageBitrateRequest(){this.sendMessageController.sendMessageToStreamer("AverageBitrateRequest")}SendStartStreaming(){this.sendMessageController.sendMessageToStreamer("StartStreaming")}SendStopStreaming(){this.sendMessageController.sendMessageToStreamer("StopStreaming")}SendRequestInitialSettings(){this.sendMessageController.sendMessageToStreamer("RequestInitialSettings")}}class En{constructor(e){this.dataChannelProvider=e}canSend(){return void 0!==this.dataChannelProvider.getDataChannelInstance().dataChannel&&"open"==this.dataChannelProvider.getDataChannelInstance().dataChannel.readyState}sendData(e){const t=this.dataChannelProvider.getDataChannelInstance();"open"==t.dataChannel.readyState?(t.dataChannel.send(e),n.Log(n.GetStackTrace(),`Message Sent: ${new Uint8Array(e)}`,6),this.resetAfkWarningTimerOnDataSend()):n.Error(n.GetStackTrace(),`Message Failed: ${new Uint8Array(e)}`)}resetAfkWarningTimerOnDataSend(){}}class kn{constructor(e){this.videoElementProvider=e,this.normalizeAndQuantizeUnsignedFunc=()=>{throw new Error("Normalize and quantize unsigned, method not implemented.")},this.normalizeAndQuantizeSignedFunc=()=>{throw new Error("Normalize and unquantize signed, method not implemented.")},this.denormalizeAndUnquantizeUnsignedFunc=()=>{throw new Error("Denormalize and unquantize unsigned, method not implemented.")}}normalizeAndQuantizeUnsigned(e,t){return this.normalizeAndQuantizeUnsignedFunc(e,t)}unquantizeAndDenormalizeUnsigned(e,t){return this.denormalizeAndUnquantizeUnsignedFunc(e,t)}normalizeAndQuantizeSigned(e,t){return this.normalizeAndQuantizeSignedFunc(e,t)}setupNormalizeAndQuantize(){if(this.videoElementParent=this.videoElementProvider.getVideoParentElement(),this.videoElement=this.videoElementProvider.getVideoElement(),this.videoElementParent&&this.videoElement){const e=this.videoElementParent.clientHeight/this.videoElementParent.clientWidth,t=this.videoElement.videoHeight/this.videoElement.videoWidth;e>t?(n.Log(n.GetStackTrace(),"Setup Normalize and Quantize for playerAspectRatio > videoAspectRatio",6),this.ratio=e/t,this.normalizeAndQuantizeUnsignedFunc=(e,t)=>this.normalizeAndQuantizeUnsignedPlayerBigger(e,t),this.normalizeAndQuantizeSignedFunc=(e,t)=>this.normalizeAndQuantizeSignedPlayerBigger(e,t),this.denormalizeAndUnquantizeUnsignedFunc=(e,t)=>this.denormalizeAndUnquantizeUnsignedPlayerBigger(e,t)):(n.Log(n.GetStackTrace(),"Setup Normalize and Quantize for playerAspectRatio <= videoAspectRatio",6),this.ratio=t/e,this.normalizeAndQuantizeUnsignedFunc=(e,t)=>this.normalizeAndQuantizeUnsignedPlayerSmaller(e,t),this.normalizeAndQuantizeSignedFunc=(e,t)=>this.normalizeAndQuantizeSignedPlayerSmaller(e,t),this.denormalizeAndUnquantizeUnsignedFunc=(e,t)=>this.denormalizeAndUnquantizeUnsignedPlayerSmaller(e,t))}}normalizeAndQuantizeUnsignedPlayerBigger(e,t){const n=e/this.videoElementParent.clientWidth,r=this.ratio*(t/this.videoElementParent.clientHeight-.5)+.5;return n<0||n>1||r<0||r>1?new Mn(!1,65535,65535):new Mn(!0,65536*n,65536*r)}denormalizeAndUnquantizeUnsignedPlayerBigger(e,t){const n=e/65536,r=(t/65536-.5)/this.ratio+.5;return new Rn(n*this.videoElementParent.clientWidth,r*this.videoElementParent.clientHeight)}normalizeAndQuantizeSignedPlayerBigger(e,t){const n=e/(.5*this.videoElementParent.clientWidth),r=this.ratio*t/(.5*this.videoElementParent.clientHeight);return new Pn(32767*n,32767*r)}normalizeAndQuantizeUnsignedPlayerSmaller(e,t){const n=this.ratio*(e/this.videoElementParent.clientWidth-.5)+.5,r=t/this.videoElementParent.clientHeight;return n<0||n>1||r<0||r>1?new Mn(!1,65535,65535):new Mn(!0,65536*n,65536*r)}denormalizeAndUnquantizeUnsignedPlayerSmaller(e,t){const n=(e/65536-.5)/this.ratio+.5,r=t/65536;return new Rn(n*this.videoElementParent.clientWidth,r*this.videoElementParent.clientHeight)}normalizeAndQuantizeSignedPlayerSmaller(e,t){const n=this.ratio*e/(.5*this.videoElementParent.clientWidth),r=t/(.5*this.videoElementParent.clientHeight);return new Pn(32767*n,32767*r)}}class Mn{constructor(e,t,n){this.inRange=e,this.x=t,this.y=n}}class Rn{constructor(e,t){this.x=e,this.y=t}}class Pn{constructor(e,t){this.x=e,this.y=t}}class Ln{constructor(e,t){this.shouldShowPlayOverlay=!0,this.autoJoinTimer=void 0,this.config=e,this.pixelStreaming=t,this.responseController=new Cn,this.file=new rn,this.sdpConstraints={offerToReceiveAudio:!0,offerToReceiveVideo:!0},this.afkController=new Dt(this.config,this.pixelStreaming,this.onAfkTriggered.bind(this)),this.afkController.onAFKTimedOutCallback=()=>{this.closeSignalingServer("You have been disconnected due to inactivity")},this.freezeFrameController=new Ae(this.pixelStreaming.videoElementParent),this.videoPlayer=new Sn(this.pixelStreaming.videoElementParent,this.config),this.videoPlayer.onVideoInitialized=()=>this.handleVideoInitialized(),this.videoPlayer.onMatchViewportResolutionCallback=(e,t)=>{const n={"Resolution.Width":e,"Resolution.Height":t};this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify(n)])},this.videoPlayer.onResizePlayerCallback=()=>{this.setUpMouseAndFreezeFrame()},this.streamController=new Oe(this.videoPlayer),this.coordinateConverter=new kn(this.videoPlayer),this.sendrecvDataChannelController=new At,this.recvDataChannelController=new At,this.registerDataChannelEventEmitters(this.sendrecvDataChannelController),this.registerDataChannelEventEmitters(this.recvDataChannelController),this.dataChannelSender=new En(this.sendrecvDataChannelController),this.dataChannelSender.resetAfkWarningTimerOnDataSend=()=>this.afkController.resetAfkWarningTimer(),this.streamMessageController=new wn,this.transport=new l,this.protocol=new xe(this.transport),this.protocol.messageHandlers.addListener(ae.typeName,(e=>this.handleOnConfigMessage(e))),this.protocol.messageHandlers.addListener(ke.typeName,(e=>this.handleStreamerListMessage(e))),this.protocol.messageHandlers.addListener(Pe.typeName,(e=>this.handleStreamerIDChangedMessage(e))),this.protocol.messageHandlers.addListener(Se.typeName,(e=>{const t=e;this.pixelStreaming._onPlayerCount(t.count)})),this.protocol.messageHandlers.addListener(se.typeName,(e=>this.handleWebRtcAnswer(e))),this.protocol.messageHandlers.addListener(pe.typeName,(e=>this.handleWebRtcOffer(e))),this.protocol.messageHandlers.addListener(be.typeName,(e=>this.handleWebRtcSFUPeerDatachannels(e))),this.protocol.messageHandlers.addListener(he.typeName,(e=>{const t=e;this.handleIceCandidate(t.candidate)})),this.protocol.transportEvents.addListener("open",(()=>{if(!this.config.isFlagEnabled(Et.BrowserSendOffer)){const e=Fe(me);this.protocol.sendMessage(e)}})),this.protocol.transportEvents.addListener("error",(()=>{n.Error(n.GetStackTrace(),"Got a transport error.")})),this.protocol.transportEvents.addListener("close",(e=>{const t=this.shouldReconnect&&1001!=e.code&&this.config.getNumericSettingValue(Mt.MaxReconnectAttempts)>0,n=this.disconnectMessage?this.disconnectMessage:e.reason;this.pixelStreaming._onDisconnect(n,!t&&!this.isReconnecting),this.afkController.stopAfkWarningTimer(),this.statsTimerHandle&&void 0!==this.statsTimerHandle&&window.clearInterval(this.statsTimerHandle),this.setVideoEncoderAvgQP(0),this.setTouchInputEnabled(!1),this.setMouseInputEnabled(!1),this.setKeyboardInputEnabled(!1),this.setGamePadInputEnabled(!1),t&&setTimeout((()=>{this.isReconnecting=!0,this.reconnectAttempt++,this.tryReconnect(e.reason)}),2e3)})),this.sendMessageController=new Tn(this.dataChannelSender,this.streamMessageController),this.toStreamerMessagesController=new bn(this.sendMessageController),this.registerMessageHandlers(),this.streamMessageController.populateDefaultProtocol(),this.inputClassesFactory=new vn(this.streamMessageController,this.videoPlayer,this.coordinateConverter),this.isUsingSFU=!1,this.isQualityController=!1,this.preferredCodec="",this.shouldReconnect=!0,this.isReconnecting=!1,this.reconnectAttempt=0,this.config._addOnOptionSettingChangedListener(Ft.StreamerId,(e=>{if(""===e)return;this.peerConnectionController.peerConnection.close(),this.peerConnectionController.createPeerConnection(this.peerConfig,this.preferredCodec),this.subscribedStream=e;const t=Fe(Me,{streamerId:e});this.protocol.sendMessage(t)})),this.setVideoEncoderAvgQP(-1),this.signallingUrlBuilder=()=>{let e=this.config.getTextSettingValue(Pt.SignallingServerUrl);return this.config.isFlagEnabled(Et.BrowserSendOffer)&&(e+="?"+Et.BrowserSendOffer+"=true"),e}}requestUnquantizedAndDenormalizeUnsigned(e,t){return this.coordinateConverter.unquantizeAndDenormalizeUnsigned(e,t)}handleOnMessage(e){const t=new Uint8Array(e.data);n.Log(n.GetStackTrace(),"Message incoming:"+t,6);const r=this.streamMessageController.fromStreamerMessages.get(t[0]);this.streamMessageController.fromStreamerHandlers.get(r)(e.data)}registerMessageHandlers(){this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"QualityControlOwnership",(e=>this.onQualityControlOwnership(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"Response",(e=>this.responseController.onResponse(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"Command",(e=>{this.onCommand(e)})),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"FreezeFrame",(e=>this.onFreezeFrameMessage(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"UnfreezeFrame",(()=>this.invalidateFreezeFrameAndEnableVideo())),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"VideoEncoderAvgQP",(e=>this.handleVideoEncoderAvgQP(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"LatencyTest",(e=>this.handleLatencyTestResult(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"DataChannelLatencyTest",(e=>this.handleDataChannelLatencyTestResponse(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"InitialSettings",(e=>this.handleInitialSettings(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"FileExtension",(e=>this.onFileExtension(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"FileMimeType",(e=>this.onFileMimeType(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"FileContents",(e=>this.onFileContents(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"TestEcho",(()=>{})),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"InputControlOwnership",(e=>this.onInputControlOwnership(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"GamepadResponse",(e=>this.onGamepadResponse(e))),this.streamMessageController.registerMessageHandler(Qt.FromStreamer,"Protocol",(e=>this.onProtocolMessage(e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"IFrameRequest",(()=>this.sendMessageController.sendMessageToStreamer("IFrameRequest"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"RequestQualityControl",(()=>this.sendMessageController.sendMessageToStreamer("RequestQualityControl"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"FpsRequest",(()=>this.sendMessageController.sendMessageToStreamer("FpsRequest"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"AverageBitrateRequest",(()=>this.sendMessageController.sendMessageToStreamer("AverageBitrateRequest"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"StartStreaming",(()=>this.sendMessageController.sendMessageToStreamer("StartStreaming"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"StopStreaming",(()=>this.sendMessageController.sendMessageToStreamer("StopStreaming"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"LatencyTest",(e=>this.sendMessageController.sendMessageToStreamer("LatencyTest",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"RequestInitialSettings",(()=>this.sendMessageController.sendMessageToStreamer("RequestInitialSettings"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"TestEcho",(()=>{})),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"UIInteraction",(e=>this.sendMessageController.sendMessageToStreamer("UIInteraction",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"Command",(e=>this.sendMessageController.sendMessageToStreamer("Command",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"TextboxEntry",(e=>this.sendMessageController.sendMessageToStreamer("TextboxEntry",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"KeyDown",(e=>this.sendMessageController.sendMessageToStreamer("KeyDown",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"KeyUp",(e=>this.sendMessageController.sendMessageToStreamer("KeyUp",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"KeyPress",(e=>this.sendMessageController.sendMessageToStreamer("KeyPress",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseEnter",(e=>this.sendMessageController.sendMessageToStreamer("MouseEnter",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseLeave",(e=>this.sendMessageController.sendMessageToStreamer("MouseLeave",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseDown",(e=>this.sendMessageController.sendMessageToStreamer("MouseDown",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseUp",(e=>this.sendMessageController.sendMessageToStreamer("MouseUp",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseMove",(e=>this.sendMessageController.sendMessageToStreamer("MouseMove",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseWheel",(e=>this.sendMessageController.sendMessageToStreamer("MouseWheel",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"MouseDouble",(e=>this.sendMessageController.sendMessageToStreamer("MouseDouble",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"TouchStart",(e=>this.sendMessageController.sendMessageToStreamer("TouchStart",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"TouchEnd",(e=>this.sendMessageController.sendMessageToStreamer("TouchEnd",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"TouchMove",(e=>this.sendMessageController.sendMessageToStreamer("TouchMove",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"GamepadConnected",(()=>this.sendMessageController.sendMessageToStreamer("GamepadConnected"))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"GamepadButtonPressed",(e=>this.sendMessageController.sendMessageToStreamer("GamepadButtonPressed",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"GamepadButtonReleased",(e=>this.sendMessageController.sendMessageToStreamer("GamepadButtonReleased",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"GamepadAnalog",(e=>this.sendMessageController.sendMessageToStreamer("GamepadAnalog",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"GamepadDisconnected",(e=>this.sendMessageController.sendMessageToStreamer("GamepadDisconnected",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRHMDTransform",(e=>this.sendMessageController.sendMessageToStreamer("XRHMDTransform",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRControllerTransform",(e=>this.sendMessageController.sendMessageToStreamer("XRControllerTransform",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRSystem",(e=>this.sendMessageController.sendMessageToStreamer("XRSystem",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRButtonTouched",(e=>this.sendMessageController.sendMessageToStreamer("XRButtonTouched",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRButtonPressed",(e=>this.sendMessageController.sendMessageToStreamer("XRButtonPressed",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRButtonReleased",(e=>this.sendMessageController.sendMessageToStreamer("XRButtonReleased",e))),this.streamMessageController.registerMessageHandler(Qt.ToStreamer,"XRAnalog",(e=>this.sendMessageController.sendMessageToStreamer("XRAnalog",e)))}onCommand(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.Command",6);const t=new TextDecoder("utf-16").decode(e.slice(1));n.Log(n.GetStackTrace(),"Data Channel Command: "+t,6);const r=JSON.parse(t);"onScreenKeyboard"===r.command&&this.pixelStreaming._activateOnScreenKeyboard(r)}onProtocolMessage(e){try{const t=new TextDecoder("utf-16").decode(e.slice(1)),r=JSON.parse(t);Object.prototype.hasOwnProperty.call(r,"Direction")||n.Error(n.GetStackTrace(),"Malformed protocol received. Ensure the protocol message contains a direction");const s=r.Direction;delete r.Direction,n.Log(n.GetStackTrace(),`Received new ${s==Qt.FromStreamer?"FromStreamer":"ToStreamer"} protocol. Updating existing protocol...`),Object.keys(r).forEach((e=>{const t=r[e];switch(s){case Qt.ToStreamer:if(!Object.prototype.hasOwnProperty.call(t,"id"))return void n.Error(n.GetStackTrace(),`ToStreamer->${e} protocol definition was malformed as it didn't contain at least an id\n\n Definition was: ${JSON.stringify(t,null,2)}`);if("UIInteraction"===e||"Command"===e||"LatencyTest"===e)return;this.streamMessageController.toStreamerHandlers.get(e)?this.streamMessageController.toStreamerMessages.set(e,t):n.Error(n.GetStackTrace(),`There was no registered handler for "${e}" - try adding one using registerMessageHandler(MessageDirection.ToStreamer, "${e}", myHandler)`);break;case Qt.FromStreamer:if(!Object.prototype.hasOwnProperty.call(t,"id"))return void n.Error(n.GetStackTrace(),`FromStreamer->${e} protocol definition was malformed as it didn't contain at least an id\n\n Definition was: ${JSON.stringify(t,null,2)}`);this.streamMessageController.fromStreamerHandlers.get(e)?this.streamMessageController.fromStreamerMessages.set(t.id,e):n.Error(n.GetStackTrace(),`There was no registered handler for "${t}" - try adding one using registerMessageHandler(MessageDirection.FromStreamer, "${e}", myHandler)`);break;default:n.Error(n.GetStackTrace(),`Unknown direction: ${s}`)}})),this.toStreamerMessagesController.SendRequestInitialSettings(),this.toStreamerMessagesController.SendRequestQualityControl()}catch(e){n.Log(n.GetStackTrace(),e)}}onInputControlOwnership(e){const t=new Uint8Array(e);n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.InputControlOwnership",6);const r=new Boolean(t[1]).valueOf();n.Log(n.GetStackTrace(),`Received input controller message - will your input control the stream: ${r}`),this.pixelStreaming._onInputControlOwnership(r)}onGamepadResponse(e){const t=new TextDecoder("utf-16").decode(e.slice(1)),n=JSON.parse(t);this.gamePadController.onGamepadResponseReceived(n.controllerId)}onAfkTriggered(){this.afkController.onAfkClick(),this.videoPlayer.isPaused()&&this.videoPlayer.hasVideoSource()&&this.playStream()}setAfkEnabled(e){e?this.onAfkTriggered():this.afkController.stopAfkWarningTimer()}tryReconnect(e){this.protocol?(this.isReconnecting=!0,this.protocol.isConnected()?(this.closeSignalingServer(`${e} Restarting stream...`),setTimeout((()=>{this.tryReconnect(e)}),3e3)):(this.pixelStreaming._onWebRtcAutoConnect(),this.connectToSignallingServer())):n.Log(n.GetStackTrace(),"This player has no protocol connection.")}loadFreezeFrameOrShowPlayOverlay(){this.pixelStreaming.dispatchEvent(new ct({shouldShowPlayOverlay:this.shouldShowPlayOverlay,isValid:this.freezeFrameController.valid,jpegData:this.freezeFrameController.jpeg})),!0===this.shouldShowPlayOverlay?(n.Log(n.GetStackTrace(),"showing play overlay"),this.resizePlayerStyle()):(n.Log(n.GetStackTrace(),"showing freeze frame"),this.freezeFrameController.showFreezeFrame()),setTimeout((()=>{this.videoPlayer.setVideoEnabled(!1)}),this.freezeFrameController.freezeFrameDelay)}onFreezeFrameMessage(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.FreezeFrame",6);const t=new Uint8Array(e);this.freezeFrameController.processFreezeFrameMessage(t,(()=>this.loadFreezeFrameOrShowPlayOverlay()))}invalidateFreezeFrameAndEnableVideo(){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.FreezeFrame",6),setTimeout((()=>{this.pixelStreaming.dispatchEvent(new dt),this.freezeFrameController.hideFreezeFrame()}),this.freezeFrameController.freezeFrameDelay),this.videoPlayer.getVideoElement()&&this.videoPlayer.setVideoEnabled(!0)}onFileExtension(e){const t=new Uint8Array(e);nn.setExtensionFromBytes(t,this.file)}onFileMimeType(e){const t=new Uint8Array(e);nn.setMimeTypeFromBytes(t,this.file)}onFileContents(e){const t=new Uint8Array(e);nn.setContentsFromBytes(t,this.file)}playStream(){if(!this.videoPlayer.getVideoElement()){const e="Could not play video stream because the video player was not initialized correctly.";return this.pixelStreaming.dispatchEvent(new at({message:e})),n.Error(n.GetStackTrace(),e),void this.closeSignalingServer("Stream not initialized correctly")}if(this.videoPlayer.hasVideoSource()){if(this.setTouchInputEnabled(this.config.isFlagEnabled(Et.TouchInput)),this.pixelStreaming.dispatchEvent(new ot),this.streamController.audioElement.srcObject){const e=this.config.isFlagEnabled(Et.StartVideoMuted);this.streamController.audioElement.muted=e,e?this.playVideo():this.streamController.audioElement.play().then((()=>{this.playVideo()})).catch((e=>{n.Log(n.GetStackTrace(),e),n.Log(n.GetStackTrace(),"Browser does not support autoplaying video without interaction - to resolve this we are going to show the play button overlay."),this.pixelStreaming.dispatchEvent(new lt({reason:e}))}))}else this.playVideo();this.shouldShowPlayOverlay=!1,this.freezeFrameController.showFreezeFrame()}else n.Warning(n.GetStackTrace(),"Cannot play stream, the video element has no srcObject to play.")}playVideo(){this.videoPlayer.play().catch((e=>{this.streamController.audioElement.srcObject&&this.streamController.audioElement.pause(),n.Log(n.GetStackTrace(),e),n.Log(n.GetStackTrace(),"Browser does not support autoplaying video without interaction - to resolve this we are going to show the play button overlay."),this.pixelStreaming.dispatchEvent(new lt({reason:e}))}))}autoPlayVideoOrSetUpPlayOverlay(){this.config.isFlagEnabled(Et.AutoPlayVideo)&&this.playStream(),this.resizePlayerStyle()}connectToSignallingServer(){this.locallyClosed=!1,this.shouldReconnect=!0,this.disconnectMessage=null;const e=this.signallingUrlBuilder();this.protocol.connect(e)}startSession(e){if(this.peerConfig=e,this.config.isFlagEnabled(Et.ForceTURN)&&!this.checkTurnServerAvailability(e))return n.Info(n.GetStackTrace(),"No turn server was found in the Peer Connection Options. TURN cannot be forced, closing connection. Please use STUN instead"),void this.closeSignalingServer("TURN cannot be forced, closing connection. Please use STUN instead.");this.peerConnectionController=new Xt(this.peerConfig,this.config,this.preferredCodec),this.peerConnectionController.onVideoStats=e=>this.handleVideoStats(e),this.peerConnectionController.onSendWebRTCOffer=e=>this.handleSendWebRTCOffer(e),this.peerConnectionController.onSendWebRTCAnswer=e=>this.handleSendWebRTCAnswer(e),this.peerConnectionController.onPeerIceCandidate=e=>this.handleSendIceCandidate(e),this.peerConnectionController.onDataChannel=e=>this.handleDataChannel(e),this.peerConnectionController.showTextOverlayConnecting=()=>this.pixelStreaming._onWebRtcConnecting(),this.peerConnectionController.showTextOverlaySetupFailure=()=>this.pixelStreaming._onWebRtcFailed();let t=!1;this.peerConnectionController.onIceConnectionStateChange=()=>{!t&&["connected","completed"].includes(this.peerConnectionController.peerConnection.iceConnectionState)&&(this.pixelStreaming._onWebRtcConnected(),t=!0)},this.peerConnectionController.onTrack=e=>this.streamController.handleOnTrack(e),this.config.isFlagEnabled(Et.BrowserSendOffer)&&(this.sendrecvDataChannelController.createDataChannel(this.peerConnectionController.peerConnection,"cirrus",this.datachannelOptions),this.sendrecvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e),this.peerConnectionController.createOffer(this.sdpConstraints,this.config))}checkTurnServerAvailability(e){if(!e.iceServers)return n.Info(n.GetStackTrace(),"A turn sever was not found"),!1;for(const t of e.iceServers)for(const e of t.urls)if(e.includes("turn"))return n.Log(n.GetStackTrace(),`A turn sever was found at ${e}`),!0;return n.Info(n.GetStackTrace(),"A turn sever was not found"),!1}handleOnConfigMessage(e){this.resizePlayerStyle(),this.startSession(e.peerConnectionOptions)}handleStreamerListMessage(e){n.Log(n.GetStackTrace(),`Got streamer list ${e.ids}`,6);let t=null;const r=this.config.getSettingOption(Ft.StreamerId);r.selected.toString().trim()&&(t=r.selected);const s=[...e.ids];s.unshift(""),this.config.setOptionSettingOptions(Ft.StreamerId,s);let i=null;const a=this.config.isFlagEnabled(Et.WaitForStreamer),o=this.config.getNumericSettingValue(Mt.MaxReconnectAttempts),l=this.config.getNumericSettingValue(Mt.StreamerAutoJoinInterval),c=this.config.useUrlParams,d=new URLSearchParams(window.location.search);c&&d.has(Ft.StreamerId)?t=d.get(Ft.StreamerId):this.subscribedStream&&(t=this.subscribedStream),t&&e.ids.includes(t)?i=t:t&&a||1!=e.ids.length||(i=e.ids[0]),i?(this.isReconnecting=!1,this.reconnectAttempt=0,this.config.setOptionSettingValue(Ft.StreamerId,i)):a&&(this.reconnectAttempt<o?(this.isReconnecting=!0,this.reconnectAttempt++,setTimeout((()=>{this.protocol.requestStreamerList()}),l)):(this.reconnectAttempt=0,this.isReconnecting=!1,this.shouldReconnect=!1)),this.pixelStreaming.dispatchEvent(new ut({messageStreamerList:e,autoSelectedStreamerId:i,wantedStreamerId:t}))}handleStreamerIDChangedMessage(e){const t=e.newID,n=this.config.getSettingOption(Ft.StreamerId),r=n.onChange;n.onChange=()=>{};const s=n.options;for(let e=0;e<s.length;++e)if(s[e]==this.subscribedStream){s[e]=t;break}n.options=s,n.selected=t,n.onChange=r,this.subscribedStream=e.newID,this.pixelStreaming.dispatchEvent(new gt({newID:t}))}handleWebRtcAnswer(e){n.Log(n.GetStackTrace(),`Got answer sdp ${e.sdp}`,6);const t={sdp:e.sdp,type:"answer"};this.peerConnectionController.receiveAnswer(t),this.handlePostWebrtcNegotiation()}handleWebRtcOffer(e){n.Log(n.GetStackTrace(),`Got offer sdp ${e.sdp}`,6),this.isUsingSFU=!!e.sfu&&e.sfu,this.isUsingSFU&&(this.peerConnectionController.preferredCodec="");const t={sdp:e.sdp,type:"offer"};this.peerConnectionController.receiveOffer(t,this.config),this.handlePostWebrtcNegotiation()}handleWebRtcSFUPeerDatachannels(e){const t={ordered:!0,negotiated:!0,id:e.sendStreamId},n=e.sendStreamId!=e.recvStreamId;if(this.sendrecvDataChannelController.createDataChannel(this.peerConnectionController.peerConnection,n?"send-datachannel":"datachannel",t),n){const t={ordered:!0,negotiated:!0,id:e.recvStreamId};this.recvDataChannelController.createDataChannel(this.peerConnectionController.peerConnection,"recv-datachannel",t),this.recvDataChannelController.handleOnOpen=()=>this.protocol.sendSFURecvDataChannelReady(),this.recvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e)}else this.sendrecvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e)}handlePostWebrtcNegotiation(){this.afkController.startAfkWarningTimer(),this.pixelStreaming._onWebRtcSdp(),this.statsTimerHandle&&void 0!==this.statsTimerHandle&&window.clearInterval(this.statsTimerHandle),this.statsTimerHandle=window.setInterval((()=>this.getStats()),1e3),this.setMouseInputEnabled(this.config.isFlagEnabled(Et.MouseInput)),this.setKeyboardInputEnabled(this.config.isFlagEnabled(Et.KeyboardInput)),this.setGamePadInputEnabled(this.config.isFlagEnabled(Et.GamepadInput))}handleIceCandidate(e){n.Log(n.GetStackTrace(),"Web RTC Controller: onWebRtcIce",6);const t=new RTCIceCandidate(e);this.peerConnectionController.handleOnIce(t)}handleSendIceCandidate(e){n.Log(n.GetStackTrace(),"OnIceCandidate",6),e.candidate&&e.candidate.candidate&&this.protocol.sendIceCandidate(e.candidate)}handleDataChannel(e){n.Log(n.GetStackTrace(),"Data channel created for us by browser as we are a receiving peer.",6),this.sendrecvDataChannelController.dataChannel=e.channel,this.sendrecvDataChannelController.setupDataChannel(),this.sendrecvDataChannelController.handleOnMessage=e=>this.handleOnMessage(e)}handleSendWebRTCOffer(e){n.Log(n.GetStackTrace(),"Sending the offer to the Server",6);const t={sdp:e.sdp,minBitrateBps:1e3*this.config.getNumericSettingValue(Mt.WebRTCMinBitrate),maxBitrateBps:1e3*this.config.getNumericSettingValue(Mt.WebRTCMaxBitrate)};this.protocol.sendWebRtcOffer(Fe(pe,t))}handleSendWebRTCAnswer(e){n.Log(n.GetStackTrace(),"Sending the answer to the Server",6);const t={sdp:e.sdp,minBitrateBps:1e3*this.config.getNumericSettingValue(Mt.WebRTCMinBitrate),maxBitrateBps:1e3*this.config.getNumericSettingValue(Mt.WebRTCMaxBitrate)};this.protocol.sendWebRtcOffer(Fe(se,t)),this.isUsingSFU&&this.protocol.sendWebRtcDatachannelRequest()}setUpMouseAndFreezeFrame(){this.videoElementParentClientRect=this.videoPlayer.getVideoParentElement().getBoundingClientRect(),this.coordinateConverter.setupNormalizeAndQuantize(),this.freezeFrameController.freezeFrame.resize()}closeSignalingServer(e){var t;this.locallyClosed=!0,this.shouldReconnect=!1,this.disconnectMessage=e,null===(t=this.protocol)||void 0===t||t.disconnect()}closePeerConnection(){var e;null===(e=this.peerConnectionController)||void 0===e||e.close()}close(){this.closeSignalingServer(""),this.closePeerConnection()}getStats(){this.peerConnectionController.generateStats()}sendLatencyTest(){this.latencyStartTime=Date.now(),this.streamMessageController.toStreamerHandlers.get("LatencyTest")([JSON.stringify({StartTime:this.latencyStartTime})])}sendDataChannelLatencyTest(e){this.streamMessageController.toStreamerHandlers.get("DataChannelLatencyTest")([JSON.stringify(e)])}sendEncoderMinQP(e){n.Log(n.GetStackTrace(),`MinQP=${e}\n`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"Encoder.MinQP":e})])}sendEncoderMaxQP(e){n.Log(n.GetStackTrace(),`MaxQP=${e}\n`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"Encoder.MaxQP":e})])}sendWebRTCMinBitrate(e){n.Log(n.GetStackTrace(),`WebRTC Min Bitrate=${e}`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.MinBitrate":e})])}sendWebRTCMaxBitrate(e){n.Log(n.GetStackTrace(),`WebRTC Max Bitrate=${e}`,6),null!=e&&this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.MaxBitrate":e})])}sendWebRTCFps(e){n.Log(n.GetStackTrace(),`WebRTC FPS=${e}`,6),null!=e&&(this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.Fps":e})]),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"WebRTC.MaxFps":e})]))}sendShowFps(){n.Log(n.GetStackTrace(),"---- Sending show stat to UE ----",6),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({"stat.fps":""})])}sendIframeRequest(){n.Log(n.GetStackTrace(),"---- Sending Request for an IFrame ----",6),this.streamMessageController.toStreamerHandlers.get("IFrameRequest")()}emitUIInteraction(e){n.Log(n.GetStackTrace(),"---- Sending custom UIInteraction message ----",6),this.streamMessageController.toStreamerHandlers.get("UIInteraction")([JSON.stringify(e)])}emitCommand(e){n.Log(n.GetStackTrace(),"---- Sending custom Command message ----",6),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify(e)])}emitConsoleCommand(e){n.Log(n.GetStackTrace(),"---- Sending custom Command:ConsoleCommand message ----",6),this.streamMessageController.toStreamerHandlers.get("Command")([JSON.stringify({ConsoleCommand:e})])}sendRequestQualityControlOwnership(){n.Log(n.GetStackTrace(),"---- Sending Request to Control Quality ----",6),this.toStreamerMessagesController.SendRequestQualityControl()}handleLatencyTestResult(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.latencyTest",6);const t=new TextDecoder("utf-16").decode(e.slice(1)),r=new tn;Object.assign(r,JSON.parse(t)),r.processFields(),r.testStartTimeMs=this.latencyStartTime,r.browserReceiptTimeMs=Date.now(),r.latencyExcludingDecode=~~(r.browserReceiptTimeMs-r.testStartTimeMs),r.testDuration=~~(r.TransmissionTimeMs-r.ReceiptTimeMs),r.networkLatency=~~(r.latencyExcludingDecode-r.testDuration),r.frameDisplayDeltaTimeMs&&r.browserReceiptTimeMs&&(r.endToEndLatency=(r.frameDisplayDeltaTimeMs,r.networkLatency,~~+r.CaptureToSendMs)),this.pixelStreaming._onLatencyTestResult(r)}handleDataChannelLatencyTestResponse(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.dataChannelLatencyResponse",6);const t=new TextDecoder("utf-16").decode(e.slice(1)),r=JSON.parse(t);this.pixelStreaming._onDataChannelLatencyTestResponse(r)}handleInitialSettings(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.InitialSettings",6);const t=new TextDecoder("utf-16").decode(e.slice(1)),r=JSON.parse(t),s=new Jt;r.Encoder&&(s.EncoderSettings=r.Encoder),r.WebRTC&&(s.WebRTCSettings=r.WebRTC),r.PixelStreaming&&(s.PixelStreamingSettings=r.PixelStreaming),r.ConfigOptions&&void 0!==r.ConfigOptions.DefaultToHover&&this.config.setFlagEnabled(Et.HoveringMouseMode,!!r.ConfigOptions.DefaultToHover),s.ueCompatible(),n.Log(n.GetStackTrace(),t,6),this.pixelStreaming._onInitialSettings(s)}handleVideoEncoderAvgQP(e){n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.VideoEncoderAvgQP",6);const t=Number(new TextDecoder("utf-16").decode(e.slice(1)));this.setVideoEncoderAvgQP(t)}handleVideoInitialized(){this.pixelStreaming._onVideoInitialized(),this.autoPlayVideoOrSetUpPlayOverlay(),this.resizePlayerStyle(),this.videoPlayer.updateVideoStreamSize()}onQualityControlOwnership(e){const t=new Uint8Array(e);n.Log(n.GetStackTrace(),"DataChannelReceiveMessageType.QualityControlOwnership",6),this.isQualityController=new Boolean(t[1]).valueOf(),n.Log(n.GetStackTrace(),`Received quality controller message, will control quality: ${this.isQualityController}`),this.pixelStreaming._onQualityControlOwnership(this.isQualityController)}handleVideoStats(e){this.pixelStreaming._onVideoStats(e)}resizePlayerStyle(){this.videoPlayer.resizePlayerStyle()}setPreferredCodec(e){this.preferredCodec=e,this.peerConnectionController&&(this.peerConnectionController.preferredCodec=e,this.peerConnectionController.updateCodecSelection=!1)}setVideoEncoderAvgQP(e){this.videoAvgQp=e,this.pixelStreaming._onVideoEncoderAvgQP(this.videoAvgQp)}setKeyboardInputEnabled(e){var t;null===(t=this.keyboardController)||void 0===t||t.unregisterKeyBoardEvents(),e&&(this.keyboardController=this.inputClassesFactory.registerKeyBoard(this.config))}setMouseInputEnabled(e){var t;if(null===(t=this.mouseController)||void 0===t||t.unregisterMouseEvents(),e){const e=this.config.isFlagEnabled(Et.HoveringMouseMode)?Ot.HoveringMouse:Ot.LockedMouse;this.mouseController=this.inputClassesFactory.registerMouse(e)}}setTouchInputEnabled(e){var t;null===(t=this.touchController)||void 0===t||t.unregisterTouchEvents(),e&&(this.touchController=this.inputClassesFactory.registerTouch(this.config.isFlagEnabled(Et.FakeMouseWithTouches),this.videoElementParentClientRect))}setGamePadInputEnabled(e){var t;null===(t=this.gamePadController)||void 0===t||t.unregisterGamePadEvents(),e&&(this.gamePadController=this.inputClassesFactory.registerGamePad(),this.gamePadController.onGamepadConnected=()=>{this.streamMessageController.toStreamerHandlers.get("GamepadConnected")()},this.gamePadController.onGamepadDisconnected=e=>{this.streamMessageController.toStreamerHandlers.get("GamepadDisconnected")([e])})}registerDataChannelEventEmitters(e){e.onOpen=(e,t)=>this.pixelStreaming.dispatchEvent(new Ye({label:e,event:t})),e.onClose=(e,t)=>this.pixelStreaming.dispatchEvent(new Ze({label:e,event:t})),e.onError=(e,t)=>this.pixelStreaming.dispatchEvent(new et({label:e,event:t}))}registerMessageHandler(e,t,r){t===Qt.FromStreamer&&void 0===r&&n.Warning(n.GetStackTrace(),`Unable to register handler for ${e} as no handler was passed`),this.streamMessageController.registerMessageHandler(t,e,(n=>void 0===r&&t===Qt.ToStreamer?this.sendMessageController.sendMessageToStreamer(e,n):r(n)))}}class Fn{static vertexShader(){return"\n\t\tattribute vec2 a_position;\n\t\tattribute vec2 a_texCoord;\n\n\t\t// input\n\t\tuniform vec2 u_resolution;\n\t\tuniform vec4 u_offset;\n\n\t\t//\n\t\tvarying vec2 v_texCoord;\n\n\t\tvoid main() {\n\t\t // convert the rectangle from pixels to 0.0 to 1.0\n\t\t vec2 zeroToOne = a_position / u_resolution;\n\n\t\t // convert from 0->1 to 0->2\n\t\t vec2 zeroToTwo = zeroToOne * 2.0;\n\n\t\t // convert from 0->2 to -1->+1 (clipspace)\n\t\t vec2 clipSpace = zeroToTwo - 1.0;\n\n\t\t gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n\t\t // pass the texCoord to the fragment shader\n\t\t // The GPU will interpolate this value between points.\n\t\t v_texCoord = (a_texCoord * u_offset.xy) + u_offset.zw;\n\t\t}\n\t\t"}static fragmentShader(){return"\n\t\tprecision mediump float;\n\n\t\t// our texture\n\t\tuniform sampler2D u_image;\n\n\t\t// the texCoords passed in from the vertex shader.\n\t\tvarying vec2 v_texCoord;\n\n\t\tvoid main() {\n\t\t gl_FragColor = texture2D(u_image, v_texCoord);\n\t\t}\n\t\t"}}class In{static deepCopyGamepad(e){return JSON.parse(JSON.stringify({buttons:e.buttons.map((e=>JSON.parse(JSON.stringify({pressed:e.pressed,touched:e.touched})))),axes:e.axes}))}}class xn{constructor(e){this.toStreamerMessagesProvider=e,this.controllers=[]}updateStatus(e,t,n){if(e.gamepad){const r=t.getPose(e.gripSpace,n);if(!r)return;let s=0;e.profiles.includes("htc-vive")?s=1:e.profiles.includes("oculus-touch")&&(s=2),this.toStreamerMessagesProvider.toStreamerHandlers.get("XRSystem")([s]);let i=2;switch(e.handedness){case"left":i=0;break;case"right":i=1}const a=r.transform.matrix,o=[];for(let e=0;e<16;e++)o[e]=new Float32Array([a[e]])[0];this.toStreamerMessagesProvider.toStreamerHandlers.get("XRControllerTransform")([o[0],o[4],o[8],o[12],o[1],o[5],o[9],o[13],o[2],o[6],o[10],o[14],o[3],o[7],o[11],o[15],i]),void 0===this.controllers[i]&&(this.controllers[i]={prevState:void 0,currentState:void 0,id:void 0},this.controllers[i].prevState=In.deepCopyGamepad(e.gamepad)),this.controllers[i].currentState=In.deepCopyGamepad(e.gamepad);const l=this.controllers[i],c=l.currentState,d=l.prevState;for(let e=0;e<c.buttons.length;e++){const t=c.buttons[e],n=d.buttons[e];t.pressed?this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonPressed")([i,e,n.pressed?1:0]):!t.pressed&&n.pressed&&this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonReleased")([i,e,0]),t.touched&&!t.pressed?this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonPressed")([i,3,n.touched?1:0]):!t.touched&&n.touched&&this.toStreamerMessagesProvider.toStreamerHandlers.get("XRButtonReleased")([i,3,0])}for(let e=0;e<c.axes.length;e++)this.toStreamerMessagesProvider.toStreamerHandlers.get("XRAnalog")([i,e,c.axes[e]]);this.controllers[i].prevState=c}}}class On{constructor(e){this.xrSession=null,this.webRtcController=e,this.xrControllers=[],this.xrGamepadController=new xn(this.webRtcController.streamMessageController),this.onSessionEnded=new EventTarget,this.onSessionStarted=new EventTarget,this.onFrame=new EventTarget}xrClicked(){this.xrSession?this.xrSession.end():navigator.xr.requestSession("immersive-vr").then((e=>{this.onXrSessionStarted(e)}))}onXrSessionEnded(){n.Log(n.GetStackTrace(),"XR Session ended"),this.xrSession=null,this.onSessionEnded.dispatchEvent(new Event("xrSessionEnded"))}onXrSessionStarted(e){n.Log(n.GetStackTrace(),"XR Session started"),this.xrSession=e,this.xrSession.addEventListener("end",(()=>{this.onXrSessionEnded()}));const t=document.createElement("canvas");this.gl=t.getContext("webgl2",{xrCompatible:!0}),this.xrSession.updateRenderState({baseLayer:new XRWebGLLayer(this.xrSession,this.gl)});const r=this.gl.createShader(this.gl.VERTEX_SHADER);this.gl.shaderSource(r,Fn.vertexShader()),this.gl.compileShader(r);const s=this.gl.createShader(this.gl.FRAGMENT_SHADER);this.gl.shaderSource(s,Fn.fragmentShader()),this.gl.compileShader(s);const i=this.gl.createProgram();this.gl.attachShader(i,r),this.gl.attachShader(i,s),this.gl.linkProgram(i),this.gl.useProgram(i),this.positionLocation=this.gl.getAttribLocation(i,"a_position"),this.texcoordLocation=this.gl.getAttribLocation(i,"a_texCoord"),this.positionBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.positionLocation);const a=this.gl.createTexture();this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST),this.texcoordBuffer=this.gl.createBuffer(),this.resolutionLocation=this.gl.getUniformLocation(i,"u_resolution"),this.offsetLocation=this.gl.getUniformLocation(i,"u_offset"),e.requestReferenceSpace("local").then((e=>{this.xrRefSpace=e,this.xrSession.requestAnimationFrame(((e,t)=>this.onXrFrame(e,t)))})),this.onSessionStarted.dispatchEvent(new Event("xrSessionStarted"))}onXrFrame(e,t){const n=t.getViewerPose(this.xrRefSpace);if(n){const e=n.transform.matrix,t=[];for(let n=0;n<16;n++)t[n]=new Float32Array([e[n]])[0];this.webRtcController.streamMessageController.toStreamerHandlers.get("XRHMDTransform")([t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15]]);const r=this.xrSession.renderState.baseLayer;this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,r.framebuffer),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.webRtcController.videoPlayer.getVideoElement()),this.render(this.webRtcController.videoPlayer.getVideoElement())}this.webRtcController.config.isFlagEnabled(Et.XRControllerInput)&&this.xrSession.inputSources.forEach(((e,n,r)=>{this.xrGamepadController.updateStatus(e,t,this.xrRefSpace)}),this),this.xrSession.requestAnimationFrame(((e,t)=>this.onXrFrame(e,t))),this.onFrame.dispatchEvent(new Ct({time:e,frame:t}))}render(e){if(!this.gl)return;const t=this.xrSession.renderState.baseLayer;let n,r,s,i,a;this.gl.viewport(0,0,t.framebufferWidth,t.framebufferHeight),this.gl.uniform4f(this.offsetLocation,1,1,0,0),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,e.videoWidth,0,0,e.videoHeight,0,e.videoHeight,e.videoWidth,0,e.videoWidth,e.videoHeight]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.texcoordBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),n=2,r=this.gl.FLOAT,s=!1,i=0,a=0,this.gl.vertexAttribPointer(this.positionLocation,n,r,s,i,a),this.gl.enableVertexAttribArray(this.texcoordLocation),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.texcoordBuffer),n=2,r=this.gl.FLOAT,s=!1,i=0,a=0,this.gl.vertexAttribPointer(this.texcoordLocation,n,r,s,i,a),this.gl.uniform2f(this.resolutionLocation,e.videoWidth,e.videoHeight);const o=this.gl.TRIANGLES;a=0,this.gl.drawArrays(o,a,6)}static isSessionSupported(e){return navigator.xr?navigator.xr.isSessionSupported(e):new Promise((()=>!1))}}class Dn{constructor(e){this.editTextButton=null,this.hiddenInput=null,"ontouchstart"in document.documentElement&&this.createOnScreenKeyboardHelpers(e)}unquantizeAndDenormalizeUnsigned(e,t){return null}createOnScreenKeyboardHelpers(e){this.hiddenInput||(this.hiddenInput=document.createElement("input"),this.hiddenInput.id="hiddenInput",this.hiddenInput.maxLength=0,e.appendChild(this.hiddenInput)),this.editTextButton||(this.editTextButton=document.createElement("button"),this.editTextButton.id="editTextButton",this.editTextButton.innerHTML="edit text",e.appendChild(this.editTextButton),this.editTextButton.classList.add("hiddenState"),this.editTextButton.addEventListener("touchend",(e=>{this.hiddenInput.focus(),e.preventDefault()})))}showOnScreenKeyboard(e){if(e.showOnScreenKeyboard){this.editTextButton.classList.remove("hiddenState");const t=this.unquantizeAndDenormalizeUnsigned(e.x,e.y);this.editTextButton.style.top=t.y.toString()+"px",this.editTextButton.style.left=(t.x-40).toString()+"px"}else this.editTextButton.classList.add("hiddenState"),this.hiddenInput.blur()}}class An{constructor(e){this.seq=e.Seq,this.playerSentTimestamp=Date.now(),this.requestFillerSize=e.Filler?e.Filler.length:0}update(e){this.playerReceivedTimestamp=Date.now(),this.streamerReceivedTimestamp=e.ReceivedTimestamp,this.streamerSentTimestamp=e.SentTimestamp,this.responseFillerSize=e.Filler?e.Filler.length:0}}class Un{constructor(e,t){this.sink=e,this.callback=t,this.records=new Map,this.seq=0}start(e){return!this.isRunning()&&(this.startTime=Date.now(),this.records.clear(),this.interval=setInterval((()=>{Date.now()-this.startTime>=e.duration?this.stop():this.sendRequest(e.requestSize,e.responseSize)}).bind(this),Math.floor(1e3/e.rps)),!0)}stop(){this.interval&&(clearInterval(this.interval),this.interval=void 0,this.callback(this.produceResult()))}produceResult(){const e=new Map(this.records);return{records:e,dataChannelRtt:Math.ceil(Array.from(this.records.values()).reduce(((e,t)=>e+(t.playerReceivedTimestamp-t.playerSentTimestamp)),0)/this.records.size),playerToStreamerTime:Math.ceil(Array.from(this.records.values()).reduce(((e,t)=>e+(t.streamerReceivedTimestamp-t.playerSentTimestamp)),0)/this.records.size),streamerToPlayerTime:Math.ceil(Array.from(this.records.values()).reduce(((e,t)=>e+(t.playerReceivedTimestamp-t.streamerSentTimestamp)),0)/this.records.size),exportLatencyAsCSV:()=>{let t="Timestamp;RTT;PlayerToStreamer;StreamerToPlayer;\n";return e.forEach((e=>{t+=e.playerSentTimestamp+";",t+=e.playerReceivedTimestamp-e.playerSentTimestamp+";",t+=e.streamerReceivedTimestamp-e.playerSentTimestamp+";",t+=e.playerReceivedTimestamp-e.streamerSentTimestamp+";",t+="\n"})),t}}}isRunning(){return!!this.interval}receive(e){if(!this.isRunning())return;if(!e)return void n.Error(n.GetStackTrace(),"Undefined response from server");let t=this.records.get(e.Seq);t&&t.update(e)}sendRequest(e,t){let n=this.createRequest(e,t),r=new An(n);this.records.set(r.seq,r),this.sink(n)}createRequest(e,t){return{Seq:this.seq++,FillResponseSize:t,Filler:e?"A".repeat(e):""}}}class Nn{constructor(e,t){this.allowConsoleCommands=!1,this.config=e,(null==t?void 0:t.videoElementParent)&&(this._videoElementParent=t.videoElementParent),this._eventEmitter=new bt,this.configureSettings(),this.setWebRtcPlayerController(new Ln(this.config,this)),this.onScreenKeyboardHelper=new Dn(this.videoElementParent),this.onScreenKeyboardHelper.unquantizeAndDenormalizeUnsigned=(e,t)=>this._webRtcController.requestUnquantizedAndDenormalizeUnsigned(e,t),this._activateOnScreenKeyboard=e=>this.onScreenKeyboardHelper.showOnScreenKeyboard(e),this._webXrController=new On(this._webRtcController)}get videoElementParent(){return this._videoElementParent||(this._videoElementParent=document.createElement("div"),this._videoElementParent.id="videoElementParent"),this._videoElementParent}configureSettings(){this.config._addOnSettingChangedListener(Et.IsQualityController,(e=>{!0!==e||this._webRtcController.isQualityController||this._webRtcController.sendRequestQualityControlOwnership()})),this.config._addOnSettingChangedListener(Et.AFKDetection,(e=>{this._webRtcController.setAfkEnabled(e)})),this.config._addOnSettingChangedListener(Et.MatchViewportResolution,(()=>{this._webRtcController.videoPlayer.updateVideoStreamSize()})),this.config._addOnSettingChangedListener(Et.HoveringMouseMode,(e=>{this.config.setFlagLabel(Et.HoveringMouseMode,`Control Scheme: ${e?"Hovering":"Locked"} Mouse`),this._webRtcController.setMouseInputEnabled(this.config.isFlagEnabled(Et.MouseInput))})),this.config._addOnSettingChangedListener(Et.KeyboardInput,(e=>{this._webRtcController.setKeyboardInputEnabled(e)})),this.config._addOnSettingChangedListener(Et.MouseInput,(e=>{this._webRtcController.setMouseInputEnabled(e)})),this.config._addOnSettingChangedListener(Et.TouchInput,(e=>{this._webRtcController.setTouchInputEnabled(e)})),this.config._addOnSettingChangedListener(Et.GamepadInput,(e=>{this._webRtcController.setGamePadInputEnabled(e)})),this.config._addOnNumericSettingChangedListener(Mt.MinQP,(e=>{n.Log(n.GetStackTrace(),"-------- Sending MinQP --------",7),this._webRtcController.sendEncoderMinQP(e),n.Log(n.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(Mt.MaxQP,(e=>{n.Log(n.GetStackTrace(),"-------- Sending encoder settings --------",7),this._webRtcController.sendEncoderMaxQP(e),n.Log(n.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(Mt.WebRTCMinBitrate,(e=>{n.Log(n.GetStackTrace(),"-------- Sending web rtc settings --------",7),this._webRtcController.sendWebRTCMinBitrate(1e3*e),n.Log(n.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(Mt.WebRTCMaxBitrate,(e=>{n.Log(n.GetStackTrace(),"-------- Sending web rtc settings --------",7),this._webRtcController.sendWebRTCMaxBitrate(1e3*e),n.Log(n.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnNumericSettingChangedListener(Mt.WebRTCFPS,(e=>{n.Log(n.GetStackTrace(),"-------- Sending web rtc settings --------",7),this._webRtcController.sendWebRTCFps(e),n.Log(n.GetStackTrace(),"-------------------------------------------",7)})),this.config._addOnOptionSettingChangedListener(Ft.PreferredCodec,(e=>{this._webRtcController&&this._webRtcController.setPreferredCodec(e)})),this.config._registerOnChangeEvents(this._eventEmitter)}_activateOnScreenKeyboard(e){throw new Error("Method not implemented.")}_onInputControlOwnership(e){this._inputController=e}setWebRtcPlayerController(e){this._webRtcController=e,this._webRtcController.setPreferredCodec(this.config.getSettingOption(Ft.PreferredCodec).selected),this._webRtcController.resizePlayerStyle(),this.checkForAutoConnect()}connect(){this._eventEmitter.dispatchEvent(new rt),this._webRtcController.connectToSignallingServer()}reconnect(){this._eventEmitter.dispatchEvent(new it),this._webRtcController.tryReconnect("Reconnecting...")}disconnect(){this._eventEmitter.dispatchEvent(new st),this._webRtcController.close()}play(){this._onStreamLoading(),this._webRtcController.playStream()}checkForAutoConnect(){this.config.isFlagEnabled(Et.AutoConnect)&&(this._onWebRtcAutoConnect(),this._webRtcController.connectToSignallingServer())}unmuteMicrophone(e=!1){if(!this.config.isFlagEnabled("UseMic"))return e?(this.config.setFlagEnabled("UseMic",!0),void this.reconnect()):void n.Warning(n.GetStackTrace(),"Trying to unmute mic, but PixelStreaming was initialized with no microphone track. Call with forceEnable == true to re-connect with a mic track.");this.setMicrophoneMuted(!1)}muteMicrophone(){this.config.isFlagEnabled("UseMic")?this.setMicrophoneMuted(!0):n.Info(n.GetStackTrace(),"Trying to mute mic, but PixelStreaming has no microphone track, so sending sound is already disabled.")}setMicrophoneMuted(e){var t,n,r,s;for(const i of null!==(s=null===(r=null===(n=null===(t=this._webRtcController)||void 0===t?void 0:t.peerConnectionController)||void 0===n?void 0:n.peerConnection)||void 0===r?void 0:r.getTransceivers())&&void 0!==s?s:[])Kt.canTransceiverSendAudio(i)&&(i.sender.track.enabled=!e)}_onWebRtcAutoConnect(){this._eventEmitter.dispatchEvent(new je)}_onWebRtcSdp(){this._eventEmitter.dispatchEvent(new Ke)}_onStreamLoading(){this._eventEmitter.dispatchEvent(new nt)}_onDisconnect(e,t){this._eventEmitter.dispatchEvent(new Je({eventString:e,allowClickToReconnect:t}))}_onWebRtcConnecting(){this._eventEmitter.dispatchEvent(new Qe)}_onWebRtcConnected(){this._eventEmitter.dispatchEvent(new qe)}_onWebRtcFailed(){this._eventEmitter.dispatchEvent(new Xe)}_onVideoInitialized(){this._eventEmitter.dispatchEvent(new tt),this._videoStartTime=Date.now()}_onLatencyTestResult(e){this._eventEmitter.dispatchEvent(new mt({latencyTimings:e}))}_onDataChannelLatencyTestResponse(e){this._eventEmitter.dispatchEvent(new pt({response:e}))}_onVideoStats(e){this._videoStartTime&&void 0!==this._videoStartTime||(this._videoStartTime=Date.now()),e.handleSessionStatistics(this._videoStartTime,this._inputController,this._webRtcController.videoAvgQp),this._eventEmitter.dispatchEvent(new ht({aggregatedStats:e}))}_onVideoEncoderAvgQP(e){this._eventEmitter.dispatchEvent(new $e({avgQP:e}))}_onInitialSettings(e){var t;this._eventEmitter.dispatchEvent(new vt({settings:e})),e.PixelStreamingSettings&&(this.allowConsoleCommands=null!==(t=e.PixelStreamingSettings.AllowPixelStreamingCommands)&&void 0!==t&&t,!1===this.allowConsoleCommands&&n.Info(n.GetStackTrace(),"-AllowPixelStreamingCommands=false, sending arbitrary console commands from browser to UE is disabled."));const r=this.config.useUrlParams,s=new URLSearchParams(window.location.search);n.Info(n.GetStackTrace(),`using URL parameters ${r}`),e.EncoderSettings&&(this.config.setNumericSetting(Mt.MinQP,r&&s.has(Mt.MinQP)?Number.parseFloat(s.get(Mt.MinQP)):e.EncoderSettings.MinQP),this.config.setNumericSetting(Mt.MaxQP,r&&s.has(Mt.MaxQP)?Number.parseFloat(s.get(Mt.MaxQP)):e.EncoderSettings.MaxQP)),e.WebRTCSettings&&(this.config.setNumericSetting(Mt.WebRTCMinBitrate,r&&s.has(Mt.WebRTCMinBitrate)?Number.parseFloat(s.get(Mt.WebRTCMinBitrate)):e.WebRTCSettings.MinBitrate/1e3),this.config.setNumericSetting(Mt.WebRTCMaxBitrate,r&&s.has(Mt.WebRTCMaxBitrate)?Number.parseFloat(s.get(Mt.WebRTCMaxBitrate)):e.WebRTCSettings.MaxBitrate/1e3),this.config.setNumericSetting(Mt.WebRTCFPS,r&&s.has(Mt.WebRTCFPS)?Number.parseFloat(s.get(Mt.WebRTCFPS)):e.WebRTCSettings.FPS))}_onQualityControlOwnership(e){this.config.setFlagEnabled(Et.IsQualityController,e)}_onPlayerCount(e){this._eventEmitter.dispatchEvent(new Tt({count:e}))}requestLatencyTest(){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.sendLatencyTest(),!0)}requestDataChannelLatencyTest(e){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._dataChannelLatencyTestController||(this._dataChannelLatencyTestController=new Un(this._webRtcController.sendDataChannelLatencyTest.bind(this._webRtcController),(e=>{this._eventEmitter.dispatchEvent(new ft({result:e}))})),this.addEventListener("dataChannelLatencyTestResponse",(({data:{response:e}})=>{this._dataChannelLatencyTestController.receive(e)}))),this._dataChannelLatencyTestController.start(e))}requestShowFps(){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.sendShowFps(),!0)}requestIframe(){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.sendIframeRequest(),!0)}emitUIInteraction(e){return!!this._webRtcController.videoPlayer.isVideoReady()&&(this._webRtcController.emitUIInteraction(e),!0)}emitCommand(e){return!(!this._webRtcController.videoPlayer.isVideoReady()||!this.allowConsoleCommands&&"ConsoleCommand"in e||(this._webRtcController.emitCommand(e),0))}emitConsoleCommand(e){return!(!this.allowConsoleCommands||!this._webRtcController.videoPlayer.isVideoReady()||(this._webRtcController.emitConsoleCommand(e),0))}addResponseEventListener(e,t){this._webRtcController.responseController.addResponseEventListener(e,t)}removeResponseEventListener(e){this._webRtcController.responseController.removeResponseEventListener(e)}dispatchEvent(e){return this._eventEmitter.dispatchEvent(e)}addEventListener(e,t){this._eventEmitter.addEventListener(e,t)}removeEventListener(e,t){this._eventEmitter.removeEventListener(e,t)}toggleXR(){this.webXrController.xrClicked()}setSignallingUrlBuilder(e){this._webRtcController.signallingUrlBuilder=e}get signallingProtocol(){return this._webRtcController.protocol}get webXrController(){return this._webXrController}registerMessageHandler(e,t,r){t!==Qt.FromStreamer||void 0!==r?t===Qt.ToStreamer&&void 0===r?this._webRtcController.streamMessageController.registerMessageHandler(t,e,(t=>this._webRtcController.sendMessageController.sendMessageToStreamer(e,t))):this._webRtcController.streamMessageController.registerMessageHandler(t,e,(e=>r(e))):n.Warning(n.GetStackTrace(),`Unable to register an undefined handler for ${e}`)}get toStreamerHandlers(){return this._webRtcController.streamMessageController.toStreamerHandlers}isReconnecting(){return this._webRtcController.isReconnecting}}})(),s})()));
|