join method

방 접속

Implementation

Future<ChannelResultModel> join(UserModel user) async {
  if (_joined != null && _joined!.isCompleted) {
    throw VChatCloudError.fromResult(VChatCloudResult.alreadyInConnection);
  }

  try {
    this.user = user;
    _joined = Completer();

    _eventInit();

    _send({
      "type": "send",
      "address": "c2s.join",
      "headers": {},
      "body": {
        "roomId": roomId,
        "clientKey": user.clientKey,
        "nickName": user.nickName,
        "grade": user.grade,
        "userInfo": user.userInfo,
      },
      "replyAddress": "join_user_init"
    });

    // 방 조인 대기
    var history = await _joined!.future;

    return history;
  } catch (e) {
    if (e is VChatCloudError) {
      _finalDisconnectResult = VChatCloudResult.fromCode(e.code);
    }
    rethrow;
  } finally {
    _joined = null;
  }
}