joinChannel method

  1. @override
Future<void> joinChannel(
  1. String token,
  2. String channelName,
  3. String optionalInfo,
  4. int optionalUid,
)

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 Meta'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.

Note

  • 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.

Warning

  • 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:

  • In situations not requiring high security: You can use the temporary token generated at Console. For details, see Get a temporary token.
  • In situations requiring high security: Set it as the token generated at your server. For details, see Get a token.

Parameter channelName The unique channel name for the MetaRTC 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.

Implementation

@override
Future<void> joinChannel(
    String token, String channelName, String optionalInfo, int optionalUid) {
  return _invokeMethod('joinChannel', {
    'token': token,
    'channelName': channelName,
    'optionalInfo': optionalInfo,
    'optionalUid': optionalUid
  });
}