Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Aug 27, 2024
1 parent 37a811e commit 1de5fb6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/rtc/src/engine/IrisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class IrisClient {
} else if (irisClientState.publishSecondaryCameraTrack == true) {
videoSourceType =
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_SECONDARY;
} else if (irisClientState.publishScreenCaptureVideo == true) {
} else if (irisClientState.publishScreenTrack == true) {
videoSourceType =
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_PRIMARY;
}

Check warning on line 132 in packages/rtc/src/engine/IrisClient.ts

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 132 in packages/rtc/src/engine/IrisClient.ts

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 132 in packages/rtc/src/engine/IrisClient.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 132 in packages/rtc/src/engine/IrisClient.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 132 in packages/rtc/src/engine/IrisClient.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 132 in packages/rtc/src/engine/IrisClient.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
Expand Down
172 changes: 138 additions & 34 deletions packages/rtc/src/helper/ImplHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { NotifyType } from '../engine/IrisClientObserver';

import { IrisRtcEngine } from '../engine/IrisRtcEngine';
import { IrisTrackEventHandler } from '../event_handler/IrisTrackEventHandler';
import { IRtcEngineImpl } from '../impl/IAgoraRtcEngineImpl';

import { IrisGlobalState } from '../state/IrisGlobalState';
import { AgoraConsole } from '../util/AgoraConsole';
import { AgoraTranslate } from '../util/AgoraTranslate';
import { AgoraConsole, AgoraTranslate, isDefined } from '../util';

