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();
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;
}

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

@ -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: {

View File

@ -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<unknown>, 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;