Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/im/call/ |
Upload File : |
(function(){BX.namespace("BX.Call");var e={invite:"im.call.invite",cancel:"im.call.cancel",answer:"im.call.answer",decline:"im.call.decline",hangup:"im.call.hangup",ping:"im.call.ping"};var t={ping:"Call::ping",answer:"Call::answer",hangup:"Call::hangup",userInviteTimeout:"Call::userInviteTimeout",repeatAnswer:"Call::repeatAnswer"};var n={voiceStarted:"Call::voiceStarted",voiceStopped:"Call::voiceStopped",microphoneState:"Call::microphoneState",cameraState:"Call::cameraState",videoPaused:"Call::videoPaused",screenState:"Call::screenState",recordState:"Call::recordState",floorRequest:"Call::floorRequest",emotion:"Call::emotion",customMessage:"Call::customMessage",showUsers:"Call::showUsers",showAll:"Call::showAll",hideAll:"Call::hideAll",joinRoom:"Call::joinRoom",leaveRoom:"Call::leaveRoom",listRooms:"Call::listRooms",requestRoomSpeaker:"Call::requestRoomSpeaker"};var i={viewerJoined:"Call::viewerJoined",viewerLeft:"Call::viewerLeft",joinRoomOffer:"Call::joinRoomOffer",transferRoomHost:"Call::transferRoomHost",listRoomsResponse:"Call::listRoomsResponse",roomUpdated:"Call::roomUpdated"};var l={onCallConference:"VoximplantCall::onCallConference"};var o=5e3;var a=25e3;var s=5500;var r=15e3;var d=6;if(window["BXDesktopSystem"]){navigator["getDisplayMedia"]=function(){var e={audio:false,video:{mandatory:{chromeMediaSource:"desktop",maxWidth:screen.width>1920?screen.width:1920,maxHeight:screen.height>1080?screen.height:1080},optional:[{googTemporalLayeredScreencast:true}]}};return navigator.mediaDevices.getUserMedia(e)}}BX.Call.VoximplantCall=function(e){BX.Call.VoximplantCall.superclass.constructor.apply(this,arguments);this.videoQuality=BX.Call.Quality.VeryHigh;this.voximplantCall=null;this.signaling=new BX.Call.VoximplantCall.Signaling({call:this});this.peers={};this.joinedElsewhere=false;this.joinedAsViewer=false;this.localVideoShown=false;this._localUserState=BX.Call.UserState.Idle;this.clientEventsBound=false;this._screenShared=false;this.videoAllowedFrom=BX.Call.UserMnemonic.all;this.direction=BX.Call.EndpointDirection.SendRecv;this.localVAD=null;this.microphoneLevelInterval=null;this.rooms={};Object.defineProperty(this,"screenShared",{get:function(){return this._screenShared},set:function(e){if(e!=this._screenShared){this._screenShared=e;this.signaling.sendScreenState(this._screenShared)}}});Object.defineProperty(this,"localUserState",{get:function(){return this._localUserState},set:function(e){if(e==this._localUserState){return}this.runCallback(BX.Call.Event.onUserStateChanged,{userId:this.userId,state:e,previousState:this._localUserState,direction:this.direction});this._localUserState=e}});this.deviceList=[];this.__onLocalDevicesUpdatedHandler=this.__onLocalDevicesUpdated.bind(this);this.__onLocalMediaRendererAddedHandler=this.__onLocalMediaRendererAdded.bind(this);this.__onBeforeLocalMediaRendererRemovedHandler=this.__onBeforeLocalMediaRendererRemoved.bind(this);this.__onMicAccessResultHandler=this.__onMicAccessResult.bind(this);this.__onClientReconnectingHandler=this.__onClientReconnecting.bind(this);this.__onClientReconnectedHandler=this.__onClientReconnected.bind(this);this.__onCallDisconnectedHandler=this.__onCallDisconnected.bind(this);this.__onCallMessageReceivedHandler=this.__onCallMessageReceived.bind(this);this.__onCallStatsReceivedHandler=this.__onCallStatsReceived.bind(this);this.__onCallEndpointAddedHandler=this.__onCallEndpointAdded.bind(this);this.__onCallReconnectingHandler=this.__onCallReconnecting.bind(this);this.__onCallReconnectedHandler=this.__onCallReconnected.bind(this);this.__onWindowUnloadHandler=this.__onWindowUnload.bind(this);window.addEventListener("unload",this.__onWindowUnloadHandler);this.initPeers();this.pingUsersInterval=setInterval(this.pingUsers.bind(this),o);this.pingBackendInterval=setInterval(this.pingBackend.bind(this),a);this.lastPingReceivedTimeout=null;this.lastSelfPingReceivedTimeout=null;this.reinviteTimeout=null;this._reconnectionEventCount=0;Object.defineProperty(this,"reconnectionEventCount",{get:function(){return this._reconnectionEventCount},set:function(e){if(this._reconnectionEventCount===0&&e>0){this.runCallback(BX.Call.Event.onReconnecting)}if(e===0){this.runCallback(BX.Call.Event.onReconnected)}this._reconnectionEventCount=e}})};BX.extend(BX.Call.VoximplantCall,BX.Call.AbstractCall);BX.Call.VoximplantCall.prototype.initPeers=function(){this.users.forEach((function(e){e=Number(e);this.peers[e]=this.createPeer(e)}),this)};BX.Call.VoximplantCall.prototype.reinitPeers=function(){for(var e in this.peers){if(this.peers.hasOwnProperty(e)&&this.peers[e]){this.peers[e].destroy();this.peers[e]=null}}this.initPeers()};BX.Call.VoximplantCall.prototype.pingUsers=function(){if(this.ready){var e=this.users.concat(this.userId);this.signaling.sendPingToUsers({userId:e},true)}};BX.Call.VoximplantCall.prototype.pingBackend=function(){if(this.ready){this.signaling.sendPingToBackend()}};BX.Call.VoximplantCall.prototype.createPeer=function(e){var t;if(this.videoAllowedFrom===BX.Call.UserMnemonic.all){t=true}else if(this.videoAllowedFrom===BX.Call.UserMnemonic.none){t=false}else if(BX.type.isArray(this.videoAllowedFrom)){t=this.videoAllowedFrom.some((function(t){return t==e}))}else{t=true}return new BX.Call.VoximplantCall.Peer({call:this,userId:e,ready:e==this.initiatorId,isIncomingVideoAllowed:t,onMediaReceived:function(t){console.log("onMediaReceived: ",t);this.runCallback(BX.Call.Event.onRemoteMediaReceived,t);if(t.kind==="video"){this.runCallback(BX.Call.Event.onUserVideoPaused,{userId:e,videoPaused:false})}}.bind(this),onMediaRemoved:function(e){console.log("onMediaRemoved: ",e);this.runCallback(BX.Call.Event.onRemoteMediaStopped,e)}.bind(this),onVoiceStarted:function(e){}.bind(this),onVoiceEnded:function(e){}.bind(this),onStateChanged:this.__onPeerStateChanged.bind(this),onInviteTimeout:this.__onPeerInviteTimeout.bind(this)})};BX.Call.VoximplantCall.prototype.getUsers=function(){var e={};for(var t in this.peers){e[t]=this.peers[t].calculatedState}return e};BX.Call.VoximplantCall.prototype.getUserCount=function(){return Object.keys(this.peers).length};BX.Call.VoximplantCall.prototype.getClient=function(){return new Promise(function(e,t){BX.Voximplant.getClient({restClient:BX.CallEngine.getRestClient()}).then(function(t){t.enableSilentLogging();t.setLoggerCallback(function(e){this.log(e.label+": "+e.message)}.bind(this));this.log("User agent: "+navigator.userAgent);this.log("Voximplant SDK version: "+VoxImplant.version);this.bindClientEvents();e(t)}.bind(this)).catch(t)}.bind(this))};BX.Call.VoximplantCall.prototype.bindClientEvents=function(){var e=VoxImplant.Hardware.StreamManager.get();if(!this.clientEventsBound){VoxImplant.getInstance().on(VoxImplant.Events.MicAccessResult,this.__onMicAccessResultHandler);if(VoxImplant.Events.Reconnecting){VoxImplant.getInstance().on(VoxImplant.Events.Reconnecting,this.__onClientReconnectingHandler);VoxImplant.getInstance().on(VoxImplant.Events.Reconnected,this.__onClientReconnectedHandler)}e.on(VoxImplant.Hardware.HardwareEvents.DevicesUpdated,this.__onLocalDevicesUpdatedHandler);e.on(VoxImplant.Hardware.HardwareEvents.MediaRendererAdded,this.__onLocalMediaRendererAddedHandler);e.on(VoxImplant.Hardware.HardwareEvents.MediaRendererUpdated,this.__onLocalMediaRendererAddedHandler);e.on(VoxImplant.Hardware.HardwareEvents.BeforeMediaRendererRemoved,this.__onBeforeLocalMediaRendererRemovedHandler);this.clientEventsBound=true}};BX.Call.VoximplantCall.prototype.removeClientEvents=function(){if(!("VoxImplant"in window)){return}VoxImplant.getInstance().off(VoxImplant.Events.MicAccessResult,this.__onMicAccessResultHandler);if(VoxImplant.Events.Reconnecting){VoxImplant.getInstance().off(VoxImplant.Events.Reconnecting,this.__onClientReconnectingHandler);VoxImplant.getInstance().off(VoxImplant.Events.Reconnected,this.__onClientReconnectedHandler)}var e=VoxImplant.Hardware.StreamManager.get();e.off(VoxImplant.Hardware.HardwareEvents.DevicesUpdated,this.__onLocalDevicesUpdatedHandler);e.off(VoxImplant.Hardware.HardwareEvents.MediaRendererAdded,this.__onLocalMediaRendererAddedHandler);e.off(VoxImplant.Hardware.HardwareEvents.BeforeMediaRendererRemoved,this.__onBeforeLocalMediaRendererRemovedHandler);this.clientEventsBound=false};BX.Call.VoximplantCall.prototype.setMuted=function(e){if(this.muted==e){return}this.muted=e;if(this.voximplantCall){if(this.muted){this.voximplantCall.muteMicrophone()}else{this.voximplantCall.unmuteMicrophone()}this.signaling.sendMicrophoneState(!this.muted)}};BX.Call.VoximplantCall.prototype.isMuted=function(){return this.muted};BX.Call.VoximplantCall.prototype.setVideoEnabled=function(e){e=e===true;if(this.videoEnabled==e){return}this.videoEnabled=e;if(this.voximplantCall){if(e){this._showLocalVideo()}else{if(this.localVideoShown){VoxImplant.Hardware.StreamManager.get().hideLocalVideo().then(function(){this.localVideoShown=false;this.runCallback(BX.Call.Event.onLocalMediaReceived,{tag:"main",stream:new MediaStream})}.bind(this))}}this.voximplantCall.sendVideo(this.videoEnabled);this.signaling.sendCameraState(this.videoEnabled)}};BX.Call.VoximplantCall.prototype.setCameraId=function(e){if(this.cameraId==e){return}this.cameraId=e;if(this.voximplantCall){VoxImplant.Hardware.CameraManager.get().getInputDevices().then(function(){VoxImplant.Hardware.CameraManager.get().setCallVideoSettings(this.voximplantCall,this.constructCameraParams())}.bind(this))}};BX.Call.VoximplantCall.prototype.setMicrophoneId=function(e){if(this.microphoneId==e){return}this.microphoneId=e;if(this.voximplantCall){VoxImplant.Hardware.AudioDeviceManager.get().getInputDevices().then(function(){VoxImplant.Hardware.AudioDeviceManager.get().setCallAudioSettings(this.voximplantCall,{inputId:this.microphoneId})}.bind(this))}};BX.Call.VoximplantCall.prototype.getCurrentMicrophoneId=function(){if(this.voximplantCall.peerConnection.impl.getTransceivers){var e=this.voximplantCall.peerConnection.impl.getTransceivers();if(e.length>0){var t=e[0].sender.track;var n=t.getSettings();return n.deviceId}}return this.microphoneId};BX.Call.VoximplantCall.prototype.constructCameraParams=function(){var e={};if(this.cameraId){e.cameraId=this.cameraId}e.videoQuality=this.videoHd?VoxImplant.Hardware.VideoQuality.VIDEO_SIZE_HD:VoxImplant.Hardware.VideoQuality.VIDEO_SIZE_nHD;e.facingMode=true;return e};BX.Call.VoximplantCall.prototype.useHdVideo=function(e){this.videoHd=e===true};BX.Call.VoximplantCall.prototype.requestFloor=function(e){this.signaling.sendFloorRequest(e)};BX.Call.VoximplantCall.prototype.sendRecordState=function(e){this.signaling.sendRecordState(e)};BX.Call.VoximplantCall.prototype.sendEmotion=function(e,t){this.signaling.sendEmotion(e,t)};BX.Call.VoximplantCall.prototype.sendCustomMessage=function(e,t){this.signaling.sendCustomMessage(e,t)};BX.Call.VoximplantCall.prototype.allowVideoFrom=function(e){if(this.videoAllowedFrom==e){return}this.videoAllowedFrom=e;if(e===BX.Call.UserMnemonic.all){this.signaling.sendShowAll();e=Object.keys(this.peers)}else if(e===BX.Call.UserMnemonic.none){this.signaling.sendHideAll();e=[]}else if(BX.type.isArray(e)){this.signaling.sendShowUsers(e)}else{throw new Error("userList is in wrong format")}var t={};e.forEach((function(e){t[e]=true}));for(var n in this.peers){if(!this.peers.hasOwnProperty(n)){continue}if(t[n]){this.peers[n].allowIncomingVideo(true)}else{this.peers[n].allowIncomingVideo(false)}}};BX.Call.VoximplantCall.prototype._setMaxBitrate=function(e){if(this.voximplantCall){var t=this.voximplantCall.peerConnection.getTransceivers();if(!t){return}t.forEach((function(t){if(t.sender&&t.sender.track&&t.sender.track.kind==="video"&&!t.stoped&&t.currentDirection.indexOf("send")!==-1){var n=t.sender;var i=n.getParameters();if(!i.encodings){i.encodings=[{}]}if(e===0){delete i.encodings[0].maxBitrate}else{i.encodings[0].maxBitrate=e*1e3}n.setParameters(i)}}),this)}};BX.Call.VoximplantCall.prototype._showLocalVideo=function(){return new Promise(function(e,t){VoxImplant.Hardware.StreamManager.get().showLocalVideo(false).then(function(){this.localVideoShown=true;e()}.bind(this),function(){this.localVideoShown=true;e()}.bind(this))}.bind(this))};BX.Call.VoximplantCall.prototype._hideLocalVideo=function(){return new Promise((function(e,t){if(!("VoxImplant"in window)){e();return}VoxImplant.Hardware.StreamManager.get().hideLocalVideo().then(function(){this.localVideoShown=false;e()}.bind(this),function(){this.localVideoShown=false;e()}.bind(this))}))};BX.Call.VoximplantCall.prototype.startScreenSharing=function(){if(!this.voximplantCall){return}var e=!this.videoEnabled;var t=this.videoEnabled||this.screenShared;this.voximplantCall.shareScreen(e,t).then(function(){this.log("Screen shared");this.screenShared=true}.bind(this)).catch(function(e){console.error(e);this.log("Screen sharing error:",e)}.bind(this))};BX.Call.VoximplantCall.prototype.stopScreenSharing=function(){if(!this.voximplantCall){return}this.voximplantCall.stopSharingScreen().then(function(){this.log("Screen is no longer shared");this.screenShared=false}.bind(this))};BX.Call.VoximplantCall.prototype.isScreenSharingStarted=function(){return this.screenShared};BX.Call.VoximplantCall.prototype.inviteUsers=function(e){var t=this;this.ready=true;if(!BX.type.isPlainObject(e)){e={}}var n=BX.type.isArray(e.users)?e.users:this.users;this.attachToConference().then((function(){t.signaling.sendPingToUsers({userId:n});if(n.length>0){return t.signaling.inviteUsers({userIds:n,video:t.videoEnabled?"Y":"N"})}})).then((function(e){t.state=BX.Call.State.Connected;t.runCallback(BX.Call.Event.onJoin,{local:true});for(var i=0;i<n.length;i++){var l=parseInt(n[i],10);if(!t.users.includes(l)){t.users.push(l)}if(!t.peers[l]){t.peers[l]=t.createPeer(l);if(t.type===BX.Call.Type.Instant){t.runCallback(BX.Call.Event.onUserInvited,{userId:l})}}if(t.type===BX.Call.Type.Instant){t.peers[l].onInvited();t.scheduleRepeatInvite()}}})).catch(t.onFatalError.bind(t))};BX.Call.VoximplantCall.prototype.scheduleRepeatInvite=function(){clearTimeout(this.reinviteTimeout);this.reinviteTimeout=setTimeout(this.repeatInviteUsers.bind(this),s)};BX.Call.VoximplantCall.prototype.repeatInviteUsers=function(){clearTimeout(this.reinviteTimeout);if(!this.ready){return}var e=[];for(var t in this.peers){if(this.peers.hasOwnProperty(t)&&this.peers[t].calculatedState===BX.Call.UserState.Calling){e.push(t)}}if(e.length===0){return}this.signaling.inviteUsers({userIds:e,video:this.videoEnabled?"Y":"N",isRepeated:"Y"}).then(function(){this.scheduleRepeatInvite()}.bind(this))};BX.Call.VoximplantCall.prototype.answer=function(e){this.ready=true;var t=BX.prop.getBoolean(e,"joinAsViewer",false);if(!BX.type.isPlainObject(e)){e={}}this.videoEnabled=e.useVideo==true;if(!t){this.signaling.sendAnswer()}this.attachToConference({joinAsViewer:t}).then((()=>{this.log("Attached to conference");this.state=BX.Call.State.Connected;this.runCallback(BX.Call.Event.onJoin,{local:true})})).catch((e=>{this.onFatalError(e)}))};BX.Call.VoximplantCall.prototype.decline=function(t){this.ready=false;var n={callId:this.id,callInstanceId:this.instanceId};if(t){n.code=t}BX.CallEngine.getRestClient().callMethod(e.decline,n)};BX.Call.VoximplantCall.prototype.hangup=function(e,t){if(!this.ready){var n=new Error("Hangup in wrong state");this.log(n);return}var i=new Error;i.name="Call stack:";this.log("Hangup received \n"+i.stack);if(this.localVAD){this.localVAD.destroy();this.localVAD=null}clearInterval(this.microphoneLevelInterval);var l={};this.ready=false;if(typeof e!="undefined"){l.code=e}if(typeof t!="undefined"){l.reason=t}this.state=BX.Call.State.Proceeding;this.runCallback(BX.Call.Event.onLeave,{local:true});l.userId=this.users.slice(0).concat(this.userId);this.signaling.sendHangup(l);this.muted=false;this.reinitPeers();if(this.voximplantCall){this.voximplantCall._replaceVideoSharing=false;try{this.voximplantCall.hangup()}catch(e){this.log("Voximplant hangup error: ",e);console.error("Voximplant hangup error: ",e)}}else{this.log("Tried to hangup, but this.voximplantCall points nowhere");console.error("Tried to hangup, but this.voximplantCall points nowhere")}this.screenShared=false;this._hideLocalVideo()};BX.Call.VoximplantCall.prototype.attachToConference=function(e){var t=this;var n=BX.prop.getBoolean(e,"joinAsViewer",false);return new Promise((function(e,i){if(t.voximplantCall&&t.voximplantCall.state()==="CONNECTED"){if(t.joinedAsViewer===n){return e()}else{return i("Already joined call in another mode")}}t.direction=n?BX.Call.EndpointDirection.RecvOnly:BX.Call.EndpointDirection.SendRecv;t.sendTelemetryEvent("call");t.getClient().then((function(l){t.localUserState=BX.Call.UserState.Connecting;VoxImplant.Hardware.CameraManager.get().setDefaultVideoSettings(t.constructCameraParams());if(t.microphoneId){VoxImplant.Hardware.AudioDeviceManager.get().setDefaultAudioSettings({inputId:t.microphoneId})}if(t.videoEnabled){t._showLocalVideo()}try{if(n){t.voximplantCall=l.joinAsViewer("bx_conf_"+t.id,{"X-Direction":BX.Call.EndpointDirection.RecvOnly})}else{t.voximplantCall=l.callConference({number:"bx_conf_"+t.id,video:{sendVideo:t.videoEnabled,receiveVideo:true},customData:JSON.stringify({cameraState:t.videoEnabled})})}}catch(e){console.error(e);return i(e)}t.joinedAsViewer=n;if(!t.voximplantCall){t.log("Error: could not create voximplant call");return i({code:"VOX_NO_CALL"})}t.runCallback(BX.Call.VoximplantCall.Event.onCallConference,{call:t});t.bindCallEvents();var o=function(){t.log("Call connected");t.sendTelemetryEvent("connect");t.localUserState=BX.Call.UserState.Connected;t.voximplantCall.removeEventListener(VoxImplant.CallEvents.Connected,o);t.voximplantCall.removeEventListener(VoxImplant.CallEvents.Failed,a);t.voximplantCall.addEventListener(VoxImplant.CallEvents.Failed,t.__onCallDisconnectedHandler);if(t.deviceList.length===0){navigator.mediaDevices.enumerateDevices().then((function(e){t.deviceList=e;t.runCallback(BX.Call.Event.onDeviceListUpdated,{deviceList:t.deviceList})}))}else{t.runCallback(BX.Call.Event.onDeviceListUpdated,{deviceList:t.deviceList})}if(t.muted){t.voximplantCall.muteMicrophone()}t.signaling.sendMicrophoneState(!t.muted);t.signaling.sendCameraState(t.videoEnabled);if(t.videoAllowedFrom==BX.Call.UserMnemonic.none){t.signaling.sendHideAll()}else if(BX.type.isArray(t.videoAllowedFrom)){t.signaling.sendShowUsers(t.videoAllowedFrom)}e()};var a=function(e){t.log("Could not attach to conference",e);t.sendTelemetryEvent("connect_failure");t.localUserState=BX.Call.UserState.Failed;t.voximplantCall.removeEventListener(VoxImplant.CallEvents.Connected,o);t.voximplantCall.removeEventListener(VoxImplant.CallEvents.Failed,a);var n=VoxImplant.getInstance();n.enableSilentLogging(false);n.setLoggerCallback(null);i(e)};t.voximplantCall.addEventListener(VoxImplant.CallEvents.Connected,o);t.voximplantCall.addEventListener(VoxImplant.CallEvents.Failed,a)})).catch(t.onFatalError.bind(t))}))};BX.Call.VoximplantCall.prototype.bindCallEvents=function(){this.voximplantCall.addEventListener(VoxImplant.CallEvents.Disconnected,this.__onCallDisconnectedHandler);this.voximplantCall.addEventListener(VoxImplant.CallEvents.MessageReceived,this.__onCallMessageReceivedHandler);if(BX.Call.Util.shouldCollectStats()){this.voximplantCall.addEventListener(VoxImplant.CallEvents.CallStatsReceived,this.__onCallStatsReceivedHandler)}this.voximplantCall.addEventListener(VoxImplant.CallEvents.EndpointAdded,this.__onCallEndpointAddedHandler);if(VoxImplant.CallEvents.Reconnecting){this.voximplantCall.addEventListener(VoxImplant.CallEvents.Reconnecting,this.__onCallReconnectingHandler);this.voximplantCall.addEventListener(VoxImplant.CallEvents.Reconnected,this.__onCallReconnectedHandler)}};BX.Call.VoximplantCall.prototype.removeCallEvents=function(){if(this.voximplantCall){this.voximplantCall.removeEventListener(VoxImplant.CallEvents.Disconnected,this.__onCallDisconnectedHandler);this.voximplantCall.removeEventListener(VoxImplant.CallEvents.MessageReceived,this.__onCallMessageReceivedHandler);if(BX.Call.Util.shouldCollectStats()){this.voximplantCall.removeEventListener(VoxImplant.CallEvents.CallStatsReceived,this.__onCallStatsReceivedHandler)}this.voximplantCall.removeEventListener(VoxImplant.CallEvents.EndpointAdded,this.__onCallEndpointAddedHandler);if(VoxImplant.CallEvents.Reconnecting){this.voximplantCall.removeEventListener(VoxImplant.CallEvents.Reconnecting,this.__onCallReconnectingHandler);this.voximplantCall.removeEventListener(VoxImplant.CallEvents.Reconnected,this.__onCallReconnectedHandler)}}};BX.Call.VoximplantCall.prototype.addJoinedUsers=function(e){for(var t=0;t<e.length;t++){var n=Number(e[t]);if(n==this.userId||this.peers[n]){continue}this.peers[n]=this.createPeer(n);if(!this.users.includes(n)){this.users.push(n)}this.runCallback(BX.Call.Event.onUserInvited,{userId:n})}};BX.Call.VoximplantCall.prototype.addInvitedUsers=function(e){for(var t=0;t<e.length;t++){var n=Number(e[t]);if(n==this.userId){continue}if(this.peers[n]){if(this.peers[n].calculatedState===BX.Call.UserState.Failed||this.peers[n].calculatedState===BX.Call.UserState.Idle){if(this.type===BX.Call.Type.Instant){this.peers[n].onInvited()}}}else{this.peers[n]=this.createPeer(n);if(this.type===BX.Call.Type.Instant){this.peers[n].onInvited()}}if(!this.users.includes(n)){this.users.push(n)}this.runCallback(BX.Call.Event.onUserInvited,{userId:n})}};BX.Call.VoximplantCall.prototype.isAnyoneParticipating=function(){for(var e in this.peers){if(this.peers[e].isParticipating()){return true}}return false};BX.Call.VoximplantCall.prototype.getParticipatingUsers=function(){var e=[];for(var t in this.peers){if(this.peers[t].isParticipating()){e.push(t)}}return e};BX.Call.VoximplantCall.prototype.updateRoom=function(e){if(!this.rooms[e.id]){this.rooms[e.id]={id:e.id,users:e.users,speaker:e.speaker}}else{this.rooms[e.id].users=e.users;this.rooms[e.id].speaker=e.speaker}};BX.Call.VoximplantCall.prototype.currentRoom=function(){return this._currentRoomId?this.rooms[this._currentRoomId]:null};BX.Call.VoximplantCall.prototype.isRoomSpeaker=function(){return this.currentRoom()?this.currentRoom().speaker==this.userId:false};BX.Call.VoximplantCall.prototype.joinRoom=function(e){this.signaling.sendJoinRoom(e)};BX.Call.VoximplantCall.prototype.requestRoomSpeaker=function(){this.signaling.sendRequestRoomSpeaker(this._currentRoomId)};BX.Call.VoximplantCall.prototype.leaveCurrentRoom=function(){this.signaling.sendLeaveRoom(this._currentRoomId)};BX.Call.VoximplantCall.prototype.listRooms=function(){return new Promise(((e,t)=>{this.signaling.sendListRooms();this.__resolveListRooms=e}))};BX.Call.VoximplantCall.prototype.__onPeerStateChanged=function(e){this.runCallback(BX.Call.Event.onUserStateChanged,e);if(!this.ready){return}if(e.state==BX.Call.UserState.Failed||e.state==BX.Call.UserState.Unavailable||e.state==BX.Call.UserState.Declined||e.state==BX.Call.UserState.Idle){if(this.type==BX.Call.Type.Instant&&!this.isAnyoneParticipating()){this.hangup()}}};BX.Call.VoximplantCall.prototype.__onPeerInviteTimeout=function(e){if(!this.ready){return}this.signaling.sendUserInviteTimeout({userId:this.users,failedUserId:e.userId})};BX.Call.VoximplantCall.prototype.__onPullEvent=function(e,t,n){var i={"Call::answer":this.__onPullEventAnswer.bind(this),"Call::hangup":this.__onPullEventHangup.bind(this),"Call::usersJoined":this.__onPullEventUsersJoined.bind(this),"Call::usersInvited":this.__onPullEventUsersInvited.bind(this),"Call::userInviteTimeout":this.__onPullEventUserInviteTimeout.bind(this),"Call::ping":this.__onPullEventPing.bind(this),"Call::finish":this.__onPullEventFinish.bind(this),"Call::repeatAnswer":this.__onPullEventRepeatAnswer.bind(this)};if(i[e]){if(e!="Call::ping"){this.log("Signaling: "+e+"; Parameters: "+JSON.stringify(t))}i[e].call(this,t)}};BX.Call.VoximplantCall.prototype.__onPullEventAnswer=function(e){var t=Number(e.senderId);if(t==this.userId){return this.__onPullEventAnswerSelf(e)}if(!this.peers[t]){this.peers[t]=this.createPeer(t);this.runCallback(BX.Call.Event.onUserInvited,{userId:t})}if(!this.users.includes(t)){this.users.push(t)}this.peers[t].setReady(true)};BX.Call.VoximplantCall.prototype.__onPullEventAnswerSelf=function(e){if(e.callInstanceId===this.instanceId){return}this.joinedElsewhere=true;this.runCallback(BX.Call.Event.onJoin,{local:false})};BX.Call.VoximplantCall.prototype.__onPullEventHangup=function(e){var t=e.senderId;if(this.userId==t&&this.instanceId!=e.callInstanceId){this.runCallback(BX.Call.Event.onLeave,{local:false});return}if(!this.peers[t])return;this.peers[t].setReady(false);if(e.code==603){this.peers[t].setDeclined(true)}else if(e.code==486){this.peers[t].setBusy(true);console.error("user "+t+" is busy")}if(this.ready&&this.type==BX.Call.Type.Instant&&!this.isAnyoneParticipating()){this.hangup()}};BX.Call.VoximplantCall.prototype.__onPullEventUsersJoined=function(e){this.log("__onPullEventUsersJoined",e);var t=e.users;this.addJoinedUsers(t)};BX.Call.VoximplantCall.prototype.__onPullEventUsersInvited=function(e){this.log("__onPullEventUsersInvited",e);var t=e.users;if(this.type===BX.Call.Type.Instant){this.addInvitedUsers(t)}};BX.Call.VoximplantCall.prototype.__onPullEventUserInviteTimeout=function(e){this.log("__onPullEventUserInviteTimeout",e);var t=e.failedUserId;if(this.peers[t]){this.peers[t].onInviteTimeout(false)}};BX.Call.VoximplantCall.prototype.__onPullEventPing=function(e){if(e.callInstanceId==this.instanceId){return}var t=Number(e.senderId);if(t==this.userId){if(!this.joinedElsewhere){this.runCallback(BX.Call.Event.onJoin,{local:false});this.joinedElsewhere=true}clearTimeout(this.lastSelfPingReceivedTimeout);this.lastSelfPingReceivedTimeout=setTimeout(this.__onNoSelfPingsReceived.bind(this),o*2.1)}clearTimeout(this.lastPingReceivedTimeout);this.lastPingReceivedTimeout=setTimeout(this.__onNoPingsReceived.bind(this),o*2.1);if(this.peers[t]){this.peers[t].setReady(true)}};BX.Call.VoximplantCall.prototype.__onNoPingsReceived=function(){if(!this.ready){this.destroy()}};BX.Call.VoximplantCall.prototype.__onNoSelfPingsReceived=function(){this.runCallback(BX.Call.Event.onLeave,{local:false});this.joinedElsewhere=false};BX.Call.VoximplantCall.prototype.__onPullEventFinish=function(e){this.destroy()};BX.Call.VoximplantCall.prototype.__onPullEventRepeatAnswer=function(){if(this.ready){this.signaling.sendAnswer({userId:this.userId},true)}};BX.Call.VoximplantCall.prototype.__onLocalDevicesUpdated=function(e){this.log("__onLocalDevicesUpdated",e)};BX.Call.VoximplantCall.prototype.__onLocalMediaRendererAdded=function(e){var t=e.renderer;var n=t.stream.getVideoTracks().length>0?t.stream.getVideoTracks()[0].label:"";this.log("__onLocalMediaRendererAdded",t.kind,n);if(t.kind==="video"){if(n.match(/^screen|window|tab|web-contents-media-stream/i)){var i="screen"}else{i="main"}this.screenShared=i==="screen";this.runCallback(BX.Call.Event.onLocalMediaReceived,{tag:i,stream:t.stream})}else if(t.kind==="sharing"){this.runCallback(BX.Call.Event.onLocalMediaReceived,{tag:"screen",stream:t.stream});this.screenShared=true}};BX.Call.VoximplantCall.prototype.__onBeforeLocalMediaRendererRemoved=function(e){var t=e.renderer;this.log("__onBeforeLocalMediaRendererRemoved",t.kind);if(t.kind==="sharing"&&!this.videoEnabled){this.runCallback(BX.Call.Event.onLocalMediaReceived,{tag:"main",stream:new MediaStream});this.screenShared=false}};BX.Call.VoximplantCall.prototype.__onMicAccessResult=function(e){if(e.result){if(e.stream.getAudioTracks().length>0){if(this.localVAD){this.localVAD.destroy()}this.localVAD=new BX.SimpleVAD({mediaStream:e.stream,onVoiceStarted:function(){this.runCallback(BX.Call.Event.onUserVoiceStarted,{userId:this.userId,local:true})}.bind(this),onVoiceStopped:function(){this.runCallback(BX.Call.Event.onUserVoiceStopped,{userId:this.userId,local:true})}.bind(this)});clearInterval(this.microphoneLevelInterval);this.microphoneLevelInterval=setInterval(function(){this.microphoneLevel=this.localVAD.currentVolume}.bind(this),200)}}};BX.Call.VoximplantCall.prototype.__onCallReconnecting=function(e){this.reconnectionEventCount++};BX.Call.VoximplantCall.prototype.__onCallReconnected=function(e){this.reconnectionEventCount--};BX.Call.VoximplantCall.prototype.__onClientReconnecting=function(e){this.reconnectionEventCount++};BX.Call.VoximplantCall.prototype.__onClientReconnected=function(e){this.reconnectionEventCount--};BX.Call.VoximplantCall.prototype.__onCallDisconnected=function(e){this.log("__onCallDisconnected",e&&e.headers?{headers:e.headers}:null);this.sendTelemetryEvent("disconnect");this.localUserState=BX.Call.UserState.Idle;this.ready=false;this.muted=false;this.joinedAsViewer=false;this.reinitPeers();this._hideLocalVideo();this.removeCallEvents();this.voximplantCall=null;var t=VoxImplant.getInstance();t.enableSilentLogging(false);t.setLoggerCallback(null);this.state=BX.Call.State.Proceeding;this.runCallback(BX.Call.Event.onLeave,{local:true})};BX.Call.VoximplantCall.prototype.__onWindowUnload=function(){if(this.ready&&this.voximplantCall){this.signaling.sendHangup({userId:this.users})}};BX.Call.VoximplantCall.prototype.onFatalError=function(e){if(e&&e.call){delete e.call}this.log("onFatalError",e);this.ready=false;this.muted=false;this.localUserState=BX.Call.UserState.Failed;this.reinitPeers();this._hideLocalVideo().then(function(){if(this.voximplantCall){this.removeCallEvents();try{this.voximplantCall.hangup({"X-Reason":"Fatal error","X-Error":typeof e==="string"?e:e.code||e.name})}catch(e){this.log("Voximplant hangup error: ",e);console.error("Voximplant hangup error: ",e)}this.voximplantCall=null}if(typeof VoxImplant!=="undefined"){var t=VoxImplant.getInstance();t.enableSilentLogging(false);t.setLoggerCallback(null)}if(typeof e==="string"){this.runCallback(BX.Call.Event.onCallFailure,{name:e})}else if(e.name){this.runCallback(BX.Call.Event.onCallFailure,e)}}.bind(this))};BX.Call.VoximplantCall.prototype.__onCallEndpointAdded=function(e){var t=e.endpoint;var n=t.userName;this.log("__onCallEndpointAdded ("+n+")",e.endpoint);console.log("__onCallEndpointAdded ("+n+")",e.endpoint);if(BX.type.isNotEmptyString(n)&&n.substr(0,4)=="user"){var i=parseInt(n.substr(4));if(this.peers[i]){this.peers[i].setEndpoint(t)}this.wasConnected=true}else{t.addEventListener(VoxImplant.EndpointEvents.InfoUpdated,function(e){var t=e.endpoint;var n=t.userName;this.log("VoxImplant.EndpointEvents.InfoUpdated ("+n+")",e.endpoint);if(BX.type.isNotEmptyString(n)&&n.substr(0,4)=="user"){var i=parseInt(n.substr(4));if(this.peers[i]){this.peers[i].setEndpoint(t)}}}.bind(this));this.log("Unknown endpoint "+n);console.warn("Unknown endpoint "+n)}};BX.Call.VoximplantCall.prototype.__onCallStatsReceived=function(e){if(this.logger){this.logger.sendStat(c(e.stats,this.voximplantCall))}};BX.Call.VoximplantCall.prototype.__onJoinRoomOffer=function(e){console.warn("__onJoinRoomOffer",e);this.updateRoom({id:e.roomId,users:e.users,speaker:e.speaker});this.runCallback(BX.Call.Event.onJoinRoomOffer,{roomId:e.roomId,users:e.users,initiator:e.initiator,speaker:e.speaker})};BX.Call.VoximplantCall.prototype.__onRoomUpdated=function(e){const t=e.roomId===this._currentRoomId&&this.rooms[e.roomId]&&this.rooms[e.roomId].speaker!=e.speaker;const n=t&&this.rooms[e.roomId].speaker;console.log("__onRoomUpdated; speakerChanged: ",t);this.updateRoom({id:e.roomId,users:e.users,speaker:e.speaker});if(e.roomId===this._currentRoomId&&e.users.indexOf(this.userId)===-1){this._currentRoomId=null;this.runCallback(BX.Call.Event.onLeaveRoom,{roomId:e.roomId})}else if(e.roomId!==this._currentRoomId&&e.users.indexOf(this.userId)!==-1){this._currentRoomId=e.roomId;this.runCallback(BX.Call.Event.onJoinRoom,{roomId:e.roomId,speaker:this.currentRoom().speaker,users:this.currentRoom().users})}else if(t){this.runCallback(BX.Call.Event.onTransferRoomSpeaker,{roomId:e.roomId,speaker:e.speaker,previousSpeaker:n,initiator:e.initiator})}};BX.Call.VoximplantCall.prototype.__onCallMessageReceived=function(e){var t;var l;try{t=JSON.parse(e.text)}catch(e){this.log("Could not parse scenario message.",e);return}var o=t.eventName;if(o===n.voiceStarted){this.runCallback(BX.Call.Event.onUserVoiceStarted,{userId:t.senderId})}else if(o===n.voiceStopped){this.runCallback(BX.Call.Event.onUserVoiceStopped,{userId:t.senderId})}else if(o===n.microphoneState){this.runCallback(BX.Call.Event.onUserMicrophoneState,{userId:t.senderId,microphoneState:t.microphoneState==="Y"})}else if(o===n.cameraState){this.runCallback(BX.Call.Event.onUserCameraState,{userId:t.senderId,cameraState:t.cameraState==="Y"})}else if(o===n.videoPaused){this.runCallback(BX.Call.Event.onUserVideoPaused,{userId:t.senderId,videoPaused:t.videoPaused==="Y"})}else if(o===n.screenState){this.runCallback(BX.Call.Event.onUserScreenState,{userId:t.senderId,screenState:t.screenState==="Y"})}else if(o===n.recordState){this.runCallback(BX.Call.Event.onUserRecordState,{userId:t.senderId,recordState:t.recordState})}else if(o===n.floorRequest){this.runCallback(BX.Call.Event.onUserFloorRequest,{userId:t.senderId,requestActive:t.requestActive==="Y"})}else if(o===n.emotion){this.runCallback(BX.Call.Event.onUserEmotion,{userId:t.senderId,toUserId:t.toUserId,emotion:t.emotion})}else if(o===n.customMessage){this.runCallback(BX.Call.Event.onCustomMessage,{message:t.message})}else if(o==="scenarioLogUrl"){console.warn("scenario log url: "+t.logUrl)}else if(o===i.joinRoomOffer){console.log(t);this.__onJoinRoomOffer(t)}else if(o===i.roomUpdated){this.__onRoomUpdated(t)}else if(o===i.listRoomsResponse){if(this.__resolveListRooms){this.__resolveListRooms(t.rooms);delete this.__resolveListRooms}}else if(o===i.viewerJoined){console.log("viewer "+t.senderId+" joined");l=this.peers[t.senderId];if(l){l.setDirection(BX.Call.EndpointDirection.RecvOnly);l.setReady(true)}}else if(o===i.viewerLeft){console.log("viewer "+t.senderId+" left");l=this.peers[t.senderId];if(l){l.setReady(false)}}else{this.log("Unknown scenario event "+o)}};BX.Call.VoximplantCall.prototype.sendTelemetryEvent=function(e){BX.Call.Util.sendTelemetryEvent({call_id:this.id,user_id:this.userId,kind:"voximplant",event:e})};BX.Call.VoximplantCall.prototype.destroy=function(){this.ready=false;this.joinedAsViewer=false;this._hideLocalVideo();if(this.localVAD){this.localVAD.destroy();this.localVAD=null}clearInterval(this.microphoneLevelInterval);if(this.voximplantCall){this.removeCallEvents();if(this.voximplantCall.state()!="ENDED"){this.voximplantCall.hangup()}this.voximplantCall=null}for(var e in this.peers){if(this.peers.hasOwnProperty(e)&&this.peers[e]){this.peers[e].destroy()}}this.removeClientEvents();clearTimeout(this.lastPingReceivedTimeout);clearTimeout(this.lastSelfPingReceivedTimeout);clearInterval(this.pingUsersInterval);clearInterval(this.pingBackendInterval);window.removeEventListener("unload",this.__onWindowUnloadHandler);this.superclass.destroy.apply(this,arguments)};BX.Call.VoximplantCall.Signaling=function(e){this.call=e.call};BX.Call.VoximplantCall.Signaling.prototype.inviteUsers=function(t){return this.__runRestAction(e.invite,t)};BX.Call.VoximplantCall.Signaling.prototype.sendAnswer=function(n,i){if(i&&BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.answer,n)}else{return this.__runRestAction(e.answer,n)}};BX.Call.VoximplantCall.Signaling.prototype.sendCancel=function(t){return this.__runRestAction(e.cancel,t)};BX.Call.VoximplantCall.Signaling.prototype.sendHangup=function(n){if(BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.hangup,n);n.retransmit=false;this.__runRestAction(e.hangup,n)}else{n.retransmit=true;this.__runRestAction(e.hangup,n)}};BX.Call.VoximplantCall.Signaling.prototype.sendVoiceStarted=function(e){return this.__sendMessage(n.voiceStarted,e)};BX.Call.VoximplantCall.Signaling.prototype.sendVoiceStopped=function(e){return this.__sendMessage(n.voiceStopped,e)};BX.Call.VoximplantCall.Signaling.prototype.sendMicrophoneState=function(e){return this.__sendMessage(n.microphoneState,{microphoneState:e?"Y":"N"})};BX.Call.VoximplantCall.Signaling.prototype.sendCameraState=function(e){return this.__sendMessage(n.cameraState,{cameraState:e?"Y":"N"})};BX.Call.VoximplantCall.Signaling.prototype.sendScreenState=function(e){return this.__sendMessage(n.screenState,{screenState:e?"Y":"N"})};BX.Call.VoximplantCall.Signaling.prototype.sendRecordState=function(e){return this.__sendMessage(n.recordState,e)};BX.Call.VoximplantCall.Signaling.prototype.sendFloorRequest=function(e){return this.__sendMessage(n.floorRequest,{requestActive:e?"Y":"N"})};BX.Call.VoximplantCall.Signaling.prototype.sendEmotion=function(e,t){return this.__sendMessage(n.emotion,{toUserId:e,emotion:t})};BX.Call.VoximplantCall.Signaling.prototype.sendCustomMessage=function(e,t){return this.__sendMessage(n.customMessage,{message:e,repeatOnConnect:!!t})};BX.Call.VoximplantCall.Signaling.prototype.sendShowUsers=function(e){return this.__sendMessage(n.showUsers,{users:e})};BX.Call.VoximplantCall.Signaling.prototype.sendShowAll=function(){return this.__sendMessage(n.showAll,{})};BX.Call.VoximplantCall.Signaling.prototype.sendHideAll=function(){return this.__sendMessage(n.hideAll,{})};BX.Call.VoximplantCall.Signaling.prototype.sendPingToUsers=function(e){if(BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.ping,e,0)}};BX.Call.VoximplantCall.Signaling.prototype.sendPingToBackend=function(){this.__runRestAction(e.ping,{retransmit:false})};BX.Call.VoximplantCall.Signaling.prototype.sendUserInviteTimeout=function(e){if(BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.userInviteTimeout,e,0)}};BX.Call.VoximplantCall.Signaling.prototype.sendJoinRoom=function(e){return this.__sendMessage(n.joinRoom,{roomId:e})};BX.Call.VoximplantCall.Signaling.prototype.sendLeaveRoom=function(e){return this.__sendMessage(n.leaveRoom,{roomId:e})};BX.Call.VoximplantCall.Signaling.prototype.sendListRooms=function(){return this.__sendMessage(n.listRooms)};BX.Call.VoximplantCall.Signaling.prototype.sendRequestRoomSpeaker=function(e){return this.__sendMessage(n.requestRoomSpeaker,{roomId:e})};BX.Call.VoximplantCall.Signaling.prototype.__sendPullEvent=function(e,t,n){n=n||5;if(!t.userId){throw new Error("userId is not found in data")}if(!BX.type.isArray(t.userId)){t.userId=[t.userId]}if(t.userId.length===0){return}t.callInstanceId=this.call.instanceId;t.senderId=this.call.userId;t.callId=this.call.id;t.requestId=BX.Call.Engine.getInstance().getUuidv4();this.call.log("Sending p2p signaling event "+e+"; "+JSON.stringify(t));BX.CallEngine.getPullClient().sendMessage(t.userId,"im",e,t,n)};BX.Call.VoximplantCall.Signaling.prototype.__sendMessage=function(e,t){if(!this.call.voximplantCall){return}if(!BX.type.isPlainObject(t)){t={}}t.eventName=e;t.requestId=BX.Call.Engine.getInstance().getUuidv4();this.call.voximplantCall.sendMessage(JSON.stringify(t))};BX.Call.VoximplantCall.Signaling.prototype.__runRestAction=function(e,t){if(!BX.type.isPlainObject(t)){t={}}t.callId=this.call.id;t.callInstanceId=this.call.instanceId;t.requestId=BX.Call.Engine.getInstance().getUuidv4();return BX.CallEngine.getRestClient().callMethod(e,t)};BX.Call.VoximplantCall.Peer=function(e){this.userId=e.userId;this.call=e.call;this.ready=!!e.ready;this.calling=false;this.declined=false;this.busy=false;this.inviteTimeout=false;this.endpoint=null;this.direction=e.direction||BX.Call.EndpointDirection.SendRecv;this.stream=null;this.mediaRenderers=[];this.isIncomingVideoAllowed=e.isIncomingVideoAllowed!==false;this.callingTimeout=0;this.connectionRestoreTimeout=0;this.callbacks={onStateChanged:BX.type.isFunction(e.onStateChanged)?e.onStateChanged:BX.DoNothing,onInviteTimeout:BX.type.isFunction(e.onInviteTimeout)?e.onInviteTimeout:BX.DoNothing,onMediaReceived:BX.type.isFunction(e.onMediaReceived)?e.onMediaReceived:BX.DoNothing,onMediaRemoved:BX.type.isFunction(e.onMediaRemoved)?e.onMediaRemoved:BX.DoNothing,onVoiceStarted:BX.type.isFunction(e.onVoiceStarted)?e.onVoiceStarted:BX.DoNothing,onVoiceEnded:BX.type.isFunction(e.onVoiceEnded)?e.onVoiceEnded:BX.DoNothing};this.__onEndpointRemoteMediaAddedHandler=this.__onEndpointRemoteMediaAdded.bind(this);this.__onEndpointRemoteMediaRemovedHandler=this.__onEndpointRemoteMediaRemoved.bind(this);this.__onEndpointVoiceStartHandler=this.__onEndpointVoiceStart.bind(this);this.__onEndpointVoiceEndHandler=this.__onEndpointVoiceEnd.bind(this);this.__onEndpointRemovedHandler=this.__onEndpointRemoved.bind(this);this.calculatedState=this.calculateState()};BX.Call.VoximplantCall.Peer.prototype={setReady:function(e){e=!!e;if(this.ready==e){return}this.ready=e;this.readyStack=(new Error).stack;if(this.calling){clearTimeout(this.callingTimeout);this.calling=false;this.inviteTimeout=false}if(this.ready){this.declined=false;this.busy=false}else{clearTimeout(this.connectionRestoreTimeout)}this.updateCalculatedState()},setDirection:function(e){if(this.direction==e){return}this.direction=e},setDeclined:function(e){this.declined=e;if(this.calling){clearTimeout(this.callingTimeout);this.calling=false}if(this.declined){this.ready=false;this.busy=false}clearTimeout(this.connectionRestoreTimeout);this.updateCalculatedState()},setBusy:function(e){this.busy=e;if(this.calling){clearTimeout(this.callingTimeout);this.calling=false}if(this.busy){this.ready=false;this.declined=false}clearTimeout(this.connectionRestoreTimeout);this.updateCalculatedState()},setEndpoint:function(e){this.log("Adding endpoint with "+e.mediaRenderers.length+" media renderers");this.setReady(true);this.inviteTimeout=false;this.declined=false;clearTimeout(this.connectionRestoreTimeout);if(this.endpoint){this.removeEndpointEventHandlers();this.endpoint=null}this.endpoint=e;for(var t=0;t<this.endpoint.mediaRenderers.length;t++){this.addMediaRenderer(this.endpoint.mediaRenderers[t]);if(this.endpoint.mediaRenderers[t].element){}}this.bindEndpointEventHandlers()},allowIncomingVideo:function(e){if(this.isIncomingVideoAllowed==e){return}this.isIncomingVideoAllowed=!!e},addMediaRenderer:function(e){this.log("Adding media renderer for user"+this.userId,e);this.mediaRenderers.push(e);this.callbacks.onMediaReceived({userId:this.userId,kind:e.kind,mediaRenderer:e});this.updateCalculatedState()},removeMediaRenderer:function(e){console.log("Removing media renderer for user"+this.userId,e);this.log("Removing media renderer for user"+this.userId,e);var t=this.mediaRenderers.indexOf(e);if(t>=0){this.mediaRenderers.splice(t,1)}this.callbacks.onMediaRemoved({userId:this.userId,kind:e.kind,mediaRenderer:e});this.updateCalculatedState()},bindEndpointEventHandlers:function(){this.endpoint.addEventListener(VoxImplant.EndpointEvents.RemoteMediaAdded,this.__onEndpointRemoteMediaAddedHandler);this.endpoint.addEventListener(VoxImplant.EndpointEvents.RemoteMediaRemoved,this.__onEndpointRemoteMediaRemovedHandler);this.endpoint.addEventListener(VoxImplant.EndpointEvents.VoiceStart,this.__onEndpointVoiceStartHandler);this.endpoint.addEventListener(VoxImplant.EndpointEvents.VoiceEnd,this.__onEndpointVoiceEndHandler);this.endpoint.addEventListener(VoxImplant.EndpointEvents.Removed,this.__onEndpointRemovedHandler)},removeEndpointEventHandlers:function(){this.endpoint.removeEventListener(VoxImplant.EndpointEvents.RemoteMediaAdded,this.__onEndpointRemoteMediaAddedHandler);this.endpoint.removeEventListener(VoxImplant.EndpointEvents.RemoteMediaRemoved,this.__onEndpointRemoteMediaRemovedHandler);this.endpoint.removeEventListener(VoxImplant.EndpointEvents.VoiceStart,this.__onEndpointVoiceStartHandler);this.endpoint.removeEventListener(VoxImplant.EndpointEvents.VoiceEnd,this.__onEndpointVoiceEndHandler);this.endpoint.removeEventListener(VoxImplant.EndpointEvents.Removed,this.__onEndpointRemovedHandler)},calculateState:function(){if(this.endpoint)return BX.Call.UserState.Connected;if(this.calling)return BX.Call.UserState.Calling;if(this.inviteTimeout)return BX.Call.UserState.Unavailable;if(this.declined)return BX.Call.UserState.Declined;if(this.busy)return BX.Call.UserState.Busy;if(this.ready)return BX.Call.UserState.Ready;return BX.Call.UserState.Idle},updateCalculatedState:function(){var e=this.calculateState();if(this.calculatedState!=e){this.callbacks.onStateChanged({userId:this.userId,state:e,previousState:this.calculatedState,direction:this.direction});this.calculatedState=e}},isParticipating:function(){return(this.calling||this.ready||this.endpoint)&&!this.declined},waitForConnectionRestore:function(){clearTimeout(this.connectionRestoreTimeout);this.connectionRestoreTimeout=setTimeout(this.onConnectionRestoreTimeout.bind(this),r)},onInvited:function(){this.ready=false;this.inviteTimeout=false;this.declined=false;this.calling=true;clearTimeout(this.connectionRestoreTimeout);if(this.callingTimeout){clearTimeout(this.callingTimeout)}this.callingTimeout=setTimeout(function(){this.onInviteTimeout(true)}.bind(this),3e4);this.updateCalculatedState()},onInviteTimeout:function(e){clearTimeout(this.callingTimeout);if(!this.calling){return}this.calling=false;this.inviteTimeout=true;if(e){this.callbacks.onInviteTimeout({userId:this.userId})}this.updateCalculatedState()},onConnectionRestoreTimeout:function(){if(this.endpoint||!this.ready){return}this.log("Done waiting for connection restoration");this.setReady(false)},__onEndpointRemoteMediaAdded:function(e){this.log("VoxImplant.EndpointEvents.RemoteMediaAdded",e.mediaRenderer);if(e.mediaRenderer.element){e.mediaRenderer.element.volume=0;e.mediaRenderer.element.srcObject=null}this.addMediaRenderer(e.mediaRenderer)},__onEndpointRemoteMediaRemoved:function(e){console.log("VoxImplant.EndpointEvents.RemoteMediaRemoved, ",e.mediaRenderer);this.removeMediaRenderer(e.mediaRenderer)},__onEndpointVoiceStart:function(e){this.callbacks.onVoiceStarted()},__onEndpointVoiceEnd:function(e){this.callbacks.onVoiceEnded()},__onEndpointRemoved:function(e){this.log("VoxImplant.EndpointEvents.Removed",e);if(this.endpoint){this.removeEndpointEventHandlers();this.endpoint=null}if(this.stream){this.stream=null}if(this.ready){this.waitForConnectionRestore()}this.updateCalculatedState()},log:function(){this.call.log.apply(this.call,arguments)},destroy:function(){if(this.stream){this.stream.getTracks().forEach((function(e){e.stop()}));this.stream=null}if(this.endpoint){this.removeEndpointEventHandlers();this.endpoint=null}this.callbacks.onStateChanged=BX.DoNothing;this.callbacks.onInviteTimeout=BX.DoNothing;this.callbacks.onMediaReceived=BX.DoNothing;this.callbacks.onMediaRemoved=BX.DoNothing;clearTimeout(this.callingTimeout);clearTimeout(this.connectionRestoreTimeout);this.callingTimeout=null;this.connectionRestoreTimeout=null}};var c=function(e,t){let n={connection:e.connection,outboundAudio:[],outboundVideo:[],inboundAudio:[],inboundVideo:[]};let i={};if(t.getEndpoints){t.getEndpoints().forEach((e=>i[e.id]=e))}if(!n.connection.timestamp){n.connection.timestamp=Date.now()}for(let t in e.outbound){if(!e.outbound.hasOwnProperty(t)){continue}var l=e.outbound[t];for(var o=0;o<l.length;o++){let e=l[o];e.trackId=t;if("audioLevel"in e){n.outboundAudio.push(e)}else{n.outboundVideo.push(e)}}}for(let t in e.inbound){if(!e.inbound.hasOwnProperty(t)){continue}let l=e.inbound[t];if(!("endpoint"in l)){continue}l.trackId=t;if("audioLevel"in l){n.inboundAudio.push(l)}else{if(i[l.endpoint]){let e=i[l.endpoint].mediaRenderers.find((e=>e.id==l.trackId));if(e&&e.element){l.actualHeight=e.element.videoHeight;l.actualWidth=e.element.videoWidth}}n.inboundVideo.push(l)}}return n};BX.Call.VoximplantCall.Event=l})(); //# sourceMappingURL=voximplant_call.map.js