%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/modules/pull/demo/webrtc/components/pull.webrtc/ |
Current File : /home/bitrix/www/bitrix/modules/pull/demo/webrtc/components/pull.webrtc/demo_webrtc.min.js |
(function(e){if(!e.YourCompanyPrefix)e.YourCompanyPrefix={};if(e.YourCompanyPrefix.webrtc)return;var t=e.YourCompanyPrefix;t.webrtc=function(e){this.parent.constructor.apply(this,arguments);e=e||{};this.debug=true;this.callWindowBeforeUnload=null;this.placeholder=e.placeholder;this.signalingLink=e.signalingLink;if(this.ready()){BX.addCustomEvent("onPullEvent-ycp",BX.delegate(function(e,t){if(e=="call"){this.log("Incoming",t.command,t.senderId,JSON.stringify(t));if(t.command=="invite"){if(this.callInit){BX.ajax({url:this.signalingLink+"?CALL_SIGNALING",method:"POST",dataType:"json",timeout:30,data:{COMMAND:"busy",USER_ID:t.senderId,sessid:BX.bitrix_sessid()}})}else{this.initiator=false;this.callVideo=true;this.callInit=true;this.callUserId=t.senderId;this.callInitUserId=t.senderId;this.drawAnswerControls()}}else if(t.command=="answer"){this.startGetUserMedia();this.drawDeclineControls()}else if(t.command=="decline"){this.callDecline()}else if(t.command=="busy"){this.callDecline(false)}else if(t.command=="ready"&&this.callInit){this.log("Apponent "+t.senderId+" ready!");this.connected[t.senderId]=true}else if(t.command=="reconnect"&&this.callActive){clearTimeout(this.pcConnectTimeout[t.senderId]);clearTimeout(this.initPeerConnectionTimeout[t.senderId]);if(this.pc[t.senderId])this.pc[t.senderId].close();delete this.pc[t.senderId];delete this.pcStart[t.senderId];if(this.callStreamMain==this.callStreamUsers[t.senderId])this.callStreamMain=null;this.callStreamUsers[t.senderId]=null;this.initPeerConnection(t.senderId)}else if(t.command=="signaling"&&this.callActive){this.signalingPeerData(t.senderId,t.peer)}else{this.log('Command "'+t.command+'" skip')}}},this));BX.garbage(function(){this.callCommand("decline",true)},this)}};BX.inheritWebrtc(t.webrtc);t.webrtc.prototype.startGetUserMedia=function(t,i){this.callWindowBeforeUnload=e.onbeforeunload;e.onbeforeunload=function(){if(typeof BX.PULL!="undefined"&&typeof BX.PULL.tryConnectDelay=="function"){BX.PULL.tryConnectDelay()}return BX.message("DW_WINDOW_RELOAD")};this.parent.startGetUserMedia.apply(this,arguments)};t.webrtc.prototype.onUserMediaSuccess=function(e){var t=this.parent.onUserMediaSuccess.apply(this,arguments);if(!t)return false;this.attachMediaStream(this.interfaceVideoSelf,this.callStreamSelf);this.interfaceVideoSelf.muted=true;BX.addClass(this.interfaceVideoSelf,"ycp-webrtc-video-self-show");this.callCommand("ready");return true};t.webrtc.prototype.onUserMediaError=function(e){var t=this.parent.onUserMediaError.apply(this,arguments);if(!t)return false;this.callDecline();return true};t.webrtc.prototype.setLocalAndSend=function(e,t){var i=this.parent.setLocalAndSend.apply(this,arguments);if(!i)return false;BX.ajax({url:this.signalingLink+"?CALL_SIGNALING",method:"POST",dataType:"json",timeout:30,data:{COMMAND:"signaling",USER_ID:e,PEER:JSON.stringify(t),sessid:BX.bitrix_sessid()}});return true};t.webrtc.prototype.onRemoteStreamAdded=function(e,t,i){if(!i)return false;this.attachMediaStream(this.interfaceVideoMain,this.callStreamMain);this.interfaceVideoMain.muted=false;this.interfaceVideoMain.volume=1;this.interfaceVideoMain.play();return true};t.webrtc.prototype.onRemoteStreamRemoved=function(e,t){};t.webrtc.prototype.onIceCandidate=function(e,t){BX.ajax({url:this.signalingLink+"?CALL_SIGNALING",method:"POST",dataType:"json",timeout:30,data:{COMMAND:"signaling",USER_ID:e,PEER:JSON.stringify(t),sessid:BX.bitrix_sessid()}})};t.webrtc.prototype.peerConnectionError=function(e,t){this.callDecline()};t.webrtc.prototype.peerConnectionReconnect=function(e){var t=this.parent.peerConnectionReconnect.apply(this,arguments);if(!t)return false;BX.ajax({url:this.signalingLink+"?CALL_RECONNECT",method:"POST",dataType:"json",timeout:30,data:{COMMAND:"reconnect",USER_ID:e,sessid:BX.bitrix_sessid()},onsuccess:BX.delegate(function(){this.initPeerConnection(e,true)},this)});return true};t.webrtc.prototype.deleteEvents=function(){if(!this.interfaceVideoMain)return false;e.onbeforeunload=this.callWindowBeforeUnload;this.interfaceVideoSelf.pause();BX.removeClass(this.interfaceVideoSelf,"ycp-webrtc-video-self-show");this.interfaceVideoMain.src="";this.interfaceVideoMain.muted=true;this.interfaceVideoMain.volume=0;this.interfaceVideoMain.pause();this.parent.deleteEvents.apply(this,arguments);return true};t.webrtc.prototype.callInvite=function(){var e=this.interfaceUserId.value?parseInt(this.interfaceUserId.value):0;if(e<=0||e==BX.message("USER_ID")){return false}this.initiator=true;this.callVideo=true;this.callInit=true;this.callActive=true;this.callUserId=e;this.callInitUserId=BX.message("USER_ID");this.callCommand("invite");this.drawWaitControls()};t.webrtc.prototype.callAnswer=function(){this.callActive=true;this.startGetUserMedia();this.callCommand("answer");this.drawDeclineControls()};t.webrtc.prototype.callDecline=function(e){e=e===false?false:true;if(e)this.callCommand("decline");this.deleteEvents();this.drawInviteControls()};t.webrtc.prototype.callCommand=function(e,t){if(!this.signalingReady())return false;BX.ajax({url:this.signalingLink+"?CALL_COMMAND",method:"POST",dataType:"json",timeout:30,async:t!=false,data:{COMMAND:e,USER_ID:this.callUserId,sessid:BX.bitrix_sessid()}})};t.webrtc.prototype.drawInterface=function(){this.interface=BX.create("div",{props:{className:"ycp-webrtc"},children:[this.interfaceVideoSelf=BX.create("video",{props:{className:"ycp-webrtc-video-self"},attrs:{autoplay:true}}),this.interfaceVideoMain=BX.create("video",{props:{className:"ycp-webrtc-video"},attrs:{autoplay:true}}),this.interfaceVideoControls=BX.create("div",{props:{className:"ycp-webrtc-controls"},html:BX.message("DW_NO_WEBRTC")})]});this.placeholder.innerHTML="";this.placeholder.appendChild(this.interface);if(this.ready()){this.drawInviteControls()}return true};t.webrtc.prototype.drawWaitControls=function(){this.interfaceVideoControls.innerHTML="";BX.adjust(this.interfaceVideoControls,{children:[BX.create("span",{props:{className:"ycp-webrtc-controls-btn ycp-webrtc-controls-btn-red"},html:BX.message("DW_VIDEO_WAIT"),events:{click:BX.delegate(this.callDecline,this)}})]})};t.webrtc.prototype.drawAnswerControls=function(){this.interfaceVideoControls.innerHTML="";BX.adjust(this.interfaceVideoControls,{children:[BX.create("span",{props:{className:"ycp-webrtc-controls-btn"},html:BX.message("DW_VIDEO_ANSWER"),events:{click:BX.delegate(this.callAnswer,this)}}),BX.create("span",{props:{className:"ycp-webrtc-controls-btn ycp-webrtc-controls-btn-red"},html:BX.message("DW_VIDEO_DECLINE"),events:{click:BX.delegate(this.callDecline,this)}})]})};t.webrtc.prototype.drawDeclineControls=function(){this.interfaceVideoControls.innerHTML="";BX.adjust(this.interfaceVideoControls,{children:[BX.create("span",{props:{className:"ycp-webrtc-controls-btn ycp-webrtc-controls-btn-red"},html:BX.message("DW_VIDEO_DECLINE"),events:{click:BX.delegate(this.callDecline,this)}})]})};t.webrtc.prototype.drawInviteControls=function(){this.interfaceVideoControls.innerHTML="";BX.adjust(this.interfaceVideoControls,{children:[this.interfaceUserId=BX.create("input",{props:{className:"ycp-webrtc-controls-input"},attrs:{placeholder:BX.message("DW_PUT_USER_ID"),type:"input"}}),BX.create("span",{props:{className:"ycp-webrtc-controls-btn"},html:BX.message("DW_VIDEO_CALL"),events:{click:BX.delegate(this.callInvite,this)}})]})}})(window); //# sourceMappingURL=demo_webrtc.map.js