Initialization
Before using other SDK features, you must complete initialization. This document details the initialization methods.
Notes
- The initialization method must be called once during the application lifecycle.
Preparing App Key
You need a valid App Key to initialize the SDK.
Log in to the RC Console and navigate to Service Management to view the App Keys of your created applications.
If you manage multiple applications, ensure you select the correct application name (labeled as ① in the image below). Additionally, each RC application provides separate App Key/Secret pairs for isolating production and development environments. When obtaining the App Key, verify the environment (Production/Development, labeled as ② below).
- If you're not the application creator, we recommend confirming that the displayed data center matches expectations when obtaining the App Key.
- If you haven't applied for application activation with RC, only the development environment is available.
Pre-Initialization Requirements
Certain configurations must be completed before initialization; otherwise, SDK functionality may not work properly.
- Enable RTC Services: RTC services require manual activation. Enable the corresponding RTC service based on your application's business type. For details, see Enable RTC Services.
- Global Data Center: Since RTC services rely on the IMLib SDK for signaling channels, if your application uses a global data center, you must modify the default IMLib SDK service address to the global data center address before initialization. Otherwise, the SDK defaults to connecting to the China (Beijing) Data Center. For details, see Configure Global Data Center Service Address.
Permission Configuration
iOS
Add camera and microphone usage descriptions to Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access required</string>
<key>NSMicrophoneUsageDescription</key>
<string>Microphone access required</string>
Android
Declare camera, microphone, and network permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
Initializing with App Key
Since signaling transmission between RTC users depends on RC's IM service, you must first initialize the IM SDK. If the AppKey remains unchanged, initialize it only once during the application lifecycle. We recommend placing the initialization call in the main()
method or at the loading point of the RTC module. After obtaining the IM engine instance, call the connect
method to establish a TCP long connection with the IM service. We recommend calling this at the module loading point before starting RTC operations. Call disconnect
or logout
to terminate the connection when the module exits.
void main() {
/// IMLib initialization
RCIMIWEngineOptions options = RCIMIWEngineOptions.create();
RCIMIWEngine imEngine = await RCIMIWEngine.create(appKey, options);
RCIMIWConnectCallback? callback = RCIMIWConnectCallback(onDatabaseOpened: (int? code) {
//...
}, onConnected: (int? code, String? userId) {
//...
});
int? ret = await imEngine?.connect(token, timeout, callback:callback);
}
For detailed IM SDK initialization methods and configurations, refer to the IM SDK Documentation.
Creating the RTC Engine
After successfully connecting to the IM service, create the RTC engine using the following code:
engine = await RCRTCEngine.create();
Alternatively, create the engine with configuration parameters. For details, see Engine Configuration.
RCRTCEngineSetup setup = RCRTCEngineSetup.create();
engine = await RCRTCEngine.create(setup);