switchRoom method

Future<void> switchRoom(
  1. String fromRoomID,
  2. String toRoomID,
  3. {ZegoRoomConfig? config}
)

Switch the room with advanced room configurations.

Available since: 1.15.0 Description: Using this interface allows users to quickly switch from one room to another room. Use cases: if you need to quickly switch to the next room, you can call this function. When to call /Trigger: After successfully login room. Restrictions: None. Caution:

  1. When this function is called, all streams currently publishing or playing will stop (but the local preview will not stop).
  2. To prevent the app from being impersonated by a malicious user, you can add authentication before logging in to the room, that is, the token parameter in the ZegoRoomConfig object passed in by the config parameter. This parameter configuration affects the room to be switched over.
  3. Multi-room mode is supported in version 3.5.0 (use the function setRoomMode to set ZegoRoomMode to ZEGO_ROOM_MODE_MULTI_ROOM).
  4. If a Token is passed in for login when logging into the room loginRoom, the switchroom interface must be used with the config parameter and the corresponding Token value passed in when switching rooms. Privacy reminder: Please do not fill in sensitive user information in this interface, including but not limited to mobile phone number, ID number, passport number, real name, etc. Related callbacks: When the user call the switchRoom function, the onRoomStateChanged (Not supported before 2.18.0, please use onRoomStateUpdate) callback will be triggered to notify the developer of the status of the current user connected to the room. Related APIs: Users can use the logoutRoom function to log out of the room.
  • fromRoomID Current roomID.
  • toRoomID The next roomID.
  • config Advanced room configuration.

Implementation

Future<void> switchRoom(String fromRoomID, String toRoomID,
    {ZegoRoomConfig? config}) async {
  return await ZegoExpressImpl.instance
      .switchRoom(fromRoomID, toRoomID, config: config);
}