Current Path : /var/www/axolotl/data/www/yar.axolotls.ru/bitrix/js/im/call/ |
Current File : /var/www/axolotl/data/www/yar.axolotls.ru/bitrix/js/im/call/engine.min.js |
(function(){BX.namespace("BX.Call");BX.Call.State={Incoming:"Incoming"};BX.Call.UserState={Idle:"Idle",Busy:"Busy",Calling:"Calling",Unavailable:"Unavailable",Declined:"Declined",Ready:"Ready",Connecting:"Connecting",Connected:"Connected",Failed:"Failed"};BX.Call.Type={Instant:1,Permanent:2};BX.Call.Provider={Plain:"Plain",Voximplant:"Voximplant",Janus:"Janus"};BX.Call.StreamTag={Main:"main",Screen:"screen"};BX.Call.Direction={Incoming:"Incoming",Outgoing:"Outgoing"};BX.Call.Quality={VeryHigh:"very_high",High:"high",Medium:"medium",Low:"low",VeryLow:"very_low"};BX.Call.Event={onUserInvited:"onUserInvited",onUserStateChanged:"onUserStateChanged",onUserMicrophoneState:"onUserMicrophoneState",onUserVoiceStarted:"onUserVoiceStarted",onUserVoiceStopped:"onUserVoiceStopped",onLocalMediaReceived:"onLocalMediaReceived",onLocalMediaStopped:"onLocalMediaStopped",onDeviceListUpdated:"onDeviceListUpdated",onRTCStatsReceived:"onRTCStatsReceived",onCallFailure:"onCallFailure",onStreamReceived:"onStreamReceived",onStreamRemoved:"onStreamRemoved",onJoin:"onJoin",onLeave:"onLeave",onDestroy:"onDestroy"};var e={createCall:"im.call.create",createChildCall:"im.call.createChildCall",getPublicChannels:"pull.channel.public.list",getCall:"im.call.get"};var l=false;BX.Call.Engine=function(){this.debugFlag=false;if(!l){throw new Error("Do not use this constructor directly, use BX.Call.Engine.getInstance instead")}this.calls={};this.userId=Number(BX.message("USER_ID"));this.unknownCalls={};this.restClient=null;this.init()};BX.Call.Engine.getInstance=function(){return BX.CallEngine};BX.Call.Engine.prototype.init=function(){BX.addCustomEvent("onPullEvent-im",this.__onPullEvent.bind(this));BX.addCustomEvent("onPullClientEvent-im",this.__onPullClientEvent.bind(this))};BX.Call.Engine.prototype.getCurrentUserId=function(){return this.userId};BX.Call.Engine.prototype.setRestClient=function(e){this.restClient=e};BX.Call.Engine.prototype.getRestClient=function(){return this.restClient||BX.rest};BX.Call.Engine.prototype.createCall=function(l){var n=this;return new Promise(function(i,a){var r=l.type||BX.Call.Type.Instant;var o=l.provider||n.getDefaultProvider();if(l.joinExisting){for(var s in n.calls){if(n.calls.hasOwnProperty(s)){var c=n.calls[s];if(c.provider==l.provider&&c.associatedEntity.type==l.entityType&&c.associatedEntity.id==l.entityId){n.log(s,"Found existing call, attaching to it");return i({call:c,isNew:false})}}}}var u={type:r,provider:o,entityType:l.entityType,entityId:l.entityId,joinExisting:!!l.joinExisting,userIds:BX.type.isArray(l.userIds)?l.userIds:[]};n.getRestClient().callMethod(e.createCall,u).then(function(e){if(e.error()){var r=e.error().getError();return a({code:r.error,message:r.error_description})}var o=e.data();if(o.userData){BX.MessengerCommon.updateUserData(o.userData)}if(o.publicChannels){BX.PULL.setPublicIds(Object.values(o.publicChannels))}var s=o.call;if(n.calls[s["ID"]]){if(n.calls[s["ID"]]instanceof t){n.calls[s["ID"]].destroy()}else{console.error("Call "+s["ID"]+" already exists");return i({call:n.calls[s["ID"]],isNew:false})}}var c=n.__getCallFabric(s["PROVIDER"]);var u=c.createCall({id:parseInt(s["ID"],10),instanceId:n.getUuidv4(),direction:BX.Call.Direction.Outgoing,users:o.users,videoEnabled:l.videoEnabled==true,enableMicAutoParameters:l.enableMicAutoParameters!==false,associatedEntity:s.ASSOCIATED_ENTITY,events:{onDestroy:n.__onCallDestroy.bind(n)},debug:l.debug===true});n.calls[s["ID"]]=u;if(o.isNew){n.log(u.id,"Creating new call")}else{n.log(u.id,"Server returned existing call, attaching to it")}BX.onCustomEvent(window,"CallEvents::callCreated",[{call:u}]);i({call:u,isNew:o.isNew})}).catch(function(e){if(BX.type.isFunction(e.error)){e=e.error().getError()}a({code:e.error,message:e.error_description})})})};BX.Call.Engine.prototype.createChildCall=function(l,t,n){var i=this;return new Promise(function(a,r){if(!i.calls[l]){return r("Parent call is not found")}var o=i.calls[l];var s={parentId:l,newProvider:t,newUsers:n};i.getRestClient().callMethod(e.createChildCall,s,function(e){var l=e.data();var t=l.call;var n=i.__getCallFabric(t["PROVIDER"]);var r=n.createCall({id:parseInt(t["ID"],10),instanceId:i.getUuidv4(),parentId:t["PARENT_ID"],direction:BX.Call.Direction.Outgoing,users:l.users,videoEnabled:o.isVideoEnabled(),enableMicAutoParameters:o.enableMicAutoParameters!==false,associatedEntity:t.ASSOCIATED_ENTITY,events:{onDestroy:i.__onCallDestroy.bind(i)}});i.calls[t["ID"]]=r;BX.onCustomEvent(window,"CallEvents::callCreated",[{call:r}]);a({call:r,isNew:l.isNew})})})};BX.Call.Engine.prototype._instantiateCall=function(e,l){if(this.calls[e["ID"]]){console.error("Call "+e["ID"]+" already exists");return this.calls[e["ID"]]}var t=this.__getCallFabric(e["PROVIDER"]);var n=t.createCall({id:parseInt(e["ID"],10),instanceId:this.getUuidv4(),initiatorId:parseInt(e["INITIATOR_ID"],10),parentId:e["PARENT_ID"],direction:e["INITIATOR_ID"]==this.userId?BX.Call.Direction.Outgoing:BX.Call.Direction.Incoming,users:l,associatedEntity:e.ASSOCIATED_ENTITY,events:{onDestroy:this.__onCallDestroy.bind(this)}});this.calls[e["ID"]]=n;BX.onCustomEvent(window,"CallEvents::callCreated",[{call:n}]);return n};BX.Call.Engine.prototype.getCallWithId=function(l){var t=this;return new Promise(function(n,i){if(t.calls[l]){return n({call:t.calls[l],isNew:false})}t.getRestClient().callMethod(e.getCall,{callId:l}).then(function(e){var l=e.data();n({call:t._instantiateCall(l.call,l.users),isNew:false})}).catch(function(e){if(BX.type.isFunction(e.error)){e=e.error().getError()}i({code:e.error,message:e.error_description})})})};BX.Call.Engine.prototype.getUuidv4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var l=Math.random()*16|0,t=e=="x"?l:l&3|8;return t.toString(16)})};BX.Call.Engine.prototype.__onPullEvent=function(e,l,t){var n={"Call::incoming":this.__onPullIncomingCall.bind(this)};if(e.substr(0,6)==="Call::"&&l.publicIds){BX.PULL.setPublicIds(Object.values(l.publicIds))}if(n[e]){n[e].call(this,l,t)}else if(e.substr(0,6)==="Call::"&&(l["call"]||l["callId"])){var i=l["call"]?l["call"]["ID"]:l["callId"];if(this.calls[i]){this.calls[i].__onPullEvent(e,l,t)}else if(e==="Call::ping"){this.__onUnknownCallPing(l,t).then(function(n){if(n&&this.calls[i]){this.calls[i].__onPullEvent(e,l,t)}}.bind(this))}}};BX.Call.Engine.prototype.__onPullClientEvent=function(e,l,t){if(e.substr(0,6)==="Call::"&&l["callId"]){var n=l["callId"];if(this.calls[n]){this.calls[n].__onPullEvent(e,l,t)}else if(e==="Call::ping"){this.__onUnknownCallPing(l,t).then(function(i){if(i&&this.calls[n]){this.calls[n].__onPullEvent(e,l,t)}}.bind(this))}}};BX.Call.Engine.prototype.__onPullIncomingCall=function(e,l){if(l.server_time_ago>30){console.error("Call was started too long time ago");return}var t=e.call;var n=parseInt(t.ID,10);var i;if(e.publicIds){BX.PULL.setPublicIds(Object.values(e.publicIds))}if(e.userData){BX.MessengerCommon.updateUserData(e.userData)}if(this.calls[n]){i=this.calls[n]}else{var a=this.__getCallFabric(t.PROVIDER);i=a.createCall({id:n,instanceId:this.getUuidv4(),parentId:t.PARENT_ID||null,callFromMobile:e.isMobile===true,direction:BX.Call.Direction.Incoming,users:e.users,initiatorId:e.senderId,associatedEntity:t.ASSOCIATED_ENTITY,events:{onDestroy:this.__onCallDestroy.bind(this)}});this.calls[n]=i;BX.onCustomEvent(window,"CallEvents::callCreated",[{call:i}])}i.addInvitedUsers(e.invitedUsers);if(i){BX.onCustomEvent(window,"CallEvents::incomingCall",[{call:i,video:e.video===true,isMobile:e.isMobile===true}])}this.log(i.id,"Incoming call "+i.id)};BX.Call.Engine.prototype.__onUnknownCallPing=function(e,l){return new Promise(function(t,n){var i=Number(e.callId);if(l.server_time_ago>10){this.log(i,"Error: Ping was sent too long time ago");return t(false)}if(!window.BXIM||!window.BXIM.init){return t(false)}if(this.unknownCalls[i]){return t(false)}this.unknownCalls[i]=true;if(e.userData){BX.MessengerCommon.updateUserData(e.userData)}this.getCallWithId(i).then(function(e){this.unknownCalls[i]=false;t(true)}.bind(this)).catch(function(e){this.unknownCalls[i]=false;this.log(i,"Error: Could not instantiate call",e);t(false)}.bind(this))}.bind(this))};BX.Call.Engine.prototype.__onCallDestroy=function(e){var l=e.call.id;this.calls[l]=new t({callId:l,onDelete:function(){if(this.calls[l]){delete this.calls[l]}}.bind(this)});BX.onCustomEvent(window,"CallEvents::callDestroyed",[{callId:e.call.id}])};BX.Call.Engine.prototype.getDefaultProvider=function(){return BX.Call.Provider.Plain};BX.Call.Engine.prototype.__getCallFabric=function(e){if(e==BX.Call.Provider.Plain){return BX.Call.PlainCallFabric}else if(e==BX.Call.Provider.Voximplant){return BX.Call.VoximplantCallFabric}else if(e==BX.Call.Provider.Janus){return BX.Call.JanusCallFabric}throw new Error("Unknown call provider type "+e)};BX.Call.Engine.prototype.debug=function(e){this.debugFlag=typeof e==="undefined"?true:!!e;return this.debugFlag};BX.Call.Engine.prototype.log=function(){var e=BX.Call.Util.getDateForLog();var l=typeof arguments[0]==="number"?arguments[0]:0;for(var t=l>0?1:0;t<arguments.length;t++){if(arguments[t]instanceof Error){e=arguments[t].message+"\n"+arguments[t].stack}else{try{e=e+" | "+(typeof arguments[t]=="object"?JSON.stringify(arguments[t]):arguments[t])}catch(l){e=e+" | (circular structure)"}}}if(BX.desktop&&BX.desktop.ready()){BX.desktop.log(BX.message("USER_ID")+".video.log",e.substr(3))}if(this.debugFlag){if(console){var n=["Call log ["+BX.Call.Util.getTimeForLog()+"]: "];console.log.apply(this,n.concat(Array.prototype.slice.call(arguments)))}}if(BX.MessengerDebug&&l){BX.MessengerDebug.addLog(l,e)}};BX.Call.Engine.prototype.getAllowedVideoQuality=function(e){if(e<5){return BX.Call.Quality.VeryHigh}else if(e<8){return BX.Call.Quality.High}else if(e<16){return BX.Call.Quality.Medium}else if(e<24){return BX.Call.Quality.Low}else{return BX.Call.Quality.VeryLow}};BX.Call.PlainCallFabric={createCall:function(e){return new BX.Call.PlainCall(e)}};BX.Call.VoximplantCallFabric={createCall:function(e){return new BX.Call.VoximplantCall(e)}};BX.Call.JanusCallFabric={createCall:function(e){return new BX.Call.JanusCall(e)}};var t=function(e){this.callId=e.callId;this.lifetime=e.lifetime||120;this.callbacks={onDelete:BX.type.isFunction(e.onDelete)?e.onDelete:BX.DoNothing};this.deleteTimeout=setTimeout(function(){this.callbacks.onDelete({callId:this.callId})}.bind(this),this.lifetime*1e3)};t.prototype.__onPullEvent=function(e,l,t){};t.prototype.isAnyoneParticipating=function(){return false};t.prototype.addEventListener=function(){return false};t.prototype.removeEventListener=function(){return false};t.prototype.destroy=function(){clearTimeout(this.deleteTimeout);this.callbacks.onDelete=BX.DoNothing};l=true;BX.CallEngine=new BX.Call.Engine;l=false})(); //# sourceMappingURL=engine.map.js