-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server onDisconnect event #91
Comments
i have yet to switch from |
The thing is, the actual "server" is just a connection controller which can be hooked up to any WebSocket implementation. Its meant to be ultra minimal and its sole purpose is marshalling the messages and having high level control over the channel. Because of this, it does not have a concept of a "disconnect" - it simply does not care. So, ultimately, there is no place for a However, you can indeed achieve this by providing a custom implementation over Lines 25 to 126 in 5483fac
If you need additional help, I'll write up an usage example for you! |
I spoke too soon... PR coming soon! |
🎉 This issue has been resolved in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hey @MartijnHols and @brettjashford, I've added 2 new callbacks:
|
Hi @enisdenjo thank you for the amazing library! I would like to implement the same feature of what @MartijnHols said.
The code should be like this, right? import { useServer } from 'graphql-ws/lib/use/ws';
import { db } from './my-db-service'
useServer({
context: (ctx) => ({
userId: ctx.connectionParams.userId // psuedo code, no auth logic
}),
onDisconnect: (ctx) => {
db.update({ status: 'offline' }).where({ userId: ctx.connectionParams.userId })
}
}, ws ) |
Hey there @acro5piano! I'd recommend reading #91 (comment) to understand the difference between In essence,
|
@enisdenjo |
If the user disconnects abruptly without |
@enisdenjo Thanks for your help! |
Story
As a server I want to track the amount of open websocket connections and update the user's online status when a user disconnects so that I can monitor and analyze the health of my server and update a user's online status immediately when the browser is closed.
Acceptance criteria
Example use case
The text was updated successfully, but these errors were encountered: