From ea8ac37aabac0f1af75772eed834c8e935b1db06 Mon Sep 17 00:00:00 2001 From: guoxianzhe <53285945+guoxianzhe@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:49:07 +0800 Subject: [PATCH] feat: add onNetworkQualityEx (#19) --- .../src/binding/IAgoraRtcEngineExDispatch.ts | 74 +++++++++++-------- packages/rtc/src/engine/IrisClientManager.ts | 4 +- .../binding/IAgoraRtcEngineExDispatch.test.ts | 13 +--- scripts/terra/config/support_list.json | 1 + .../templates/binding/file_content.mustache | 2 +- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts b/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts index 0a3ee07..aab302a 100644 --- a/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts +++ b/packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts @@ -73,7 +73,9 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { } onRejoinChannelSuccessEx(connection: RtcConnection, elapsed: number): void { - AgoraConsole.warn('onRejoinChannelSuccess not supported in this platform!'); + AgoraConsole.warn( + 'onRejoinChannelSuccessEx not supported in this platform!' + ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -84,7 +86,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { delay: number, lost: number ): void { - AgoraConsole.warn('onAudioQuality not supported in this platform!'); + AgoraConsole.warn('onAudioQualityEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -126,7 +128,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { } onRtcStatsEx(connection: RtcConnection, stats: RtcStats): void { - AgoraConsole.warn('onRtcStats not supported in this platform!'); + AgoraConsole.warn('onRtcStatsEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -136,12 +138,26 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { txQuality: number, rxQuality: number ): void { - AgoraConsole.warn('onNetworkQuality not supported in this platform!'); - this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); + let _obj = { + connection, + remoteUid, + txQuality, + rxQuality, + }; + let _json = JSON.stringify(_obj); + let _key = this.eventKey('onNetworkQualityEx'); + + let eventParam = new IrisCore.EventParam(_key, _json, 0, '', [], [], 0); + AgoraConsole.log( + `onNetworkQualityEx eventParam ${JSON.stringify(eventParam)}` + ); + this.notifyEvent(eventParam); } onIntraRequestReceivedEx(connection: RtcConnection): void { - AgoraConsole.warn('onIntraRequestReceived not supported in this platform!'); + AgoraConsole.warn( + 'onIntraRequestReceivedEx not supported in this platform!' + ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -177,7 +193,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { height: number, rotation: number ): void { - AgoraConsole.warn('onVideoSizeChanged not supported in this platform!'); + AgoraConsole.warn('onVideoSizeChangedEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -189,7 +205,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { elapsed: number ): void { AgoraConsole.warn( - 'onRemoteVideoStateChanged not supported in this platform!' + 'onRemoteVideoStateChangedEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -301,7 +317,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { remoteUid: number, enabled: boolean ): void { - AgoraConsole.warn('onUserEnableVideo not supported in this platform!'); + AgoraConsole.warn('onUserEnableVideoEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -346,7 +362,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { } onLocalAudioStatsEx(connection: RtcConnection, stats: LocalAudioStats): void { - AgoraConsole.warn('onLocalAudioStats not supported in this platform!'); + AgoraConsole.warn('onLocalAudioStatsEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -354,7 +370,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { connection: RtcConnection, stats: RemoteAudioStats ): void { - AgoraConsole.warn('onRemoteAudioStats not supported in this platform!'); + AgoraConsole.warn('onRemoteAudioStatsEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -362,7 +378,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { connection: RtcConnection, stats: RemoteVideoStats ): void { - AgoraConsole.warn('onRemoteVideoStats not supported in this platform!'); + AgoraConsole.warn('onRemoteVideoStatsEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -416,7 +432,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { length: number, sentTs: number ): void { - AgoraConsole.warn('onStreamMessage not supported in this platform!'); + AgoraConsole.warn('onStreamMessageEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -428,7 +444,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { missed: number, cached: number ): void { - AgoraConsole.warn('onStreamMessageError not supported in this platform!'); + AgoraConsole.warn('onStreamMessageErrorEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -451,7 +467,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { reason: LICENSE_ERROR_TYPE ): void { AgoraConsole.warn( - 'onLicenseValidationFailure not supported in this platform!' + 'onLicenseValidationFailureEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -476,7 +492,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { elapsed: number ): void { AgoraConsole.warn( - 'onFirstLocalAudioFramePublished not supported in this platform!' + 'onFirstLocalAudioFramePublishedEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -527,7 +543,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { error: LOCAL_AUDIO_STREAM_ERROR ): void { AgoraConsole.warn( - 'onLocalAudioStateChanged not supported in this platform!' + 'onLocalAudioStateChangedEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -540,13 +556,13 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { elapsed: number ): void { AgoraConsole.warn( - 'onRemoteAudioStateChanged not supported in this platform!' + 'onRemoteAudioStateChangedEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } onActiveSpeakerEx(connection: RtcConnection, uid: number): void { - AgoraConsole.warn('onActiveSpeaker not supported in this platform!'); + AgoraConsole.warn('onActiveSpeakerEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -578,7 +594,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { currentRole: CLIENT_ROLE_TYPE ): void { AgoraConsole.warn( - 'onClientRoleChangeFailed not supported in this platform!' + 'onClientRoleChangeFailedEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -591,7 +607,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { rxKBitRate: number ): void { AgoraConsole.warn( - 'onRemoteAudioTransportStats not supported in this platform!' + 'onRemoteAudioTransportStatsEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -604,7 +620,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { rxKBitRate: number ): void { AgoraConsole.warn( - 'onRemoteVideoTransportStats not supported in this platform!' + 'onRemoteVideoTransportStatsEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -635,7 +651,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { action: WLACC_SUGGEST_ACTION, wlAccMsg: string ): void { - AgoraConsole.warn('onWlAccMessage not supported in this platform!'); + AgoraConsole.warn('onWlAccMessageEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -644,12 +660,12 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { currentStats: WlAccStats, averageStats: WlAccStats ): void { - AgoraConsole.warn('onWlAccStats not supported in this platform!'); + AgoraConsole.warn('onWlAccStatsEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } onNetworkTypeChangedEx(connection: RtcConnection, type: NETWORK_TYPE): void { - AgoraConsole.warn('onNetworkTypeChanged not supported in this platform!'); + AgoraConsole.warn('onNetworkTypeChangedEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -677,7 +693,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { success: boolean, reason: UPLOAD_ERROR_REASON ): void { - AgoraConsole.warn('onUploadLogResult not supported in this platform!'); + AgoraConsole.warn('onUploadLogResultEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -686,7 +702,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { remoteUid: number, userAccount: string ): void { - AgoraConsole.warn('onUserAccountUpdated not supported in this platform!'); + AgoraConsole.warn('onUserAccountUpdatedEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -698,7 +714,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { height: number, errCode: number ): void { - AgoraConsole.warn('onSnapshotTaken not supported in this platform!'); + AgoraConsole.warn('onSnapshotTakenEx not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } @@ -709,7 +725,7 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler { tracingInfo: VideoRenderingTracingInfo ): void { AgoraConsole.warn( - 'onVideoRenderingTracingResult not supported in this platform!' + 'onVideoRenderingTracingResultEx not supported in this platform!' ); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); } diff --git a/packages/rtc/src/engine/IrisClientManager.ts b/packages/rtc/src/engine/IrisClientManager.ts index 08792b5..c66fdd4 100644 --- a/packages/rtc/src/engine/IrisClientManager.ts +++ b/packages/rtc/src/engine/IrisClientManager.ts @@ -346,8 +346,8 @@ export class IrisClientManager { this._engine.rtcEngineEventHandler.onNetworkQualityEx( connection, remoteUserPackage.uid as number, - stats[remoteUserPackage.uid].downlinkNetworkQuality, - stats[remoteUserPackage.uid].uplinkNetworkQuality + stats[remoteUserPackage.uid]?.downlinkNetworkQuality, + stats[remoteUserPackage.uid]?.uplinkNetworkQuality ); }, this._engine.globalState.networkQualityInterval); this._engine.addIrisInterval( diff --git a/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts b/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts index f4ac532..13bae2e 100644 --- a/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts +++ b/packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts @@ -141,19 +141,12 @@ describe('IRtcEngineEventHandlerEx', () => { let eventHandler = new bindingAPI.IRtcEngineEventHandlerEx(irisRtcEngine); jest.spyOn(eventHandler._engine.irisEventHandlerManager, 'notifyEvent'); jest.spyOn(eventHandler, 'eventKey'); - jest - .spyOn(irisRtcEngine, 'returnResult') - .mockResolvedValue(new CallIrisApiResult(0, '')); eventHandler.onNetworkQualityEx(undefined, undefined, undefined, undefined); expect( eventHandler._engine.irisEventHandlerManager.notifyEvent - ).toBeCalledTimes(0); - expect(eventHandler.eventKey).toBeCalledTimes(0); - expect(irisRtcEngine.returnResult).toBeCalledTimes(1); - expect(irisRtcEngine.returnResult).toBeCalledWith( - false, - -NATIVE_RTC.ERROR_CODE_TYPE.ERR_NOT_SUPPORTED - ); + ).toBeCalledTimes(1); + expect(eventHandler.eventKey).toBeCalledTimes(1); + expect(eventHandler.eventKey).toBeCalledWith('onNetworkQualityEx'); }); test('onIntraRequestReceivedEx impl call', async () => { let eventHandler = new bindingAPI.IRtcEngineEventHandlerEx(irisRtcEngine); diff --git a/scripts/terra/config/support_list.json b/scripts/terra/config/support_list.json index 21885f6..7af544b 100644 --- a/scripts/terra/config/support_list.json +++ b/scripts/terra/config/support_list.json @@ -57,6 +57,7 @@ "agora::rtc::IRtcEngineEventHandlerEx.onUserMuteAudio", "agora::rtc::IRtcEngineEventHandlerEx.onUserStateChanged", "agora::rtc::IRtcEngineEventHandlerEx.onClientRoleChanged", + "agora::rtc::IRtcEngineEventHandlerEx.onNetworkQuality", "agora::rtc::IRtcEngineEventHandlerEx.onUserMuteVideo", "agora::rtc::IRtcEngineEventHandlerEx.onUserEnableLocalVideo", "agora::rtc::IRtcEngineEventHandlerEx.onAudioVolumeIndication", diff --git a/scripts/terra/templates/binding/file_content.mustache b/scripts/terra/templates/binding/file_content.mustache index d4e8826..be5d8d9 100644 --- a/scripts/terra/templates/binding/file_content.mustache +++ b/scripts/terra/templates/binding/file_content.mustache @@ -39,7 +39,7 @@ export class {{name}} {{#base_clazzs}}extends {{.}}{{/base_clazzs}}{ this.notifyEvent(eventParam); {{/user_data.isSupport}} {{^user_data.isSupport}} - AgoraConsole.warn('{{name}} not supported in this platform!'); + AgoraConsole.warn('{{name}}{{user_data._prefix}} not supported in this platform!'); this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED); {{/user_data.isSupport}} }