Your IP : 18.222.104.211
(function(){BX.namespace("BX.Call");if(BX.Call.FloatingVideo){return}var e={setStream:"FloatingVideo::setStream",setAudioMuted:"FloatingVideo::setAudioMuted",setTitle:"FloatingVideo::setTitle",setAvatars:"FloatingVideo::setAvatars",setTalking:"FloatingVideo::setTalking",onMainAreaClick:"FloatingVideo::onMainAreaClick",onMicButtonClick:"FloatingVideo::onMicButtonClick",onHangupButtonClick:"FloatingVideo::onHangupButtonClick",connectionOffer:"FloatingVideo::connectionOffer",connectionAnswer:"FloatingVideo::connectionAnswer",connectionClose:"FloatingVideo::connectionClose",connectionIceCandidate:"FloatingVideo::connectionIceCandidate"};var t=320;var n=180;var i=320;var s=70;BX.Call.FloatingVideo=function(e){if(typeof e!=="object"){e={}}this.stream=e.stream&&BX.Call.Util.containsVideoTrack(e.stream)?e.stream:null;this.audioMuted=e.audioMuted||false;this.title=e.title||"";this.avatars=e.avatars||{};this.window=null;this.visible=false;this.peerConnection=null;this.callbacks={onMainAreaClick:BX.type.isFunction(e.onMainAreaClick)?e.onMainAreaClick:BX.DoNothing,onButtonClick:BX.type.isFunction(e.onButtonClick)?e.onButtonClick:BX.DoNothing};this._onContentMainAreaClickHandler=this._onContentMainAreaClick.bind(this);this._onContentMicButtonClickHandler=this._onContentMicButtonClick.bind(this);this._onContentHangupButtonClickHandler=this._onContentHangupButtonClick.bind(this);this._onPCNegotiationNeededHandler=this._onPCNegotiationNeeded.bind(this);this._onPCIceCandidateHandler=this._onPCIceCandidate.bind(this);this._onConnectionAnswerHandler=this._onConnectionAnswer.bind(this);this._onConnectionIceCandidateHandler=this._onConnectionIceCandidate.bind(this);this.bindEventHandlers()};BX.Call.FloatingVideo.prototype={bindEventHandlers:function(){BX.desktop.addCustomEvent(e.onMainAreaClick,this._onContentMainAreaClickHandler);BX.desktop.addCustomEvent(e.onMicButtonClick,this._onContentMicButtonClickHandler);BX.desktop.addCustomEvent(e.onHangupButtonClick,this._onContentHangupButtonClickHandler);BX.desktop.addCustomEvent(e.connectionAnswer,this._onConnectionAnswerHandler);BX.desktop.addCustomEvent(e.connectionIceCandidate,this._onConnectionIceCandidateHandler)},_onContentMainAreaClick:function(){this.callbacks.onMainAreaClick()},_onContentMicButtonClick:function(){this.callbacks.onButtonClick({buttonName:"toggleMute",muted:!this.audioMuted})},_onContentHangupButtonClick:function(){this.callbacks.onButtonClick({buttonName:"hangup"})},setStream:function(e){if(BX.Call.Util.containsVideoTrack(e)){this.stream=e}else{this.stream=null}if(this.window&&this.visible){if(this.stream){this.sendVideo()}else{this.stopSendingVideo()}}},setTitle:function(t){this.title=t;if(this.window){BX.desktop.onCustomEvent(this.window,e.setTitle,[this.title])}},setAvatars:function(t){this.avatars=t;if(this.window&&this.visible){BX.desktop.onCustomEvent(this.window,e.setAvatars,[this.avatars])}},setTalking:function(t){if(this.window){BX.desktop.onCustomEvent(this.window,e.setTalking,[t])}},sendVideo:function(){if(!this.peerConnection){this.peerConnection=new RTCPeerConnection;this.peerConnection.addEventListener("negotiationneeded",this._onPCNegotiationNeededHandler);this.peerConnection.addEventListener("icecandidate",this._onPCIceCandidateHandler)}this.peerConnection.addTrack(this.stream.getVideoTracks()[0],this.stream)},_onPCNegotiationNeeded:function(){var t;this.peerConnection.createOffer().then(function(e){t=e;return this.peerConnection.setLocalDescription(e)}.bind(this)).then(function(){BX.desktop.onCustomEvent(this.window,e.connectionOffer,[t.sdp])}.bind(this))},_onPCIceCandidate:function(t){var n=t.candidate;if(n){BX.desktop.onCustomEvent(this.window,e.connectionIceCandidate,[n.toJSON()])}},_onConnectionAnswer:function(e){if(this.peerConnection){var t=new RTCSessionDescription({type:"answer",sdp:e});this.peerConnection.setRemoteDescription(t)}},_onConnectionIceCandidate:function(e){if(this.peerConnection){this.peerConnection.addIceCandidate(e)}},stopSendingVideo:function(){if(this.peerConnection){this.peerConnection.close();this.peerConnection.removeEventListener("negotiationneeded",this._onPCNegotiationNeededHandler);this.peerConnection.removeEventListener("icecandidate",this._onPCIceCandidateHandler);this.peerConnection=null}BX.desktop.onCustomEvent(this.window,e.connectionClose,[])},setAudioMuted:function(t){if(this.audioMuted==t){return}this.audioMuted=t;if(this.window&&this.visible){BX.desktop.onCustomEvent(this.window,e.setAudioMuted,[this.audioMuted])}},show:function(){if(!BX.desktop){return}if(this.window){this.window.BXDesktopWindow.ExecuteCommand("show");BX.desktop.onCustomEvent(this.window,e.setAudioMuted,[this.audioMuted]);BX.desktop.onCustomEvent(this.window,e.setAvatars,[this.avatars]);if(this.stream){this.sendVideo()}}else{var t={audioMuted:this.audioMuted,title:this.title,avatars:this.avatars};this.window=BXDesktopSystem.ExecuteCommand("topmost.show.html",BX.desktop.getHtmlPage("","window.FVC = new BX.Call.FloatingVideoContent("+JSON.stringify(t)+");"));setTimeout(function(){if(this.stream&&this.visible){this.sendVideo()}}.bind(this),2e3)}this.visible=true},hide:function(){if(!this.window||!this.window.document){return false}this.stopSendingVideo();this.window.BXDesktopWindow.ExecuteCommand("hide");this.visible=false},close:function(){if(!this.window||!this.window.document){return false}this.window.BXDesktopWindow.ExecuteCommand("close");this.window=null;this.visible=false},destroy:function(){if(this.window){this.window.BXDesktopWindow.ExecuteCommand("close");this.window=null}this.stream=null;BX.desktop.removeCustomEvents(e.onMainAreaClick);BX.desktop.removeCustomEvents(e.onMicButtonClick);BX.desktop.removeCustomEvents(e.onHangupButtonClick)}};BX.Call.FloatingVideoContent=function(e){this.stream=e.stream;this.audioMuted=e.audioMuted;this.avatars=e.avatars||{};this.title=e.title||"";this.talking=[];this.elements={container:null,video:null,avatars:null,title:null,micButton:null,micButtonText:null,hangupButton:null};this.render();this.adjustWindow();this.bindEventHandlers();this.callAspectHorizontal=true;if(this.stream){this.callAspectCheckInterval=setInterval(this.checkVideoAspect.bind(this),500)}this.slavePeerConnection=null;this._onSlavePCIceCandidateHandler=this._onSlavePCIceCandidate.bind(this);this._onSlavePCIceConnectionStateChangeHandler=this._onSlavePCIceConnectionStateChange.bind(this)};BX.Call.FloatingVideoContent.prototype={bindEventHandlers:function(){BX.desktop.addCustomEvent(e.setStream,this.setStream.bind(this));BX.desktop.addCustomEvent(e.setAudioMuted,this.setAudioMuted.bind(this));BX.desktop.addCustomEvent(e.setTitle,this.setTitle.bind(this));BX.desktop.addCustomEvent(e.setAvatars,this.setAvatars.bind(this));BX.desktop.addCustomEvent(e.setTalking,this.setTalking.bind(this));BX.desktop.addCustomEvent(e.connectionOffer,this._onConnectionOfferFromMain.bind(this));BX.desktop.addCustomEvent(e.connectionIceCandidate,this._onIceCandidateFromMain.bind(this));BX.desktop.addCustomEvent(e.connectionClose,this._onRTCconnectionClose.bind(this));window.addEventListener("beforeunload",this.destroy.bind(this))},render:function(){var e=this.stream?t:i;var o=this.stream?n:s;var a={width:e+"px",height:o+"px"};this.elements.container=BX.create("div",{props:{className:"bx-messenger-call-float"+(this.stream?"":" bx-messenger-call-float-audio")},style:a,events:{click:this.onMainAreaClick.bind(this)},children:[BX.create("div",{props:{className:"bx-messenger-call-float-audio-unfold"},children:[this.elements.avatars=BX.create("div",{props:{className:"bx-messenger-call-float-avatars"}}),this.elements.title=BX.create("span",{props:{className:"bx-messenger-call-float-button-text"},text:this.title})]}),BX.create("div",{props:{className:"bx-messenger-call-float-buttons"},children:[this.elements.micButton=BX.create("div",{props:{className:"bx-messenger-call-float-button bx-messenger-call-float-button-mic"+(this.audioMuted?" bx-messenger-call-float-button-mic-disabled":"")},events:{click:this.onMicButtonClick.bind(this)},children:[BX.create("span",{props:{className:"bx-messenger-call-float-button-icon"}}),this.elements.micButtonText=BX.create("span",{props:{className:"bx-messenger-call-float-button-text"},text:BX.message("IM_M_CALL_BTN_MIC")+" "+BX.message("IM_M_CALL_BTN_MIC_"+(this.audioMuted?"OFF":"ON"))})]}),this.elements.hangupButton=BX.create("div",{props:{className:"bx-messenger-call-float-button bx-messenger-call-float-button-decline"},events:{click:this.onHangupButtonClick.bind(this)},children:[BX.create("span",{props:{className:"bx-messenger-call-float-button-icon"}}),BX.create("span",{props:{className:"bx-messenger-call-float-button-text"},text:BX.message("IM_M_CALL_BTN_HANGUP")})]})]})]});this.elements.video=BX.create("video",{attrs:{autoplay:true,src:this.stream},props:{className:"bx-messenger-call-float-video",volume:0}});if(this.stream){BX.prepend(this.elements.video,this.elements.container)}this.setAvatars(this.avatars);document.body.appendChild(this.elements.container)},adjustWindow:function(e,o){var a=this.stream?t:i;var d=this.stream?n:s;e=e||a;o=o||d;if(!this.stream){var l=Math.ceil(Object.keys(this.avatars).length/4);o+=l*74+10}this.elements.container.style.width=e+"px";this.elements.container.style.height=o+"px";BX.desktop.setWindowMinSize({Width:e,Height:o});BX.desktop.setWindowResizable(false);BX.desktop.setWindowClosable(false);BX.desktop.setWindowResizable(false);BX.desktop.setWindowTitle(this.title);if(BXDesktopSystem.QuerySettings("global_topmost_x",null)){BX.desktop.setWindowPosition({X:parseInt(BXDesktopSystem.QuerySettings("global_topmost_x",STP_RIGHT)),Y:parseInt(BXDesktopSystem.QuerySettings("global_topmost_y",STP_TOP)),Width:e,Height:o,Mode:STP_FRONT});if(!BX.browser.IsMac())BX.desktop.setWindowPosition({X:parseInt(BXDesktopSystem.QuerySettings("global_topmost_x",STP_RIGHT)),Y:parseInt(BXDesktopSystem.QuerySettings("global_topmost_y",STP_TOP)),Width:e,Height:o,Mode:STP_FRONT})}else{BX.desktop.setWindowPosition({X:STP_RIGHT,Y:STP_TOP,Width:e,Height:o,Mode:STP_FRONT});if(!BX.browser.IsMac())BX.desktop.setWindowPosition({X:STP_RIGHT,Y:STP_TOP,Width:e,Height:o,Mode:STP_FRONT})}},checkVideoAspect:function(){if(this.elements.video.videoWidth<this.elements.video.videoHeight){if(this.callAspectHorizontal){this.callAspectHorizontal=false;BX.addClass(this.elements.container,"bx-messenger-call-overlay-aspect-vertical");BX.desktop.setWindowSize({Width:n,Height:t})}}else{if(!this.callAspectHorizontal){this.callAspectHorizontal=true;BX.removeClass(this.elements.container,"bx-messenger-call-overlay-aspect-vertical");BX.desktop.setWindowSize({Width:t,Height:n})}}},_onConnectionOfferFromMain:function(t){if(this.slavePeerConnection){this.slavePeerConnection.removeEventListener("icecandidate",this._onSlavePCIceCandidateHandler);this.slavePeerConnection.removeEventListener("iceconnectionstatechange",this._onSlavePCIceConnectionStateChangeHandler);this.slavePeerConnection.close()}this.slavePeerConnection=new RTCPeerConnection;this.slavePeerConnection.addEventListener("icecandidate",this._onSlavePCIceCandidateHandler);this.slavePeerConnection.addEventListener("iceconnectionstatechange",this._onSlavePCIceConnectionStateChangeHandler);var n=new RTCSessionDescription({type:"offer",sdp:t});this.slavePeerConnection.setRemoteDescription(n).then(function(){if(this.slavePeerConnection){this.slavePeerConnection.createAnswer().then(function(t){this.slavePeerConnection.setLocalDescription(t);BX.desktop.onCustomEvent("main",e.connectionAnswer,[t.sdp])}.bind(this))}}.bind(this))},_onIceCandidateFromMain:function(e){setTimeout(function(){if(this.slavePeerConnection){this.slavePeerConnection.addIceCandidate(e)}}.bind(this),200)},_onRTCconnectionClose:function(){if(this.slavePeerConnection){this.slavePeerConnection.removeEventListener("icecandidate",this._onSlavePCIceCandidateHandler);this.slavePeerConnection.removeEventListener("iceconnectionstatechange",this._onSlavePCIceConnectionStateChangeHandler);this.slavePeerConnection.close();this.slavePeerConnection=null}this.setStream(null)},_onSlavePCIceCandidate:function(t){var n=t.candidate;if(n){BX.desktop.onCustomEvent("main",e.connectionIceCandidate,[n.toJSON()])}},_onSlavePCIceConnectionStateChange:function(e){if(this.slavePeerConnection.iceConnectionState==="connected"){this.setStream(this.slavePeerConnection.getRemoteStreams()[0])}else if(this.slavePeerConnection.iceConnectionState==="disconnected"){this.setStream(null);this.slavePeerConnection.removeEventListener("icecandidate",this._onSlavePCIceCandidateHandler);this.slavePeerConnection.removeEventListener("iceconnectionstatechange",this._onSlavePCIceConnectionStateChangeHandler)}},setStream:function(e){clearInterval(this.callAspectCheckInterval);this.stream=e;var o=this.stream?t:i;var a=this.stream?n:s;var d={width:o+"px",height:a+"px"};if(this.elements.container){if(this.stream){if(!this.elements.video.parentNode){BX.prepend(this.elements.video,this.elements.container);BX.removeClass(this.elements.container,"bx-messenger-call-float-audio")}this.elements.video.srcObject=this.stream}else{BX.remove(this.elements.video);BX.addClass(this.elements.container,"bx-messenger-call-float-audio")}BX.adjust(this.elements.container,{style:d})}if(this.stream){this.callAspectCheckInterval=setInterval(this.checkVideoAspect.bind(this),500)}this.adjustWindow()},setAudioMuted:function(e){this.audioMuted=e;if(this.audioMuted){BX.addClass(this.elements.micButton,"bx-messenger-call-float-button-mic-disabled");BX.adjust(this.elements.micButtonText,{text:BX.message("IM_M_CALL_BTN_MIC")+" "+BX.message("IM_M_CALL_BTN_MIC_OFF")})}else{BX.removeClass(this.elements.micButton,"bx-messenger-call-float-button-mic-disabled");BX.adjust(this.elements.micButtonText,{text:BX.message("IM_M_CALL_BTN_MIC")+" "+BX.message("IM_M_CALL_BTN_MIC_ON")})}},setTitle:function(e){this.title=e;this.elements.title.innerText=e;BX.desktop.setWindowTitle(this.title)},setAvatars:function(e){this.avatars=e;this.elements.avatars.innerHTML="";for(var t in this.avatars){var n=this.avatars[t];var i=BX.create("div",{props:{className:"bx-messenger-call-float-avatar"},dataset:{userId:t}});if(n!=""){i.style.backgroundImage="url('"+n+"')"}this.elements.avatars.appendChild(i)}this.adjustWindow()},setTalking:function(e){this.talking=e;if(this.elements.avatars){for(var t=0;t<this.elements.avatars.children.length;t++){var n=this.elements.avatars.children[t];var i=Number(n.dataset.userId);if(this.talking.includes(i)){n.classList.add("talking")}else{n.classList.remove("talking")}}}},onMainAreaClick:function(t){BX.desktop.onCustomEvent("main",e.onMainAreaClick,[]);t.stopPropagation()},onMicButtonClick:function(t){BX.desktop.onCustomEvent("main",e.onMicButtonClick,[this.audioMuted]);t.stopPropagation()},onHangupButtonClick:function(t){BX.desktop.onCustomEvent("main",e.onHangupButtonClick,[]);t.stopPropagation()},destroy:function(){this.stream=null;BX.desktop.removeCustomEvents(e.setStream);BX.desktop.removeCustomEvents(e.setAudioMuted)}}})();
//# sourceMappingURL=floating_video.map.js