@rongcloud/plugin-call 5.1.0 → 5.1.1
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/dist/RCCallClient.d.ts +1 -0
- package/dist/RCCallSession.d.ts +0 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.esm.js +2 -2
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/interface.d.ts +5 -0
- package/package.json +3 -3
package/dist/RCCallClient.d.ts
CHANGED
package/dist/RCCallSession.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* RCCall - v5.1.
|
|
3
|
-
* CommitId -
|
|
4
|
-
* Wed
|
|
2
|
+
* RCCall - v5.1.1
|
|
3
|
+
* CommitId - ba3fba8044d94f2fb2d74a189c4ecc3adbad8e46
|
|
4
|
+
* Wed Jan 11 2023 14:39:33 GMT+0800 (China Standard Time)
|
|
5
5
|
* ©2020 RongCloud, Inc. All rights reserved.
|
|
6
6
|
*/
|
|
7
7
|
import { ConversationType, RTCJoinType, LogLevel, RTCPluginContext, IRuntime, IRTCJoinedInfo, IPluginGenerator } from '@rongcloud/engine';
|
|
@@ -53,7 +53,6 @@ declare class RCCallSession {
|
|
|
53
53
|
* 加入房间定时器
|
|
54
54
|
*/
|
|
55
55
|
private joinRoomTimer;
|
|
56
|
-
private ifCross;
|
|
57
56
|
constructor(
|
|
58
57
|
/**
|
|
59
58
|
* 状态机实例
|
|
@@ -428,6 +427,7 @@ interface IRCCallSessionOptions {
|
|
|
428
427
|
* 产生session的场景,是主叫产生 或 被叫产生
|
|
429
428
|
*/
|
|
430
429
|
produceType?: ProduceTypes;
|
|
430
|
+
isCrossAppkey?: boolean;
|
|
431
431
|
}
|
|
432
432
|
interface IRCTrackBitrate {
|
|
433
433
|
/**
|
|
@@ -486,6 +486,10 @@ interface IRCCallParams {
|
|
|
486
486
|
video?: IRCTrackBitrate;
|
|
487
487
|
audio?: number;
|
|
488
488
|
};
|
|
489
|
+
/**
|
|
490
|
+
* 是否为跨 appkey 通话
|
|
491
|
+
*/
|
|
492
|
+
isCrossAppkey?: boolean;
|
|
489
493
|
}
|
|
490
494
|
interface IMediaStreamConstraints {
|
|
491
495
|
video?: ICameraVideoProfile;
|
|
@@ -609,6 +613,7 @@ declare class RCCallClient {
|
|
|
609
613
|
code: RCCallErrorCode;
|
|
610
614
|
session?: RCCallSession;
|
|
611
615
|
}>;
|
|
616
|
+
private __call;
|
|
612
617
|
/**
|
|
613
618
|
* 发起群组呼叫
|
|
614
619
|
* @param params.targetId 群组 Id 必填
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{RCCallMediaType as e,RCCallLanguage as
|
|
1
|
+
import{RCCallMediaType as e,RCCallLanguage as t,RCCallSessionState as o,RCCallEndReason as i,RCCallErrorCode as s,RCCallEngine as n}from"@rongcloud/plugin-call-engine";export{RCCallEndReason,RCCallErrorCode,RCCallLanguage,RCCallMediaType,RCCallSessionState,RCCallUserState}from"@rongcloud/plugin-call-engine";import{Logger as r,RTCJoinType as a,LogLevel as l,VersionManage as c,ErrorCode as d}from"@rongcloud/engine";import{RCRTCCode as u,RCKickReason as h}from"@rongcloud/plugin-rtc";const C=new r("RCCall");
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function R(e,o,t,i){return new(t||(t=Promise))((function(s,n){function r(e){try{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(r,l)}a((i=i.apply(e,o||[])).next())}))}var _;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(_||(_={}));var p=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const f=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const t=Object.keys(e),i=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{t.includes(e)||i.push(e)})),i.length?{result:!1,msg:`Initialization missing parameter -> "${i.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(s=e.joinType,Object.values(l).includes(s))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(o).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(a).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var s},m=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},g=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},S=o=>o===e.AUDIO||o===e.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},y=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},T=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},E=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},I=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class v{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class b{constructor(o,s,n={}){this._stateMachine=o,this._rtcClient=s,this._options=n,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this.ifCross=!1,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{C.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>R(this,void 0,void 0,(function*(){const{state:o,reason:s}=e;if(C.info(`[RCCallSession onStateChange] : state->${o} reason->${s}`),o===t.KEEPING){const e=this._stateMachine.getCallId();C.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void p.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),C.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{C.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){C.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{C.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){C.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{C.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){C.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{C.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){C.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{C.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){C.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{C.info(`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this.ifCross=e}})}_joinRoom(e){return R(this,void 0,void 0,(function*(){let o;try{o=this.ifCross?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:t,userIds:n,room:r}=o;if(t!==u.SUCCESS)return t===u.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(i.SERVICE_NOT_OPENED),t===u.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(i.OTHER_CLIENT_IN_CALL):this._exceptionClose(i.NETWORK_ERROR),C.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:s.JOIN_ROOM_ERROR};n.length<1&&(this.joinRoomTimer=new v((()=>{this._exceptionClose(i.REMOTE_NETWORK_ERROR)}),6e4)),this._room=r}catch(o){return this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:s.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:s.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(i.PUBLISH_ERROR),C.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:s.JOIN_ROOM_ERROR}}return{code:s.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return R(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==u.SUCCESS&&(this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return R(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==u.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:i};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:i}}))}_publish(){return R(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:o}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(o!==u.SUCCESS)return this._exceptionClose(i.PUBLISH_ERROR),void C.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${o}`);this._options.produceType===_.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return R(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==u.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:i};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:i}}))}_leaveRoom(){return R(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this.ifCross=!1,C.info("[RCCallSession _leaveRoom] Successfully exited the room",e)}catch(e){C.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();p.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=m(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,t){return R(this,void 0,void 0,(function*(){if(o===e.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:o})}}))}_getLocalTrack(o,t){return R(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.AUDIO_VIDEO){const{code:o,tracks:n}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,t);if(o!==s.SUCCESS){const{code:o,tracks:n}=yield this._getLocalTrackCore(e.AUDIO,t);return o!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:n}}return{code:o,tracks:n}}{const{code:e,tracks:n}=yield this._getLocalTrackCore(o,t);return e!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:n}}}))}changeAudioDevice(e){return R(this,void 0,void 0,(function*(){const o=[],t=[],{code:i,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==u.SUCCESS)return C.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${i}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||t.push(e)})),o.push(n),t.push(n),this._options.localTracks=t,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==u.SUCCESS)return{code:s.AUDIO_PUBLISH_ERROR}}return{code:s.SUCCESS}}))}invite(e,o={}){return R(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,n=[I(e),y(t),T(i),E(s)],r=[];if(!n.every((e=>(!e.result&&r.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${r.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return R(this,void 0,void 0,(function*(){const o=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(e);if(!o.result)throw new Error(`[RCCallSession accept] ${o.msg}`);p.emit("hungupOtherSession",{session:this});const t=this._stateMachine.getMediaType(),{code:i,tracks:n}=yield this._getLocalTrack(t,e);if(i!==s.SUCCESS)return{code:i};this._options.localTracks=n;const{code:r}=yield this._stateMachine.accept();return r!==s.SUCCESS?(C.error(`[RCCallSession accept]Send accept message failed -> code: ${r}`),{code:r}):{code:r}}))}hungup(){return R(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return R(this,void 0,void 0,(function*(){const{code:o}=yield this._stateMachine.changeMediaType(e);return o!==s.SUCCESS&&C.error(`[RCCallSession _changeMediaType] change media type fail code-> ${o}`),{code:o}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return R(this,void 0,void 0,(function*(){const{code:o,track:t}=yield this._rtcClient.createCameraVideoTrack();if(o!==u.SUCCESS)return{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:i}=yield this._room.publish([t]);i===u.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(e.AUDIO_VIDEO)):C.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_setMediaTypeToAudio(){return R(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==u.SUCCESS&&C.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return R(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.AUDIO);return o===s.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return R(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return C.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:s.SUCCESS};const{code:o}=yield this._room.unpublish(e);return o!==u.SUCCESS?(C.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:s.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:s.SUCCESS})}))}enableVideoTrack(){return R(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:s.SUCCESS}):(C.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return C.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:s.GET_LOCAL_VIDEO_TRACK_ERROR};const t=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():t.push(e)})),t.push(o),this._options.localTracks=t,o.mute();const{code:i}=yield this._room.publish([o]);return i!==u.SUCCESS?(C.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:s.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:s.SUCCESS})}))}disableAudioTrack(){return R(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return R(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){C.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const t=this._rtcClient.getCurrentId();this._stateMachine.userLeave([t]),e?(o===h.SERVER_KICK&&this._exceptionClose(i.KICKED_BY_SERVER),o===h.OTHER_KICK&&this._exceptionClose(i.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(i.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{C.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){C.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{C.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){C.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>R(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==u.SUCCESS&&C.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{C.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{C.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){C.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){C.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){C.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}c.add("plugin-call","5.1.0"),c.validEngine("^5.5.4")||C.error(`The current engine version '${c.getInfo().engine}' error,plugin-call required engine version at least '^5.5.4'.`);class O{constructor(e,t,i){this._context=e,this._runtime=t,this._sessionList=[],this._rtcClient=i.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:l.COEXIST,isAllowDemotionGetStream:!1,lang:o.ZH},i),this._callEngine=new n(this._context,t,C,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.ZH}),p.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){C.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),p.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();C.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),C.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;C.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){C.info("[RCCallClient _onInvite] Received invite message");const t=new b(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLEE});C.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){C.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw C.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=m(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){C.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),C.info("[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:o,mediaType:t=e.AUDIO,listener:i,constraints:n,channelId:r="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:d}){return R(this,void 0,void 0,(function*(){C.info(`[RCCallClient call] extra->${l} pushTitle->${a} pushContent->${c}`);const e=[g(o),S(t),m(i),y(l),T(a),E(c)],u=[];if(!e.every((e=>(!e.result&&u.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${u.join("\n")}`);let h=[];const{code:R,tracks:p}=yield this._getLocalTrack(t,n);if(R!==s.SUCCESS)return{code:R};h=p,h.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==d?void 0:d.audio)&&e.setBitrate(null==d?void 0:d.audio),e.isVideoTrack()&&(null==d?void 0:d.video)&&e.setBitrate(null===(o=null==d?void 0:d.video)||void 0===o?void 0:o.max,null===(t=null==d?void 0:d.video)||void 0===t?void 0:t.min,null===(s=null==d?void 0:d.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:f,stateMachine:I}=yield this._callEngine.startCrossCall(r,o,t,l,a,c);if(f===s.SUCCESS&&I){C.info("[RCCallClient call] successfully created state machine");const e=new b(I,this._rtcClient,{localTracks:h,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),C.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:f,session:e}}return C.error(`[RCCallClient call] call failed code ->: ${f}`),h.forEach((e=>{e.mute(),e.destroy()})),{code:f}}))}call({targetId:o,mediaType:t=e.AUDIO,listener:i,constraints:n,channelId:r="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:d}){return R(this,void 0,void 0,(function*(){C.info(`[RCCallClient call] extra->${l} pushTitle->${a} pushContent->${c}`);const e=[g(o),S(t),m(i),y(l),T(a),E(c)],u=[];if(!e.every((e=>(!e.result&&u.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${u.join("\n")}`);let h=[];const{code:R,tracks:p}=yield this._getLocalTrack(t,n);if(R!==s.SUCCESS)return{code:R};h=p,h.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==d?void 0:d.audio)&&e.setBitrate(null==d?void 0:d.audio),e.isVideoTrack()&&(null==d?void 0:d.video)&&e.setBitrate(null===(o=null==d?void 0:d.video)||void 0===o?void 0:o.max,null===(t=null==d?void 0:d.video)||void 0===t?void 0:t.min,null===(s=null==d?void 0:d.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:f,stateMachine:I}=yield this._callEngine.call(r,o,t,l,a,c);if(f===s.SUCCESS&&I){C.info("[RCCallClient call] successfully created state machine");const e=new b(I,this._rtcClient,{localTracks:h,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),C.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:f,session:e}}return C.error(`[RCCallClient call] call failed code ->: ${f}`),h.forEach((e=>{e.mute(),e.destroy()})),{code:f}}))}callInGroup({targetId:o,userIds:t,mediaType:i=e.AUDIO,listener:n,constraints:r,channelId:l="",extra:a="",pushTitle:c="",pushContent:d="",bitrate:u}){return R(this,void 0,void 0,(function*(){const e=[g(o),I(t),S(i),m(n),y(a),T(c),E(d)],h=[];if(!e.every((e=>(!e.result&&h.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${h.join("\n")}`);let R=[];const{code:p,tracks:f}=yield this._getLocalTrack(i,r);if(p!==s.SUCCESS)return{code:p};R=f,R.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==u?void 0:u.audio)&&e.setBitrate(null==u?void 0:u.audio),e.isVideoTrack()&&(null==u?void 0:u.video)&&e.setBitrate(null===(o=null==u?void 0:u.video)||void 0===o?void 0:o.max,null===(t=null==u?void 0:u.video)||void 0===t?void 0:t.min,null===(i=null==u?void 0:u.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:v,stateMachine:O}=yield this._callEngine.callInGroup(l,o,i,t,a,c,d);if(v===s.SUCCESS&&O){C.info("[RCCallClient callInGroup] successfully created state machine");const e=new b(O,this._rtcClient,{localTracks:R,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),C.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return C.info(`[RCCallClient callInGroup] callInGroup failed code -> ${v}`),R.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}_getLocalTrackCore(o,t){return R(this,void 0,void 0,(function*(){if(o===e.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:o})}}))}_getLocalTrack(o,t){return R(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,t);if(o!==s.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.AUDIO,t);return o!==s.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:e,tracks:i}=yield this._getLocalTrackCore(o,t);return e!==s.SUCCESS?{code:e}:{code:e,tracks:i}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return R(this,void 0,void 0,(function*(){const{code:e,data:o}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==d.SUCCESS?(C.error("getJoinedUserInfo error",e),{code:s.QUERY_JOINED_USER_INFO_ERROR}):{code:s.SUCCESS,data:o}}))}}const k={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=f(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return C.setLogLevel(t.logLevel),C.setLogStdout(t.logStdout),C.warn("RCCall Version: 5.1.0, Commit: b538264c6c82a359de6d52c45df2e0dd8dbc055e"),new O(e,o,t)}};export{O as RCCallClient,b as RCCallSession,k as installer};
|
|
15
|
+
***************************************************************************** */function _(e,t,o,i){return new(o||(o=Promise))((function(s,n){function r(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(r,a)}l((i=i.apply(e,t||[])).next())}))}var R;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(R||(R={}));var p=new class{constructor(){this.list={}}on(e,t){return(this.list[e]||(this.list[e]=[])).push(t),this}once(e,t){const o=i=>{this.off(e,o),t.call(this,i)};o.fun=t,this.on(e,o)}off(e,t){const o=this.list[e];if(!o)return!1;if(t){let e;for(let i=0,s=o.length;i<s;i++)if(e=o[i],e===t||e.fun===t){o.splice(i,1);break}}else o&&(o.length=0)}emit(e,t){const o=[...this.list[e]];if(!o||0===o.length)return!1;o.forEach((e=>{e.call(this,t)}))}};const f=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const o=Object.keys(e),i=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{o.includes(e)||i.push(e)})),i.length?{result:!1,msg:`Initialization missing parameter -> "${i.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(s=e.joinType,Object.values(a).includes(s))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(t).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(l).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var s},g=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const t=Object.keys(e),o=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{t.includes(e)||o.push(e)})),o.length?{result:!1,msg:`missing parameter -> "${o.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},m=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},S=t=>t===e.AUDIO||t===e.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},y=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},T=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},I=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},E=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class v{constructor(e,t){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,t)=>setTimeout(e,t))((()=>{e()}),t)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let t=e-this._startTime;return 0===this._startTime&&(t=0),{startTime:this._startTime,endTime:e,duration:t}}reset(){this._startTime=0}}class b{constructor(t,s,n={}){this._stateMachine=t,this._rtcClient=s,this._options=n,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:t})=>{C.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${t}`)},onStateChange:e=>_(this,void 0,void 0,(function*(){const{state:t,reason:s}=e;if(C.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===o.KEEPING){const e=this._stateMachine.getCallId();C.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void p.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),C.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{C.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){C.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{C.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){C.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,t)=>{C.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${t}`);try{this._listener.onHungup(e,t,this)}catch(e){C.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:t})=>{C.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,t,this)}catch(e){C.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:t,mediaType:o})=>{C.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${t.userId} mediaType: ${o}`),o===e.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(t,o,this)}catch(e){C.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{C.info(`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}})}_joinRoom(e){return _(this,void 0,void 0,(function*(){let t;try{t=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:o,userIds:n,room:r}=t;if(o!==u.SUCCESS)return o===u.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(i.SERVICE_NOT_OPENED),o===u.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(i.OTHER_CLIENT_IN_CALL):this._exceptionClose(i.NETWORK_ERROR),C.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${o}`),{code:s.JOIN_ROOM_ERROR};n.length<1&&(this.joinRoomTimer=new v((()=>{this._exceptionClose(i.REMOTE_NETWORK_ERROR)}),6e4)),this._room=r}catch(t){return this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(i.PUBLISH_ERROR),C.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}return{code:s.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return _(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==u.SUCCESS&&(this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==u.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._subscribeRetry(e,t,o)}return{code:i}}))}_publish(){return _(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==u.SUCCESS)return this._exceptionClose(i.PUBLISH_ERROR),void C.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===R.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==u.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._publishRetry(e,t,o)}return{code:i}}))}_leaveRoom(){return _(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);C.info("[RCCallSession _leaveRoom] Successfully exited the room",e)}catch(e){C.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();p.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const t=g(e);if(!t.result)throw new Error(`[RCCallSession registerSessionListener] ${t.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(t,o){return _(this,void 0,void 0,(function*(){if(t===e.AUDIO){const{code:e,track:t}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[t]})}{const{code:e,tracks:t}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:t})}}))}_getLocalTrack(t,o){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&t===e.AUDIO_VIDEO){const{code:t,tracks:n}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,o);if(t!==s.SUCCESS){const{code:t,tracks:n}=yield this._getLocalTrackCore(e.AUDIO,o);return t!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:t}):{code:t,tracks:n}}return{code:t,tracks:n}}{const{code:e,tracks:n}=yield this._getLocalTrackCore(t,o);return e!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:n}}}))}changeAudioDevice(e){return _(this,void 0,void 0,(function*(){const t=[],o=[],{code:i,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==u.SUCCESS)return C.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${i}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||o.push(e)})),t.push(n),o.push(n),this._options.localTracks=o,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==u.SUCCESS)return{code:s.AUDIO_PUBLISH_ERROR}}return{code:s.SUCCESS}}))}invite(e,t={}){return _(this,void 0,void 0,(function*(){const{extra:o="",pushTitle:i="",pushContent:s=""}=t,n=[E(e),y(o),T(i),I(s)],r=[];if(!n.every((e=>(!e.result&&r.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${r.join("\n")}`);const{code:a}=yield this._stateMachine.invite(e,{extra:o,pushTitle:i,pushContent:s});return{code:a}}))}accept(e){return _(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(t=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(t))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var t})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);p.emit("hungupOtherSession",{session:this});const o=this._stateMachine.getMediaType(),{code:i,tracks:n}=yield this._getLocalTrack(o,e);if(i!==s.SUCCESS)return{code:i};this._options.localTracks=n;const{code:r}=yield this._stateMachine.accept();return r!==s.SUCCESS?(C.error(`[RCCallSession accept]Send accept message failed -> code: ${r}`),{code:r}):{code:r}}))}hungup(){return _(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==s.SUCCESS&&C.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return _(this,void 0,void 0,(function*(){const{code:t,track:o}=yield this._rtcClient.createCameraVideoTrack();if(t!==u.SUCCESS)return{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:i}=yield this._room.publish([o]);i===u.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(e.AUDIO_VIDEO)):C.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${t}`)}))}_setMediaTypeToAudio(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:t}=yield this._room.unpublish(e);t!==u.SUCCESS&&C.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),this._destroyTracks(e)}}))}descendAbility(){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._changeMediaType(e.AUDIO);return t===s.SUCCESS&&this._setMediaTypeToAudio(),{code:t}}))}disableVideoTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return C.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:s.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==u.SUCCESS?(C.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:s.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:s.SUCCESS})}))}enableVideoTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:s.SUCCESS}):(C.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return C.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:s.GET_LOCAL_VIDEO_TRACK_ERROR};const o=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():o.push(e)})),o.push(t),this._options.localTracks=o,t.mute();const{code:i}=yield this._room.publish([t]);return i!==u.SUCCESS?(C.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:s.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:s.SUCCESS})}))}disableAudioTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.NOT_IN_ROOM_ERROR}`),{code:s.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return C.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){C.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const o=this._rtcClient.getCurrentId();this._stateMachine.userLeave([o]),e?(t===h.SERVER_KICK&&this._exceptionClose(i.KICKED_BY_SERVER),t===h.OTHER_KICK&&this._exceptionClose(i.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(i.NETWORK_ERROR)},onMessageReceive(e,t,o,i){},onRoomAttributeChange(e,t){},onAudioMuteChange:e=>{C.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(t,this)}catch(e){C.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{C.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(t,this)}catch(e){C.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>_(this,void 0,void 0,(function*(){if(this._room){const{code:t}=yield this._room.subscribe(e);t!==u.SUCCESS&&C.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${t}`)}})),onTrackUnpublish:e=>{},onTrackReady:t=>{this._stateMachine.getMediaType()===e.AUDIO&&t.isVideoTrack()||this._notifyTrackReady([t])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{C.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{C.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){C.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){C.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){C.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}c.add("plugin-call","5.1.1"),c.validEngine("^5.5.4")||C.error(`The current engine version '${c.getInfo().engine}' error,plugin-call required engine version at least '^5.5.4'.`);class O{constructor(e,o,i){this._context=e,this._runtime=o,this._sessionList=[],this._rtcClient=i.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:a.COEXIST,isAllowDemotionGetStream:!1,lang:t.ZH},i),this._callEngine=new n(this._context,o,C,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.ZH}),p.on("sessionClose",(({session:e,summaryInfo:t})=>{this._removeSession(e);try{this._options.onSessionClose(e,t)}catch(e){C.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),p.on("hungupOtherSession",(({session:e})=>{const t=e.getSessionId();C.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${t}`),C.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let o=0;for(;this._sessionList.length>1;)this._sessionList[o].getSessionId()!==t?(this._sessionList[o].hungup(),this._sessionList.splice(o,1)):o++;C.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,t){C.info("[RCCallClient _onInvite] Received invite message");const o=new b(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLEE});C.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o,t)}catch(e){C.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw C.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=g(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){C.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),C.info("[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:t,mediaType:o=e.AUDIO,listener:i,constraints:s,channelId:n="",extra:r="",pushTitle:a="",pushContent:l="",bitrate:c}){return _(this,void 0,void 0,(function*(){return this.__call({targetId:t,mediaType:o,listener:i,constraints:s,channelId:n,extra:r,pushTitle:a,pushContent:l,bitrate:c,isCrossAppkey:!0})}))}call({targetId:t,mediaType:o=e.AUDIO,listener:i,constraints:s,channelId:n="",extra:r="",pushTitle:a="",pushContent:l="",bitrate:c}){return _(this,void 0,void 0,(function*(){return this.__call({targetId:t,mediaType:o,listener:i,constraints:s,channelId:n,extra:r,pushTitle:a,pushContent:l,bitrate:c})}))}__call({targetId:t,mediaType:o=e.AUDIO,listener:i,constraints:n,channelId:r="",extra:a="",pushTitle:l="",pushContent:c="",bitrate:d,isCrossAppkey:u=!1}){return _(this,void 0,void 0,(function*(){C.info(`[RCCallClient call] extra->${a} pushTitle->${l} pushContent->${c}`);const e=[m(t),S(o),g(i),y(a),T(l),I(c)],h=[];if(!e.every((e=>(!e.result&&h.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${h.join("\n")}`);let _=[];const{code:p,tracks:f}=yield this._getLocalTrack(o,n);if(p!==s.SUCCESS)return{code:p};_=f,_.forEach((e=>{var t,o,s;e.isAudioTrack()&&(null==d?void 0:d.audio)&&e.setBitrate(null==d?void 0:d.audio),e.isVideoTrack()&&(null==d?void 0:d.video)&&e.setBitrate(null===(t=null==d?void 0:d.video)||void 0===t?void 0:t.max,null===(o=null==d?void 0:d.video)||void 0===o?void 0:o.min,null===(s=null==d?void 0:d.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:E,stateMachine:v}=yield this._callEngine.call(r,t,o,a,l,c,u);if(E===s.SUCCESS&&v){C.info("[RCCallClient call] successfully created state machine");const e=new b(v,this._rtcClient,{localTracks:_,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLER,isCrossAppkey:u});return e.registerSessionListener(i),this._sessionList.push(e),C.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:E,session:e}}return C.error(`[RCCallClient call] call failed code ->: ${E}`),_.forEach((e=>{e.mute(),e.destroy()})),{code:E}}))}callInGroup({targetId:t,userIds:o,mediaType:i=e.AUDIO,listener:n,constraints:r,channelId:a="",extra:l="",pushTitle:c="",pushContent:d="",bitrate:u}){return _(this,void 0,void 0,(function*(){const e=[m(t),E(o),S(i),g(n),y(l),T(c),I(d)],h=[];if(!e.every((e=>(!e.result&&h.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${h.join("\n")}`);let _=[];const{code:p,tracks:f}=yield this._getLocalTrack(i,r);if(p!==s.SUCCESS)return{code:p};_=f,_.forEach((e=>{var t,o,i;e.isAudioTrack()&&(null==u?void 0:u.audio)&&e.setBitrate(null==u?void 0:u.audio),e.isVideoTrack()&&(null==u?void 0:u.video)&&e.setBitrate(null===(t=null==u?void 0:u.video)||void 0===t?void 0:t.max,null===(o=null==u?void 0:u.video)||void 0===o?void 0:o.min,null===(i=null==u?void 0:u.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:v,stateMachine:O}=yield this._callEngine.callInGroup(a,t,i,o,l,c,d);if(v===s.SUCCESS&&O){C.info("[RCCallClient callInGroup] successfully created state machine");const e=new b(O,this._rtcClient,{localTracks:_,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),C.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return C.info(`[RCCallClient callInGroup] callInGroup failed code -> ${v}`),_.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}_getLocalTrackCore(t,o){return _(this,void 0,void 0,(function*(){if(t===e.AUDIO){const{code:e,track:t}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[t]})}{const{code:e,tracks:t}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:t})}}))}_getLocalTrack(t,o){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&t===e.AUDIO_VIDEO){const{code:t,tracks:i}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,o);if(t!==s.SUCCESS){const{code:t,tracks:i}=yield this._getLocalTrackCore(e.AUDIO,o);return t!==s.SUCCESS?{code:t}:{code:t,tracks:i}}return{code:t,tracks:i}}{const{code:e,tracks:i}=yield this._getLocalTrackCore(t,o);return e!==s.SUCCESS?{code:e}:{code:e,tracks:i}}}))}_removeSession(e){const t=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==t))}getJoinedRoomInfo(){return _(this,void 0,void 0,(function*(){const{code:e,data:t}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==d.SUCCESS?(C.error("getJoinedUserInfo error",e),{code:s.QUERY_JOINED_USER_INFO_ERROR}):{code:s.SUCCESS,data:t}}))}}const k={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,o){const i=f(o);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return C.setLogLevel(o.logLevel),C.setLogStdout(o.logStdout),C.warn("RCCall Version: 5.1.1, Commit: ba3fba8044d94f2fb2d74a189c4ecc3adbad8e46"),new O(e,t,o)}};export{O as RCCallClient,b as RCCallSession,k as installer};
|
package/dist/index.js
CHANGED
|
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var r;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(r||(r={}));var n=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const l=t=>{if(!t)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof t)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(t),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof t.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof t.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof t.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==t.isAllowSubscribeRetry&&"boolean"!=typeof t.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==t.isAllowPublishRetry&&"boolean"!=typeof t.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==t.isOffCameraWhenVideoDisable&&"boolean"!=typeof t.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===t.joinType||(r=t.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==t.isAllowDemotionGetStream&&"boolean"!=typeof t.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===t.lang||function(o){return Object.values(e.RCCallLanguage).includes(o)}(t.lang)?void 0===t.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(t.logLevel)?void 0!==t.logStdout&&"function"!=typeof t.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},a=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},c=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=o=>o===e.RCCallMediaType.AUDIO||o===e.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class _{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class p{constructor(o,t,r={}){this._stateMachine=o,this._rtcClient=t,this._options=r,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this.ifCross=!1,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{i.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:o=>s(this,void 0,void 0,(function*(){const{state:t,reason:s}=o;if(i.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===e.RCCallSessionState.KEEPING){const o=this._stateMachine.getCallId();i.info(`[RCCallSession onStateChange] roomId: ${o}`);try{yield this._joinRoom(o)}catch(t){this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${o}`),console.error(t)}}else if(t===e.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),i.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{i.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){i.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{i.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){i.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{i.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){i.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{i.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){i.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{i.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){i.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{i.info(`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this.ifCross=e}})}_joinRoom(o){return s(this,void 0,void 0,(function*(){let s;try{s=this.ifCross?yield this._rtcClient.joinCrossRTCRoom(o,this._options.joinType):yield this._rtcClient.joinRTCRoom(o,this._options.joinType);const{code:r,userIds:n,room:l}=s;if(r!==t.RCRTCCode.SUCCESS)return r===t.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(e.RCCallEndReason.SERVICE_NOT_OPENED),r===t.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${o} RCRTCCode -> ${r}`),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR};n.length<1&&(this.joinRoomTimer=new _((()=>{this._exceptionClose(e.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=l}catch(t){return this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),i.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const o=this._room.getRemoteTracks();if(o.length){const{code:s}=yield this._subscribeRetry(o,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);s!==t.RCRTCCode.SUCCESS&&(this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${s}`))}}))}_subscribeRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._subscribeRetry(e,o,r)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==t.RCRTCCode.SUCCESS)return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),void i.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===r.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._publishRetry(e,o,r)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this.ifCross=!1,i.info("[RCCallSession _leaveRoom] Successfully exited the room",e)}catch(e){i.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();n.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=a(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(o){return s(this,void 0,void 0,(function*(){const s=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o);if(n!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),s.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(s),this._room){const{code:o}=yield this._room.publish(s);if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return s(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[h(e),d(t),u(i),R(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(o){return s(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(o);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);n.emit("hungupOtherSession",{session:this});const s=this._stateMachine.getMediaType(),{code:r,tracks:l}=yield this._getLocalTrack(s,o);if(r!==e.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=l;const{code:a}=yield this._stateMachine.accept();return a!==e.RCCallErrorCode.SUCCESS?(i.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(o){return s(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(o);return t!==e.RCCallErrorCode.SUCCESS&&i.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([s]);r===t.RCRTCCode.SUCCESS?(this._notifyTrackReady([s]),this._changeMediaType(e.RCCallMediaType.AUDIO_VIDEO)):i.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.RCCallMediaType.AUDIO);return o===e.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};const o=this._getLocalVideoTracks();if(!o.length)return i.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(o.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:e.RCCallErrorCode.SUCCESS};const{code:s}=yield this._room.unpublish(o);return s!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession disableVideo] unpublish failed -> ${s}`),{code:e.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(o.forEach((e=>{e.destroy()})),{code:e.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const o=this._getLocalVideoTracks();return o.length?(o.forEach((e=>{e.unmute()})),{code:e.RCCallErrorCode.SUCCESS}):(i.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(s),this._options.localTracks=r,s.mute();const{code:n}=yield this._room.publish([s]);return n!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(s.unmute(),this._notifyTrackReady([s]),{code:e.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};const o=this._getLocalAudioTracks();if(!o.length)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};o.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){i.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(o,i)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),o?(i===t.RCKickReason.SERVER_KICK&&this._exceptionClose(e.RCCallEndReason.KICKED_BY_SERVER),i===t.RCKickReason.OTHER_KICK&&this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{i.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){i.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{i.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){i.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.RCCallMediaType.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{i.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{i.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){i.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){i.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){i.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}o.VersionManage.add("plugin-call","5.1.0"),o.VersionManage.validEngine("^5.5.4")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '^5.5.4'.`);class f{constructor(t,s,r){this._context=t,this._runtime=s,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:e.RCCallLanguage.ZH},r),this._callEngine=new e.RCCallEngine(this._context,s,i,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||e.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){i.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();i.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),i.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;i.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){i.info("[RCCallClient _onInvite] Received invite message");const t=new p(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLEE});i.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){i.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw i.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){i.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),i.info("[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:h="",extra:_="",pushTitle:f="",pushContent:g="",bitrate:m}){return s(this,void 0,void 0,(function*(){i.info(`[RCCallClient call] extra->${_} pushTitle->${f} pushContent->${g}`);const s=[c(o),C(t),a(n),d(_),u(f),R(g)],S=[];if(!s.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let T=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==e.RCCallErrorCode.SUCCESS)return{code:y};T=E,T.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(i=null==m?void 0:m.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:v,stateMachine:I}=yield this._callEngine.startCrossCall(h,o,t,_,f,g);if(v===e.RCCallErrorCode.SUCCESS&&I){i.info("[RCCallClient call] successfully created state machine");const e=new p(I,this._rtcClient,{localTracks:T,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${v}`),T.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:h="",extra:_="",pushTitle:f="",pushContent:g="",bitrate:m}){return s(this,void 0,void 0,(function*(){i.info(`[RCCallClient call] extra->${_} pushTitle->${f} pushContent->${g}`);const s=[c(o),C(t),a(n),d(_),u(f),R(g)],S=[];if(!s.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let T=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==e.RCCallErrorCode.SUCCESS)return{code:y};T=E,T.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(i=null==m?void 0:m.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:v,stateMachine:I}=yield this._callEngine.call(h,o,t,_,f,g);if(v===e.RCCallErrorCode.SUCCESS&&I){i.info("[RCCallClient call] successfully created state machine");const e=new p(I,this._rtcClient,{localTracks:T,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${v}`),T.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}callInGroup({targetId:o,userIds:t,mediaType:n=e.RCCallMediaType.AUDIO,listener:l,constraints:_,channelId:f="",extra:g="",pushTitle:m="",pushContent:S="",bitrate:T}){return s(this,void 0,void 0,(function*(){const s=[c(o),h(t),C(n),a(l),d(g),u(m),R(S)],y=[];if(!s.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:v,tracks:I}=yield this._getLocalTrack(n,_);if(v!==e.RCCallErrorCode.SUCCESS)return{code:v};E=I,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==T?void 0:T.audio)&&e.setBitrate(null==T?void 0:T.audio),e.isVideoTrack()&&(null==T?void 0:T.video)&&e.setBitrate(null===(o=null==T?void 0:T.video)||void 0===o?void 0:o.max,null===(t=null==T?void 0:T.video)||void 0===t?void 0:t.min,null===(i=null==T?void 0:T.video)||void 0===i?void 0:i.start),l.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.callInGroup(f,o,n,t,g,m,S);if(b===e.RCCallErrorCode.SUCCESS&&O){i.info("[RCCallClient callInGroup] successfully created state machine");const e=new p(O,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),i.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return i.info(`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:t,data:s}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return t!==o.ErrorCode.SUCCESS?(i.error("getJoinedUserInfo error",t),{code:e.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:e.RCCallErrorCode.SUCCESS,data:s}}))}}const g={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const s=l(t);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);return i.setLogLevel(t.logLevel),i.setLogStdout(t.logStdout),i.warn("RCCall Version: 5.1.0, Commit: b538264c6c82a359de6d52c45df2e0dd8dbc055e"),new f(e,o,t)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return e.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return e.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return e.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return e.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return e.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return e.RCCallUserState}}),exports.RCCallClient=f,exports.RCCallSession=p,exports.installer=g;
|
|
15
|
+
***************************************************************************** */function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var r;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(r||(r={}));var n=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const l=t=>{if(!t)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof t)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(t),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof t.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof t.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof t.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==t.isAllowSubscribeRetry&&"boolean"!=typeof t.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==t.isAllowPublishRetry&&"boolean"!=typeof t.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==t.isOffCameraWhenVideoDisable&&"boolean"!=typeof t.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===t.joinType||(r=t.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==t.isAllowDemotionGetStream&&"boolean"!=typeof t.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===t.lang||function(o){return Object.values(e.RCCallLanguage).includes(o)}(t.lang)?void 0===t.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(t.logLevel)?void 0!==t.logStdout&&"function"!=typeof t.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},a=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},c=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=o=>o===e.RCCallMediaType.AUDIO||o===e.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class _{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class p{constructor(o,t,r={}){this._stateMachine=o,this._rtcClient=t,this._options=r,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{i.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:o=>s(this,void 0,void 0,(function*(){const{state:t,reason:s}=o;if(i.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===e.RCCallSessionState.KEEPING){const o=this._stateMachine.getCallId();i.info(`[RCCallSession onStateChange] roomId: ${o}`);try{yield this._joinRoom(o)}catch(t){this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${o}`),console.error(t)}}else if(t===e.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),i.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{i.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){i.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{i.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){i.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{i.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){i.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{i.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){i.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{i.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){i.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{i.info(`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}})}_joinRoom(o){return s(this,void 0,void 0,(function*(){let s;try{s=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(o,this._options.joinType):yield this._rtcClient.joinRTCRoom(o,this._options.joinType);const{code:r,userIds:n,room:l}=s;if(r!==t.RCRTCCode.SUCCESS)return r===t.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(e.RCCallEndReason.SERVICE_NOT_OPENED),r===t.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${o} RCRTCCode -> ${r}`),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR};n.length<1&&(this.joinRoomTimer=new _((()=>{this._exceptionClose(e.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=l}catch(t){return this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),i.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const o=this._room.getRemoteTracks();if(o.length){const{code:s}=yield this._subscribeRetry(o,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);s!==t.RCRTCCode.SUCCESS&&(this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${s}`))}}))}_subscribeRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._subscribeRetry(e,o,r)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==t.RCRTCCode.SUCCESS)return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),void i.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===r.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._publishRetry(e,o,r)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);i.info("[RCCallSession _leaveRoom] Successfully exited the room",e)}catch(e){i.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();n.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=a(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(o){return s(this,void 0,void 0,(function*(){const s=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o);if(n!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),s.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(s),this._room){const{code:o}=yield this._room.publish(s);if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return s(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[h(e),d(t),u(i),R(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(o){return s(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(o);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);n.emit("hungupOtherSession",{session:this});const s=this._stateMachine.getMediaType(),{code:r,tracks:l}=yield this._getLocalTrack(s,o);if(r!==e.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=l;const{code:a}=yield this._stateMachine.accept();return a!==e.RCCallErrorCode.SUCCESS?(i.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(o){return s(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(o);return t!==e.RCCallErrorCode.SUCCESS&&i.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([s]);r===t.RCRTCCode.SUCCESS?(this._notifyTrackReady([s]),this._changeMediaType(e.RCCallMediaType.AUDIO_VIDEO)):i.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.RCCallMediaType.AUDIO);return o===e.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};const o=this._getLocalVideoTracks();if(!o.length)return i.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(o.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:e.RCCallErrorCode.SUCCESS};const{code:s}=yield this._room.unpublish(o);return s!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession disableVideo] unpublish failed -> ${s}`),{code:e.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(o.forEach((e=>{e.destroy()})),{code:e.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const o=this._getLocalVideoTracks();return o.length?(o.forEach((e=>{e.unmute()})),{code:e.RCCallErrorCode.SUCCESS}):(i.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(s),this._options.localTracks=r,s.mute();const{code:n}=yield this._room.publish([s]);return n!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(s.unmute(),this._notifyTrackReady([s]),{code:e.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:e.RCCallErrorCode.NOT_IN_ROOM_ERROR};const o=this._getLocalAudioTracks();if(!o.length)return i.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};o.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){i.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(o,i)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),o?(i===t.RCKickReason.SERVER_KICK&&this._exceptionClose(e.RCCallEndReason.KICKED_BY_SERVER),i===t.RCKickReason.OTHER_KICK&&this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{i.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){i.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{i.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){i.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.RCCallMediaType.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{i.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{i.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){i.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){i.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){i.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}o.VersionManage.add("plugin-call","5.1.1"),o.VersionManage.validEngine("^5.5.4")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '^5.5.4'.`);class g{constructor(t,s,r){this._context=t,this._runtime=s,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:e.RCCallLanguage.ZH},r),this._callEngine=new e.RCCallEngine(this._context,s,i,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||e.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){i.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();i.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),i.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;i.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){i.info("[RCCallClient _onInvite] Received invite message");const t=new p(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLEE});i.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){i.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw i.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){i.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),i.info("[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:o,mediaType:t,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C,isCrossAppkey:!0})}))}call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:o,mediaType:t,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C})}))}__call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:h="",extra:_="",pushTitle:g="",pushContent:f="",bitrate:m,isCrossAppkey:S=!1}){return s(this,void 0,void 0,(function*(){i.info(`[RCCallClient call] extra->${_} pushTitle->${g} pushContent->${f}`);const s=[c(o),C(t),a(n),d(_),u(g),R(f)],T=[];if(!s.every((e=>(!e.result&&T.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${T.join("\n")}`);let y=[];const{code:E,tracks:I}=yield this._getLocalTrack(t,l);if(E!==e.RCCallErrorCode.SUCCESS)return{code:E};y=I,y.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(i=null==m?void 0:m.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:b,stateMachine:v}=yield this._callEngine.call(h,o,t,_,g,f,S);if(b===e.RCCallErrorCode.SUCCESS&&v){i.info("[RCCallClient call] successfully created state machine");const e=new p(v,this._rtcClient,{localTracks:y,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER,isCrossAppkey:S});return e.registerSessionListener(n),this._sessionList.push(e),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${b}`),y.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}callInGroup({targetId:o,userIds:t,mediaType:n=e.RCCallMediaType.AUDIO,listener:l,constraints:_,channelId:g="",extra:f="",pushTitle:m="",pushContent:S="",bitrate:T}){return s(this,void 0,void 0,(function*(){const s=[c(o),h(t),C(n),a(l),d(f),u(m),R(S)],y=[];if(!s.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:I,tracks:b}=yield this._getLocalTrack(n,_);if(I!==e.RCCallErrorCode.SUCCESS)return{code:I};E=b,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==T?void 0:T.audio)&&e.setBitrate(null==T?void 0:T.audio),e.isVideoTrack()&&(null==T?void 0:T.video)&&e.setBitrate(null===(o=null==T?void 0:T.video)||void 0===o?void 0:o.max,null===(t=null==T?void 0:T.video)||void 0===t?void 0:t.min,null===(i=null==T?void 0:T.video)||void 0===i?void 0:i.start),l.onTrackReady(e)}));const{code:v,stateMachine:O}=yield this._callEngine.callInGroup(g,o,n,t,f,m,S);if(v===e.RCCallErrorCode.SUCCESS&&O){i.info("[RCCallClient callInGroup] successfully created state machine");const e=new p(O,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),i.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return i.info(`[RCCallClient callInGroup] callInGroup failed code -> ${v}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:t,data:s}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return t!==o.ErrorCode.SUCCESS?(i.error("getJoinedUserInfo error",t),{code:e.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:e.RCCallErrorCode.SUCCESS,data:s}}))}}const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const s=l(t);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);return i.setLogLevel(t.logLevel),i.setLogStdout(t.logStdout),i.warn("RCCall Version: 5.1.1, Commit: ba3fba8044d94f2fb2d74a189c4ecc3adbad8e46"),new g(e,o,t)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return e.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return e.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return e.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return e.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return e.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return e.RCCallUserState}}),exports.RCCallClient=g,exports.RCCallSession=p,exports.installer=f;
|
package/dist/index.umd.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function r(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var n;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(n||(n={}));var l=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const a=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(t.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(o.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(t.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},c=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},C=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},d=e=>e===o.RCCallMediaType.AUDIO||e===o.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class p{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class f{constructor(e,t,i={}){this._stateMachine=e,this._rtcClient=t,this._options=i,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this.ifCross=!1,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{s.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>r(this,void 0,void 0,(function*(){const{state:t,reason:i}=e;if(s.info(`[RCCallSession onStateChange] : state->${t} reason->${i}`),t===o.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();s.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void l.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),s.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{s.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){s.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{s.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){s.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{s.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){s.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{s.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){s.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{s.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===o.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){s.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{s.info(`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this.ifCross=e}})}_joinRoom(e){return r(this,void 0,void 0,(function*(){let t;try{t=this.ifCross?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:r,userIds:n,room:l}=t;if(r!==i.RCRTCCode.SUCCESS)return r===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(o.RCCallEndReason.SERVICE_NOT_OPENED),r===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${r}`),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR};n.length<1&&(this.joinRoomTimer=new p((()=>{this._exceptionClose(o.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=l}catch(t){return this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),s.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return r(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.subscribe(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:r}}))}_publish(){return r(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==i.RCRTCCode.SUCCESS)return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),void s.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===n.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.publish(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:r}}))}_leaveRoom(){return r(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this.ifCross=!1,s.info("[RCCallSession _leaveRoom] Successfully exited the room",e)}catch(e){s.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();l.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=c(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return r(this,void 0,void 0,(function*(){const t=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(n!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),t.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return r(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[_(e),u(t),R(i),h(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return r(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);l.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:r,tracks:n}=yield this._getLocalTrack(i,e);if(r!==o.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=n;const{code:a}=yield this._stateMachine.accept();return a!==o.RCCallErrorCode.SUCCESS?(s.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return r(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return r(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==o.RCCallErrorCode.SUCCESS&&s.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return r(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([t]);r===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(o.RCCallMediaType.AUDIO_VIDEO)):s.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return r(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(o.RCCallMediaType.AUDIO);return e===o.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return s.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:o.RCCallErrorCode.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:o.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:o.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:o.RCCallErrorCode.SUCCESS}):(s.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(t),this._options.localTracks=r,t.mute();const{code:n}=yield this._room.publish([t]);return n!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:o.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){s.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(t===i.RCKickReason.SERVER_KICK&&this._exceptionClose(o.RCCallEndReason.KICKED_BY_SERVER),t===i.RCKickReason.OTHER_KICK&&this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{s.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){s.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{s.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){s.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>r(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===o.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{s.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{s.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){s.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){s.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){s.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}t.VersionManage.add("plugin-call","5.1.0"),t.VersionManage.validEngine("^5.5.4")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '^5.5.4'.`);class g{constructor(e,i,r){this._context=e,this._runtime=i,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:t.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:o.RCCallLanguage.ZH},r),this._callEngine=new o.RCCallEngine(this._context,i,s,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.RCCallLanguage.ZH}),l.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){s.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),l.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();s.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),s.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;s.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){s.info("[RCCallClient _onInvite] Received invite message");const t=new f(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLEE});s.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){s.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw s.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=c(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){s.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),s.info("[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a="",extra:_="",pushTitle:p="",pushContent:g="",bitrate:m}){return r(this,void 0,void 0,(function*(){s.info(`[RCCallClient call] extra->${_} pushTitle->${p} pushContent->${g}`);const r=[C(e),d(t),c(i),u(_),R(p),h(g)],S=[];if(!r.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let T=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==o.RCCallErrorCode.SUCCESS)return{code:y};T=E,T.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(s=null==m?void 0:m.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:v,stateMachine:I}=yield this._callEngine.startCrossCall(a,e,t,_,p,g);if(v===o.RCCallErrorCode.SUCCESS&&I){s.info("[RCCallClient call] successfully created state machine");const e=new f(I,this._rtcClient,{localTracks:T,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${v}`),T.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a="",extra:_="",pushTitle:p="",pushContent:g="",bitrate:m}){return r(this,void 0,void 0,(function*(){s.info(`[RCCallClient call] extra->${_} pushTitle->${p} pushContent->${g}`);const r=[C(e),d(t),c(i),u(_),R(p),h(g)],S=[];if(!r.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let T=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==o.RCCallErrorCode.SUCCESS)return{code:y};T=E,T.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(s=null==m?void 0:m.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:v,stateMachine:I}=yield this._callEngine.call(a,e,t,_,p,g);if(v===o.RCCallErrorCode.SUCCESS&&I){s.info("[RCCallClient call] successfully created state machine");const e=new f(I,this._rtcClient,{localTracks:T,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${v}`),T.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}callInGroup({targetId:e,userIds:t,mediaType:i=o.RCCallMediaType.AUDIO,listener:l,constraints:a,channelId:p="",extra:g="",pushTitle:m="",pushContent:S="",bitrate:T}){return r(this,void 0,void 0,(function*(){const r=[C(e),_(t),d(i),c(l),u(g),R(m),h(S)],y=[];if(!r.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:v,tracks:I}=yield this._getLocalTrack(i,a);if(v!==o.RCCallErrorCode.SUCCESS)return{code:v};E=I,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==T?void 0:T.audio)&&e.setBitrate(null==T?void 0:T.audio),e.isVideoTrack()&&(null==T?void 0:T.video)&&e.setBitrate(null===(o=null==T?void 0:T.video)||void 0===o?void 0:o.max,null===(t=null==T?void 0:T.video)||void 0===t?void 0:t.min,null===(i=null==T?void 0:T.video)||void 0===i?void 0:i.start),l.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.callInGroup(p,e,i,t,g,m,S);if(b===o.RCCallErrorCode.SUCCESS&&O){s.info("[RCCallClient callInGroup] successfully created state machine");const e=new f(O,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),s.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return s.info(`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return r(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==t.ErrorCode.SUCCESS?(s.error("getJoinedUserInfo error",e),{code:o.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:o.RCCallErrorCode.SUCCESS,data:i}}))}}const m={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=a(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return s.setLogLevel(t.logLevel),s.setLogStdout(t.logStdout),s.warn("RCCall Version: 5.1.0, Commit: b538264c6c82a359de6d52c45df2e0dd8dbc055e"),new g(e,o,t)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return o.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return o.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return o.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return o.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return o.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return o.RCCallUserState}}),e.RCCallClient=g,e.RCCallSession=f,e.installer=m,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */function r(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var n;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(n||(n={}));var l=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const a=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(t.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(o.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(t.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},c=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},C=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},d=e=>e===o.RCCallMediaType.AUDIO||e===o.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class p{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class g{constructor(e,t,i={}){this._stateMachine=e,this._rtcClient=t,this._options=i,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{s.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>r(this,void 0,void 0,(function*(){const{state:t,reason:i}=e;if(s.info(`[RCCallSession onStateChange] : state->${t} reason->${i}`),t===o.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();s.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void l.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),s.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{s.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){s.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{s.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){s.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{s.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){s.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{s.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){s.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{s.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===o.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){s.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{s.info(`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}})}_joinRoom(e){return r(this,void 0,void 0,(function*(){let t;try{t=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:r,userIds:n,room:l}=t;if(r!==i.RCRTCCode.SUCCESS)return r===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(o.RCCallEndReason.SERVICE_NOT_OPENED),r===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${r}`),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR};n.length<1&&(this.joinRoomTimer=new p((()=>{this._exceptionClose(o.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=l}catch(t){return this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),s.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return r(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.subscribe(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:r}}))}_publish(){return r(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==i.RCRTCCode.SUCCESS)return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),void s.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===n.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.publish(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:r}}))}_leaveRoom(){return r(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);s.info("[RCCallSession _leaveRoom] Successfully exited the room",e)}catch(e){s.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();l.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=c(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return r(this,void 0,void 0,(function*(){const t=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(n!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),t.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return r(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[_(e),u(t),R(i),h(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return r(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);l.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:r,tracks:n}=yield this._getLocalTrack(i,e);if(r!==o.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=n;const{code:a}=yield this._stateMachine.accept();return a!==o.RCCallErrorCode.SUCCESS?(s.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return r(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return r(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==o.RCCallErrorCode.SUCCESS&&s.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return r(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([t]);r===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(o.RCCallMediaType.AUDIO_VIDEO)):s.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return r(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(o.RCCallMediaType.AUDIO);return e===o.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return s.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:o.RCCallErrorCode.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:o.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:o.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:o.RCCallErrorCode.SUCCESS}):(s.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(t),this._options.localTracks=r,t.mute();const{code:n}=yield this._room.publish([t]);return n!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:o.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return r(this,void 0,void 0,(function*(){if(!this._room)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:o.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return s.error(`[RCCallSession disableAudioTrack] Room missing audio track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){s.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(t===i.RCKickReason.SERVER_KICK&&this._exceptionClose(o.RCCallEndReason.KICKED_BY_SERVER),t===i.RCKickReason.OTHER_KICK&&this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{s.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){s.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{s.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){s.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>r(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===o.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{s.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{s.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){s.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){s.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){s.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}t.VersionManage.add("plugin-call","5.1.1"),t.VersionManage.validEngine("^5.5.4")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '^5.5.4'.`);class f{constructor(e,i,r){this._context=e,this._runtime=i,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:t.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:o.RCCallLanguage.ZH},r),this._callEngine=new o.RCCallEngine(this._context,i,s,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.RCCallLanguage.ZH}),l.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){s.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),l.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();s.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),s.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;s.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){s.info("[RCCallClient _onInvite] Received invite message");const t=new g(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLEE});s.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){s.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw s.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=c(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){s.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),s.info("[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:s,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return r(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:t,listener:i,constraints:s,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C,isCrossAppkey:!0})}))}call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:s,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return r(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:t,listener:i,constraints:s,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C})}))}__call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a="",extra:_="",pushTitle:p="",pushContent:f="",bitrate:m,isCrossAppkey:S=!1}){return r(this,void 0,void 0,(function*(){s.info(`[RCCallClient call] extra->${_} pushTitle->${p} pushContent->${f}`);const r=[C(e),d(t),c(i),u(_),R(p),h(f)],T=[];if(!r.every((e=>(!e.result&&T.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${T.join("\n")}`);let y=[];const{code:E,tracks:I}=yield this._getLocalTrack(t,l);if(E!==o.RCCallErrorCode.SUCCESS)return{code:E};y=I,y.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(s=null==m?void 0:m.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:b,stateMachine:v}=yield this._callEngine.call(a,e,t,_,p,f,S);if(b===o.RCCallErrorCode.SUCCESS&&v){s.info("[RCCallClient call] successfully created state machine");const e=new g(v,this._rtcClient,{localTracks:y,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER,isCrossAppkey:S});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${b}`),y.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}callInGroup({targetId:e,userIds:t,mediaType:i=o.RCCallMediaType.AUDIO,listener:l,constraints:a,channelId:p="",extra:f="",pushTitle:m="",pushContent:S="",bitrate:T}){return r(this,void 0,void 0,(function*(){const r=[C(e),_(t),d(i),c(l),u(f),R(m),h(S)],y=[];if(!r.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:I,tracks:b}=yield this._getLocalTrack(i,a);if(I!==o.RCCallErrorCode.SUCCESS)return{code:I};E=b,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==T?void 0:T.audio)&&e.setBitrate(null==T?void 0:T.audio),e.isVideoTrack()&&(null==T?void 0:T.video)&&e.setBitrate(null===(o=null==T?void 0:T.video)||void 0===o?void 0:o.max,null===(t=null==T?void 0:T.video)||void 0===t?void 0:t.min,null===(i=null==T?void 0:T.video)||void 0===i?void 0:i.start),l.onTrackReady(e)}));const{code:v,stateMachine:O}=yield this._callEngine.callInGroup(p,e,i,t,f,m,S);if(v===o.RCCallErrorCode.SUCCESS&&O){s.info("[RCCallClient callInGroup] successfully created state machine");const e=new g(O,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),s.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return s.info(`[RCCallClient callInGroup] callInGroup failed code -> ${v}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return r(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==t.ErrorCode.SUCCESS?(s.error("getJoinedUserInfo error",e),{code:o.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:o.RCCallErrorCode.SUCCESS,data:i}}))}}const m={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=a(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return s.setLogLevel(t.logLevel),s.setLogStdout(t.logStdout),s.warn("RCCall Version: 5.1.1, Commit: ba3fba8044d94f2fb2d74a189c4ecc3adbad8e46"),new f(e,o,t)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return o.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return o.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return o.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return o.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return o.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return o.RCCallUserState}}),e.RCCallClient=f,e.RCCallSession=g,e.installer=m,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/dist/interface.d.ts
CHANGED
|
@@ -174,6 +174,7 @@ export interface IRCCallSessionOptions {
|
|
|
174
174
|
* 产生session的场景,是主叫产生 或 被叫产生
|
|
175
175
|
*/
|
|
176
176
|
produceType?: ProduceTypes;
|
|
177
|
+
isCrossAppkey?: boolean;
|
|
177
178
|
}
|
|
178
179
|
export interface IRCTrackBitrate {
|
|
179
180
|
/**
|
|
@@ -232,6 +233,10 @@ export interface IRCCallParams {
|
|
|
232
233
|
video?: IRCTrackBitrate;
|
|
233
234
|
audio?: number;
|
|
234
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* 是否为跨 appkey 通话
|
|
238
|
+
*/
|
|
239
|
+
isCrossAppkey?: boolean;
|
|
235
240
|
}
|
|
236
241
|
export interface IMediaStreamConstraints {
|
|
237
242
|
video?: ICameraVideoProfile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rongcloud/plugin-call",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "@rongcloud/plugin-call",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"__attrs__": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@rongcloud/plugin-rtc": "^5.5.1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@rongcloud/plugin-call-engine": "^5.0.
|
|
39
|
+
"@rongcloud/plugin-call-engine": "^5.0.10"
|
|
40
40
|
},
|
|
41
|
-
"__commit__": "
|
|
41
|
+
"__commit__": "ba3fba8044d94f2fb2d74a189c4ecc3adbad8e46"
|
|
42
42
|
}
|