Skip to content

Commit 1aad708

Browse files
committed
chore: optimize
1 parent 2071580 commit 1aad708

File tree

10 files changed

+1687
-93
lines changed

10 files changed

+1687
-93
lines changed

packages/rtc/src/binding/IAgoraRtcEngineDispatch.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,10 +3424,14 @@ export class IRtcEngineDispatch implements IRtcEngine {
34243424

34253425
// @ts-ignore
34263426
adjustRecordingSignalVolume(apiParam: ApiParam): CallApiReturnType {
3427-
AgoraConsole.warn(
3428-
'RtcEngine_adjustRecordingSignalVolume not supported in this platform!'
3429-
);
3430-
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
3427+
let obj = JSON.parse(apiParam.data) as any;
3428+
let volume = obj.volume;
3429+
if (volume === undefined) {
3430+
AgoraConsole.error('volume is undefined');
3431+
throw 'volume is undefined';
3432+
}
3433+
3434+
return this._impl.adjustRecordingSignalVolume(volume);
34313435
}
34323436

34333437
// @ts-ignore
@@ -3440,18 +3444,31 @@ export class IRtcEngineDispatch implements IRtcEngine {
34403444

34413445
// @ts-ignore
34423446
adjustPlaybackSignalVolume(apiParam: ApiParam): CallApiReturnType {
3443-
AgoraConsole.warn(
3444-
'RtcEngine_adjustPlaybackSignalVolume not supported in this platform!'
3445-
);
3446-
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
3447+
let obj = JSON.parse(apiParam.data) as any;
3448+
let volume = obj.volume;
3449+
if (volume === undefined) {
3450+
AgoraConsole.error('volume is undefined');
3451+
throw 'volume is undefined';
3452+
}
3453+
3454+
return this._impl.adjustPlaybackSignalVolume(volume);
34473455
}
34483456

34493457
// @ts-ignore
34503458
adjustUserPlaybackSignalVolume(apiParam: ApiParam): CallApiReturnType {
3451-
AgoraConsole.warn(
3452-
'RtcEngine_adjustUserPlaybackSignalVolume not supported in this platform!'
3453-
);
3454-
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
3459+
let obj = JSON.parse(apiParam.data) as any;
3460+
let uid = obj.uid;
3461+
if (uid === undefined) {
3462+
AgoraConsole.error('uid is undefined');
3463+
throw 'uid is undefined';
3464+
}
3465+
let volume = obj.volume;
3466+
if (volume === undefined) {
3467+
AgoraConsole.error('volume is undefined');
3468+
throw 'volume is undefined';
3469+
}
3470+
3471+
return this._impl.adjustUserPlaybackSignalVolume(uid, volume);
34553472
}
34563473

34573474
// @ts-ignore

packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,19 @@ export class IRtcEngineExDispatch extends IRtcEngineDispatch
332332

333333
// @ts-ignore
334334
adjustRecordingSignalVolumeEx(apiParam: ApiParam): CallApiReturnType {
335-
AgoraConsole.warn(
336-
'RtcEngineEx_adjustRecordingSignalVolumeEx not supported in this platform!'
337-
);
338-
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
335+
let obj = JSON.parse(apiParam.data) as any;
336+
let volume = obj.volume;
337+
if (volume === undefined) {
338+
AgoraConsole.error('volume is undefined');
339+
throw 'volume is undefined';
340+
}
341+
let connection = obj.connection;
342+
if (connection === undefined) {
343+
AgoraConsole.error('connection is undefined');
344+
throw 'connection is undefined';
345+
}
346+
347+
return this._impl.adjustRecordingSignalVolumeEx(volume, connection);
339348
}
340349

341350
// @ts-ignore
@@ -348,10 +357,24 @@ export class IRtcEngineExDispatch extends IRtcEngineDispatch
348357

349358
// @ts-ignore
350359
adjustUserPlaybackSignalVolumeEx(apiParam: ApiParam): CallApiReturnType {
351-
AgoraConsole.warn(
352-
'RtcEngineEx_adjustUserPlaybackSignalVolumeEx not supported in this platform!'
353-
);
354-
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
360+
let obj = JSON.parse(apiParam.data) as any;
361+
let uid = obj.uid;
362+
if (uid === undefined) {
363+
AgoraConsole.error('uid is undefined');
364+
throw 'uid is undefined';
365+
}
366+
let volume = obj.volume;
367+
if (volume === undefined) {
368+
AgoraConsole.error('volume is undefined');
369+
throw 'volume is undefined';
370+
}
371+
let connection = obj.connection;
372+
if (connection === undefined) {
373+
AgoraConsole.error('connection is undefined');
374+
throw 'connection is undefined';
375+
}
376+
377+
return this._impl.adjustUserPlaybackSignalVolumeEx(uid, volume, connection);
355378
}
356379

357380
// @ts-ignore
@@ -440,10 +463,34 @@ export class IRtcEngineExDispatch extends IRtcEngineDispatch
440463

441464
// @ts-ignore
442465
enableAudioVolumeIndicationEx(apiParam: ApiParam): CallApiReturnType {
443-
AgoraConsole.warn(
444-
'RtcEngineEx_enableAudioVolumeIndicationEx not supported in this platform!'
466+
let obj = JSON.parse(apiParam.data) as any;
467+
let interval = obj.interval;
468+
if (interval === undefined) {
469+
AgoraConsole.error('interval is undefined');
470+
throw 'interval is undefined';
471+
}
472+
let smooth = obj.smooth;
473+
if (smooth === undefined) {
474+
AgoraConsole.error('smooth is undefined');
475+
throw 'smooth is undefined';
476+
}
477+
let reportVad = obj.reportVad;
478+
if (reportVad === undefined) {
479+
AgoraConsole.error('reportVad is undefined');
480+
throw 'reportVad is undefined';
481+
}
482+
let connection = obj.connection;
483+
if (connection === undefined) {
484+
AgoraConsole.error('connection is undefined');
485+
throw 'connection is undefined';
486+
}
487+
488+
return this._impl.enableAudioVolumeIndicationEx(
489+
interval,
490+
smooth,
491+
reportVad,
492+
connection
445493
);
446-
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
447494
}
448495

449496
// @ts-ignore

packages/rtc/src/helper/TrackHelper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CallIrisApiResult } from 'iris-web-core';
1313
import { IrisRtcEngine } from '../engine/IrisRtcEngine';
1414

1515
import { AgoraConsole } from '../util/AgoraConsole';
16+
import { AgoraTranslate } from '../util/AgoraTranslate';
1617

1718
export class TrackHelper {
1819
_engine: IrisRtcEngine;
@@ -104,4 +105,15 @@ export class TrackHelper {
104105
throw e;
105106
}
106107
}
108+
109+
public setVolume(
110+
track: ILocalAudioTrack | IRemoteAudioTrack,
111+
volume: number
112+
): void {
113+
try {
114+
track?.setVolume(AgoraTranslate.NATIVE_RTC_Volume2WebVolume(volume));
115+
} catch (e) {
116+
AgoraConsole.error(e);
117+
}
118+
}
107119
}

packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,99 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx {
422422
}
423423
return this._engine.returnResult();
424424
}
425+
426+
enableAudioVolumeIndicationEx(
427+
interval: number,
428+
smooth: number,
429+
reportVad: boolean,
430+
connection: NATIVE_RTC.RtcConnection
431+
): CallApiReturnType {
432+
let processFunc = async (): Promise<CallIrisApiResult> => {
433+
this._engine.globalState.enableAudioVolumeIndicationConfig = {
434+
...this._engine.globalState.enableAudioVolumeIndicationConfig,
435+
...(interval && { interval }),
436+
...(smooth && { smooth }),
437+
...(reportVad && { reportVad }),
438+
};
439+
440+
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
441+
connection
442+
);
443+
444+
let agoraRTCClient = irisClient?.agoraRTCClient;
445+
446+
if (!agoraRTCClient) {
447+
return this._engine.irisRtcErrorHandler.notInChannel();
448+
}
449+
450+
this._engine.globalState.enableAudioVolumeIndication = interval > 0;
451+
452+
if (this._engine.globalState.enableAudioVolumeIndication) {
453+
this._engine
454+
.getImplInstance('RtcEngine')
455+
.setParameters(
456+
JSON.stringify({ AUDIO_VOLUME_INDICATION_INTERVAL: interval })
457+
);
458+
agoraRTCClient?.enableAudioVolumeIndicator();
459+
}
460+
return this._engine.returnResult();
461+
};
462+
return this._engine.execute(processFunc);
463+
}
464+
465+
adjustUserPlaybackSignalVolumeEx(
466+
uid: number,
467+
volume: number,
468+
connection: NATIVE_RTC.RtcConnection
469+
): CallApiReturnType {
470+
let fun = async () => {
471+
try {
472+
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
473+
connection
474+
);
475+
if (irisClient) {
476+
let user = irisClient.agoraRTCClient?.remoteUsers.find(
477+
(item) => item.uid === uid
478+
);
479+
if (user?.hasAudio && user.audioTrack) {
480+
this._engine.trackHelper.setVolume(user.audioTrack, volume);
481+
}
482+
}
483+
} catch (e) {
484+
AgoraConsole.log(e);
485+
return this._engine.returnResult(false);
486+
}
487+
return this._engine.returnResult();
488+
};
489+
return this._engine.execute(fun);
490+
}
491+
492+
adjustRecordingSignalVolumeEx(
493+
volume: number,
494+
connection: NATIVE_RTC.RtcConnection
495+
): CallApiReturnType {
496+
let fun = async () => {
497+
try {
498+
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
499+
connection
500+
);
501+
irisClient?.audioTrackPackages.map((audioTrackPackage) => {
502+
if (
503+
audioTrackPackage.track &&
504+
this._engine.implHelper.isAudio(audioTrackPackage.type)
505+
) {
506+
this._engine.trackHelper.setVolume(
507+
audioTrackPackage.track as ILocalAudioTrack,
508+
volume
509+
);
510+
}
511+
});
512+
} catch (e) {
513+
AgoraConsole.log(e);
514+
return this._engine.returnResult(false);
515+
}
516+
return this._engine.returnResult();
517+
};
518+
return this._engine.execute(fun);
519+
}
425520
}