export class ImplHelper {
_engine: IrisRtcEngine;
Expand Down Expand Up @@ -354,47 +354,151 @@ export class ImplHelper {
} else {
irisClient = irisClientManager.getIrisClient();
}

let irisClientState = irisClient.irisClientState;
let agoraRTCClient = irisClient?.agoraRTCClient;
if (!agoraRTCClient) {
return this._engine.returnResult(
false,
-NATIVE_RTC.ERROR_CODE_TYPE.ERR_FAILED
);
}

let audioTrackPackages = irisClient.audioTrackPackages!;
let videoTrackPackage = irisClient.videoTrackPackage!;
let irisClientObserver = irisClientManager.irisClientObserver;
await irisClientObserver.notifyLocal(NotifyType.UNPUBLISH_TRACK, [
...audioTrackPackages,
videoTrackPackage,
]);

let irisClientState = irisClient.irisClientState;
irisClientState.mergeChannelMediaOptions(options);
if (irisClientState.clientRoleType) {
await this._engine.clientHelper.setClientRole(
agoraRTCClient,
irisClientState.clientRoleType,
irisClientState.audienceLatencyLevel
);
//clientRole update
if (isDefined(options.clientRoleType)) {
if (
options.clientRoleType ===
NATIVE_RTC.CLIENT_ROLE_TYPE.CLIENT_ROLE_AUDIENCE &&
irisClientState.clientRoleType !== options.clientRoleType
) {
(this._engine.getImplInstance(
'RtcEngine'
) as IRtcEngineImpl).muteLocalAudioStream_5039d15(true);
(this._engine.getImplInstance(
'RtcEngine'
) as IRtcEngineImpl).muteLocalVideoStream_5039d15(true);
this._engine.rtcEngineEventHandler.onClientRoleChanged_2acaf10(
irisClient.connection!,
irisClientState.clientRoleType!,
options.clientRoleType!,
options
);
await this._engine.clientHelper.setClientRole(
agoraRTCClient!,
options.clientRoleType!,
irisClientState.audienceLatencyLevel
);
}
irisClientState.clientRoleType = options.clientRoleType;
}
if (irisClientState.token) {

//token update
if (isDefined(options.token)) {
try {
await agoraRTCClient.renewToken(irisClientState.token);
await agoraRTCClient!.renewToken(options.token);
} catch (e) {
return this._engine.returnResult(false);
}
}
irisClientObserver.notifyLocal(
NotifyType.PUBLISH_TRACK,
[
...irisClientManager.localAudioTrackPackages,
...irisClientManager.localVideoTrackPackages,
],
[irisClient]
);

let needPublishVideoTrackPackages: VideoTrackPackage[] = [];
let needUnPublishVideoTrackPackages: VideoTrackPackage[] = [];
let needPublishAudioTrackPackages: AudioTrackPackage[] = [];
let needUnPublishAudioTrackPackages: AudioTrackPackage[] = [];
if (
irisClientState.clientRoleType ===
NATIVE_RTC.CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER
) {
if (isDefined(options.publishCameraTrack)) {
if (irisClientState.publishCameraTrack) {
if (options.publishCameraTrack === false) {
needUnPublishVideoTrackPackages = [
...needUnPublishVideoTrackPackages,
...this._engine.irisClientManager.getLocalVideoTrackPackageBySourceType(
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_PRIMARY
),
];
}
} else {
if (options.publishCameraTrack === true) {
needPublishVideoTrackPackages = [
...needPublishVideoTrackPackages,
...this._engine.irisClientManager.getLocalVideoTrackPackageBySourceType(
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_PRIMARY
),
];
}
}
}

if (isDefined(options.publishMicrophoneTrack)) {
if (irisClientState.publishMicrophoneTrack) {
if (options.publishMicrophoneTrack === false) {
needUnPublishAudioTrackPackages = [
...needUnPublishAudioTrackPackages,
...this._engine.irisClientManager.getLocalAudioTrackPackageBySourceType(
IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary
),
];
}
} else {
if (options.publishMicrophoneTrack === true) {
needPublishAudioTrackPackages = [
...needPublishAudioTrackPackages,
...this._engine.irisClientManager.getLocalAudioTrackPackageBySourceType(
IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary
),
];
}
}
}

if (isDefined(options.publishScreenTrack)) {
if (irisClientState.publishScreenTrack) {
if (options.publishScreenTrack === false) {
needUnPublishAudioTrackPackages = [
...needUnPublishAudioTrackPackages,
...this._engine.irisClientManager.getLocalAudioTrackPackageBySourceType(
IrisAudioSourceType.kAudioSourceTypeScreenCapture
),
];
needUnPublishVideoTrackPackages = [
...needUnPublishVideoTrackPackages,
...this._engine.irisClientManager.getLocalVideoTrackPackageBySourceType(
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_PRIMARY
),
];
}
} else {
if (options.publishScreenTrack === true) {
needPublishAudioTrackPackages = [
...needPublishAudioTrackPackages,
...this._engine.irisClientManager.getLocalAudioTrackPackageBySourceType(
IrisAudioSourceType.kAudioSourceTypeScreenCapture
),
];
needPublishVideoTrackPackages = [
...needPublishVideoTrackPackages,
...this._engine.irisClientManager.getLocalVideoTrackPackageBySourceType(
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_PRIMARY
),
];
}
}
}

await irisClientObserver.notifyLocal(
NotifyType.UNPUBLISH_TRACK,
[
...irisClientManager.localAudioTrackPackages,
...needUnPublishVideoTrackPackages,
],
[irisClient]
);

await irisClientObserver.notifyLocal(
NotifyType.PUBLISH_TRACK,
[
...irisClientManager.localAudioTrackPackages,
...irisClientManager.localVideoTrackPackages,
],
[irisClient]
);
}
}

public async joinChannel(
Expand Down
2 changes: 1 addition & 1 deletion packages/rtc/src/impl/IAgoraRtcEngineImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
): CallApiReturnType {
let process = async (): Promise<CallIrisApiResult> => {
if (this._engine.globalState.enabledVideo == false) {
AgoraConsole.error('call enableVideo(true) before startPreview');
AgoraConsole.warn('call enableVideo(true) before startPreview');
return this._engine.returnResult();
}

Expand Down
9 changes: 4 additions & 5 deletions packages/rtc/test/impl/IAgoraRtcEngineImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,9 @@ describe('IAgoraRtcEngineImpl', () => {
jest.spyOn(agoraRTCClient!, 'setClientRole');
let param = {
options: {
clientRoleType: NATIVE_RTC.CLIENT_ROLE_TYPE.CLIENT_ROLE_AUDIENCE,
publishCameraTrack: true,
publishMicrophoneTrack: true,
publishScreenCaptureVideo: true,
publishScreenCaptureAudio: true,
publishScreenTrack: true,
publishCustomVideoTrack: true,
token: '123',
Expand Down Expand Up @@ -448,17 +447,17 @@ describe('IAgoraRtcEngineImpl', () => {
irisRtcEngine.rtcEngineEventHandler,
'onLocalVideoStateChanged_a44228a'
);
jest.spyOn(AgoraConsole, 'error');
jest.spyOn(AgoraConsole, 'warn');

await callIris(apiEnginePtr, 'RtcEngine_startPreview_4fd718e', param);
expect(AgoraConsole.error).toBeCalledWith(
expect(AgoraConsole.warn).toBeCalledWith(
'call enableVideo(true) before startPreview'
);
jest.clearAllMocks();
await callIris(apiEnginePtr, 'RtcEngine_startPreview_4fd718e', {
sourceType: 100,
});
expect(AgoraConsole.error).toBeCalledWith(
expect(AgoraConsole.warn).toBeCalledWith(
'call enableVideo(true) before startPreview'
);
await callIris(apiEnginePtr, 'RtcEngine_enableVideo', null);
Expand Down
3 changes: 1 addition & 2 deletions packages/rtc/test/impl/IAgoraRtcEngineImplEx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ describe('IAgoraRtcEngineImpl', () => {
let param2 = {
connection: param.connection,
options: {
clientRoleType: NATIVE_RTC.CLIENT_ROLE_TYPE.CLIENT_ROLE_AUDIENCE,
publishCameraTrack: true,
publishMicrophoneTrack: true,
publishScreenCaptureVideo: true,
publishScreenCaptureAudio: true,
publishScreenTrack: true,
publishCustomVideoTrack: true,
token: '123',
Expand Down

0 comments on commit 1de5fb6

Please sign in to comment.