Skip to content
This repository was archived by the owner on Dec 15, 2019. It is now read-only.

Commit 529e42b

Browse files
committed
Answer ping in websocket; Prevent multiple registrations
1 parent faea35c commit 529e42b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/websocket.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ module.exports = server => {
1010

1111
ws.on('message', async message => {
1212

13+
// Answer ping request
14+
if (message === '__ping__') {
15+
return ws.send('__pong__');
16+
}
17+
1318
// Try to parse message
1419
try {
1520
message = JSON.parse(message);
@@ -30,6 +35,8 @@ module.exports = server => {
3035
const userid = user.id;
3136
if (!(userid in userMap)) {
3237
userMap[userid] = [];
38+
} else if (userMap[userid].includes(ws)) {
39+
return;
3340
}
3441

3542
userMap[userid].push(ws);

0 commit comments

Comments
 (0)