forked from wcamarao/session.socket.io
-
Notifications
You must be signed in to change notification settings - Fork 4
/
package.json
39 lines (39 loc) · 6.63 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
"name": "session.socket.io-express4",
"version": "0.1.0",
"description": "Express middleware sessions in socket.io",
"author": {
"name": "Wagner Camarao",
"email": "[email protected]"
},
"contributors": [
{
"name": "Wagner Camarao",
"email": "[email protected]"
},
{
"name": "Eirik Vullum",
"email": "[email protected]"
},
{
"name": "Nathan G. Romano",
"email": "[email protected]"
}
],
"repository": {
"type": "git",
"url": "https://github.com/eiriklv/session.socket.io.git"
},
"engine": {
"node": ">=0.6"
},
"dependencies": {},
"devDependencies": {},
"main": "./session.socket.io.js",
"readme": "session.socket.io (SessionSockets)\n==================================\n\nThis tiny node module aims to simplify your socket.io application when using http sessions from express or connect middlewares. It has no dependencies and can be initialized using any session store and cookie parser compatible with express or connect.\n\nIt's written and tested using express 3.0.0rc4, connect 2.4.5 and socket.io 0.9.10.\n\n## Quick Start\n\nImport the module and initialize it providing the required parameters\n\n```js\nvar SessionSockets = require('session.socket.io')\n , sessionSockets = new SessionSockets(io, sessionStore, cookieParser);\n```\n\nListen to socket connections and get the socket _as provided by socket.io_, together with either the session or an error\n\n```js\nsessionSockets.on('connection', function (err, socket, session) {\n //your regular socket.io code goes here\n //and you can still use your io object\n});\n```\n\n## Running the example\n\n $ cd example\n $ npm install\n $ node server.js\n\n Visit http://localhost:3000\n\n## Saving values into the session\n\n```js\nsessionSockets.on('connection', function (err, socket, session) {\n session.foo = 'bar';\n //at this point the value is not yet saved into the session\n session.save();\n //now you can read session.foo from your express routes or connect middlewares\n});\n```\n\n## Namespacing\n\n```js\nsessionSockets.of('/chat').on('connection', function (err, socket, session) {\n //the socket here will address messages only to the /chat namespace\n});\n```\n\n## Get session for a client\n\n```js\nio.sockets.clients().forEach(function (socket) {\n // so far we have access only to client sockets\n sessionSockets.getSession(socket, function (err, session) {\n // getSession gives you an error object or the session for a given socket\n });\n});\n```\n\n## Error handling\n\nNote that now you receive 3 parameters in the connection callback (err, socket, session). The first will be an error object (if an error has occured) from either the cookie parser (when trying to parse the cookie) or the session store (when trying to lookup the session by key); the second will _always be the socket as provided by socket.io_; and the third (if no error has ocurred) will be the corresponding user session for that socket connection.\n\n## Troubleshooting\n\nThe cookieParser doesn't need to be the same reference, you can create another instance somewhere else, but it _should_ take the same 'secret', otherwise the cookie id won't be decoded, therefore the session data won't be retrieved.\n\nThe sessionStore _must_ be the same instance. It's quite obvious why.\n\nYou can always debug the cookies and session data from any socket.handshake. The socket is the same _as provided by socket.io_ and contains all of that information.\n\n## Cookie lookup precedence\n\nWhen looking up for the cookie in a socket.handshake, SessionSockets will take precedence on the following order:\n\n1. secureCookies\n2. signedCookies\n3. cookies\n\n## Specifying a session store key\n\nYou can specify your own session store key\n\n```js\nnew SessionSockets(io, sessionStore, cookieParser, 'yourOwnSessionStoreKey');\n```\n\nIt defaults to 'connect.sid' (which is default for both connect and express).\n\n## A more detailed example\n\n```js\nvar http = require('http')\n , connect = require('connect')\n , express = require('express')\n , app = express();\n```\n\nBelow are the two main references you will need to keep\n\n```js\nvar cookieParser = express.cookieParser('your secret sauce')\n , sessionStore = new connect.middleware.session.MemoryStore();\n```\n\nBoth will be used by express - so far everything's familiar, except that you need to provide sessionStore when using express.session(). Here you could use Redis or any other store as well.\n\n```js\napp.configure(function () {\n //hiding other express configuration\n app.use(cookieParser);\n app.use(express.session({ store: sessionStore }));\n});\n```\n\nThen you create the server and bind socket.io to it (nothing new here)\n\n```js\nvar server = http.createServer(app)\n , io = require('socket.io').listen(server);\n```\n\nNow instead of listening to io.sockets.on('connection', ...) you will pass it together with the sessionStore and cookieParser\n\n```js\nvar SessionSockets = require('session.socket.io')\n , sessionSockets = new SessionSockets(io, sessionStore, cookieParser);\n```\n\nWhich will use it all together to get you what matters\n\n```js\nsessionSockets.on('connection', function (err, socket, session) {\n //your regular socket.io code goes here\n //and you can still use your io object\n});\n```\n\n## License\n\n (The MIT License)\n\n Copyright (c) 2012 Wagner Camarao <[email protected]>\n\n Permission is hereby granted, free of charge, to any person obtaining\n a copy of this software and associated documentation files (the \"Software\"),\n to deal in the Software without restriction, including without limitation\n the rights to use, copy, modify, merge, publish, distribute, sublicense,\n and/or sell copies of the Software, and to permit persons to whom the\n Software is furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included\n in all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\n OR OTHER DEALINGS IN THE SOFTWARE.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/eiriklv/session.socket.io/issues"
},
"homepage": "https://github.com/eiriklv/session.socket.io"
}