Skip to content

Commit

Permalink
fix: muteRemoteStream api
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Aug 7, 2024
1 parent 4921a8c commit 6bf5895
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 74 deletions.
42 changes: 3 additions & 39 deletions packages/rtc/src/engine/IrisClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
} from '../base/BaseType';
import { IrisTrackEventHandler } from '../event_handler/IrisTrackEventHandler';

import { AgoraConsole } from '../util';

import { IrisClient } from './IrisClient';
import { IrisClientObserver } from './IrisClientObserver';
import { IrisIntervalType, IrisRtcEngine } from './IrisRtcEngine';
Expand Down Expand Up @@ -548,19 +546,9 @@ export class IrisClientManager {
}

async processBufferSourceAudioTrackClose(
bufferSourceAudioTrackPackage: BufferSourceAudioTrackPackage,
agoraRTCClient?: IAgoraRTCClient
bufferSourceAudioTrackPackage: BufferSourceAudioTrackPackage
) {
let track = bufferSourceAudioTrackPackage.track;
if (agoraRTCClient?.localTracks?.indexOf(track) != -1) {
try {
await agoraRTCClient?.unpublish(track);
AgoraConsole.log('unpublish success');
} catch (e) {
this._engine.returnResult(false);
throw e;
}
}

//删除完毕后进行stop,close
track.stopProcessAudioBuffer();
Expand All @@ -569,20 +557,8 @@ export class IrisClientManager {
this.removeTrackEventHandlerByTrack(track);
}

async processAudioTrackClose(
audioTrackPackage: AudioTrackPackage,
agoraRTCClient?: IAgoraRTCClient
) {
async processAudioTrackClose(audioTrackPackage: AudioTrackPackage) {
let audioTrack = audioTrackPackage.track as ILocalAudioTrack;
if (agoraRTCClient?.localTracks?.indexOf(audioTrack) != -1) {
try {
await agoraRTCClient?.unpublish(audioTrack);
AgoraConsole.log('unpublish success');
} catch (e) {
this._engine.returnResult(false);
throw e;
}
}
//删除完毕后进行stop
if (audioTrack.isPlaying) {
this._engine.trackHelper.stop(audioTrack);
Expand All @@ -593,20 +569,8 @@ export class IrisClientManager {
this.removeTrackEventHandlerByTrack(audioTrack);
}

async processVideoTrackClose(
videoTrackPackage: VideoTrackPackage,
agoraRTCClient?: IAgoraRTCClient
) {
async processVideoTrackClose(videoTrackPackage: VideoTrackPackage) {
let videoTrack = videoTrackPackage.track as ILocalVideoTrack;
if (agoraRTCClient?.localTracks?.indexOf(videoTrack) != -1) {
try {
await agoraRTCClient?.unpublish(videoTrack);
AgoraConsole.log('unpublish success');
} catch (e) {
this._engine.returnResult(false);
throw e;
}
}

//如果isPreview是false则停止播放以及设置为不可用
if (!videoTrackPackage.isPreview) {
Expand Down
84 changes: 60 additions & 24 deletions packages/rtc/src/engine/IrisClientObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum NotifyType {
'UPDATE_TRACK',
'MUTE_TRACK',
'UNMUTE_TRACK',
'REMOVE_TRACK',
}
export enum NotifyRemoteType {
'SUBSCRIBE_VIDEO_TRACK',
Expand Down Expand Up @@ -200,8 +201,28 @@ export class IrisClientObserver {
}
}

async unpublishTrack(trackPackage: TrackPackage) {
if (!trackPackage.track) {
return;

Check warning on line 206 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 207 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;
if (!irisClient) {
return;
}
let agoraRTCClient = irisClient.agoraRTCClient;
let track = trackPackage.track as ILocalTrack;
if (agoraRTCClient?.localTracks?.indexOf(track) != -1) {

Check warning on line 215 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
AgoraConsole.debug(`unpublishTrack ${track}`);
if (!track?.enabled) {

Check warning on line 217 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
await this._engine.clientHelper.unpublish(agoraRTCClient!, track);
}
}
}

async enableTrack(trackPackage: TrackPackage) {
let track = trackPackage.track as ILocalTrack;
AgoraConsole.debug(`enableTrack ${track}`);
if (!track?.enabled) {
await this._engine.trackHelper.setEnabled(
trackPackage.track as ILocalTrack,
Expand All @@ -212,6 +233,7 @@ export class IrisClientObserver {

async unableTrack(trackPackage: TrackPackage) {
let track = trackPackage.track as ILocalTrack;
AgoraConsole.debug(`unableTrack ${track}`);
if (track?.enabled) {
await this._engine.trackHelper.setEnabled(
trackPackage.track as ILocalTrack,
Expand All @@ -222,6 +244,7 @@ export class IrisClientObserver {

async muteTrack(trackPackage: TrackPackage) {
let track = trackPackage.track as ILocalTrack;
AgoraConsole.debug(`muteTrack ${track}`);
if (!track?.muted) {
await this._engine.trackHelper.setMuted(
trackPackage.track as ILocalTrack,
Expand All @@ -232,6 +255,7 @@ export class IrisClientObserver {

async unmuteTrack(trackPackage: TrackPackage) {
let track = trackPackage.track as ILocalTrack;
AgoraConsole.debug(`unmuteTrack ${track}`);
if (track?.muted) {
await this._engine.trackHelper.setMuted(
trackPackage.track as ILocalTrack,
Expand All @@ -240,24 +264,22 @@ export class IrisClientObserver {
}
}

async stopTrack(trackPackage: TrackPackage) {
async removeTrack(trackPackage: TrackPackage) {
let irisClientManager = this._engine.irisClientManager;
try {
if (!trackPackage.track) {
return;
}

AgoraConsole.debug(`stopTrack ${trackPackage.track}`);
//还没有分配给对应的irisClient时,track会放到engine.initialize创建的client
AgoraConsole.debug(`removeTrack ${trackPackage.track}`);
let irisClient = trackPackage.irisClient;
if (!irisClient) {
irisClient = irisClientManager.irisClientList[0];
}
let agoraRTCClient = irisClient.agoraRTCClient;
this.unpublishTrack(trackPackage);
if (this._engine.implHelper.isAudio(trackPackage.type!)) {
await irisClientManager.processAudioTrackClose(
trackPackage as AudioTrackPackage,
agoraRTCClient
trackPackage as AudioTrackPackage
);
if (
trackPackage.type ===
Expand All @@ -276,20 +298,17 @@ export class IrisClientObserver {
trackPackage.type
) {
await irisClientManager.processBufferSourceAudioTrackClose(
trackPackage as BufferSourceAudioTrackPackage,
agoraRTCClient
trackPackage as BufferSourceAudioTrackPackage
);
irisClient.removeLocalAudioTrack(trackPackage);
irisClientManager.removeLocalAudioTrackPackage(trackPackage);
} else if (this._engine.implHelper.isVideoCamera(trackPackage.type!)) {
await irisClientManager.processVideoTrackClose(
trackPackage as VideoTrackPackage,
agoraRTCClient
trackPackage as VideoTrackPackage
);
} else if (this._engine.implHelper.isScreenCapture(trackPackage.type!)) {
await irisClientManager.processVideoTrackClose(
trackPackage as VideoTrackPackage,
agoraRTCClient
trackPackage as VideoTrackPackage
);
this._engine.rtcEngineEventHandler.onLocalVideoStateChanged_a44228a(
trackPackage.type as NATIVE_RTC.VIDEO_SOURCE_TYPE,
Expand Down Expand Up @@ -344,19 +363,24 @@ export class IrisClientObserver {

case NotifyType.UNPUBLISH_TRACK:
if (scopePackage) {
await this.stopTrack(scopePackage);
await this.unpublishTrack(scopePackage);
}
break;
case NotifyType.UPDATE_TRACK:
if (scopePackage) {
await this.updateTrack(scopePackage);
}
break;
case NotifyType.REMOVE_TRACK:
if (scopePackage) {
await this.removeTrack(scopePackage);
}
break;
}
}
}

subscribeVideoTrack(userPackage: RemoteUserPackage) {
subscribeVideoTrack(userPackage: RemoteUserPackage, force: boolean = false) {

Check warning on line 383 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 = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -365,8 +389,9 @@ export class IrisClientObserver {
}
let autoSubscribeVideo: boolean =
irisClient.irisClientState.autoSubscribeVideo;
let needSubscribe = autoSubscribeVideo || force;
let enableVideo: boolean = this._engine.globalState.enabledVideo;
if (enableVideo && autoSubscribeVideo && irisClient.agoraRTCClient) {
if (enableVideo && needSubscribe && irisClient.agoraRTCClient) {
let user = irisClient.agoraRTCClient.remoteUsers.find(
(item) => item.uid === userPackage.uid
);
Expand All @@ -393,7 +418,7 @@ export class IrisClientObserver {
});
}
}
subscribeAudioTrack(userPackage: RemoteUserPackage) {
subscribeAudioTrack(userPackage: RemoteUserPackage, force: boolean = false) {

Check warning on line 421 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 = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -402,8 +427,9 @@ export class IrisClientObserver {
}
let autoSubscribeAudio: boolean =
irisClient.irisClientState.autoSubscribeAudio;
let needSubscribe = autoSubscribeAudio || force;

Check warning on line 430 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 enableAudio: boolean = this._engine.globalState.enabledAudio;
if (enableAudio && autoSubscribeAudio && irisClient.agoraRTCClient) {
if (enableAudio && needSubscribe && irisClient.agoraRTCClient) {
let user = irisClient.agoraRTCClient.remoteUsers.find(
(item) => item.uid === userPackage.uid
);
Expand All @@ -426,7 +452,10 @@ export class IrisClientObserver {
}
}

unsubscribeVideoTrack(userPackage: RemoteUserPackage) {
unsubscribeVideoTrack(
userPackage: RemoteUserPackage,
force: boolean = false

Check warning on line 457 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 = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -447,7 +476,10 @@ export class IrisClientObserver {
}
}

unsubscribeAudioTrack(userPackage: RemoteUserPackage) {
unsubscribeAudioTrack(
userPackage: RemoteUserPackage,
force: boolean = false

Check warning on line 481 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 = this._engine.irisClientManager.getIrisClientByConnection(
userPackage.connection
);
Expand All @@ -468,27 +500,31 @@ export class IrisClientObserver {
}
}

notifyRemote(type: NotifyRemoteType, scopePackages: RemoteUserPackage[]) {
notifyRemote(
type: NotifyRemoteType,
scopePackages: RemoteUserPackage[],
force: boolean = false
) {
for (let scopePackage of scopePackages) {
switch (type) {
case NotifyRemoteType.SUBSCRIBE_VIDEO_TRACK:
if (scopePackage) {
this.subscribeVideoTrack(scopePackage);
this.subscribeVideoTrack(scopePackage, force);
}
break;
case NotifyRemoteType.SUBSCRIBE_AUDIO_TRACK:
if (scopePackage) {
this.subscribeAudioTrack(scopePackage);
this.subscribeAudioTrack(scopePackage, force);
}
break;
case NotifyRemoteType.UNSUBSCRIBE_AUDIO_TRACK:
if (scopePackage) {
this.unsubscribeAudioTrack(scopePackage);
this.unsubscribeAudioTrack(scopePackage, force);
}
break;
case NotifyRemoteType.UNSUBSCRIBE_VIDEO_TRACK:
if (scopePackage) {
this.unsubscribeVideoTrack(scopePackage);
this.unsubscribeVideoTrack(scopePackage, force);
}
break;
}
Expand Down
3 changes: 0 additions & 3 deletions packages/rtc/src/engine/IrisRtcEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ export class IrisRtcEngine implements ApiInterceptor {
let obj = this.implDispatchesMap.get(className);
if (obj) {
let callApiFun = obj[funName];
// if (apiParam.event === 'RtcEngine_joinChannelWithUserAccount_670ae7c3') {
// debugger;
// }
if (callApiFun) {
if (
func_name !== 'RtcEngine_initialize_0320339' &&
Expand Down
17 changes: 16 additions & 1 deletion packages/rtc/src/helper/ClientHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as NATIVE_RTC from '@iris/native-rtc';
import { ClientRole, IAgoraRTCClient } from 'agora-rtc-sdk-ng';
import { ClientRole, IAgoraRTCClient, ILocalTrack } from 'agora-rtc-sdk-ng';
import { CallIrisApiResult } from 'iris-web-core';

import { IrisRtcEngine } from '../engine/IrisRtcEngine';
Expand Down Expand Up @@ -81,4 +81,19 @@ export class ClientHelper {
throw e;
}
}

public async unpublish(
client: IAgoraRTCClient,
tracks?: ILocalTrack | ILocalTrack[]
): Promise<void> {
try {
await client.unpublish(tracks);
} catch (e) {
AgoraConsole.error(e);
Promise.resolve(
new CallIrisApiResult(-NATIVE_RTC.ERROR_CODE_TYPE.ERR_FAILED, e)
);
throw e;
}
}
}
3 changes: 3 additions & 0 deletions packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx {
options: NATIVE_RTC.LeaveChannelOptions
): CallApiReturnType {
let processFunc = async (): Promise<CallIrisApiResult> => {
if (!options) {
options = defaultLeaveChannelOptions;
}
if (this._engine.irisClientManager.irisClientList.length === 0) {
return this._engine.returnResult();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/rtc/src/impl/IAgoraRtcEngineImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
for (let irisClient of this._engine.irisClientManager.irisClientList) {
irisClient.irisClientState.autoSubscribeVideo = false;
await this._engine.irisClientManager.irisClientObserver.notifyLocal(
NotifyType.UNPUBLISH_TRACK,
NotifyType.REMOVE_TRACK,
[...this._engine.irisClientManager.localVideoTrackPackages],
[irisClient]
);
Expand Down Expand Up @@ -549,7 +549,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
for (let irisClient of this._engine.irisClientManager.irisClientList) {
irisClient.irisClientState.autoSubscribeAudio = false;
await this._engine.irisClientManager.irisClientObserver.notifyLocal(
NotifyType.UNPUBLISH_TRACK,
NotifyType.REMOVE_TRACK,
[...this._engine.irisClientManager.localAudioTrackPackages],
[irisClient]
);
Expand Down Expand Up @@ -921,7 +921,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
return this._engine.returnResult();
}
await this._engine.irisClientManager.irisClientObserver.notifyLocal(
NotifyType.UNPUBLISH_TRACK,
NotifyType.REMOVE_TRACK,
[bufferSourceAudioTrackPackage]
);

Expand Down Expand Up @@ -1018,7 +1018,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
}

await this._engine.irisClientManager.irisClientObserver.notifyLocal(
NotifyType.UNPUBLISH_TRACK,
NotifyType.REMOVE_TRACK,
[...videoPackages, ...audioPackages]
);

Expand Down
3 changes: 0 additions & 3 deletions scripts/terra/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ export function binding(parseResult: ParseResult) {
});

cxxfile.nodes = nodes.map((node: CXXTerraNode) => {
if (node.name === 'IRtcEngineEventHandler') {
// debugger;
}

let hasSupportApi = false;
node.asClazz().methods.map((method) => {
Expand Down

0 comments on commit 6bf5895

Please sign in to comment.