joinChannel abstract method
- required String token,
- required String channelId,
- required int uid,
- required ChannelMediaOptions options,
Sets media options and joins a channel.
This method allows you to set media options when joining a channel, such as whether to publish audio and video streams in the channel. By default, users subscribe to all remote audio and video streams in the channel, which may incur usage and affect billing. If you want to unsubscribe, you can do so by setting the options parameter or using the corresponding mute methods. This method only supports joining one channel at a time. Apps with different App IDs cannot communicate with each other. Before joining a channel, ensure that the App ID used to generate the Token is the same as the one used in the initialize method to initialize the engine. Otherwise, joining the channel using the Token will fail.
tokenThe dynamic key generated on your server for authentication. See Token Authentication. (Recommended) If your project enables security mode (i.e., uses APP ID + Token for authentication), this parameter is required. If your project only enables debug mode (i.e., uses APP ID for authentication), you can join a channel without providing a Token. You will automatically leave the channel after 24 hours. If you need to join multiple channels at once or frequently switch between channels, Agora recommends using a wildcard Token to avoid requesting a new Token from your server for each new channel. See Wildcard Token.channelIdThe channel name. This parameter identifies the channel for real-time audio and video interaction. Users with the same App ID and channel name will join the same channel. This parameter must be a string of up to 64 bytes. Supported character set (89 characters): 26 lowercase letters az 26 uppercase letters AZ 10 digits 09 "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "", ","", "", "^", "_", "{", "}", "|", "uidUser ID. This parameter identifies the user in the real-time audio and video interaction channel. You must set and manage the user ID yourself and ensure that each user ID is unique within the same channel. This parameter is a 32-bit unsigned integer. Recommended range: 1 to 2^32-1. If not specified (i.e., set to 0), the SDK automatically assigns one and returns it in the onJoinChannelSuccess callback. The application must remember and maintain this return value; the SDK does not maintain it.optionsChannel media 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: Method call failed. See Error Codes for details and resolution suggestions. -2: Invalid parameters. For example, an invalid Token, uid is not an integer, or ChannelMediaOptions contains invalid values. Provide valid parameters and rejoin the channel. -3: RtcEngine initialization failed. Reinitialize the RtcEngine object. -7: RtcEngine not initialized. Initialize the RtcEngine object before calling this method. -8: Internal state error in RtcEngine. Possible cause: startEchoTest was called but stopEchoTest was not called before joining the channel. Call stopEchoTest before this method. -17: Join channel rejected. Possible cause: user is already in the channel. Use onConnectionStateChanged to check if the user is in the channel. Do not call this method again unless you receive 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> joinChannel(
{required String token,
required String channelId,
required int uid,
required ChannelMediaOptions options});