[Pkg-javascript-commits] [node-socket.io-adapter] 01/02: Imported Upstream version 0.3.1

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sat Mar 28 18:20:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-socket.io-adapter.

commit 85af9b8ea4246485b5ec81271d07eec96f81f21f
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sat Mar 28 18:04:05 2015 +0100

    Imported Upstream version 0.3.1
---
 .gitignore   |   1 +
 History.md   |  25 +++++++++++
 Readme.md    |  16 +++++++
 index.js     | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json |  14 ++++++
 5 files changed, 200 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/History.md b/History.md
new file mode 100644
index 0000000..1234b9f
--- /dev/null
+++ b/History.md
@@ -0,0 +1,25 @@
+
+0.3.1 / 2014-10-27
+==================
+
+ * bump parser version
+ * fix room autopruning
+ * add autoprunning of empty rooms
+ * rooms are now created as objects
+ * added the repository field.
+ * updated the debug dependency.
+
+0.3.0 / 2014-05-30
+==================
+
+ * bump `socket.io-parser` for binary ack fix
+
+0.2.0 / 2014-03-14
+==================
+
+ * upgraded faster parser
+
+0.1.0 / 2014-03-07
+==================
+
+ * initial commit
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..bcef653
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,16 @@
+
+# socket.io-adapter
+
+Default socket.io in-memory adapter class.
+
+## How to use
+
+This module is not intended for end-user usage, but can be used as an
+interface to inheirt from from other adapters you might want to build.
+
+As an example of an adapter that builds on top of this, please take a look
+at [socket.io-redis](https://github.com/learnboost/socket.io-redis).
+
+## License
+
+MIT
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..58b84c9
--- /dev/null
+++ b/index.js
@@ -0,0 +1,144 @@
+
+/**
+ * Module dependencies.
+ */
+
+var keys = require('object-keys');
+var Emitter = require('events').EventEmitter;
+var parser = require('socket.io-parser');
+
+/**
+ * Module exports.
+ */
+
+module.exports = Adapter;
+
+/**
+ * Memory adapter constructor.
+ *
+ * @param {Namespace} nsp
+ * @api public
+ */
+
+function Adapter(nsp){
+  this.nsp = nsp;
+  this.rooms = {};
+  this.sids = {};
+  this.encoder = new parser.Encoder();
+}
+
+/**
+ * Inherits from `EventEmitter`.
+ */
+
+Adapter.prototype.__proto__ = Emitter.prototype;
+
+/**
+ * Adds a socket from a room.
+ *
+ * @param {String} socket id
+ * @param {String} room name
+ * @param {Function} callback
+ * @api public
+ */
+
+Adapter.prototype.add = function(id, room, fn){
+  this.sids[id] = this.sids[id] || {};
+  this.sids[id][room] = true;
+  this.rooms[room] = this.rooms[room] || {};
+  this.rooms[room][id] = true;
+  if (fn) process.nextTick(fn.bind(null, null));
+};
+
+/**
+ * Removes a socket from a room.
+ *
+ * @param {String} socket id
+ * @param {String} room name
+ * @param {Function} callback
+ * @api public
+ */
+
+Adapter.prototype.del = function(id, room, fn){
+  this.sids[id] = this.sids[id] || {};
+  this.rooms[room] = this.rooms[room] || {};
+  delete this.sids[id][room];
+  delete this.rooms[room][id];
+  if (this.rooms.hasOwnProperty(room) && !keys(this.rooms[room]).length) {
+    delete this.rooms[room];
+  }
+
+  if (fn) process.nextTick(fn.bind(null, null));
+};
+
+/**
+ * Removes a socket from all rooms it's joined.
+ *
+ * @param {String} socket id
+ * @api public
+ */
+
+Adapter.prototype.delAll = function(id, fn){
+  var rooms = this.sids[id];
+  if (rooms) {
+    for (var room in rooms) {
+      if (rooms.hasOwnProperty(room)) {
+        delete this.rooms[room][id];
+      }
+
+      if (this.rooms.hasOwnProperty(room) && !keys(this.rooms[room]).length) {
+        delete this.rooms[room];
+      }
+    }
+  }
+  delete this.sids[id];
+};
+
+/**
+ * Broadcasts a packet.
+ *
+ * Options:
+ *  - `flags` {Object} flags for this packet
+ *  - `except` {Array} sids that should be excluded
+ *  - `rooms` {Array} list of rooms to broadcast to
+ *
+ * @param {Object} packet object
+ * @api public
+ */
+
+Adapter.prototype.broadcast = function(packet, opts){
+  var rooms = opts.rooms || [];
+  var except = opts.except || [];
+  var flags = opts.flags || {};
+  var ids = {};
+  var self = this;
+  var socket;
+
+  packet.nsp = this.nsp.name;
+  this.encoder.encode(packet, function(encodedPackets) {
+    if (rooms.length) {
+      for (var i = 0; i < rooms.length; i++) {
+        var room = self.rooms[rooms[i]];
+        if (!room) continue;
+        for (var id in room) {
+          if (room.hasOwnProperty(id)) {
+            if (ids[id] || ~except.indexOf(id)) continue;
+            socket = self.nsp.connected[id];
+            if (socket) {
+              socket.packet(encodedPackets, true, flags.volatile);
+              ids[id] = true;
+            }
+          }
+        }
+      }
+    } else {
+      for (var id in self.sids) {
+        if (self.sids.hasOwnProperty(id)) {
+          if (~except.indexOf(id)) continue;
+          socket = self.nsp.connected[id];
+          if (socket) socket.packet(encodedPackets, true, flags.volatile);
+        }
+      }
+    }
+  });
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..8ab9e7c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,14 @@
+{
+  "name": "socket.io-adapter",
+  "version": "0.3.1",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/Automattic/socket.io-adapter.git"
+  },
+  "description": "",
+  "dependencies": {
+    "debug": "1.0.2",
+    "socket.io-parser": "2.2.2",
+    "object-keys": "1.0.1"
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-socket.io-adapter.git



More information about the Pkg-javascript-commits mailing list