preloadChannelWithUserAccount abstract method

Future<void> preloadChannelWithUserAccount({
  1. required String token,
  2. required String channelId,
  3. required String userAccount,
})

Preloads a channel using token, channelId, and userAccount.

Calling this method reduces the time it takes for an audience member to join a channel when switching channels frequently, thereby shortening the time to hear the first audio frame and see the first video frame from the host, and improving the audience's video experience. If the current channel has already been successfully preloaded, and the audience leaves and rejoins the channel, as long as the Token passed during preloading is still valid, re-preloading is not required. Preloading failure does not affect normal channel joining later, nor does it increase the time to join the channel. When calling this method, ensure the user role is set to audience and the audio scenario is not chorus (audioScenarioChorus), otherwise preloading will not take effect. Ensure the channel name, user account, and Token passed during preloading are the same as those used when joining the channel later; otherwise, preloading will not take effect. Currently, a single RtcEngine instance supports preloading up to 20 channels. If this limit is exceeded, only the latest 20 preloaded channels take effect.

  • token A dynamic key generated on your server for authentication. See Token Authentication. When the Token expires, depending on the number of preloaded channels, you can pass in a new Token for preloading in different ways: For a single channel: call this method again with the new Token. For multiple channels: If you use a wildcard Token, call updatePreloadChannelToken to update the Token for all preloaded channels. When generating a wildcard Token, the user ID must not be set to 0. See Wildcard Token. If you use different Tokens: call this method and pass in your user ID, corresponding channel name, and the updated Token.
  • channelId The name of the channel to preload. This parameter identifies the channel for real-time audio and video communication. Under the same App ID, users who enter the same channel name will join the same channel for audio and video interaction. This parameter must be a string no longer than 64 bytes. Supported character set (89 characters total): 26 lowercase letters az 26 uppercase letters AZ 10 digits 09 "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "", "", "^", "_", "{", "}", "|", "", ","
  • userAccount User account. This parameter identifies the user in the real-time audio and video channel. You need to set and manage the user account yourself and ensure it is unique within the same channel. This parameter is required, must not exceed 255 bytes, and cannot be null. Supported character set (89 characters total): 26 lowercase letters a-z 26 uppercase letters A-Z 10 digits 0-9 Space "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "", "", "^", "_", "{", "}", "|", "~", ","

Returns When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions. < 0: The method call fails. See Error Codes for details and resolution suggestions. -2: Invalid parameter. For example, the user account is empty. You need to enter a valid parameter and rejoin the channel. -7: The RtcEngine object is not initialized. You need to initialize the RtcEngine object before calling this method. -102: Invalid channel name. You need to enter a valid channel name and rejoin the channel.

Implementation

Future<void> preloadChannelWithUserAccount(
    {required String token,
    required String channelId,
    required String userAccount});