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
IAgoraServiceinstance, setAgoraServiceConfiguration.useStringUidtotrue.// Create an IAgoraService object auto service = createAgoraService(); // Initialize the IAgoraService object agora::base::AgoraServiceConfiguration config; // Set Agora App ID config.appId = appid; // Enable the audio processing module config.enableAudioProcessor = enableAudioProcessor; // Disable the audio device module // Normally, audio capture or playback devices are not connected to a server config.enableAudioDevice = enableAudioDevice; // Whether to enable video config.enableVideo = enableVideo; // Enable user IDs in string format (the characters can be digits, letters, or special symbols) config.useStringUid = enableUseStringUid; if (service->initialize(config) != agora::ERR_OK) { return nullptr; } -
Call
connectto connect to the Video SDK channel.if (connection->connect(options.appId.c_str(), options.channelId.c_str(), options.userId.c_str())) { AG_LOG(ERROR, "Failed to connect to Agora channel!"); return -1; }
Limitations
-
Enabling string user IDs when initializing
IAgoraServicetakes 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 leave it unset, 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
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ","
