Skip to content

Commit

Permalink
Adjust websocket route code
Browse files Browse the repository at this point in the history
- Fixes issue introduced by #71.
- Uses async/await now where possible.
  • Loading branch information
stefandesu committed Sep 16, 2024
1 parent f1e3138 commit 70036b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions routes/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import jwt from "jsonwebtoken"

export default app => {

app.ws("/", (ws, req) => {
app.ws("/", async (ws, req) => {
// Generate a unique identifier for this WebSocket
const wsID = utils.uuid()
let socket = {
Expand All @@ -22,17 +22,20 @@ export default app => {
events.sendEvent(wsID, "open", null)

// Send information about the server as well as the list of providers.
events.sendEvent(wsID, "about", utils.prepareAbout())
events.sendEvent(wsID, "about", await utils.prepareAbout())
events.sendEvent(wsID, "providers", {
providers: utils.prepareProviders(),
})

// Check if sessionID already exists in store. If yes, consider connection authenticated.
mongoStore.get(req.sessionID).then(session => {
try {
const session = await mongoStore.get(req.sessionID)
if (session) {
events.sendEvent(wsID, "authenticated")
}
}).catch(() => {})
} catch (error) {
// ignore error
}


if (req.user) {
Expand Down

0 comments on commit 70036b7

Please sign in to comment.