@zoom/meetingsdk
Version:
Zoom MeetingSDK-Web Client
1 lines • 488 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VB=t():e.VB=t()}(self,(()=>(()=>{var e={3143:(e,t,i)=>{"use strict";var r,n=i(6984),o=i.n(n);e=i.hmd(e),r=function(e,t){var i={createInstance:30,createInstanceResult:31,newVideoElement:32,removeVideoElement:33,updateVideoElement:34,newFrame:36,removeFrame:37,version:40,enumDevices:41,enumVideoDevice:42,createPeerConnection:43,createOffer:44,createAnswer:45,setLocalDescription:46,setRemoteDescription:47,addIceCandidate:48,addStream:49,getLocalStreams:50,getStats:51,removeStream:52,close:53,getUserMediaShim:54,mediaTrkStop:55,trackEnabled:56,newAudioElement:57,setSinkId:58,updateSrcObject:59,notifyAudio:60,mediaStreamClone:61,mediaTrackClone:62,getDisplayMediaShim:63,setDefaultSinkId:64,shimLogToWebSocket:65,insertDTMF:66,getReceivers:67,customClipRect:69,applyConstraints:70,getScreens:71,setScreenId:72,addTrack:74,removeTrack:75,senderCmd:76,createMediaStream:77,connectedStateChanged:78,updateObjectFit:79,transceiverCmd:300,dataChannelCmd:301,dataChannelEvent:302,videoEffectsAsyncRequest:305,getHWND:309,pcCmd:310,removeAudioElement:311},r={ERROR:0,WARN:1,INFO:2,DEBUG:3},n={RPF_ACTIVE:1,RPF_CODEPAYLOADTYPE:2,RPF_DTX:4,RPF_MAXBITRATE:8,RPF_MAXFRAMERATE:16,RPF_PTIME:32,RPF_RID:64,RPF_SCALE_RESOLUTION_DOWNBY:128},s="52406081",a="1.0.",c=(a+="@"===s[0]?"00000":s,{UNSUPPORTED:"unsupported",CHROME:"chrome",CHROMIUM_EDGE:"chromium_edge",ELECTRON:"electron"});const u="0";function d(e){setTimeout(e,0)}function h(e){if(!e||!e.ownerDocument)return 1;if((t=e.ownerDocument.defaultView)&&"function"==typeof t.getZoomFactor)return t.getZoomFactor(e);if(g&&g.zoomFactor)return g.zoomFactor;var{innerWidth:e,outerWidth:t}=t;if(0===e)return t;var i=document.body&&document.body.clientWidth?document.body.clientWidth:e;let r,n;return X==c.ELECTRON?r=Math.round((t-(e-i))/e*1e3)/1e3:X==c.CHROME||X==c.CHROMIUM_EDGE?(r=(t-8)/e*100,n=J(r),Math.round(n||r)/100):1}function l(e,t){var i;return e&&t?((i={left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}).left+=t.left,i.right+=t.left,i.top+=t.top,i.bottom+=t.top,i):e}function v(e,t){return e&&t?e.left==t.left&&e.top==t.top&&e.right==t.right&&e.bottom==t.bottom:e==t}function f(e){var t;B.multiwindow&&F?(t=Y(e))?z[t]?K.debug("ensureFrame skipped due to frame already registered."):G&&G.allowNullHandle&&t===u?K.debug("ensureFrame skipped due to allowNullHandle config."):(F.send({cmd:"newFrame",frame:t,browser:X,customClipRect:1},-1),z[t]=e):K.debug("ensureFrame skipped due to no frameWnd"):K.debug("ensureFrame skipped due to feature not enabled or no connection.")}var p,g,m=-1,_=-1,w=0,y=0,b=0,E=0,C=0,S=0,R=0,T={},x={},k={},I={},A={},N=window.navigator.mediaDevices.enumerateDevices,O=null,P={},L={},D={},M={},F=null,V=null,U=null,j=[],W=[],B={},H={},z={},q={},G={},$=[],X=0<navigator.userAgent.indexOf("Electron")?c.ELECTRON:0<navigator.userAgent.indexOf("Chrome")?0<navigator.userAgent.indexOf("Edg")?c.CHROMIUM_EDGE:c.CHROME:c.UNSUPPORTED,K={logLevel:r.DEBUG,websocketlogLevel:r.INFO,logToConsole:!1,updateLogLevel:function(e,t){K.logLevel=e,K.websocketlogLevel=t},error:function(e){K.log("ERROR",e),U&&"function"==typeof U.error&&U.error(e)},warn:function(e){K.log("WARN",e),U&&"function"==typeof U.warn&&U.warn(e)},info:function(e){K.log("INFO",e),U&&"function"==typeof U.info&&U.info(e)},debug:function(e){K.log("DEBUG",e),U&&"function"==typeof U.debug&&U.debug(e)},log:function(e,t){try{r[e]<=K.logLevel&&(K.logToConsole&&console&&("object"==typeof t?console.log(t):console.log(e+": "+t)),"string"==typeof t)&&r[e]<=K.websocketlogLevel&&F&&F.sendLogToWebSocket(t,e)}catch(e){}}},Y=function(e){return e},J=function(e){for(var t=[25,33,50,67,75,80,90,100,110,125,150,175,200,250,300,400,500],i=0;i<t.length;i++){var r=t[i],n=.05*r;if(Math.abs(r-e)<n)return r}};function Z(e,t,i){var r,n,o="_id#",s=e.indexOf(t);return-1==s?e+t+"1"+o+i:(r=e.substring(0,s),n=e.indexOf(o,s+t.length),e=Number(e.substring(s+t.length,n)),r+t+((e=isNaN(e)?0:e)+1)+o+i)}function Q(e){var t;void 0!==e&&void 0===B.constraintCapabilities&&e.deviceId&&e.deviceId.exact&&(t=e.deviceId.exact,e.deviceId=t)}function ee(e,t){function i(){return 1<=arguments.length&&"function"==typeof arguments[0]}function r(){return 2<=arguments.length&&"function"==typeof arguments[1]}function n(e,t,i,r){return new Promise((function(n,o){var s=new DOMException("createOffer cancelled","OperationError"),a=new DOMException("The RTCPeerConnection is closed","InvalidStateError"),c=e?n:i,u=e?o:r;F.send({cmd:"createOffer",options:t},d.id,(function(e){x[d.id]?void 0===e.error?(K.debug("createOffer done"),K.debug(e.desc),e.transceivers&&p(e.transceivers),c(e.desc)):u(s):u(a)}))}))}function o(e,t,i,r){return new Promise((function(n,o){var s=new DOMException("createAnswer cancelled","OperationError"),a=new DOMException("The RTCPeerConnection is closed","InvalidStateError"),c=e?n:i,u=e?o:r;F.send({cmd:"createAnswer",options:t},d.id,(function(e){x[d.id]?void 0===e.error?(K.debug("createAnswer done"),K.debug(e.desc),e.transceivers&&p(e.transceivers),c(e.desc)):u(s):u(a)}))}))}function s(e,t,i,r){return d._remoteDescription=t,new Promise((function(n,o){var s=new DOMException("setRemoteDescription cancelled","OperationError"),a=new DOMException("The RTCPeerConnection is closed","InvalidStateError"),c=e?n:i,u=e?o:r;F.send({cmd:"setRemoteDescription",desc:t},d.id,(function(e){x[d.id]?void 0===e.error?(e.transceivers&&p(e.transceivers,e.transceiversRemoved),c()):u(s):u(a)}))}))}function a(e,t,i,r){return d._localDescription=t,new Promise((function(n,o){var s=new DOMException("setLocalDescription cancelled","OperationError"),a=new DOMException("The RTCPeerConnection is closed","InvalidStateError"),c=e?n:i,u=e?o:r;F.send({cmd:"setLocalDescription",desc:t},d.id,(function(e){x[d.id]?void 0===e.error?(e.transceivers&&p(e.transceivers,e.transceiversRemoved),c()):u(s):u(a)}))}))}function c(e,t,i,r){return new Promise((function(n,o){var s=new DOMException("addIceCandidate cancelled","OperationError"),a=new DOMException("The RTCPeerConnection is closed","InvalidStateError"),c=e?n:i,u=e?o:r;F.send({cmd:"addIceCandidate",candidate:t},d.id,(function(e){x[d.id]?void 0===e.error?c():u(s):u(a)}))}))}function u(e,t){return new Promise((function(i,r){new DOMException("getStats cancelled","InvalidAccessError");var n=e?i:t;i={cmd:"getStats"},1==e&&(i.capability=4),F.send(i,d.id,(function(t){var i;"function"==typeof n&&(void 0===t.error&&void 0!==t.stats&&void 0!==x[d.id]?(1==e?i=pe(t.stats):(i=new te)._create(t.stats),n(i)):n({}))}))}))}var d=this,h={},l={},v={},f=!1,p=(this.id=++w,this._localStreams=[],this._remoteStreams=[],this._dataChannelMap={},this._dataChannelIdToShimIdMap={},this._iceConnectionState="new",e&&"unified-plan"===e.sdpSemantics&&(f=!0),this.isUnifiedPlan=function(){return f},Object.defineProperty(this,"iceConnectionState",{get:function(){return K.debug("get iceConnectionState:"+this._iceConnectionState),this._iceConnectionState},configurable:!0}),this._iceGatheringState="new",Object.defineProperty(this,"iceGatheringState",{get:function(){return K.debug("get iceGatheringState:"+this._iceGatheringState),this._iceGatheringState},configurable:!0}),this._signalingState="stable",Object.defineProperty(this,"signalingState",{get:function(){return K.debug("get signalingState:"+this._signalingState),this._signalingState},configurable:!0}),this._connectionState="new",B.connectionState&&Object.defineProperty(this,"connectionState",{get:function(){return K.debug("get connectionState:"+this._connectionState),this._connectionState},configurable:!0}),this._localDescription=null,Object.defineProperty(this,"localDescription",{get:function(){return K.debug("get localDescription:"+this._localDescription),this._localDescription},configurable:!0}),this._remoteDescription=null,Object.defineProperty(this,"remoteDescription",{get:function(){return K.debug("get remoteDescription:"+this._remoteDescription),this._remoteDescription},configurable:!0}),this.cleanUp=function(){var e,t;"complete"!==this._iceGatheringState&&(t={type:"icecandidate",candidate:null,target:this},this.onicecandidate&&this.onicecandidate(t),this._iceGatheringState="complete",e={type:"icegatheringstatechange",target:this},this.onicegatheringstatechange)&&this.onicegatheringstatechange(e),"disconnected"!=this._iceConnectionState&&(this._iceConnectionState="disconnected",t={type:"iceconnectionstatechange",target:this},this.oniceconnectionstatechange)&&this.oniceconnectionstatechange(t),this._localStreams=[],this._remoteStreams=[]},this.createOfferV0=function(e,t,i){n(0,i,e,t)},this.createOfferV1=function(){return i.apply(null,arguments)?this.createOfferV0.apply(this,arguments):n(1,arguments[0])},this.createAnswerV0=function(e,t,i){o(0,i,e,t)},this.createAnswerV1=function(){return i.apply(null,arguments)?this.createAnswerV0.apply(this,arguments):o(1,arguments[0])},this.setRemoteDescriptionV0=function(e,t,i){s(0,e,t,i)},this.setRemoteDescriptionV1=function(){return r.apply(null,arguments)?this.setRemoteDescriptionV0.apply(this,arguments):s(1,arguments[0])},this.setLocalDescriptionV0=function(e,t,i){a(0,e,t,i)},this.setLocalDescriptionV1=function(){return r.apply(null,arguments)?this.setLocalDescriptionV0.apply(this,arguments):a(1,arguments[0])},this.addIceCandidateV0=function(e,t,i){c(0,e,t,i)},this.addIceCandidateV1=function(){return r.apply(null,arguments)?this.addIceCandidateV0.apply(this,arugments):c(1,arguments[0])},this.createDTMFSender=function(e){var t;return"audio"!==e.kind?(K.error("DTMF only could be associated with audio track."),null):((t=new ie).initPlanB(d.id,e),A[e.id]=t)},this.getStatsV0=function(e){return u(0,e)},this.getStatsV1=function(){return i.apply(null,arguments)?this.getStatsV0.apply(this,arguments):u(1)},this.getLocalStreams=function(){return f?(K.warn("getLocalStreams is not supported in the unified plan, use getSenders()"),[]):(K.debug("getLocalStreams():"+this._localStreams.length),this._localStreams)},this.getRemoteStreams=function(){return f?(K.warn("getRemoteStreams is not supported in the unified plan, use getReceivers()"),[]):(K.debug("getRemoteStreams():"+this._remoteStreams.length),this._remoteStreams)},this.addStream=function(e){this._localStreams.push(e),F.send({cmd:"addStream",sid:e.id},d.id)},this.removeStream=function(e){K.debug("RTCPeerConnection.removeStream(): "+e.id);var t=this._localStreams.indexOf(e);-1!=t?this._localStreams.splice(t,1):K.error("RTCPeerConnection.removeStream(): Failed to find stream: "+e.id),F.send({cmd:"removeStream",sid:e.id},d.id)},this.addTrackImplV1=function(e,t){var i,r;if(e&&t)return f?((i=new oe(d)).initTrackOrKind(e),(r=(v[i.id]=i).sender).setTrack(e,t),F.send({cmd:"addTrack",transceiverId:i.id,tid:e.id,sid:t.id},d.id,(function(e){void 0===e.error?p(e.transceivers):delete v[i.id]}))):(r=l[e.id])?K.warn("RTCPeerConnection.addTrack: sender already exists."):((r=new _e(d)).initPlanB(e,t),l[r.id]=r,F.send({cmd:"addTrack",transceiverId:"",tid:e.id,sid:t.id},d.id,(function(e){void 0!==e.error&&delete l[r.id]}))),r;throw new Error("both media track and stream need to be provided")},this.removeTrackImplV1=function(e){e?void 0===e._cap?K.error("sender object doesn't have the capability bits"):e.id?(e.removeTrack(),f||delete l[e.id]):K.error("RTCPeerConnection.removeTrack: not a valid sender object"):K.error("RTCPeerConnection.removeTrack: invalid sender.")},this.getSendersImplV1=function(){K.debug("RTCPeerConnection.getSendersImplV1");var e=[];if(f)for(var t in v){var i=v[t].sender;i&&e.push(i)}else for(var t in l)l[t]&&e.push(l[t]);return e},this.getTranceiversImplV1=function(){K.debug("RTCPeerConnection.getTranceiversImplV1");var e,t=[];for(e in v)K.debug("RTCPeerConnection.getTranceiversImplV1 id="+e),t.push(v[e]);return t},this.addTransceiverImplV1=function(e,t){var i=new oe(d),r=(i.initTrackOrKind(e,t),v[i.id]=i,{cmd:"transceiverCmd",transceiverCmd:1,hint:"RTCRtpTransceiver.addTransceiver",transceiverId:i.id});if("audio"===e||"video"===e)r.trackOrKind=e;else{if(!(e instanceof fe))return K.error("addTranceiver: Unknown type"),null;K.debug("addTranceiver with track is not Implemented"),r.trackOrKind=e.id}if(e={},t.direction&&(e.direction=t.direction),t.sendEncodings&&(e.sendEncodings=t.sendEncodings),t.streams){for(var n in streamIds=[],t.streams)streamIds.push(n.id);e.streams=streamIds}return r.init=e,F.send(r,d.id,(function(e){void 0===e.error&&p(e.transceivers)})),i},this.createDataChannelImplV1=function(e,t){var i,r;return K.debug("RTCPeerConnection.createDataChannel: "+e+" option: "+JSON.stringify(this.options)),e?(i=++R,(r=new le(d.id,i))._createChannel(e,t),d._dataChannelMap[i]=r):(K.error("RTCPeerConnection.createDataChannel: missing label"),null)},this._untrackDataChannel=function(e,t){void 0!==t&&d._dataChannelMap[t]&&(K.debug("Untrack datachannel: "+e+" shimId: "+t),delete d._dataChannelMap[t]),e!=_&&d._dataChannelIdToShimIdMap[e]&&(K.debug("Remove mapped datachannel: "+e+" shimId:"+t),delete d._dataChannelIdToShimIdMap[e])},function(e,t){for(var i in e){var r,n=e[i],o=v[n.id];(o||(o=n.id,K.debug("_updateTransceivers: addTransceiver id="+o),(r=new oe(d)).initId(o),v[o]=r)).update(n)}if(t)for(var i in t){var s=t[i];K.debug("_updateTransceivers: removeTransceiver id="+s),delete v[s]}}),g=(this.close=function(){g=null,F.send({cmd:"close"},d.id,(function(e){delete x[d.id]}),!0)},null);this.getReceivers=function(){if(f){var e=[];if(v)for(var t in v){var i=v[t].receiver;i&&e.push(i)}}else for(t in g||(g={},F.send({cmd:"getReceivers"},d.id,(function(e){}),!0)),e=[],g)g[t]&&e.push(g[t]);return e},this.addEventListener=function(e,t){K.debug("RTCPeerConnection.addEventListener(): "+e),"function"!=typeof t?K.error("RTCPeerConnection.addEventListener(): The listener handler is invalid."):"string"!=typeof e?K.error("RTCPeerConnection.addEventListener(): The event name is invalid."):(void 0===h[e]&&(h[event]={listeners:[]}),h[e].listeners.push(t))},this.removeEventListener=function(e,t){K.debug("RTCPeerConnection.removeEventListener(): "+e),void 0===h[e]?K.error("RTCPeerConnection.removeEventListener(): Event does not exist = "+e):h[e].listeners=h[e].listeners.filter((function(e){return e.toString()!==t.toString()}))},this._onReceiveDataChannelEvent=function(e){var t;void 0===e.shimId?K.error("RTCPeerConnection._onReceiveDataChannelEvent: missing shimId"):((t=e.shimId)==_&&e.channel&&void 0!==e.channel.id&&(K.debug("Try to find mapped "+e.channel.id+" in:"+JSON.stringify(d._dataChannelIdToShimIdMap)),void 0!==d._dataChannelIdToShimIdMap[e.channel.id])&&(t=d._dataChannelIdToShimIdMap[e.channel.id],K.debug("RTCPeerConnection._onReceiveDataChannelEvent: use mapped shimId: "+t)),t!=_&&d._dataChannelMap[t]?d._dataChannelMap[t]._onReceiveEvent(e):K.error("RTCPeerConnection._onReceiveDataChannelEvent: dataChannle "+t+" not existed"))},this._onReceiveEvent=function(e){if(void 0===e||void 0===e.evt)K.error("_onReceiveEvent(): evt property is invalid.");else{var t={type:e.evt,target:this};switch(e.details&&this._updateVars(e.details),e.evt){case"connectionstatechange":this.onconnectionstatechange&&this.onconnectionstatechange(t);break;case"negotiationneeded":this.onnegotiationneeded&&this.onnegotiationneeded(t);break;case"icecandidate":t.candidate=e.candidate,this.onicecandidate&&this.onicecandidate(t);break;case"icegatheringstatechange":this.onicegatheringstatechange&&this.onicegatheringstatechange(t);break;case"iceconnectionstatechange":this.oniceconnectionstatechange&&this.oniceconnectionstatechange(t);break;case"signalingstatechange":this.onsignalingstatechange&&this.onsignalingstatechange(t);break;case"ondatachannel":e.channel?this.ondatachannel&&(n=++R,o=new le(d.id,n),void 0!==e.channel.id&&(K.debug("ondatachannel shimId: "+e.channel.id+" mapped to "+n),d._dataChannelIdToShimIdMap[e.channel.id]=n),(d._dataChannelMap[n]=o)._updateChannel(e.channel),t.channel=o,K.debug("ondatachannel shimId: "+n+" channel:"+JSON.stringify(e.channel)),this.ondatachannel(t)):K.warn("ondatachannel from legacy client");break;case"addStream":void 0===e.stream?K.debug("_onReceiveEvent(): stream property is invalid."):(t.stream=new ve,t.stream._create(e.stream,e.peer),this._remoteStreams.push(t.stream),this.onaddstream&&this.onaddstream(t));break;case"removeStream":void 0===e.stream?K.debug("_onReceiveEvent(): stream property is invalid."):(t.stream=I[e.stream],void 0===t.stream?K.debug("_onReceiveEvent(): no stream found."):(-1!=(o=this._remoteStreams.indexOf(t.stream))&&(e.trackId&&t.stream.removeTrackById(e.trackId),this._remoteStreams.splice(o,1)),this.onremovestream&&this.onremovestream(t)));break;case"ontrack":void 0===e.transceiver||void 0===e.stream?K.error("_onReceiveEvent ontrack property is invalid"):(i=e.transceiver.id,(r=v[i])||(K.debug("ontrack: add transceiver id="+i),(r=new oe(d)).initId(i),v[i]=r),r.update(e.transceiver),(n=new ve)._create(e.stream,e.peer),this._remoteStreams.push(n),t.transceiver=r,t.receiver=r.receiver,t.streams=[n],t.track=n.track[0],this.ontrack&&this.ontrack(t));break;case"tonechange":var i,r,n,o=null;(o=f?(i=e.transceiverId,(n=(r=v?v[i]:null)?r.sender:null)?n.dtmf:null):A[e.tid])?o.ontonechange&&o.ontonechange(e):K.debug("_onReceiveEvent(): tonechange, dtmfId is invalid or not found.");break;case"onreceivers":(i=e.receivers)&&i.forEach((function(e){var t,i;e.id&&(t=e.id,"-"===e.op?delete g[t]:("+"===e.op&&delete g[t],(i=g[t])||(i=new me,g[t]=i),i.update(e)))}));break;case"onsenders":(r=e.senders)&&r.forEach((function(e){var t=l[e.id];t&&t.update(e)}));break;case"ontransceivers":p(e.transceivers)}}},this._updateVars=function(e){e.iceConnectionState&&(this._iceConnectionState=e.iceConnectionState),e.iceGatheringState&&(this._iceGatheringState=e.iceGatheringState),e.signalingState&&(this._signalingState=e.signalingState),e.connectionState&&(this._connectionState=e.connectionState),e.localDescription&&(this._localDescription=e.localDescription),e.remoteDescription&&(this._remoteDescription=e.remoteDescription)},this.setConfigurationImpl=function(e){F.send({cmd:"pcCmd",pcCmdId:1,hint:"peerConnection.setConfiguration",config:e},d.id,(function(e){null==e.error&&e.configuration}))},this.restartIceImpl=function(){F.send({cmd:"pcCmd",pcCmdId:2,hint:"peerConnection.restartIce"},d.id)}}function te(){this.reports=[],this.result=function(){return this.reports},this._create=function(e){var t=this;e.forEach((function(e){var i=new ge;i._create(e),t.reports.push(i)}))}}function ie(){this.canInsertDTMF=!0;var e=void 0,t=null,i="",r=null,n=null;this.initPlanB=function(i,r){e=i,t=r},this.initUnifiedPlan=function(i,o,s,a){o&&s?(e=i,t=a,r=o,n=s):K.error("RTCDTMFSender.initUnifiedPlan: invalid transceiver or sender")},Object.defineProperty(this,"toneBuffer",{get:function(){return K.debug("get DTMF tone buffer"+i),i},set:function(e){void 0===e&&K.warn("Set RTCDTMFSender.toneBuffer to undefined."),K.debug("set DTMF tone buffer"+e),i=e},configurable:!0}),this.insertDTMF=function(i,o,s){K.debug("insertDTMF audio tones: "+i),void 0===o&&(K.debug("Duration is not set, use default"),o=100),void 0===s&&(K.debug("Gap is not set, use default"),s=70),F.send({cmd:"insertDTMF",transceiverId:r?r.id:"",senderId:n?n.id:"",tid:t.id,tones:i,duration:o,gap:s},e)}}function re(e){if(K.info("RTCRtpReceiverGetCapabilitiesImpl: "+e),q.receiver&&q.receiver[e])return q.receiver[e]}function ne(e){if(q.sender&&q.sender[e])return q.sender[e]}function oe(e){function t(e){K.info(e+"("+i+")")}var i,r=this,n=e,o="inactive",s="inactive",a=null,c=!1,u=null,d=null,h=(this.initId=function(e){i=e,(u=new _e(n)).initUnifiedPlan(r,null),d=new me,h(d)},this.initTrackOrKind=function(e,t){var o="";"audio"===(e=e instanceof fe?e.kind:e)?o="A":"video"===e&&(o="V"),i="Transceiver#"+o+S.toString(),S++,(u=new _e(n)).initUnifiedPlan(r,t),d=new me,h(d),t&&t.direction&&(s=t.direction),t&&t.stream&&K.debug("RTCRtpTransceiver.init with stream is not implemented.")},function(e){B.receiverGetStats&&(e.getStats=function(){return new Promise((function(e,t){F.send({cmd:"transceiverCmd",transceiverCmd:5,hint:"RTCRtpTransceiver.receiverGetStats",transceiverId:i},n.id,(function(i){var r;void 0===i.error?(r=i.stats,e(pe(r))):(r=i.error&&i.error.message?i.error.message:"Invalid receiver.getStats response",t(new DOMException(r,"OperationError")))}))}))})});this.update=function(e){e.currentDirection&&(o=e.currentDirection),e.direction&&(s=e.direction),e.mid&&(a=e.mid),void 0!==e.stopped&&(c=e.stopped),e.sender&&u&&u.update(e.sender),e.receiver&&d&&d.update(e.receiver)},Object.defineProperty(this,"id",{get:function(){return i},configurable:!0}),Object.defineProperty(this,"mid",{get:function(){return t("RTCRtpTransceiver.mid="+a),a}}),Object.defineProperty(this,"currentDirection",{get:function(){return t("RTCRtpTransceiver.currentDirection"),o},configurable:!0}),Object.defineProperty(this,"direction",{get:function(){return t("RTCRtpTransceiver.direction="+s),s},set:function(e){t("RTCRtpTransceiver.direction setter"),s=e,e={cmd:"transceiverCmd",transceiverCmd:4,hint:"RTCRtpTransceiver.direction",transceiverId:i,value:e},F.send(e,n.id)},configurable:!0}),Object.defineProperty(this,"receiver",{get:function(){return t("RTCRtpTransceiver.receiver"),d},configurable:!0}),Object.defineProperty(this,"sender",{get:function(){return t("RTCRtpTransceiver.sender"),u},configurable:!0}),Object.defineProperty(this,"stopped",{get:function(){return t("RTCRtpTransceiver stopped"),c},set:function(e){t("RTCRtpTransceiver stopped setter"),c=e},configurable:!0}),this.setCodecPreferences=function(e){t("RTCRtpTransceiver setCodecPreferences"),F.send({cmd:"transceiverCmd",transceiverCmd:2,hint:"RTCRtpTransceiver.setCodecPreference",transceiverId:i,codecs:e},n.id,(function(e){void 0!==e.error&&t("RTCRtpTransceiver.setCodecPreferences failed.")}))},this.stop=function(){t("RTCRtpTransceiver stop"),F.send({cmd:"transceiverCmd",transceiverCmd:3,hint:"RTCRtpTransceiver.stop",transceiverId:i},n.id,(function(e){void 0!==e.error&&t("RTCRtpTransceiver.stop failed.")}))}}function se(e,t){var i=this,r=t,n=!1;this._srcObject=e.srcObject,this._id=b++,this._rawAudio=e,this.sendAudioElement=function(){var t={cmd:"newAudioElement",audioId:this._id};e.setAttribute("data-vdi_audioid",this._id),F.send(t,-1)},Object.defineProperty(e,"srcObject",{get:function(){return i._srcObject},set:function(e){n?K.error("srcObject: audioElement is disposed."):(void 0===e&&K.warn("Set audio.srcObject to undefined."),K.debug("Setting srcObject for audio element: "+i._id),K.debug(e),i._srcObject=void 0===e?null:e,i.sendSrcObject())},configurable:!0}),this.sendSrcObject=function(){var e=this._srcObject?this._srcObject.id:"null",t=this._srcObject?this._srcObject.peer:m;F.send({cmd:"updateSrcObject",mediaStreamId:e,audioId:this._id,type:"audio",streamPeer:t},-1)},Object.defineProperty(e,"sinkId",{get:function(){return i._sinkId},set:function(e){},configurable:!0}),e.setSinkId=function(e){return n?(K.error("setSinkId: audioElement is disposed."),Promise.reject(new Error("setSinkId: audioElement is disposed."))):(i._sinkId=e,K.debug("Audio.setSinkId for ID = "+i._id+" Value = "+e),0===(void 0!==B.setSinkId?B.setSinkId:0)?new Promise((function(t,r){F.send({cmd:"setSinkId",deviceId:e,audioId:i._id,context:"audioElement"},-1),t()})):new Promise((function(t,r){F.send({cmd:"setSinkId",deviceId:e,audioId:i._id,context:"audioElement"},-1,(function(e){void 0===e.error?t():r(e.error)}))})))},e.play=function(){return Promise.resolve()},this.init=function(){f(r),this.sendAudioElement(),this._srcObject&&(K.debug("srcObject already set for audio: "+this._id),this.sendSrcObject()),K.debug(e)},this.removeAudioElement=function(){this._rawAudio&&(this._rawAudio.srcObject=null),this._srcObject&&(this._srcObject=null);var e={cmd:"removeAudioElement",audioId:this._id};F.send(e,-1),n=!0,K.debug("RemoveAudioElement: "+this._id)},this.init()}function ae(e,t){var i=this,r=t,n=Y(t),o=!1,s=(this._srcObject=e.srcObject,this._videoWidth=e.videoWidth,this._videoHeight=e.videoHeight,this._cloaked=!1,this._id=y++,this._clientRect=null,this._bodyClientRect=null,this._boundingFrame=void 0,this._colorKey=null,this._rawVideo=e,this._removeTimer=null,this._removed=!1,this._objectFit=e.style.objectFit,this._transform,this._dpiServerTranslate=!!B.multiwindow&&!!(2&B.multiwindow),this._styleObserver=new MutationObserver((function(t){t.forEach((function(t){i.handleStyleChanges(t,e)}))})),function(e){return(e=Number(e).toString(16)).length<2?"0"+e:e});this.sendVideoElement=function(){this._colorKey=function(){for(var e="";""==e;){var t,i=Math.floor(16*Math.random())+1,r=Math.floor(16*Math.random())+1,n=Math.floor(16*Math.random())+1,o=(e="#"+s(i)+s(r)+s(n),Object.keys(P));for(t in o){var a=P[o[t]];if(a&&a._colorKey==e){e="";break}}}return e}();var t={cmd:"newVideoElement",videoId:this._id,colorKey:this._colorKey,requestDpiTranslate:this._dpiServerTranslate?1:0,body:{},boundingFrame:this._boundingFrame,zoomFactor:h(this._rawVideo)},i=(n&&(t.frame=n),l(this._clientRect,this._boundingFrame));for(r in i)t[r]=i[r];var r,o=l(this._bodyClientRect,this._boundingFrame);for(r in o)t.body[r]=o[r];""!==this._objectFit&&(t.objectFit=this._objectFit),e.setAttribute("data-vdi_videoid",this._id),e.setAttribute("data-vmw_videoid",this._id),F.send(t,-1)},this.updateVideoElement=function(){var t=this.getBoundingClientRect(e),i=(this._cloaked||(t.right=t.left,t.bottom=t.top),this.getBoundingClientRect(document.body)),r=g;if(v(t,this._clientRect)&&v(i,this._bodyClientRect)&&v(r,this._boundingFrame))return!1;this._clientRect=t,this._bodyClientRect=i,this._boundingFrame=r?Object.assign({},r):void 0;var o,s={cmd:"updateVideoElement",videoId:this._id,requestDpiTranslate:this._dpiServerTranslate?1:0,transform:e.style.transform,body:{},boundingFrame:this._boundingFrame};for(o in n&&(s.frame=n),t=l(t,r),i=l(i,r),t)s[o]=t[o];for(o in i)s.body[o]=i[o];""!==this._objectFit&&(s.objectFit=this._objectFit),s.zoomFactor=h(this._rawVideo),K.debug(s),F.send(s,-1)},this.removeVideoElement=function(){var e={cmd:"removeVideoElement",videoId:i._id};n&&(e.frame=n),K.debug("RemoveVideoElement: "+i._id),F.send(e,-1),delete P[i._id],i._removeTimer=null,i._removed=!0},this.disposeVideo=function(){o=!0},this.cloak=function(){!0!==this._cloaked&&(this._colorKey?(e.style.backgroundColor=this._colorKey,this._styleObserver.observe(e,{attributes:!0,attributeFilter:["style"]}),this._cloaked=!0,this._poll=setInterval((function(){i.updateVideoElement()}),500)):K.error("cloak(): Invalid color key."))},this.uncloak=function(){if(!1===this._cloaked)return!1;e.style.backgroundColor="",this._styleObserver.disconnect(),clearInterval(this._poll),this._cloaked=!1,this.updateVideoElement()},this.getBoundingClientRect=function(e){e=e.getBoundingClientRect();var t=1;return this._dpiServerTranslate||"number"!=typeof window.devicePixelRatio||(t=window.devicePixelRatio),{left:e.left*t,top:e.top*t,bottom:e.bottom*t,right:e.right*t,width:e.width*t,height:e.height*t}},this.onReceiveEvent=function(e){var t;void 0===e||void 0===e.evt?K.error("onReceiveEvent(): evt property is invalid."):this._rawVideo?"loadedmetadata"===e.evt&&(""==this._objectFit&&""!==(t=window.getComputedStyle(this._rawVideo).objectFit)&&(K.debug("onReceiveEvent(): updating objectfit to "+t),this._objectFit=t,this.sendObjectFit()),void 0!==e.videoWidth&&(this._videoWidth=e.videoWidth),void 0!==e.videoHeight&&(this._videoHeight=e.videoHeight),t=new Event(e.evt),this._rawVideo.dispatchEvent(t)):K.error("onReceiveEvent(): Invalid rawVideo object.")},this.sendSrcObject=function(){var e=this._srcObject?this._srcObject.id:"null",t=this._srcObject?this._srcObject.peer:m,i=""!==(i=window.getComputedStyle(this._rawVideo).zIndex)&&"auto"!==i?parseInt(i,10):void 0;F.send({cmd:"updateSrcObject",mediaStreamId:e,videoId:this._id,type:"video",streamPeer:t,layer:i},-1),this._srcObject?this.cloak():this.uncloak()},this.sendObjectFit=function(){F.send({cmd:"updateObjectFit",videoId:this._id,objectFit:this._objectFit},-1)},Object.defineProperty(e,"srcObject",{get:function(){return i._srcObject},set:function(e){i._removed?K.warn("Setting srcObject of zombie video element: "+i._id):(i._removeTimer&&(clearTimeout(i._removeTimer),i._removeTimer=null),void 0===e&&K.warn("Set video.srcObject to undefined."),K.debug("Setting srcObject for video element: "+i._id),K.debug(e),i._srcObject=e,i.sendSrcObject(),i._srcObject||(o?i.removeVideoElement():(K.debug("srcObject is null, setup removeTimer for "+i._id),i._removeTimer=setTimeout(i.removeVideoElement,5e3))))},configurable:!0}),Object.defineProperty(e,"videoWidth",{get:function(){return i._videoWidth},configurable:!0}),Object.defineProperty(e,"videoHeight",{get:function(){return i._videoHeight},configurable:!0}),Object.defineProperty(e.style,"objectFit",{get:function(){return console.log("keyword defineProperty get objectFit "+i._objectFit),i._objectFit},set:function(e){console.log("keyword defineProperty set objectFit "+e),i._objectFit=e,i.sendObjectFit()},configurable:!0}),ae.prototype.handleStyleChanges=function(e,t){"attributes"===e.type&&"style"===e.attributeName&&(K.debug("video style change in id = "+this._id+", object-fit = "+t.style.objectFit),K.debug(t),this._objectFit!==t.style.objectFit&&(K.debug("change in object-fit. Old = "+this._objectFit+", new = "+t.style.objectFit),this._objectFit=t.style.objectFit,this.sendObjectFit()),this._transform!=t.style.transform)&&(this._transform=t.style.transform,this.updateVideoElement())},this.init=function(){this._clientRect=this.getBoundingClientRect(e),this._bodyClientRect=this.getBoundingClientRect(document.body),this._boundingFrame=g?Object.assign({},g):void 0,f(r),this.sendVideoElement(),this._srcObject&&(K.debug("srcObject already set for video: "+this._id),this.sendSrcObject()),K.debug(e)},this.init()}function ce(e){"function"==typeof O?(K.info("onVMEvent(): Fire event = "+JSON.stringify(e)),O(e)):K.warn("onVMEvent(): setVMEventCallback is not called yet.")}function ue(){var e=null,t=null,i=0,r=null,n=0,s="",a="",c="",u=(this.processEffectRequest=function(o,c){return new Promise((function(p,g){if("EnableEffects"===c.type){if(!c.request||!c.request.effects||!Array.isArray(c.request.effects)||0==c.request.effects.length)return K.debug("sendMessageDeviceVideoEffectsAsync(): rejecting incomplete request message"),void g({type:"Error",code:2});var m=c.request.effects[0];if("BackgroundModification"===m.type&&!m.options)return K.debug("sendMessageDeviceVideoEffectsAsync(): rejecting incomplete request message"),void g({type:"Error",code:2});var _=m.options;if("Replacement"===_.variant)return _.location?void h(_.location).then((function(){return u()})).then((function(){return d()})).then((function(){return K.debug("sendMessageDeviceVideoEffectsAsync(): sending smaller JPEG for hash "+s),c.image=a,c.hash=s,l(o,c)})).then((function(e){v(),p(e)})).catch((function(e){switch(K.debug("sendMessageDeviceVideoEffectsAsync(): internal promise chain failed with code "+e.errCode),e.errCode){case f.HASH_SAME:K.debug("sendMessageDeviceVideoEffectsAsync(): promise chain same hash error"),p({type:"EnableEffects",code:0,response:{effects:[m]}});break;case f.CLIENT_ERROR:K.debug("sendMessageDeviceVideoEffectsAsync(): promise chain client error"),g(e.errObj);break;default:K.debug("sendMessageDeviceVideoEffectsAsync(): promise chain unknown error"),g({type:"Error",code:4})}})).finally((function(){r=t=e=null,n=i=0,a=s=""})):(K.debug("sendMessageDeviceVideoEffectsAsync(): rejecting incomplete request message"),void g({type:"Error",code:2}))}l(o,c).then((function(e){p(e)})).catch((function(e){g(e.errObj)}))}))},this.cleanup=function(){c=""},function(){return new Promise((function(e,i){t?window.crypto.subtle.digest("SHA-256",t).then((function(t){r=Array.from(new Uint8Array(t)),n=r.length,s=r.map((function(e){return e.toString(16).padStart(2,"0")})).join(""),K.debug("sendMessageDeviceVideoEffectsAsync(): got current image hash "+s),s==c?(K.debug("sendMessageDeviceVideoEffectsAsync(): discarding replacement request for same hash as last ("+s+")"),i({errCode:f.HASH_SAME,errObj:null})):e()})).catch((function(){K.error("sendMessageDeviceVideoEffectsAsync(): Could not get hash for current image"),i({errCode:f.HASH_FAILED,errObj:null})})):i({errCode:f.GENERIC_ERROR,errObj:null})}))}),d=function(){return new Promise((function(e,i){var r;t?((r=new window.Image).onload=function(){K.debug("sendMessageDeviceVideoEffectsAsync(): creating canvas from original size "+r.width+", "+r.height);var t=document.createElement("canvas");t.width=p,t.height=t.width*(r.height/r.width),t.getContext("2d").drawImage(r,0,0,t.width,t.height),a=(a=t.toDataURL("image/jpeg")).replace(/^data:image\/(jpeg);base64,/,""),K.debug("sendMessageDeviceVideoEffectsAsync(): created smaller jpeg of base64 length "+a.length+", hash "+s),e()},r.onerror=function(){K.error("sendMessageDeviceVideoEffectsAsync(): Could not load image object"),i({errCode:f.IMGLOAD_FAILED,errObj:null})},r.src=o().createObjectURL(new Blob([t]))):i({errCode:f.GENERIC_ERROR,errObj:null})}))},h=function(r){return new Promise((function(n,o){K.debug("sendMessageDeviceVideoEffectsAsync(): attempting to fetch image from "+r),(e=new XMLHttpRequest).open("GET",r,!0),e.responseType="arraybuffer",e.onreadystatechange=function(){e.readyState==XMLHttpRequest.DONE&&(200!=e.status?(K.error("sendMessageDeviceVideoEffectsAsync(): Could not download image from "+r),o({errCode:f.XHR_FAILED,errObj:null})):(t=new Uint8Array(e.response),i=e.response.byteLength,K.debug("sendMessageDeviceVideoEffectsAsync(): Got image from "+r+" with byte size "+i),n()))},e.onerror=function(){K.error("sendMessageDeviceVideoEffectsAsync(): Could not download image from "+r),o({errCode:f.XHR_FAILED,errObj:null})},e.send()}))},l=function(e,t){return new Promise((function(i,r){F.send({cmd:"videoEffectsAsyncRequest",device:e,request:t},-1,(function(e){void 0===e.error?(K.debug("sendMessageDeviceVideoEffectsAsync(): response = "+JSON.stringify(e.videoEffects)),c=e.lastHash,i(e.videoEffects)):r({errCode:f.CLIENT_ERROR,errObj:e.error})}))}))},v=function(){var e,o,a;t&&r&&i&&n?(e=BINARY_DATA_HEADER_LEN+n+i,o=F.makeBinaryHeader(1447314758,e,n),(a=new Uint8Array(e)).set(o,0),a.set(r,BINARY_DATA_HEADER_LEN),a.set(t,BINARY_DATA_HEADER_LEN+n),F.sendBinary(a),K.debug("sendMessageDeviceVideoEffectsAsync(): Sent full image with hash - "+s+", total length "+e)):K.error("sendMessageDeviceVideoEffectsAsync(): Incomplete state information to send full image")},f={XHR_FAILED:0,IMGLOAD_FAILED:1,HASH_FAILED:2,GENERIC_ERROR:3,HASH_SAME:4,CLIENT_ERROR:5},p=128}function de(){const e=-1;var t=this,n=null,o=0,s={},h=0,l=null,v=!1,f=void 0,g=e,m=e,_=!0,w=(Object.defineProperty(this,"state",{get:function(){return o},configurable:!0}),Object.defineProperty(this,"shortPollingIntervalMs",{get:function(){return 500}}),Object.defineProperty(this,"shortPollingTimeout",{get:function(){return 1e4}}),Object.defineProperty(this,"longPollingIntervalMs",{get:function(){return 5e3}}),Object.defineProperty(this,"isHorizonRegistryPresent",{get:function(){return v},set:function(e){v=e},configurable:!0}),Object.defineProperty(this,"sendVdiClientEventsOnError",{get:function(){return _},set:function(e){_=e},configurable:!0}),this.sendLogToWebSocket=function(e,t){return"string"==typeof e&&0!==e.length&&2===o&&(T({cmd:"shimLogToWebSocket",message:e,level:t},-1),!0)},this.isSocketConnected=function(){return 2===o},this.isSocketOpen=function(){return!!n&&n.readyState===WebSocket.OPEN},this.init=function(t){K.info("RequestManager.init(): Initializing Request Manager."),w(),m!==e?K.error("RequestManager.init(): webrtc stack is still in use."):(m=++g,this.startPolling(500,1e4,this.sendEvents))},this.deinit=function(){K.info("RequestManager.deinit(): stop RequestManager."),w()},function(){var i;m!==e&&(K.info("RequestManager._deinit(): close stack ".concat(m,".")),i=m,m=e,t.stopPolling(),O("RequestManager._deinit(): cleanup stack ".concat(i,".")))}),y=(this.connectedStateChanged=function(i){m===e?K.error("RequestManager.connectedStateChanged: webrtc stack is not in use."):(K.info("RequestManager.connectedStateChanged called "+i),2===t.state&&t.send({cmd:"connectedStateChanged",connectionState:!0===i?1:0},-1),!0===i?(t.sendVdiClientEventsOnError=!0,t.startPolling(500,1e4,t.sendEvents)):(t.sendVdiClientEventsOnError=!1,t.isHorizonRegistryPresent=!1,K.info("RequestManager.connectedStateChanged(): isHorizonRegistryPresent false"),t.stopPolling()))},this.startPolling=function(i,r,n){var s;m===e?K.error("RequestManager.startPolling(): webrtc stack is not in use."):(K.info("RequestManager.startPolling(): stop the old polling timer(if there is any) and start a new one"),t.stopPolling(),0!==o?K.info("RequestManager.startPolling(): Socket state not disconnected, exiting"):(s=r,K.info("intervalMs "+i+" timeout "+r),l=setInterval((function(){K.info("RequestManager: connectToHorizon"),t.connectToHorizon(),void 0!==s&&(s-=i,v||t.queryHorizonRegistry()),void 0!==s&&s<=0&&(t.stopPolling(),n)&&!0===v&&n()}),i)))},this.stopPolling=function(){K.info("RequestManager.stopPolling()"),null!==l&&(clearInterval(l),l=null,K.info("Stopped polling websocket"))},this.sendEvents=function(){if(m===e)K.error("RequestManager.sendEvents(): webrtc stack is not in use.");else{var t=((t={}).shimVersion=a,{event:"vdiClientConnected",version:t});if(!G||!G.simpleDisconnectOnError)try{ce(t)}catch(t){K.warn("Catch exception in onVMEvent()"+JSON.stringify(t))}try{ce({event:"vdiClientDisconnected",reason:"endpointUnsupported"})}catch(t){K.warn("Catch exception in onVMEvent()"+JSON.stringify(t))}F.startPolling(5e3)}},this.queryHorizonRegistry=function(){window.getHorizonClientID().then((function(e){K.info("queryHorizonRegistry(): Horizon Client ID "+e),e&&F&&(F.isHorizonRegistryPresent=!0,K.info("queryHorizonRegistry(): isHorizonRegistryPresent true"))}),(function(){return K.error("queryHorizonRegistry(): Failed to query Horizon Client ID"),!1}))},this.connectToHorizon=function(){m===e?K.error("RequestManager.connectToHorizon(): webrtc stack is not in use."):0===o&&window.getHorizonWSSPort().then((function(e){"string"!=typeof e||0===e.length?(K.error("connectToHorizon(): Port is not valid"),O("Horizon HTML5 Server port not valid")):(K.info("connectToHorizon(): port is "+e),o=1,(n=new WebSocket("wss://view-localhost:"+e+"/")).binaryType="arraybuffer",n.onopen=E,n.onclose=C,n.onerror=S,n.onmessage=R)}),(function(){K.error("connectToHorizon(): Failed to receive port number"),O("Failed to receive port number")}))},function(){return new Promise((function(e,t){X===c.ELECTRON?(K.error("getWindowHandleByTitle: function called on unsupported browser"),t("function called on unsupported browser")):f=setInterval((function(){b(e,t,f)}),500)}))}),b=function(e,i,r){var n="function"==typeof window.getHorizonWindowTitle?window.getHorizonWindowTitle():document.title;void 0===n?K.error("getWindowHandleByTitle:: cannot find the window with undefined title"):t.send({cmd:"getHWND",title:n},-1,(function(t){void 0===t.error&&void 0!==t.hwnd&&t.hwnd!=u?(K.debug("getWindowHandleByTitle: received window handle"+t.hwnd),clearInterval(r),f=void 0,e(t.hwnd)):K.error("getWindowHandleByTitle:: cannot find the window that matches the title"+t.error)}))},E=function(){var i;K.info("onWebSocketOpen(): Websocket opened"),m===e?K.error("RequestManager.onWebSocketOpen(): webrtc stack is not in use."):(F.stopPolling(),i="function"==typeof window.getHorizonWindowTitle?window.getHorizonWindowTitle():document.title,T({cmd:"createInstance",hwnd:D.hwnd,shimVersion:a,shimMinAgentVersion:1,customClipRect:1,allowFeatureChange:1,supportObjectFit:1,supportE911:0,receiverGetStats:1,senderGetStats:1,allowNullHandle:G&&G.allowNullHandle?1:0,streamBundleWithPeer:1,sdkConfig:G||{},appName:p,appType:2,title:i,browser:X},-1,(function(e){if(0!=o){e.uid&&K.info("onWebSocketOpen(): ["+e.uid+"] createInstanceDone"),"true"===e.traceEnabled&&K.updateLogLevel(r.DEBUG,r.DEBUG);var i=["agentOsVersion","clientOsVersion","haVersion","hcVersion","shimVersion","webrtcClientVer","webRTCRedirAgentVersion","webRTCRedirClientVersion"],n={};K.logToConsole=!!e.logToConsole,K.debug("VDI Shim: Log to console = "+K.logToConsole),K.debug("VDI createInstance = "+JSON.stringify(e));for(var s=0;s<i.length;s++)e[i[s]]?(n[i[s]]=e[i[s]],K.debug("onWebSocketOpen(): "+i[s]+" = "+e[i[s]])):K.warn("onWebSocketOpen(): Could not find property "+i[s]);e.clientOsVersion?(h=e.clientOsVersion.toLowerCase()).startsWith("win")?n.clientPlatform="Windows":h.startsWith("mac")?n.clientPlatform="Mac":h.startsWith("lin")?n.clientPlatform="Linux":h.startsWith("chromeos")?n.clientPlatform="ChromeOS":h.startsWith("chrome")?n.clientPlatform="Chrome Browser":(K.error("Unknown client os: "+h),n.clientPlatform="Unknown"):(K.error("Missing client os information."),n.clientPlatform="Unknown"),K.debug("onWebSocketOpen(): clientPlatform = "+n.clientPlatform);var a,c={event:"vdiClientConnected",version:n},h=(e.hcId&&(c.endpointId=e.hcId,K.debug("onWebSocketOpen(): ClientId = "+e.hcId)),function(e,t){var i;if(void 0!==e&&void 0!==t)return i=[],Object.keys(e).forEach((function(r){void 0!==t[r]&&"number"==typeof e[r]&&"number"==typeof t[r]&&t[r]>=e[r]||i.push(r)})),0<i.length?i:void 0}(G?G.requiredAPIs:void 0,e["api-capabilities"]));if("true"!==e.allow||"Mac"===n.clientPlatform||"Unknown"===n.clientPlatform||h){if(!G||!G.simpleDisconnectOnError)try{ce(c)}catch(i){K.warn("Catch exception in onVMEvent()"+JSON.stringify(i))}var l="";for(i=["errorCode","errorMsg"],s=0;s<i.length;s++)void 0!==e[i[s]]?(K.debug("onWebSocketOpen(): "+i[s]+": "+e[i[s]]),l+=i[s]+" = "+e[i[s]],s!=i.length-1&&(l+="; ")):K.warn("onWebSocketOpen(): Could not find property "+i[s]);try{ce({event:"vdiClientDisconnected",reason:h?"requiredApiUnsupported":"endpointUnsupported",msg:h?JSON.stringify(h):l})}catch(i){K.warn("Catch exception in onVMEvent()"+JSON.stringify(i))}O("Horizon HTML5 Server connection not allowed")}else{o=2,(B=e["api-capabilities"]||{})&&(h={deviceId:!0,width:!0,height:!0,frameRate:!0},void 0!==(a=B.echoCancellation)&&(h.echoCancellation=!!a),void 0!==(a=B.noiseSuppression)&&(h.noiseSuppression=!!a),H=h),q=e.rtpCapabilities||{},$=e.callConfigs||[],Array.isArray(e.featuresSupported)?(j=e.featuresSupported,K.info("onWebSocketOpen(): Supported features = "+JSON.stringify(j))):K.warn("onWebSocketOpen(): featureSupported property not valid");try{D.hwnd!==u?ce(c):d((function(){!async function(e,t){var i=!(!G||!G.allowNullHandle);e!==u||i||(K.info("Start polling window from server"),e=await y()),K.info("window handle ="+e),D.hwnd=e,window.getWindowReference=function(){return Promise.resolve(D.hwnd)},ce(t)}(e.hwnd||u,c)}))}catch(i){K.warn("Catch exception in onVMEvent()"+JSON.stringify(i))}t.invokeDeviceChange()}}})))},C=function(){K.info("onWebSocketClose(): Websocket closed"),m===e?K.error("RequestManager.onWebSocketClose(): webrtc stack is not in use."):O("Horizon HTML5 Server connection closed")},S=function(t){var i;K.debug("onWebSocketError(): Websocket error"),m===e?K.error("RequestManager.onWebSocketError(): webrtc stack is not in use."):(i=0,F&&(i=F.state),O("Horizon HTML5 Server connection error: "+t.message),1==i&&(K.debug("Error in connecting socket"),F)&&F.sendVdiClientEventsOnError&&(K.error("Error in connecting to websocket"),F.stopPolling(),F.sendEvents(),F.sendVdiClientEventsOnError=!1))},R=function(t){if(m===e)K.error("RequestManager.onWebSocketMessage: webrtc stack is not in use.");else if("object"==typeof t.data){var i=new Uint8Array(t.data),r=new DataView(t.data),n=r.getInt32(0),o=r.getInt32(36);if(1396920910!=n)K.warn("Unsupport binary data: "+n.toString(16));else{B.getScreens&&32&B.getScreens&&K.warn("New client should return string for getScreen.");for(var a=40,c=[];a+12<i.length;){var u=r.getInt32(a),d=(_=r.getInt32(a+4))*(w=r.getInt32(a+8))*4;if(_<0||w<0||a+12+d>i.length){K.warn("Invalid screen "+_+"X"+w+" offs:"+a+" size:"+d+" len:"+i.length);break}a+=12;var h=new Uint8ClampedArray(i.buffer,a,d),l=new ImageData(h,_,w),v=new he(u,"Screen "+u,l);a+=d,c.push(v),K.debug("Screen:"+u+": "+_+"X"+w+" offs:"+a+" size:"+d+" len:"+i.length)}var f=s[o];delete s[o],void 0!==f&&"function"==typeof f.responseCb&&f.responseCb(c)}}else if("string"!=typeof t.data)K.error("onWebSocketMessage(): invalid data type: "+typeof t.data);else{n=t.data;var p=JSON.parse(n);if(K.logToConsole&&console.log("onWebSocketMessage(): "+n),"number"==typeof p.id&&0<p.id){if(f=s[p.id],delete s[p.id],f&&"function"==typeof f.responseCb)if("getScreens"!==p.evt||p.screens)f.responseCb(p);else if(p.error)f.responseCb(p);else{c=[];var g="number"==typeof p.screens?p.screens:1;for(u=1;u<=g;u++){for(var _,w,y=4*(_=100)*(w=100),b=(h=new Uint8ClampedArray(y),0);b<y;b+=4)h[b]=81,h[b+1]=144,h[b+2]=201,h[b+3]=255;v=new he(u,"Screen "+u,l=new ImageData(h,_,w)),c.push(v)}f.responseCb(c)}}else if(void 0===p.evt)K.error("onWebSocketMessage(): evt property is invalid");else switch(p.evt){case"version":void 0===p.ver?K.error("onWebSocketMessage(): ver property is invalid."):K.info("onWebSocketMessage(): version = "+p.ver);break;case"negotiationneeded":case"icecandidate":case"icegatheringstatechange":case"iceconnectionstatechange":case"signalingstatechange":case"connectionstatechange":case"addStream":case"ontrack":case"tonechange":case"onreceivers":case"onsenders":case"ontransceivers":case"ondatachannel":case"removeStream":void 0!==p.peer&&void 0!==x[p.peer]?x[p.peer]._onReceiveEvent(p):K.error("onWebSocketMessage(): peerConnection is invalid.");break;case"loadedmetadata":void 0!==p.videoId&&void 0!==P[p.videoId]?P[p.videoId].onReceiveEvent(p):K.error("onReceiveCommand(): Invalid context.");break;case"devicechange":var E=new Event("devicechange");navigator.mediaDevices.dispatchEvent(E);break;case"vdiScreenTopologyChanged":try{ce({event:"vdiScreenTopologyChanged"})}catch(t){K.warn("Catch exception in onVMEvent()"+JSON.stringify(t))}break;case"featuresSupportedChanged":for(var b in p.features){var C=p.features[b],S=j.indexOf(C.feature);"+"==C.op&&S<0?j.push(C.feature):"-"==C.op&&0<=S&&j.splice(S,1)}ce({event:"vdiFeatureSupportedChanged",reason:p.reason||"endpoint changes supported features"});break;case"vdiE911InfoChanged":p.event="vdiE911InfoChanged",ce(p);break;case"powerevent":E=p.eventData,N(E);break;case"dconopen":case"dconbufferedamountlow":case"dconclosing":case"dconerror":case"dconmessage":case"dconclose":void 0!==p.peer&&void 0!==x[p.peer]?x[p.peer]._onReceiveDataChannelEvent(p):K.error("Datachannel event: peerConnection is invalid.")}}},T=function(e,t,r,a){var c;t=null==t?-1:t,void 0===e?(c=new DOMException("Invalid command, operation cancelled","OperationError"),r?r({error:c}):K.error(c)):-1===t||x[t]?(e.feature=3,e.commandId=i[e.cmd],e.id=++h,e.peer=t,e.browser=X,e.player=1,"createInstance"===e.cmd&&(e.uid=2147483647&Date.now(),K.info("sendHelper(): ["+e.uid+"] createInstance")),"createInstance"!==e.cmd&&2!==o||(r&&(a?r():s[e.id]={id:e.id,webCommandId:e.commandId,responseCb:r}),n.send(JSON.stringify(e)))):(c=new DOMException("peer Id is not found, operation cancelled","OperationError"),r?r({error:c}):K.error(c))},A=(this.send=function(e,t,i,r){"getStats"!=e.cmd&&K.debug(JSON.stringify(e)),T(e,t,i,r)},this.invokeDeviceChange=function(){d((function(){K.info("invokeDeviceChange(): Fire devicechange event");var e=new Event("devicechange");navigator.mediaDevices.dispatchEvent(e)}))},this.sendBinary=function(e){2===o?n.send(e):K.warn("sendBinary(): WSS is not connected.")},function(){var e=Math.random()*Number.MAX_SAFE_INTEGER;return e=Math.floor(e),e="v=0\no=- "+String(e)+" 2 IP4 127.0.0.1\n",(e+="s=-\n")+"t= 0 0\na=msid-semantic: WMS"}),N=function(e){if(0==e)try{K.info("onPowerEvent(): received suspend"),ce({event:"vdiRequestEndCalls",reason:"vdiClientPowerEventSuspend"})}catch(e){K.warn("Catch exception in onVMEvent()"+JSON.stringify(e))}else if(1==e){K.info("onPowerEvent(): received resume");try{ce({event:"vdiRequestEndCalls",reason:"vdiClientPowerEventResume"})}catch(e){K.warn("Catch exception in onVMEvent()"+JSON.stringify(e))}}else K.error("powerevent: Invalid param.")},O=function(r,a){K.info("cleanup: Clean up all script resources");var c=o;if(o=a?1:0,Object.keys(s).forEach((function(e){var t,n=new DOMException(r,"OperationError");s[e].responseCb?s[e].webCommandId===i.createOffer||s[e].webCommandId===i.createAnswer?(t={desc:{sdp:A()}},K.debug("Resolving createoffer/createAnswer with desc "+t.desc),s[e].responseCb(t)):s[e].responseCb({error:n}):K.error(n)})),s={},n&&n.readyState===WebSocket.OPEN&&0==o&&n.close(),n=null,Object.keys(x).forEach((function(e){x[e].cleanUp()})),V&&V.cleanup(),x={},Object.keys(k).forEach((function(e){(e=k[e]).onended&&e.onended()})),k={},I={},j=[],W=[],z={},q={},$=[],2===c&&m!==e){try{ce({event:"vdiClientDisconnected",reason:"endpointDisconnected"})}catch(a){K.warn("Catch exception in onVMEvent()"+JSON.stringify(a))}t.invokeDeviceChange()}B={}}}function he(e,t,i,r){var n=this;this.id=e,this.name=t,this.image=i,this.icon=void 0,this.bounds=r||{x:0,y:0,width:0,height:0},this.getId=function(){return K.debug("getId "+n.id),n.id},this.getDeviceId=function(){return K.debug("getDeviceId "+n.id),Ee+"-"+n.id},this.getType=function(){return be.Monitor},this.getPreview=function(e,t,i){return K.debug("ScreensAsync getPreview "),new Promise((function(e,t){t()}))},this.getPreviewAsync=function(e,t,i){return K.debug("ScreensAsync getPreviewAsync"),new Promise(i?function(e,t){var i=document.createElement("canvas");i.getContext("2d").putImageData(n.image,0,0),e({data:i.toDataURL().replace("data:image/png;base64,","")})}:function(e,t){e(n.image)})},this.getDescription=function(){return K.debug("ScreensAsync getDescription "),n.name},this.getIcon=function(e,t){return K.debug("ScreensAsync getIcon"),new Promise((function(e,t){e(n.image)}))},this.getAppName=function(){return K.warn("getAppName: not support."),null