Skip to content

Commit

Permalink
feat: add RtcEngineContext instead of RtcEngineConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Jun 28, 2021
1 parent d14a41a commit d646652
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 81 deletions.
32 changes: 4 additions & 28 deletions example/src/examples/advanced/CreateStreamData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import {
} from 'react-native';

import RtcEngine, {
AudienceLatencyLevelType,
ChannelProfile,
ClientRole,
DataStreamConfig,
RtcEngineConfig,
RtcEngineContext,
RtcLocalView,
RtcRemoteView,
VideoFrameRate,
VideoOutputOrientationMode,
VideoRenderMode,
} from 'react-native-agora';

Expand Down Expand Up @@ -66,8 +63,8 @@ export default class LiveStreaming extends Component<{}, State, any> {
PermissionsAndroid.PERMISSIONS.CAMERA,
]);
}
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();

Expand All @@ -76,7 +73,7 @@ export default class LiveStreaming extends Component<{}, State, any> {

// make myself a broadcaster
await this._engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
await this._updateClientRole(ClientRole.Broadcaster);
await this._engine.setClientRole(ClientRole.Broadcaster);

// Set audio route to speaker
await this._engine.setDefaultAudioRoutetoSpeakerphone(true);
Expand Down Expand Up @@ -139,27 +136,6 @@ export default class LiveStreaming extends Component<{}, State, any> {
);
};

_updateClientRole = async (role: ClientRole) => {
let option;
if (role === ClientRole.Broadcaster) {
await this._engine?.setVideoEncoderConfiguration({
dimensions: {
width: 640,
height: 360,
},
frameRate: VideoFrameRate.Fps30,
orientationMode: VideoOutputOrientationMode.Adaptative,
});
// enable camera/mic, this will bring up permission dialog for first time
await this._engine?.enableLocalAudio(true);
await this._engine?.enableLocalVideo(true);
} else {
// You have to provide client role options if set to audience
option = { audienceLatencyLevel: AudienceLatencyLevelType.LowLatency };
}
await this._engine?.setClientRole(role, option);
};

render() {
const { isJoin } = this.state;
return (
Expand Down
6 changes: 3 additions & 3 deletions example/src/examples/advanced/LiveStreaming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import RtcEngine, {
AudienceLatencyLevelType,
ChannelProfile,
ClientRole,
RtcEngineConfig,
RtcEngineContext,
RtcLocalView,
RtcRemoteView,
VideoFrameRate,
Expand Down Expand Up @@ -67,8 +67,8 @@ export default class LiveStreaming extends Component<{}, State, any> {
PermissionsAndroid.PERMISSIONS.CAMERA,
]);
}
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();

Expand Down
32 changes: 4 additions & 28 deletions example/src/examples/advanced/MediaChannelRelay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import {
} from 'react-native';

import RtcEngine, {
AudienceLatencyLevelType,
ChannelMediaRelayError,
ChannelMediaRelayEvent,
ChannelMediaRelayState,
ChannelProfile,
ClientRole,
RtcEngineConfig,
RtcEngineContext,
RtcLocalView,
RtcRemoteView,
VideoFrameRate,
VideoOutputOrientationMode,
VideoRenderMode,
} from 'react-native-agora';

Expand Down Expand Up @@ -79,8 +76,8 @@ export default class MediaChannelRelay extends Component<{}, State, any> {
PermissionsAndroid.PERMISSIONS.CAMERA,
]);
}
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();

Expand All @@ -89,7 +86,7 @@ export default class MediaChannelRelay extends Component<{}, State, any> {

// make myself a broadcaster
await this._engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
await this._updateClientRole(ClientRole.Broadcaster);
await this._engine.setClientRole(ClientRole.Broadcaster);

// Set audio route to speaker
await this._engine.setDefaultAudioRoutetoSpeakerphone(true);
Expand Down Expand Up @@ -162,27 +159,6 @@ export default class MediaChannelRelay extends Component<{}, State, any> {
);
};

_updateClientRole = async (role: ClientRole) => {
let option;
if (role === ClientRole.Broadcaster) {
await this._engine?.setVideoEncoderConfiguration({
dimensions: {
width: 640,
height: 360,
},
frameRate: VideoFrameRate.Fps30,
orientationMode: VideoOutputOrientationMode.Adaptative,
});
// enable camera/mic, this will bring up permission dialog for first time
await this._engine?.enableLocalAudio(true);
await this._engine?.enableLocalVideo(true);
} else {
// You have to provide client role options if set to audience
option = { audienceLatencyLevel: AudienceLatencyLevelType.LowLatency };
}
await this._engine?.setClientRole(role, option);
};

