My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How to know which web socket was disconnected in express-ws (npm) ?

Anuj Sharma's photo
Anuj Sharma
·May 5, 2017

I am using express-ws npm for websocket. How i know which user is disconnected ?

var allclients = [];
router.ws('/', function(ws, req) { allclients.push({id: req.headers.userid,data: ws});
ws.on('close',function(msg) { console.log(msg); })
})

When any client disconnect then all websockets ws.readyState give us status 3 instead of 1.