Use a string user ID
Updated
How to use string user IDs in Server Gateway.
The Agora Server Gateway supports both integer and string user IDs. This page shows you how to use string user IDs.
Implementation
-
When initializing the
AgoraServiceobject, callAgoraServiceConfiguration.setUseStringUid(1).// Create an AgoraService object AgoraService service = new AgoraService(); if (null == service) { System.out.printf("createAndInitAgoraService fail\n"); return; } AgoraServiceConfig config = new AgoraServiceConfig(); // Disable the audio device module (Normally we do not directly connect audio capture or playback devices to a server) config.setEnableAudioDevice(0); // Enable the audio processing module config.setEnableAudioProcessor(1); // Enable video config.setEnableVideo(1); // Enable 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
connectto connect to the Video SDK 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");
Limitations
-
Enabling string user IDs when initializing
AgoraServicetakes effect only after connecting to a channel. Before connection, the SDK defaults to integer user IDs. This means that you cannot subscribe to non-numeric user IDs. Ensure that any user ID yousubscribeto before connection include only numbers. After connection, you can subscribe to user IDs with other characters. -
String user IDs can only communicate with other string user IDs. If a channel contains both string and integer user IDs, unknown errors may occur.
-
Unlike integer user IDs, you must specify the string
userIdparameter in theconnectmethod. If you set it to null, you receive an error. -
A string user ID must be unique within each channel.
Supported character set
-
Integer user IDs
- 10 digits: 0-9
-
String user IDs
- Lowercase English letters
- Uppercase English letters
- 10 digits: 0-9
- The space character
"!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
