roomJoinHandler.ts 577 Bytes
import { Connection } from "../../connection/Connection";
import { RoomManager } from "../../room/RoomManager";
import { RoomInfo } from "../../room/types";
import { User } from "../../user/User";
import { MessageResponse, RoomJoinMessage } from "../types";

export function roomJoinHandler(
  user: User,
  message: RoomJoinMessage
): MessageResponse<RoomInfo> {
  const room = RoomManager.instance().get(message.uuid);
  if (room !== undefined) {
    room.connect(user);
    return { ok: user.room !== undefined, result: user.room?.getInfo() };
  }
  return { ok: false };
}