Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: socketio/socket.io-adapter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: efd6141dbd6947761ee9ce91fa729f3bec0aaab0
Choose a base ref
...
head repository: socketio/socket.io-adapter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6874ea4952346d1dfc80c53beaa2ec014fc024b7
Choose a head ref
  • 12 commits
  • 4 files changed
  • 4 contributors

Commits on Oct 18, 2016

  1. Copy the full SHA
    97bdbab View commit details

Commits on Nov 20, 2016

  1. Copy the full SHA
    35987a5 View commit details
  2. Copy the full SHA
    915af31 View commit details
  3. [feature] Add clientRooms method (#41)

    That method returns the list of rooms a given socket has joined. It is
    intended to be used by other adapters, without them needing to access
    the innards of the adapter.
    darrachequesne authored Nov 20, 2016
    Copy the full SHA
    ffadfa6 View commit details
  4. Copy the full SHA
    9a621ec View commit details

Commits on Feb 16, 2017

  1. Copy the full SHA
    fd086d7 View commit details
  2. [feat] Remove the socket.io-parser dependency (#47)

    That will allow to use a custom parser (see socketio/socket.io#2829).
    darrachequesne authored Feb 16, 2017
    Copy the full SHA
    40764bb View commit details
  3. Copy the full SHA
    b983377 View commit details

Commits on Feb 26, 2017

  1. [feat] Add addAll method (#49)

    That will allow to efficiently join a list of rooms.
    darrachequesne authored Feb 26, 2017
    Copy the full SHA
    f627cd2 View commit details
  2. Copy the full SHA
    c6f7bae View commit details

Commits on Aug 2, 2017

  1. Copy the full SHA
    bdb015a View commit details
  2. [chore] release 1.1.1

    darrachequesne committed Aug 2, 2017
    Copy the full SHA
    6874ea4 View commit details
Showing with 43 additions and 53 deletions.
  1. +0 −33 History.md
  2. +1 −1 Readme.md
  3. +39 −12 index.js
  4. +3 −7 package.json
33 changes: 0 additions & 33 deletions History.md

This file was deleted.

2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ 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.
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).
51 changes: 39 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
*/

var Emitter = require('events').EventEmitter;
var parser = require('socket.io-parser');

/**
* Module exports.
@@ -23,7 +22,7 @@ function Adapter(nsp){
this.nsp = nsp;
this.rooms = {};
this.sids = {};
this.encoder = new parser.Encoder();
this.encoder = nsp.server.encoder;
}

/**
@@ -42,10 +41,26 @@ Adapter.prototype.__proto__ = Emitter.prototype;
*/

Adapter.prototype.add = function(id, room, fn){
this.sids[id] = this.sids[id] || {};
this.sids[id][room] = true;
this.rooms[room] = this.rooms[room] || Room();
this.rooms[room].add(id);
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));
};

@@ -151,6 +166,7 @@ Adapter.prototype.broadcast = function(packet, opts){
* Gets a list of clients by sid.
*
* @param {Array} explicit set of rooms to check.
* @param {Function} callback
* @api public
*/

@@ -163,19 +179,18 @@ Adapter.prototype.clients = function(rooms, fn){
rooms = rooms || [];

var ids = {};
var self = this;
var sids = [];
var socket;

if (rooms.length) {
for (var i = 0; i < rooms.length; i++) {
var room = self.rooms[rooms[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 = self.nsp.connected[id];
socket = this.nsp.connected[id];
if (socket) {
sids.push(id);
ids[id] = true;
@@ -184,9 +199,9 @@ Adapter.prototype.clients = function(rooms, fn){
}
}
} else {
for (var id in self.sids) {
if (self.sids.hasOwnProperty(id)) {
socket = self.nsp.connected[id];
for (var id in this.sids) {
if (this.sids.hasOwnProperty(id)) {
socket = this.nsp.connected[id];
if (socket) sids.push(id);
}
}
@@ -195,6 +210,18 @@ Adapter.prototype.clients = function(rooms, fn){
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.
*
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"name": "socket.io-adapter",
"version": "0.4.0",
"version": "1.1.1",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/Automattic/socket.io-adapter.git"
"url": "git://github.com/socketio/socket.io-adapter.git"
},
"description": "",
"dependencies": {
"debug": "2.2.0",
"socket.io-parser": "2.2.2"
}
"description": "default socket.io in-memory adapter"
}