Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socket.io-adapter

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket.io-adapter - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

LICENSE

8

History.md
0.4.0 / 2015-12-03
==================
* package: bump `debug`
* use a `Room` class to efficiently track room size
* allow `clients(fn)`
* call the callback on `delAll`
0.3.1 / 2014-10-27

@@ -3,0 +11,0 @@ ==================

128

index.js

@@ -6,3 +6,2 @@

var keys = require('object-keys');
var Emitter = require('events').EventEmitter;

@@ -38,3 +37,3 @@ var parser = require('socket.io-parser');

/**
* Adds a socket from a room.
* Adds a socket to a room.
*

@@ -50,4 +49,4 @@ * @param {String} socket id

this.sids[id][room] = true;
this.rooms[room] = this.rooms[room] || {};
this.rooms[room][id] = true;
this.rooms[room] = this.rooms[room] || Room();
this.rooms[room].add(id);
if (fn) process.nextTick(fn.bind(null, null));

@@ -67,7 +66,6 @@ };

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 (this.rooms.hasOwnProperty(room)) {
this.rooms[room].del(id);
if (this.rooms[room].length === 0) delete this.rooms[room];
}

@@ -82,2 +80,3 @@

* @param {String} socket id
* @param {Function} callback
* @api public

@@ -90,12 +89,11 @@ */

for (var room in rooms) {
if (rooms.hasOwnProperty(room)) {
delete this.rooms[room][id];
if (this.rooms.hasOwnProperty(room)) {
this.rooms[room].del(id);
if (this.rooms[room].length === 0) delete this.rooms[room];
}
if (this.rooms.hasOwnProperty(room) && !keys(this.rooms[room]).length) {
delete this.rooms[room];
}
}
}
delete this.sids[id];
if (fn) process.nextTick(fn.bind(null, null));
};

@@ -119,2 +117,7 @@

var flags = opts.flags || {};
var packetOpts = {
preEncoded: true,
volatile: flags.volatile,
compress: flags.compress
};
var ids = {};

@@ -130,8 +133,9 @@ var self = this;

if (!room) continue;
for (var id in room) {
if (room.hasOwnProperty(id)) {
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, true, flags.volatile);
socket.packet(encodedPackets, packetOpts);
ids[id] = true;

@@ -147,3 +151,3 @@ }

socket = self.nsp.connected[id];
if (socket) socket.packet(encodedPackets, true, flags.volatile);
if (socket) socket.packet(encodedPackets, packetOpts);
}

@@ -154,1 +158,89 @@ }

};
/**
* Gets a list of clients by sid.
*
* @param {Array} explicit set of rooms to check.
* @api public
*/
Adapter.prototype.clients = function(rooms, fn){
if ('function' == typeof rooms){
fn = rooms;
rooms = null;
}
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]];
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];
if (socket) {
sids.push(id);
ids[id] = true;
}
}
}
}
} else {
for (var id in self.sids) {
if (self.sids.hasOwnProperty(id)) {
socket = self.nsp.connected[id];
if (socket) sids.push(id);
}
}
}
if (fn) process.nextTick(fn.bind(null, null, sids));
};
/**
* 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--;
}
};

8

package.json
{
"name": "socket.io-adapter",
"version": "0.3.1",
"version": "0.4.0",
"license": "MIT",
"repository": {

@@ -10,6 +11,5 @@ "type": "git",

"dependencies": {
"debug": "1.0.2",
"socket.io-parser": "2.2.2",
"object-keys": "1.0.1"
"debug": "2.2.0",
"socket.io-parser": "2.2.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc