Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Aug 19, 2024
1 parent 5e55455 commit 055f0d5
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 279 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/IrisApiEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ApiInterceptor {
dispose(): Promise<void>;
}

class EventParam {
export class EventParam {
constructor(
event: string,
data: string,
Expand Down
11 changes: 3 additions & 8 deletions packages/rtc/src/engine/IrisClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,7 @@ export class IrisClientManager {
getIrisClientByConnection(connection: NATIVE_RTC.RtcConnection): IrisClient {
if (connection) {
return this.irisClientList.filter((irisClient: IrisClient) => {
if (
irisClient.connection?.channelId == connection.channelId &&
irisClient.connection?.localUid == connection.localUid
) {
if (irisClient.connection?.channelId == connection.channelId) {
return irisClient;
}
})[0];
Expand Down Expand Up @@ -540,10 +537,8 @@ export class IrisClientManager {
}
}

removeUserInfoByUserAccount(userAccount: string) {
const index = this.userInfoList.findIndex(
(user) => user.userAccount === userAccount
);
removeUserInfoByUid(uid: number) {
const index = this.userInfoList.findIndex((user) => user.uid === uid);
if (index !== -1) {
this.userInfoList.splice(index, 1);
}
Expand Down
35 changes: 14 additions & 21 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, ITrack } from 'agora-rtc-sdk-ng';
import { ILocalTrack, IMicrophoneAudioTrack } from 'agora-rtc-sdk-ng';

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

subscribeVideoTrack(userPackage: RemoteUserPackage, force: boolean) {
async subscribeVideoTrack(userPackage: RemoteUserPackage, force: boolean) {
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -392,15 +392,8 @@ export class IrisClientObserver {
if (!user || !user.hasVideo) {
return;
}
irisClient.agoraRTCClient.subscribe(user, 'video').then(() => {
await irisClient.agoraRTCClient.subscribe(user, 'video').then(() => {
AgoraConsole.debug('onEventUserPublished subscribe video success');
if (userPackage.element) {
this._engine.trackHelper.play(
user!.videoTrack as ITrack,
userPackage.element,
userPackage.videoPlayerConfig
);
}
let param: IrisTrackEventHandlerParam = {
client: irisClient.agoraRTCClient,
remoteUser: user!,
Expand All @@ -413,7 +406,7 @@ export class IrisClientObserver {
});
}
}
subscribeAudioTrack(userPackage: RemoteUserPackage, force: boolean) {
async subscribeAudioTrack(userPackage: RemoteUserPackage, force: boolean) {
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -431,7 +424,7 @@ export class IrisClientObserver {
if (!user || !user.hasAudio) {
return;
}
irisClient.agoraRTCClient.subscribe(user, 'audio').then(() => {
await irisClient.agoraRTCClient.subscribe(user, 'audio').then(() => {
AgoraConsole.debug('onEventUserPublished subscribe audio success');
this._engine.trackHelper.play(user!.audioTrack!);
let param: IrisTrackEventHandlerParam = {
Expand All @@ -447,7 +440,7 @@ export class IrisClientObserver {
}
}

unsubscribeVideoTrack(userPackage: RemoteUserPackage, force: boolean) {
async unsubscribeVideoTrack(userPackage: RemoteUserPackage, force: boolean) {
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -458,7 +451,7 @@ export class IrisClientObserver {
if (!user || !user.videoTrack) {
return;
}
irisClient.agoraRTCClient.unsubscribe(user, 'video').then(() => {
await irisClient.agoraRTCClient.unsubscribe(user, 'video').then(() => {
AgoraConsole.debug('onEventUserPublished unsubscribe video success');
this._engine.irisClientManager.removetrackEventHandlerByRemoteUser(
user!,
Expand All @@ -468,7 +461,7 @@ export class IrisClientObserver {
}
}

unsubscribeAudioTrack(userPackage: RemoteUserPackage, force: boolean) {
async unsubscribeAudioTrack(userPackage: RemoteUserPackage, force: boolean) {
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -479,7 +472,7 @@ export class IrisClientObserver {
if (!user || !user.audioTrack) {
return;
}
irisClient.agoraRTCClient.unsubscribe(user, 'audio').then(() => {
await irisClient.agoraRTCClient.unsubscribe(user, 'audio').then(() => {
AgoraConsole.debug('onEventUserPublished unsubscribe audio success');
this._engine.irisClientManager.removetrackEventHandlerByRemoteUser(
user!,
Expand All @@ -489,7 +482,7 @@ export class IrisClientObserver {
}
}

notifyRemote(
async notifyRemote(
type: NotifyRemoteType,
scopePackages: RemoteUserPackage[],
force: boolean = true
Expand All @@ -498,22 +491,22 @@ export class IrisClientObserver {
switch (type) {
case NotifyRemoteType.SUBSCRIBE_VIDEO_TRACK:
if (scopePackage) {
this.subscribeVideoTrack(scopePackage, force);
await this.subscribeVideoTrack(scopePackage, force);
}
break;
case NotifyRemoteType.SUBSCRIBE_AUDIO_TRACK:
if (scopePackage) {
this.subscribeAudioTrack(scopePackage, force);
await this.subscribeAudioTrack(scopePackage, force);
}
break;
case NotifyRemoteType.UNSUBSCRIBE_AUDIO_TRACK:
if (scopePackage) {
this.unsubscribeAudioTrack(scopePackage, force);
await this.unsubscribeAudioTrack(scopePackage, force);
}
break;
case NotifyRemoteType.UNSUBSCRIBE_VIDEO_TRACK:
if (scopePackage) {
this.unsubscribeVideoTrack(scopePackage, force);
await this.unsubscribeVideoTrack(scopePackage, force);
}
break;
}
Expand Down
Loading

0 comments on commit 055f0d5

Please sign in to comment.