goeasy-rtc 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GRTC.d.ts +1 -0
- package/goeasy-rtc.esm.min.js +1 -1
- package/package.json +1 -1
package/GRTC.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export default class GRTC {
|
|
|
13
13
|
static toggleSpeaker(enabled: boolean): void;
|
|
14
14
|
static muteCamera(enabled: boolean): void;
|
|
15
15
|
static switchCamera(): void;
|
|
16
|
+
static play(userId?: string): void;
|
|
16
17
|
static on(event: any, callback: Function): void;
|
|
17
18
|
static off(event: any, callback: any): void;
|
|
18
19
|
}
|
package/goeasy-rtc.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{c(s.next(t))}catch(t){o(t)}}function a(t){try{c(s.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}c((s=s.apply(t,e||[])).next())}))}var e;"function"==typeof SuppressedError&&SuppressedError,function(t){t.RTC_LOST="RTC_LOST",t.RTC_RECONNECT="RTC_RECONNECT",t.RTC_TIMEOUT="RTC_TIMEOUT",t.RTC_ACCEPTED="RTC_ACCEPTED",t.RECEIVED_RTC_REMOTE_FLOW="RECEIVED_RTC_REMOTE_FLOW",t.GOEASY_TIMEOUT="GOEASY_TIMEOUT",t.GOEASY_DISCONNECTED="GOEASY_DISCONNECTED",t.RTC_REMOTE_MIC_CHANGED="RTC_REMOTE_MIC_CHANGED",t.RTC_REMOTE_CAMERA_CHANGED="RTC_REMOTE_CAMERA_CHANGED"}(e||(e={}));var i={exports:{}};!function(t){function e(t){if(t)return function(t){for(var i in e.prototype)t[i]=e.prototype[i];return t}(t)}i.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},e.prototype.once=function(t,e){function i(){this.off(t,i),e.apply(this,arguments)}return i.fn=e,this.on(t,i),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i,s=this._callbacks["$"+t];if(!s)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n=0;n<s.length;n++)if((i=s[n])===e||i.fn===e){s.splice(n,1);break}return this},e.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),i=this._callbacks["$"+t];if(i)for(var s=0,n=(i=i.slice(0)).length;s<n;++s)i[s].apply(this,e);return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}}();var s=i.exports,n={exports:{}},o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(o){var r=new Uint8Array(16);n.exports=function(){return o(r),r}}else{var a=new Array(16);n.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),a[e]=t>>>((3&e)<<3)&255;return a}}for(var c=[],l=0;l<256;++l)c[l]=(l+256).toString(16).substr(1);var u,d,C=function(t,e){var i=e||0,s=c;return[s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]]].join("")},m=n.exports,h=C,E=0,p=0;var T=function(t,e,i){var s=e&&i||0,n=e||[],o=(t=t||{}).node||u,r=void 0!==t.clockseq?t.clockseq:d;if(null==o||null==r){var a=m();null==o&&(o=u=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==r&&(r=d=16383&(a[6]<<8|a[7]))}var c=void 0!==t.msecs?t.msecs:(new Date).getTime(),l=void 0!==t.nsecs?t.nsecs:p+1,C=c-E+(l-p)/1e4;if(C<0&&void 0===t.clockseq&&(r=r+1&16383),(C<0||c>E)&&void 0===t.nsecs&&(l=0),l>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");E=c,p=l,d=r;var T=(1e4*(268435455&(c+=122192928e5))+l)%4294967296;n[s++]=T>>>24&255,n[s++]=T>>>16&255,n[s++]=T>>>8&255,n[s++]=255&T;var R=c/4294967296*1e4&268435455;n[s++]=R>>>8&255,n[s++]=255&R,n[s++]=R>>>24&15|16,n[s++]=R>>>16&255,n[s++]=r>>>8|128,n[s++]=255&r;for(var f=0;f<6;++f)n[s+f]=o[f];return e||h(n)},R=n.exports,f=C;var g=function(t,e,i){var s=e&&i||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var n=(t=t||{}).random||(t.rng||R)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e)for(var o=0;o<16;++o)e[s+o]=n[o];return e||f(n)},v=T,y=g,_=y;_.v1=v,_.v4=y;var I=_;class S{support(){return!0}getParams(){return this.params}setData(t){this.active=t.a,this.data=t.d}preConnect(t){}postConnect(){}}const A=s;class D{constructor(){this.emitter=new A}on(t,e){return this.emitter.on(t,e),this}once(t,e){return this.emitter.once(t,e),this}off(t,e){return this.emitter.off(t,e),this}fire(t,e){return this.emitter.emit(t,e),this}}class b{constructor(){this.eventDriver=new D}on(t,e){this.eventDriver.on(t,e)}off(t,e){this.eventDriver.off(t,e)}fire(t,e){this.eventDriver.fire(t,e)}}let N=new class{isDef(t){return!this.isUndef(t)}isUndef(t){return null==t}isPrimitive(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}isObject(t){return null!==t&&"object"==typeof t}isPlainObject(t){return"[object Object]"===Object.prototype.toString.call(t)}isRegExp(t){return"[object RegExp]"===Object.prototype.toString.call(t)}isValidArrayIndex(t){let e=parseFloat(String(t));return e>=0&&Math.floor(e)===e&&isFinite(t)}isString(t){return"string"==typeof t}isNumber(t){return"number"==typeof t}isStringOrNumber(t){return this.isString(t)||this.isNumber(t)}isArray(t){return"[object Array]"===Object.prototype.toString.call(t)}isEmpty(t){return this.isArray(t)?0===t.length:this.isObject(t)?!this.isDef(t):!this.isNumber(t)&&(this.isString(t)?""===t.trim():!this.isDef(t))}isNative(t){return"function"==typeof t&&/native code/.test(t.toString())}isFunction(t){return"function"==typeof t}isBoolean(t){return"boolean"==typeof t}isTrue(t){return!0===t}isFalse(t){return!1===t}isNull(t){return null===t}};const w=s;class M{constructor(){this.emitter=new w}on(t,e){if(!N.isString(t))throw Error("event require a string.");if(!N.isFunction(e))throw Error("callback must be a function");this.emitter.on(t,e)}fire(t,e){this.emitter.emit(t,e)}off(t,e){this.emitter.off(t,e)}}class O{static init(t,e,i,s,n,o){this.Socket=t,this.N=e,this.Member=i,this.v=s,this.Platform=n,this.GModules=o}}const U=I;class k{static get(){return U.v1().replace(/-/g,"")}}var P,L,G;(L=P||(P={})).WRITE="WRITE",L.READ="READ",L.NONE="NONE";class x{constructor(t){this.permission=P.NONE,this.singleTimeout=0,this.totalTimeout=0,this.startTime=0,this.complete=!1,this.retried=0,this.unique=!1,this.uuid=k.get(),this.name=t.name,this.params=t.params,this.permission=t.permission,this.totalTimeout=t.totalTimeout,this.singleTimeout=t.singleTimeout,t.unique&&(this.unique=t.unique),this.success=e=>{this.complete||(this.end(),t.success(e))},this.fail=e=>{this.complete||(this.end(),t.fail(e))}}start(){this.startTime=Date.now(),this.initAutoTimeout()}end(){this.complete=!0,clearTimeout(this.timeoutHandler)}initAutoTimeout(){this.timeoutHandler=setTimeout((()=>{this.complete||this.fail({resultCode:408,content:"Host unreachable or timeout"})}),this.totalTimeout)}}class j extends b{static init(){this.i=new j}}class q{constructor(){j.i.on(e.RTC_LOST,(()=>this.onRTCLost())),j.i.on(e.RTC_RECONNECT,(()=>this.onRTCReconnect()))}onRTCLost(){this.rtcLostTimeoutId=setTimeout((()=>{j.i.fire(e.RTC_TIMEOUT)}),1e4)}onRTCReconnect(){clearTimeout(this.rtcLostTimeoutId)}onGoEasyLost(){this.goeasyLostTimeoutId=setTimeout((()=>{j.i.fire(e.GOEASY_TIMEOUT)}),2e4)}onGoEasyReconnected(){clearTimeout(this.goeasyLostTimeoutId)}}!function(t){t.RTC_CMD="RTC_CMD",t.RTC_PKT="RTC_PKT"}(G||(G={}));class F{constructor(){if(this.rtcClientPlugin=uni.requireNativePlugin("RTCClientPlugin"),!this.rtcClientPlugin)throw"Please configure GoEasy RTC native plugin first: https://www.goeasy.io"}}var H,V,W,Q,Y;!function(t){t[t.AUDIO=0]="AUDIO",t[t.VIDEO=1]="VIDEO"}(H||(H={}));class ${constructor(t,e,i){this.name=t,this.callId=e,this.data=i}static createCallCommand(t,e,i){let s={calleeIds:t.callees.map((t=>t.id)),mediaType:i.mediaType,groupId:i.groupId,callId:e};return i.notification&&(s.notification=i.notification),new $(V.CALL,e,s)}}!function(t){t.CALL="CALL",t.QUIT="QUIT",t.BUSY="BUSY",t.ACCEPT="ACCEPT",t.RANG="RANG",t.HANGUP="HANGUP",t.CANCEL="CANCEL",t.REJECT="REJECT",t.RTC_DISCONNECT="RTC_DISCONNECT",t.GET_TOKEN="GET_TOKEN"}(V||(V={})),function(t){t[t.connect=3e3]="connect",t[t.reconnectionDelayMax=3e3]="reconnectionDelayMax",t[t.commonQuerySingle=2500]="commonQuerySingle",t[t.commonQueryTotal=12e3]="commonQueryTotal",t[t.commonRequestSingle=1700]="commonRequestSingle",t[t.commonRequestTotal=12e3]="commonRequestTotal",t[t.commonInfiniteSingle=1700]="commonInfiniteSingle",t[t.commonInfiniteTotal=864e5]="commonInfiniteTotal"}(W||(W={}));class K extends F{constructor(){super(),this.joined=!1,plus.globalEvent.addEventListener("connectionLost",(()=>{j.i.fire(e.RTC_LOST)})),plus.globalEvent.addEventListener("connectionRecovery",(t=>{j.i.fire(e.RTC_RECONNECT)})),plus.globalEvent.addEventListener("receivedRemoteFlow",(t=>{j.i.fire(e.RECEIVED_RTC_REMOTE_FLOW,t)})),plus.globalEvent.addEventListener("remoteMicChanged",(t=>{j.i.fire(e.RTC_REMOTE_MIC_CHANGED,t)})),plus.globalEvent.addEventListener("remoteCameraChanged",(t=>{j.i.fire(e.RTC_REMOTE_CAMERA_CHANGED,t)}))}destroy(){plus.globalEvent.removeEventListener("connectionLost"),plus.globalEvent.removeEventListener("connectionRecovery"),plus.globalEvent.removeEventListener("receivedRemoteFlow"),plus.globalEvent.removeEventListener("remoteMicChanged"),plus.globalEvent.removeEventListener("remoteCameraChanged"),this.joined&&(this.leave(),this.joined=!1),this.rtcClientPlugin.destroyEngine()}createEngine(e,i){return t(this,void 0,void 0,(function*(){return this.token=yield this.getNewToken(i),this.token.video=e===H.VIDEO,this.token.userId=O.Socket.user().id,this.rtcClientPlugin.createRTCClient({vendor:this.token.vendor,userId:this.token.userId}),this.token.callId}))}join(){return new Promise(((t,e)=>{this.rtcClientPlugin.joinChannel(this.token,(()=>{this.token.userId,this.token.callId,this.joined=!0,t()}),(t=>{this.token.userId,this.token.callId,e({code:400,content:"Failed to join Channel, error code:"+t})}))}))}push(){this.token.video?this.rtcClientPlugin.callVideo():this.rtcClientPlugin.callAudio()}leave(){this.rtcClientPlugin.leaveChannel()}requestPermission(t){return new Promise(((e,i)=>{H.VIDEO===t?this.rtcClientPlugin.requestVideoCallPermission((t=>{200===t?e():i({code:403,content:"Failed to request video call permission, error code:"+t})})):H.AUDIO===t?this.rtcClientPlugin.requestVoiceCallPermission((t=>{200===t?e():i({code:403,content:"Failed to request voice call permission, error code:"+t})})):i({code:400,content:"Unsupported media type"})}))}accept(){return t(this,void 0,void 0,(function*(){yield this.join(),this.push()}))}getNewToken(e){return t(this,void 0,void 0,(function*(){let t={name:V.GET_TOKEN};return e&&(t.callId=e),new Promise(((e,i)=>{let s=new x({name:G.RTC_CMD,params:t,permission:P.WRITE,singleTimeout:W.commonRequestSingle,totalTimeout:W.commonRequestTotal,success:t=>{e(t.content)},fail:t=>{i(t)}});O.Socket.e(s)}))}))}muteMic(t){this.rtcClientPlugin.muteMic({enabled:t})}toggleSpeaker(t){this.rtcClientPlugin.enableSpeaker({enabled:t})}muteCamera(t){this.rtcClientPlugin.muteCamera({enabled:t})}switchCamera(){this.rtcClientPlugin.switchCamera()}}class B{static setStatus(t){this.status&&this.status.destroy(),this.status=t,Et.callContext.call.status=t.name()}static clearStatus(){this.status.destroy(),this.status=null}}!function(t){t.RING="RING",t.USER_RANG="U_RANG",t.USER_QUIT="U_QUIT",t.USER_ACCEPTED="U_ACCEPTED",t.ENDED="ENDED"}(Q||(Q={}));class J{constructor(){this.callees=new Array}getDuration(){return Math.floor((Date.now()-this.acceptedAt)/1e3)}}class z{constructor(t,e,i){this.micMuted=!1,this.cameraMuted=!1,this.id=t,this.data=e,this.status=i}}class X{constructor(t){this.call=new J,this.cloudRTC=new K,this.acceptedUsers=new Z,this.call=t}}class Z{constructor(){this.acceptedUsers=new Map,this.onRTCRemoteFlow=t=>{this.updateUserStatus(t.userId,{remoteFlow:!0}),this.tryFireUserAccepted(t.userId)},this.onUserAcceptPacket=t=>{t.name===Q.USER_ACCEPTED&&(this.updateUserStatus(t.data.userId,{acceptPacket:!0}),this.tryFireUserAccepted(t.data.userId))},O.Socket.onMessage(G.RTC_PKT,this.onUserAcceptPacket),j.i.on(e.RECEIVED_RTC_REMOTE_FLOW,this.onRTCRemoteFlow)}updateUserStatus(t,e){let i;const s=this.acceptedUsers;i=s.has(t)?s.get(t):{acceptPacket:!1,remoteFlow:!1},s.set(t,Object.assign(Object.assign({},i),e))}tryFireUserAccepted(t){const e=this.acceptedUsers;if(e.has(t)){const i=e.get(t);i.remoteFlow&&i.acceptPacket&&(e.delete(t),B.status.onUserAccepted({userId:t}))}}destroy(){O.Socket.offMessage(G.RTC_PKT,this.onUserAcceptPacket),j.i.off(e.RECEIVED_RTC_REMOTE_FLOW,this.onRTCRemoteFlow)}}class tt{static init(){this.eventCenter=new M}static on(t,e){this.eventCenter.on(t,e)}static fire(t,e){this.eventCenter.fire(t,e)}static off(t,e){this.eventCenter.off(t,e)}}!function(t){t.RING="RING",t.USER_RANG="USER_RANG",t.USER_QUIT="USER_QUIT",t.USER_ACCEPTED="USER_ACCEPTED",t.CALL_ENDED="CALL_ENDED",t.USER_MIC_CHANGED="USER_MIC_CHANGED",t.USER_CAMERA_CHANGED="USER_CAMERA_CHANGED"}(Y||(Y={}));class et extends S{static init(t){t.c(O),this.module=new et,this.module.name=this.RTC_MODULE_NAME;let e=null;if(this.supportApp()){let t=uni.requireNativePlugin("RTCClientPlugin");t&&(e=t.v())}this.module.params={v:{n:"goeasy-rtc",v:"0.2.1",npv:e}},O.GModules.initModule(this.module)}static check(){if(!this.module)throw new Error("Please init GRTC first.");if(!this.module.active)throw new Error("RTC unavailable. Please confirm if your GoEasy application supports RTC or contact GoEasy team.");if(!this.supportApp())throw new Error("GRTC is only supported in Android and iOS apps developed with UniApp");if(!this.supportGoEasyVersion())throw new Error("GRTC is only supported in GoEasy SDK version 2.10.0 or later")}static supportGoEasyVersion(){return O.v.localeCompare("2.10.0",void 0,{numeric:!0,sensitivity:"base"})>=0}static supportApp(){return[O.Platform.type.UNI_ANDROID,O.Platform.type.UNI_IOS].includes(O.Platform.current)}support(){return et.supportGoEasyVersion()&&et.supportApp()}postConnect(){j.init(),tt.init(),pt.init()}}et.RTC_MODULE_NAME="GRTC";let it=new class{isDef(t){return!this.isUndef(t)}isUndef(t){return null==t}isPrimitive(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}isObject(t){return null!==t&&"object"==typeof t}isString(t){return"string"==typeof t}isNumber(t){return"number"==typeof t}isStringOrNumber(t){return this.isString(t)||this.isNumber(t)}isArray(t){return"[object Array]"===Object.prototype.toString.call(t)}isEmpty(t){return this.isArray(t)?0===t.length:this.isObject(t)?!this.isDef(t):!this.isNumber(t)&&(this.isString(t)?""===t.trim():!this.isDef(t))}isNative(t){return"function"==typeof t&&/native code/.test(t.toString())}isFunction(t){return"function"==typeof t}};const st=new class{validateId(t,e){if(it.isEmpty(t))throw{code:400,content:` ${e} is required.`};if(!it.isStringOrNumber(t))throw{code:400,content:`TypeError: ${e} require string or number.`}}validateNotification(t){function e(t,e,i){if(!(it.isString(t[e])&&t[e].length<=i))throw{code:400,content:`notification.${e} must be a string of no more than ${i} characters`}}function i(t,e,i,s){let n=t[e];if(it.isObject(n)&&it.isDef(n[i])){let t={code:400,content:`notification.vendorOptions.${e}.${i} require a ${s}}`},o=n[i];if("string"===s&&!it.isString(o))throw t;if("number"===s&&!it.isNumber(o))throw t}}if(!it.isObject(t))throw{code:400,content:"TypeError: notification requires an object."};{if(e(t,"title",32),e(t,"body",50),it.isDef(t.sound)&&!it.isString(t.sound))throw{code:400,content:"notification.sound must be a string"};if(it.isDef(t.badge)&&!it.isString(t.badge))throw{code:400,content:"notification.badge must be a string"};t.badge=t.badge||"0";let s=t.vendorOptions;it.isObject(s)&&(i(s,"huawei","category","string"),i(s,"xiaomi","channel_id","string"),i(s,"oppo","channel_id","string"),i(s,"vivo","classification","number"),i(s,"vivo","category","string"))}}validateObject(t,e){if(it.isUndef(t)||!it.isObject(t))throw{code:400,content:e+" must be an object."}}validateString(t,e){if(it.isUndef(t)||!it.isString(t))throw{code:400,content:e+" must be a string."}}};var nt;!function(t){t.ALL_BUSY="ALL_BUSY",t.DIAL_FAILED="DIAL_FAILED",t.CANCELLED="CANCELLED",t.REJECTED="REJECTED",t.HUNG_UP="HUNG_UP",t.RTC_DISCONNECTED="RTC_DISCONNECTED",t.GOEASY_DISCONNECTED="GOEASY_DISCONNECTED",t.HANDLED_ON_ANOTHER_DEVICE="HANDLED_ON_ANOTHER_DEVICE",t.RING_TIMEOUT="RING_TIMEOUT",t.ACCEPT_FAILED="ACCEPT_FAILED",t.DIAL_TIMEOUT="DIAL_TIMEOUT"}(nt||(nt={}));class ot{onRTCRemoteFlow(t){}onUserAcceptPacket(t){}onUserRang(e){return t(this,void 0,void 0,(function*(){Et.updateMemberStatus(e.callerId,"Ringing");const t=yield O.Member.i.getData(e.callerId),i={id:e.callerId,data:t.get(e.callerId)};tt.fire(Y.USER_RANG,{user:i})}))}onUserQuit(e){return t(this,void 0,void 0,(function*(){Et.updateMemberStatus(e.userId,"Quit");const t=yield O.Member.i.getData(e.userId),i={id:e.userId,data:t.get(e.userId)};e.userId===O.Socket.user().id?Et.destroyWithEvent(nt.HANDLED_ON_ANOTHER_DEVICE):!0===e.ended?Et.destroyWithEvent(e.reason,i):tt.fire(Y.USER_QUIT,{user:i,reason:e.reason})}))}onRTCTimeout(){}onGoEasyDisconnected(){Et.destroyWithEvent(nt.GOEASY_DISCONNECTED)}destroy(){}muteMic(t){}toggleSpeaker(t){}switchCamera(){Et.callContext.cloudRTC.switchCamera()}muteCamera(t){Et.callContext.cloudRTC.muteCamera(t),Et.muteMemberCamera(O.Socket.user().id,t)}onRTCRemoteMicChanged(t){}onRTCRemoteCameraChanged(e){return t(this,void 0,void 0,(function*(){}))}}class rt{static sendRequest(t){return new Promise(((e,i)=>{let s=new x({name:G.RTC_CMD,params:t,permission:P.WRITE,singleTimeout:W.commonRequestSingle,totalTimeout:W.commonRequestTotal,success:t=>{e(t)},fail:t=>{i({code:400,content:t.content})}});O.Socket.e(s)}))}}class at extends ot{constructor(){super(),Et.callContext.call.acceptedAt=Date.now()}name(){return"InCall"}accept(){return Promise.reject("The call has already been accepted")}end(){const t=new $(V.HANGUP,Et.callContext.call.id);rt.sendRequest(t),Et.destroyWithEvent(nt.HUNG_UP)}onRTCTimeout(){const t=new $(V.RTC_DISCONNECT,Et.callContext.call.id);rt.sendRequest(t),Et.destroyWithEvent(nt.RTC_DISCONNECTED)}onUserAccepted(e){return t(this,void 0,void 0,(function*(){const t=Et.callContext.call;Et.updateMemberStatus(e.userId,t.status);const i=yield O.Member.i.getData(e.userId),s={id:e.userId,data:i.get(e.userId)};tt.fire(Y.USER_ACCEPTED,{user:s})}))}muteMic(t){Et.callContext.cloudRTC.muteMic(t),Et.muteMemberMic(O.Socket.user().id,t)}toggleSpeaker(t){Et.callContext.cloudRTC.toggleSpeaker(t),Et.toggleSpeaker(t)}onRTCRemoteMicChanged(e){return t(this,void 0,void 0,(function*(){let t=e.userId;Et.muteMemberMic(t,e.muted);const i={user:{id:t,data:(yield O.Member.i.getData(t)).get(t)},micMuted:e.muted};tt.fire(Y.USER_MIC_CHANGED,i)}))}onRTCRemoteCameraChanged(e){return t(this,void 0,void 0,(function*(){let t=e.userId;Et.muteMemberCamera(t,e.muted);const i={user:{id:t,data:(yield O.Member.i.getData(t)).get(t)},cameraMuted:e.muted};tt.fire(Y.USER_CAMERA_CHANGED,i)}))}}class ct extends ot{constructor(){super(),this.dialTimeoutId=setTimeout((()=>{Et.destroyWithEvent(nt.DIAL_TIMEOUT)}),45e3)}name(){return"Dialing"}accept(){return Promise.reject("Cannot accept the call during dialing.")}end(){const t=new $(V.CANCEL,Et.callContext.call.id);rt.sendRequest(t),Et.destroyWithEvent(nt.CANCELLED)}onUserAccepted(e){return t(this,void 0,void 0,(function*(){B.setStatus(new at),Et.callContext.cloudRTC.push();const t=Et.callContext.call;t.caller.status=t.status,Et.updateMemberStatus(e.userId,t.status);const i=yield O.Member.i.getData(e.userId),s={id:e.userId,data:i.get(e.userId)};tt.fire(Y.USER_ACCEPTED,{user:s})}))}destroy(){clearTimeout(this.dialTimeoutId)}}class lt extends ot{name(){return"Ringing"}constructor(){super(),this.startAccept=!1;const t=Date.now()-Et.callContext.call.time;t>0&&(this.ringTimeoutId=setTimeout((()=>{Et.destroyWithEvent(nt.RING_TIMEOUT)}),45e3-t))}accept(){return new Promise(((i,s)=>t(this,void 0,void 0,(function*(){try{if(this.startAccept)return void s("The call has already been accepted.");this.startAccept=!0;const t=s=>{B.setStatus(new at);let n=Et.callContext.call;"Quit"!==n.caller.status&&(n.caller.status=n.status),Et.updateMemberStatus(O.Socket.user().id,n.status),Et.updateMemberStatus(s.userId,n.status),j.i.off(e.RTC_ACCEPTED,t),i()};j.i.on(e.RTC_ACCEPTED,t);const n=new $(V.ACCEPT,Et.callContext.call.id);yield rt.sendRequest(n),yield Et.callContext.cloudRTC.join(),Et.callContext.cloudRTC.push()}catch(t){Et.destroyWithEvent(nt.ACCEPT_FAILED),console.warn("accepte failed:",t),s(t)}}))))}onUserAcceptPacket(t){t.userId===O.Socket.user().id?Et.destroyWithEvent(nt.HANDLED_ON_ANOTHER_DEVICE):Et.updateMemberStatus(t.userId,"InCall")}end(){const t=new $(V.REJECT,Et.callContext.call.id);rt.sendRequest(t),Et.destroyWithEvent(nt.REJECTED)}onRTCRemoteFlow(t){const i=Et.callContext.call;"Quit"!==[...i.callees,i.caller].find((e=>e.id===t.userId)).status&&j.i.fire(e.RTC_ACCEPTED,t)}onUserRang(e){return t(this,void 0,void 0,(function*(){}))}destroy(){clearTimeout(this.ringTimeoutId)}onUserAccepted(t){}}class ut{static initNotificationAssembler(){O.N.addAssembler({assemble:t=>({callId:t.callId}),support:t=>!!t.callId})}static createLocalNotification(t){const e=O.N.supportAppNotification();let i=t.notification;if(!it.isObject(i)||!e)return;let s={callId:t.callId};O.N.createLocalNotification(i.title,i.body,s,i.sound,i.badge)}}class dt{onServerPacket(t,e){switch(t){case Q.RING:this.onRing(e);break;case Q.USER_RANG:this.onUserRang(e);break;case Q.USER_ACCEPTED:this.onUserAcceptPacket(e);break;case Q.USER_QUIT:this.onUserQuit(e)}}}class Ct extends dt{name(){return"Busy"}accept(){return B.status.accept()}end(){B.status.end(),ht.setStatus(new mt)}call(t){return Promise.reject("Another call is in progress.")}onRing(t){const e=new $(V.BUSY,t.id);rt.sendRequest(e)}onUserAcceptPacket(t){B.status.onUserAcceptPacket(t)}onUserRang(t){B.status.onUserRang(t)}onUserQuit(t){B.status.onUserQuit(t)}onRTCTimeout(){B.status.onRTCTimeout()}onRTCRemoteFlow(t){B.status.onRTCRemoteFlow(t)}onGoEasyDisconnected(){B.status.onGoEasyDisconnected()}muteMic(t){B.status.muteMic(t)}toggleSpeaker(t){B.status.toggleSpeaker(t)}muteCamera(t){B.status.muteCamera(t)}switchCamera(){B.status.switchCamera()}onRTCRemoteMicChanged(t){B.status.onRTCRemoteMicChanged(t)}onRTCRemoteCameraChanged(t){B.status.onRTCRemoteCameraChanged(t)}}class mt extends dt{name(){return"Idle"}call(e){if(et.check(),st.validateNotification(e.notification),!O.Socket.user().id)throw new Error("Dialing failed: `id` is required when connecting to GoEasy.");return new Promise(((i,s)=>t(this,void 0,void 0,(function*(){try{ht.setStatus(new Ct),"calleeIds"in e?Et.initGroupCall(e):Et.initPrivateCall(e),B.setStatus(new ct);const t=Et.callContext.cloudRTC;yield t.requestPermission(e.mediaType);const n=yield t.createEngine(e.mediaType);t.join();const o=Et.callContext.call;o.id=n;const r=B.status.name();o.status=r;const a="calleeIds"in e?e.calleeIds:[e.calleeId],c=yield O.Member.i.getData(...a);o.callees=a.map((t=>new z(t,c.get(t),"Ringing")));const l=$.createCallCommand(o,n,e);const u=(yield rt.sendRequest(l)).content.users;o.callees=o.callees.filter((t=>!u.find((e=>e.userId===t.id&&e.busy))));u.every((t=>t.busy))?(Et.destroy(),s({code:400,content:"all callees are busy"})):i()}catch(t){Et.destroy(),console.warn("Call failed",t),s(t)}}))))}onRing(e){return t(this,void 0,void 0,(function*(){try{ht.setStatus(new Ct),Et.ring(e),B.setStatus(new lt),ut.createLocalNotification(e);const t=B.status.name(),i=Et.callContext.call;i.status=t;const s=e.users.map((t=>t.id)),n=yield O.Member.i.getData(e.callerId,...s);i.caller=new z(e.callerId,n.get(e.callerId),t),i.callees=e.users.map((e=>new z(e.id,n.get(e.id),t)));const o=Et.callContext.cloudRTC;o.requestPermission(e.type),yield o.createEngine(e.type,e.callId);const r=new $(V.RANG,i.id);rt.sendRequest(r);const a=yield O.Member.i.getData(e.callerId),c={id:e.callerId,data:a.get(e.callerId)};tt.fire(Y.RING,{user:c})}catch(t){console.warn("Ring failed",t),Et.destroy()}}))}accept(){return Promise.reject("No active call to accept.")}end(){}onUserRang(t){}onUserAcceptPacket(t){}onUserQuit(t){}onRTCTimeout(){}onRTCRemoteFlow(t){}onGoEasyDisconnected(){}muteMic(){}toggleSpeaker(){}muteCamera(){}switchCamera(){}onRTCRemoteCameraChanged(t){}onRTCRemoteMicChanged(t){}}class ht{static setStatus(t){this.status=t}}ht.status=new mt;class Et{static ring(t){const e=new J;e.id=t.callId,e.time=t.time,e.mediaType=t.type,e.groupId=t.groupId,e.speakerOn=!0,this.callContext=new X(e)}static initPrivateCall(t){const e=new J;e.mediaType=t.mediaType,e.speakerOn=!0,e.caller=new z(O.Socket.user().id,O.Socket.user().data,"Dialing"),this.callContext=new X(e)}static initGroupCall(t){if(t.calleeIds.length>8)throw new Error("calleeIds can not more than 8");const e=new J;e.groupId=t.groupId,e.mediaType=t.mediaType,e.speakerOn=!0,e.caller=new z(O.Socket.user().id,O.Socket.user().data,"Dialing"),this.callContext=new X(e)}static updateMemberStatus(t,e){const i=this.callContext.call;[...i.callees,i.caller].find((e=>e.id===t)).status=e}static muteMemberMic(t,e){const i=this.callContext.call,s=[...i.callees,i.caller].find((e=>e.id===t));s.micMuted&&e||!s.micMuted&&!e||(s.micMuted=e)}static muteMemberCamera(t,e){const i=this.callContext.call,s=[...i.callees,i.caller].find((e=>e.id===t));s.cameraMuted&&e||!s.cameraMuted&&!e||(s.cameraMuted=e)}static toggleSpeaker(t){this.callContext.call.speakerOn=t}static isCaller(){return this.callContext.call.caller.id===O.Socket.user().id}static destroyWithEvent(t,e=O.Socket.user()){tt.fire(Y.USER_QUIT,{user:e,reason:t}),tt.fire(Y.CALL_ENDED),this.destroy()}static destroy(){this.callContext.cloudRTC.destroy(),this.callContext.acceptedUsers.destroy(),this.callContext=null,B.clearStatus(),ht.setStatus(new mt)}}class pt{static init(){this.instance=new pt}static i(){if(this.instance)return this.instance;throw new Error("Please connect GoEasy first.")}constructor(){this.rtcStabilizer=new q,ut.initNotificationAssembler(),O.Socket.onMessage(G.RTC_PKT,this.onServerPacket.bind(this)),j.i.on(e.RECEIVED_RTC_REMOTE_FLOW,this.onRTCRemoteFlow.bind(this)),j.i.on(e.RTC_TIMEOUT,this.onRTCTimeout.bind(this)),j.i.on(e.RTC_REMOTE_MIC_CHANGED,this.onRTCRemoteMicChanged.bind(this)),j.i.on(e.RTC_REMOTE_CAMERA_CHANGED,this.onRTCRemoteCameraChanged.bind(this)),O.Socket.on(O.Socket.EVENT.LOST,this.onGoEasyDisconnected.bind(this)),O.Socket.on(O.Socket.EVENT.DISCONNECT,this.onGoEasyDisconnected.bind(this))}on(t,e){tt.on(t.toString(),e)}off(t,e){tt.off(t.toString(),e)}call(e){return t(this,void 0,void 0,(function*(){return ht.status.call(e)}))}groupCall(e){return t(this,void 0,void 0,(function*(){return ht.status.call(e)}))}accept(){return ht.status.accept()}getCurrentCall(){return Et.callContext.call}end(){ht.status.end()}muteMic(t){ht.status.muteMic(t)}toggleSpeaker(t){ht.status.toggleSpeaker(t)}muteCamera(t){ht.status.muteCamera(t)}switchCamera(){ht.status.switchCamera()}onServerPacket(t){ht.status.onServerPacket(t.name,t.data)}onRTCTimeout(){ht.status.onRTCTimeout()}onRTCRemoteFlow(t){ht.status.onRTCRemoteFlow(t)}onGoEasyDisconnected(){ht.status.onGoEasyDisconnected()}onRTCRemoteMicChanged(t){ht.status.onRTCRemoteMicChanged(t)}onRTCRemoteCameraChanged(t){ht.status.onRTCRemoteCameraChanged(t)}}class Tt{static init(t){et.init(t)}static call(t){return pt.i().call(t)}static groupCall(t){return pt.i().groupCall(t)}static accept(){return pt.i().accept()}static currentCall(){return pt.i().getCurrentCall()}static end(){pt.i().end()}static muteMic(t){pt.i().muteMic(t)}static toggleSpeaker(t){pt.i().toggleSpeaker(t)}static muteCamera(t){pt.i().muteCamera(t)}static switchCamera(){pt.i().switchCamera()}static on(t,e){pt.i().on(t,e)}static off(t,e){pt.i().off(t,e)}}Tt.EVENT=Y;export{Tt as default};
|
|
1
|
+
function t(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{c(s.next(t))}catch(t){o(t)}}function a(t){try{c(s.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}c((s=s.apply(t,e||[])).next())}))}var e;"function"==typeof SuppressedError&&SuppressedError,function(t){t.RTC_LOST="RTC_LOST",t.RTC_RECONNECT="RTC_RECONNECT",t.RTC_TIMEOUT="RTC_TIMEOUT",t.RTC_ACCEPTED="RTC_ACCEPTED",t.RECEIVED_RTC_REMOTE_FLOW="RECEIVED_RTC_REMOTE_FLOW",t.GOEASY_TIMEOUT="GOEASY_TIMEOUT",t.GOEASY_DISCONNECTED="GOEASY_DISCONNECTED",t.RTC_REMOTE_MIC_CHANGED="RTC_REMOTE_MIC_CHANGED",t.RTC_REMOTE_CAMERA_CHANGED="RTC_REMOTE_CAMERA_CHANGED"}(e||(e={}));var i={exports:{}};!function(t){function e(t){if(t)return function(t){for(var i in e.prototype)t[i]=e.prototype[i];return t}(t)}i.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},e.prototype.once=function(t,e){function i(){this.off(t,i),e.apply(this,arguments)}return i.fn=e,this.on(t,i),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i,s=this._callbacks["$"+t];if(!s)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n=0;n<s.length;n++)if((i=s[n])===e||i.fn===e){s.splice(n,1);break}return this},e.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),i=this._callbacks["$"+t];if(i)for(var s=0,n=(i=i.slice(0)).length;s<n;++s)i[s].apply(this,e);return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}}();var s=i.exports,n={exports:{}},o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(o){var r=new Uint8Array(16);n.exports=function(){return o(r),r}}else{var a=new Array(16);n.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),a[e]=t>>>((3&e)<<3)&255;return a}}for(var c=[],l=0;l<256;++l)c[l]=(l+256).toString(16).substr(1);var u,d,h=function(t,e){var i=e||0,s=c;return[s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],"-",s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]],s[t[i++]]].join("")},C=n.exports,m=h,E=0,T=0;var p=function(t,e,i){var s=e&&i||0,n=e||[],o=(t=t||{}).node||u,r=void 0!==t.clockseq?t.clockseq:d;if(null==o||null==r){var a=C();null==o&&(o=u=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==r&&(r=d=16383&(a[6]<<8|a[7]))}var c=void 0!==t.msecs?t.msecs:(new Date).getTime(),l=void 0!==t.nsecs?t.nsecs:T+1,h=c-E+(l-T)/1e4;if(h<0&&void 0===t.clockseq&&(r=r+1&16383),(h<0||c>E)&&void 0===t.nsecs&&(l=0),l>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");E=c,T=l,d=r;var p=(1e4*(268435455&(c+=122192928e5))+l)%4294967296;n[s++]=p>>>24&255,n[s++]=p>>>16&255,n[s++]=p>>>8&255,n[s++]=255&p;var R=c/4294967296*1e4&268435455;n[s++]=R>>>8&255,n[s++]=255&R,n[s++]=R>>>24&15|16,n[s++]=R>>>16&255,n[s++]=r>>>8|128,n[s++]=255&r;for(var f=0;f<6;++f)n[s+f]=o[f];return e||m(n)},R=n.exports,f=h;var g=function(t,e,i){var s=e&&i||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var n=(t=t||{}).random||(t.rng||R)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e)for(var o=0;o<16;++o)e[s+o]=n[o];return e||f(n)},y=p,v=g,_=v;_.v1=y,_.v4=v;var I=_;class A{support(){return!0}getParams(){return this.params}setData(t){this.active=t.a,this.data=t.d}preConnect(t){}postConnect(){}}const S=s;class b{constructor(){this.emitter=new S}on(t,e){return this.emitter.on(t,e),this}once(t,e){return this.emitter.once(t,e),this}off(t,e){return this.emitter.off(t,e),this}fire(t,e){return this.emitter.emit(t,e),this}}class D{constructor(){this.eventDriver=new b}on(t,e){this.eventDriver.on(t,e)}off(t,e){this.eventDriver.off(t,e)}fire(t,e){this.eventDriver.fire(t,e)}}let N=new class{isDef(t){return!this.isUndef(t)}isUndef(t){return null==t}isPrimitive(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}isObject(t){return null!==t&&"object"==typeof t}isPlainObject(t){return"[object Object]"===Object.prototype.toString.call(t)}isRegExp(t){return"[object RegExp]"===Object.prototype.toString.call(t)}isValidArrayIndex(t){let e=parseFloat(String(t));return e>=0&&Math.floor(e)===e&&isFinite(t)}isString(t){return"string"==typeof t}isNumber(t){return"number"==typeof t}isStringOrNumber(t){return this.isString(t)||this.isNumber(t)}isArray(t){return"[object Array]"===Object.prototype.toString.call(t)}isEmpty(t){return this.isArray(t)?0===t.length:this.isObject(t)?!this.isDef(t):!this.isNumber(t)&&(this.isString(t)?""===t.trim():!this.isDef(t))}isNative(t){return"function"==typeof t&&/native code/.test(t.toString())}isFunction(t){return"function"==typeof t}isBoolean(t){return"boolean"==typeof t}isTrue(t){return!0===t}isFalse(t){return!1===t}isNull(t){return null===t}};const w=s;class k{constructor(){this.emitter=new w}on(t,e){if(!N.isString(t))throw Error("event require a string.");if(!N.isFunction(e))throw Error("callback must be a function");this.emitter.on(t,e)}fire(t,e){this.emitter.emit(t,e)}off(t,e){this.emitter.off(t,e)}}class M{static init(t,e,i,s,n,o){this.Socket=t,this.N=e,this.Member=i,this.v=s,this.Platform=n,this.GModules=o}}const O=I;class U{static get(){return O.v1().replace(/-/g,"")}}var L,P,G,x,j;(P=L||(L={})).WRITE="WRITE",P.READ="READ",P.NONE="NONE";class q{constructor(t){this.permission=L.NONE,this.singleTimeout=0,this.totalTimeout=0,this.startTime=0,this.complete=!1,this.retried=0,this.unique=!1,this.uuid=U.get(),this.name=t.name,this.params=t.params,this.permission=t.permission,this.totalTimeout=t.totalTimeout,this.singleTimeout=t.singleTimeout,t.unique&&(this.unique=t.unique),this.success=e=>{this.complete||(this.end(),t.success(e))},this.fail=e=>{this.complete||(this.end(),t.fail(e))}}start(){this.startTime=Date.now(),this.initAutoTimeout()}end(){this.complete=!0,clearTimeout(this.timeoutHandler)}initAutoTimeout(){this.timeoutHandler=setTimeout((()=>{this.complete||this.fail({resultCode:408,content:"Host unreachable or timeout"})}),this.totalTimeout)}}class F extends D{static init(){this.i=new F}}class V{constructor(){F.i.on(e.RTC_LOST,(()=>this.onRTCLost())),F.i.on(e.RTC_RECONNECT,(()=>this.onRTCReconnect()))}onRTCLost(){this.rtcLostTimeoutId=setTimeout((()=>{F.i.fire(e.RTC_TIMEOUT)}),1e4)}onRTCReconnect(){clearTimeout(this.rtcLostTimeoutId)}onGoEasyLost(){this.goeasyLostTimeoutId=setTimeout((()=>{F.i.fire(e.GOEASY_TIMEOUT)}),2e4)}onGoEasyReconnected(){clearTimeout(this.goeasyLostTimeoutId)}}!function(t){t.RTC_CMD="RTC_CMD",t.RTC_PKT="RTC_PKT"}(G||(G={}));class H{constructor(t,e,i){this.name=t,this.callId=e,this.data=i}static createCallCommand(t,e,i){let s={calleeIds:t.callees.map((t=>t.id)),mediaType:i.mediaType,groupId:i.groupId,callId:e};return i.notification&&(s.notification=i.notification),new H(x.CALL,e,s)}}!function(t){t.CALL="CALL",t.QUIT="QUIT",t.BUSY="BUSY",t.ACCEPT="ACCEPT",t.RANG="RANG",t.HANGUP="HANGUP",t.CANCEL="CANCEL",t.REJECT="REJECT",t.RTC_DISCONNECT="RTC_DISCONNECT",t.GET_TOKEN="GET_TOKEN"}(x||(x={})),function(t){t[t.connect=3e3]="connect",t[t.reconnectionDelayMax=3e3]="reconnectionDelayMax",t[t.commonQuerySingle=2500]="commonQuerySingle",t[t.commonQueryTotal=12e3]="commonQueryTotal",t[t.commonRequestSingle=1700]="commonRequestSingle",t[t.commonRequestTotal=12e3]="commonRequestTotal",t[t.commonInfiniteSingle=1700]="commonInfiniteSingle",t[t.commonInfiniteTotal=864e5]="commonInfiniteTotal"}(j||(j={}));class Q{constructor(){this.joined=!1}play(t){}getNewToken(e){return t(this,void 0,void 0,(function*(){let t={name:x.GET_TOKEN};return e&&(t.callId=e),new Promise(((e,i)=>{let s=new q({name:G.RTC_CMD,params:t,permission:L.WRITE,singleTimeout:j.commonRequestSingle,totalTimeout:j.commonRequestTotal,success:t=>{e(t.content)},fail:t=>{i(t)}});M.Socket.e(s)}))}))}}var W,B;!function(t){t[t.AUDIO=0]="AUDIO",t[t.VIDEO=1]="VIDEO"}(W||(W={}));class Y extends Q{constructor(){if(super(),this.client=uni.requireNativePlugin("RTCClientPlugin"),!this.client)throw"Please configure GoEasy RTC native plugin first: https://www.goeasy.io";plus.globalEvent.addEventListener("connectionLost",(()=>{F.i.fire(e.RTC_LOST)})),plus.globalEvent.addEventListener("connectionRecovery",(t=>{F.i.fire(e.RTC_RECONNECT)})),plus.globalEvent.addEventListener("receivedRemoteFlow",(t=>{F.i.fire(e.RECEIVED_RTC_REMOTE_FLOW,t)})),plus.globalEvent.addEventListener("remoteMicChanged",(t=>{F.i.fire(e.RTC_REMOTE_MIC_CHANGED,t)})),plus.globalEvent.addEventListener("remoteCameraChanged",(t=>{F.i.fire(e.RTC_REMOTE_CAMERA_CHANGED,t)}))}destroy(){plus.globalEvent.removeEventListener("connectionLost"),plus.globalEvent.removeEventListener("connectionRecovery"),plus.globalEvent.removeEventListener("receivedRemoteFlow"),plus.globalEvent.removeEventListener("remoteMicChanged"),plus.globalEvent.removeEventListener("remoteCameraChanged"),this.joined&&(this.leave(),this.joined=!1),this.client.destroyEngine()}createEngine(e,i){return t(this,void 0,void 0,(function*(){return this.token=yield this.getNewToken(i),this.token.video=e===W.VIDEO,this.token.userId=M.Socket.user().id,this.client.createRTCClient({vendor:this.token.vendor,userId:this.token.userId}),this.token.callId}))}join(){return new Promise(((t,e)=>{this.client.joinChannel(this.token,(()=>{this.token.userId,this.token.callId,this.joined=!0,t()}),(t=>{this.token.userId,this.token.callId,e({code:400,content:"Failed to join Channel, error code:"+t})}))}))}push(){this.token.video?this.client.callVideo():this.client.callAudio()}leave(){this.client.leaveChannel()}requestPermission(t){return new Promise(((e,i)=>{W.VIDEO===t?this.client.requestVideoCallPermission((t=>{200===t?e():i({code:403,content:"Failed to request video call permission, error code:"+t})})):W.AUDIO===t?this.client.requestVoiceCallPermission((t=>{200===t?e():i({code:403,content:"Failed to request voice call permission, error code:"+t})})):i({code:400,content:"Unsupported media type"})}))}accept(){return t(this,void 0,void 0,(function*(){yield this.join(),this.push()}))}muteMic(t){this.client.muteMic({enabled:t})}toggleSpeaker(t){this.client.enableSpeaker({enabled:t})}muteCamera(t){this.client.muteCamera({enabled:t})}switchCamera(){this.client.switchCamera()}}class ${static setStatus(t){this.status&&this.status.destroy(),this.status=t,pt.callContext.call.status=t.name()}static clearStatus(){this.status.destroy(),this.status=null}}!function(t){t.RING="RING",t.USER_RANG="U_RANG",t.USER_QUIT="U_QUIT",t.USER_ACCEPTED="U_ACCEPTED",t.ENDED="ENDED"}(B||(B={}));class K{static init(){this.eventCenter=new k}static on(t,e){this.eventCenter.on(t,e)}static fire(t,e){this.eventCenter.fire(t,e)}static off(t,e){this.eventCenter.off(t,e)}}class J extends A{static init(t){t.c(M),this.module=new J,this.module.name=this.RTC_MODULE_NAME;let e=null;if(this.supportApp()){let t=uni.requireNativePlugin("RTCClientPlugin");t&&(e=t.v())}this.module.params={v:{n:"goeasy-rtc",v:"0.3.0",npv:e}},M.GModules.initModule(this.module)}static check(){if(!this.module)throw new Error("Please init GRTC first.");if(!this.module.active)throw new Error("RTC unavailable. Please confirm if your GoEasy application supports RTC or contact GoEasy team.");if(!this.supportApp()&&!this.supportBrowser())throw new Error("GRTC is only supported in Android and iOS apps developed with UniApp and Browsers");if(!this.supportGoEasyVersion())throw new Error("GRTC is only supported in GoEasy SDK version 2.10.0 or later")}static supportGoEasyVersion(){return M.v.localeCompare("2.10.0",void 0,{numeric:!0,sensitivity:"base"})>=0}static supportApp(){return[M.Platform.type.UNI_ANDROID,M.Platform.type.UNI_IOS].includes(M.Platform.current)}static supportBrowser(){return M.Platform.type.BROWSER===M.Platform.current}support(){return J.supportGoEasyVersion()&&(J.supportApp()||J.supportBrowser())}postConnect(){F.init(),K.init(),Rt.init()}}J.RTC_MODULE_NAME="GRTC";class z{constructor(t,e){this.userId=t,this.muted=e}}let X=new class{isDef(t){return!this.isUndef(t)}isUndef(t){return null==t}isPrimitive(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}isObject(t){return null!==t&&"object"==typeof t}isString(t){return"string"==typeof t}isNumber(t){return"number"==typeof t}isStringOrNumber(t){return this.isString(t)||this.isNumber(t)}isArray(t){return"[object Array]"===Object.prototype.toString.call(t)}isEmpty(t){return this.isArray(t)?0===t.length:this.isObject(t)?!this.isDef(t):!this.isNumber(t)&&(this.isString(t)?""===t.trim():!this.isDef(t))}isNative(t){return"function"==typeof t&&/native code/.test(t.toString())}isFunction(t){return"function"==typeof t}};class Z extends Q{constructor(){super(),this.localTracks=[],this.remoteTracks=new Map;this.QNRTC=(()=>{try{return require("qnweb-rtc")}catch(t){throw new Error("Please run npm install qnweb-rtc")}})(),this.QNRTC.setLogLevel("NONE"),this.client=this.QNRTC.createClient(),this.initListeners()}initListeners(){this.client.on("connection-state-changed",((t,i)=>{"RECONNECTED"===t?F.i.fire(e.RTC_RECONNECT):"DISCONNECTED"===t&&F.i.fire(e.RTC_LOST)})),this.client.on("user-published",((t,e)=>{this.subscribe(t,e)}))}listenRemoteTrackMutedChanged(t){t.on("mute-state-changed",(i=>{let s=t.isAudio(),n=t.userID,o=s?e.RTC_REMOTE_MIC_CHANGED:e.RTC_REMOTE_CAMERA_CHANGED;F.i.fire(o,new z(n,i))}))}subscribe(i,s){return t(this,void 0,void 0,(function*(){const t=yield this.client.subscribe(s);if(t.audioTracks.length>0&&this.listenRemoteTrackMutedChanged(t.audioTracks[0]),t.videoTracks.length>0&&this.listenRemoteTrackMutedChanged(t.videoTracks[0]),this.remoteTracks.set(i,t),F.i.fire(e.RECEIVED_RTC_REMOTE_FLOW,{userId:i}),!1===this.token.video)this.playRemoteMicrophoneTracks();else{let t=this.getView(i);t&&this.playRemoteTrack(i,t)}}))}createEngine(e,i){return t(this,void 0,void 0,(function*(){return this.token=yield this.getNewToken(i),this.token.video=e===W.VIDEO,this.token.userId=M.Socket.user().id,yield this.initLocalTracks(),this.token.callId}))}join(){return t(this,void 0,void 0,(function*(){const t=this.token.vendorToken.token;yield this.client.join(t),this.joined=!0}))}push(){return t(this,void 0,void 0,(function*(){yield this.client.publish(this.localTracks)}))}accept(){return t(this,void 0,void 0,(function*(){yield this.join(),yield this.push()}))}initLocalTracks(){return t(this,void 0,void 0,(function*(){this.localTracks.length>0||(this.token.video?this.localTracks=yield this.QNRTC.createMicrophoneAndCameraTracks():this.localTracks=[yield this.QNRTC.createMicrophoneAudioTrack()])}))}play(e){return t(this,void 0,void 0,(function*(){if(this.token.video)if(M.Socket.user().id===e){yield this.initLocalTracks();const t=this.getView(e);this.listenCustomAttributes(t),this.playLocalTrack(t)}else{const t=this.getView(e);this.listenCustomAttributes(t),this.playRemoteTrack(e,t)}else this.playRemoteMicrophoneTracks()}))}getView(t){const e=document.getElementsByClassName("grtc-video");for(let i=0;i<e.length;i++){const s=e[i];if(s.getAttribute("userId")===t)return s}}listenCustomAttributes(t){new MutationObserver((e=>{e.forEach((e=>{const i=e.oldValue,s=t.getAttribute("userId");X.isEmpty(s)||s===i||(M.Socket.user().id===s?this.playLocalTrack(t):this.playRemoteTrack(s,t))}))})).observe(t,{attributes:!0,attributeOldValue:!0,attributeFilter:["userid"]})}playRemoteMicrophoneTracks(){const t=document.getElementsByClassName("grtc-audio")[0];t&&this.remoteTracks.forEach(((e,i)=>{for(const i of e.audioTracks)i.play(t)}))}playLocalTrack(t){for(const e of this.localTracks)e.isAudio()||e.play(t,{mirror:!0})}playRemoteTrack(t,e){const i=this.remoteTracks.get(t);if(i)for(const t of[...i.videoTracks,...i.audioTracks])t.play(e)}destroy(){this.joined&&this.leave(),this.releaseMediaTracks()}releaseMediaTracks(){for(const t of this.localTracks)t.destroy();this.localTracks=[],this.remoteTracks.clear()}leave(){return t(this,void 0,void 0,(function*(){yield this.client.leave()}))}requestPermission(e){return t(this,void 0,void 0,(function*(){}))}toggleSpeaker(t){throw new Error("not support.")}muteCamera(t){for(const e of this.localTracks)e.isVideo()&&e.setMuted(t)}muteMic(t){for(const e of this.localTracks)e.isAudio()&&e.setMuted(t)}switchCamera(){throw new Error("not support.")}}class tt{constructor(){this.callees=new Array}getDuration(){return Math.floor((Date.now()-this.acceptedAt)/1e3)}}class et{constructor(t,e,i){this.micMuted=!1,this.cameraMuted=!1,this.id=t,this.data=e,this.status=i}}class it{constructor(t){this.call=new tt,this.acceptedUsers=new st,this.call=t,J.supportApp()?this.cloudRTC=new Y:J.supportBrowser()&&(this.cloudRTC=new Z)}}class st{constructor(){this.acceptedUsers=new Map,this.onRTCRemoteFlow=t=>{this.updateUserStatus(t.userId,{remoteFlow:!0}),this.tryFireUserAccepted(t.userId)},this.onUserAcceptPacket=t=>{t.name===B.USER_ACCEPTED&&(this.updateUserStatus(t.data.userId,{acceptPacket:!0}),this.tryFireUserAccepted(t.data.userId))},M.Socket.onMessage(G.RTC_PKT,this.onUserAcceptPacket),F.i.on(e.RECEIVED_RTC_REMOTE_FLOW,this.onRTCRemoteFlow)}updateUserStatus(t,e){let i;const s=this.acceptedUsers;i=s.has(t)?s.get(t):{acceptPacket:!1,remoteFlow:!1},s.set(t,Object.assign(Object.assign({},i),e))}tryFireUserAccepted(t){const e=this.acceptedUsers;if(e.has(t)){const i=e.get(t);i.remoteFlow&&i.acceptPacket&&(e.delete(t),$.status.onUserAccepted({userId:t}))}}destroy(){M.Socket.offMessage(G.RTC_PKT,this.onUserAcceptPacket),F.i.off(e.RECEIVED_RTC_REMOTE_FLOW,this.onRTCRemoteFlow)}}var nt;!function(t){t.RING="RING",t.USER_RANG="USER_RANG",t.USER_QUIT="USER_QUIT",t.USER_ACCEPTED="USER_ACCEPTED",t.CALL_ENDED="CALL_ENDED",t.USER_MIC_CHANGED="USER_MIC_CHANGED",t.USER_CAMERA_CHANGED="USER_CAMERA_CHANGED"}(nt||(nt={}));const ot=new class{validateId(t,e){if(X.isEmpty(t))throw{code:400,content:` ${e} is required.`};if(!X.isStringOrNumber(t))throw{code:400,content:`TypeError: ${e} require string or number.`}}validateNotification(t){function e(t,e,i){if(!(X.isString(t[e])&&t[e].length<=i))throw{code:400,content:`notification.${e} must be a string of no more than ${i} characters`}}function i(t,e,i,s){let n=t[e];if(X.isObject(n)&&X.isDef(n[i])){let t={code:400,content:`notification.vendorOptions.${e}.${i} require a ${s}}`},o=n[i];if("string"===s&&!X.isString(o))throw t;if("number"===s&&!X.isNumber(o))throw t}}if(!X.isObject(t))throw{code:400,content:"TypeError: notification requires an object."};{if(e(t,"title",32),e(t,"body",50),X.isDef(t.sound)&&!X.isString(t.sound))throw{code:400,content:"notification.sound must be a string"};if(X.isDef(t.badge)&&!X.isString(t.badge))throw{code:400,content:"notification.badge must be a string"};t.badge=t.badge||"0";let s=t.vendorOptions;X.isObject(s)&&(i(s,"huawei","category","string"),i(s,"xiaomi","channel_id","string"),i(s,"oppo","channel_id","string"),i(s,"vivo","classification","number"),i(s,"vivo","category","string"))}}validateObject(t,e){if(X.isUndef(t)||!X.isObject(t))throw{code:400,content:e+" must be an object."}}validateString(t,e){if(X.isUndef(t)||!X.isString(t))throw{code:400,content:e+" must be a string."}}};var rt;!function(t){t.ALL_BUSY="ALL_BUSY",t.DIAL_FAILED="DIAL_FAILED",t.CANCELLED="CANCELLED",t.REJECTED="REJECTED",t.HUNG_UP="HUNG_UP",t.RTC_DISCONNECTED="RTC_DISCONNECTED",t.GOEASY_DISCONNECTED="GOEASY_DISCONNECTED",t.HANDLED_ON_ANOTHER_DEVICE="HANDLED_ON_ANOTHER_DEVICE",t.RING_TIMEOUT="RING_TIMEOUT",t.ACCEPT_FAILED="ACCEPT_FAILED",t.DIAL_TIMEOUT="DIAL_TIMEOUT"}(rt||(rt={}));class at{onRTCRemoteFlow(t){}onUserAcceptPacket(t){}onUserRang(e){return t(this,void 0,void 0,(function*(){pt.updateMemberStatus(e.callerId,"Ringing");const t=yield M.Member.i.getData(e.callerId),i={id:e.callerId,data:t.get(e.callerId)};K.fire(nt.USER_RANG,{user:i})}))}onUserQuit(e){return t(this,void 0,void 0,(function*(){pt.updateMemberStatus(e.userId,"Quit");const t=yield M.Member.i.getData(e.userId),i={id:e.userId,data:t.get(e.userId)};e.userId===M.Socket.user().id?pt.destroyWithEvent(rt.HANDLED_ON_ANOTHER_DEVICE):!0===e.ended?pt.destroyWithEvent(e.reason,i):K.fire(nt.USER_QUIT,{user:i,reason:e.reason})}))}onRTCTimeout(){}onGoEasyDisconnected(){pt.destroyWithEvent(rt.GOEASY_DISCONNECTED)}destroy(){}muteMic(t){}toggleSpeaker(t){}switchCamera(){pt.callContext.cloudRTC.switchCamera()}muteCamera(t){pt.callContext.cloudRTC.muteCamera(t),pt.muteMemberCamera(M.Socket.user().id,t)}play(t){pt.callContext.cloudRTC.play(t)}onRTCRemoteMicChanged(t){}onRTCRemoteCameraChanged(e){return t(this,void 0,void 0,(function*(){}))}}class ct{static sendRequest(t){return new Promise(((e,i)=>{let s=new q({name:G.RTC_CMD,params:t,permission:L.WRITE,singleTimeout:j.commonRequestSingle,totalTimeout:j.commonRequestTotal,success:t=>{e(t)},fail:t=>{i({code:400,content:t.content})}});M.Socket.e(s)}))}}class lt extends at{constructor(){super(),pt.callContext.call.acceptedAt=Date.now()}name(){return"InCall"}accept(){return Promise.reject("The call has already been accepted")}end(){const t=new H(x.HANGUP,pt.callContext.call.id);ct.sendRequest(t),pt.destroyWithEvent(rt.HUNG_UP)}onRTCTimeout(){const t=new H(x.RTC_DISCONNECT,pt.callContext.call.id);ct.sendRequest(t),pt.destroyWithEvent(rt.RTC_DISCONNECTED)}onUserAccepted(e){return t(this,void 0,void 0,(function*(){const t=pt.callContext.call;pt.updateMemberStatus(e.userId,t.status);const i=yield M.Member.i.getData(e.userId),s={id:e.userId,data:i.get(e.userId)};K.fire(nt.USER_ACCEPTED,{user:s})}))}muteMic(t){pt.callContext.cloudRTC.muteMic(t),pt.muteMemberMic(M.Socket.user().id,t)}toggleSpeaker(t){pt.callContext.cloudRTC.toggleSpeaker(t),pt.toggleSpeaker(t)}onRTCRemoteMicChanged(e){return t(this,void 0,void 0,(function*(){let t=e.userId;pt.muteMemberMic(t,e.muted);const i={user:{id:t,data:(yield M.Member.i.getData(t)).get(t)},micMuted:e.muted};K.fire(nt.USER_MIC_CHANGED,i)}))}onRTCRemoteCameraChanged(e){return t(this,void 0,void 0,(function*(){let t=e.userId;pt.muteMemberCamera(t,e.muted);const i={user:{id:t,data:(yield M.Member.i.getData(t)).get(t)},cameraMuted:e.muted};K.fire(nt.USER_CAMERA_CHANGED,i)}))}}class ut extends at{constructor(){super(),this.dialTimeoutId=setTimeout((()=>{pt.destroyWithEvent(rt.DIAL_TIMEOUT)}),45e3)}name(){return"Dialing"}accept(){return Promise.reject("Cannot accept the call during dialing.")}end(){const t=new H(x.CANCEL,pt.callContext.call.id);ct.sendRequest(t),pt.destroyWithEvent(rt.CANCELLED)}onUserAccepted(e){return t(this,void 0,void 0,(function*(){$.setStatus(new lt),pt.callContext.cloudRTC.push();const t=pt.callContext.call;t.caller.status=t.status,pt.updateMemberStatus(e.userId,t.status);const i=yield M.Member.i.getData(e.userId),s={id:e.userId,data:i.get(e.userId)};K.fire(nt.USER_ACCEPTED,{user:s})}))}destroy(){clearTimeout(this.dialTimeoutId)}}class dt extends at{name(){return"Ringing"}constructor(){super(),this.startAccept=!1;const t=Date.now()-pt.callContext.call.time;t>0&&(this.ringTimeoutId=setTimeout((()=>{pt.destroyWithEvent(rt.RING_TIMEOUT)}),45e3-t))}accept(){return new Promise(((i,s)=>t(this,void 0,void 0,(function*(){try{if(this.startAccept)return void s("The call has already been accepted.");this.startAccept=!0;const t=s=>{$.setStatus(new lt);let n=pt.callContext.call;"Quit"!==n.caller.status&&(n.caller.status=n.status),pt.updateMemberStatus(M.Socket.user().id,n.status),pt.updateMemberStatus(s.userId,n.status),F.i.off(e.RTC_ACCEPTED,t),i()};F.i.on(e.RTC_ACCEPTED,t);const n=new H(x.ACCEPT,pt.callContext.call.id);yield ct.sendRequest(n),yield pt.callContext.cloudRTC.join(),pt.callContext.cloudRTC.push()}catch(t){pt.destroyWithEvent(rt.ACCEPT_FAILED),console.warn("accepte failed:",t),s(t)}}))))}onUserAcceptPacket(t){t.userId===M.Socket.user().id?pt.destroyWithEvent(rt.HANDLED_ON_ANOTHER_DEVICE):pt.updateMemberStatus(t.userId,"InCall")}end(){const t=new H(x.REJECT,pt.callContext.call.id);ct.sendRequest(t),pt.destroyWithEvent(rt.REJECTED)}onRTCRemoteFlow(t){const i=pt.callContext.call;"Quit"!==[...i.callees,i.caller].find((e=>e.id===t.userId)).status&&F.i.fire(e.RTC_ACCEPTED,t)}onUserRang(e){return t(this,void 0,void 0,(function*(){}))}destroy(){clearTimeout(this.ringTimeoutId)}onUserAccepted(t){}}class ht{static initNotificationAssembler(){M.N.addAssembler({assemble:t=>({callId:t.callId}),support:t=>!!t.callId})}static createLocalNotification(t){const e=M.N.supportAppNotification();let i=t.notification;if(!X.isObject(i)||!e)return;let s={callId:t.callId};M.N.createLocalNotification(i.title,i.body,s,i.sound,i.badge)}}class Ct{onServerPacket(t,e){switch(t){case B.RING:this.onRing(e);break;case B.USER_RANG:this.onUserRang(e);break;case B.USER_ACCEPTED:this.onUserAcceptPacket(e);break;case B.USER_QUIT:this.onUserQuit(e)}}}class mt extends Ct{name(){return"Busy"}accept(){return $.status.accept()}end(){$.status.end(),Tt.setStatus(new Et)}call(t){return Promise.reject("Another call is in progress.")}onRing(t){const e=new H(x.BUSY,t.id);ct.sendRequest(e)}onUserAcceptPacket(t){$.status.onUserAcceptPacket(t)}onUserRang(t){$.status.onUserRang(t)}onUserQuit(t){$.status.onUserQuit(t)}onRTCTimeout(){$.status.onRTCTimeout()}onRTCRemoteFlow(t){$.status.onRTCRemoteFlow(t)}onGoEasyDisconnected(){$.status.onGoEasyDisconnected()}muteMic(t){$.status.muteMic(t)}toggleSpeaker(t){$.status.toggleSpeaker(t)}muteCamera(t){$.status.muteCamera(t)}switchCamera(){$.status.switchCamera()}play(t){$.status.play(t)}onRTCRemoteMicChanged(t){$.status.onRTCRemoteMicChanged(t)}onRTCRemoteCameraChanged(t){$.status.onRTCRemoteCameraChanged(t)}}class Et extends Ct{name(){return"Idle"}call(e){if(J.check(),ot.validateNotification(e.notification),!M.Socket.user().id)throw new Error("Dialing failed: `id` is required when connecting to GoEasy.");return new Promise(((i,s)=>t(this,void 0,void 0,(function*(){try{Tt.setStatus(new mt),"calleeIds"in e?pt.initGroupCall(e):pt.initPrivateCall(e),$.setStatus(new ut);const t=pt.callContext.cloudRTC;yield t.requestPermission(e.mediaType);const n=yield t.createEngine(e.mediaType);t.join();const o=pt.callContext.call;o.id=n;const r=$.status.name();o.status=r;const a="calleeIds"in e?e.calleeIds:[e.calleeId],c=yield M.Member.i.getData(...a);o.callees=a.map((t=>new et(t,c.get(t),"Ringing")));const l=H.createCallCommand(o,n,e);const u=(yield ct.sendRequest(l)).content.users;o.callees=o.callees.filter((t=>!u.find((e=>e.userId===t.id&&e.busy))));u.every((t=>t.busy))?(pt.destroy(),s({code:400,content:"all callees are busy"})):i()}catch(t){pt.destroy(),console.warn("Call failed",t),s(t)}}))))}onRing(e){return t(this,void 0,void 0,(function*(){try{Tt.setStatus(new mt),pt.ring(e),$.setStatus(new dt),ht.createLocalNotification(e);const t=$.status.name(),i=pt.callContext.call;i.status=t;const s=e.users.map((t=>t.id)),n=yield M.Member.i.getData(e.callerId,...s);i.caller=new et(e.callerId,n.get(e.callerId),t),i.callees=e.users.map((e=>new et(e.id,n.get(e.id),t)));const o=pt.callContext.cloudRTC;o.requestPermission(e.type),yield o.createEngine(e.type,e.callId);const r=new H(x.RANG,i.id);ct.sendRequest(r);const a=yield M.Member.i.getData(e.callerId),c={id:e.callerId,data:a.get(e.callerId)};K.fire(nt.RING,{user:c})}catch(t){console.warn("Ring failed",t),pt.destroy()}}))}accept(){return Promise.reject("No active call to accept.")}end(){}onUserRang(t){}onUserAcceptPacket(t){}onUserQuit(t){}onRTCTimeout(){}onRTCRemoteFlow(t){}onGoEasyDisconnected(){}muteMic(){}toggleSpeaker(){}muteCamera(){}switchCamera(){}play(t){}onRTCRemoteCameraChanged(t){}onRTCRemoteMicChanged(t){}}class Tt{static setStatus(t){this.status=t}}Tt.status=new Et;class pt{static ring(t){const e=new tt;e.id=t.callId,e.time=t.time,e.mediaType=t.type,e.groupId=t.groupId,e.speakerOn=!0,this.callContext=new it(e)}static initPrivateCall(t){const e=new tt;e.mediaType=t.mediaType,e.speakerOn=!0,e.caller=new et(M.Socket.user().id,M.Socket.user().data,"Dialing"),this.callContext=new it(e)}static initGroupCall(t){if(t.calleeIds.length>8)throw new Error("calleeIds can not more than 8");const e=new tt;e.groupId=t.groupId,e.mediaType=t.mediaType,e.speakerOn=!0,e.caller=new et(M.Socket.user().id,M.Socket.user().data,"Dialing"),this.callContext=new it(e)}static updateMemberStatus(t,e){const i=this.callContext.call;[...i.callees,i.caller].find((e=>e.id===t)).status=e}static muteMemberMic(t,e){const i=this.callContext.call,s=[...i.callees,i.caller].find((e=>e.id===t));s.micMuted&&e||!s.micMuted&&!e||(s.micMuted=e)}static muteMemberCamera(t,e){const i=this.callContext.call,s=[...i.callees,i.caller].find((e=>e.id===t));s.cameraMuted&&e||!s.cameraMuted&&!e||(s.cameraMuted=e)}static toggleSpeaker(t){this.callContext.call.speakerOn=t}static isCaller(){return this.callContext.call.caller.id===M.Socket.user().id}static destroyWithEvent(t,e=M.Socket.user()){K.fire(nt.USER_QUIT,{user:e,reason:t}),K.fire(nt.CALL_ENDED),this.destroy()}static destroy(){this.callContext.cloudRTC.destroy(),this.callContext.acceptedUsers.destroy(),this.callContext=null,$.clearStatus(),Tt.setStatus(new Et)}}class Rt{static init(){this.instance=new Rt}static i(){if(this.instance)return this.instance;throw new Error("Please connect GoEasy first.")}constructor(){this.rtcStabilizer=new V,ht.initNotificationAssembler(),M.Socket.onMessage(G.RTC_PKT,this.onServerPacket.bind(this)),F.i.on(e.RECEIVED_RTC_REMOTE_FLOW,this.onRTCRemoteFlow.bind(this)),F.i.on(e.RTC_TIMEOUT,this.onRTCTimeout.bind(this)),F.i.on(e.RTC_REMOTE_MIC_CHANGED,this.onRTCRemoteMicChanged.bind(this)),F.i.on(e.RTC_REMOTE_CAMERA_CHANGED,this.onRTCRemoteCameraChanged.bind(this)),M.Socket.on(M.Socket.EVENT.LOST,this.onGoEasyDisconnected.bind(this)),M.Socket.on(M.Socket.EVENT.DISCONNECT,this.onGoEasyDisconnected.bind(this))}on(t,e){K.on(t.toString(),e)}off(t,e){K.off(t.toString(),e)}call(e){return t(this,void 0,void 0,(function*(){return Tt.status.call(e)}))}groupCall(e){return t(this,void 0,void 0,(function*(){return Tt.status.call(e)}))}accept(){return Tt.status.accept()}getCurrentCall(){return pt.callContext.call}end(){Tt.status.end()}muteMic(t){Tt.status.muteMic(t)}toggleSpeaker(t){Tt.status.toggleSpeaker(t)}muteCamera(t){Tt.status.muteCamera(t)}switchCamera(){Tt.status.switchCamera()}play(t){Tt.status.play(t)}onServerPacket(t){Tt.status.onServerPacket(t.name,t.data)}onRTCTimeout(){Tt.status.onRTCTimeout()}onRTCRemoteFlow(t){Tt.status.onRTCRemoteFlow(t)}onGoEasyDisconnected(){Tt.status.onGoEasyDisconnected()}onRTCRemoteMicChanged(t){Tt.status.onRTCRemoteMicChanged(t)}onRTCRemoteCameraChanged(t){Tt.status.onRTCRemoteCameraChanged(t)}}class ft{static init(t){J.init(t)}static call(t){return Rt.i().call(t)}static groupCall(t){return Rt.i().groupCall(t)}static accept(){return Rt.i().accept()}static currentCall(){return Rt.i().getCurrentCall()}static end(){Rt.i().end()}static muteMic(t){Rt.i().muteMic(t)}static toggleSpeaker(t){Rt.i().toggleSpeaker(t)}static muteCamera(t){Rt.i().muteCamera(t)}static switchCamera(){Rt.i().switchCamera()}static play(t){Rt.i().play(t)}static on(t,e){Rt.i().on(t,e)}static off(t,e){Rt.i().off(t,e)}}ft.EVENT=nt;export{ft as default};
|