aboutsummaryrefslogtreecommitdiffhomepage
path: root/node_modules/socket.io-adapter
diff options
context:
space:
mode:
authorYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
committerYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
commit67fdec20726e48ba3a934cb25bb30d47ec4a4f29 (patch)
tree37fd9f4f0b0c20103e1646fc83021e4765de3680 /node_modules/socket.io-adapter
downloadspanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.tar.gz
spanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.zip
Initial commit, version 0.5.3
Diffstat (limited to 'node_modules/socket.io-adapter')
-rw-r--r--node_modules/socket.io-adapter/.npmignore1
-rw-r--r--node_modules/socket.io-adapter/LICENSE20
-rw-r--r--node_modules/socket.io-adapter/Readme.md16
-rw-r--r--node_modules/socket.io-adapter/index.js263
-rw-r--r--node_modules/socket.io-adapter/package.json81
5 files changed, 381 insertions, 0 deletions
diff --git a/node_modules/socket.io-adapter/.npmignore b/node_modules/socket.io-adapter/.npmignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/node_modules/socket.io-adapter/.npmignore
@@ -0,0 +1 @@
+node_modules
diff --git a/node_modules/socket.io-adapter/LICENSE b/node_modules/socket.io-adapter/LICENSE
new file mode 100644
index 0000000..7e43606
--- /dev/null
+++ b/node_modules/socket.io-adapter/LICENSE
@@ -0,0 +1,20 @@
+(The MIT License)
+
+Copyright (c) 2014 Guillermo Rauch <guillermo@learnboost.com>
+
+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.
diff --git a/node_modules/socket.io-adapter/Readme.md b/node_modules/socket.io-adapter/Readme.md
new file mode 100644
index 0000000..1327723
--- /dev/null
+++ b/node_modules/socket.io-adapter/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 inherit 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/node_modules/socket.io-adapter/index.js b/node_modules/socket.io-adapter/index.js
new file mode 100644
index 0000000..aeb5b6e
--- /dev/null
+++ b/node_modules/socket.io-adapter/index.js
@@ -0,0 +1,263 @@
+
+/**
+ * Module dependencies.
+ */
+
+var Emitter = require('events').EventEmitter;
+
+/**
+ * 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 = nsp.server.encoder;
+}
+
+/**
+ * Inherits from `EventEmitter`.
+ */
+
+Adapter.prototype.__proto__ = Emitter.prototype;
+
+/**
+ * Adds a socket to a room.
+ *
+ * @param {String} socket id
+ * @param {String} room name
+ * @param {Function} callback
+ * @api public
+ */
+
+Adapter.prototype.add = function(id, room, fn){
+ return this.addAll(id, [ room ], fn);
+};
+
+/**
+ * Adds a socket to a list of room.
+ *
+ * @param {String} socket id
+ * @param {String} rooms
+ * @param {Function} callback
+ * @api public
+ */
+
+Adapter.prototype.addAll = function(id, rooms, fn){
+ for (var i = 0; i < rooms.length; i++) {
+ var room = rooms[i];
+ this.sids[id] = this.sids[id] || {};
+ this.sids[id][room] = true;
+ this.rooms[room] = this.rooms[room] || Room();
+ this.rooms[room].add(id);
+ }
+ 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] || {};
+ delete this.sids[id][room];
+ if (this.rooms.hasOwnProperty(room)) {
+ this.rooms[room].del(id);
+ if (this.rooms[room].length === 0) 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
+ * @param {Function} callback
+ * @api public
+ */
+
+Adapter.prototype.delAll = function(id, fn){
+ var rooms = this.sids[id];
+ if (rooms) {
+ for (var room in rooms) {
+ if (this.rooms.hasOwnProperty(room)) {
+ this.rooms[room].del(id);
+ if (this.rooms[room].length === 0) delete this.rooms[room];
+ }
+ }
+ }
+ delete this.sids[id];
+
+ if (fn) process.nextTick(fn.bind(null, null));
+};
+
+/**
+ * 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 packetOpts = {
+ preEncoded: true,
+ volatile: flags.volatile,
+ compress: flags.compress
+ };
+ 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;
+ var sockets = room.sockets;
+ for (var id in sockets) {
+ if (sockets.hasOwnProperty(id)) {
+ if (ids[id] || ~except.indexOf(id)) continue;
+ socket = self.nsp.connected[id];
+ if (socket) {
+ socket.packet(encodedPackets, packetOpts);
+ 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, packetOpts);
+ }
+ }
+ }
+ });
+};
+
+/**
+ * Gets a list of clients by sid.
+ *
+ * @param {Array} explicit set of rooms to check.
+ * @param {Function} callback
+ * @api public
+ */
+
+Adapter.prototype.clients = function(rooms, fn){
+ if ('function' == typeof rooms){
+ fn = rooms;
+ rooms = null;
+ }
+
+ rooms = rooms || [];
+
+ var ids = {};
+ var sids = [];
+ var socket;
+
+ if (rooms.length) {
+ for (var i = 0; i < rooms.length; i++) {
+ var room = this.rooms[rooms[i]];
+ if (!room) continue;
+ var sockets = room.sockets;
+ for (var id in sockets) {
+ if (sockets.hasOwnProperty(id)) {
+ if (ids[id]) continue;
+ socket = this.nsp.connected[id];
+ if (socket) {
+ sids.push(id);
+ ids[id] = true;
+ }
+ }
+ }
+ }
+ } else {
+ for (var id in this.sids) {
+ if (this.sids.hasOwnProperty(id)) {
+ socket = this.nsp.connected[id];
+ if (socket) sids.push(id);
+ }
+ }
+ }
+
+ if (fn) process.nextTick(fn.bind(null, null, sids));
+};
+
+/**
+ * Gets the list of rooms a given client has joined.
+ *
+ * @param {String} socket id
+ * @param {Function} callback
+ * @api public
+ */
+Adapter.prototype.clientRooms = function(id, fn){
+ var rooms = this.sids[id];
+ if (fn) process.nextTick(fn.bind(null, null, rooms ? Object.keys(rooms) : null));
+};
+
+/**
+* Room constructor.
+*
+* @api private
+*/
+
+function Room(){
+ if (!(this instanceof Room)) return new Room();
+ this.sockets = {};
+ this.length = 0;
+}
+
+/**
+ * Adds a socket to a room.
+ *
+ * @param {String} socket id
+ * @api private
+ */
+
+Room.prototype.add = function(id){
+ if (!this.sockets.hasOwnProperty(id)) {
+ this.sockets[id] = true;
+ this.length++;
+ }
+};
+
+/**
+ * Removes a socket from a room.
+ *
+ * @param {String} socket id
+ * @api private
+ */
+
+Room.prototype.del = function(id){
+ if (this.sockets.hasOwnProperty(id)) {
+ delete this.sockets[id];
+ this.length--;
+ }
+};
diff --git a/node_modules/socket.io-adapter/package.json b/node_modules/socket.io-adapter/package.json
new file mode 100644
index 0000000..6b7eeba
--- /dev/null
+++ b/node_modules/socket.io-adapter/package.json
@@ -0,0 +1,81 @@
+{
+ "_args": [
+ [
+ {
+ "raw": "socket.io-adapter@~1.1.0",
+ "scope": null,
+ "escapedName": "socket.io-adapter",
+ "name": "socket.io-adapter",
+ "rawSpec": "~1.1.0",
+ "spec": ">=1.1.0 <1.2.0",
+ "type": "range"
+ },
+ "/mnt/e/Yaroslav/Documents/Webs/nodejs/checkers/node_modules/socket.io"
+ ]
+ ],
+ "_from": "socket.io-adapter@>=1.1.0 <1.2.0",
+ "_id": "socket.io-adapter@1.1.1",
+ "_inCache": true,
+ "_location": "/socket.io-adapter",
+ "_nodeVersion": "6.10.3",
+ "_npmOperationalInternal": {
+ "host": "s3://npm-registry-packages",
+ "tmp": "tmp/socket.io-adapter-1.1.1.tgz_1501675485180_0.7659221475478262"
+ },
+ "_npmUser": {
+ "name": "darrachequesne",
+ "email": "damien.arrachequesne@gmail.com"
+ },
+ "_npmVersion": "3.10.10",
+ "_phantomChildren": {},
+ "_requested": {
+ "raw": "socket.io-adapter@~1.1.0",
+ "scope": null,
+ "escapedName": "socket.io-adapter",
+ "name": "socket.io-adapter",
+ "rawSpec": "~1.1.0",
+ "spec": ">=1.1.0 <1.2.0",
+ "type": "range"
+ },
+ "_requiredBy": [
+ "/socket.io"
+ ],
+ "_resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz",
+ "_shasum": "2a805e8a14d6372124dd9159ad4502f8cb07f06b",
+ "_shrinkwrap": null,
+ "_spec": "socket.io-adapter@~1.1.0",
+ "_where": "/mnt/e/Yaroslav/Documents/Webs/nodejs/checkers/node_modules/socket.io",
+ "bugs": {
+ "url": "https://github.com/socketio/socket.io-adapter/issues"
+ },
+ "dependencies": {},
+ "description": "default socket.io in-memory adapter",
+ "devDependencies": {},
+ "directories": {},
+ "dist": {
+ "shasum": "2a805e8a14d6372124dd9159ad4502f8cb07f06b",
+ "tarball": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz"
+ },
+ "gitHead": "6874ea4952346d1dfc80c53beaa2ec014fc024b7",
+ "homepage": "https://github.com/socketio/socket.io-adapter#readme",
+ "license": "MIT",
+ "maintainers": [
+ {
+ "name": "darrachequesne",
+ "email": "damien.arrachequesne@gmail.com"
+ },
+ {
+ "name": "rauchg",
+ "email": "rauchg@gmail.com"
+ }
+ ],
+ "name": "socket.io-adapter",
+ "optionalDependencies": {},
+ "readme": "ERROR: No README data found!",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/socketio/socket.io-adapter.git"
+ },
+ "scripts": {},
+ "version": "1.1.1"
+}