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 e9a0f44 commit 5dd294f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example/lib/examples/advanced/create_stream_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _State extends State<CreateStreamData> {
if (defaultTargetPlatform == TargetPlatform.android) {
await Permission.microphone.request();
}
_engine = await RtcEngine.createWithConfig(RtcEngineConfig(config.appId));
_engine = await RtcEngine.createWithContext(RtcEngineContext(config.appId));
this._addListener();

// enable video module and set up video encoding configs
Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/advanced/live_streaming.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class _State extends State<LiveStreaming> {
if (defaultTargetPlatform == TargetPlatform.android) {
await Permission.microphone.request();
}
_engine = await RtcEngine.createWithConfig(RtcEngineConfig(config.appId));
_engine = await RtcEngine.createWithContext(RtcEngineContext(config.appId));

this._addListener();

Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/advanced/media_channel_relay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _State extends State<MediaChannelRelay> {
if (defaultTargetPlatform == TargetPlatform.android) {
await Permission.microphone.request();
}
_engine = await RtcEngine.createWithConfig(RtcEngineConfig(config.appId));
_engine = await RtcEngine.createWithContext(RtcEngineContext(config.appId));
this._addListener();

// enable video module and set up video encoding configs
Expand Down
20 changes: 17 additions & 3 deletions example/lib/examples/advanced/multi_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _State extends State<MultiChannel> {
}

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

await _engine.enableVideo();
await _engine.startPreview();
Expand All @@ -56,7 +56,14 @@ class _State extends State<MultiChannel> {
this._addListener(_channel0);

await _channel0.setClientRole(ClientRole.Broadcaster);
await _channel0.joinChannel(null, null, 0, ChannelMediaOptions());
await _channel0.joinChannel(
null,
null,
0,
ChannelMediaOptions(
publishLocalAudio: false,
publishLocalVideo: false,
));
}

_joinChannel1() async {
Expand All @@ -68,7 +75,14 @@ class _State extends State<MultiChannel> {
this._addListener(_channel1);

await _channel1.setClientRole(ClientRole.Broadcaster);
await _channel1.joinChannel(null, null, 0, ChannelMediaOptions());
await _channel1.joinChannel(
null,
null,
0,
ChannelMediaOptions(
publishLocalAudio: false,
publishLocalVideo: false,
));
}

_addListener(RtcChannel channel) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/advanced/voice_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _State extends State<VoiceChange> {
if (defaultTargetPlatform == TargetPlatform.android) {
await Permission.microphone.request();
}
_engine = await RtcEngine.createWithConfig(RtcEngineConfig(config.appId));
_engine = await RtcEngine.createWithContext(RtcEngineContext(config.appId));
this._addListener();

// make this room live broadcasting room
Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/basic/join_channel_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _State extends State<JoinChannelAudio> {
}

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

await _engine.enableAudio();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/basic/join_channel_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _State extends State<JoinChannelVideo> {
}

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

await _engine.enableVideo();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/basic/string_uid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _State extends State<StringUid> {
}

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

await _engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
Expand Down
28 changes: 25 additions & 3 deletions lib/src/rtc_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RtcEngine with RtcEngineInterface {
/// - The error code, if this method call fails:
/// - [ErrorCode.InvalidAppId]
static Future<RtcEngine> create(String appId) {
return createWithConfig(RtcEngineConfig(appId));
return createWithContext(RtcEngineContext(appId));
}

/// Creates an [RtcEngine] instance.
Expand Down Expand Up @@ -114,7 +114,7 @@ class RtcEngine with RtcEngineInterface {
@deprecated
static Future<RtcEngine> createWithAreaCode(
String appId, List<AreaCode> areaCode) {
return createWithConfig(RtcEngineConfig(appId, areaCode: areaCode));
return createWithContext(RtcEngineContext(appId, areaCode: areaCode));
}

/// Creates an [RtcEngine] instance.
Expand All @@ -134,11 +134,33 @@ class RtcEngine with RtcEngineInterface {
/// - An [RtcEngine] instance if the method call succeeds.
/// - The error code, if this method call fails:
/// - [ErrorCode.InvalidAppId]
@deprecated
static Future<RtcEngine> createWithConfig(RtcEngineConfig config) async {
return createWithContext(config);
}

/// Creates an [RtcEngine] instance.
///
/// Since v3.3.1
///
/// Unless otherwise specified, all the methods provided by the [RtcEngine] instance are executed asynchronously. Agora recommends calling these methods in the same thread.
///
/// **Note**
/// - You must create the [RtcEngine] instance before calling any other method.
/// - You can create an [RtcEngine] instance either by calling this method or by calling [create]. The difference between [create] and this method is that this method enables you to specify the region for connection.
/// - The Agora RTC Native SDK supports creating only one [RtcEngine] instance for an app for now.
///
/// **Parameter**[context] Configurations for the [RtcEngine] instance. For details, see [RtcEngineContext].
///
/// **Returns**
/// - An [RtcEngine] instance if the method call succeeds.
/// - The error code, if this method call fails:
/// - [ErrorCode.InvalidAppId]
static Future<RtcEngine> createWithContext(RtcEngineContext context) async {
if (_instance != null) return _instance!;
_instance = RtcEngine._();
await _instance!._invokeMethod('create', {
'config': config.toJson(),
'config': context.toJson(),
'appType': 4,
});
return _instance!;
Expand Down

0 comments on commit 5dd294f

Please sign in to comment.