简体   繁体   中英

Socket.io room empty event

I have online file editing application using socket.io. Users join a room that is related with particular file they want to work with. I don't want use file system every time user changes something, so file is cached in memory, but when file is not used anymore I would like to save it on the disk. As far as I know users are removed from a room as soon as they are disconnected. Is there a way to subscribe on "room empty" event?

You could use

socket.on('disconnect', function() {})

and count the number of open connections.

  • Torben

If you're managing rooms somehow, then you can use this:

io.sockets.clients('room name');

And this returns socket instances of all client in a room. If the length of this list is 0 then it means file is no longer used by any client and is ready to be saved. Hope this will work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM