-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed websockets by using db collection for active users
- Loading branch information
1 parent
03ab83b
commit 315b743
Showing
6 changed files
with
66 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { getDB } = require('../db.js'); | ||
|
||
const addSocketUser = async (socketID, userID) => { | ||
const db = getDB(); | ||
const user = await getSocketUserByUserID(userID); | ||
if (user) return; | ||
const result = await db.collection('socketUsers').insertOne({ socketID, userID }); | ||
return result; | ||
} | ||
|
||
const getSocketUserByUserID = async (userID) => { | ||
const db = getDB(); | ||
const user = await db.collection('socketUsers').findOne({ userID }); | ||
return user; | ||
} | ||
|
||
const deleteSocketUser = async (socketID) => { | ||
const db = getDB(); | ||
const user = await db.collection('socketUsers').findOne({ socketID }); | ||
const userID = user ? user.userID : null; | ||
const result = await db.collection('socketUsers').deleteOne({ socketID }); | ||
if (userID) { | ||
await db.collection('socketUsers').deleteMany({ userID }); | ||
} | ||
return result; | ||
} | ||
|
||
module.exports = { | ||
addSocketUser, | ||
getSocketUserByUserID , | ||
deleteSocketUser, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters