aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sockets.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sockets.js b/lib/sockets.js
index 89278580..ee16b962 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -59,6 +59,12 @@ export const broadcast = (type, data) => {
});
};
+function subtractSeconds(numOfSeconds, date = new Date()) {
+ date.setSeconds(date.getSeconds() - numOfSeconds);
+
+ return date;
+}
+
app.register(fastifyWs);
app.register(async function(app) {
app.get("/ws", { websocket: true }, ({ socket: ws }, req) => {
@@ -85,6 +91,7 @@ app.register(async function(app) {
case "login":
let token = data;
+ if (lastSeen[token] > subtractSeconds(5)) ws.close();
lastSeen[token] = new Date();
try {