Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Jan 18, 2024
1 parent 4d5b6d0 commit cd0b4ca
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 123 deletions.
1 change: 1 addition & 0 deletions scripts/terra/generate-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
24 changes: 13 additions & 11 deletions src/internal/IrisApiEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down Expand Up @@ -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(''))
Expand All @@ -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(''))
Expand All @@ -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':
Expand All @@ -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
Expand Down
87 changes: 1 addition & 86 deletions src/internal/LocalSpatialAudioEngineInternal.ts
Original file line number Diff line number Diff line change
@@ -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 {}
4 changes: 2 additions & 2 deletions src/internal/MediaPlayerInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
4 changes: 2 additions & 2 deletions src/internal/MusicContentCenterInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class MusicContentCenterInternal extends IMusicContentCenterImpl {
}

protected override getApiTypeFromPreload(songCode: number): string {
return 'MusicContentCenter_preload2';
return 'MusicContentCenter_preload_d3baeab';
}
}

Expand All @@ -126,7 +126,7 @@ class _MusicPlayerInternal extends IMusicPlayerImpl {
songCode: number,
startPos = 0
): string {
return 'MusicPlayer_open';
return 'MusicPlayer_open_303b92e';
}
}

Expand Down
66 changes: 44 additions & 22 deletions src/internal/RtcEngineExInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { createCheckers } from 'ts-interface-checker';

import {
AudioEncodedFrameObserverConfig,
AudioProfileType,
AudioRecordingConfiguration,
AudioScenarioType,
ClientRoleOptions,
ClientRoleType,
DataStreamConfig,
Expand All @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -297,36 +303,36 @@ export class RtcEngineExInternal extends IRtcEngineExImpl {
uid: number,
options: ChannelMediaOptions
): string {
return 'RtcEngine_joinChannel2';
return 'RtcEngine_joinChannel_cdbb747';
}

protected override getApiTypeFromLeaveChannel(
options?: LeaveChannelOptions
): string {
return options === undefined
? 'RtcEngine_leaveChannel'
: 'RtcEngine_leaveChannel2';
: 'RtcEngine_leaveChannel_2c0e3aa';
}

protected override getApiTypeFromSetClientRole(
role: ClientRoleType,
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 {
Expand All @@ -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(
Expand All @@ -351,45 +357,45 @@ export class RtcEngineExInternal extends IRtcEngineExImpl {
cycle: number,
startPos: number = 0
): string {
return 'RtcEngine_startAudioMixing2';
return 'RtcEngine_startAudioMixing_1ee1b1e';
}

protected override getApiTypeFromEnableDualStreamMode(
enabled: boolean,
streamConfig?: SimulcastStreamConfig
): string {
return streamConfig === undefined
? 'RtcEngine_enableDualStreamMode'
: 'RtcEngine_enableDualStreamMode2';
? 'RtcEngine_enableDualStreamMode_5039d15'
: 'RtcEngine_enableDualStreamMode_9822d8a';
}

protected override getApiTypeFromSetDualStreamMode(
mode: SimulcastStreamMode,
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(
Expand All @@ -399,23 +405,23 @@ 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(
token: string,
channelId: string,
userAccount: string
): string {
return 'RtcEngine_preloadChannel2';
return 'RtcEngine_startScreenCapture_9ebb320';
}

override getAudioDeviceManager(): IAudioDeviceManager {
Expand Down Expand Up @@ -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';
}
}

0 comments on commit cd0b4ca

Please sign in to comment.