diff --git a/packages/fake/rtc/package.json b/packages/fake/rtc/package.json index 1c75e4f..c8cacc1 100644 --- a/packages/fake/rtc/package.json +++ b/packages/fake/rtc/package.json @@ -14,7 +14,7 @@ "dependencies": { "@iris/native-rtc": "workspace: *", "agora-rtc-sdk-ng": "4.21.0", - "@agoraio-extensions/agora-rtc-sdk-ng-fake": "^1.0.12", + "@agoraio-extensions/agora-rtc-sdk-ng-fake": "^1.0.13", "iris-web-rtc": "workspace: *" }, "devDependencies": { diff --git a/packages/rtc/package.json b/packages/rtc/package.json index fef9079..7536bda 100644 --- a/packages/rtc/package.json +++ b/packages/rtc/package.json @@ -17,7 +17,7 @@ "author": "AgoraIO-Extensions", "license": "MIT", "dependencies": { - "@agoraio-extensions/agora-rtc-sdk-ng-fake": "^1.0.12", + "@agoraio-extensions/agora-rtc-sdk-ng-fake": "^1.0.13", "@iris/native-rtc": "workspace: *", "agora-rtc-sdk-ng": "4.21.0", "iris-web-core": "workspace: *" diff --git a/packages/rtc/src/binding/IAgoraRtcEngineDispatch.ts b/packages/rtc/src/binding/IAgoraRtcEngineDispatch.ts index 1dfdd03..bb85b25 100644 --- a/packages/rtc/src/binding/IAgoraRtcEngineDispatch.ts +++ b/packages/rtc/src/binding/IAgoraRtcEngineDispatch.ts @@ -71,10 +71,8 @@ import { ApiParam, CallApiReturnType, IrisCore } from 'iris-web-core'; import { IrisRtcEngine } from '../engine/IrisRtcEngine'; import { callApiBufferExtension } from '../extensions/CallApiBufferExtensions'; import { eventHandlerBufferExtension } from '../extensions/EventhandlerBufferExtensions'; -import { - IRtcEngineImpl, - IVideoDeviceManagerImpl, -} from '../impl/IAgoraRtcEngineImpl'; +import { IRtcEngineImpl } from '../impl/IAgoraRtcEngineImpl'; +import { IVideoDeviceManagerImpl } from '../impl/IVideoDeviceManagerImpl'; import { AgoraConsole } from '../util/AgoraConsole'; export class IRtcEngineEventHandler { @@ -4437,7 +4435,7 @@ export class IRtcEngineDispatch implements IRtcEngine { } let userInfo = obj.userInfo; - return this._impl.getUserInfoByUserAccount_c6a8f08(userAccount, userInfo); + return this._impl.getUserInfoByUserAccount_c6a8f08(userAccount); } // @ts-ignore @@ -4450,7 +4448,7 @@ export class IRtcEngineDispatch implements IRtcEngine { } let userInfo = obj.userInfo; - return this._impl.getUserInfoByUid_6b7aee8(uid, userInfo); + return this._impl.getUserInfoByUid_6b7aee8(uid); } // @ts-ignore diff --git a/packages/rtc/src/binding/IAudioDeviceManagerDispatch.ts b/packages/rtc/src/binding/IAudioDeviceManagerDispatch.ts index c13cc66..594a24e 100644 --- a/packages/rtc/src/binding/IAudioDeviceManagerDispatch.ts +++ b/packages/rtc/src/binding/IAudioDeviceManagerDispatch.ts @@ -4,44 +4,46 @@ import { ERROR_CODE_TYPE, IAudioDeviceManager } from '@iris/native-rtc'; import { ApiParam, CallApiReturnType } from 'iris-web-core'; import { IrisRtcEngine } from '../engine/IrisRtcEngine'; +import { IAudioDeviceManagerImpl } from '../impl/IAudioDeviceManagerImpl'; import { AgoraConsole } from '../util/AgoraConsole'; export class IAudioDeviceManagerDispatch implements IAudioDeviceManager { + // @ts-ignore + _impl: IAudioDeviceManagerImpl; _engine: IrisRtcEngine; constructor(engine: IrisRtcEngine) { + this._impl = new IAudioDeviceManagerImpl(engine); this._engine = engine; } // @ts-ignore enumeratePlaybackDevices(): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_enumeratePlaybackDevices not supported in this platform!' - ); - return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); + return this._impl.enumeratePlaybackDevices(); } // @ts-ignore enumerateRecordingDevices(): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_enumerateRecordingDevices not supported in this platform!' - ); - return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); + return this._impl.enumerateRecordingDevices(); } // @ts-ignore setPlaybackDevice_4ad5f6e(apiParam: ApiParam): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_setPlaybackDevice_4ad5f6e 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 deviceId = obj.deviceId; + if (deviceId === undefined) { + AgoraConsole.error('deviceId is undefined'); + throw 'deviceId is undefined'; + } + + return this._impl.setPlaybackDevice_4ad5f6e(deviceId); } // @ts-ignore getPlaybackDevice_73b9872(apiParam: ApiParam): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_getPlaybackDevice_73b9872 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 deviceId = obj.deviceId; + + return this._impl.getPlaybackDevice_73b9872(); } // @ts-ignore @@ -70,18 +72,22 @@ export class IAudioDeviceManagerDispatch implements IAudioDeviceManager { // @ts-ignore setRecordingDevice_4ad5f6e(apiParam: ApiParam): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_setRecordingDevice_4ad5f6e 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 deviceId = obj.deviceId; + if (deviceId === undefined) { + AgoraConsole.error('deviceId is undefined'); + throw 'deviceId is undefined'; + } + + return this._impl.setRecordingDevice_4ad5f6e(deviceId); } // @ts-ignore getRecordingDevice_73b9872(apiParam: ApiParam): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_getRecordingDevice_73b9872 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 deviceId = obj.deviceId; + + return this._impl.getRecordingDevice_73b9872(); } // @ts-ignore @@ -230,9 +236,6 @@ export class IAudioDeviceManagerDispatch implements IAudioDeviceManager { // @ts-ignore release(): CallApiReturnType { - AgoraConsole.warn( - 'AudioDeviceManager_release not supported in this platform!' - ); - return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); + return this._impl.release(); } } diff --git a/packages/rtc/src/helper/TrackHelper.ts b/packages/rtc/src/helper/TrackHelper.ts index 88e7ca9..62adbfe 100644 --- a/packages/rtc/src/helper/TrackHelper.ts +++ b/packages/rtc/src/helper/TrackHelper.ts @@ -1,7 +1,9 @@ import * as NATIVE_RTC from '@iris/native-rtc'; import { ICameraVideoTrack, + ILocalAudioTrack, ILocalTrack, + IMicrophoneAudioTrack, IRemoteAudioTrack, ITrack, } from 'agora-rtc-sdk-ng'; @@ -69,7 +71,7 @@ export class TrackHelper { } } public async setDevice( - track: ICameraVideoTrack, + track: ICameraVideoTrack | IMicrophoneAudioTrack, deviceId: string ): Promise { try { @@ -82,4 +84,18 @@ export class TrackHelper { throw e; } } + public async setPlaybackDevice( + track: ILocalAudioTrack | IRemoteAudioTrack, + deviceId: string + ): Promise { + try { + await track?.setPlaybackDevice(deviceId); + } catch (e) { + AgoraConsole.error(e); + Promise.resolve( + new CallIrisApiResult(-NATIVE_RTC.ERROR_CODE_TYPE.ERR_FAILED, e) + ); + throw e; + } + } } diff --git a/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts b/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts index ca42d29..467585d 100644 --- a/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts +++ b/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts @@ -1111,10 +1111,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { return this._engine.execute(processJoinChannel); } - getUserInfoByUserAccount_c6a8f08( - userAccount: string, - userInfo: NATIVE_RTC.UserInfo - ): CallApiReturnType { + getUserInfoByUserAccount_c6a8f08(userAccount: string): CallApiReturnType { let user = this._engine.irisClientManager.getUserInfoByUserAccount( userAccount ); @@ -1128,10 +1125,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { ); } - getUserInfoByUid_6b7aee8( - uid: number, - userInfo: NATIVE_RTC.UserInfo - ): CallApiReturnType { + getUserInfoByUid_6b7aee8(uid: number): CallApiReturnType { let user = this._engine.irisClientManager.getUserInfoByUid(uid); return this._engine.returnResult( true, @@ -1143,98 +1137,3 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { ); } } - -//@ts-ignore -export class IVideoDeviceManagerImpl implements NATIVE_RTC.IVideoDeviceManager { - private _engine: IrisRtcEngine; - - public constructor(engine: IrisRtcEngine) { - this._engine = engine; - } - - enumerateVideoDevices(): CallApiReturnType { - let deviceList: MediaDeviceInfo[] = []; - let process = async () => { - try { - deviceList = (await this._engine.implHelper.enumerateDevices()) - ?.videoDevices; - } catch (e) { - AgoraConsole.log(e); - return this._engine.returnResult(false); - } - return this._engine.returnResult( - true, - 0, - JSON.stringify({ result: deviceList }) - ); - }; - return this._engine.execute(process); - } - setDevice_4ad5f6e(deviceIdUTF8: string): CallApiReturnType { - let process = async () => { - this._engine.globalState.videoDeviceId = deviceIdUTF8; - - for (let videoTrackPackage of this._engine.irisClientManager - .localVideoTrackPackages) { - if (videoTrackPackage.track) { - if ( - videoTrackPackage.type == - NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_PRIMARY || - videoTrackPackage.type == - NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_SECONDARY || - videoTrackPackage.type == - NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_THIRD || - videoTrackPackage.type == - NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_FOURTH - ) { - await this._engine.trackHelper.setDevice( - videoTrackPackage.track as ICameraVideoTrack, - deviceIdUTF8 - ); - } - } - } - - return this._engine.returnResult(); - }; - return this._engine.execute(process); - } - getDevice_73b9872(): CallApiReturnType { - let process = async () => { - let list: MediaDeviceInfo[] = []; - let deviceId = ''; - if (this._engine.globalState.videoDeviceId) { - deviceId = this._engine.globalState.videoDeviceId; - } else { - try { - list = await this._engine.globalState.AgoraRTC.getCameras(); - } catch (e) { - return this._engine.returnResult(false); - } - if (list && list.length > 0) { - deviceId = list[0].deviceId; - } - } - return this._engine.returnResult( - true, - 0, - JSON.stringify({ - result: NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK, - deviceIdUTF8: deviceId, - }) - ); - }; - return this._engine.execute(process); - } - - release(): CallApiReturnType { - let process = async () => { - let engine = this._engine; - engine.globalState.playbackDevices = new Array(); - engine.globalState.recordingDevices = new Array(); - engine.globalState.videoDevices = new Array(); - return this._engine.returnResult(); - }; - return this._engine.execute(process); - } -} diff --git a/packages/rtc/src/impl/IAudioDeviceManagerImpl.ts b/packages/rtc/src/impl/IAudioDeviceManagerImpl.ts new file mode 100644 index 0000000..b5617fb --- /dev/null +++ b/packages/rtc/src/impl/IAudioDeviceManagerImpl.ts @@ -0,0 +1,179 @@ +import * as NATIVE_RTC from '@iris/native-rtc'; +import { + ILocalAudioTrack, + IMicrophoneAudioTrack, + IRemoteAudioTrack, +} from 'agora-rtc-sdk-ng'; +import { CallApiReturnType } from 'iris-web-core'; + +import { IrisAudioSourceType } from '../base/BaseType'; + +import { IrisRtcEngine } from '../engine/IrisRtcEngine'; +import { AgoraConsole } from '../util'; + +//@ts-ignore +export class IAudioDeviceManagerImpl implements NATIVE_RTC.IAudioDeviceManager { + private _engine: IrisRtcEngine; + + public constructor(engine: IrisRtcEngine) { + this._engine = engine; + } + + enumeratePlaybackDevices(): CallApiReturnType { + let deviceList: MediaDeviceInfo[] = []; + let process = async () => { + try { + deviceList = (await this._engine.implHelper.enumerateDevices()) + ?.playbackDevices; + } catch (e) { + AgoraConsole.log(e); + return this._engine.returnResult(false); + } + return this._engine.returnResult( + true, + 0, + JSON.stringify({ result: deviceList }) + ); + }; + return this._engine.execute(process); + } + + enumerateRecordingDevices(): CallApiReturnType { + let deviceList: MediaDeviceInfo[] = []; + let process = async () => { + try { + deviceList = (await this._engine.implHelper.enumerateDevices()) + ?.recordingDevices; + } catch (e) { + AgoraConsole.log(e); + return this._engine.returnResult(false); + } + return this._engine.returnResult( + true, + 0, + JSON.stringify({ result: deviceList }) + ); + }; + return this._engine.execute(process); + } + + setPlaybackDevice_4ad5f6e(deviceId: string): CallApiReturnType { + let process = async () => { + this._engine.globalState.playbackDeviceId = deviceId; + + for (let audioTrackPackage of this._engine.irisClientManager + .localAudioTrackPackages) { + if (audioTrackPackage.track) { + if ( + audioTrackPackage.type == + IrisAudioSourceType.kAudioSourceTypeRemote || + audioTrackPackage.type == + IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary || + audioTrackPackage.type == + IrisAudioSourceType.kAudioSourceTypeMicrophoneSecondary + ) { + await this._engine.trackHelper.setPlaybackDevice( + audioTrackPackage.track as ILocalAudioTrack | IRemoteAudioTrack, + deviceId + ); + } + } + } + + return this._engine.returnResult(); + }; + return this._engine.execute(process); + } + + getPlaybackDevice_73b9872(): CallApiReturnType { + let process = async () => { + let list: MediaDeviceInfo[] = []; + let deviceId = ''; + if (this._engine.globalState.playbackDeviceId) { + deviceId = this._engine.globalState.playbackDeviceId; + } else { + try { + list = await this._engine.globalState.AgoraRTC.getPlaybackDevices(); + } catch (e) { + return this._engine.returnResult(false); + } + if (list && list.length > 0) { + deviceId = list[0].deviceId; + } + } + return this._engine.returnResult( + true, + 0, + JSON.stringify({ + result: NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK, + deviceId, + }) + ); + }; + return this._engine.execute(process); + } + + setRecordingDevice_4ad5f6e(deviceId: string): CallApiReturnType { + let process = async () => { + this._engine.globalState.recordingDeviceId = deviceId; + + for (let audioTrackPackage of this._engine.irisClientManager + .localAudioTrackPackages) { + if (audioTrackPackage.track) { + if ( + audioTrackPackage.type == + IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary || + audioTrackPackage.type == + IrisAudioSourceType.kAudioSourceTypeMicrophoneSecondary + ) { + await this._engine.trackHelper.setDevice( + audioTrackPackage.track as IMicrophoneAudioTrack, + deviceId + ); + } + } + } + + return this._engine.returnResult(); + }; + return this._engine.execute(process); + } + + getRecordingDevice_73b9872(): CallApiReturnType { + let process = async () => { + let list: MediaDeviceInfo[] = []; + let deviceId = ''; + if (this._engine.globalState.recordingDeviceId) { + deviceId = this._engine.globalState.recordingDeviceId; + } else { + try { + list = await this._engine.globalState.AgoraRTC.getMicrophones(); + } catch (e) { + return this._engine.returnResult(false); + } + if (list && list.length > 0) { + deviceId = list[0].deviceId; + } + } + return this._engine.returnResult( + true, + 0, + JSON.stringify({ + result: NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK, + deviceId, + }) + ); + }; + return this._engine.execute(process); + } + + release(): CallApiReturnType { + let process = async () => { + let engine = this._engine; + engine.globalState.playbackDevices = new Array(); + engine.globalState.recordingDevices = new Array(); + return this._engine.returnResult(); + }; + return this._engine.execute(process); + } +} diff --git a/packages/rtc/src/impl/IVideoDeviceManagerImpl.ts b/packages/rtc/src/impl/IVideoDeviceManagerImpl.ts new file mode 100644 index 0000000..a90a045 --- /dev/null +++ b/packages/rtc/src/impl/IVideoDeviceManagerImpl.ts @@ -0,0 +1,99 @@ +import * as NATIVE_RTC from '@iris/native-rtc'; +import { ICameraVideoTrack } from 'agora-rtc-sdk-ng'; +import { CallApiReturnType } from 'iris-web-core'; + +import { IrisRtcEngine } from '../engine/IrisRtcEngine'; +import { AgoraConsole } from '../util'; + +//@ts-ignore +export class IVideoDeviceManagerImpl implements NATIVE_RTC.IVideoDeviceManager { + private _engine: IrisRtcEngine; + + public constructor(engine: IrisRtcEngine) { + this._engine = engine; + } + + enumerateVideoDevices(): CallApiReturnType { + let deviceList: MediaDeviceInfo[] = []; + let process = async () => { + try { + deviceList = (await this._engine.implHelper.enumerateDevices()) + ?.videoDevices; + } catch (e) { + AgoraConsole.log(e); + return this._engine.returnResult(false); + } + return this._engine.returnResult( + true, + 0, + JSON.stringify({ result: deviceList }) + ); + }; + return this._engine.execute(process); + } + setDevice_4ad5f6e(deviceIdUTF8: string): CallApiReturnType { + let process = async () => { + this._engine.globalState.videoDeviceId = deviceIdUTF8; + + for (let videoTrackPackage of this._engine.irisClientManager + .localVideoTrackPackages) { + if (videoTrackPackage.track) { + if ( + videoTrackPackage.type == + NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_PRIMARY || + videoTrackPackage.type == + NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_SECONDARY || + videoTrackPackage.type == + NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_THIRD || + videoTrackPackage.type == + NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_FOURTH + ) { + await this._engine.trackHelper.setDevice( + videoTrackPackage.track as ICameraVideoTrack, + deviceIdUTF8 + ); + } + } + } + + return this._engine.returnResult(); + }; + return this._engine.execute(process); + } + getDevice_73b9872(): CallApiReturnType { + let process = async () => { + let list: MediaDeviceInfo[] = []; + let deviceId = ''; + if (this._engine.globalState.videoDeviceId) { + deviceId = this._engine.globalState.videoDeviceId; + } else { + try { + list = await this._engine.globalState.AgoraRTC.getCameras(); + } catch (e) { + return this._engine.returnResult(false); + } + if (list && list.length > 0) { + deviceId = list[0].deviceId; + } + } + return this._engine.returnResult( + true, + 0, + JSON.stringify({ + result: NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK, + deviceIdUTF8: deviceId, + }) + ); + }; + return this._engine.execute(process); + } + + release(): CallApiReturnType { + let process = async () => { + let engine = this._engine; + engine.globalState.videoDevices = new Array(); + return this._engine.returnResult(); + }; + return this._engine.execute(process); + } +} diff --git a/packages/rtc/src/state/IrisGlobalState.ts b/packages/rtc/src/state/IrisGlobalState.ts index 2774fcd..9cd7274 100644 --- a/packages/rtc/src/state/IrisGlobalState.ts +++ b/packages/rtc/src/state/IrisGlobalState.ts @@ -69,9 +69,15 @@ export class IrisGlobalState { recordingDevices: DeviceInfo[] = new Array(); videoDevices: DeviceInfo[] = new Array(); - //setDevice() : videoDevice + //setDevice() videoDeviceId: string; + //setPlaybackDevice_4ad5f6e() + playbackDeviceId: string; + + //setRecordingDevice_4ad5f6e() + recordingDeviceId: string; + //enableAudioVolumeIndication enableAudioVolumeIndication: boolean = false; enableAudioVolumeIndicationConfig = { diff --git a/packages/rtc/test/binding/IAgoraRtcEngineDispatch.test.ts b/packages/rtc/test/binding/IAgoraRtcEngineDispatch.test.ts index 312ad59..67b17a2 100644 --- a/packages/rtc/test/binding/IAgoraRtcEngineDispatch.test.ts +++ b/packages/rtc/test/binding/IAgoraRtcEngineDispatch.test.ts @@ -11261,7 +11261,7 @@ describe('IRtcEngine', () => { expect( irisRtcEngine.implDispatchesMap.get('RtcEngine')._impl .getUserInfoByUserAccount_c6a8f08 - ).toBeCalledWith('test', 'test'); + ).toBeCalledWith('test'); }); test('RtcEngine_getUserInfoByUid_6b7aee8 parameter', async () => { @@ -11317,7 +11317,7 @@ describe('IRtcEngine', () => { expect( irisRtcEngine.implDispatchesMap.get('RtcEngine')._impl .getUserInfoByUid_6b7aee8 - ).toBeCalledWith('test', 'test'); + ).toBeCalledWith('test'); }); test('RtcEngine_startOrUpdateChannelMediaRelay_e68f0a4 impl call', async () => { diff --git a/packages/rtc/test/binding/IAudioDeviceManagerDispatch.test.ts b/packages/rtc/test/binding/IAudioDeviceManagerDispatch.test.ts index 02cef3d..113ba62 100644 --- a/packages/rtc/test/binding/IAudioDeviceManagerDispatch.test.ts +++ b/packages/rtc/test/binding/IAudioDeviceManagerDispatch.test.ts @@ -42,7 +42,10 @@ afterEach(() => { describe('IAudioDeviceManager', () => { test('AudioDeviceManager_enumeratePlaybackDevices impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'enumeratePlaybackDevices' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = {}; let apiParam = new IrisCore.EventParam( @@ -57,18 +60,20 @@ describe('IAudioDeviceManager', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl - ?.enumeratePlaybackDevices - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .enumeratePlaybackDevices + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl + .enumeratePlaybackDevices + ).toBeCalledWith(); }); test('AudioDeviceManager_enumerateRecordingDevices impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'enumerateRecordingDevices' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = {}; let apiParam = new IrisCore.EventParam( @@ -83,18 +88,44 @@ describe('IAudioDeviceManager', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl - ?.enumerateRecordingDevices - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .enumerateRecordingDevices + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl + .enumerateRecordingDevices + ).toBeCalledWith(); + }); + + test('AudioDeviceManager_setPlaybackDevice_4ad5f6e parameter', async () => { + let nParam = { + deviceId: undefined, + }; + try { + await IrisCore.callIrisApi( + apiEnginePtr, + new IrisCore.EventParam( + 'AudioDeviceManager_setPlaybackDevice_4ad5f6e', + JSON.stringify(nParam), + 0, + '', + ['test'], + [], + 1 + ) + ); + } catch (e) { + expect(e).toEqual('deviceId is undefined'); + } + //@ts-ignore + nParam.deviceId = 'test'; }); test('AudioDeviceManager_setPlaybackDevice_4ad5f6e impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'setPlaybackDevice_4ad5f6e' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = { deviceId: 'test', @@ -111,18 +142,26 @@ describe('IAudioDeviceManager', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl - ?.setPlaybackDevice_4ad5f6e - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .setPlaybackDevice_4ad5f6e + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl + .setPlaybackDevice_4ad5f6e + ).toBeCalledWith('test'); + }); + + test('AudioDeviceManager_getPlaybackDevice_73b9872 parameter', async () => { + let nParam = { + deviceId: undefined, + }; }); test('AudioDeviceManager_getPlaybackDevice_73b9872 impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'getPlaybackDevice_73b9872' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = { deviceId: 'test', @@ -139,13 +178,12 @@ describe('IAudioDeviceManager', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl - ?.getPlaybackDevice_73b9872 - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .getPlaybackDevice_73b9872 + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl + .getPlaybackDevice_73b9872 + ).toBeCalledWith(); }); test('AudioDeviceManager_getPlaybackDeviceInfo_5540658 impl call', async () => { @@ -230,9 +268,36 @@ describe('IAudioDeviceManager', () => { ); }); + test('AudioDeviceManager_setRecordingDevice_4ad5f6e parameter', async () => { + let nParam = { + deviceId: undefined, + }; + try { + await IrisCore.callIrisApi( + apiEnginePtr, + new IrisCore.EventParam( + 'AudioDeviceManager_setRecordingDevice_4ad5f6e', + JSON.stringify(nParam), + 0, + '', + ['test'], + [], + 1 + ) + ); + } catch (e) { + expect(e).toEqual('deviceId is undefined'); + } + //@ts-ignore + nParam.deviceId = 'test'; + }); + test('AudioDeviceManager_setRecordingDevice_4ad5f6e impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'setRecordingDevice_4ad5f6e' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = { deviceId: 'test', @@ -249,18 +314,26 @@ describe('IAudioDeviceManager', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl - ?.setRecordingDevice_4ad5f6e - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .setRecordingDevice_4ad5f6e + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl + .setRecordingDevice_4ad5f6e + ).toBeCalledWith('test'); + }); + + test('AudioDeviceManager_getRecordingDevice_73b9872 parameter', async () => { + let nParam = { + deviceId: undefined, + }; }); test('AudioDeviceManager_getRecordingDevice_73b9872 impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'getRecordingDevice_73b9872' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = { deviceId: 'test', @@ -277,13 +350,12 @@ describe('IAudioDeviceManager', () => { await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl - ?.getRecordingDevice_73b9872 - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + .getRecordingDevice_73b9872 + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl + .getRecordingDevice_73b9872 + ).toBeCalledWith(); }); test('AudioDeviceManager_getRecordingDeviceInfo_5540658 impl call', async () => { @@ -784,7 +856,10 @@ describe('IAudioDeviceManager', () => { test('AudioDeviceManager_release impl call', async () => { jest - .spyOn(irisRtcEngine, 'returnResult') + .spyOn( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl, + 'release' + ) .mockResolvedValue(new CallIrisApiResult(0, '')); let nParam = {}; let apiParam = new IrisCore.EventParam( @@ -798,12 +873,10 @@ describe('IAudioDeviceManager', () => { ); await IrisCore.callIrisApi(apiEnginePtr, apiParam); expect( - irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl?.release - ).toBeUndefined(); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl.release + ).toBeCalledTimes(1); + expect( + irisRtcEngine.implDispatchesMap.get('AudioDeviceManager')._impl.release + ).toBeCalledWith(); }); }); diff --git a/packages/rtc/test/impl/IAudioDeviceManagerImpl.test.ts b/packages/rtc/test/impl/IAudioDeviceManagerImpl.test.ts new file mode 100644 index 0000000..911a5f2 --- /dev/null +++ b/packages/rtc/test/impl/IAudioDeviceManagerImpl.test.ts @@ -0,0 +1,194 @@ +import { + FAKE_PLAYBACKINPUT_DEVICE_ID, + FAKE_RECORDINGINPUT_DEVICE_ID, + FakeAgoraRTCWrapper, +} from '@agoraio-extensions/agora-rtc-sdk-ng-fake'; +import * as NATIVE_RTC from '@iris/native-rtc'; +import 'jest-canvas-mock'; + +import { ILocalAudioTrack, IMicrophoneAudioTrack } from 'agora-rtc-sdk-ng'; +import { IrisApiEngine, IrisCore } from 'iris-web-core'; + +import { IrisWebRtc } from '../../src/IrisRtcApi'; +import { IrisAudioSourceType } from '../../src/base/BaseType'; + +import { IAudioDeviceManagerImpl } from '../../src/impl/IAudioDeviceManagerImpl'; +import { IrisRtcEngine } from '../engine/IrisRtcEngine'; + +import { + callIris, + callIrisWithoutCheck, + joinChannel, + setupLocalVideo, +} from '../utils'; + +let apiEnginePtr: IrisApiEngine; +let irisRtcEngine: IrisRtcEngine; +let audioDeviceManagerImpl: IAudioDeviceManagerImpl; + +beforeEach(async () => { + apiEnginePtr = IrisCore.createIrisApiEngine(); + IrisWebRtc.initIrisRtc(apiEnginePtr, { + agoraRTC: FakeAgoraRTCWrapper.getFakeAgoraRTC(), + }); + jest.useFakeTimers(); + irisRtcEngine = apiEnginePtr['apiInterceptors'][0]; + audioDeviceManagerImpl = irisRtcEngine.implDispatchesMap.get( + 'AudioDeviceManager' + )._impl; + jest.spyOn(irisRtcEngine, 'returnResult'); + + let nParam = { + context: { + areaCode: 1, + logConfig: { + level: 1, + }, + }, + }; + await callIris(apiEnginePtr, 'RtcEngine_initialize_0320339', nParam); +}); + +afterEach(() => { + IrisCore.disposeIrisApiEngine(apiEnginePtr); + jest.clearAllMocks(); + jest.useRealTimers(); +}); + +describe('IAgoraRtcEngineImpl', () => { + test('enumeratePlaybackDevices', async () => { + let result = await callIrisWithoutCheck( + apiEnginePtr, + 'AudioDeviceManager_enumeratePlaybackDevices' + ); + expect(result.code).toBe(NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK); + expect(irisRtcEngine.globalState.playbackDevices.length).not.toBe(0); + expect(irisRtcEngine.globalState.recordingDevices.length).not.toBe(0); + expect(irisRtcEngine.globalState.videoDevices.length).not.toBe(0); + expect(JSON.parse(result.data).result.length).toBe(1); + }); + test('enumerateRecordingDevices', async () => { + let result = await callIrisWithoutCheck( + apiEnginePtr, + 'AudioDeviceManager_enumerateRecordingDevices' + ); + expect(result.code).toBe(NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK); + expect(irisRtcEngine.globalState.playbackDevices.length).not.toBe(0); + expect(irisRtcEngine.globalState.recordingDevices.length).not.toBe(0); + expect(irisRtcEngine.globalState.videoDevices.length).not.toBe(0); + expect(JSON.parse(result.data).result.length).toBe(1); + }); + test('setPlaybackDevice_4ad5f6e', async () => { + let param = { + deviceId: 1, + }; + await joinChannel(apiEnginePtr, null); + jest.spyOn( + irisRtcEngine.irisClientManager.getLocalAudioTrackPackageBySourceType( + IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary + )[0].track as ILocalAudioTrack, + 'setPlaybackDevice' + ); + await callIris( + apiEnginePtr, + 'AudioDeviceManager_setPlaybackDevice_4ad5f6e', + param + ); + expect(irisRtcEngine.globalState.playbackDeviceId).toBe(param.deviceId); + expect( + (irisRtcEngine.irisClientManager.getLocalAudioTrackPackageBySourceType( + IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary + )[0].track as ILocalAudioTrack).setPlaybackDevice + ).toBeCalledWith(param.deviceId); + }); + test('getPlaybackDevice_73b9872', async () => { + jest.spyOn(irisRtcEngine.globalState.AgoraRTC, 'getPlaybackDevices'); + let param = { + deviceId: 1, + }; + let result = await callIrisWithoutCheck( + apiEnginePtr, + 'AudioDeviceManager_getPlaybackDevice_73b9872', + param + ); + expect(result.code).toBe(NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK); + expect(JSON.parse(result.data).deviceId).toBe(FAKE_PLAYBACKINPUT_DEVICE_ID); + expect( + irisRtcEngine.globalState.AgoraRTC.getPlaybackDevices + ).toBeCalledTimes(1); + jest.clearAllMocks(); + await callIris( + apiEnginePtr, + 'AudioDeviceManager_setPlaybackDevice_4ad5f6e', + param + ); + await callIris( + apiEnginePtr, + 'AudioDeviceManager_getPlaybackDevice_73b9872', + param + ); + expect( + irisRtcEngine.globalState.AgoraRTC.getPlaybackDevices + ).toBeCalledTimes(0); + }); + test('setRecordingDevice_4ad5f6e', async () => { + let param = { + deviceId: 1, + }; + await joinChannel(apiEnginePtr, null); + jest.spyOn( + irisRtcEngine.irisClientManager.getLocalAudioTrackPackageBySourceType( + IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary + )[0].track as IMicrophoneAudioTrack, + 'setDevice' + ); + await callIris( + apiEnginePtr, + 'AudioDeviceManager_setRecordingDevice_4ad5f6e', + param + ); + expect(irisRtcEngine.globalState.recordingDeviceId).toBe(param.deviceId); + expect( + (irisRtcEngine.irisClientManager.getLocalAudioTrackPackageBySourceType( + IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary + )[0].track as IMicrophoneAudioTrack).setDevice + ).toBeCalledWith(param.deviceId); + }); + test('getRecordingDevice_73b9872', async () => { + jest.spyOn(irisRtcEngine.globalState.AgoraRTC, 'getMicrophones'); + let param = { + deviceId: 1, + }; + let result = await callIrisWithoutCheck( + apiEnginePtr, + 'AudioDeviceManager_getRecordingDevice_73b9872', + param + ); + expect(result.code).toBe(NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK); + expect(JSON.parse(result.data).deviceId).toBe( + FAKE_RECORDINGINPUT_DEVICE_ID + ); + expect(irisRtcEngine.globalState.AgoraRTC.getMicrophones).toBeCalledTimes( + 1 + ); + jest.clearAllMocks(); + await callIris( + apiEnginePtr, + 'AudioDeviceManager_setRecordingDevice_4ad5f6e', + param + ); + await callIris( + apiEnginePtr, + 'AudioDeviceManager_getRecordingDevice_73b9872', + param + ); + expect(irisRtcEngine.globalState.AgoraRTC.getMicrophones).toBeCalledTimes( + 0 + ); + }); + test('release', async () => { + await callIris(apiEnginePtr, 'AudioDeviceManager_release', { sync: false }); + expect(irisRtcEngine.globalState.playbackDevices.length).toBe(0); + expect(irisRtcEngine.globalState.recordingDevices.length).toBe(0); + }); +}); diff --git a/packages/rtc/test/impl/IVideoDeviceManagerImpl.test.ts b/packages/rtc/test/impl/IVideoDeviceManagerImpl.test.ts index cb51058..c93b4b9 100644 --- a/packages/rtc/test/impl/IVideoDeviceManagerImpl.test.ts +++ b/packages/rtc/test/impl/IVideoDeviceManagerImpl.test.ts @@ -11,12 +11,11 @@ import { IrisApiEngine, IrisCore } from 'iris-web-core'; import { IrisWebRtc } from '../../src/IrisRtcApi'; +import { IVideoDeviceManagerImpl } from '../../src/impl/IVideoDeviceManagerImpl'; import { IrisRtcEngine } from '../engine/IrisRtcEngine'; import { callIris, callIrisWithoutCheck, setupLocalVideo } from '../utils'; -import { IVideoDeviceManagerImpl } from './IAgoraRtcEngineImpl'; - let apiEnginePtr: IrisApiEngine; let irisRtcEngine: IrisRtcEngine; let videoDeviceManagerImpl: IVideoDeviceManagerImpl; @@ -52,20 +51,9 @@ afterEach(() => { describe('IAgoraRtcEngineImpl', () => { test('enumerateVideoDevices', async () => { - let param = { - enabled: true, - useTexture: true, - sourceType: NATIVE_RTC.EXTERNAL_VIDEO_SOURCE_TYPE.ENCODED_VIDEO_FRAME, - encodedVideoOption: { - ccMode: NATIVE_RTC.TCcMode.CC_DISABLED, - codecType: NATIVE_RTC.VIDEO_CODEC_TYPE.VIDEO_CODEC_AV1, - targetBitrate: 1, - }, - }; let result = await callIrisWithoutCheck( apiEnginePtr, - 'VideoDeviceManager_enumerateVideoDevices', - param + 'VideoDeviceManager_enumerateVideoDevices' ); expect(result.code).toBe(NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK); expect(irisRtcEngine.globalState.playbackDevices.length).not.toBe(0); @@ -114,8 +102,6 @@ describe('IAgoraRtcEngineImpl', () => { }); test('release', async () => { await callIris(apiEnginePtr, 'VideoDeviceManager_release', { sync: false }); - expect(irisRtcEngine.globalState.playbackDevices.length).toBe(0); - expect(irisRtcEngine.globalState.recordingDevices.length).toBe(0); expect(irisRtcEngine.globalState.videoDevices.length).toBe(0); }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0017f5c..2675a1c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,8 +92,8 @@ importers: packages/fake/rtc: dependencies: '@agoraio-extensions/agora-rtc-sdk-ng-fake': - specifier: ^1.0.12 - version: 1.0.12 + specifier: ^1.0.13 + version: 1.0.13 '@iris/native-rtc': specifier: 'workspace: *' version: link:../../@iris/rtc @@ -147,8 +147,8 @@ importers: packages/rtc: dependencies: '@agoraio-extensions/agora-rtc-sdk-ng-fake': - specifier: ^1.0.12 - version: 1.0.12 + specifier: ^1.0.13 + version: 1.0.13 '@iris/native-rtc': specifier: 'workspace: *' version: link:../@iris/rtc @@ -247,8 +247,8 @@ packages: - debug dev: false - /@agoraio-extensions/agora-rtc-sdk-ng-fake@1.0.12: - resolution: {integrity: sha512-fXKDztmtIe+JwquCKlsEd59ZmvJVtGBaoj6g3QIzy6E8Z/VB6UMEn8thvvHO8wEzZ6CKl+uG2k8OF22kdpRkXQ==, tarball: https://npm.pkg.github.com/download/@agoraio-extensions/agora-rtc-sdk-ng-fake/1.0.12/99350f1d3d2b0ed7d3bd4dd58e39cad252b07ee0} + /@agoraio-extensions/agora-rtc-sdk-ng-fake@1.0.13: + resolution: {integrity: sha512-/aKmZwDxb4Vf50Bddbftz+vyibEcas9wrcfK5Qt5G1hONfoRegiub7h+dJhqubxRoFVARsGgBEB1NAFNOxICtQ==, tarball: https://npm.pkg.github.com/download/@agoraio-extensions/agora-rtc-sdk-ng-fake/1.0.13/73bd47268a178a4499e546f47c4bdeca3146560a} dev: false /@ampproject/remapping@2.2.1: diff --git a/scripts/terra/config/support_list.json b/scripts/terra/config/support_list.json index e9c2366..ace73ac 100644 --- a/scripts/terra/config/support_list.json +++ b/scripts/terra/config/support_list.json @@ -100,5 +100,12 @@ "VideoDeviceManager_enumerateVideoDevices", "VideoDeviceManager_setDevice_4ad5f6e", "VideoDeviceManager_getDevice_73b9872", - "VideoDeviceManager_release" + "VideoDeviceManager_release", + "AudioDeviceManager_enumerateRecordingDevices", + "AudioDeviceManager_enumeratePlaybackDevices", + "AudioDeviceManager_setRecordingDevice_4ad5f6e", + "AudioDeviceManager_setPlaybackDevice_4ad5f6e", + "AudioDeviceManager_getRecordingDevice_73b9872", + "AudioDeviceManager_getPlaybackDevice_73b9872", + "AudioDeviceManager_release" ] diff --git a/scripts/terra/templates/binding/file_content.mustache b/scripts/terra/templates/binding/file_content.mustache index 70c0af4..bf11f04 100644 --- a/scripts/terra/templates/binding/file_content.mustache +++ b/scripts/terra/templates/binding/file_content.mustache @@ -103,7 +103,7 @@ export class {{name}}Dispatch {{#base_clazzs}}extends {{.}}Dispatch{{/base_clazz {{/parameters}} {{/user_data.isRegisterMethod}} - return this._impl.{{name}}({{#parameters}}{{name}},{{/parameters}}); + return this._impl.{{name}}({{#parameters}}{{^is_output}}{{name}},{{/is_output}}{{/parameters}}); {{/user_data.isSupport}} {{^user_data.isSupport}} AgoraConsole.warn('{{{user_data.IrisApiIdParser.value}}} not supported in this platform!'); diff --git a/scripts/terra/templates/binding/test/file_content.mustache b/scripts/terra/templates/binding/test/file_content.mustache index 0e81f81..f9c44fa 100644 --- a/scripts/terra/templates/binding/test/file_content.mustache +++ b/scripts/terra/templates/binding/test/file_content.mustache @@ -158,7 +158,7 @@ describe('{{name}}', () => { expect( irisRtcEngine.implDispatchesMap.get('{{user_data.prefix_name}}')._impl .{{name}} - ).toBeCalledWith({{#parameters}}'test',{{/parameters}}); + ).toBeCalledWith({{#parameters}}{{^is_output}}'test',{{/is_output}}{{/parameters}}); }); {{/user_data.isSupport}} {{^user_data.isSupport}}