enter method

Future<ChatroomHandleImpl> enter(
  1. String roomId, {
  2. String? ext,
  3. bool leaveOthers = false,
})

多次进入返回同一个句柄,计数加一(《sdk-web/3.接口设计》第 13 节)。

Implementation

Future<ChatroomHandleImpl> enter(String roomId, {String? ext, bool leaveOthers = false}) async {
  core.requireSignedIn();
  if (roomId.isEmpty) throw validationError('required', 'room_id');
  if (ext != null && utf8Length(ext) > 512) throw validationError('invalid_ext', 'ext');
  final existing = _handles[roomId];
  if (existing != null && !existing.ended) {
    existing.retain();
    await existing.joined;
    return existing;
  }
  final handle = ChatroomHandleImpl(core, this, roomId, ext);
  _handles[roomId] = handle;
  try {
    await handle.join(leaveOthers);
  } catch (_) {
    if (identical(_handles[roomId], handle)) _handles.remove(roomId);
    rethrow;
  }
  return handle;
}