preloadChannelWithUserAccount

Preload the channel using token, channelId, and userAccount.

virtual int preloadChannelWithUserAccount(const char* token, const char* channelId, const char* userAccount) = 0;
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.

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.

Note: 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.

Call timing

To improve the user experience of preloading channels, Agora recommends that before joining the channel, calling this method as early as possible once confirming the channel name and user information.

Call Restrictions

  • 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.
  • Ensure that the channel name, user account, token, and the values passed when subsequently joining the channel are the same when preloading the channel, otherwise preloading will not be effective.
  • One IRtcEngine instance supports preloading 20 channels at most. When exceeding this limit, the latest 20 preloaded channels take effect.

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.
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
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 as follows(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: Method call succeeded.
  • < 0: Method call failed.
    • -2: Invalid parameter. For example, the user account is empty. You need to provide a valid parameter and rejoin the channel.
    • -7: The IRtcEngine object has not been initialized. You need to successfully initialize the IRtcEngine object before calling this method.
    • -102: Invalid channel name. You need to provide a valid channel name and rejoin the channel.