강동현

자유로운 이름으로 입장할 수 있도록 닉네임 구현

......@@ -38,6 +38,7 @@ export const RoomInfoRecord = Record({
users: Array(
Record({
username: String,
nickname: String,
admin: Boolean,
ready: Boolean,
})
......
......@@ -22,7 +22,7 @@ import {
// 'result' 속성은 서버 요청 결과에만 포함되는 특별한 속성입니다.
export class ServerInboundMessageRecordMap {
// 로그인을 시도합니다.
login = Record({ username: String });
login = Record({ nickname: String, result: String });
// 방 목록을 요청합니다.
roomList = Record({
......@@ -94,6 +94,7 @@ interface ServerOutboundMessageMap {
state: "added" | "updated" | "removed";
user: {
username: string;
nickname: string;
admin: boolean;
ready: boolean;
};
......
......@@ -77,7 +77,7 @@ export class Connection {
private handleLogin(
message: ServerInboundMessage<"login">
): ServerResponse<"login"> {
this.user = new User(message.username, this);
this.user = new User(message.nickname, this);
// console.log(`User ${message.username} has logged in!`);
return { ok: true };
......
......@@ -106,6 +106,7 @@ export class Room {
state: "added",
user: {
username: user.username,
nickname: user.nickname,
admin: user === this.admin,
ready: this.usersReady.includes(user),
},
......@@ -128,6 +129,7 @@ export class Room {
state: "removed",
user: {
username: user.username,
nickname: user.nickname,
admin: user === this.admin,
ready: this.usersReady.includes(user),
},
......@@ -221,6 +223,7 @@ export class Room {
state: "updated",
user: {
username: user.username,
nickname: user.nickname,
admin: this.isAdmin(user),
ready: this.isReady(user),
},
......@@ -244,6 +247,7 @@ export class Room {
users: this.users.map((u) => {
return {
username: u.username,
nickname: u.nickname,
admin: this.isAdmin(u),
ready: this.usersReady.includes(u),
};
......
......@@ -3,9 +3,11 @@ import { Connection } from "../connection/Connection";
import { MessageHandler } from "../message/MessageHandler";
import { Room } from "../room/Room";
import { RoomManager } from "../room/RoomManager";
import { v4 as uuidv4 } from "uuid";
export class User {
public readonly username: string;
public readonly username: string; // TODO: 실제 역할은 uuid임
public readonly nickname: string;
public readonly connection: Connection;
......@@ -13,8 +15,9 @@ export class User {
public handler: MessageHandler;
constructor(username: string, connection: Connection) {
this.username = username;
constructor(nickname: string, connection: Connection) {
this.username = uuidv4();
this.nickname = nickname;
this.connection = connection;
this.handler = new MessageHandler({
roomList: (user, message) => {
......