This commit is contained in:
leca 2024-11-13 23:08:50 +03:00
parent 1e6975fa13
commit 0e4cc6507b
1 changed files with 13 additions and 7 deletions

View File

@ -35,7 +35,7 @@ wss.on('connection', (client) => {
let parsed = JSON.parse(message);
let token = parsed.token;
let currentGroup = parsed.currentGroup;
try {
if (!jwt.verify(token, config.secret)) {
client.send("Invalid token");
return;
@ -45,6 +45,12 @@ wss.on('connection', (client) => {
client.send("Not a member of specified group");
return;
}
} catch (e) {
log.error("Error during connection through websocket.")
client.send("Error")
return;
}
clients.push({
socket: client,
@ -69,7 +75,7 @@ const server = app.listen(config.port, () => {
server.on('upgrade', (req, res, head) => {
wss.handleUpgrade(req, res, head, socket => {
wss.emit('connection', socket, request);
wss.emit('connection', socket, req);
});
});