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

  1. When initializing the IAgoraService instance, set AgoraServiceConfiguration.useStringUid to true.

    // 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;
    }
  2. Call connect to 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 IAgoraService takes 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 you subscribe to 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 userId parameter in the connect method. 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
    • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ","