From ca434a4ca5a06a9bb6df056d28389302b955e97d Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Sun, 10 Sep 2023 17:35:16 -0400 Subject: [PATCH] Fix channel bug --- src/channel/Channel.ts | 10 ++++++++-- src/util/types.d.ts | 4 ++-- src/ws/Socket.ts | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index 3c943e5..b0e61a6 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -76,6 +76,9 @@ export class Channel extends EventEmitter { } this.bindEventListeners(); + + channelList.push(this); + // TODO channel closing } public getID() { @@ -174,7 +177,10 @@ export class Channel extends EventEmitter { } ]); - const cursorPos = socket.getCursorPos(); + const cursorPos: { + x: string | number | undefined; + y: string | number | undefined; + } = socket.getCursorPos(); // Broadcast participant update this.sendArray([ @@ -313,7 +319,7 @@ export class Channel extends EventEmitter { let hasFullChannel = false; for (const id of config.forceLoad) { - channelList.push(new Channel(id)); + new Channel(id); if (id == config.fullChannel) hasFullChannel = true; } diff --git a/src/util/types.d.ts b/src/util/types.d.ts index dbdb659..e546fce 100644 --- a/src/util/types.d.ts +++ b/src/util/types.d.ts @@ -306,8 +306,8 @@ declare interface ClientEvents { p: { m: "p"; - x: number | string; - y: number | string; + x: number | string | undefined; + y: number | string | undefined; } & Participant; t: { diff --git a/src/ws/Socket.ts b/src/ws/Socket.ts index c369908..2733550 100644 --- a/src/ws/Socket.ts +++ b/src/ws/Socket.ts @@ -49,10 +49,12 @@ export class Socket extends EventEmitter { }; public currentChannelID: string | undefined; - private cursorPos = { - x: "-10.00", - y: "-10.00" - }; + private cursorPos: + | { + x: string | number | undefined; + y: string | number | undefined; + } + | undefined; constructor(private ws: ServerWebSocket, public socketID: string) { super(); @@ -239,6 +241,11 @@ export class Socket extends EventEmitter { } public getCursorPos() { + if (!this.cursorPos) + this.cursorPos = { + x: undefined, + y: undefined + }; return this.cursorPos; } @@ -251,6 +258,7 @@ export class Socket extends EventEmitter { y = y.toFixed(2); } + if (!this.cursorPos) this.cursorPos = { x, y }; this.cursorPos.x = x; this.cursorPos.y = y;