Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the rest of the files.

  • Loading branch information...
commit d8f5f6ac98f0ce261fb1603af075a20872934df3 1 parent 7c2e2c8
@aviddiviner authored
Showing with 88 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +54 −0 index.js
  3. +14 −0 package.json
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 David Irvine
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
54 index.js
@@ -0,0 +1,54 @@
+/**
+ * Enables session handling on the socket.io socket by adding the `sconnection` event.
+ *
+ * @param {Object} socket.io Listener
+ * @param {Object} connect Session Store
+ * @api public
+ */
+exports.enable = function(socket, store, options){
+
+ per_message = (options && options.per_message) ? options.per_message : false;
+ socket.load_session_per_message = per_message; // If you need to check later
+
+ // This doesn't seem to cause any kind of recursive explosion, so it's all good I guess. :)
+ socket.on('connection', function(client){
+ client.on('message', function(message){
+ if (message.__sid && message.connect) {
+ // Message-based session handling; read & write the session on each message.
+ if (per_message) {
+ client.on('message', function(msg){
+ store.get(message.__sid, function(error, session){
+ if (error || !session) {
+ socket.emit('sinvalid', client);
+ } else {
+ client.emit('smessage', msg, session);
+ store.set(message.__sid, session);
+ }
+ });
+ });
+ socket.emit('sconnection', client);
+ }
+ // Connection-based session handling; read & write the session once per connection.
+ if (!per_message) {
+ store.get(message.__sid, function(error, session){
+ if (error || !session) {
+ socket.emit('sinvalid', client);
+ } else {
+ socket.emit('sconnection', client, session);
+ client.on('disconnect', function(){
+ store.set(message.__sid, session);
+ });
+ }
+ });
+ }
+ }
+ });
+ });
+ return socket;
+
+};
+
+/**
+ * Version
+ */
+exports.version = '0.4.1';
View
14 package.json
@@ -0,0 +1,14 @@
+{
+ "name" : "socket.io-sessions",
+ "description" : "Use your sessions from Connect, Express and others with Socket.IO",
+ "url" : "http://github.com/aviddiviner/Socket.IO-sessions",
+ "keywords" : ["connect", "express", "socket.io", "session", "sessions"],
+ "author" : "David Irvine <aviddiviner@gmail.com>",
+ "contributors" : [],
+ "licenses" : ["MIT"],
+ "dependencies" : [],
+ "main" : "./index",
+ "version" : "0.4.1",
+ "repository" : "git://github.com/aviddiviner/Socket.IO-sessions.git",
+ "engines" : { "node": ">= 0.4.1" }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.