joinChannelWithUserAccount abstract method
- required String token,
- required String channelId,
- required String userAccount,
- ChannelMediaOptions? options,
Joins a channel using a User Account and token, and sets channel media options.
Before calling this method, if you have not registered a User Account using registerLocalUserAccount, the SDK automatically creates one for you when you join a channel using this method. To reduce the time it takes to join a channel, register the account first using registerLocalUserAccount, then call this method.
After a user successfully joins a channel, they automatically subscribe to all audio and video streams from other users in the channel, which incurs usage and affects billing. To unsubscribe, call the corresponding mute methods. To ensure communication quality, make sure that all users in the channel use the same type of identifier, either UID or User Account. If users join the channel via the Web SDK, ensure they use the same identifier type. This method only supports joining one channel at a time. Apps with different App IDs cannot communicate with each other. Before joining a channel, make sure the App ID used to generate the token is the same as the one used in the initialize method. Otherwise, joining the channel with the token will fail.
tokenThe dynamic key generated on your server for authentication. See Use Token Authentication. (Recommended) If your project has enabled secure mode (using APP ID + Token for authentication), this parameter is required. If your project is in debug mode only (using APP ID for authentication), you can join the channel without a token. The user will automatically leave the channel after 24 hours. If you need to join multiple channels or frequently switch between channels, Agora recommends using a wildcard token to avoid requesting a new token from your server every time. See Use Wildcard Token.userAccountThe User Account of the user. This parameter identifies the user in the real-time audio/video interaction channel. You must manage and ensure the uniqueness of each User Account 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 "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "", "", "^", "_", "{", "}", "|", "~", ","optionsChannel media configuration options. See ChannelMediaOptions.
Returns When the method call succeeds, there is no return value; when it 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, an illegal token is used, the uid parameter is not an integer, or a member value of ChannelMediaOptions is invalid. Provide valid parameters and rejoin the channel. -3: RtcEngine initialization failed. Reinitialize the RtcEngine object. -7: RtcEngine not initialized. Initialize RtcEngine before calling this method. -8: Internal state error of RtcEngine. This may occur if you call this method after starting an echo test with startEchoTest but before stopping it with stopEchoTest. Call stopEchoTest before this method. -17: Join channel rejected. Possibly because the user is already in the channel. Use the onConnectionStateChanged callback to check if the user is in the channel. Do not call this method again unless the state is connectionStateDisconnected (1). -102: Invalid channel name. Provide a valid channelId and rejoin the channel. -121: Invalid user ID. Provide a valid uid and rejoin the channel.
Implementation
Future<void> joinChannelWithUserAccount(
{required String token,
required String channelId,
required String userAccount,
ChannelMediaOptions? options});