packages/rtc/src/impl/IAgoraRtcEngineImpl.ts

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -735,27 +735,14 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
735735
smooth: number,
736736
reportVad: boolean
737737
): CallApiReturnType {
738-
let processFunc = async (): Promise<CallIrisApiResult> => {
739-
this._engine.globalState.enableAudioVolumeIndicationConfig = {
740-
...this._engine.globalState.enableAudioVolumeIndicationConfig,
741-
...(interval && { interval }),
742-
...(smooth && { smooth }),
743-
...(reportVad && { reportVad }),
744-
};
745-
let agoraRTCClient = this._engine.irisClientManager.getIrisClient()
746-
?.agoraRTCClient;
747-
748-
this._engine.globalState.enableAudioVolumeIndication = interval > 0;
749-
750-
if (this._engine.globalState.enableAudioVolumeIndication) {
751-
this.setParameters(
752-
JSON.stringify({ AUDIO_VOLUME_INDICATION_INTERVAL: interval })
753-
);
754-
agoraRTCClient?.enableAudioVolumeIndicator();
755-
}
756-
return this._engine.returnResult();
757-
};
758-
return this._engine.execute(processFunc);
738+
return this._engine
739+
.getImplInstance('RtcEngineEx')
740+
.enableAudioVolumeIndicationEx(
741+
interval,
742+
smooth,
743+
reportVad,
744+
this._engine.irisClientManager.getIrisClient()?.connection
745+
);
759746
}
760747
playEffect(
761748
soundId: number,
@@ -1228,4 +1215,80 @@ export class IRtcEngineImpl implements IRtcEngineExtensions {
12281215
};
12291216
return this._engine.execute(fun);
12301217
}
1218+
1219+
adjustPlaybackSignalVolume(volume: number): CallApiReturnType {
1220+
let fun = async () => {
1221+
try {
1222+
this._engine.irisClientManager.irisClientList.map((irisClient) => {
1223+
irisClient.agoraRTCClient?.remoteUsers.map((remoteUser) => {
1224+
if (remoteUser.hasAudio && remoteUser.audioTrack) {
1225+
this._engine.trackHelper.setVolume(remoteUser.audioTrack, volume);
1226+
}
1227+
});
1228+
});
1229+
} catch (e) {
1230+
AgoraConsole.log(e);
1231+
return this._engine.returnResult(false);
1232+
}
1233+
return this._engine.returnResult();
1234+
};
1235+
return this._engine.execute(fun);
1236+
}
1237+
1238+
adjustRecordingSignalVolume(volume: number): CallApiReturnType {
1239+
let fun = async () => {
1240+
try {
1241+
this._engine.irisClientManager.localAudioTrackPackages.map(
1242+
(audioTrackPackage) => {
1243+
if (
1244+
audioTrackPackage.track &&
1245+
this._engine.implHelper.isAudio(audioTrackPackage.type)
1246+
) {
1247+
this._engine.trackHelper.setVolume(
1248+
audioTrackPackage.track as ILocalAudioTrack,
1249+
volume
1250+
);
1251+
}
1252+
}
1253+
);
1254+
} catch (e) {
1255+
AgoraConsole.log(e);
1256+
return this._engine.returnResult(false);
1257+
}
1258+
return this._engine.returnResult();
1259+
};
1260+
return this._engine.execute(fun);
1261+
}
1262+
1263+
adjustUserPlaybackSignalVolume(
1264+
uid: number,
1265+
volume: number
1266+
): CallApiReturnType {
1267+
let fun = async () => {
1268+
try {
1269+
this._engine.irisClientManager.remoteUserPackages.map(
1270+
(remoteUserPackage) => {
1271+
if (remoteUserPackage.uid === uid) {
1272+
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
1273+
remoteUserPackage.connection
1274+
);
1275+
if (irisClient) {
1276+
let user = irisClient.agoraRTCClient?.remoteUsers.find(
1277+
(item) => item.uid === remoteUserPackage.uid
1278+
);
1279+
if (user?.hasAudio && user.audioTrack) {
1280+
this._engine.trackHelper.setVolume(user.audioTrack, volume);
1281+
}
1282+
}
1283+
}
1284+
}
1285+
);
1286+
} catch (e) {
1287+
AgoraConsole.log(e);
1288+
return this._engine.returnResult(false);
1289+
}
1290+
return this._engine.returnResult();
1291+
};
1292+
return this._engine.execute(fun);
1293+
}
12311294
}

0 commit comments

Comments
 (0)