diff --git a/packages/rtc/src/base/DefaultValue.ts b/packages/rtc/src/base/DefaultValue.ts new file mode 100644 index 0000000..ea0d91e --- /dev/null +++ b/packages/rtc/src/base/DefaultValue.ts @@ -0,0 +1,7 @@ +import * as NATIVE_RTC from '@iris/native-rtc'; + +export const defaultLeaveChannelOptions: NATIVE_RTC.LeaveChannelOptions = { + stopAudioMixing: true, + stopAllEffect: true, + stopMicrophoneRecording: true, +}; diff --git a/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts b/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts index 9a6c651..6685335 100644 --- a/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts +++ b/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts @@ -57,10 +57,19 @@ export class IRtcEngineExDispatch extends IRtcEngineDispatch // @ts-ignore leaveChannelEx_b03ee9a(apiParam: ApiParam): CallApiReturnType { - AgoraConsole.warn( - 'RtcEngineEx_leaveChannelEx_b03ee9a not supported in this platform!' - ); - return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); + let obj = JSON.parse(apiParam.data) as any; + let connection = obj.connection; + if (connection === undefined) { + AgoraConsole.error('connection is undefined'); + throw 'connection is undefined'; + } + let options = obj.options; + if (options === undefined) { + AgoraConsole.error('options is undefined'); + throw 'options is undefined'; + } + + return this._impl.leaveChannelEx_b03ee9a(connection, options); } // @ts-ignore diff --git a/packages/rtc/src/engine/IrisRtcEngine.ts b/packages/rtc/src/engine/IrisRtcEngine.ts index f58fadb..94c3cdd 100644 --- a/packages/rtc/src/engine/IrisRtcEngine.ts +++ b/packages/rtc/src/engine/IrisRtcEngine.ts @@ -181,6 +181,10 @@ export class IrisRtcEngine implements ApiInterceptor { } } + public getImplInstance(className: string): any { + return this.implDispatchesMap.get(className)?._impl; + } + public getVideoFrame(uid: number, channel_id: string): VideoParams { return this.irisClientManager.getVideoFrame(uid, channel_id); } diff --git a/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts b/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts index eedb183..39f7fb5 100644 --- a/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts +++ b/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts @@ -1,8 +1,10 @@ import * as NATIVE_RTC from '@iris/native-rtc'; +import { IMicrophoneAudioTrack } from 'agora-rtc-sdk-ng'; import { CallApiReturnType, CallIrisApiResult } from 'iris-web-core'; import { IrisAudioSourceType } from '../base/BaseType'; +import { defaultLeaveChannelOptions } from '../base/DefaultValue'; import { IrisClient } from '../engine/IrisClient'; import { RemoteUserPackage } from '../engine/IrisClientManager'; @@ -69,6 +71,17 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx { } leaveChannelEx_c81e1a4( connection: NATIVE_RTC.RtcConnection + ): CallApiReturnType { + let processFunc = async (): Promise => { + this.leaveChannelEx_b03ee9a(connection, defaultLeaveChannelOptions); + return this._engine.returnResult(); + }; + return this._engine.execute(processFunc); + } + + leaveChannelEx_b03ee9a( + connection: NATIVE_RTC.RtcConnection, + options: NATIVE_RTC.LeaveChannelOptions ): CallApiReturnType { let processFunc = async (): Promise => { if (this._engine.irisClientManager.irisClientList.length === 0) { @@ -89,6 +102,21 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx { let agoraRTCClient = irisClient?.agoraRTCClient; if (agoraRTCClient) { + //读取 options + for (let trackPackage of irisClient.audioTrackPackages) { + if (trackPackage.track) { + let track = trackPackage.track as IMicrophoneAudioTrack; + if (options.stopMicrophoneRecording) { + await this._engine.trackHelper.setMuted(track, true); + } + } + } + if (options.stopAllEffect) { + this._engine.getImplInstance('RtcEngine').stopAllEffects(); + } + if (options.stopAudioMixing) { + //todo audio Mixing + } try { await this._engine.clientHelper.leave(agoraRTCClient); } catch (e) { @@ -105,11 +133,11 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx { ); irisClient.release(); } - return this._engine.returnResult(); }; return this._engine.execute(processFunc); } + updateChannelMediaOptionsEx_457bb35( options: NATIVE_RTC.ChannelMediaOptions, connection: NATIVE_RTC.RtcConnection diff --git a/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts b/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts index 43cb9c6..cdeef24 100644 --- a/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts +++ b/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts @@ -13,6 +13,7 @@ import { } from 'iris-web-core'; import { IrisAudioSourceType } from '../base/BaseType'; +import { defaultLeaveChannelOptions } from '../base/DefaultValue'; import { IrisClient } from '../engine/IrisClient'; import { BufferSourceAudioTrackPackage, @@ -135,19 +136,12 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { return this._engine.execute(processFunc); } leaveChannel(): CallApiReturnType { - let options: NATIVE_RTC.LeaveChannelOptions = { - stopAudioMixing: true, - stopAllEffect: true, - stopMicrophoneRecording: true, - }; - return this.leaveChannel_2c0e3aa(options); + return this.leaveChannel_2c0e3aa(defaultLeaveChannelOptions); } leaveChannel_2c0e3aa( options: NATIVE_RTC.LeaveChannelOptions ): CallApiReturnType { let processFunc: AsyncTaskType = async (): Promise => { - //离开频道后重置参数 - // this._engine.globalState.reset(); if (this._engine.irisClientManager.irisClientList.length === 0) { return this._engine.returnResult(); } @@ -161,9 +155,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { ); for (let irisClient of this._engine.irisClientManager.irisClientList) { - irisClient.irisClientState.mergeChannelMediaOptions(options); let agoraRTCClient = irisClient.agoraRTCClient; - options = irisClient.irisClientState; if (agoraRTCClient) { //读取 options @@ -173,15 +165,15 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { if (options.stopMicrophoneRecording) { await this._engine.trackHelper.setMuted(track, true); } - if (options.stopAllEffect) { - this.stopAllEffects(); - //todo effect - } - if (options.stopAudioMixing) { - //todo audio Mixing - } } } + if (options.stopAllEffect) { + this.stopAllEffects(); + //todo effect + } + if (options.stopAudioMixing) { + //todo audio Mixing + } //为了防止离开频道后丢失了channelName和uid,所以需要先保存一下 let con: NATIVE_RTC.RtcConnection = { diff --git a/packages/rtc/src/state/IrisClientState.ts b/packages/rtc/src/state/IrisClientState.ts index 518c94d..e4a1af5 100644 --- a/packages/rtc/src/state/IrisClientState.ts +++ b/packages/rtc/src/state/IrisClientState.ts @@ -6,11 +6,6 @@ import { IrisGlobalState } from './IrisGlobalState'; export class IrisClientState { _globalState: IrisGlobalState; - //LeaveChannelOptions - stopAudioMixing?: boolean = true; - stopAllEffect?: boolean = true; - stopMicrophoneRecording?: boolean = true; - //ChannelMediaOptions publishCameraTrack?: boolean = true; @@ -164,9 +159,7 @@ export class IrisClientState { } } - mergeChannelMediaOptions( - options: NATIVE_RTC.ChannelMediaOptions | NATIVE_RTC.LeaveChannelOptions - ) { + mergeChannelMediaOptions(options: NATIVE_RTC.ChannelMediaOptions) { for (let key in options) { this[key] = options[key]; } diff --git a/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts b/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts index 71337c7..0327430 100644 --- a/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts +++ b/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts @@ -188,9 +188,55 @@ describe('IRtcEngineEx', () => { ).toBeCalledWith('test'); }); + test('RtcEngineEx_leaveChannelEx_b03ee9a parameter', async () => { + let nParam = { + connection: undefined, + options: undefined, + }; + try { + await IrisCore.callIrisApi( + apiEnginePtr, + new IrisCore.EventParam( + 'RtcEngineEx_leaveChannelEx_b03ee9a', + JSON.stringify(nParam), + 0, + '', + ['test'], + [], + 1 + ) + ); + } catch (e) { + expect(e).toEqual('connection is undefined'); + } + //@ts-ignore + nParam.connection = 'test'; + try { + await IrisCore.callIrisApi( + apiEnginePtr, + new IrisCore.EventParam( + 'RtcEngineEx_leaveChannelEx_b03ee9a', + JSON.stringify(nParam), + 0, + '', + ['test'], + [], + 1 + ) + ); + } catch (e) { + expect(e).toEqual('options is undefined'); + } + //@ts-ignore + nParam.options = 'test'; + }); + test('RtcEngineEx_leaveChannelEx_b03ee9a impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('RtcEngineEx')._impl, + 'leaveChannelEx_b03ee9a' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = { connection: 'test', @@ -208,13 +254,12 @@ describe('IRtcEngineEx', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('RtcEngineEx')._impl - ?.leaveChannelEx_b03ee9a - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .leaveChannelEx_b03ee9a + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('RtcEngineEx')._impl + .leaveChannelEx_b03ee9a + ).toBeCalledWith('test', 'test'); }); test('RtcEngineEx_updateChannelMediaOptionsEx_457bb35 parameter', async () => { diff --git a/packages/rtc/test/impl/IAgoraRtcEngineImplEx.test.ts b/packages/rtc/test/impl/IAgoraRtcEngineImplEx.test.ts index 4eaa673..bcb5bed 100644 --- a/packages/rtc/test/impl/IAgoraRtcEngineImplEx.test.ts +++ b/packages/rtc/test/impl/IAgoraRtcEngineImplEx.test.ts @@ -9,6 +9,7 @@ import { IrisApiEngine, IrisCore } from 'iris-web-core'; import { IrisWebRtc } from '../../src/IrisRtcApi'; import { IrisAudioSourceType } from '../../src/base/BaseType'; +import { defaultLeaveChannelOptions } from '../../src/base/DefaultValue'; import { IrisRtcEngine } from '../engine/IrisRtcEngine'; @@ -88,6 +89,20 @@ describe('IAgoraRtcEngineImpl', () => { ).toBeCalledTimes(1); }); test('leaveChannelEx_c81e1a4', async () => { + await callIris(apiEnginePtr, 'RtcEngine_enableVideo', null); + let connection = await joinChannelEx(apiEnginePtr); + jest.spyOn(rtcEngineExImpl, 'leaveChannelEx_b03ee9a'); + let leaveParam = { + connection: connection, + }; + await callIris( + apiEnginePtr, + 'RtcEngineEx_leaveChannelEx_c81e1a4', + leaveParam + ); + expect(rtcEngineExImpl.leaveChannelEx_b03ee9a).toBeCalled(); + }); + test('leaveChannelEx_b03ee9a', async () => { let param = { token: '1234', connection: { @@ -107,13 +122,15 @@ describe('IAgoraRtcEngineImpl', () => { jest.spyOn(irisClient.agoraRTCClient!, 'leave'); let leaveParam = { connection: param.connection, + options: defaultLeaveChannelOptions, }; await callIris( apiEnginePtr, - 'RtcEngineEx_leaveChannelEx_c81e1a4', + 'RtcEngineEx_leaveChannelEx_b03ee9a', leaveParam ); expect(irisClient.agoraRTCClient).toBeUndefined(); + expect(irisRtcEngine.irisClientManager.remoteUserPackages.length).toBe(0); expect(irisClient.videoTrackPackage).toBeUndefined(); expect(irisClient.audioTrackPackages.length).toBe(0); }); @@ -169,12 +186,16 @@ describe('IAgoraRtcEngineImpl', () => { clientRoleType: NATIVE_RTC.CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER, }, }; - await callIris(apiEnginePtr, 'RtcEngineEx_joinChannelEx_a3cd08c', param); + let connection = await callIris( + apiEnginePtr, + 'RtcEngineEx_joinChannelEx_a3cd08c', + param + ); let param2 = { canvas: { uid: TEST_REMOTE_UID, view: 'test-view', - sourceType: NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_PRIMARY, + sourceType: NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_REMOTE, }, connection: param.connection, }; diff --git a/scripts/terra/config/support_list.json b/scripts/terra/config/support_list.json index 73af639..e9c2366 100644 --- a/scripts/terra/config/support_list.json +++ b/scripts/terra/config/support_list.json @@ -55,6 +55,7 @@ "RtcEngineEx_muteLocalAudioStreamEx_3cf17a4", "RtcEngineEx_muteRemoteVideoStreamEx_6d93082", "RtcEngineEx_muteRemoteAudioStreamEx_6d93082", + "RtcEngineEx_leaveChannelEx_b03ee9a", "RtcEngineEx_leaveChannelEx_c81e1a4", "RtcEngineEx_updateChannelMediaOptionsEx_457bb35", "RtcEngineEx_setupRemoteVideoEx_522a409",