joinChannel method Null safety

Future<int> joinChannel(
  1. String? token,
  2. String channelName,
  3. int uid
)

Joins an RTC room.

If the specified room does not exist when you join the room, a room with the specified name is automatically created in the CommsEase server.

After you join a room by calling the relevant method supported by the SDK, users in the same room can make audio or video calls. Users that have joined the same room can start a group chat. Apps that use different App Keys cannot communicate with each other. After the method is called successfully, the onJoinChannel callback is locally triggered, and the onUserJoined callback is remotely triggered. If you join a room, you subscribe to all audio streams published by other participants in the same room by default. In this case, the data usage is billed. To unsubscribe, you can call the mute method. In live streaming, audiences can switch to different rooms by calling switchChannel.

token NERTC token for authentication Valid values:

  • null You can set the value to null in the debugging mode. This poses a security risk. We recommend that you contact your business manager to change to the default safe mode before your product is officially launched.
  • Obtained NERTC Token. In safe mode, the acquired token must be specified. If the specified token is invalid, users are unable to join the room. We recommend that you use the safe mode.

channelName The room name. Participants that use the same room name can join the same room.

  • The name must be of STRING type and must be 1 to 64 characters long.
  • The following 89 characters are supported: a-z, A-Z, 0-9, space, !#$%&()+-:;≤.,>? @[]^_{|}~”

uid The unique identifier of a user. The uid of each user in a room must be unique.

Implementation

// The uid is optional, The default value is 0. If the uid is unspecified (set to 0), the SDK automatically assigns a random uid and returns the uid in a callback. The application layer must keep and maintain the return value. The SDK does not maintain the return value.
Future<int> joinChannel(String? token, String channelName, int uid) async {
  IntValue reply = await _api.joinChannel(JoinChannelRequest()
    ..token = token
    ..channelName = channelName
    ..uid = uid);
  return reply.value ?? -1;
}