preloadChannel [2/2]

Preloads a channel with token, channelId, and userAccount.

virtual int preloadChannel(const char* token, const char* channelId, const char* userAccount) = 0;

Details

Since
v4.2.2

When audience members need to switch between different channels frequently, calling the method can help shortening the time of joining a channel, thus reducing the time it takes for audience members to hear and see the host. As it may take a while for the SDK to preload a channel, Agora recommends that you call this method as soon as possible after obtaining the channel name and user ID to join a channel.

Note:
  • When calling this method, ensure you set the user role as audience and do not set the audio scenario as AUDIO_SCENARIO_CHORUS, otherwise, this method does not take effect.
  • You also need to make sure that the User Account, channel ID and token passed in for preloading are the same as the values passed in when joining the channel, otherwise, this method does not take effect.
  • One IRtcEngine instance supports preloading 20 channels at most. When exceeding this limit, the latest 20 preloaded channels take effect.
  • Failing to preload a channel does not mean that you can't join a channel, nor will it increase the time of joining a channel.

If you join a preloaded channel, leave it and want to rejoin the same channel, you do not need to call this method unless the token for preloading the channel expires.

Parameters

token
The token generated on your server for authentication. See .
When the token for preloading channels expires, you can update the token based on the number of channels you preload.
  • When preloading one channel, calling this method to pass in the new token.
  • When preloading more than one channels:
    • If you use a wildcard token for all preloaded channels, call updatePreloadChannelToken to update the token.
      Note: When generating a wildcard token, ensure the user ID is not set as 0. See Secure authentication with tokens.
    • If you use different tokens to preload different channels, call this method to pass in your user ID, channel name and the new token.
channelId
The channel name that you want to preload. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters (89 characters in total):
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
userAccount
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as NULL. Supported characters are (89 in total):
  • The 26 lowercase English letters: a to z.
  • The 26 uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","

Returns

  • 0: Success.
  • < 0: Failure.
    • -2: The parameter is invalid. For example, the User Account is empty. You need to pass in a valid parameter and join the channel again.
    • -7: The IRtcEngine object has not been initialized. You need to initialize the IRtcEngine object before calling this method.
    • -102: The channel name is invalid. You need to pass in a valid channel name and join the channel again.