I need to handle the events "user is online now" and "user is now disconnected" on the GraphQL server Apollo Node.js. What is the best way to do this?
My investigation . I am sure that I do not need to implement the beat logic because subscribers are working on WebSockets. But I did not find in my documents information on how to handle WebSockets events, such as “connect” and “disconnect” from the subscription ... In fact, I can process these events from outside the actual subscription:
SubscriptionServer.create({
execute,
subscribe,
schema,
onConnect = (...args) => {
console.log('User connected')
},
onDisconnect = (...args) => {
console.log('User disconnected')
}
}, {
server: ws,
path: '/subscriptions'
})
But it cannot determine which user is connected through this socket.
My implementation : so far I have done it like this:
, . - ?