Your IP : 52.15.128.81


Current Path : /home/bitrix/ext_www/rk_shared_core/bitrix/js/im/call/
Upload File :
Current File : /home/bitrix/ext_www/rk_shared_core/bitrix/js/im/call/view.min.js

(function(){BX.namespace("BX.Call");if(BX.Call.View){return}var e={Grid:1,Centered:2};var t={Calling:1,Connected:2,Error:3};var s=1200;BX.Call.View=function(s){this.title=s.title;this.container=s.container;this.cameraId=s.cameraId;this.microphoneId=s.microphoneId;this.showChatButtons=s.showChatButtons===true;this.language=s.language||"";this.cameraList=[];this.microphoneList=[];this.userLimit=s.userLimit||1;this.userId=BX.message("USER_ID");this.localUser=new n({id:this.userId,state:BX.Call.UserState.Connected,localUser:true});this.elements={root:null,container:null,overlay:null,panel:null,audioContainer:null,audio:{},center:{container:null,video:null},userBlock:null,ear:{left:null,right:null},userList:{rows:[],addButton:null}};this.buttons={title:null,grid:null,add:null,link:null,microphone:null,camera:null,screen:null,chat:null,history:null,hangup:null,fullscreen:null,overlay:null,status:null};this.size=BX.Call.View.Size.Full;this.isMuted=false;this.isCameraOn=false;this.isFullScreen=false;this.disabledButtons={};this.uiState=t.Calling;this.layout=e.Centered;this.grid={rows:0,columns:0};this.users={};if(BX.type.isPlainObject(s.userStates)){this.appendUsers(s.userStates)}this.callbacks={onClose:BX.type.isFunction(s.onClose)?s.onClose:BX.DoNothing,onDestroy:BX.type.isFunction(s.onDestroy)?s.onDestroy:BX.DoNothing,onButtonClick:BX.type.isFunction(s.onButtonClick)?s.onButtonClick:BX.DoNothing,onBodyClick:BX.type.isFunction(s.onBodyClick)?s.onBodyClick:BX.DoNothing,onReplaceCamera:BX.type.isFunction(s.onReplaceCamera)?s.onReplaceCamera:BX.DoNothing,onReplaceMicrophone:BX.type.isFunction(s.onReplaceMicrophone)?s.onReplaceMicrophone:BX.DoNothing,onSetCentralUser:BX.type.isFunction(s.onSetCentralUser)?s.onSetCentralUser:BX.DoNothing};this.scrollInterval=0;this._onFullScreenChangeHandler=this._onFullScreenChange.bind(this);this._onResizeHandler=this._onResize.bind(this);this.init()};BX.Call.View.prototype.init=function(){if(this.isFullScreenSupported()){if(BX.browser.IsChrome()||BX.browser.IsSafari()){window.addEventListener("webkitfullscreenchange",this._onFullScreenChangeHandler)}else if(BX.browser.IsFirefox()){window.addEventListener("mozfullscreenchange",this._onFullScreenChangeHandler)}}window.addEventListener("resize",this._onResizeHandler);this.elements.audioContainer=BX.create("div",{props:{className:"bx-messenger-videocall-audio-container"}});this.container.appendChild(this.elements.audioContainer)};BX.Call.View.prototype.setCallback=function(e,t){if(BX.type.isFunction(t)&&this.callbacks.hasOwnProperty(e)){this.callbacks[e]=t}};BX.Call.View.prototype.appendUsers=function(e){if(!BX.type.isPlainObject(e)){return}var t=Object.keys(e);for(var s=0;s<t.length;s++){this.users[t[s]]=new n({id:t[s],state:e[t[s]]?e[t[s]]:BX.Call.UserState.Idle,onClick:this._onUserClick.bind(this)})}BX.Call.Util.updateUserData(t)};BX.Call.View.prototype.setDeviceList=function(e){this.cameraList=[];this.microphoneList=[];for(var t=0;t<e.length;t++){var s=e[t];if(s.kind=="audioinput"){this.microphoneList.push(s)}else if(s.kind=="videoinput"){this.cameraList.push(s)}}if(this.buttons.camera){if(this.cameraList.length===0){this.buttons.camera.hideArrow()}else{this.buttons.camera.showArrow()}}if(this.buttons.microphone){if(this.microphoneList.length===0){this.buttons.microphone.hideArrow()}else{this.buttons.microphone.showArrow()}}};BX.Call.View.prototype.setCentralUser=function(t){if(this.centralUser.userId==t){return}if(t==this.userId&&this.getUsersWithVideo().length>0){return}if(!this.users[t]){return}this.centralUser.setUserId(t);if(this.layout==e.Centered){this.updateUserList()}this.callbacks.onSetCentralUser({userId:t,stream:t==this.userId?this.localUser.stream:this.users[t].stream})};BX.Call.View.prototype.getUserCount=function(){return Object.keys(this.users).length};BX.Call.View.prototype.getConnectedUserCount=function(){return this.getConnectedUsers().length};BX.Call.View.prototype.getUsersWithVideo=function(){var e=[];for(var t in this.users){if(this.users[t].hasVideo()){e.push(t)}}return e};BX.Call.View.prototype.getConnectedUsers=function(){var e=[];for(var t in this.users){if(this.users[t].state==BX.Call.UserState.Connected){e.push(t)}}return e};BX.Call.View.prototype.setUiState=function(e){if(this.uiState==e){return}this.uiState=e;this.updateButtons()};BX.Call.View.prototype.setLayout=function(t){if(t==this.layout){return}this.layout=t;for(var s=0;s<this.elements.userList.rows.length;s++){BX.remove(this.elements.userList.rows[s])}this.elements.userList.rows=this.renderUserList();if(this.layout==e.Centered){this.elements.root.className="bx-messenger-videocall bx-messenger-videocall-centered";BX.Call.Util.appendChildren(this.elements.userBlock,this.elements.userList.rows);this.elements.container.appendChild(this.elements.center);this.elements.container.appendChild(this.elements.userBlock);this.centralUser.reattachStream()}else if(this.layout==e.Grid){this.elements.root.className="bx-messenger-videocall bx-messenger-videocall-grid bx-messenger-videocall-grid-r-"+this.grid.rows+" bx-messenger-videocall-grid-c-"+this.grid.columns;this.elements.container.removeChild(this.elements.center);this.elements.container.removeChild(this.elements.userBlock);BX.Call.Util.appendChildren(this.elements.container,this.elements.userList.rows)}this.toggleEars()};BX.Call.View.prototype.setCameraState=function(e){e=!!e;if(this.isCameraOn==e){return}this.isCameraOn=e;if(this.buttons.camera){if(this.isCameraOn){this.buttons.camera.enable()}else{this.buttons.camera.disable()}}};BX.Call.View.prototype.setMuted=function(e){e=!!e;if(this.isMuted==e){return}this.isMuted=e;if(this.buttons.microphone){if(this.isMuted){this.buttons.microphone.disable()}else{this.buttons.microphone.enable()}}};BX.Call.View.prototype.addUser=function(e,t){if(this.users[e]){return}this.users[e]=new n({id:e,state:t||BX.Call.UserState.Idle,onClick:this._onUserClick.bind(this)});this.updateUserList();this.updateButtons()};BX.Call.View.prototype.setUserState=function(e,t){var s=this.users[e];if(!s){return}s.setState(t);if(this.centralUser.userId==this.userId&&t==BX.Call.UserState.Connected){this.setCentralUser(e)}else if(e==this.centralUser.userId&&(t==BX.Call.UserState.Idle||t==BX.Call.UserState.Failed)){var i=this.getUsersWithVideo();var n=this.getConnectedUsers();if(i.length>0){this.setCentralUser(i[0])}else if(this.localUser.hasVideo()){this.setCentralUser(this.userId)}else if(n.length>0){this.setCentralUser(n[0])}}this.updateUserList();this.updateButtons()};BX.Call.View.prototype.setTitle=function(e){this.title=e};BX.Call.View.prototype.setUserTalking=function(e,t){var s=this.users[e];if(!s){return}s.setTalking(t)};BX.Call.View.prototype.setLocalStream=function(t){this.localUser.stream=t;this.setCameraState(this.localUser.hasVideo());var s=t.getVideoTracks();if(s.length>0){var i=s[0].getSettings();this.cameraId=i.deviceId||""}else{this.cameraId=""}var n=t.getAudioTracks();if(n.length>0){var r=n[0].getSettings();this.microphoneId=r.deviceId||""}else{this.microphoneId=""}if(this.layout==e.Centered&&this.centralUser.userId==this.userId){this.centralUser.setStream(t)}else{this.updateUserList()}};BX.Call.View.prototype.setStream=function(e,s){if(this.uiState==t.Calling){this.setUiState(t.Connected)}if(!this.users[e]){throw Error("User "+e+" is not a part of this call")}if(!this.elements.audio[e]){this.elements.audio[e]=BX.create("audio");this.elements.audioContainer.appendChild(this.elements.audio[e])}if(s.getAudioTracks().length>0&&s!=this.elements.audio[e].srcObject){this.elements.audio[e].srcObject=s;this.elements.audio[e].play()}this.users[e].stream=s;if(this.users[e].hasVideo()){if(this.centralUser.userId==this.userId){this.setCentralUser(e)}}else{if(this.centralUser.userId==e){var i=this.getUsersWithVideo();if(i.length>0){this.setCentralUser(i[0])}else if(this.localUser.hasVideo()){this.setCentralUser(this.userId)}}}if(this.centralUser.userId==e){this.centralUser.setStream(s)}this.updateUserList()};BX.Call.View.prototype.show=function(){if(!this.elements.root){this.render()}this.container.appendChild(this.elements.root);if(this.layout==e.Centered){this.centralUser.reattachStream()}this.updateButtons();this.updateUserList();this.toggleEars()};BX.Call.View.prototype.hide=function(){BX.remove(this.elements.root)};BX.Call.View.prototype.showFatalError=function(e){if(!this.elements.root){this.render();this.container.appendChild(this.elements.root)}var s=BX.create("div",{props:{className:"bx-messenger-videocall-user-status bx-messenger-videocall-user-status-wide"}});if(BX.type.isNotEmptyString(e.text)){var i=BX.create("div",{props:{className:"bx-messenger-videocall-status-text"},text:e.text});s.appendChild(i)}if(this.elements.overlay.childElementCount){BX.cleanNode(this.elements.overlay)}this.elements.overlay.appendChild(s);this.setUiState(t.Error)};BX.Call.View.prototype.close=function(){BX.cleanNode(this.container);this.callbacks.onClose()};BX.Call.View.prototype.setSize=function(t){if(this.size==t){return}this.size=t;if(this.size==BX.Call.View.Size.Folded){this.elements.panel.classList.add("bx-messenger-videocall-panel-folded");BX.remove(this.elements.container);this.updateButtons()}else{this.elements.panel.classList.remove("bx-messenger-videocall-panel-folded");this.elements.wrap.appendChild(this.elements.container);if(this.layout==e.Centered){this.centralUser.reattachStream()}this.updateButtons();this.updateUserList()}};BX.Call.View.prototype.toggleFullScreen=function(){if(this.isFullScreen){this.exitFullScreen()}else{this.enterFullScreen()}};BX.Call.View.prototype.isButtonDisabled=function(e){return this.disabledButtons.hasOwnProperty(e)};BX.Call.View.prototype.disableAddUser=function(){this.disabledButtons["add"]=true;if(this.elements.userList.addButton){BX.remove(this.elements.userList.addButton);this.elements.userList.addButton=null}};BX.Call.View.prototype.disableSwitchCamera=function(){this.disabledButtons["camera"]=true};BX.Call.View.prototype.disableSwitchMicrophone=function(){this.disabledButtons["microphone"]=true};BX.Call.View.prototype.disableScreenSharing=function(){this.disabledButtons["screen"]=true};BX.Call.View.prototype.getButtonList=function(){if(this.uiState==t.Error){return["close"]}if(this.size==BX.Call.View.Size.Folded){return["title","hangup","fullscreen"]}var e=[];if(this.uiState===t.Connected){e.push("grid")}if(this.getConnectedUserCount()<this.userLimit-1&&!this.isFullScreen&&this.uiState===t.Connected){e.push("add")}if(false&&!this.isFullScreen){e.push("link")}if(this.uiState===t.Connected){e.push("microphone","camera")}if(this.isScreenSharingSupported()&&!this.isFullScreen&&this.uiState===t.Connected){e.push("screen")}if(this.showChatButtons&&!this.isFullScreen){e.push("chat","history")}e.push("hangup");if(this.isFullScreenSupported()){e.push("fullscreen")}e=e.filter(function(e){return!this.isButtonDisabled(e)},this);return e};BX.Call.View.prototype.render=function(){this.elements.root=BX.create("div",{props:{className:"bx-messenger-videocall bx-messenger-videocall-centered"},children:[this.elements.wrap=BX.create("div",{props:{className:"bx-messenger-videocall-wrap"},children:[this.elements.container=BX.create("div",{props:{className:"bx-messenger-videocall-inner"},children:[this.elements.overlay=BX.create("div",{props:{className:"bx-messenger-videocall-overlay"}})]}),this.elements.panel=BX.create("div",{props:{className:"bx-messenger-videocall-panel"}})]})],events:{click:this._onBodyClick.bind(this)}});this.centralUser=new i({parent:this,video:false,stream:false,userId:this.userId,language:this.language});this.elements.center=this.centralUser.render();this.elements.userBlock=BX.create("div",{props:{className:"bx-messenger-videocall-user-block"},children:[this.elements.ear.left=BX.create("div",{props:{className:"bx-messenger-videocall-ear bx-messenger-videocall-ear-left"},events:{mouseenter:this.scrollUserBlockLeft.bind(this),mouseleave:this.stopScroll.bind(this)}}),this.elements.ear.right=BX.create("div",{props:{className:"bx-messenger-videocall-ear bx-messenger-videocall-ear-right"},events:{mouseenter:this.scrollUseBlockRight.bind(this),mouseleave:this.stopScroll.bind(this)}})]});if(this.layout==e.Centered){this.elements.container.appendChild(this.elements.center);this.elements.container.appendChild(this.elements.userBlock)}return this.elements.root};BX.Call.View.prototype.renderUserList=function(){var s=this.elements.root.getBoundingClientRect();var i=this.localUser.hasVideo()&&(this.layout==e.Grid||this.centralUser.userId!=this.userId);var n=[];for(var r in this.users){var l=this.users[r];if(this.layout==e.Centered&&r==this.centralUser.userId){continue}if(l.state==BX.Call.UserState.Idle){continue}n.push(l.render())}if(i){n.push(this.localUser.render())}var a=[];var o=n.length;var c=this.layout==e.Centered?1:BX.Call.Util.findRowCount(s.width,s.height,o);var h=Math.ceil(o/c);var d;for(d=0;d<c;d++){a.push(BX.create("div",{props:{className:"bx-messenger-videocall-user-list"}}))}var u=0;var p=0;for(d=0;d<o;d++){if(p>=h){p=0;u++}a[u].appendChild(n[d]);p++}var m=this.layout==e.Centered&&o>0&&!this.isFullScreen&&this.uiState===t.Connected&&!this.isButtonDisabled("add")&&this.getConnectedUserCount()<this.userLimit-1;if(m){this.elements.userList.addButton=BX.create("div",{props:{className:"bx-messenger-videocall-user-add"},children:[BX.create("div",{props:{className:"bx-messenger-videocall-user-add-inner"}})],events:{click:this._onAddButtonClick.bind(this)}});if(!this.isFullScreen){a[u].appendChild(this.elements.userList.addButton)}}else{this.elements.userList.addButton=null}this.grid.rows=c;this.grid.columns=h;if(this.layout===e.Centered&&a.length===1){a[0].addEventListener("scroll",this.toggleEars.bind(this))}return a};BX.Call.View.prototype.renderButtons=function(e){var t;var s;var i;var n;t=BX.create("div",{props:{className:"bx-messenger-videocall-panel-inner"},children:[s=BX.create("div",{props:{className:"bx-messenger-videocall-panel-block"}}),i=BX.create("div",{props:{className:"bx-messenger-videocall-panel-block"}}),n=BX.create("div",{props:{className:"bx-messenger-videocall-panel-block"}})]});for(var c=0;c<e.length;c++){switch(e[c]){case"title":this.buttons.title=new r({text:this.title,isGroupCall:Object.keys(this.users).length>1});s.appendChild(this.buttons.title.render());break;case"grid":this.buttons.grid=new l({class:"grid",text:BX.message("IM_M_CALL_BTN_GRID"),onClick:this._onGridButtonClick.bind(this)});s.appendChild(this.buttons.grid.render());break;case"add":this.buttons.add=new l({class:"add",text:BX.message("IM_M_CALL_BTN_ADD"),onClick:this._onAddButtonClick.bind(this)});s.appendChild(this.buttons.add.render());break;case"link":this.buttons.link=new l({class:"link",text:BX.message("IM_M_CALL_BTN_LINK"),onClick:this._onLinkButtonClick.bind(this)});s.appendChild(this.buttons.link.render());break;case"microphone":this.buttons.microphone=new o({class:"microphone",text:BX.message("IM_M_CALL_BTN_MIC"),enabled:!this.isMuted,arrowEnabled:this.microphoneList.length>0&&!this.isFullScreen,onClick:this._onMicrophoneButtonClick.bind(this),onArrowClick:this._onMicrophoneArrowClick.bind(this)});i.appendChild(this.buttons.microphone.render());break;case"camera":this.buttons.camera=new o({class:"camera",text:BX.message("IM_M_CALL_BTN_CAMERA"),enabled:this.isCameraOn,arrowEnabled:this.cameraList.length>0&&!this.isFullScreen,onClick:this._onCameraButtonClick.bind(this),onArrowClick:this._onCameraArrowClick.bind(this)});i.appendChild(this.buttons.camera.render());break;case"screen":this.buttons.screen=new l({class:"screen",text:BX.message("IM_M_CALL_BTN_SCREEN"),onClick:this._onScreenButtonClick.bind(this)});i.appendChild(this.buttons.screen.render());break;case"chat":this.buttons.chat=new l({class:"chat",text:BX.message("IM_M_CALL_BTN_CHAT"),onClick:this._onChatButtonClick.bind(this)});i.appendChild(this.buttons.chat.render());break;case"history":this.buttons.history=new l({class:"history",text:BX.message("IM_M_CALL_BTN_HISTORY"),onClick:this._onHistoryButtonClick.bind(this)});i.appendChild(this.buttons.history.render());break;case"hangup":this.buttons.hangup=new a({text:BX.message("IM_M_CALL_BTN_HANGUP"),onClick:this._onHangupButtonClick.bind(this)});n.appendChild(this.buttons.hangup.render());break;case"close":this.buttons.close=new a({text:BX.message("IM_M_CALL_BTN_CLOSE"),onClick:this._onCloseButtonClick.bind(this)});i.appendChild(this.buttons.close.render());break;case"fullscreen":this.buttons.fullscreen=new l({class:"resize",text:"",onClick:this._onFullScreenButtonClick.bind(this)});n.appendChild(this.buttons.fullscreen.render());break}}return t};BX.Call.View.prototype.updateUserList=function(){for(var t=0;t<this.elements.userList.rows.length;t++){BX.remove(this.elements.userList.rows[t])}this.elements.userList.rows=this.renderUserList();if(this.layout==e.Centered){BX.Call.Util.appendChildren(this.elements.userBlock,this.elements.userList.rows);var s=this.elements.userList.rows[0];this.centralUser.setFullSize(s.childElementCount==0)}else if(this.layout==e.Grid){BX.Call.Util.appendChildren(this.elements.container,this.elements.userList.rows);this.elements.root.className="bx-messenger-videocall bx-messenger-videocall-grid bx-messenger-videocall-grid-r-"+this.grid.rows+" bx-messenger-videocall-grid-c-"+this.grid.columns}this.toggleEars()};BX.Call.View.prototype.updateButtons=function(){var e=this.getButtonList();BX.cleanNode(this.elements.panel);this.elements.panel.appendChild(this.renderButtons(e))};BX.Call.View.prototype.isScreenSharingSupported=function(){return typeof BXDesktopSystem!=="undefined"};BX.Call.View.prototype.isFullScreenSupported=function(){if(BX.browser.IsChrome()||BX.browser.IsSafari()){return document.webkitFullscreenEnabled===true}else if(BX.browser.IsFirefox()){return document.mozFullscreenEnabled===true}else{return false}};BX.Call.View.prototype.enterFullScreen=function(){if(BX.browser.IsChrome()||BX.browser.IsSafari()){this.elements.root.webkitRequestFullScreen()}else if(BX.browser.IsFirefox()){this.elements.root.mozRequestFullScreen()}};BX.Call.View.prototype.exitFullScreen=function(){if(document.cancelFullScreen){document.cancelFullScreen()}else if(document.mozCancelFullScreen){document.mozCancelFullScreen()}else if(document.webkitCancelFullScreen){document.webkitCancelFullScreen()}};BX.Call.View.prototype.toggleEars=function(){this.toggleRightEar();this.toggleLeftEar()};BX.Call.View.prototype.toggleRightEar=function(){if(this.layout==e.Centered&&this.elements.userList.rows.length==1&&this.elements.userList.rows[0].scrollWidth>this.elements.userList.rows[0].offsetWidth&&this.elements.userList.rows[0].offsetWidth+this.elements.userList.rows[0].scrollLeft<this.elements.userList.rows[0].scrollWidth){this.elements.ear.right.classList.add("bx-messenger-videocall-ear-show")}else{this.elements.ear.right.classList.remove("bx-messenger-videocall-ear-show")}};BX.Call.View.prototype.toggleLeftEar=function(){if(this.layout==e.Centered&&this.elements.userList.rows.length==1&&this.elements.userList.rows[0].scrollLeft>0){this.elements.ear.left.classList.add("bx-messenger-videocall-ear-show")}else{this.elements.ear.left.classList.remove("bx-messenger-videocall-ear-show")}};BX.Call.View.prototype.scrollUserBlockLeft=function(){this.stopScroll();this.scrollInterval=setInterval(function(){this.elements.userList.rows[0].scrollLeft-=10}.bind(this),20)};BX.Call.View.prototype.scrollUseBlockRight=function(){this.stopScroll();this.scrollInterval=setInterval(function(){this.elements.userList.rows[0].scrollLeft+=10}.bind(this),20)};BX.Call.View.prototype.stopScroll=function(){if(this.scrollInterval){clearInterval(this.scrollInterval);this.scrollInterval=0}};BX.Call.View.prototype._onBodyClick=function(e){this.callbacks.onBodyClick()};BX.Call.View.prototype._onFullScreenChange=function(e){if(BX.browser.IsChrome()||BX.browser.IsSafari()){this.isFullScreen=document.webkitFullscreenElement==this.elements.root}else if(BX.browser.IsFirefox()){this.isFullScreen=document.mozFullscreenElement==this.elements.root}if(this.isFullScreen){if(this.elements.userList.addButton){BX.remove(this.elements.userList.addButton)}}else{if(this.elements.userList.addButton){this.elements.userList.rows[this.elements.userList.rows.length-1].appendChild(this.elements.userList.addButton)}}this.updateButtons()};BX.Call.View.prototype._onResize=function(){if(this.centralUser){this.centralUser.updateAvatarWidth()}this.toggleEars()};BX.Call.View.prototype._onUserClick=function(t){var s=t.userId;if(s==this.userId){return}this.setCentralUser(s);if(this.layout==e.Grid){this.setLayout(e.Centered)}};BX.Call.View.prototype._onGridButtonClick=function(t){this.setLayout(this.layout==e.Centered?e.Grid:e.Centered)};BX.Call.View.prototype._onAddButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"inviteUser",node:e.currentTarget})};BX.Call.View.prototype._onLinkButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"settings",node:e.currentTarget})};BX.Call.View.prototype._onMicrophoneButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"toggleMute",muted:!this.isMuted})};BX.Call.View.prototype._onMicrophoneArrowClick=function(e){e.stopPropagation();if(this.microphoneList.length===0){return}c.create({parentElement:e.currentTarget,deviceList:this.microphoneList,current:this.microphoneId,onSelect:this._onMicrophoneSelected.bind(this)}).show()};BX.Call.View.prototype._onMicrophoneSelected=function(e){if(e.deviceId===this.microphoneId){return}this.callbacks.onReplaceMicrophone(e)};BX.Call.View.prototype._onCameraButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"toggleVideo",video:!this.isCameraOn})};BX.Call.View.prototype._onCameraArrowClick=function(e){e.stopPropagation();if(this.cameraList.length===0){return}c.create({parentElement:e.currentTarget,deviceList:this.cameraList,current:this.cameraId,onSelect:this._onCameraSelected.bind(this)}).show()};BX.Call.View.prototype._onCameraSelected=function(e){if(e.deviceId===this.cameraId){return}this.callbacks.onReplaceCamera(e)};BX.Call.View.prototype._onScreenButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"toggleScreenSharing",node:e.target})};BX.Call.View.prototype._onChatButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"showChat",node:e.target})};BX.Call.View.prototype._onHistoryButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"showHistory",node:e.target})};BX.Call.View.prototype._onHangupButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"hangup",node:e.target})};BX.Call.View.prototype._onCloseButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"close",node:e.target})};BX.Call.View.prototype._onFullScreenButtonClick=function(e){e.stopPropagation();this.callbacks.onButtonClick({buttonName:"fullscreen",node:e.target})};BX.Call.View.prototype.destroy=function(){if(this.elements.root){BX.cleanNode(this.elements.root,true);this.elements.root=null}window.removeEventListener("webkitfullscreenchange",this._onFullScreenChangeHandler);window.removeEventListener("mozfullscreenchange",this._onFullScreenChangeHandler);window.removeEventListener("resize",this._onResizeHandler);for(var e in this.users){if(this.users.hasOwnProperty(e)){this.users[e].destroy()}}this.centralUser.destroy();this.callbacks.onDestroy()};var i=function(e){this.parent=e.parent;this.stream=e.stream||null;this.userId=e.userId;this.language=e.language;this.hasVideo=false;this.elements={container:null,inner:null,watermark:null,video:null,user:null,userBlock:null,avatar:null,nameBlock:null,name:null};this.checkAspectInterval=setInterval(this.checkVideoAspect.bind(this),500)};i.prototype.getWatermarkUrl=function(e){switch(e){case"ua":return"/bitrix/js/im/images/watermark-white-ua.svg";case"ru":case"kz":case"by":return"/bitrix/js/im/images/watermark-white-ru.svg";default:return"/bitrix/js/im/images/watermark-white-en.svg"}};i.prototype.render=function(){this.elements.container=BX.create("div",{props:{className:"bx-messenger-videocall-video-block"},children:[this.elements.watermark=BX.create("div",{props:{className:"bx-messenger-videocall-watermark"},children:[BX.create("img",{props:{className:"bx-messenger-videocall-watermark-img",src:this.getWatermarkUrl(this.language)}})]})]});this.elements.video=BX.create("video",{props:{className:"bx-messenger-videocall-video",autoplay:true,volume:0}});this.elements.user=BX.create("div",{props:{className:"bx-messenger-audiocall"},children:[BX.create("div",{props:{className:"bx-messenger-audiocall-wrap"},children:[this.elements.inner=BX.create("div",{props:{className:"bx-messenger-audiocall-inner"},children:[this.elements.userBlock=BX.create("div",{props:{className:"bx-messenger-audiocall-user-block"},children:[BX.create("div",{props:{className:"bx-messenger-audiocall-user-block-inner"},children:[BX.create("div",{props:{className:"bx-messenger-audiocall-user"},children:[this.elements.avatar=BX.create("div",{props:{className:"bx-messenger-audiocall-user-item"}})]})]})]}),this.elements.nameBlock=BX.create("div",{props:{className:"bx-messenger-audiocall-user-name"},children:[this.elements.name=BX.create("span",{props:{className:"bx-messenger-audiocall-user-link"}})]})]})]})]});if(this.stream&&BX.Call.Util.containsVideoTrack(this.stream)){this.elements.container.appendChild(this.elements.video);this.elements.container.classList.remove("bx-messenger-videocall-audio")}else{if(this.userId!=this.parent.userId){this.elements.container.classList.add("bx-messenger-videocall-audio")}}this.updateUserInfo();return this.elements.container};i.prototype.updateUserInfo=function(){var e=this;BX.Call.Util.getUserName(this.userId).then(function(t){e.elements.name.innerText=t;return BX.Call.Util.getUserAvatar(e.userId)}).then(function(t){if(t!=""){e.elements.avatar.style.backgroundImage="url("+t+")"}else{e.elements.avatar.style.removeProperty("background-image")}})};i.prototype.updateAvatarWidth=function(){this.elements.userBlock.style.maxWidth=this.elements.inner.offsetHeight-this.elements.nameBlock.offsetHeight+"px"};i.prototype.setUserId=function(e){if(this.userId==e){return}if(e==this.parent.userId){this.setStream(this.parent.localUser.stream)}else{this.setStream(this.parent.users[e].stream)}this.userId=e;this.updateUserInfo()};i.prototype.setStream=function(e){this.stream=e;var t=BX.Call.Util.containsVideoTrack(e);if(this.hasVideo&&!t){BX.remove(this.elements.video);this.elements.container.appendChild(this.elements.user);this.elements.container.classList.add("bx-messenger-videocall-audio");this.updateAvatarWidth()}else if(!this.hasVideo&&t){BX.remove(this.elements.user);this.elements.container.appendChild(this.elements.video);this.elements.container.classList.remove("bx-messenger-videocall-audio")}this.hasVideo=t;if(this.hasVideo){this.elements.video.srcObject=e}};i.prototype.reattachStream=function(){if(this.hasVideo){this.elements.video.srcObject=this.stream}};i.prototype.setFullSize=function(e){if(e){this.elements.container.classList.add("bx-messenger-videocall-video-block-full")}else{this.elements.container.classList.remove("bx-messenger-videocall-video-block-full")}this.updateAvatarWidth()};i.prototype.isVideo=function(){};i.prototype.checkVideoAspect=function(){if(!this.elements.video){return}if(this.elements.video.videoHeight>this.elements.video.videoWidth){this.elements.video.classList.add("bx-messenger-videocall-video-vertical")}else{this.elements.video.classList.remove("bx-messenger-videocall-video-vertical")}};i.prototype.destroy=function(){this.stream=null;clearInterval(this.checkAspectInterval)};var n=function(e){this.id=e.id;this.name="";this.avatar="";this.state=e.state;this.stream=e.stream;this.talking=false;this.localUser=e.localUser===true;this.hidden=false;this.elements={root:null,container:null,video:null,avatar:null,nameContainer:null,name:null,overlay:null,state:null,removeButton:null};this.callBacks={onClick:BX.type.isFunction(e.onClick)?e.onClick:BX.DoNothing};this.checkAspectInterval=setInterval(this.checkVideoAspect.bind(this),500)};n.prototype.render=function(){var e=this;this.elements.root=BX.create("div",{props:{className:"bx-messenger-videocall-user"},dataset:{userId:this.id},children:[this.elements.container=BX.create("div",{props:{className:"bx-messenger-videocall-user-inner"}})],events:{click:function(e){e.stopPropagation();this.callBacks.onClick({userId:this.id})}.bind(this)}});if(this.talking){this.elements.root.classList.add("bx-messenger-videocall-user-talking")}if(this.localUser){this.elements.root.classList.add("bx-messenger-videocall-user-self")}this.elements.avatar=BX.create("div",{props:{className:"bx-message-videocall-user-avatar"}});BX.Call.Util.getUserAvatar(this.id).then(function(t){if(t!=""){e.elements.avatar.style.backgroundImage="url("+t+")"}else{e.elements.avatar.style.removeProperty("background-image")}});if(!this.hasVideo()){this.elements.container.appendChild(this.elements.avatar)}this.elements.video=BX.create("video",{props:{className:"bx-messenger-videocall-video",volume:0,autoplay:true}});if(this.stream&&this.stream.active){this.elements.video.srcObject=this.stream}this.elements.container.appendChild(this.elements.video);this.elements.overlay=BX.create("div",{props:{className:"bx-messenger-videocall-overlay"}});this.elements.container.appendChild(this.elements.overlay);this.elements.state=this.renderState();if(this.elements.state){this.elements.overlay.appendChild(this.elements.state)}this.elements.nameContainer=BX.create("div",{props:{className:"bx-messenger-videocall-user-name"},children:[this.elements.name=BX.create("span",{props:{className:"bx-messenger-videocall-user-text"},text:name}),BX.create("div",{props:{className:"bx-messenger-videocall-user-shadow"}})]});this.elements.container.appendChild(this.elements.nameContainer);BX.Call.Util.getUserName(this.id).then(function(t){if(t!=""){e.elements.name.innerText=t}});return this.elements.root};n.prototype.renderState=function(){var e;switch(this.state){case BX.Call.UserState.Idle:break;case BX.Call.UserState.Calling:e=BX.create("div",{props:{className:"bx-messenger-videocall-user-status"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-pic"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-dot"}}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-dot"}}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-dot"}})]}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-text"},text:BX.message("IM_M_CALL_STATUS_WAIT_ANSWER")})]});break;case BX.Call.UserState.Declined:e=BX.create("div",{props:{className:"bx-messenger-videocall-user-status bx-messenger-videocall-user-status-wide"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-pic"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-cross"}})]}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-text"},text:BX.message("IM_M_CALL_STATUS_DECLINED")})]});break;case BX.Call.UserState.Ready:case BX.Call.UserState.Connecting:e=BX.create("div",{props:{className:"bx-messenger-videocall-user-status"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-pic"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-dot"}}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-dot"}}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-dot"}})]}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-text"},text:BX.message("IM_M_CALL_STATUS_WAIT_CONNECT")})]});break;case BX.Call.UserState.Connected:break;case BX.Call.UserState.Failed:e=BX.create("div",{props:{className:"bx-messenger-videocall-user-status bx-messenger-videocall-user-status-wide"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-pic"},children:[BX.create("span",{props:{className:"bx-messenger-videocall-user-status-cross"}})]}),BX.create("span",{props:{className:"bx-messenger-videocall-user-status-text"},text:BX.message("IM_M_CALL_STATUS_CONNECTION_ERROR")})]});break}return e?e:null};n.prototype.setState=function(e){if(this.state==e){return}this.state=e;if(!this.elements.root){return}if(this.elements.state){BX.cleanNode(this.elements.overlay);this.elements.state=null}this.elements.state=this.renderState();if(this.elements.state){this.elements.overlay.appendChild(this.elements.state)}};n.prototype.setTalking=function(e){if(this.talking==e){return}this.talking=e;if(!this.elements.root){return}if(this.talking){this.elements.root.classList.add("bx-messenger-videocall-user-talking")}else{this.elements.root.classList.remove("bx-messenger-videocall-user-talking")}};n.prototype.hide=function(){if(!this.elements.root){return}this.elements.root.dataset.hidden=1};n.prototype.show=function(){if(!this.elements.root){return}delete this.elements.root.dataset.hidden};n.prototype.hasVideo=function(){return this.state==BX.Call.UserState.Connected&&BX.Call.Util.containsVideoTrack(this.stream)};n.prototype.checkVideoAspect=function(){if(!this.elements.video){return}if(this.elements.video.videoHeight>this.elements.video.videoWidth){this.elements.video.classList.add("bx-messenger-videocall-video-vertical")}else{this.elements.video.classList.remove("bx-messenger-videocall-video-vertical")}};n.prototype.destroy=function(){this.stream=null;clearInterval(this.checkAspectInterval)};var r=function(e){this.elements={root:null};this.text=BX.type.isNotEmptyString(e.text)?e.text:"";this.isGroupCall=e.isGroupCall};r.prototype.render=function(){this.elements.root=BX.create("div",{props:{className:"bx-messenger-videocall-panel-title"},html:this.getTitle(this.text)});return this.elements.root};r.prototype.getTitle=function(e){var t='<span class="bx-messenger-videocall-panel-title-name">'+BX.util.htmlspecialchars(this.text)+"</span>";if(this.isGroupCall){return BX.message("IM_M_GROUP_CALL_WITH").replace("#CHAT_NAME#",t)}else{return BX.message("IM_M_CALL_WITH").replace("#USER_NAME#",t)}};var l=function(e){this.class=e.class;this.text=BX.type.isNotEmptyString(e.text)?e.text:"";this.elements={root:null};this.callbacks={onClick:BX.type.isFunction(e.onClick)?e.onClick:BX.DoNothing}};l.prototype.render=function(){if(this.elements.root){return this.elements.root}var e;if(this.text!==""){e=BX.create("div",{props:{className:"bx-messenger-videocall-panel-text"},text:this.text})}else{e=null}this.elements.root=BX.create("div",{props:{className:"bx-messenger-videocall-panel-item"},children:[BX.create("div",{props:{className:"bx-messenger-videocall-panel-icon bx-messenger-videocall-panel-icon-"+this.class}}),e],events:{click:this.callbacks.onClick}});return this.elements.root};var a=function(e){this.text=e.text;this.elements={root:null};this.callbacks={onClick:BX.type.isFunction(e.onClick)?e.onClick:BX.DoNothing}};a.prototype.render=function(){if(this.elements.root){return this.elements.root}this.elements.root=BX.create("div",{props:{className:"bx-messenger-videocall-panel-item bx-messenger-videocall-panel-item-btn"},children:[BX.create("button",{props:{className:"ui-btn ui-btn-round bx-messenger-videocall-panel-btn ui-btn-icon-phone-down"},text:this.text})],events:{click:this.callbacks.onClick}});return this.elements.root};var o=function(e){this.class=e.class;this.text=e.text;this.enabled=e.enabled==true;this.arrowEnabled=e.arrowEnabled==true;this.elements={root:null,icon:null,arrow:null};this.callbacks={onClick:BX.type.isFunction(e.onClick)?e.onClick:BX.DoNothing,onArrowClick:BX.type.isFunction(e.onArrowClick)?e.onArrowClick:BX.DoNothing}};o.prototype.render=function(){if(this.elements.root){return this.elements.root}this.elements.root=BX.create("div",{props:{className:"bx-messenger-videocall-panel-item"},children:[this.elements.icon=BX.create("div",{props:{className:this.getIconClass()}}),BX.create("div",{props:{className:"bx-messenger-videocall-panel-text"},text:this.text})],events:{click:this.callbacks.onClick}});this.elements.arrow=BX.create("div",{props:{className:"bx-messenger-videocall-panel-arrow"},events:{click:function(e){this.callbacks.onArrowClick.apply(this,arguments);e.stopPropagation()}.bind(this)}});if(this.arrowEnabled){this.elements.icon.appendChild(this.elements.arrow)}return this.elements.root};o.prototype.getIconClass=function(){return"bx-messenger-videocall-panel-icon bx-messenger-videocall-panel-icon-"+this.class+(this.enabled?"":"-off")};o.prototype.enable=function(){if(this.enabled){return}this.enabled=true;this.elements.icon.className=this.getIconClass()};o.prototype.disable=function(){if(!this.enabled){return}this.enabled=false;this.elements.icon.className=this.getIconClass()};o.prototype.showArrow=function(){if(this.arrowEnabled){return}this.arrowEnabled=true;this.elements.icon.appendChild(this.elements.arrow)};o.prototype.hideArrow=function(){if(!this.arrowEnabled){return}this.arrowEnabled=false;this.elements.icon.removeChild(this.elements.arrow)};var c=function(e){this.deviceList=e.deviceList;this.current=e.current;this.parentElement=e.parentElement;this.menu=null;this.callbacks={onSelect:BX.type.isFunction(e.onSelect)?e.onSelect:BX.DoNothing}};c.create=function(e){return new c(e)};c.prototype.show=function(){var e=this;var t=[];this.deviceList.forEach(function(s){t.push({id:s.deviceId,text:s.label||"("+BX.message("IM_M_CALL_DEVICE_NO_NAME")+")",className:e.current==s.deviceId?"menu-popup-item-accept":"device-selector-empty",onclick:function(){e.menu.close();e.callbacks.onSelect(s)}})});this.menu=BX.PopupMenu.create("call-view-select-device",this.parentElement,t,{autoHide:true,zIndex:s+500,closeByEsc:true,offsetTop:0,offsetLeft:0,bindOptions:{position:"top"},angle:{position:"bottom"},overlay:{backgroundColor:"white",opacity:0},events:{onPopupClose:function(){e.menu.popupWindow.destroy();BX.PopupMenu.destroy("call-view-select-device")},onPopupDestroy:function(){e.menu=null}}});this.menu.popupWindow.show()};BX.Call.View.Size={Folded:"folded",Full:"full"}})();
//# sourceMappingURL=view.map.js