Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Jul 15, 2024
1 parent 24eaae6 commit 202141a
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 41 deletions.
7 changes: 7 additions & 0 deletions packages/rtc/src/base/DefaultValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as NATIVE_RTC from '@iris/native-rtc';

export const defaultLeaveChannelOptions: NATIVE_RTC.LeaveChannelOptions = {
stopAudioMixing: true,
stopAllEffect: true,
stopMicrophoneRecording: true,
};
17 changes: 13 additions & 4 deletions packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/rtc/src/engine/IrisRtcEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export class IrisRtcEngine implements ApiInterceptor {
}
}

public getImplInstance(className: string): any {
return this.implDispatchesMap.get(className)?._impl;

Check warning on line 185 in packages/rtc/src/engine/IrisRtcEngine.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

public getVideoFrame(uid: number, channel_id: string): VideoParams {
return this.irisClientManager.getVideoFrame(uid, channel_id);
}
Expand Down
30 changes: 29 additions & 1 deletion packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -69,6 +71,17 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx {
}
leaveChannelEx_c81e1a4(
connection: NATIVE_RTC.RtcConnection
): CallApiReturnType {
let processFunc = async (): Promise<CallIrisApiResult> => {
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<CallIrisApiResult> => {
if (this._engine.irisClientManager.irisClientList.length === 0) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down
26 changes: 9 additions & 17 deletions packages/rtc/src/impl/IAgoraRtcEngineImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<CallIrisApiResult> => {
//离开频道后重置参数
// this._engine.globalState.reset();
if (this._engine.irisClientManager.irisClientList.length === 0) {
return this._engine.returnResult();
}
Expand All @@ -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
Expand All @@ -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 = {
Expand Down
9 changes: 1 addition & 8 deletions packages/rtc/src/state/IrisClientState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
}
Expand Down
61 changes: 53 additions & 8 deletions packages/rtc/test/binding/IAgoraRtcEngineExDispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 () => {
Expand Down
27 changes: 24 additions & 3 deletions packages/rtc/test/impl/IAgoraRtcEngineImplEx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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: {
Expand All @@ -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);
});
Expand Down Expand Up @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions scripts/terra/config/support_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 202141a

Please sign in to comment.