Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Aug 28, 2024
1 parent 87f00f9 commit 7c3535c
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 131 deletions.
19 changes: 12 additions & 7 deletions packages/rtc/src/engine/IrisClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class VideoTrackPackage {
type?: NATIVE_RTC.VIDEO_SOURCE_TYPE | NATIVE_RTC.EXTERNAL_VIDEO_SOURCE_TYPE;
track?: ILocalVideoTrack | IRemoteVideoTrack;
isPreview: boolean = false;
isPublished: boolean = false;
irisClient: IrisClient;

constructor(
Expand Down Expand Up @@ -98,6 +99,7 @@ export class AudioTrackPackage {
| IMicrophoneAudioTrack
| ILocalTrack;
irisClient: IrisClient;
isPublished: boolean = false;

constructor(
type: IrisAudioSourceType,
Expand All @@ -124,11 +126,6 @@ export class BufferSourceAudioTrackPackage extends AudioTrackPackage {
type: IrisAudioSourceType;
track: IBufferSourceAudioTrack;
needPublish: boolean;
isPublished: boolean;

setIsPublished(isPublished: boolean) {
this.isPublished = isPublished;
}

constructor(
type: IrisAudioSourceType,
Expand Down Expand Up @@ -418,7 +415,10 @@ export class IrisClientManager {
getIrisClientByConnection(connection: NATIVE_RTC.RtcConnection): IrisClient {
if (connection) {
return this.irisClientList.filter((irisClient: IrisClient) => {
if (irisClient.connection?.channelId == connection.channelId) {
if (
irisClient.connection?.channelId == connection.channelId &&
irisClient.connection?.localUid == connection.localUid
) {
return irisClient;
}
})[0];
Expand Down Expand Up @@ -511,7 +511,12 @@ export class IrisClientManager {
this._engine.trackHelper.stop(audioTrack);
}
if (!audioTrack.muted) {
await this._engine.trackHelper.setEnabled(audioTrack, false);
if (
audioTrackPackage.type !==
IrisAudioSourceType.kAudioSourceTypeScreenCapture
) {
await this._engine.trackHelper.setEnabled(audioTrack, false);
}
}
this.removeTrackEventHandlerByTrack(audioTrack);
}
Expand Down
82 changes: 32 additions & 50 deletions packages/rtc/src/engine/IrisClientObserver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as NATIVE_RTC from '@iris/native-rtc';
import { ILocalTrack, IMicrophoneAudioTrack } from 'agora-rtc-sdk-ng';
import { ILocalTrack } from 'agora-rtc-sdk-ng';

import { IrisAudioSourceType } from '../base/BaseType';
import {
Expand Down Expand Up @@ -70,12 +70,12 @@ export class IrisClientObserver {
);
}

//根据每个irisClient的options,分配对应的轨道,如果irisClient的agoraRTCClient已经加入频道,则发布轨道
async publishTrack(trackPackage: TrackPackage, irisClientList: IrisClient[]) {
const globalState = this._engine.globalState;
if (!trackPackage.track) return;
if (!trackPackage.track && trackPackage.isPublished) return;

Check warning on line 75 in packages/rtc/src/engine/IrisClientObserver.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 75 in packages/rtc/src/engine/IrisClientObserver.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 75 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

let publishTrack: ILocalTrack | undefined = undefined;
let needPublish: boolean = false;
let track = trackPackage.track as ILocalTrack;

for (const irisClient of irisClientList) {
const options = irisClient.irisClientState;
Expand All @@ -85,18 +85,13 @@ export class IrisClientObserver {
case IrisAudioSourceType.kAudioSourceTypeMicrophonePrimary:
case IrisAudioSourceType.kAudioSourceTypeMicrophoneSecondary:
if (options.publishMicrophoneTrack) {
this._engine.trackHelper.setMuted(
trackPackage.track as IMicrophoneAudioTrack,
false
);
publishTrack = trackPackage.track as ILocalTrack;
irisClient.addLocalAudioTrack(trackPackage);
this._engine.trackHelper.setMuted(track, false);
needPublish = true;
}
break;
case IrisAudioSourceType.kAudioSourceTypeScreenCapture:
if (options.publishScreenCaptureAudio) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.addLocalAudioTrack(trackPackage);
needPublish = true;

Check warning on line 94 in packages/rtc/src/engine/IrisClientObserver.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 95 in packages/rtc/src/engine/IrisClientObserver.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 95 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 96 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case IrisAudioSourceType.kAudioSourceTypeBufferSourceAudio:
Expand All @@ -105,91 +100,77 @@ export class IrisClientObserver {
bufferTrackPackage.needPublish &&
!bufferTrackPackage.isPublished
) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.addLocalAudioTrack(trackPackage);
needPublish = true;
}
break;
}
if (needPublish) {
irisClient.addLocalAudioTrack(trackPackage as AudioTrackPackage);
}
}

if (globalState.enabledVideo && globalState.enabledLocalVideo) {
switch (trackPackage.type) {
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_PRIMARY:
if (options.publishScreenTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 116 in packages/rtc/src/engine/IrisClientObserver.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 117 in packages/rtc/src/engine/IrisClientObserver.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 117 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 118 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_SECONDARY:
if (options.publishSecondaryScreenTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 121 in packages/rtc/src/engine/IrisClientObserver.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 122 in packages/rtc/src/engine/IrisClientObserver.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 122 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 123 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_THIRD:
if (options.publishThirdScreenTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 126 in packages/rtc/src/engine/IrisClientObserver.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 127 in packages/rtc/src/engine/IrisClientObserver.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 127 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 128 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_SCREEN_FOURTH:
if (options.publishFourthScreenTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 131 in packages/rtc/src/engine/IrisClientObserver.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/IrisClientObserver.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/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 133 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_PRIMARY:
if (options.publishCameraTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;
}
break;
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_SECONDARY:
if (options.publishSecondaryCameraTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 141 in packages/rtc/src/engine/IrisClientObserver.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 142 in packages/rtc/src/engine/IrisClientObserver.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 142 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 143 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_THIRD:
if (options.publishThirdCameraTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 146 in packages/rtc/src/engine/IrisClientObserver.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 147 in packages/rtc/src/engine/IrisClientObserver.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 147 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 148 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CAMERA_FOURTH:
if (options.publishFourthCameraTrack) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
needPublish = true;

Check warning on line 151 in packages/rtc/src/engine/IrisClientObserver.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 152 in packages/rtc/src/engine/IrisClientObserver.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 152 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;

Check warning on line 153 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
case NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_CUSTOM:
if (
options.publishCustomVideoTrack ||
globalState.pushVideoFrameEnabled
) {
publishTrack = trackPackage.track as ILocalTrack;
irisClient.setLocalVideoTrack(trackPackage);
if (options.publishCustomVideoTrack) {
needPublish = true;

Check warning on line 156 in packages/rtc/src/engine/IrisClientObserver.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 157 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
break;
}
if (needPublish) {
irisClient.setLocalVideoTrack(trackPackage as VideoTrackPackage);
}
}

if (
publishTrack &&
needPublish &&
irisClient.agoraRTCClient?.channelName &&
!irisClient.agoraRTCClient.localTracks?.includes(publishTrack)
!irisClient.agoraRTCClient.localTracks?.includes(track)

Check warning on line 168 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
) {
try {
AgoraConsole.debug(`publishTrack ${publishTrack}`);
await irisClient.agoraRTCClient!.publish(publishTrack);
if (
trackPackage.type ===
IrisAudioSourceType.kAudioSourceTypeBufferSourceAudio
) {
(trackPackage as BufferSourceAudioTrackPackage).setIsPublished(
true
);
}
AgoraConsole.debug(`publishTrack ${track}`);
await irisClient.agoraRTCClient!.publish(track);
trackPackage.isPublished = true;
} catch (reason) {
AgoraConsole.error(reason);
}
Expand All @@ -198,19 +179,20 @@ export class IrisClientObserver {
}

async unpublishTrack(trackPackage: TrackPackage) {
if (!trackPackage.track) {
if (!trackPackage.track && !trackPackage.isPublished) {

Check warning on line 182 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
return;
}

Check warning on line 184 in packages/rtc/src/engine/IrisClientObserver.ts

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

let irisClient = trackPackage.irisClient;
let track = trackPackage.track as ILocalTrack;
if (!irisClient) {
return;
}
let agoraRTCClient = irisClient.agoraRTCClient;
let track = trackPackage.track as ILocalTrack;
if (agoraRTCClient?.localTracks?.includes(track)) {
AgoraConsole.debug(`unpublishTrack ${track}`);
await this._engine.clientHelper.unpublish(agoraRTCClient!, track);
trackPackage.isPublished = false;

Check warning on line 195 in packages/rtc/src/engine/IrisClientObserver.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 196 in packages/rtc/src/engine/IrisClientObserver.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
Loading

0 comments on commit 7c3535c

Please sign in to comment.