joinChannel method Null safety

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

Joins the channel with a user ID.

  • RtcChannel.joinChannel

    • Does not contain the channelName parameter, because channelName is specified when creating the RtcChannel instance.
    • Contains the options parameter, which decides whether to subscribe to all streams before joining the channel.
    • Users can join multiple channels simultaneously by creating multiple RtcChannel instances and calling the joinChannel method of each instance.
    • By default, the SDK does not publish any stream after the user joins the channel. You need to call the publish method to do that.
  • RtcEngine.joinChannel

    • Contains the channelName parameter, which specifies the channel to join.
    • Does not contain the options parameter. By default, users subscribe to all streams when joining the channel.
    • Users can join only one channel.
    • By default, the SDK publishes streams once the user joins the channel.

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.

Note

  • If you are already in a channel, you cannot rejoin it with the same uid.
  • We recommend using different UIDs for different channels.
  • If you want to join the same channel from different devices, ensure that the UIDs in all devices are different.
  • Ensure that the app ID you use to generate the token is the same with the app ID used when creating the RtcEngine instance.

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

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

Parameter optionalUid The user ID. A 32-bit unsigned integer with a value ranging from 1 to (232-1). This parameter must be unique. If uid is not assigned (or set as 0), the SDK assigns a uid and reports it in the onJoinChannelSuccess callback. The app must maintain this user ID.

Parameter options The channel media options. See ChannelMediaOptions.

Implementation

@override
Future<void> joinChannel(String? token, String? optionalInfo, int optionalUid,
    ChannelMediaOptions options) {
  return _invokeMethod('joinChannel', {
    'token': token,
    'optionalInfo': optionalInfo,
    'optionalUid': optionalUid,
    'options': options.toJson(),
  });
}