From 094aeb061c8c94008539ef25d0c1e811e7543695 Mon Sep 17 00:00:00 2001 From: sophie Date: Fri, 19 Jul 2024 04:26:14 +0300 Subject: [PATCH] improve --- src/Client.ts | 2 +- src/Room.ts | 16 ++-------------- src/Server.ts | 6 +++--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 895a8d2..e302e82 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -17,7 +17,7 @@ export class Client { .join(""); this.uniqWsID = crypto.randomUUID(); } - updateRole() { + sendWelcome() { const profile = Server.profiles.get(this.id) if(!profile) return; this.send(new proto.ServerMessage({ diff --git a/src/Room.ts b/src/Room.ts index 628da1f..c909c5d 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -86,20 +86,8 @@ export class Room { particpiant.addClient(ws.data); } - const welcome = new proto.ServerMessage({ - event: proto.ServerMessage_EventType.WELCOME, - welcome: { - id: ws.data.id, - name: particpiant.profile.name, - color: particpiant.profile.color, - room: this.name, - owner: this.owner, - chat: this.chats, - role: particpiant.profile.role, - }, - }); - - ws.data.send(welcome); + ws.data.sendWelcome(); + if (particpiant.clients.length <= 1) { //#region Annouce to everyone that the user has joined const joinMessage = new proto.ServerMessage({ diff --git a/src/Server.ts b/src/Server.ts index c515454..e94e71e 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -119,7 +119,7 @@ export class Server { profile.emit("update"); Server.wses.forEach((z) => { if (z.data.id == profile.id) { - z?.data?.updateRole(); + z?.data?.sendWelcome(); } }); return; @@ -156,7 +156,7 @@ export class Server { profile.emit("update"); Server.wses.forEach((z) => { if (z.data.id == profile.id) { - z?.data?.updateRole(); + z?.data?.sendWelcome(); } }); ws.data.send( @@ -176,7 +176,7 @@ export class Server { profile.emit("update"); Server.wses.forEach((z) => { if (z.data.id == profile.id) { - z?.data?.updateRole(); + z?.data?.sendWelcome(); } });