fix bug for mode 2 and remove unused code

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle
2023-10-31 15:52:07 +07:00
parent 2611654775
commit b06f29da5b
2 changed files with 1 additions and 18 deletions

View File

@@ -68,14 +68,6 @@ module.exports = (ws, req) => {
csess.set(ws.id, ws);
}
// CL - Broadcast message to every existing client sockets
function bc_c(msg) {
for (sock of csess) {
if (sock.readyState >= 2) return csess.delete(sock.id);
sock.send(JSON.stringify(msg));
}
}
// WS - Broadcast message to every existing sockets
function bc(msg) {
for (sock of socks) {

View File

@@ -70,15 +70,6 @@ module.exports = (ws, req) => {
relays.forEach(_ => newConn(_, ws.id));
}
// CL - Broadcast message to every existing client sockets
function bc_c(msg, id) {
for (sock of csess) {
if (sock.id !== id) continue;
if (sock.readyState >= 2) return csess.delete(sock.id);
sock.send(JSON.stringify(msg));
}
}
// WS - Broadcast message to every existing sockets
function bc(msg, id) {
for (sock of socks) {
@@ -126,7 +117,7 @@ function newConn(addr, id) {
if (sess.prepare("SELECT * FROM events WHERE cID = ? AND subID = ? AND eID = ?;").get(id, data[1], data[2]?.id)) return; // No need to transmit once it has been transmitted before.
sess.prepare("INSERT INTO events VALUES (?, ?, ?);").run(id, data[1], data[2]?.id);
bc_c(data, id);
csess.get(id)?.send(JSON.stringify(data));
break;
}
}