From f45746984f8b5aadf1f3e8451c576698a980d9bb Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Fri, 11 Dec 2020 18:00:14 +0100 Subject: [PATCH] Add connections stats --- package-lock.json | 2 +- src/database/database.ts | 2 ++ src/websocket.ts | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 570c7f0..bda00ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@hibas123/realtimedb", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/database/database.ts b/src/database/database.ts index bf3e7a3..3e002ab 100644 --- a/src/database/database.ts +++ b/src/database/database.ts @@ -104,6 +104,8 @@ export class Database { return this.#rules; } + public connections = 0; + private locks = new DocumentLock(); public collectionLocks = new DocumentLock(); diff --git a/src/websocket.ts b/src/websocket.ts index 4ed7419..efab073 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -151,8 +151,9 @@ export class WebsocketConnectionManager { Logging.error(err); } }); - + db.connections++; socket.on("close", () => { + db.connections--; Logging.log(`${session.id} has disconnected!`); session.subscriptions.forEach((unsubscribe) => unsubscribe()); session.subscriptions.clear();