diff --git a/packages/rtc/src/engine/IrisClientManager.ts b/packages/rtc/src/engine/IrisClientManager.ts index d7675d0..4d4c5be 100644 --- a/packages/rtc/src/engine/IrisClientManager.ts +++ b/packages/rtc/src/engine/IrisClientManager.ts @@ -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'; @@ -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(); @@ -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); @@ -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) { diff --git a/packages/rtc/src/engine/IrisClientObserver.ts b/packages/rtc/src/engine/IrisClientObserver.ts index f1ea26d..63b9218 100644 --- a/packages/rtc/src/engine/IrisClientObserver.ts +++ b/packages/rtc/src/engine/IrisClientObserver.ts @@ -27,6 +27,7 @@ export enum NotifyType { 'UPDATE_TRACK', 'MUTE_TRACK', 'UNMUTE_TRACK', + 'REMOVE_TRACK', } export enum NotifyRemoteType { 'SUBSCRIBE_VIDEO_TRACK', @@ -200,8 +201,28 @@ export class IrisClientObserver { } } + async unpublishTrack(trackPackage: TrackPackage) { + if (!trackPackage.track) { + return; + } + + let irisClient = trackPackage.irisClient; + if (!irisClient) { + return; + } + let agoraRTCClient = irisClient.agoraRTCClient; + let track = trackPackage.track as ILocalTrack; + if (agoraRTCClient?.localTracks?.indexOf(track) != -1) { + AgoraConsole.debug(`unpublishTrack ${track}`); + if (!track?.enabled) { + 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, @@ -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, @@ -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, @@ -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, @@ -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 === @@ -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, @@ -344,7 +363,7 @@ export class IrisClientObserver { case NotifyType.UNPUBLISH_TRACK: if (scopePackage) { - await this.stopTrack(scopePackage); + await this.unpublishTrack(scopePackage); } break; case NotifyType.UPDATE_TRACK: @@ -352,11 +371,16 @@ export class IrisClientObserver { 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) { let irisClient = this._engine.irisClientManager.getIrisClientByConnection( userPackage.connection ); @@ -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 ); @@ -393,7 +418,7 @@ export class IrisClientObserver { }); } } - subscribeAudioTrack(userPackage: RemoteUserPackage) { + subscribeAudioTrack(userPackage: RemoteUserPackage, force: boolean = false) { let irisClient = this._engine.irisClientManager.getIrisClientByConnection( userPackage.connection ); @@ -402,8 +427,9 @@ export class IrisClientObserver { } let autoSubscribeAudio: boolean = irisClient.irisClientState.autoSubscribeAudio; + let needSubscribe = autoSubscribeAudio || force; 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 ); @@ -426,7 +452,10 @@ export class IrisClientObserver { } } - unsubscribeVideoTrack(userPackage: RemoteUserPackage) { + unsubscribeVideoTrack( + userPackage: RemoteUserPackage, + force: boolean = false + ) { let irisClient = this._engine.irisClientManager.getIrisClientByConnection( userPackage.connection ); @@ -447,7 +476,10 @@ export class IrisClientObserver { } } - unsubscribeAudioTrack(userPackage: RemoteUserPackage) { + unsubscribeAudioTrack( + userPackage: RemoteUserPackage, + force: boolean = false + ) { let irisClient = this._engine.irisClientManager.getIrisClientByConnection( userPackage.connection ); @@ -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; } diff --git a/packages/rtc/src/engine/IrisRtcEngine.ts b/packages/rtc/src/engine/IrisRtcEngine.ts index 94c3cdd..077aac7 100644 --- a/packages/rtc/src/engine/IrisRtcEngine.ts +++ b/packages/rtc/src/engine/IrisRtcEngine.ts @@ -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' && diff --git a/packages/rtc/src/helper/ClientHelper.ts b/packages/rtc/src/helper/ClientHelper.ts index 9a73d86..3879a3b 100644 --- a/packages/rtc/src/helper/ClientHelper.ts +++ b/packages/rtc/src/helper/ClientHelper.ts @@ -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'; @@ -81,4 +81,19 @@ export class ClientHelper { throw e; } } + + public async unpublish( + client: IAgoraRTCClient, + tracks?: ILocalTrack | ILocalTrack[] + ): Promise { + try { + await client.unpublish(tracks); + } catch (e) { + AgoraConsole.error(e); + Promise.resolve( + new CallIrisApiResult(-NATIVE_RTC.ERROR_CODE_TYPE.ERR_FAILED, e) + ); + throw e; + } + } } diff --git a/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts b/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts index 7615f68..d414f20 100644 --- a/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts +++ b/packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts @@ -80,6 +80,9 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx { options: NATIVE_RTC.LeaveChannelOptions ): CallApiReturnType { let processFunc = async (): Promise => { + if (!options) { + options = defaultLeaveChannelOptions; + } if (this._engine.irisClientManager.irisClientList.length === 0) { return this._engine.returnResult(); } diff --git a/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts b/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts index dfcf7b7..ca42d29 100644 --- a/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts +++ b/packages/rtc/src/impl/IAgoraRtcEngineImpl.ts @@ -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] ); @@ -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] ); @@ -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] ); @@ -1018,7 +1018,7 @@ export class IRtcEngineImpl implements IRtcEngineExtensions { } await this._engine.irisClientManager.irisClientObserver.notifyLocal( - NotifyType.UNPUBLISH_TRACK, + NotifyType.REMOVE_TRACK, [...videoPackages, ...audioPackages] ); diff --git a/scripts/terra/binding.ts b/scripts/terra/binding.ts index b4da4d0..5b0b148 100644 --- a/scripts/terra/binding.ts +++ b/scripts/terra/binding.ts @@ -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) => {