Reputation: 51393
I'm looking for some help figuring out sessions on a server that relies on express and socket.io. Mostly the goal is handling things like pairing socket.io session ids with user ids, maintaing state on reconnects, and being able to easily group any actors on the server.
Any help is very much appreciated.
Thanks.
Upvotes: 7
Views: 3942
Reputation: 907
If you are using socket.io v1+ you can do it the less hacky way by using middleware. Look at https://github.com/peerigon/socket.io-session-middleware for a middleware which shares sessions between socket.io, connect, express.
Upvotes: 0
Reputation: 4694
I've just uploaded a project which allows you to use your sessions from express in Socket.IO. Maybe this can be of some help to you. https://github.com/aviddiviner/Socket.IO-sessions
You can install it with npm install socket.io-sessions
. Be sure to check out the README.
If you're new to Node, I would suggest spending some time reading through the express docs on how they handle sessions as well. http://expressjs.com/guide.html#session-support
Lastly, I've also posted some code snippets here: socket.io and session?
Hope that helps!
Upvotes: 5