From cd0b4ca23b5943c37f778839459d1c3779708fce Mon Sep 17 00:00:00 2001 From: gxz Date: Thu, 18 Jan 2024 12:04:29 +0800 Subject: [PATCH] chore: optimize --- scripts/terra/generate-code.sh | 1 + src/internal/IrisApiEngine.ts | 24 ++--- .../LocalSpatialAudioEngineInternal.ts | 87 +------------------ src/internal/MediaPlayerInternal.ts | 4 +- src/internal/MusicContentCenterInternal.ts | 4 +- src/internal/RtcEngineExInternal.ts | 66 +++++++++----- 6 files changed, 63 insertions(+), 123 deletions(-) diff --git a/scripts/terra/generate-code.sh b/scripts/terra/generate-code.sh index 6780bf53c..f6180ea86 100644 --- a/scripts/terra/generate-code.sh +++ b/scripts/terra/generate-code.sh @@ -7,6 +7,7 @@ PROJECT_ROOT=$(realpath ${MY_PATH}/../..) rm -rf node_modules rm -rf .terra +yarn npm exec terra -- run \ --config ${PROJECT_ROOT}/scripts/terra/config/types_config.yaml \ diff --git a/src/internal/IrisApiEngine.ts b/src/internal/IrisApiEngine.ts index d13ab50c4..7709327ea 100644 --- a/src/internal/IrisApiEngine.ts +++ b/src/internal/IrisApiEngine.ts @@ -392,6 +392,11 @@ function handleEvent({ event, data, buffers }: any) { _event = _event.replace(/Ex$/g, ''); } + // for new IrisType, but this is temporary + if (_event.includes('_')) { + _event = _event.substring(0, _event.indexOf('_')); + } + const _buffers: Uint8Array[] = (buffers as string[])?.map((value) => { return Buffer.from(value, 'base64'); }); @@ -421,16 +426,13 @@ export function callIrisApi(funcName: string, params: any): any { if (funcName.startsWith('MediaEngine_')) { switch (funcName) { - case 'MediaEngine_pushAudioFrame': - case 'MediaEngine_pushCaptureAudioFrame': - case 'MediaEngine_pushReverseAudioFrame': - case 'MediaEngine_pushDirectAudioFrame': + case 'MediaEngine_pushAudioFrame_c71f4ab': // frame.buffer buffers.push( base64.fromByteArray(params.frame.buffer ?? Buffer.from('')) ); break; - case 'MediaEngine_pushVideoFrame': + case 'MediaEngine_pushVideoFrame_4e544e2': // frame.buffer buffers.push( base64.fromByteArray(params.frame.buffer ?? Buffer.from('')) @@ -446,7 +448,7 @@ export function callIrisApi(funcName: string, params: any): any { // frame.d3d11_texture_2d buffers.push(base64.fromByteArray(Buffer.from(''))); break; - case 'MediaEngine_pushEncodedVideoImage': + case 'MediaEngine_pushEncodedVideoImage_e71452b': // imageBuffer buffers.push( base64.fromByteArray(params.imageBuffer ?? Buffer.from('')) @@ -472,7 +474,7 @@ export function callIrisApi(funcName: string, params: any): any { }; } else if (funcName.startsWith('RtcEngine_')) { switch (funcName) { - case 'RtcEngine_initialize': + case 'RtcEngine_initialize_0320339': AgoraRtcNg.newIrisApiEngine(); break; case 'RtcEngine_release': @@ -489,18 +491,18 @@ export function callIrisApi(funcName: string, params: any): any { base64.fromByteArray(params.metadata.buffer ?? Buffer.from('')) ); break; - case 'RtcEngine_sendStreamMessage': - case 'RtcEngine_sendStreamMessageEx': + case 'RtcEngine_sendStreamMessage_8715a45': + case 'RtcEngineEx_sendStreamMessageEx_0c34857': // data buffers.push(base64.fromByteArray(params.data ?? Buffer.from(''))); break; - case 'RtcEngine_destroyMediaPlayer': + case 'RtcEngine_destroyMediaPlayer_328a49b': params.mediaPlayerId = params.media_player.getMediaPlayerId(); params.toJSON = function () { return { playerId: params.mediaPlayerId }; }; break; - case 'RtcEngine_destroyMediaRecorder': + case 'RtcEngine_destroyMediaRecorder_95cdef5': // @ts-ignore params.nativeHandle = ( params.mediaRecorder as MediaRecorderInternal diff --git a/src/internal/LocalSpatialAudioEngineInternal.ts b/src/internal/LocalSpatialAudioEngineInternal.ts index 17b0acfe0..ba3f51fa7 100644 --- a/src/internal/LocalSpatialAudioEngineInternal.ts +++ b/src/internal/LocalSpatialAudioEngineInternal.ts @@ -1,88 +1,3 @@ -import { RtcConnection } from '../IAgoraRtcEngineEx'; -import { - RemoteVoicePositionInfo, - SpatialAudioZone, -} from '../IAgoraSpatialAudio'; import { ILocalSpatialAudioEngineImpl } from '../impl/IAgoraSpatialAudioImpl'; -export class LocalSpatialAudioEngineInternal extends ILocalSpatialAudioEngineImpl { - protected override getApiTypeFromRelease(): string { - return 'LocalSpatialAudioEngine_release'; - } - - protected override getApiTypeFromSetMaxAudioRecvCount( - maxCount: number - ): string { - return 'LocalSpatialAudioEngine_setMaxAudioRecvCount'; - } - - protected override getApiTypeFromSetAudioRecvRange(range: number): string { - return 'LocalSpatialAudioEngine_setAudioRecvRange'; - } - - protected override getApiTypeFromSetDistanceUnit(unit: number): string { - return 'LocalSpatialAudioEngine_setDistanceUnit'; - } - - protected override getApiTypeFromUpdateSelfPosition( - position: number[], - axisForward: number[], - axisRight: number[], - axisUp: number[] - ): string { - return 'LocalSpatialAudioEngine_updateSelfPosition'; - } - - protected override getApiTypeFromUpdateSelfPositionEx( - position: number[], - axisForward: number[], - axisRight: number[], - axisUp: number[], - connection: RtcConnection - ): string { - return 'LocalSpatialAudioEngine_updateSelfPositionEx'; - } - - protected override getApiTypeFromUpdatePlayerPositionInfo( - playerId: number, - positionInfo: RemoteVoicePositionInfo - ): string { - return 'LocalSpatialAudioEngine_updatePlayerPositionInfo'; - } - - protected override getApiTypeFromSetParameters(params: string): string { - return 'LocalSpatialAudioEngine_setParameters'; - } - - protected override getApiTypeFromMuteLocalAudioStream(mute: boolean): string { - return 'LocalSpatialAudioEngine_muteLocalAudioStream'; - } - - protected override getApiTypeFromMuteAllRemoteAudioStreams( - mute: boolean - ): string { - return 'LocalSpatialAudioEngine_muteAllRemoteAudioStreams'; - } - - protected override getApiTypeFromSetZones( - zones: SpatialAudioZone[], - zoneCount: number - ): string { - return 'LocalSpatialAudioEngine_setZones'; - } - - protected override getApiTypeFromSetPlayerAttenuation( - playerId: number, - attenuation: number, - forceSet: boolean - ): string { - return 'LocalSpatialAudioEngine_setPlayerAttenuation'; - } - - protected override getApiTypeFromMuteRemoteAudioStream( - uid: number, - mute: boolean - ): string { - return 'LocalSpatialAudioEngine_muteRemoteAudioStream'; - } -} +export class LocalSpatialAudioEngineInternal extends ILocalSpatialAudioEngineImpl {} diff --git a/src/internal/MediaPlayerInternal.ts b/src/internal/MediaPlayerInternal.ts index 5dde92c4c..89d330ef1 100644 --- a/src/internal/MediaPlayerInternal.ts +++ b/src/internal/MediaPlayerInternal.ts @@ -288,13 +288,13 @@ export class MediaPlayerInternal extends IMediaPlayerImpl { key: string, value: number ): string { - return 'MediaPlayer_setPlayerOption'; + return 'MediaPlayer_setPlayerOption_4d05d29'; } protected override getApiTypeFromSetPlayerOptionInString( key: string, value: string ): string { - return 'MediaPlayer_setPlayerOption2'; + return 'MediaPlayer_setPlayerOption_ccad422'; } } diff --git a/src/internal/MusicContentCenterInternal.ts b/src/internal/MusicContentCenterInternal.ts index 2562a1323..f28fce8e1 100644 --- a/src/internal/MusicContentCenterInternal.ts +++ b/src/internal/MusicContentCenterInternal.ts @@ -106,7 +106,7 @@ export class MusicContentCenterInternal extends IMusicContentCenterImpl { } protected override getApiTypeFromPreload(songCode: number): string { - return 'MusicContentCenter_preload2'; + return 'MusicContentCenter_preload_d3baeab'; } } @@ -126,7 +126,7 @@ class _MusicPlayerInternal extends IMusicPlayerImpl { songCode: number, startPos = 0 ): string { - return 'MusicPlayer_open'; + return 'MusicPlayer_open_303b92e'; } } diff --git a/src/internal/RtcEngineExInternal.ts b/src/internal/RtcEngineExInternal.ts index ef83c663c..ad0f82070 100644 --- a/src/internal/RtcEngineExInternal.ts +++ b/src/internal/RtcEngineExInternal.ts @@ -2,7 +2,9 @@ import { createCheckers } from 'ts-interface-checker'; import { AudioEncodedFrameObserverConfig, + AudioProfileType, AudioRecordingConfiguration, + AudioScenarioType, ClientRoleOptions, ClientRoleType, DataStreamConfig, @@ -13,7 +15,11 @@ import { SimulcastStreamMode, WatermarkOptions, } from '../AgoraBase'; -import { IAudioSpectrumObserver, VideoSourceType } from '../AgoraMediaBase'; +import { + IAudioSpectrumObserver, + MediaSourceType, + VideoSourceType, +} from '../AgoraMediaBase'; import { IH265Transcoder } from '../IAgoraH265Transcoder'; import { IMediaEngine } from '../IAgoraMediaEngine'; import { IMediaPlayer } from '../IAgoraMediaPlayer'; @@ -195,7 +201,7 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { } override getVersion(): SDKBuildInfo { - const apiType = 'RtcEngine_getVersion'; + const apiType = 'RtcEngine_getVersion_915cb25'; const jsonParams = {}; const jsonResults = callIrisApi.call(this, apiType, jsonParams); return { @@ -297,7 +303,7 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { uid: number, options: ChannelMediaOptions ): string { - return 'RtcEngine_joinChannel2'; + return 'RtcEngine_joinChannel_cdbb747'; } protected override getApiTypeFromLeaveChannel( @@ -305,7 +311,7 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { ): string { return options === undefined ? 'RtcEngine_leaveChannel' - : 'RtcEngine_leaveChannel2'; + : 'RtcEngine_leaveChannel_2c0e3aa'; } protected override getApiTypeFromSetClientRole( @@ -313,20 +319,20 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { options?: ClientRoleOptions ): string { return options === undefined - ? 'RtcEngine_setClientRole' - : 'RtcEngine_setClientRole2'; + ? 'RtcEngine_setClientRole_3426fa6' + : 'RtcEngine_setClientRole_b46cc48'; } protected override getApiTypeFromStartEchoTest( config: EchoTestConfiguration ): string { - return 'RtcEngine_startEchoTest3'; + return 'RtcEngine_startEchoTest_16140d7'; } protected override getApiTypeFromStartPreview( sourceType: VideoSourceType = VideoSourceType.VideoSourceCameraPrimary ): string { - return 'RtcEngine_startPreview2'; + return 'RtcEngine_startPreview_4fd718e'; } protected override getApiTypeFromStartPreviewWithoutSourceType(): string { @@ -336,13 +342,13 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { protected override getApiTypeFromStopPreview( sourceType: VideoSourceType = VideoSourceType.VideoSourceCameraPrimary ): string { - return 'RtcEngine_stopPreview2'; + return 'RtcEngine_stopPreview_4fd718e'; } protected override getApiTypeFromStartAudioRecording( config: AudioRecordingConfiguration ): string { - return 'RtcEngine_startAudioRecording3'; + return 'RtcEngine_startAudioRecording_e32bb3b'; } protected override getApiTypeFromStartAudioMixing( @@ -351,7 +357,7 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { cycle: number, startPos: number = 0 ): string { - return 'RtcEngine_startAudioMixing2'; + return 'RtcEngine_startAudioMixing_1ee1b1e'; } protected override getApiTypeFromEnableDualStreamMode( @@ -359,8 +365,8 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { streamConfig?: SimulcastStreamConfig ): string { return streamConfig === undefined - ? 'RtcEngine_enableDualStreamMode' - : 'RtcEngine_enableDualStreamMode2'; + ? 'RtcEngine_enableDualStreamMode_5039d15' + : 'RtcEngine_enableDualStreamMode_9822d8a'; } protected override getApiTypeFromSetDualStreamMode( @@ -368,28 +374,28 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { streamConfig?: SimulcastStreamConfig ): string { return streamConfig === undefined - ? 'RtcEngine_setDualStreamMode' - : 'RtcEngine_setDualStreamMode2'; + ? 'RtcEngine_setDualStreamMode_3a7f662' + : 'RtcEngine_setDualStreamMode_b3a4f6c'; } protected override getApiTypeFromLeaveChannelEx( connection: RtcConnection, options?: LeaveChannelOptions ): string { - return 'RtcEngineEx_leaveChannelEx2'; + return 'RtcEngineEx_leaveChannelEx_b03ee9a'; } protected override getApiTypeFromCreateDataStream( config: DataStreamConfig ): string { - return 'RtcEngine_createDataStream2'; + return 'RtcEngine_createDataStream_5862815'; } protected override getApiTypeFromAddVideoWatermark( watermarkUrl: string, options: WatermarkOptions ): string { - return 'RtcEngine_addVideoWatermark2'; + return 'RtcEngine_addVideoWatermark_7480410'; } protected override getApiTypeFromJoinChannelWithUserAccount( @@ -399,15 +405,15 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { options?: ChannelMediaOptions ): string { return options === undefined - ? 'RtcEngine_joinChannelWithUserAccount' - : 'RtcEngine_joinChannelWithUserAccount2'; + ? 'RtcEngine_joinChannelWithUserAccount_0e4f59e' + : 'RtcEngine_joinChannelWithUserAccount_4685af9'; } protected override getApiTypeFromCreateDataStreamEx( config: DataStreamConfig, connection: RtcConnection ): string { - return 'RtcEngineEx_createDataStreamEx2'; + return 'RtcEngineEx_createDataStreamEx_9f641b6'; } protected override getApiTypeFromPreloadChannelWithUserAccount( @@ -415,7 +421,7 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { channelId: string, userAccount: string ): string { - return 'RtcEngine_preloadChannel2'; + return 'RtcEngine_startScreenCapture_9ebb320'; } override getAudioDeviceManager(): IAudioDeviceManager { @@ -488,4 +494,20 @@ export class RtcEngineExInternal extends IRtcEngineExImpl { ); return super.unregisterAudioSpectrumObserver(observer); } + + protected override getApiTypeFromEnableExtension( + provider: string, + extension: string, + enable: boolean = true, + type: MediaSourceType = MediaSourceType.UnknownMediaSource + ): string { + return 'RtcEngine_enableExtension_0b60a2c'; + } + + protected override getApiTypeFromSetAudioProfile( + profile: AudioProfileType, + scenario: AudioScenarioType = AudioScenarioType.AudioScenarioDefault + ): string { + return 'RtcEngine_setAudioProfile_d944543'; + } }