File manager - Edit - /home/c14075/dragmet-ural.ru/www/bitrix/modules/im/install/js/im/call/plain_call.min.js
Back
(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",negotiationNeeded:"im.call.negotiationNeeded",connectionOffer:"im.call.connectionOffer",connectionAnswer:"im.call.connectionAnswer",iceCandidate:"im.call.iceCandidate"};var t={ping:"Call::ping",answer:"Call::answer",negotiationNeeded:"Call::negotiationNeeded",connectionOffer:"Call::connectionOffer",connectionAnswer:"Call::connectionAnswer",iceCandidate:"Call::iceCandidate",voiceStarted:"Call::voiceStarted",voiceStopped:"Call::voiceStopped",recordState:"Call::recordState",microphoneState:"Call::microphoneState",cameraState:"Call::cameraState",videoPaused:"Call::videoPaused",customMessage:"Call::customMessage",hangup:"Call::hangup",userInviteTimeout:"Call::userInviteTimeout"};var i={offerToReceiveVideo:true,offerToReceiveAudio:true};var n=3e4;var a=1e4;var o=5e3;var l=25e3;var s=5500;BX.Call.PlainCall=function(e){this.superclass.constructor.apply(this,arguments);this.callFromMobile=e.callFromMobile;this.state=e.state||"";this.peers=this.initPeers(this.users);this.signaling=new BX.Call.PlainCall.Signaling({call:this});this.recordState={state:"stopped",userId:0,date:{start:null,pause:[]}};this.deviceList=[];this.turnServer=(BX.browser.IsFirefox()?BX.message("turn_server_firefox"):BX.message("turn_server"))||"turn.calls.bitrix24.com";this.turnServerLogin=BX.message("turn_server_login")||"bitrix";this.turnServerPassword=BX.message("turn_server_password")||"bitrix";this.pingUsersInterval=setInterval(this.pingUsers.bind(this),o);this.pingBackendInterval=setInterval(this.pingBackend.bind(this),l);this.reinviteTimeout=null;this._onUnloadHandler=this._onUnload.bind(this);this.enableMicAutoParameters=e.enableMicAutoParameters!==false;this.microphoneLevelInterval=null;window.addEventListener("unload",this._onUnloadHandler)};BX.extend(BX.Call.PlainCall,BX.Call.AbstractCall);BX.Call.PlainCall.prototype.initPeers=function(e){var t={};for(var i=0;i<e.length;i++){var n=Number(e[i]);if(n==this.userId)continue;t[n]=this.createPeer(n)}return t};BX.Call.PlainCall.prototype.createPeer=function(e){var t=this;return new BX.Call.PlainCall.Peer({call:this,userId:e,ready:e==this.initiatorId,signalingConnected:e==this.initiatorId,isLegacyMobile:e==this.initiatorId&&this.callFromMobile,onMediaReceived:function(e){console.log("onMediaReceived: ",e);t.runCallback(BX.Call.Event.onRemoteMediaReceived,e)},onMediaStopped:function(e){t.runCallback(BX.Call.Event.onRemoteMediaStopped,e)},onStateChanged:this.__onPeerStateChanged.bind(this),onInviteTimeout:this.__onPeerInviteTimeout.bind(this),onRTCStatsReceived:this.__onPeerRTCStatsReceived.bind(this),onNetworkProblem:function(e){t.runCallback(BX.Call.Event.onNetworkProblem,e)}})};BX.Call.PlainCall.prototype.getUsers=function(){var e={};for(var t in this.peers){e[t]=this.peers[t].calculatedState}return e};BX.Call.PlainCall.prototype.isReady=function(){return this.ready};BX.Call.PlainCall.prototype.setVideoEnabled=function(e){e=e===true;if(this.videoEnabled==e){return}this.videoEnabled=e;var t=this.localStreams["main"]&&this.localStreams["main"].getVideoTracks().length>0;if(this.ready&&t!==this.videoEnabled){this.replaceLocalMediaStream().then(function(){var e=this.localStreams["main"]&&this.localStreams["main"].getVideoTracks().length>0;if(this.videoEnabled&&!e){this.videoEnabled=false}this.signaling.sendCameraState(this.users,this.videoEnabled)}.bind(this))}};BX.Call.PlainCall.prototype.setMuted=function(e){e=!!e;if(this.muted==e){return}this.muted=e;if(this.localStreams["main"]){var t=this.localStreams["main"].getAudioTracks();if(t[0]){t[0].enabled=!this.muted}}this.signaling.sendMicrophoneState(this.users,!this.muted);this.sendTalkingState()};BX.Call.PlainCall.prototype.isMuted=function(){return this.muted};BX.Call.PlainCall.prototype.setCameraId=function(e){if(this.cameraId==e){return}this.cameraId=e;if(this.ready&&this.videoEnabled){BX.debounce(this.replaceLocalMediaStream,100,this)()}};BX.Call.PlainCall.prototype.setMicrophoneId=function(e){if(this.microphoneId==e){return}this.microphoneId=e;if(this.ready){BX.debounce(this.replaceLocalMediaStream,100,this)()}};BX.Call.PlainCall.prototype.getCurrentMicrophoneId=function(){if(!this.localStreams["main"]){return this.microphoneId}var e=this.localStreams["main"].getAudioTracks();if(e.length>0){var t=e[0].getSettings();return t.deviceId}else{return this.microphoneId}};BX.Call.PlainCall.prototype.useHdVideo=function(e){this.videoHd=e===true};BX.Call.PlainCall.prototype.sendRecordState=function(e){e.senderId=this.userId;if(!this.__changeRecordState(e)){return false}var t=[this.userId].concat(this.users);this.signaling.sendRecordState(t,this.recordState)};BX.Call.PlainCall.prototype.stopSendingStream=function(e){};BX.Call.PlainCall.prototype.allowVideoFrom=function(e){};BX.Call.PlainCall.prototype.inviteUsers=function(e){var t=this;if(!BX.type.isPlainObject(e)){e={}}var i=BX.type.isArray(e.users)?e.users:Object.keys(this.peers);this.ready=true;if(e.localStream instanceof MediaStream&&!this.localStreams["main"]){this.localStreams["main"]=e.localStream}this.getLocalMediaStream("main",true).then((function(){return t.signaling.inviteUsers({userIds:i,video:t.videoEnabled?"Y":"N"})})).then((function(e){t.state=BX.Call.State.Connected;t.runCallback(BX.Call.Event.onJoin,{local:true});for(var n=0;n<i.length;n++){var a=Number(i[n]);if(!t.peers[a]){t.peers[a]=t.createPeer(a);t.runCallback(BX.Call.Event.onUserInvited,{userId:a})}t.peers[a].onInvited();t.scheduleRepeatInvite()}})).catch((function(e){console.error(e);t.runCallback(BX.Call.Event.onCallFailure,e)}))};BX.Call.PlainCall.prototype.scheduleRepeatInvite=function(){clearTimeout(this.reinviteTimeout);this.reinviteTimeout=setTimeout(this.repeatInviteUsers.bind(this),s)};BX.Call.PlainCall.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.PlainCall.prototype.getMediaConstraints=function(e){var t={};var i=e.videoEnabled?{}:false;hdVideo=!!e.hdVideo;var n=navigator.mediaDevices.getSupportedConstraints?navigator.mediaDevices.getSupportedConstraints():{};if(this.microphoneId){t.deviceId={ideal:this.microphoneId}}if(!this.enableMicAutoParameters){if(n.echoCancellation){t.echoCancellation=false}if(n.noiseSuppression){t.noiseSuppression=false}if(n.autoGainControl){t.autoGainControl=false}}if(i){if(this.cameraId){i.deviceId={exact:this.cameraId}}if(hdVideo){i.width={max:1920,min:1280};i.height={max:1080,min:720}}else{i.width={ideal:640};i.height={ideal:360}}}return{audio:t,video:i}};BX.Call.PlainCall.prototype.getUserMedia=function(e){return new Promise(function(t,i){var n=e[0];navigator.mediaDevices.getUserMedia(n).then((function(e){t(e)}),function(a){this.log("getUserMedia error: ",a);this.log("Current constraints",n);if(e.length>1){this.getUserMedia(e.slice(1)).then((function(e){t(e)}),(function(e){i(e)}))}else{this.log("Last fallback constraints used, failing");i(a)}}.bind(this))}.bind(this))};BX.Call.PlainCall.prototype.getLocalMediaStream=function(e,t){var i=this;if(!BX.type.isNotEmptyString(e)){e="main"}this.log("Requesting access to media devices");return new Promise((function(n,a){if(i.localStreams[e]){return n(i.localStreams[e])}var o=[];if(i.videoEnabled){if(i.videoHd){o.push(i.getMediaConstraints({videoEnabled:true,hdVideo:true}))}o.push(i.getMediaConstraints({videoEnabled:true,hdVideo:false}));if(t){o.push(i.getMediaConstraints({videoEnabled:false}))}}else{o.push(i.getMediaConstraints({videoEnabled:false}))}i.getUserMedia(o).then((function(t){i.log("Local media stream received");i.localStreams[e]=t;i.runCallback(BX.Call.Event.onLocalMediaReceived,{tag:e,stream:t});if(e==="main"){i.attachVoiceDetection();if(i.muted){var a=t.getAudioTracks();if(a[0]){a[0].enabled=false}}}if(i.deviceList.length===0){navigator.mediaDevices.enumerateDevices().then((function(e){i.deviceList=e;i.runCallback(BX.Call.Event.onDeviceListUpdated,{deviceList:i.deviceList})}))}n(i.localStreams[e])})).catch((function(t){i.log("Could not get local media stream.",t);i.log("Request constraints: .",o);i.runCallback("onLocalMediaError",{tag:e,error:t});a(t)}))}))};BX.Call.PlainCall.prototype.startMediaCapture=function(){return this.getLocalMediaStream()};BX.Call.PlainCall.prototype.attachVoiceDetection=function(){if(this.voiceDetection){this.voiceDetection.destroy()}if(this.microphoneLevelInterval){clearInterval(this.microphoneLevelInterval)}try{this.voiceDetection=new BX.SimpleVAD({mediaStream:this.localStreams["main"],onVoiceStarted:this.onLocalVoiceStarted.bind(this),onVoiceStopped:this.onLocalVoiceStopped.bind(this)});this.microphoneLevelInterval=setInterval(function(){this.microphoneLevel=this.voiceDetection.currentVolume}.bind(this),200)}catch(e){this.log("Could not attach voice detection to media stream")}};BX.Call.PlainCall.prototype.getDisplayMedia=function(){return new Promise((function(e,t){if(window["BXDesktopSystem"]){navigator.mediaDevices.getUserMedia({video:{mandatory:{chromeMediaSource:"screen",maxWidth:1920,maxHeight:1080,maxFrameRate:5}}}).then((function(t){e(t)}),(function(e){t(e)}))}else if(navigator.mediaDevices.getDisplayMedia){navigator.mediaDevices.getDisplayMedia({video:{width:{max:1920},height:{max:1080},frameRate:{max:5}}}).then((function(t){e(t)}),(function(e){t(e)}))}else{console.error("Screen sharing is not supported");t("Screen sharing is not supported")}}))};BX.Call.PlainCall.prototype.startScreenSharing=function(e){var t=this;e=!!e;if(this.localStreams["screen"]&&!e){return}this.getDisplayMedia().then((function(e){t.localStreams["screen"]=e;e.getVideoTracks().forEach((function(e){e.addEventListener("ended",(function(){t.stopScreenSharing()}))}));t.runCallback(BX.Call.Event.onUserScreenState,{userId:t.userId,screenState:true});if(t.ready){for(var i in t.peers){if(t.peers[i].calculatedState===BX.Call.UserState.Connected){t.peers[i].sendMedia()}}}})).catch(function(e){this.log(e)}.bind(this))};BX.Call.PlainCall.prototype.stopScreenSharing=function(){if(!this.localStreams["screen"]){return}this.localStreams["screen"].getTracks().forEach((function(e){e.stop()}));this.localStreams["screen"]=null;this.runCallback(BX.Call.Event.onUserScreenState,{userId:this.userId,screenState:false});for(var e in this.peers){if(this.peers[e].calculatedState===BX.Call.UserState.Connected){this.peers[e].sendMedia()}}};BX.Call.PlainCall.prototype.isScreenSharingStarted=function(){return this.localStreams["screen"]instanceof MediaStream};BX.Call.PlainCall.prototype.onLocalVoiceStarted=function(){this.talking=true;this.sendTalkingState()};BX.Call.PlainCall.prototype.onLocalVoiceStopped=function(){this.talking=false;this.sendTalkingState()};BX.Call.PlainCall.prototype.sendTalkingState=function(){if(this.talking&&!this.muted){this.runCallback(BX.Call.Event.onUserVoiceStarted,{userId:this.userId,local:true});this.signaling.sendVoiceStarted({userId:this.users})}else{this.runCallback(BX.Call.Event.onUserVoiceStopped,{userId:this.userId,local:true});this.signaling.sendVoiceStopped({userId:this.users})}};BX.Call.PlainCall.prototype.sendCustomMessage=function(e){this.signaling.sendCustomMessage({userId:this.users,message:e})};BX.Call.PlainCall.prototype.answer=function(e){var t=this;if(!BX.type.isPlainObject(e)){e={}}this.ready=true;this.videoEnabled=e.useVideo==true;this.enableMicAutoParameters=e.enableMicAutoParameters!==false;if(e.localStream instanceof MediaStream){this.localStreams["main"]=e.localStream}return new Promise((function(e,i){t.getLocalMediaStream("main",true).then((function(){t.state=BX.Call.State.Connected;t.runCallback(BX.Call.Event.onJoin,{local:true});return t.sendAnswer()}),(function(e){t.runCallback(BX.Call.Event.onCallFailure,e)})).then((function(){e()}))}))};BX.Call.PlainCall.prototype.sendAnswer=function(){this.signaling.sendAnswer()};BX.Call.PlainCall.prototype.decline=function(t,i){this.ready=false;var n={callId:this.id,callInstanceId:this.instanceId};if(typeof t!="undefined"){n.code=t}if(typeof i!="undefined"){n.reason=i}BX.CallEngine.getRestClient().callMethod(e.decline,n).then(function(){this.destroy()}.bind(this))};BX.Call.PlainCall.prototype.hangup=function(){if(!this.ready){var e=new Error("Hangup in wrong state");this.log(e);return Promise.reject(e)}var t=new Error;t.name="Call stack:";this.log("Hangup received \n"+t.stack);this.ready=false;this.state=BX.Call.State.Proceeding;return new Promise(function(e,t){for(var i in this.peers){this.peers[i].disconnect()}this.runCallback(BX.Call.Event.onLeave,{local:true});this.signaling.sendHangup({userId:this.users})}.bind(this))};BX.Call.PlainCall.prototype.pingUsers=function(){if(this.ready){this.signaling.sendPingToUsers({userId:this.users.concat(this.userId)})}};BX.Call.PlainCall.prototype.pingBackend=function(){if(this.ready){this.signaling.sendPingToBackend()}};BX.Call.PlainCall.prototype.getState=function(){};BX.Call.PlainCall.prototype.replaceLocalMediaStream=function(e){e=e||"main";if(this.localStreams[e]){BX.webrtc.stopMediaStream(this.localStreams[e]);this.localStreams[e]=null}return new Promise(function(t,i){this.getLocalMediaStream(e).then(function(){if(this.ready){for(var i in this.peers){if(this.peers[i].isReady()){this.peers[i].replaceMediaStream(e)}}}t()}.bind(this)).catch(function(e){console.error("Could not get access to hardware; don't really know what to do. error:",e);i(e)}.bind(this))}.bind(this))};BX.Call.PlainCall.prototype.sendAllStreams=function(e){if(!this.peers[e])return;if(!this.peers[e].isReady())return;for(var t in this.localStreams){if(this.localStreams[t]){this.peers[e].sendMedia()}}};BX.Call.PlainCall.prototype.isAnyoneParticipating=function(){for(var e in this.peers){if(this.peers[e].isParticipating()){return true}}return false};BX.Call.PlainCall.prototype.getParticipatingUsers=function(){var e=[];for(var t in this.peers){if(this.peers[t].isParticipating()){e.push(t)}}return e};BX.Call.PlainCall.prototype.addJoinedUsers=function(e){for(var t=0;t<e.length;t++){var i=Number(e[t]);if(i==this.userId||this.peers[i]){continue}this.peers[i]=this.createPeer(i);if(!this.users.includes(i)){this.users.push(i)}}};BX.Call.PlainCall.prototype.addInvitedUsers=function(e){for(var t=0;t<e.length;t++){var i=Number(e[t]);if(i==this.userId){continue}if(this.peers[i]){if(this.peers[i].calculatedState===BX.Call.UserState.Failed||this.peers[i].calculatedState===BX.Call.UserState.Idle){this.peers[i].onInvited()}}else{this.peers[i]=this.createPeer(i);this.runCallback(BX.Call.Event.onUserInvited,{userId:i});this.peers[i].onInvited()}if(!this.users.includes(i)){this.users.push(i)}}};BX.Call.PlainCall.prototype.__changeRecordState=function(e){if(e.action!==BX.Call.View.RecordState.Started&&this.recordState.userId!=e.senderId){return false}if(e.action===BX.Call.View.RecordState.Started){if(this.recordState.state!==BX.Call.View.RecordState.Stopped){return false}this.recordState.state=BX.Call.View.RecordState.Started;this.recordState.userId=e.senderId;this.recordState.date.start=e.date;this.recordState.date.pause=[]}else if(e.action===BX.Call.View.RecordState.Paused){if(this.recordState.state!==BX.Call.View.RecordState.Started){return false}this.recordState.state=BX.Call.View.RecordState.Paused;this.recordState.date.pause.push({start:e.date,finish:null})}else if(e.action===BX.Call.View.RecordState.Resumed){if(this.recordState.state!==BX.Call.View.RecordState.Paused){return false}this.recordState.state=BX.Call.View.RecordState.Started;var t=this.recordState.date.pause.find((function(e){return e.finish===null}));if(t){t.finish=e.date}}else if(e.action===BX.Call.View.RecordState.Stopped){this.recordState.state=BX.Call.View.RecordState.Stopped;this.recordState.userId=0;this.recordState.date.start=null;this.recordState.date.pause=[]}return true};BX.Call.PlainCall.prototype.__onPullEvent=function(e,t,i){var n={"Call::answer":this.__onPullEventAnswer.bind(this),"Call::hangup":this.__onPullEventHangup.bind(this),"Call::ping":this.__onPullEventPing.bind(this),"Call::negotiationNeeded":this.__onPullEventNegotiationNeeded.bind(this),"Call::connectionOffer":this.__onPullEventConnectionOffer.bind(this),"Call::connectionAnswer":this.__onPullEventConnectionAnswer.bind(this),"Call::iceCandidate":this.__onPullEventIceCandidate.bind(this),"Call::voiceStarted":this.__onPullEventVoiceStarted.bind(this),"Call::voiceStopped":this.__onPullEventVoiceStopped.bind(this),"Call::microphoneState":this.__onPullEventMicrophoneState.bind(this),"Call::cameraState":this.__onPullEventCameraState.bind(this),"Call::videoPaused":this.__onPullEventVideoPaused.bind(this),"Call::recordState":this.__onPullEventRecordState.bind(this),"Call::usersJoined":this.__onPullEventUsersJoined.bind(this),"Call::usersInvited":this.__onPullEventUsersInvited.bind(this),"Call::userInviteTimeout":this.__onPullEventUserInviteTimeout.bind(this),"Call::associatedEntityReplaced":this.__onPullEventAssociatedEntityReplaced.bind(this),"Call::finish":this.__onPullEventFinish.bind(this),"Call::repeatAnswer":this.__onPullEventRepeatAnswer.bind(this),"Call::customMessage":this.__onPullEventCallCustomMessage.bind(this)};if(n[e]){if(e==="Call::ping"){if(t.senderId!=this.userId||t.instanceId!=this.instanceId){this.log("Signaling: ping from user "+t.senderId)}}else{this.log("Signaling: "+e+"; Parameters: "+JSON.stringify(t))}n[e].call(this,t)}};BX.Call.PlainCall.prototype.__onPullEventUsersJoined=function(e){if(!this.ready){return}var t=e.users;this.addJoinedUsers(t)};BX.Call.PlainCall.prototype.__onPullEventUsersInvited=function(e){if(!this.ready){return}var t=e.users;this.addInvitedUsers(t)};BX.Call.PlainCall.prototype.__onPullEventUserInviteTimeout=function(e){this.log("__onPullEventUserInviteTimeout",e);var t=e.failedUserId;if(this.peers[t]){this.peers[t].onInviteTimeout(false)}};BX.Call.PlainCall.prototype.__onPullEventAnswer=function(e){var t=Number(e.senderId);if(t==this.userId){return this.__onPullEventAnswerSelf(e)}if(!this.ready){return}if(!this.peers[t]){return}if(this.peers[t].isReady()){this.log("Received answer for user "+t+" in ready state, ignoring");return}this.peers[t].setSignalingConnected(true);this.peers[t].setReady(true);this.peers[t].isLegacyMobile=e.isLegacyMobile===true;if(this.ready){this.sendAllStreams(t)}};BX.Call.PlainCall.prototype.__onPullEventAnswerSelf=function(e){if(e.callInstanceId===this.instanceId)return;if(this.ready){this.log("Received remote self-answer in ready state, ignoring");return}this.log("Call was answered elsewhere");this.runCallback(BX.Call.Event.onJoin,{local:false})};BX.Call.PlainCall.prototype.__onPullEventHangup=function(e){var t=e.senderId;if(this.userId==t){if(this.instanceId!=e.callInstanceId){this.runCallback(BX.Call.Event.onLeave,{local:false})}return}if(!this.peers[t])return;this.peers[t].disconnect(e.code);this.peers[t].setReady(false);if(e.code==603){this.peers[t].setDeclined(true)}if(!this.isAnyoneParticipating()){this.hangup()}};BX.Call.PlainCall.prototype.__onPullEventPing=function(e){if(e.callInstanceId==this.instanceId){return}var t=this.peers[e.senderId];if(!t)return;t.setSignalingConnected(true)};BX.Call.PlainCall.prototype.__onPullEventNegotiationNeeded=function(e){if(!this.ready){return}var t=this.peers[e.senderId];if(!t){return}t.setReady(true);if(e.restart){t.reconnect()}else{t.onNegotiationNeeded()}};BX.Call.PlainCall.prototype.__onPullEventConnectionOffer=function(e){if(!this.ready){return}var t=this.peers[e.senderId];if(!t){return}t.setReady(true);t.setUserAgent(e.userAgent);t.setConnectionOffer(e.connectionId,e.sdp,e.tracks)};BX.Call.PlainCall.prototype.__onPullEventConnectionAnswer=function(e){if(!this.ready){return}var t=this.peers[e.senderId];if(!t)return;var i=e.connectionId;t.setUserAgent(e.userAgent);t.setConnectionAnswer(i,e.sdp,e.tracks)};BX.Call.PlainCall.prototype.__onPullEventIceCandidate=function(e){if(!this.ready){return}var t=this.peers[e.senderId];var i;if(!t)return;try{i=e.candidates;for(var n=0;n<i.length;n++){t.addIceCandidate(e.connectionId,i[n])}}catch(e){this.log("Error parsing serialized candidate: ",e)}};BX.Call.PlainCall.prototype.__onPullEventVoiceStarted=function(e){this.runCallback(BX.Call.Event.onUserVoiceStarted,{userId:e.senderId})};BX.Call.PlainCall.prototype.__onPullEventVoiceStopped=function(e){this.runCallback(BX.Call.Event.onUserVoiceStopped,{userId:e.senderId})};BX.Call.PlainCall.prototype.__onPullEventMicrophoneState=function(e){this.runCallback(BX.Call.Event.onUserMicrophoneState,{userId:e.senderId,microphoneState:e.microphoneState})};BX.Call.PlainCall.prototype.__onPullEventCameraState=function(e){this.runCallback(BX.Call.Event.onUserCameraState,{userId:e.senderId,cameraState:e.cameraState})};BX.Call.PlainCall.prototype.__onPullEventVideoPaused=function(e){var t=this.peers[e.senderId];if(!t){return}this.runCallback(BX.Call.Event.onUserVideoPaused,{userId:e.senderId,videoPaused:e.videoPaused});t.holdOutgoingVideo(!!e.videoPaused)};BX.Call.PlainCall.prototype.__onPullEventRecordState=function(e){this.runCallback(BX.Call.Event.onUserRecordState,{userId:e.senderId,recordState:e.recordState})};BX.Call.PlainCall.prototype.__onPullEventAssociatedEntityReplaced=function(e){if(e.call&&e.call.ASSOCIATED_ENTITY){this.associatedEntity=e.call.ASSOCIATED_ENTITY}};BX.Call.PlainCall.prototype.__onPullEventFinish=function(e){this.destroy()};BX.Call.PlainCall.prototype.__onPullEventRepeatAnswer=function(){if(this.ready){this.signaling.sendAnswer({userId:this.userId},true)}};BX.Call.PlainCall.prototype.__onPullEventCallCustomMessage=function(e){this.runCallback(BX.Call.Event.onCustomMessage,{message:e.message})};BX.Call.PlainCall.prototype.__onPeerStateChanged=function(e){this.runCallback(BX.Call.Event.onUserStateChanged,e);if(e.state==BX.Call.UserState.Failed||e.state==BX.Call.UserState.Unavailable){if(!this.isAnyoneParticipating()){this.hangup().then(this.destroy.bind(this)).catch(function(e){this.destroy()}.bind(this))}}else if(e.state==BX.Call.UserState.Connected){this.signaling.sendMicrophoneState(e.userId,!this.muted);this.signaling.sendCameraState(e.userId,this.videoEnabled);this.wasConnected=true}};BX.Call.PlainCall.prototype.__onPeerInviteTimeout=function(e){if(!this.ready){return}this.signaling.sendUserInviteTimeout({userId:this.users,failedUserId:e.userId})};BX.Call.PlainCall.prototype.__onPeerRTCStatsReceived=function(e){this.runCallback(BX.Call.Event.onRTCStatsReceived,e)};BX.Call.PlainCall.prototype._onUnload=function(t){if(!this.ready){return}BX.CallEngine.getRestClient().callMethod(e.hangup,{callId:this.id,callInstanceId:this.instanceId});for(var i in this.peers){this.peers[i].disconnect()}};BX.Call.PlainCall.prototype.destroy=function(){var e=new Error;e.name="Call stack:";this.log("Call destroy \n"+e.stack);for(var t in this.peers){if(this.peers[t]){this.peers[t].destroy()}}for(var i in this.localStreams){if(this.localStreams[i]){BX.webrtc.stopMediaStream(this.localStreams[i]);this.localStreams[i]=null}}if(this.voiceDetection){this.voiceDetection.destroy();this.voiceDetection=null}window.removeEventListener("unload",this._onUnloadHandler);clearInterval(this.pingUsersInterval);clearInterval(this.pingBackendInterval);clearInterval(this.microphoneLevelInterval);clearTimeout(this.reinviteTimeout);this.superclass.destroy.apply(this,arguments)};BX.Call.PlainCall.Signaling=function(e){this.call=e.call};BX.Call.PlainCall.Signaling.prototype.isIceTricklingAllowed=function(){return BX.CallEngine.getPullClient().isPublishingSupported()};BX.Call.PlainCall.Signaling.prototype.inviteUsers=function(t){return this.__runRestAction(e.invite,t)};BX.Call.PlainCall.Signaling.prototype.sendAnswer=function(i,n){if(n&&BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.answer,i)}else{return this.__runRestAction(e.answer,i)}};BX.Call.PlainCall.Signaling.prototype.sendConnectionOffer=function(i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.connectionOffer,i)}else{return this.__runRestAction(e.connectionOffer,i)}};BX.Call.PlainCall.Signaling.prototype.sendConnectionAnswer=function(i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.connectionAnswer,i)}else{return this.__runRestAction(e.connectionAnswer,i)}};BX.Call.PlainCall.Signaling.prototype.sendIceCandidate=function(i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.iceCandidate,i)}else{return this.__runRestAction(e.iceCandidate,i)}};BX.Call.PlainCall.Signaling.prototype.sendNegotiationNeeded=function(i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.negotiationNeeded,i)}else{return this.__runRestAction(e.negotiationNeeded,i)}};BX.Call.PlainCall.Signaling.prototype.sendVoiceStarted=function(e){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.voiceStarted,e)}};BX.Call.PlainCall.Signaling.prototype.sendVoiceStopped=function(e){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.voiceStopped,e)}};BX.Call.PlainCall.Signaling.prototype.sendMicrophoneState=function(e,i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.microphoneState,{userId:e,microphoneState:i},0)}};BX.Call.PlainCall.Signaling.prototype.sendCameraState=function(e,i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.cameraState,{userId:e,cameraState:i},0)}};BX.Call.PlainCall.Signaling.prototype.sendRecordState=function(e,i){if(BX.CallEngine.getPullClient().isPublishingSupported()){return this.__sendPullEvent(t.recordState,{userId:e,recordState:i},0)}};BX.Call.PlainCall.Signaling.prototype.sendPingToUsers=function(e){if(BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.ping,e,5)}};BX.Call.PlainCall.Signaling.prototype.sendCustomMessage=function(e){if(BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.customMessage,e,5)}};BX.Call.PlainCall.Signaling.prototype.sendPingToBackend=function(){var t=!BX.CallEngine.getPullClient().isPublishingEnabled();this.__runRestAction(e.ping,{retransmit:t})};BX.Call.PlainCall.Signaling.prototype.sendUserInviteTimeout=function(e){if(BX.CallEngine.getPullClient().isPublishingEnabled()){this.__sendPullEvent(t.userInviteTimeout,e,0)}};BX.Call.PlainCall.Signaling.prototype.sendHangup=function(i){if(BX.CallEngine.getPullClient().isPublishingSupported()){this.__sendPullEvent(t.hangup,i,3600);i.retransmit=false;return this.__runRestAction(e.hangup,i)}else{i.retransmit=true;return this.__runRestAction(e.hangup,i)}};BX.Call.PlainCall.Signaling.prototype.__sendPullEvent=function(e,t,i){i=i||5;if(!t.userId){throw new Error("userId is not found in data")}if(!BX.type.isArray(t.userId)){t.userId=[t.userId]}t.callInstanceId=this.call.instanceId;t.senderId=this.call.userId;t.callId=this.call.id;t.requestId=BX.Call.Engine.getInstance().getUuidv4();if(e=="Call::ping"){this.call.log("Sending p2p signaling event "+e)}else{this.call.log("Sending p2p signaling event "+e+"; "+JSON.stringify(t))}BX.CallEngine.getPullClient().sendMessage(t.userId,"im",e,t,i)};BX.Call.PlainCall.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();if(e=="Call::ping"){this.call.log("Sending ajax-based signaling event "+e)}else{this.call.log("Sending ajax-based signaling event "+e+"; "+JSON.stringify(t))}return BX.CallEngine.getRestClient().callMethod(e,t).catch((function(e){console.error(e)}))};BX.Call.PlainCall.Peer=function(e){this.call=e.call;this.userId=e.userId;this.ready=e.ready===true;this.calling=false;this.inviteTimeout=false;this.declined=false;this.busy=false;this.signalingConnected=e.signalingConnected===true;this.failureReason="";this.userAgent="";this.isFirefox=false;this.isChrome=false;this.isLegacyMobile=e.isLegacyMobile===true;this.calculatedState=this.calculateState();this.localStreams={main:null,screen:null};this.videoSender=null;this.audioSender=null;this.screenSender=null;this.peerConnection=null;this.peerConnectionId=null;this.pendingIceCandidates={};this.localIceCandidates=[];this.trackList={};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,onMediaStopped:BX.type.isFunction(e.onMediaStopped)?e.onMediaStopped:BX.DoNothing,onRTCStatsReceived:BX.type.isFunction(e.onRTCStatsReceived)?e.onRTCStatsReceived:BX.DoNothing,onNetworkProblem:BX.type.isFunction(e.onNetworkProblem)?e.onNetworkProblem:BX.DoNothing};this.answerTimeout=null;this.callingTimeout=null;this.connectionTimeout=null;this.signalingConnectionTimeout=null;this.candidatesTimeout=null;this.statsInterval=null;this.connectionOfferReplyTimeout=null;this.negotiationNeededReplyTimeout=null;this.reconnectAfterDisconnectTimeout=null;this.connectionAttempt=0;this.hasStun=false;this.hasTurn=false;this._outgoingVideoTrack=null;Object.defineProperty(this,"outgoingVideoTrack",{get:function(){return this._outgoingVideoTrack},set:function(e){if(this._outgoingVideoTrack){this._outgoingVideoTrack.stop()}this._outgoingVideoTrack=e;if(this._outgoingVideoTrack){this._outgoingVideoTrack.enabled=!this.outgoingVideoHoldState}}});this._outgoingScreenTrack=null;Object.defineProperty(this,"outgoingScreenTrack",{get:function(){return this._outgoingScreenTrack},set:function(e){if(this._outgoingScreenTrack){this._outgoingScreenTrack.stop()}this._outgoingScreenTrack=e;if(this._outgoingScreenTrack){this._outgoingScreenTrack.enabled=!this.outgoingVideoHoldState}}});this._incomingAudioTrack=null;this._incomingVideoTrack=null;this._incomingScreenTrack=null;Object.defineProperty(this,"incomingAudioTrack",{get:this._mediaGetter("_incomingAudioTrack"),set:this._mediaSetter("_incomingAudioTrack","audio")});Object.defineProperty(this,"incomingVideoTrack",{get:this._mediaGetter("_incomingVideoTrack"),set:this._mediaSetter("_incomingVideoTrack","video")});Object.defineProperty(this,"incomingScreenTrack",{get:this._mediaGetter("_incomingScreenTrack"),set:this._mediaSetter("_incomingScreenTrack","screen")});this.outgoingVideoHoldState=false;this._onPeerConnectionIceCandidateHandler=this._onPeerConnectionIceCandidate.bind(this);this._onPeerConnectionIceConnectionStateChangeHandler=this._onPeerConnectionIceConnectionStateChange.bind(this);this._onPeerConnectionIceGatheringStateChangeHandler=this._onPeerConnectionIceGatheringStateChange.bind(this);this._onPeerConnectionSignalingStateChangeHandler=this._onPeerConnectionSignalingStateChange.bind(this);this._onPeerConnectionTrackHandler=this._onPeerConnectionTrack.bind(this);this._onPeerConnectionRemoveStreamHandler=this._onPeerConnectionRemoveStream.bind(this);this._updateTracksDebounced=BX.debounce(this._updateTracks.bind(this),50);this._waitTurnCandidatesTimeout=null};BX.Call.PlainCall.Peer.prototype._mediaGetter=function(e){return function(){return this[e]}.bind(this)};BX.Call.PlainCall.Peer.prototype._mediaSetter=function(e,t){return function(i){if(this[e]!=i){this[e]=i;if(i){this.callbacks.onMediaReceived({userId:this.userId,kind:t,track:i})}else{this.callbacks.onMediaStopped({userId:this.userId,kind:t})}}}.bind(this)};BX.Call.PlainCall.Peer.prototype.sendMedia=function(e){if(!this.peerConnection){if(!this.isInitiator()){this.log("waiting for the other side to send connection offer");this.sendNegotiationNeeded(false);return}}if(!this.peerConnection){var t=BX.Call.Engine.getInstance().getUuidv4();this._createPeerConnection(t)}this.updateOutgoingTracks();this.applyResolutionScale();if(!e){this.createAndSendOffer()}};BX.Call.PlainCall.Peer.prototype.updateOutgoingTracks=function(){if(!this.peerConnection){return}var e;var t;var i;if(this.call.localStreams["main"]&&this.call.localStreams["main"].getAudioTracks().length>0){e=this.call.localStreams["main"].getAudioTracks()[0]}if(this.call.localStreams["screen"]&&this.call.localStreams["screen"].getVideoTracks().length>0){i=this.call.localStreams["screen"].getVideoTracks()[0]}if(this.call.localStreams["main"]&&this.call.localStreams["main"].getVideoTracks().length>0){t=this.call.localStreams["main"].getVideoTracks()[0]}this.outgoingVideoTrack=t?t.clone():null;this.outgoingScreenTrack=i?i.clone():null;var n=[];if(e){n.push(e.id+" (audio)")}if(t){n.push(t.id+" ("+t.kind+")")}if(i){n.push(i.id+" ("+i.kind+")")}console.log("User: "+this.userId+"; Sending media streams. Tracks: "+n.join("; "));if(this.videoSender&&this.outgoingVideoTrack){this.videoSender.replaceTrack(this.outgoingVideoTrack)}if(!this.videoSender&&this.outgoingVideoTrack){this.videoSender=this.peerConnection.addTrack(this.outgoingVideoTrack)}if(this.videoSender&&!this.outgoingVideoTrack){this.peerConnection.removeTrack(this.videoSender);this.videoSender=null}if(this.screenSender&&this.outgoingScreenTrack){this.screenSender.replaceTrack(this.outgoingScreenTrack)}if(!this.screenSender&&this.outgoingScreenTrack){this.screenSender=this.peerConnection.addTrack(this.outgoingScreenTrack)}if(this.screenSender&&!this.outgoingScreenTrack){this.peerConnection.removeTrack(this.screenSender);this.screenSender=null}if(this.audioSender&&e){this.audioSender.replaceTrack(e)}if(!this.audioSender&&e){this.audioSender=this.peerConnection.addTrack(e)}if(this.audioSender&&!e){this.peerConnection.removeTrack(this.audioSender);this.audioSender=null}};BX.Call.PlainCall.Peer.prototype.getSenderMid=function(e){if(e===null||!this.peerConnection){return null}var t=this.peerConnection.getTransceivers().find((function(t){return t.sender==e}));return t?t.mid:null};BX.Call.PlainCall.Peer.prototype.applyResolutionScale=function(e){if(!this.videoSender){return}var t=e||(this.screenSender?4:1);var i=this.videoSender.getParameters();if(i.encodings&&i.encodings.length>0){i.encodings[0].scaleResolutionDownBy=t;this.videoSender.setParameters(i)}};BX.Call.PlainCall.Peer.prototype.replaceMediaStream=function(e){if(this.isRenegotiationSupported()){this.sendMedia()}else{this.localStreams[e]=this.call.getLocalStream(e);this.reconnect()}};BX.Call.PlainCall.Peer.prototype.holdOutgoingVideo=function(e){if(this.outgoingVideoHoldState==e){return}this.outgoingVideoHoldState=e;if(this._outgoingVideoTrack){this._outgoingVideoTrack.enabled=!this.outgoingVideoHoldState}};BX.Call.PlainCall.Peer.prototype.isInitiator=function(){return this.call.userId<this.userId};BX.Call.PlainCall.Peer.prototype.isRenegotiationSupported=function(){return true;return BX.browser.IsChrome()&&this.isChrome};BX.Call.PlainCall.Peer.prototype.setReady=function(e){this.ready=e;if(this.ready){this.declined=false;this.busy=false}if(this.calling){clearTimeout(this.callingTimeout);this.calling=false}this.updateCalculatedState()};BX.Call.PlainCall.Peer.prototype.isReady=function(){return this.ready};BX.Call.PlainCall.Peer.prototype.onInvited=function(){this.ready=false;this.inviteTimeout=false;this.declined=false;this.calling=true;if(this.callingTimeout){clearTimeout(this.callingTimeout)}this.callingTimeout=setTimeout(function(){this.onInviteTimeout(true)}.bind(this),3e4);this.updateCalculatedState()};BX.Call.PlainCall.Peer.prototype.onInviteTimeout=function(e){clearTimeout(this.callingTimeout);this.calling=false;this.inviteTimeout=true;if(e){this.callbacks.onInviteTimeout({userId:this.userId})}this.updateCalculatedState()};BX.Call.PlainCall.Peer.prototype.setUserAgent=function(e){this.userAgent=e;this.isFirefox=e.toLowerCase().indexOf("firefox")!=-1;this.isChrome=e.toLowerCase().indexOf("chrome")!=-1;this.isLegacyMobile=e==="Bitrix Legacy Mobile"};BX.Call.PlainCall.Peer.prototype.getUserAgent=function(){return this.userAgent};BX.Call.PlainCall.Peer.prototype.isParticipating=function(){if(this.calling)return true;if(this.declined||this.busy)return false;if(this.peerConnection){var e=this.peerConnection.iceConnectionState;if(e=="checking"||e=="connected"||e=="completed"){return true}}return false};BX.Call.PlainCall.Peer.prototype.setSignalingConnected=function(e){this.signalingConnected=e;this.updateCalculatedState();if(this.signalingConnected)this.refreshSignalingTimeout();else this.stopSignalingTimeout()};BX.Call.PlainCall.Peer.prototype.isSignalingConnected=function(){return this.signalingConnected};BX.Call.PlainCall.Peer.prototype.setDeclined=function(e){this.declined=e;if(this.calling){clearTimeout(this.callingTimeout);this.calling=false}this.updateCalculatedState()};BX.Call.PlainCall.Peer.prototype.setBusy=function(e){this.busy=e;if(this.calling){clearTimeout(this.callingTimeout);this.calling=false}this.updateCalculatedState()};BX.Call.PlainCall.Peer.prototype.isDeclined=function(){return this.declined};BX.Call.PlainCall.Peer.prototype.updateCalculatedState=function(){var e=this.calculateState();if(this.calculatedState!=e){this.callbacks.onStateChanged({userId:this.userId,state:e,previousState:this.calculatedState,isLegacyMobile:this.isLegacyMobile,networkProblem:!this.hasStun||!this.hasTurn});this.calculatedState=e}};BX.Call.PlainCall.Peer.prototype.calculateState=function(){if(this.peerConnection){if(this.failureReason!==""){return BX.Call.UserState.Failed}if(this.peerConnection.iceConnectionState==="connected"||this.peerConnection.iceConnectionState==="completed"){return BX.Call.UserState.Connected}return BX.Call.UserState.Connecting}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};BX.Call.PlainCall.Peer.prototype.getSignaling=function(){return this.call.signaling};BX.Call.PlainCall.Peer.prototype.startStatisticsGathering=function(){clearInterval(this.statsInterval);this.statsInterval=setInterval(function(){if(!this.peerConnection){return false}this.peerConnection.getStats().then(function(e){this.callbacks.onRTCStatsReceived({userId:this.userId,stats:e})}.bind(this))}.bind(this),1e3)};BX.Call.PlainCall.Peer.prototype.stopStatisticsGathering=function(){clearInterval(this.statsInterval);this.statsInterval=null};BX.Call.PlainCall.Peer.prototype.updateCandidatesTimeout=function(){if(this.candidatesTimeout){clearTimeout(this.candidatesTimeout)}this.candidatesTimeout=setTimeout(this.sendIceCandidates.bind(this),500)};BX.Call.PlainCall.Peer.prototype.sendIceCandidates=function(){this.log("User "+this.userId+": sending ICE candidates due to the timeout");this.candidatesTimeout=null;if(this.localIceCandidates.length>0){this.getSignaling().sendIceCandidate({userId:this.userId,connectionId:this.peerConnectionId,candidates:this.localIceCandidates});this.localIceCandidates=[]}else{this.log("User "+this.userId+": ICE candidates pool is empty")}};BX.Call.PlainCall.Peer.prototype._createPeerConnection=function(e){this.log("User "+this.userId+": Creating peer connection");var t={iceServers:[{urls:"stun:"+this.call.turnServer},{urls:"turn:"+this.call.turnServer,username:this.call.turnServerLogin,credential:this.call.turnServerPassword}]};this.localIceCandidates=[];this.peerConnection=new RTCPeerConnection(t);this.peerConnectionId=e;this.peerConnection.addEventListener("icecandidate",this._onPeerConnectionIceCandidateHandler);this.peerConnection.addEventListener("iceconnectionstatechange",this._onPeerConnectionIceConnectionStateChangeHandler);this.peerConnection.addEventListener("icegatheringstatechange",this._onPeerConnectionIceGatheringStateChangeHandler);this.peerConnection.addEventListener("signalingstatechange",this._onPeerConnectionSignalingStateChangeHandler);this.peerConnection.addEventListener("track",this._onPeerConnectionTrackHandler);this.peerConnection.addEventListener("removestream",this._onPeerConnectionRemoveStreamHandler);this.failureReason="";this.hasStun=false;this.hasTurn=false;this.updateCalculatedState();this.startStatisticsGathering()};BX.Call.PlainCall.Peer.prototype._destroyPeerConnection=function(){if(!this.peerConnection)return;this.log("User "+this.userId+": Destroying peer connection "+this.peerConnectionId);this.stopStatisticsGathering();this.peerConnection.removeEventListener("icecandidate",this._onPeerConnectionIceCandidateHandler);this.peerConnection.removeEventListener("iceconnectionstatechange",this._onPeerConnectionIceConnectionStateChangeHandler);this.peerConnection.removeEventListener("icegatheringstatechange",this._onPeerConnectionIceGatheringStateChangeHandler);this.peerConnection.removeEventListener("signalingstatechange",this._onPeerConnectionSignalingStateChangeHandler);this.peerConnection.removeEventListener("track",this._onPeerConnectionTrackHandler);this.peerConnection.removeEventListener("removestream",this._onPeerConnectionRemoveStreamHandler);this.localIceCandidates=[];if(this.pendingIceCandidates[this.peerConnectionId]){delete this.pendingIceCandidates[this.peerConnectionId]}this.peerConnection.close();this.peerConnection=null;this.peerConnectionId=null;this.videoSender=null;this.audioSender=null;this.incomingAudioTrack=null;this.incomingVideoTrack=null;this.incomingScreenTrack=null};BX.Call.PlainCall.Peer.prototype._onPeerConnectionIceCandidate=function(e){var t=e.candidate;this.log("User "+this.userId+": ICE candidate discovered. Candidate: "+(t?t.candidate:t));if(t){if(this.getSignaling().isIceTricklingAllowed()){this.getSignaling().sendIceCandidate({userId:this.userId,connectionId:this.peerConnectionId,candidates:[t.toJSON()]})}else{this.localIceCandidates.push(t.toJSON());this.updateCandidatesTimeout()}var i=t.candidate.match(/typ\s(\w+)?/);if(i){var n=i[1];if(n=="srflx"){this.hasStun=true}else if(n=="relay"){this.hasTurn=true}}}};BX.Call.PlainCall.Peer.prototype._onPeerConnectionIceConnectionStateChange=function(e){this.log("User "+this.userId+": ICE connection state changed. New state: "+this.peerConnection.iceConnectionState);if(this.peerConnection.iceConnectionState==="connected"||this.peerConnection.iceConnectionState==="completed"){this.connectionAttempt=0;clearTimeout(this.reconnectAfterDisconnectTimeout);this._updateTracksDebounced()}else if(this.peerConnection.iceConnectionState==="failed"){this.log("ICE connection failed. Trying to restore connection immediately");this.reconnect()}else if(this.peerConnection.iceConnectionState==="disconnected"){this.log("ICE connection lost. Waiting 5 seconds before trying to restore it");clearTimeout(this.reconnectAfterDisconnectTimeout);this.reconnectAfterDisconnectTimeout=setTimeout(function(){this.reconnect()}.bind(this),5e3)}this.updateCalculatedState()};BX.Call.PlainCall.Peer.prototype._onPeerConnectionIceGatheringStateChange=function(e){var t=e.target;this.log("User "+this.userId+": ICE gathering state changed to : "+t.iceGatheringState);if(t.iceGatheringState==="complete"){this.log("User "+this.userId+": ICE gathering complete");if(!this.hasStun||!this.hasTurn){var i=[];if(!this.hasTurn){i.push("TURN")}if(!this.hasStun){i.push("STUN")}this.log("Connectivity problem detected: no ICE candidates from "+i.join(" and ")+" servers");console.error("Connectivity problem detected: no ICE candidates from "+i.join(" and ")+" servers");this.callbacks.onNetworkProblem()}if(!this.hasTurn&&!this.hasStun){}if(!this.getSignaling().isIceTricklingAllowed()){if(this.localIceCandidates.length>0){this.getSignaling().sendIceCandidate({userId:this.userId,connectionId:this.peerConnectionId,candidates:this.localIceCandidates});this.localIceCandidates=[]}else{this.log("User "+this.userId+": ICE candidates already sent")}}}};BX.Call.PlainCall.Peer.prototype._onPeerConnectionSignalingStateChange=function(e){this.log("User "+this.userId+" PC signalingState: "+this.peerConnection.signalingState);if(this.peerConnection.signalingState==="stable"){this._updateTracksDebounced()}};BX.Call.PlainCall.Peer.prototype._onPeerConnectionNegotiationNeeded=function(e){this.log("User "+this.userId+": needed negotiation for peer connection");this.log("signaling state: ",e.target.signalingState);this.log("ice connection state: ",e.target.iceConnectionState);this.log("pendingRemoteDescription: ",e.target.pendingRemoteDescription);if(e.target.iceConnectionState!=="new"&&e.target.iceConnectionState!=="connected"&&e.target.iceConnectionState!=="completed"){this.log("User "+this.userId+": wrong connection state");return}if(this.isInitiator()){this.createAndSendOffer()}else{this.sendNegotiationNeeded(this.peerConnection._forceReconnect===true)}};BX.Call.PlainCall.Peer.prototype._onPeerConnectionTrack=function(e){this.log("User "+this.userId+": media track received: ",e.track.id+" ("+e.track.kind+")");if(e.track.kind=="video"){e.track.addEventListener("mute",this._onVideoTrackMuted.bind(this));e.track.addEventListener("unmute",this._onVideoTrackUnMuted.bind(this));e.track.addEventListener("ended",this._onVideoTrackEnded.bind(this));if(this.trackList[e.track.id]==="screen"){this.incomingScreenTrack=e.track}else{this.incomingVideoTrack=e.track}}else if(e.track.kind==="audio"){this.incomingAudioTrack=e.track}};BX.Call.PlainCall.Peer.prototype._onPeerConnectionRemoveStream=function(e){this.log("User: "+this.userId+"_onPeerConnectionRemoveStream: ",e)};BX.Call.PlainCall.Peer.prototype._onVideoTrackMuted=function(){console.log("Video track muted")};BX.Call.PlainCall.Peer.prototype._onVideoTrackUnMuted=function(){console.log("Video track unmuted")};BX.Call.PlainCall.Peer.prototype._onVideoTrackEnded=function(){console.log("Video track ended")};BX.Call.PlainCall.Peer.prototype._updateTracks=function(){if(!this.peerConnection){return null}var e=null;var t=null;var i=null;this.peerConnection.getTransceivers().forEach((function(n){this.call.log("[debug] tr direction: "+n.direction+" currentDirection: "+n.currentDirection);if(n.currentDirection=="sendrecv"||n.currentDirection=="recvonly"){if(n.receiver&&n.receiver.track){var a=n.receiver.track;if(a.kind==="audio"){e=a}else if(a.kind==="video"){if(this.trackList[n.mid]==="screen"){i=a}else{t=a}}}}}),this);this.incomingAudioTrack=e;this.incomingVideoTrack=t;this.incomingScreenTrack=i};BX.Call.PlainCall.Peer.prototype.stopSignalingTimeout=function(){clearTimeout(this.signalingConnectionTimeout)};BX.Call.PlainCall.Peer.prototype.refreshSignalingTimeout=function(){clearTimeout(this.signalingConnectionTimeout);this.signalingConnectionTimeout=setTimeout(this._onLostSignalingConnection.bind(this),n)};BX.Call.PlainCall.Peer.prototype._onLostSignalingConnection=function(){this.setSignalingConnected(false)};BX.Call.PlainCall.Peer.prototype._onConnectionOfferReplyTimeout=function(e){this.log("did not receive connection answer for connection "+e);this.reconnect()};BX.Call.PlainCall.Peer.prototype._onNegotiationNeededReplyTimeout=function(){this.log("did not receive connection offer in time");this.reconnect()};BX.Call.PlainCall.Peer.prototype.setConnectionOffer=function(e,t,i){this.log("User "+this.userId+": applying connection offer for connection "+e);clearTimeout(this.negotiationNeededReplyTimeout);this.negotiationNeededReplyTimeout=null;if(!this.call.isReady())return;if(!this.isReady())return;if(i){this.trackList=BX.util.array_flip(i)}if(this.peerConnection){if(this.peerConnectionId!==e){this._destroyPeerConnection();this._createPeerConnection(e)}}else{this._createPeerConnection(e)}this.applyOfferAndSendAnswer(t)};BX.Call.PlainCall.Peer.prototype.createAndSendOffer=function(e){var t=this;connectionConfig=i;for(var n in e){connectionConfig[n]=e[n]}t.peerConnection.createOffer(connectionConfig).then((function(e){t.log("User "+t.userId+": Created connection offer.");t.log("Applying local description");return t.peerConnection.setLocalDescription(e)})).then((function(){t.sendOffer()}))};BX.Call.PlainCall.Peer.prototype.sendOffer=function(){clearTimeout(this.connectionOfferReplyTimeout);this.connectionOfferReplyTimeout=setTimeout(function(){this._onConnectionOfferReplyTimeout(this.peerConnectionId)}.bind(this),a);this.getSignaling().sendConnectionOffer({userId:this.userId,connectionId:this.peerConnectionId,sdp:this.peerConnection.localDescription.sdp,tracks:{audio:this.getSenderMid(this.audioSender),video:this.getSenderMid(this.videoSender),screen:this.getSenderMid(this.screenSender)},userAgent:navigator.userAgent})};BX.Call.PlainCall.Peer.prototype.sendNegotiationNeeded=function(e){e=e===true;clearTimeout(this.negotiationNeededReplyTimeout);this.negotiationNeededReplyTimeout=setTimeout(function(){this._onNegotiationNeededReplyTimeout()}.bind(this),a);var t={userId:this.userId};if(e){t.restart=true}this.getSignaling().sendNegotiationNeeded(t)};BX.Call.PlainCall.Peer.prototype.applyOfferAndSendAnswer=function(e){var t=new RTCSessionDescription({type:"offer",sdp:e});this.log("User: "+this.userId+"; Applying remote offer");this.log("User: "+this.userId+"; Peer ice connection state ",this.peerConnection.iceConnectionState);this.peerConnection.setRemoteDescription(t).then(function(){if(this.peerConnection.iceConnectionState==="new"){this.sendMedia(true)}return this.peerConnection.createAnswer()}.bind(this)).then(function(e){this.log("Created connection answer.");this.log("Applying local description.");return this.peerConnection.setLocalDescription(e)}.bind(this)).then(function(){this.applyPendingIceCandidates();this.getSignaling().sendConnectionAnswer({userId:this.userId,connectionId:this.peerConnectionId,sdp:this.peerConnection.localDescription.sdp,tracks:{audio:this.getSenderMid(this.audioSender),video:this.getSenderMid(this.videoSender),screen:this.getSenderMid(this.screenSender)},userAgent:navigator.userAgent})}.bind(this)).catch(function(e){this.failureReason=e.toString();this.updateCalculatedState();this.log("Could not apply remote offer",e);console.error("Could not apply remote offer",e)}.bind(this))};BX.Call.PlainCall.Peer.prototype.setConnectionAnswer=function(e,t,i){if(!this.peerConnection||this.peerConnectionId!=e){this.log("Could not apply answer, for unknown connection "+e);return}if(this.peerConnection.signalingState!=="have-local-offer"){this.log("Could not apply answer, wrong peer connection signaling state "+this.peerConnection.signalingState);return}if(i){this.trackList=BX.util.array_flip(i)}var n=new RTCSessionDescription({type:"answer",sdp:t});clearTimeout(this.connectionOfferReplyTimeout);this.log("User: "+this.userId+"; Applying remote answer");this.peerConnection.setRemoteDescription(n).then(function(){this.applyPendingIceCandidates()}.bind(this)).catch(function(e){this.failureReason=e.toString();this.updateCalculatedState();this.log(e)}.bind(this))};BX.Call.PlainCall.Peer.prototype.addIceCandidate=function(e,t){if(!this.peerConnection)return;if(this.peerConnectionId!=e){this.log("Error: Candidate for unknown connection "+e);return}if(this.peerConnection.remoteDescription&&this.peerConnection.remoteDescription.type){this.peerConnection.addIceCandidate(t).then(function(){this.log("User: "+this.userId+"; Added remote ICE candidate: "+(t?t.candidate:t))}.bind(this)).catch(function(e){this.log(e)}.bind(this))}else{if(!this.pendingIceCandidates[e]){this.pendingIceCandidates[e]=[]}this.pendingIceCandidates[e].push(t)}};BX.Call.PlainCall.Peer.prototype.applyPendingIceCandidates=function(){var e=this;if(!this.peerConnection||!this.peerConnection.remoteDescription.type)return;if(BX.type.isArray(this.pendingIceCandidates[this.peerConnectionId])){this.pendingIceCandidates[this.peerConnectionId].forEach((function(t){e.peerConnection.addIceCandidate(t).then(function(){this.log("User: "+this.userId+"; Added remote ICE candidate: "+(t?t.candidate:t))}.bind(this))}),this);e.pendingIceCandidates[this.peerConnectionId]=[]}};BX.Call.PlainCall.Peer.prototype.onNegotiationNeeded=function(){if(this.peerConnection){if(this.peerConnection.signalingState=="have-local-offer"){this.sendOffer()}else{this.createAndSendOffer({iceRestart:true})}}else{this.sendMedia()}};BX.Call.PlainCall.Peer.prototype.reconnect=function(){clearTimeout(this.reconnectAfterDisconnectTimeout);this.connectionAttempt++;if(this.connectionAttempt>3){this.log("Error: Too many reconnection attempts, giving up");this.failureReason="Could not connect to user in time";this.updateCalculatedState();return}this.log("Trying to restore ICE connection. Attempt "+this.connectionAttempt);if(this.isInitiator()){this._destroyPeerConnection();this.sendMedia()}else{this.sendNegotiationNeeded(true)}};BX.Call.PlainCall.Peer.prototype.disconnect=function(){this._destroyPeerConnection()};BX.Call.PlainCall.Peer.prototype.log=function(){this.call.log.apply(this.call,arguments)};BX.Call.PlainCall.Peer.prototype.destroy=function(){this.disconnect();if(this.voiceDetection){this.voiceDetection.destroy();this.voiceDetection=null}for(var e in this.localStreams){this.localStreams[e]=null}this.outgoingVideoTrack=null;this.outgoingScreenTrack=null;this.outgoingVideoHoldState=false;this.incomingAudioTrack=null;this.incomingVideoTrack=null;this.incomingScreenTrack=null;clearTimeout(this.answerTimeout);this.answerTimeout=null;clearTimeout(this.connectionTimeout);this.connectionTimeout=null;clearTimeout(this.signalingConnectionTimeout);this.signalingConnectionTimeout=null;this.callbacks.onStateChanged=BX.DoNothing;this.callbacks.onMediaReceived=BX.DoNothing;this.callbacks.onMediaStopped=BX.DoNothing}})(); //# sourceMappingURL=plain_call.map.js
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.27 |
proxy
|
phpinfo
|
Settings