Agora Cloud Gateway supports int user ID and string user ID. This page introduces how to use string user id.
When initializing the AgoraService
object, call AgoraServiceConfiguration.setUseStringUid(1)
.
SDK.load(); // ensure JNI library load
// Creates an AgoraService object
AgoraService service = new AgoraService();
if (null == service) {
System.out.printf("createAndInitAgoraService fail\n");
return;
}
AgoraServiceConfig config = new AgoraServiceConfig();
// Disables the audio device module (Normally we do not directly connect audio capture or playback devices to a server)
config.setEnableAudioDevice(0);
// Enables the audio processing module
config.setEnableAudioProcessor(1);
// Enables video
config.setEnableVideo(1);
// Enables user ID in String format
config.setUseStringUid(1);
int ret = service.initialize(config);
if (ret != 0) {
System.out.printf("createAndInitAgoraService AgoraService.initialize fail ret=%d\n", ret);
return;
}
service.setLogFile("agorasdk.log",10*1024);
Call connect
to connect to the RTC channel.
RtcConnConfig ccfg = new RtcConnConfig();
ccfg.setAutoSubscribeAudio(0);
ccfg.setAutoSubscribeVideo(0);
ccfg.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
ccfg.setClientRoleType(Constants.CLIENT_ROLE_BROADCASTER);
AgoraRtcConn conn = service.agoraRtcConnCreate(ccfg);
if (conn == null) {
System.out.printf("AgoraService.agoraRtcConnCreate fail\n");
return;
}
conn.connect(token, "demo_channel", "1");
The supported character set of int user IDs includes:
The supported character set of string user IDs includes:
String user IDs can only communicate with string user IDs. Unknown errors occur when both string user IDs and int user IDs connect to a channel.
Different from int user IDs, when you call the connect
method, you must specify the userId
parameter.
A string user ID must be unique in a channel.