Fix channel bug

This commit is contained in:
Hri7566 2023-09-10 17:35:16 -04:00
parent 8831188137
commit ca434a4ca5
3 changed files with 22 additions and 8 deletions

View File

@ -76,6 +76,9 @@ export class Channel extends EventEmitter {
} }
this.bindEventListeners(); this.bindEventListeners();
channelList.push(this);
// TODO channel closing
} }
public getID() { 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 // Broadcast participant update
this.sendArray([ this.sendArray([
@ -313,7 +319,7 @@ export class Channel extends EventEmitter {
let hasFullChannel = false; let hasFullChannel = false;
for (const id of config.forceLoad) { for (const id of config.forceLoad) {
channelList.push(new Channel(id)); new Channel(id);
if (id == config.fullChannel) hasFullChannel = true; if (id == config.fullChannel) hasFullChannel = true;
} }

4
src/util/types.d.ts vendored
View File

@ -306,8 +306,8 @@ declare interface ClientEvents {
p: { p: {
m: "p"; m: "p";
x: number | string; x: number | string | undefined;
y: number | string; y: number | string | undefined;
} & Participant; } & Participant;
t: { t: {

View File

@ -49,10 +49,12 @@ export class Socket extends EventEmitter {
}; };
public currentChannelID: string | undefined; public currentChannelID: string | undefined;
private cursorPos = { private cursorPos:
x: "-10.00", | {
y: "-10.00" x: string | number | undefined;
}; y: string | number | undefined;
}
| undefined;
constructor(private ws: ServerWebSocket<unknown>, public socketID: string) { constructor(private ws: ServerWebSocket<unknown>, public socketID: string) {
super(); super();
@ -239,6 +241,11 @@ export class Socket extends EventEmitter {
} }
public getCursorPos() { public getCursorPos() {
if (!this.cursorPos)
this.cursorPos = {
x: undefined,
y: undefined
};
return this.cursorPos; return this.cursorPos;
} }
@ -251,6 +258,7 @@ export class Socket extends EventEmitter {
y = y.toFixed(2); y = y.toFixed(2);
} }
if (!this.cursorPos) this.cursorPos = { x, y };
this.cursorPos.x = x; this.cursorPos.x = x;
this.cursorPos.y = y; this.cursorPos.y = y;