render() {
const { isJoin } = this.state;
return (
Expand Down
6 changes: 3 additions & 3 deletions example/src/examples/advanced/MultiChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import RtcEngine, {
ChannelProfile,
ClientRole,
RtcChannel,
RtcEngineConfig,
RtcEngineContext,
RtcLocalView,
RtcRemoteView,
VideoRemoteState,
Expand Down Expand Up @@ -57,8 +57,8 @@ export default class MultiChannel extends Component<{}, State, any> {
}

_initEngine = async () => {
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);

await this._engine.enableVideo();
Expand Down
6 changes: 3 additions & 3 deletions example/src/examples/advanced/VoiceChange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import RtcEngine, {
AudioScenario,
ChannelProfile,
ClientRole,
RtcEngineConfig,
RtcEngineContext,
VoiceBeautifierPreset,
} from 'react-native-agora';
import VoiceChangeConfig, {
Expand Down Expand Up @@ -83,8 +83,8 @@ export default class VoiceChange extends Component<{}, State, any> {
PermissionsAndroid.PERMISSIONS.CAMERA,
]);
}
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);

this._addListeners();
Expand Down
6 changes: 3 additions & 3 deletions example/src/examples/basic/JoinChannelAudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import RtcEngine, {
ChannelProfile,
ClientRole,
RtcEngineConfig,
RtcEngineContext,
} from 'react-native-agora';
import RNFS from 'react-native-fs';
import Item from '../component/Item';
Expand Down Expand Up @@ -48,8 +48,8 @@ export default class JoinChannelAudio extends Component<{}, State, any> {
}

_initEngine = async () => {
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();

Expand Down
6 changes: 3 additions & 3 deletions example/src/examples/basic/JoinChannelVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import RtcEngine, {
ChannelProfile,
ClientRole,
RtcEngineConfig,
RtcEngineContext,
RtcLocalView,
RtcRemoteView,
} from 'react-native-agora';
Expand Down Expand Up @@ -51,8 +51,8 @@ export default class JoinChannelAudio extends Component<{}, State, any> {
}

_initEngine = async () => {
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();

Expand Down
6 changes: 3 additions & 3 deletions example/src/examples/basic/StringUid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, StyleSheet, TextInput, View } from 'react-native';
import RtcEngine, {
ChannelProfile,
ClientRole,
RtcEngineConfig,
RtcEngineContext,
} from 'react-native-agora';

const config = require('../../../agora.config.json');
Expand Down Expand Up @@ -36,8 +36,8 @@ export default class StringUid extends Component<{}, State, any> {
}

_initEngine = async () => {
this._engine = await RtcEngine.createWithConfig(
new RtcEngineConfig(config.appId)
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();

Expand Down
11 changes: 10 additions & 1 deletion src/common/Classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ export class DataStreamConfig {
*
* @since v3.3.1
*/
export class RtcEngineConfig {
export class RtcEngineContext {
/**
* The App ID issued to you by Agora. See [How to get the App ID](https://docs.agora.io/en/Agora%20Platform/token#get-an-app-id).
* Only users in apps with the same App ID can join the same channel and communicate with each other. Use an App ID to create only
Expand Down Expand Up @@ -1649,6 +1649,15 @@ export class RtcEngineConfig {
}
}

/**
* @deprecated
*
* Configurations for the [`RtcEngine`]{@link RtcEngine}.
*
* @since v3.3.1
*/
export class RtcEngineConfig extends RtcEngineContext {}

/**
* Recording configuration, which is set in [`startAudioRecordingWithConfig`]{@link startAudioRecordingWithConfig}.
*/
Expand Down
49 changes: 43 additions & 6 deletions src/common/RtcEngine.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
LiveTranscoding,
RhythmPlayerConfig,
RtcEngineConfig,
RtcEngineContext,
UserInfo,
VideoEncoderConfiguration,
WatermarkOptions,
Expand Down Expand Up @@ -148,7 +149,7 @@ export default class RtcEngine implements RtcEngineInterface {
* - 101(InvalidAppId): The app ID is invalid. Check if it is in the correct format.
*/
static async create(appId: string): Promise<RtcEngine> {
return RtcEngine.createWithConfig(new RtcEngineConfig(appId));
return RtcEngine.createWithContext(new RtcEngineContext(appId));
}

/**
Expand Down Expand Up @@ -181,8 +182,8 @@ export default class RtcEngine implements RtcEngineInterface {
appId: string,
areaCode: AreaCode
): Promise<RtcEngine> {
return RtcEngine.createWithConfig(
new RtcEngineConfig(appId, { areaCode: [areaCode] })
return RtcEngine.createWithContext(
new RtcEngineContext(appId, { areaCode: [areaCode] })
);
}

Expand All @@ -203,9 +204,46 @@ export default class RtcEngine implements RtcEngineInterface {
* - The error code, if the method call fails.
* - 101(InvalidAppId): The app ID is invalid. Check if it is in the correct format.
*/
static async createWithConfig(config: RtcEngineConfig) {
static async createWithConfig(config: RtcEngineConfig): Promise<RtcEngine> {
return this.createWithContext(config);
}

/**
* Creates an [`RtcEngine`]{@link RtcEngine} instance.
*
* @since v3.3.1.
*
* Unless otherwise specified, all the methods provided by the [`RtcEngine`]{@link RtcEngine} class are executed asynchronously. Agora recommends calling these methods in the same thread.
*
* @note
* - You must create an [`RtcEngine`]{@link RtcEngine} instance before calling any other method.
* - The Agora RTC Native SDK supports creating only one [`RtcEngine`]{@link RtcEngine} instance for an app for now.
*
* @param context Configurations for the [`RtcEngine`]{@link RtcEngine} instance. For details, see [`RtcEngineContext`]{@link RtcEngineContext}.
* @return
* - The [`RtcEngine`]{@link RtcEngine} instance, if the method call succeeds.
* - The error code, if the method call fails.
* - 101(InvalidAppId): The app ID is invalid. Check if it is in the correct format.
*/
static async createWithContext(
context: RtcEngineContext
): Promise<RtcEngine> {
if (engine) return engine;
await RtcEngine._callMethod('create', { config, appType: 8 });
let areaCode: number | undefined;
if (context.areaCode) {
let code = 0;
context.areaCode.forEach((value) => {
code |= value;
});
areaCode = code;
}
await RtcEngine._callMethod('create', {
config: {
...context,
areaCode: areaCode,
},
appType: 8,
});
engine = new RtcEngine();
return engine;
}
Expand Down Expand Up @@ -2931,7 +2969,6 @@ export default class RtcEngine implements RtcEngineInterface {
*
* @param config The configurations for the data stream.
*
*
* @return
* - Returns the stream ID if you successfully create the data stream.
* - < 0: Fails to create the data stream.
Expand Down

0 comments on commit d646652

Please sign in to comment.