joinChannel method Null safety

Future<void> joinChannel(
  1. String? token,
  2. String channelName,
  3. String? optionalInfo,
  4. int optionalUid,
  5. [ChannelMediaOptions? options]

Allows a user to join a channel.

Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different App IDs cannot call each other. You must call the RtcEngine.leaveChannel method to exit the current call before joining another channel. A successful joinChannel method call triggers the following callbacks:

When the connection between the client and Agora's server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the RtcEngineEventHandler.rejoinChannelSuccess callback on the local client.

Once the user joins the channel (switches to another channel), the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. If you do not want to subscribe to a specified stream or all remote streams, call the mute methods accordingly.


  • A channel does not accept duplicate uids, such as two users with the same uid. If you set uid as 0, the system automatically assigns a uid.


  • Ensure that the App ID used for creating the token is the same App ID used in the create method for creating an RtcEngine object. Otherwise, CDN live streaming may fail.

Parameter token The token for authentication. Set it as the token generated at your server. For details, see Get a token.

Parameter channelName The unique channel name for the AgoraRTC session in the string format. The string length must be less than 64 bytes. Supported character scopes are:

  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • The space character.
  • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".

Parameter optionalInfo Additional information about the channel. This parameter can be set as null or contain channel related information. Other users in the channel do not receive this message.

Parameter optionalUid (Optional) User ID. optionalUid must be unique. If optionalUid is not assigned (or set to 0), the SDK assigns and returns uid in the RtcEngineEventHandler.joinChannelSuccess callback. Your app must record and maintain the returned uid since the SDK does not do so.

Parameter options The channel media options. See ChannelMediaOptions.


Future<void> joinChannel(
    String? token, String channelName, String? optionalInfo, int optionalUid,
    [ChannelMediaOptions? options]) {
  return _invokeMethod('joinChannel', {
    'token': token,
    'channelName': channelName,
    'optionalInfo': optionalInfo,
    'optionalUid': optionalUid,
    'options': options?.toJson(),