socket.io
Advanced tools
Comparing version 1.5.1 to 1.6.0
1.6.0 / 2016-11-20 | ||
================== | ||
* [fix] Make ETag header comply with standard. (#2603) | ||
* [feature] Loading client script on demand. (#2567) | ||
* [test] Fix leaking clientSocket (#2721) | ||
* [feature] Add support for all event emitter methods (#2601) | ||
* [chore] Update year to 2016 (#2456) | ||
* [feature] Add support for socket middleware (#2306) | ||
* [feature] add support for Server#close(callback) (#2748) | ||
* [fix] Don't drop query variables on handshake (#2745) | ||
* [example] Add disconnection/reconnection logs to the chat example (#2675) | ||
* [perf] Minor code optimizations (#2219) | ||
* [chore] Bump debug to version 2.3.3 (#2754) | ||
* [chore] Bump engine.io to version 1.8.0 (#2755) | ||
* [chore] Bump socket.io-adapter to version 0.5.0 (#2756) | ||
1.5.1 / 2016-10-24 | ||
@@ -3,0 +20,0 @@ ================== |
@@ -12,2 +12,3 @@ | ||
var Client = require('./client'); | ||
var Emitter = require('events').EventEmitter; | ||
var Namespace = require('./namespace'); | ||
@@ -28,3 +29,3 @@ var Adapter = require('socket.io-adapter'); | ||
var clientSource = read(require.resolve('socket.io-client/socket.io.js'), 'utf-8'); | ||
var clientSource = undefined; | ||
@@ -99,2 +100,7 @@ /** | ||
this._serveClient = v; | ||
if (v && !clientSource) { | ||
clientSource = read(require.resolve('socket.io-client/socket.io.js'), 'utf-8'); | ||
} | ||
return this; | ||
@@ -278,5 +284,9 @@ }; | ||
Server.prototype.serve = function(req, res){ | ||
// Per the standard, ETags must be quoted: | ||
// https://tools.ietf.org/html/rfc7232#section-2.3 | ||
var expectedEtag = '"' + clientVersion + '"'; | ||
var etag = req.headers['if-none-match']; | ||
if (etag) { | ||
if (clientVersion == etag) { | ||
if (expectedEtag == etag) { | ||
debug('serve client 304'); | ||
@@ -291,3 +301,3 @@ res.writeHead(304); | ||
res.setHeader('Content-Type', 'application/javascript'); | ||
res.setHeader('ETag', clientVersion); | ||
res.setHeader('ETag', expectedEtag); | ||
res.writeHead(200); | ||
@@ -350,6 +360,7 @@ res.end(clientSource); | ||
* | ||
* @param {Function} [fn] optional, called as `fn([err])` on error OR all conns closed | ||
* @api public | ||
*/ | ||
Server.prototype.close = function(){ | ||
Server.prototype.close = function(fn){ | ||
for (var id in this.nsps['/'].sockets) { | ||
@@ -363,4 +374,6 @@ if (this.nsps['/'].sockets.hasOwnProperty(id)) { | ||
if(this.httpServer){ | ||
this.httpServer.close(); | ||
if (this.httpServer) { | ||
this.httpServer.close(fn); | ||
} else { | ||
fn && fn(); | ||
} | ||
@@ -373,6 +386,9 @@ }; | ||
['on', 'to', 'in', 'use', 'emit', 'send', 'write', 'clients', 'compress'].forEach(function(fn){ | ||
var emitterMethods = Object.keys(Emitter.prototype).filter(function(key){ | ||
return typeof Emitter.prototype[key] === 'function'; | ||
}); | ||
emitterMethods.concat(['to', 'in', 'use', 'send', 'write', 'clients', 'compress']).forEach(function(fn){ | ||
Server.prototype[fn] = function(){ | ||
var nsp = this.sockets[fn]; | ||
return nsp.apply(this.sockets, arguments); | ||
return this.sockets[fn].apply(this.sockets, arguments); | ||
}; | ||
@@ -382,6 +398,8 @@ }); | ||
Namespace.flags.forEach(function(flag){ | ||
Server.prototype.__defineGetter__(flag, function(){ | ||
this.sockets.flags = this.sockets.flags || {}; | ||
this.sockets.flags[flag] = true; | ||
return this; | ||
Object.defineProperty(Server.prototype, flag, { | ||
get: function() { | ||
this.sockets.flags = this.sockets.flags || {}; | ||
this.sockets.flags[flag] = true; | ||
return this; | ||
} | ||
}); | ||
@@ -388,0 +406,0 @@ }); |
@@ -72,6 +72,8 @@ | ||
exports.flags.forEach(function(flag){ | ||
Namespace.prototype.__defineGetter__(flag, function(){ | ||
this.flags = this.flags || {}; | ||
this.flags[flag] = true; | ||
return this; | ||
Object.defineProperty(Namespace.prototype, flag, { | ||
get: function() { | ||
this.flags = this.flags || {}; | ||
this.flags[flag] = true; | ||
return this; | ||
} | ||
}); | ||
@@ -141,3 +143,3 @@ }); | ||
Namespace.prototype.to = | ||
Namespace.prototype['in'] = function(name){ | ||
Namespace.prototype.in = function(name){ | ||
this.rooms = this.rooms || []; | ||
@@ -144,0 +146,0 @@ if (!~this.rooms.indexOf(name)) this.rooms.push(name); |
@@ -11,2 +11,3 @@ | ||
var hasBin = require('has-binary'); | ||
var assign = require('object-assign'); | ||
@@ -72,2 +73,3 @@ /** | ||
this.handshake = this.buildHandshake(query); | ||
this.fns = []; | ||
} | ||
@@ -86,6 +88,8 @@ | ||
flags.forEach(function(flag){ | ||
Socket.prototype.__defineGetter__(flag, function(){ | ||
this.flags = this.flags || {}; | ||
this.flags[flag] = true; | ||
return this; | ||
Object.defineProperty(Socket.prototype, flag, { | ||
get: function() { | ||
this.flags = this.flags || {}; | ||
this.flags[flag] = true; | ||
return this; | ||
} | ||
}); | ||
@@ -100,4 +104,6 @@ }); | ||
Socket.prototype.__defineGetter__('request', function(){ | ||
return this.conn.request; | ||
Object.defineProperty(Socket.prototype, 'request', { | ||
get: function() { | ||
return this.conn.request; | ||
} | ||
}); | ||
@@ -116,9 +122,3 @@ | ||
//if socket-specific query exist, replace query strings in requestQuery | ||
if(query){ | ||
query.t = requestQuery.t; | ||
query.EIO = requestQuery.EIO; | ||
query.transport = requestQuery.transport; | ||
return query; | ||
} | ||
return requestQuery || {}; | ||
return assign({}, query, requestQuery); | ||
} | ||
@@ -353,3 +353,3 @@ return { | ||
emit.apply(this, args); | ||
this.dispatch(args); | ||
}; | ||
@@ -491,1 +491,61 @@ | ||
}; | ||
/** | ||
* Dispatch incoming event to socket listeners. | ||
* | ||
* @param {Array} event that will get emitted | ||
* @api private | ||
*/ | ||
Socket.prototype.dispatch = function(event){ | ||
debug('dispatching an event %j', event); | ||
var self = this; | ||
this.run(event, function(err){ | ||
process.nextTick(function(){ | ||
if (err) { | ||
return self.emit('error', err.data || err.message); | ||
} | ||
emit.apply(self, event); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Sets up socket middleware. | ||
* | ||
* @param {Function} middleware function (event, next) | ||
* @return {Socket} self | ||
* @api public | ||
*/ | ||
Socket.prototype.use = function(fn){ | ||
this.fns.push(fn); | ||
return this; | ||
}; | ||
/** | ||
* Executes the middleware for an incoming event. | ||
* | ||
* @param {Array} event that will get emitted | ||
* @param {Function} last fn call in the middleware | ||
* @api private | ||
*/ | ||
Socket.prototype.run = function(event, fn){ | ||
var fns = this.fns.slice(0); | ||
if (!fns.length) return fn(null); | ||
function run(i){ | ||
fns[i](event, function(err){ | ||
// upon error, short-circuit | ||
if (err) return fn(err); | ||
// if no middleware left, summon callback | ||
if (!fns[i + 1]) return fn(null); | ||
// go on to next | ||
run(i + 1); | ||
}); | ||
} | ||
run(0); | ||
}; |
{ | ||
"name": "socket.io", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "node.js realtime framework server", | ||
@@ -27,8 +27,9 @@ "keywords": [ | ||
"dependencies": { | ||
"engine.io": "1.7.2", | ||
"socket.io-parser": "2.3.1", | ||
"socket.io-client": "1.5.1", | ||
"socket.io-adapter": "0.4.0", | ||
"debug": "2.3.3", | ||
"engine.io": "1.8.0", | ||
"has-binary": "0.1.7", | ||
"debug": "2.2.0" | ||
"object-assign": "4.1.0", | ||
"socket.io-adapter": "0.5.0", | ||
"socket.io-client": "1.6.0", | ||
"socket.io-parser": "2.3.1" | ||
}, | ||
@@ -35,0 +36,0 @@ "devDependencies": { |
@@ -201,5 +201,10 @@ | ||
### Server#close | ||
### Server#close([fn:Function]) | ||
Closes socket.io server | ||
Closes socket.io server. | ||
The optional `fn` is passed to the `server.close([callback])` method of the | ||
core `net` module and is called on error or when all connections are closed. | ||
The callback is expected to implement the common single argument `err` | ||
signature (if any). | ||
@@ -308,2 +313,21 @@ ```js | ||
### Socket#use(fn:Function):Socket | ||
Registers a middleware, which is a function that gets executed for | ||
every incoming `Packet` and receives as parameter the packet and a | ||
function to optionally defer execution to the next registered | ||
middleware. | ||
```js | ||
var io = require('socket.io')(); | ||
io.on('connection', function(socket){ | ||
socket.use(function(packet, next){ | ||
if (packet.doge === true) return next(); | ||
next(new Error('Not a doge error')); | ||
}); | ||
``` | ||
Errors passed to middleware callbacks are sent as special `error` | ||
packets to clients. | ||
### Socket#rooms:Object | ||
@@ -310,0 +334,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67526
1251
490
7
+ Addedobject-assign@4.1.0
+ Addedcomponent-emitter@1.2.1(transitive)
+ Addedcookie@0.3.1(transitive)
+ Addeddebug@2.3.3(transitive)
+ Addedengine.io@1.8.0(transitive)
+ Addedengine.io-client@1.8.0(transitive)
+ Addedms@0.7.2(transitive)
+ Addedobject-assign@4.1.0(transitive)
+ Addedparsejson@0.0.3(transitive)
+ Addedparseqs@0.0.5(transitive)
+ Addedparseuri@0.0.5(transitive)
+ Addedsocket.io-adapter@0.5.0(transitive)
+ Addedsocket.io-client@1.6.0(transitive)
+ Addedxmlhttprequest-ssl@1.5.3(transitive)
- Removedbenchmark@1.0.0(transitive)
- Removedcomponent-emitter@1.2.0(transitive)
- Removeddebug@0.7.4(transitive)
- Removedengine.io@1.7.2(transitive)
- Removedengine.io-client@1.7.2(transitive)
- Removedjson3@3.2.6(transitive)
- Removedparsejson@0.0.1(transitive)
- Removedparseqs@0.0.2(transitive)
- Removedparseuri@0.0.4(transitive)
- Removedsocket.io-adapter@0.4.0(transitive)
- Removedsocket.io-client@1.5.1(transitive)
- Removedsocket.io-parser@2.2.2(transitive)
- Removedxmlhttprequest-ssl@1.5.1(transitive)
Updateddebug@2.3.3
Updatedengine.io@1.8.0
Updatedsocket.io-adapter@0.5.0
Updatedsocket.io-client@1.6.0