loginRoom method

Future<ZegoRoomLoginResult> loginRoom(
  1. String roomID,
  2. ZegoUser user,
  3. {ZegoRoomConfig? config}
)

Log in to the room by configuring advanced properties, and return the login result through the callback parameter. You must log in to the room before pushing or pulling the stream.

Available since: 2.18.0 Description: If the room does not exist, loginRoom creates and logs in the room. SDK uses the 'room' to organize users. After users log in to a room, they can use interface such as push stream startPublishingStream, pull stream startPlayingStream, send and receive broadcast messages sendBroadcastMessage, etc. 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. Use cases: In the same room, users can conduct live broadcast, audio and video calls, etc. When to call /Trigger: This interface is called after createEngine initializes the SDK. Restrictions: For restrictions on the use of this function, please refer to https://docs.zegocloud.com/article/7611 or contact ZEGO technical support. Caution:

  1. Apps that use different appIDs cannot intercommunication with each other.
  2. SDK supports startPlayingStream audio and video streams from different rooms under the same appID, that is, startPlayingStream audio and video streams across rooms. Since ZegoExpressEngine's room related callback notifications are based on the same room, when developers want to startPlayingStream streams across rooms, developers need to maintain related messages and signaling notifications by themselves.
  3. It is strongly recommended that userID corresponds to the user ID of the business APP, that is, a userID and a real user are fixed and unique, and should not be passed to the SDK in a random userID. Because the unique and fixed userID allows ZEGO technicians to quickly locate online problems.
  4. After the first login failure due to network reasons or the room is disconnected, the default time of SDK reconnection is 20min. 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:
  5. When the user starts to log in to the room, the room is successfully logged in, or the room fails to log in, 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.
  6. Different users who log in to the same room can get room related notifications in the same room (eg onRoomUserUpdate, onRoomStreamUpdate, etc.), and users in one room cannot receive room signaling notifications in another room.
  7. If the network is temporarily interrupted due to network quality reasons, the SDK will automatically reconnect internally. You can get the current connection status of the local room by listening to the onRoomStateChanged (Not supported before 2.18.0, please use onRoomStateUpdate) callback method, and other users in the same room will receive onRoomUserUpdate callback notification.
  8. Messages sent in one room (e.g. setStreamExtraInfo, sendBroadcastMessage, sendBarrageMessage, sendCustomCommand, etc.) cannot be received callback ((eg onRoomStreamExtraInfoUpdate, onIMRecvBroadcastMessage, onIMRecvBarrageMessage, onIMRecvCustomCommand, etc) in other rooms. Currently, SDK does not provide the ability to send messages across rooms. Developers can integrate the SDK of third-party IM to achieve. Related APIs:
  9. Users can call logoutRoom to log out. In the case that a user has successfully logged in and has not logged out, if the login interface is called again, the console will report an error and print the error code 1002001.
  10. SDK supports multi-room login, please call setRoomMode function to select multi-room mode before engine initialization, and then call loginRoom to log in to multi-room.
  11. Calling destroyEngine will also automatically log out.
  • roomID Room ID, a string of up to 128 bytes in length. Caution:
    1. room ID is defined by yourself.
    2. Only support numbers, English characters and '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '`', ';', '’', ',', '.', '<', '>', ''.
    3. If you need to communicate with the Web SDK, please do not use '%'.
  • user User object instance, configure userID, userName. Note that the userID needs to be globally unique with the same appID, otherwise the user who logs in later will kick out the user who logged in first.
  • config Advanced room configuration.
  • Returns The result of this login room

Implementation

Future<ZegoRoomLoginResult> loginRoom(String roomID, ZegoUser user,
    {ZegoRoomConfig? config}) async {
  return await ZegoExpressImpl.instance
      .loginRoom(roomID, user, config: config);
}