mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 16:08:24 -05:00
Compare commits
86 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65f1399a44 | ||
|
|
d86ffcf06d | ||
|
|
ab5beaff63 | ||
|
|
f0ef33b45f | ||
|
|
a4ec5aafa6 | ||
|
|
984639ba67 | ||
|
|
9923c1dee9 | ||
|
|
1b0a4849df | ||
|
|
4fc43f322f | ||
|
|
5c0f78ab02 | ||
|
|
d8c7060cc8 | ||
|
|
b0335b0a61 | ||
|
|
a1797ccd4b | ||
|
|
a1c997bc58 | ||
|
|
0b9b28d251 | ||
|
|
a79b2fa761 | ||
|
|
195eba74de | ||
|
|
3edebe5d61 | ||
|
|
b56389fbc8 | ||
|
|
203293db0b | ||
|
|
2b7ea448c4 | ||
|
|
c627f1b7d0 | ||
|
|
4c20afd4b7 | ||
|
|
f689434f61 | ||
|
|
b694ee68c9 | ||
|
|
8b22ca2ffd | ||
|
|
5c50c4844f | ||
|
|
4fcad6e4bc | ||
|
|
3b2316e0d8 | ||
|
|
a821cce390 | ||
|
|
abe142ac66 | ||
|
|
5eff0e5ca7 | ||
|
|
c06242efd3 | ||
|
|
f69f387e1d | ||
|
|
f5c10aec7f | ||
|
|
34bd9d9092 | ||
|
|
c30151d03a | ||
|
|
f784c477f0 | ||
|
|
c899c98f31 | ||
|
|
53f0f4d66d | ||
|
|
c826fadb9f | ||
|
|
097094cd7a | ||
|
|
c3fa1bf5af | ||
|
|
8798cfbced | ||
|
|
81d71ebb08 | ||
|
|
074e74c6c5 | ||
|
|
65b8272724 | ||
|
|
ca3f3379cb | ||
|
|
faad10baee | ||
|
|
d3eac92eaa | ||
|
|
fb5b9bc0b1 | ||
|
|
34505071f4 | ||
|
|
0a2d0b9d0b | ||
|
|
4495f5987a | ||
|
|
aad29d5d92 | ||
|
|
ad8452035d | ||
|
|
b2ffed891b | ||
|
|
27ab98dca4 | ||
|
|
a8ca11cb47 | ||
|
|
d39d1401c4 | ||
|
|
159c75096d | ||
|
|
a70347b15f | ||
|
|
1a2c8aa31f | ||
|
|
15e1e68cfd | ||
|
|
167da44211 | ||
|
|
1372838092 | ||
|
|
7257e1ec36 | ||
|
|
af5960bc28 | ||
|
|
206cfdf9c6 | ||
|
|
65d7229079 | ||
|
|
c18aa40ba6 | ||
|
|
249f33da16 | ||
|
|
b9a7c8be90 | ||
|
|
e4ac72a316 | ||
|
|
dff9cbfe1b | ||
|
|
489bc860d2 | ||
|
|
29a8fff576 | ||
|
|
e66a68f0fa | ||
|
|
4058eacbd4 | ||
|
|
8cbd1544b9 | ||
|
|
f302744fec | ||
|
|
a3ba4e2c10 | ||
|
|
a483f9cafd | ||
|
|
b43c82f3db | ||
|
|
84f0099c1d | ||
|
|
c6a883c8a9 |
50
History.md
50
History.md
@@ -1,4 +1,54 @@
|
||||
|
||||
0.7.8 / 2011-08-08
|
||||
==================
|
||||
|
||||
* Changed; make sure sio#listen passes options to both HTTP server and socket.io manager.
|
||||
* Added docs for sio#listen.
|
||||
* Added options parameter support for Manager constructor.
|
||||
* Added memory leaks tests and test-leaks Makefile task.
|
||||
* Removed auto npm-linking from make test.
|
||||
* Make sure that you can disable heartbeats. [3rd-Eden]
|
||||
* Fixed rooms memory leak [3rd-Eden]
|
||||
* Send response once we got all POST data, not immediately [Pita]
|
||||
* Fixed onLeave behavior with missing clientsk [3rd-Eden]
|
||||
* Prevent duplicate references in rooms.
|
||||
* Added alias for `to` to `in` and `in` to `to`.
|
||||
* Fixed roomClients definition.
|
||||
* Removed dependency on redis for installation without npm [3rd-Eden]
|
||||
* Expose path and querystring in handshakeData [3rd-Eden]
|
||||
|
||||
0.7.7 / 2011-07-12
|
||||
==================
|
||||
|
||||
* Fixed double dispatch handling with emit to closed clients.
|
||||
* Added test for emitting to closed clients to prevent regression.
|
||||
* Fixed race condition in redis test.
|
||||
* Changed Transport#end instrumentation.
|
||||
* Leveraged $emit instead of emit internally.
|
||||
* Made tests faster.
|
||||
* Fixed double disconnect events.
|
||||
* Fixed disconnect logic
|
||||
* Simplified remote events handling in Socket.
|
||||
* Increased testcase timeout.
|
||||
* Fixed unknown room emitting (GH-291). [3rd-Eden]
|
||||
* Fixed `address` in handshakeData. [3rd-Eden]
|
||||
* Removed transports definition in chat example.
|
||||
* Fixed room cleanup
|
||||
* Fixed; make sure the client is cleaned up after booting.
|
||||
* Make sure to mark the client as non-open if the connection is closed.
|
||||
* Removed unneeded `buffer` declarations.
|
||||
* Fixed; make sure to clear socket handlers and subscriptions upon transport close.
|
||||
|
||||
0.7.6 / 2011-06-30
|
||||
==================
|
||||
|
||||
* Fixed general dispatching when a client has closed.
|
||||
|
||||
0.7.5 / 2011-06-30
|
||||
==================
|
||||
|
||||
* Fixed dispatching to clients that are disconnected.
|
||||
|
||||
0.7.4 / 2011-06-30
|
||||
==================
|
||||
|
||||
|
||||
5
Makefile
5
Makefile
@@ -2,8 +2,8 @@
|
||||
ALL_TESTS = $(shell find test/ -name '*.test.js')
|
||||
|
||||
run-tests:
|
||||
@npm link > /dev/null --local
|
||||
@./node_modules/.bin/expresso \
|
||||
-t 3000 \
|
||||
-I support \
|
||||
-I lib \
|
||||
--serial \
|
||||
@@ -16,4 +16,7 @@ test:
|
||||
test-cov:
|
||||
@TESTFLAGS=--cov $(MAKE) test
|
||||
|
||||
test-leaks:
|
||||
@ls test/leaks/* | xargs node --expose_debug_as=debug --expose_gc
|
||||
|
||||
.PHONY: test
|
||||
|
||||
@@ -20,7 +20,7 @@ Next, attach it to a HTTP/HTTPS server. If you're using the fantastic `express`
|
||||
web framework:
|
||||
|
||||
```js
|
||||
var app = express.createServer();
|
||||
var app = express.createServer()
|
||||
, io = io.listen(app);
|
||||
|
||||
app.listen(80);
|
||||
|
||||
@@ -61,10 +61,6 @@ app.listen(3000, function () {
|
||||
var io = sio.listen(app)
|
||||
, nicknames = {};
|
||||
|
||||
io.set('transports', [
|
||||
, 'xhr-polling'
|
||||
]);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('user message', function (msg) {
|
||||
socket.broadcast.emit('user message', socket.nickname, msg);
|
||||
|
||||
119
lib/manager.js
119
lib/manager.js
@@ -1,4 +1,3 @@
|
||||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
@@ -9,9 +8,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var http = require('http')
|
||||
, https = require('https')
|
||||
, fs = require('fs')
|
||||
var fs = require('fs')
|
||||
, url = require('url')
|
||||
, util = require('./util')
|
||||
, store = require('./store')
|
||||
@@ -55,7 +52,7 @@ var parent = module.parent.exports
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Manager (server) {
|
||||
function Manager (server, options) {
|
||||
this.server = server;
|
||||
this.namespaces = {};
|
||||
this.sockets = this.of('');
|
||||
@@ -83,6 +80,10 @@ function Manager (server) {
|
||||
, 'client store expiration': 15
|
||||
};
|
||||
|
||||
for (var i in options) {
|
||||
this.settings[i] = options[i];
|
||||
}
|
||||
|
||||
this.initStore();
|
||||
|
||||
// reset listeners
|
||||
@@ -99,6 +100,13 @@ function Manager (server) {
|
||||
self.handleUpgrade(req, socket, head);
|
||||
});
|
||||
|
||||
server.on('close', function () {
|
||||
clearInterval(self.gc);
|
||||
});
|
||||
|
||||
// run our private gc every 10 seconds
|
||||
this.gc = setInterval(this.garbageCollection.bind(this), 10000);
|
||||
|
||||
for (var i in transports) {
|
||||
if (transports[i].init) {
|
||||
transports[i].init(this);
|
||||
@@ -324,16 +332,6 @@ Manager.prototype.onOpen = function (id) {
|
||||
*/
|
||||
|
||||
Manager.prototype.onDispatch = function (room, packet, volatile, exceptions) {
|
||||
// go through the users who have pending buffers
|
||||
for (var i = 0, l = this.closedA.length; i < l; i++) {
|
||||
if (this.roomClients[this.closedA[i]][room]) {
|
||||
if (!~exceptions.indexOf(this.closedA[i])) {
|
||||
this.closed[this.closedA[i]].push(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// go through room clients
|
||||
if (this.rooms[room]) {
|
||||
for (var i = 0, l = this.rooms[room].length; i < l; i++) {
|
||||
var id = this.rooms[room][i];
|
||||
@@ -357,15 +355,17 @@ Manager.prototype.onDispatch = function (room, packet, volatile, exceptions) {
|
||||
|
||||
Manager.prototype.onJoin = function (id, name) {
|
||||
if (!this.roomClients[id]) {
|
||||
this.roomClients[id] = [];
|
||||
this.roomClients[id] = {};
|
||||
}
|
||||
|
||||
if (!this.rooms[name]) {
|
||||
this.rooms[name] = [];
|
||||
}
|
||||
|
||||
this.rooms[name].push(id);
|
||||
this.roomClients[id][name] = true;
|
||||
if (!~this.rooms[name].indexOf(id)) {
|
||||
this.rooms[name].push(id);
|
||||
this.roomClients[id][name] = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -376,7 +376,15 @@ Manager.prototype.onJoin = function (id, name) {
|
||||
|
||||
Manager.prototype.onLeave = function (id, room) {
|
||||
if (this.rooms[room]) {
|
||||
this.rooms[room].splice(this.rooms[room].indexOf(id), 1);
|
||||
var index = this.rooms[room].indexOf(id);
|
||||
|
||||
if (index >= 0) {
|
||||
this.rooms[room].splice(index, 1);
|
||||
}
|
||||
|
||||
if (!this.rooms[room].length) {
|
||||
delete this.rooms[room];
|
||||
}
|
||||
delete this.roomClients[id][room];
|
||||
}
|
||||
};
|
||||
@@ -388,6 +396,10 @@ Manager.prototype.onLeave = function (id, room) {
|
||||
*/
|
||||
|
||||
Manager.prototype.onClose = function (id) {
|
||||
if (this.open[id]) {
|
||||
delete this.open[id];
|
||||
}
|
||||
|
||||
this.closed[id] = [];
|
||||
this.closedA.push(id);
|
||||
|
||||
@@ -407,7 +419,9 @@ Manager.prototype.onClose = function (id) {
|
||||
*/
|
||||
|
||||
Manager.prototype.onClientDispatch = function (id, packet) {
|
||||
this.closed[id].push(packet);
|
||||
if (this.closed[id]) {
|
||||
this.closed[id].push(packet);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -434,6 +448,8 @@ Manager.prototype.onClientDisconnect = function (id, reason) {
|
||||
this.namespaces[name].handleDisconnect(id, reason);
|
||||
}
|
||||
}
|
||||
|
||||
this.onDisconnect(id);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -465,8 +481,9 @@ Manager.prototype.onDisconnect = function (id, local) {
|
||||
|
||||
if (this.roomClients[id]) {
|
||||
for (var room in this.roomClients[id]) {
|
||||
this.rooms[room].splice(this.rooms.indexOf(id), 1);
|
||||
this.onLeave(id, room);
|
||||
}
|
||||
delete this.roomClients[id]
|
||||
}
|
||||
|
||||
this.store.destroyClient(id, this.get('client store expiration'));
|
||||
@@ -583,9 +600,10 @@ Manager.prototype.handleClient = function (data, req) {
|
||||
return;
|
||||
}
|
||||
|
||||
var transport = new transports[data.transport](this, data, req);
|
||||
var transport = new transports[data.transport](this, data, req)
|
||||
, handshaken = this.handshaken[data.id];
|
||||
|
||||
if (this.handshaken[data.id]) {
|
||||
if (handshaken) {
|
||||
if (transport.open) {
|
||||
if (this.closed[data.id] && this.closed[data.id].length) {
|
||||
transport.payload(this.closed[data.id]);
|
||||
@@ -601,6 +619,11 @@ Manager.prototype.handleClient = function (data, req) {
|
||||
this.onConnect(data.id);
|
||||
this.store.publish('connect', data.id);
|
||||
|
||||
// flag as used
|
||||
delete handshaken.issued;
|
||||
this.onHandshake(data.id, handshaken);
|
||||
this.store.publish('handshake', data.id, handshaken);
|
||||
|
||||
// initialize the socket for all namespaces
|
||||
for (var i in this.namespaces) {
|
||||
var socket = this.namespaces[i].socket(data.id, true);
|
||||
@@ -775,7 +798,7 @@ Manager.prototype.handleHandshake = function (data, req, res) {
|
||||
var id = self.generateId()
|
||||
, hs = [
|
||||
id
|
||||
, self.get('heartbeat timeout') || ''
|
||||
, self.enabled('heartbeats') ? self.get('heartbeat timeout') || '' : ''
|
||||
, self.get('close timeout') || ''
|
||||
, self.transports(data).join(',')
|
||||
].join(':');
|
||||
@@ -807,16 +830,31 @@ Manager.prototype.handleHandshake = function (data, req, res) {
|
||||
*/
|
||||
|
||||
Manager.prototype.handshakeData = function (data) {
|
||||
var connectionAddress = null;
|
||||
if (data.request.connection.address) {
|
||||
connectionAddress = data.request.connection.address();
|
||||
var connection = data.request.connection
|
||||
, connectionAddress
|
||||
, date = new Date;
|
||||
|
||||
if (connection.remoteAddress) {
|
||||
connectionAddress = {
|
||||
address: connection.remoteAddress
|
||||
, port: connection.remotePort
|
||||
};
|
||||
} else if (connection.socket && connection.socket.remoteAddress) {
|
||||
connectionAddress = {
|
||||
address: connection.socket.remoteAddress
|
||||
, port: connection.socket.remotePort
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
headers: data.headers
|
||||
, address: connectionAddress
|
||||
, time: (new Date).toString()
|
||||
, time: date.toString()
|
||||
, query: data.query
|
||||
, url: data.request.url
|
||||
, xdomain: !!data.request.headers.origin
|
||||
, secure: data.request.connection.secure
|
||||
, issued: +date
|
||||
};
|
||||
};
|
||||
|
||||
@@ -946,6 +984,8 @@ Manager.prototype.checkRequest = function (req) {
|
||||
|
||||
/**
|
||||
* Declares a socket namespace
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Manager.prototype.of = function (nsp) {
|
||||
@@ -955,3 +995,26 @@ Manager.prototype.of = function (nsp) {
|
||||
|
||||
return this.namespaces[nsp] = new SocketNamespace(this, nsp);
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform garbage collection on long living objects and properties that cannot
|
||||
* be removed automatically.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Manager.prototype.garbageCollection = function () {
|
||||
// clean up unused handshakes
|
||||
var ids = Object.keys(this.handshaken)
|
||||
, i = ids.length
|
||||
, now = Date.now()
|
||||
, handshake;
|
||||
|
||||
while (i--) {
|
||||
handshake = this.handshaken[ids[i]];
|
||||
|
||||
if ('issued' in handshake && (now - handshake.issued) >= 3E4) {
|
||||
this.onDisconnect(ids[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ SocketNamespace.prototype.$emit = EventEmitter.prototype.emit;
|
||||
|
||||
SocketNamespace.prototype.clients = function (room) {
|
||||
var room = this.name + (room !== undefined ?
|
||||
(this.name !== '' ? '/' : '') + room : '');
|
||||
'/' + room : '');
|
||||
|
||||
if (!this.manager.rooms[room]) {
|
||||
return [];
|
||||
@@ -108,8 +108,8 @@ SocketNamespace.prototype.__defineGetter__('volatile', function () {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.in = function (room) {
|
||||
this.flags.endpoint = (this.name === '' ? '' : (this.name + '/')) + room;
|
||||
SocketNamespace.prototype.in = SocketNamespace.prototype.to = function (room) {
|
||||
this.flags.endpoint = this.name + (room ? '/' + room : '');
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -181,7 +181,7 @@ SocketNamespace.prototype.send = function (data) {
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.emit = function (name) {
|
||||
if (name == 'connection' || name == 'newListener') {
|
||||
if (name == 'newListener') {
|
||||
return this.$emit.apply(this, arguments);
|
||||
}
|
||||
|
||||
@@ -227,6 +227,7 @@ SocketNamespace.prototype.authorization = function (fn) {
|
||||
SocketNamespace.prototype.handleDisconnect = function (sid, reason) {
|
||||
if (this.sockets[sid] && this.sockets[sid].readable) {
|
||||
this.sockets[sid].onDisconnect(reason);
|
||||
delete this.sockets[sid];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -287,7 +288,7 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
|
||||
socket.packet({ type: 'connect' });
|
||||
|
||||
// emit connection event
|
||||
self.emit('connection', socket);
|
||||
self.$emit('connection', socket);
|
||||
};
|
||||
|
||||
switch (packet.type) {
|
||||
@@ -333,7 +334,7 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
|
||||
this.manager.onLeave(sessid, this.name);
|
||||
this.store.publish('leave', sessid, this.name);
|
||||
|
||||
socket.emit('disconnect', packet.reason || 'packet');
|
||||
socket.$emit('disconnect', packet.reason || 'packet');
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
@@ -343,6 +344,6 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
|
||||
if (dataAck)
|
||||
params.push(ack);
|
||||
|
||||
socket.emit.apply(socket, params);
|
||||
socket.$emit.apply(socket, params);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ var client = require('socket.io-client');
|
||||
* Version.
|
||||
*/
|
||||
|
||||
exports.version = '0.7.4';
|
||||
exports.version = '0.7.8';
|
||||
|
||||
/**
|
||||
* Supported protocol version.
|
||||
@@ -32,6 +32,9 @@ exports.clientVersion = client.version;
|
||||
/**
|
||||
* Attaches a manager
|
||||
*
|
||||
* @param {HTTPServer/Number} a HTTP/S server or a port number to listen on.
|
||||
* @param {Object} opts to be passed to Manager and/or http server
|
||||
* @param {Function} callback if a port is supplied
|
||||
* @api public
|
||||
*/
|
||||
|
||||
@@ -65,7 +68,7 @@ exports.listen = function (server, options, fn) {
|
||||
}
|
||||
|
||||
// otherwise assume a http/s server
|
||||
return new exports.Manager(server);
|
||||
return new exports.Manager(server, options);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,22 +19,6 @@ var parser = require('./parser')
|
||||
|
||||
exports = module.exports = Socket;
|
||||
|
||||
/**
|
||||
* Reserved event names.
|
||||
*/
|
||||
|
||||
var events = {
|
||||
message: 1
|
||||
, connect: 1
|
||||
, disconnect: 1
|
||||
, open: 1
|
||||
, close: 1
|
||||
, error: 1
|
||||
, retry: 1
|
||||
, reconnect: 1
|
||||
, newListener: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Socket constructor.
|
||||
*
|
||||
@@ -122,7 +106,7 @@ Socket.prototype.__defineGetter__('broadcast', function () {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.to = function (room) {
|
||||
Socket.prototype.to = Socket.prototype.in = function (room) {
|
||||
this.flags.room = room;
|
||||
return this;
|
||||
};
|
||||
@@ -149,7 +133,7 @@ Socket.prototype.setFlags = function () {
|
||||
|
||||
Socket.prototype.onDisconnect = function (reason) {
|
||||
if (!this.disconnected) {
|
||||
this.emit('disconnect', reason);
|
||||
this.$emit('disconnect', reason);
|
||||
this.disconnected = true;
|
||||
}
|
||||
};
|
||||
@@ -162,7 +146,7 @@ Socket.prototype.onDisconnect = function (reason) {
|
||||
|
||||
Socket.prototype.join = function (name, fn) {
|
||||
var nsp = this.namespace.name
|
||||
, name = (nsp === '' ? '' : (nsp + '/')) + name;
|
||||
, name = (nsp + '/') + name;
|
||||
|
||||
this.manager.onJoin(this.id, name);
|
||||
this.manager.store.publish('join', this.id, name);
|
||||
@@ -183,7 +167,7 @@ Socket.prototype.join = function (name, fn) {
|
||||
|
||||
Socket.prototype.leave = function (name, fn) {
|
||||
var nsp = this.namespace.name
|
||||
, name = (nsp === '' ? '' : (nsp + '/')) + name;
|
||||
, name = (nsp + '/') + name;
|
||||
|
||||
this.manager.onLeave(this.id, name);
|
||||
this.manager.store.publish('leave', this.id, name);
|
||||
@@ -293,13 +277,8 @@ Socket.prototype.disconnect = function () {
|
||||
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
|
||||
this.manager.transports[this.id].onForcedDisconnect();
|
||||
} else {
|
||||
if (this.manager.open[this.id]) {
|
||||
// if the connection is open in a different node
|
||||
this.manager.store.publish('disconnect-force:' + this.id);
|
||||
} else {
|
||||
this.manager.onClientDisconnect(this.id);
|
||||
this.manager.store.publish('disconnect:' + this.id);
|
||||
}
|
||||
this.manager.onClientDisconnect(this.id);
|
||||
this.manager.store.publish('disconnect:' + this.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +321,7 @@ Socket.prototype.$emit = EventEmitter.prototype.emit;
|
||||
*/
|
||||
|
||||
Socket.prototype.emit = function (ev) {
|
||||
if (events[ev]) {
|
||||
if (ev == 'newListener') {
|
||||
return this.$emit.apply(this, arguments);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
|
||||
var crypto = require('crypto')
|
||||
, Store = require('../store')
|
||||
, assert = require('assert')
|
||||
, redis = require('redis');
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Exports the constructor.
|
||||
@@ -25,6 +24,7 @@ Redis.Client = Client;
|
||||
* Redis store.
|
||||
* Options:
|
||||
* - nodeId (fn) gets an id that uniquely identifies this node
|
||||
* - redis (fn) redis constructor, defaults to redis
|
||||
* - redisPub (object) options to pass to the pub redis client
|
||||
* - redisSub (object) options to pass to the sub redis client
|
||||
* - redisClient (object) options to pass to the general redis client
|
||||
@@ -60,6 +60,8 @@ function Redis (opts) {
|
||||
}
|
||||
}
|
||||
|
||||
var redis = opts.redis || require('redis');
|
||||
|
||||
// initialize a pubsub client and a regular client
|
||||
this.pub = redis.createClient(opts.redisPub);
|
||||
this.sub = redis.createClient(opts.redisSub);
|
||||
|
||||
@@ -28,7 +28,6 @@ function Transport (mng, data, req) {
|
||||
this.id = data.id;
|
||||
this.disconnected = false;
|
||||
this.drained = true;
|
||||
this.buffer = [];
|
||||
this.handleRequest(req);
|
||||
};
|
||||
|
||||
@@ -260,7 +259,7 @@ Transport.prototype.clearCloseTimeout = function () {
|
||||
*/
|
||||
|
||||
Transport.prototype.setHeartbeatTimeout = function () {
|
||||
if (!this.heartbeatTimeout) {
|
||||
if (!this.heartbeatTimeout && this.manager.enabled('heartbeats')) {
|
||||
var self = this;
|
||||
|
||||
this.heartbeatTimeout = setTimeout(function () {
|
||||
@@ -280,7 +279,7 @@ Transport.prototype.setHeartbeatTimeout = function () {
|
||||
*/
|
||||
|
||||
Transport.prototype.clearHeartbeatTimeout = function () {
|
||||
if (this.heartbeatTimeout) {
|
||||
if (this.heartbeatTimeout && this.manager.enabled('heartbeats')) {
|
||||
clearTimeout(this.heartbeatTimeout);
|
||||
this.heartbeatTimeout = null;
|
||||
this.log.debug('cleared heartbeat timeout for client', this.id);
|
||||
@@ -295,7 +294,7 @@ Transport.prototype.clearHeartbeatTimeout = function () {
|
||||
*/
|
||||
|
||||
Transport.prototype.setHeartbeatInterval = function () {
|
||||
if (!this.heartbeatInterval) {
|
||||
if (!this.heartbeatInterval && this.manager.enabled('heartbeats')) {
|
||||
var self = this;
|
||||
|
||||
this.heartbeatInterval = setTimeout(function () {
|
||||
@@ -357,11 +356,13 @@ Transport.prototype.onMessage = function (packet) {
|
||||
if ('disconnect' == packet.type && packet.endpoint == '') {
|
||||
this.log.debug('got disconnection packet');
|
||||
|
||||
if (current && current.open) {
|
||||
if (current) {
|
||||
current.onForcedDisconnect();
|
||||
} else {
|
||||
this.store.publish('disconnect-force:' + this.id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.id && packet.ack != 'data') {
|
||||
@@ -397,7 +398,7 @@ Transport.prototype.onMessage = function (packet) {
|
||||
*/
|
||||
|
||||
Transport.prototype.clearHeartbeatInterval = function () {
|
||||
if (this.heartbeatInterval) {
|
||||
if (this.heartbeatInterval && this.manager.enabled('heartbeats')) {
|
||||
clearTimeout(this.heartbeatInterval);
|
||||
this.heartbeatInterval = null;
|
||||
this.log.debug('cleared heartbeat interval for client', this.id);
|
||||
@@ -439,6 +440,7 @@ Transport.prototype.close = function () {
|
||||
Transport.prototype.onClose = function () {
|
||||
if (this.open) {
|
||||
this.setCloseTimeout();
|
||||
this.clearHandlers();
|
||||
this.open = false;
|
||||
this.manager.onClose(this.id);
|
||||
this.store.publish('close', this.id);
|
||||
@@ -453,7 +455,7 @@ Transport.prototype.onClose = function () {
|
||||
|
||||
Transport.prototype.end = function (reason) {
|
||||
if (!this.disconnected) {
|
||||
this.log.info('ending socket');
|
||||
this.log.info('transport end');
|
||||
|
||||
var local = this.manager.transports[this.id];
|
||||
|
||||
@@ -480,7 +482,6 @@ Transport.prototype.discard = function () {
|
||||
this.discarded = true;
|
||||
this.clearTimeouts();
|
||||
this.clearHandlers();
|
||||
this.buffer = [];
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -54,6 +54,9 @@ HTTPTransport.prototype.handleRequest = function (req) {
|
||||
});
|
||||
|
||||
req.on('end', function () {
|
||||
res.writeHead(200, headers);
|
||||
res.end('1');
|
||||
|
||||
self.onData(self.postEncoded ? qs.parse(buffer).d : buffer);
|
||||
});
|
||||
|
||||
@@ -65,9 +68,6 @@ HTTPTransport.prototype.handleRequest = function (req) {
|
||||
headers['Access-Control-Allow-Credentials'] = 'true';
|
||||
}
|
||||
}
|
||||
|
||||
res.writeHead(200, headers);
|
||||
res.end('1');
|
||||
} else {
|
||||
this.response = req.res;
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ JSONPPolling.prototype.doWrite = function (data) {
|
||||
'Content-Type': 'text/javascript; charset=UTF-8'
|
||||
, 'Content-Length': Buffer.byteLength(data)
|
||||
, 'Connection': 'Keep-Alive'
|
||||
, 'X-XSS-Protection': '0'
|
||||
});
|
||||
|
||||
this.response.write(data);
|
||||
|
||||
11
package.json
11
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "socket.io"
|
||||
, "version": "0.7.4"
|
||||
, "description": "Realtime apps made cross-browser & easy with a WebSocket-like API"
|
||||
, "version": "0.7.8"
|
||||
, "description": "Real-time apps made cross-browser & easy with a WebSocket-like API"
|
||||
, "homepage": "http://socket.io"
|
||||
, "keywords": ["websocket", "socket", "realtime", "socket.io", "comet", "ajax"]
|
||||
, "author": "Guillermo Rauch <guillermo@learnboost.com>"
|
||||
@@ -15,13 +15,14 @@
|
||||
, "url": "https://github.com/LearnBoost/Socket.IO-node.git"
|
||||
}
|
||||
, "dependencies": {
|
||||
"socket.io-client": "0.7.3"
|
||||
, "policyfile": "0.0.3"
|
||||
, "redis": "0.6.0"
|
||||
"socket.io-client": "0.7.5"
|
||||
, "policyfile": "0.0.4"
|
||||
, "redis": "0.6.6"
|
||||
}
|
||||
, "devDependencies": {
|
||||
"expresso": "0.7.7"
|
||||
, "should": "0.0.4"
|
||||
, "assertvanish": "0.0.3-1"
|
||||
}
|
||||
, "main": "index"
|
||||
, "engines": { "node": ">= 0.4.0" }
|
||||
|
||||
@@ -180,7 +180,9 @@ client = function (port) {
|
||||
|
||||
create = function (cl) {
|
||||
console.log('');
|
||||
return io.listen(cl.port);
|
||||
var manager = io.listen(cl.port);
|
||||
manager.set('client store expiration', 0);
|
||||
return manager;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
54
test/leaks/socket.leaktest.js
Normal file
54
test/leaks/socket.leaktest.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test dependencies.
|
||||
*/
|
||||
|
||||
require.paths.unshift(__dirname + '/../../lib');
|
||||
|
||||
var assertvanish = require('assertvanish')
|
||||
, common = require('../common')
|
||||
, ports = 15800;
|
||||
|
||||
function resultCallback (leaks, leakedSocket) {
|
||||
if (leaks) {
|
||||
console.error('Leak detected');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.error('No leaks');
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
|
||||
var cl = client(++ports);
|
||||
var io = create(cl);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
console.log('connected');
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
console.log("client gone");
|
||||
setTimeout(gc, 1000);
|
||||
assertvanish(socket, 2000, {silent: true, callback: resultCallback});
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
cl.handshake(function (sid) {
|
||||
var ws = websocket(cl, sid);
|
||||
ws.on('open', function () {
|
||||
console.log('open!');
|
||||
setTimeout(function() {
|
||||
ws.close();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
}, 100);
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
@@ -21,6 +20,22 @@ var sio = require('socket.io')
|
||||
module.exports = {
|
||||
|
||||
'test setting and getting a configuration flag': function (done) {
|
||||
var port = ++ports
|
||||
, io = sio.listen(http.createServer());
|
||||
|
||||
io.set('a', 'b');
|
||||
io.get('a').should.eql('b');
|
||||
|
||||
var port = ++ports
|
||||
, io = sio.listen(http.createServer());
|
||||
|
||||
io.configure(function () {
|
||||
io.set('a', 'b');
|
||||
io.enable('tobi');
|
||||
});
|
||||
|
||||
io.get('a').should.eql('b');
|
||||
|
||||
done();
|
||||
},
|
||||
|
||||
@@ -37,11 +52,9 @@ module.exports = {
|
||||
, io = sio.listen(http.createServer());
|
||||
|
||||
io.configure(function () {
|
||||
io.set('a', 'b');
|
||||
io.enable('tobi');
|
||||
});
|
||||
|
||||
io.get('a').should.eql('b');
|
||||
io.enabled('tobi').should.be.true;
|
||||
|
||||
done();
|
||||
@@ -534,6 +547,100 @@ module.exports = {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'test disabling heartbeats': function (done) {
|
||||
var port = ++ports
|
||||
, io = sio.listen(port)
|
||||
, cl = client(port)
|
||||
, messages = 0
|
||||
, beat = false
|
||||
, ws;
|
||||
|
||||
io.configure(function () {
|
||||
io.disable('heartbeats');
|
||||
io.set('heartbeat interval', .05);
|
||||
io.set('heartbeat timeout', .05);
|
||||
io.set('close timeout', .05);
|
||||
});
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
setTimeout(function () {
|
||||
socket.disconnect();
|
||||
}, io.get('heartbeat timeout') * 1000 + 100);
|
||||
|
||||
socket.on('disconnect', function (reason) {
|
||||
beat.should.be.false;
|
||||
|
||||
cl.end();
|
||||
ws.finishClose();
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
cl.get('/socket.io/{protocol}/', function (res, data) {
|
||||
res.statusCode.should.eql(200);
|
||||
data.should.match(/([^:]+)::[\.0-9]+:(.*)/);
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws = websocket(cl, sid);
|
||||
ws.on('message', function (packet) {
|
||||
if (++messages == 1) {
|
||||
packet.type.should.eql('connect');
|
||||
} else if (packet.type == 'heartbeat'){
|
||||
beat = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'no duplicate room members': function (done) {
|
||||
var port = ++ports
|
||||
, io = sio.listen(port);
|
||||
|
||||
Object.keys(io.rooms).length.should.equal(0);
|
||||
|
||||
io.onJoin(123, 'foo');
|
||||
io.rooms.foo.length.should.equal(1);
|
||||
|
||||
io.onJoin(123, 'foo');
|
||||
io.rooms.foo.length.should.equal(1);
|
||||
|
||||
io.onJoin(124, 'foo');
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
|
||||
io.onJoin(124, 'foo');
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
|
||||
io.onJoin(123, 'bar');
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
io.rooms.bar.length.should.equal(1);
|
||||
|
||||
io.onJoin(123, 'bar');
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
io.rooms.bar.length.should.equal(1);
|
||||
|
||||
io.onJoin(124, 'bar');
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
io.rooms.bar.length.should.equal(2);
|
||||
|
||||
io.onJoin(124, 'bar');
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
io.rooms.bar.length.should.equal(2);
|
||||
|
||||
io.server.close();
|
||||
done();
|
||||
},
|
||||
|
||||
'test passing options directly to the Manager through listen': function (done) {
|
||||
var port = ++ports
|
||||
, io = sio.listen(port, { resource: '/my resource', custom: 'opt' });
|
||||
|
||||
io.get('resource').should.equal('/my resource');
|
||||
io.get('custom').should.equal('opt');
|
||||
io.server.close();
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,8 +80,8 @@ module.exports = {
|
||||
fn(null, true);
|
||||
})
|
||||
.on('connection', function (socket) {
|
||||
socket.handshake.address.address.should.equal('127.0.0.1');
|
||||
socket.handshake.address.port.should.equal(ports);
|
||||
(!!socket.handshake.address.address).should.be.true;
|
||||
(!!socket.handshake.address.port).should.be.true;
|
||||
socket.handshake.headers.host.should.equal('localhost');
|
||||
socket.handshake.headers.connection.should.equal('keep-alive');
|
||||
socket.handshake.time.should.match(/GMT/);
|
||||
@@ -139,5 +139,109 @@ module.exports = {
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
'broadcasting sends and emits on a namespace': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, calls = 0
|
||||
, connect = 0
|
||||
, message = 0
|
||||
, events = 0
|
||||
, expected = 5
|
||||
, ws1
|
||||
, ws2;
|
||||
|
||||
io.of('a')
|
||||
.on('connection', function (socket){
|
||||
socket.broadcast.emit('b', 'test');
|
||||
socket.broadcast.json.emit('json', {foo:'bar'});
|
||||
socket.broadcast.send('foo');
|
||||
});
|
||||
|
||||
function finish () {
|
||||
connect.should.equal(2);
|
||||
message.should.equal(1);
|
||||
events.should.equal(2);
|
||||
|
||||
cl.end();
|
||||
ws1.finishClose();
|
||||
ws2.finishClose();
|
||||
io.server.close();
|
||||
done();
|
||||
}
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws1 = websocket(cl, sid);
|
||||
|
||||
ws1.on('open', function() {
|
||||
ws1.packet({
|
||||
type: 'connect'
|
||||
, endpoint: 'a'
|
||||
});
|
||||
});
|
||||
|
||||
ws1.on('message', function (data) {
|
||||
if (data.type === 'connect') {
|
||||
++connect;
|
||||
if (++calls === expected) finish();
|
||||
}
|
||||
|
||||
if (data.type === 'message') {
|
||||
++message;
|
||||
if (++calls === expected) finish();
|
||||
}
|
||||
|
||||
if (data.type === 'event') {
|
||||
if (data.name === 'b' || data.name === 'json') ++events;
|
||||
if (++calls === expected) finish();
|
||||
}
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws2 = websocket(cl, sid);
|
||||
|
||||
ws2.on('open', function () {
|
||||
ws2.packet({
|
||||
type: 'connect'
|
||||
, endpoint: 'a'
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
'joining rooms inside a namespace': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, calls = 0
|
||||
, ws;
|
||||
|
||||
io.of('/foo').on('connection', function (socket) {
|
||||
socket.join('foo.bar');
|
||||
this.in('foo.bar').emit('baz', 'pewpew');
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws = websocket(cl, sid);
|
||||
|
||||
ws.on('open', function (){
|
||||
ws.packet({
|
||||
type: 'connect'
|
||||
, endpoint: '/foo'
|
||||
});
|
||||
});
|
||||
|
||||
ws.on('message', function (data) {
|
||||
if (data.type === 'event') {
|
||||
data.name.should.equal('baz');
|
||||
|
||||
cl.end();
|
||||
ws.finishClose();
|
||||
io.server.close();
|
||||
done();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -233,7 +233,7 @@ module.exports = {
|
||||
store.destroy();
|
||||
done();
|
||||
});
|
||||
}, 1900);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
var sio = require('socket.io')
|
||||
, should = require('./common')
|
||||
, parser = sio.parser
|
||||
, ports = 15400;
|
||||
, ports = 15800;
|
||||
|
||||
/**
|
||||
* Tests.
|
||||
@@ -899,6 +899,59 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test leaving a room': function (done) {
|
||||
var port = ++ports
|
||||
, cl1 = client(port)
|
||||
, cl2 = client(port)
|
||||
, io = create(cl1)
|
||||
, joins = 0
|
||||
, disconnects = 0;
|
||||
|
||||
io.set('close timeout', 0);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.join('foo');
|
||||
io.sockets.clients('foo').should.have.length(++joins);
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
socket.leave('foo');
|
||||
socket.leave('foo');
|
||||
socket.leave('foo');
|
||||
|
||||
io.sockets.clients('foo').should.have.length(--joins);
|
||||
|
||||
if (++disconnects == 2) {
|
||||
io.server.close();
|
||||
cl1.end();
|
||||
cl2.end();
|
||||
done();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
cl1.handshake(function (sid) {
|
||||
var ws1 = websocket(cl1, sid);
|
||||
ws1.on('message', function (msg) {
|
||||
if (!ws1.connected) {
|
||||
msg.type.should.eql('connect');
|
||||
ws1.connected = true;
|
||||
ws1.finishClose();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cl2.handshake(function (sid) {
|
||||
var ws2 = websocket(cl2, sid);
|
||||
ws2.on('message', function (msg) {
|
||||
if (!ws2.connected) {
|
||||
msg.type.should.eql('connect');
|
||||
ws2.connected = true;
|
||||
ws2.finishClose();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'test message with broadcast flag': function (done) {
|
||||
var port = ++ports
|
||||
, cl1 = client(port)
|
||||
@@ -1493,8 +1546,8 @@ module.exports = {
|
||||
, ws;
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.handshake.address.address.should.equal('127.0.0.1');
|
||||
socket.handshake.address.port.should.equal(ports);
|
||||
(!!socket.handshake.address.address).should.be.true;
|
||||
(!!socket.handshake.address.port).should.be.true;
|
||||
socket.handshake.headers.host.should.equal('localhost');
|
||||
socket.handshake.headers.connection.should.equal('keep-alive');
|
||||
socket.handshake.time.should.match(/GMT/);
|
||||
@@ -1584,6 +1637,42 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test accessing handshake data from sockets on disconnect': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, ws;
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('disconnect', function () {
|
||||
|
||||
(!!socket.handshake.address.address).should.be.true;
|
||||
(!!socket.handshake.address.port).should.be.true;
|
||||
socket.handshake.headers.host.should.equal('localhost');
|
||||
socket.handshake.headers.connection.should.equal('keep-alive');
|
||||
socket.handshake.time.should.match(/GMT/);
|
||||
|
||||
setTimeout(function () {
|
||||
ws.finishClose();
|
||||
cl.end();
|
||||
io.server.close();
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
socket.disconnect();
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws = websocket(cl, sid);
|
||||
ws.on('message', function (msg) {
|
||||
if (!ws.connected) {
|
||||
msg.type.should.eql('connect');
|
||||
ws.connected = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'test for intentional and unintentional disconnects': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
@@ -1642,5 +1731,41 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'test socket clean up': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, ws;
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
var self = this
|
||||
, id = socket.id;
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
setTimeout(function () {
|
||||
var available = !!self.sockets[id];
|
||||
|
||||
available.should.be.false;
|
||||
ws.finishClose();
|
||||
cl.end();
|
||||
io.server.close();
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
socket.disconnect();
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws = websocket(cl, sid);
|
||||
ws.on('message', function (msg) {
|
||||
if (!ws.connected) {
|
||||
msg.type.should.eql('connect');
|
||||
ws.connected = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -2635,4 +2635,82 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test emitting to closed clients': function (done) {
|
||||
var cl = client(++ports)
|
||||
, cl2 = client(ports)
|
||||
, io = create(cl)
|
||||
, connections = 0;
|
||||
|
||||
io.configure(function () {
|
||||
io.set('close timeout', .1);
|
||||
});
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.send('a');
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
cl.get('/socket.io/{protocol}/xhr-polling/' + sid, function (res, packs) {
|
||||
res.statusCode.should.equal(200);
|
||||
packs.should.have.length(1);
|
||||
packs[0].should.eql({ type: 'message', endpoint: '', data: 'a' });
|
||||
|
||||
cl2.handshake(function (sid2) {
|
||||
cl2.get(
|
||||
'/socket.io/{protocol}/xhr-polling/' + sid2
|
||||
, function (res, packs) {
|
||||
res.statusCode.should.equal(200);
|
||||
packs.should.have.length(1);
|
||||
packs[0].should.eql({ type: 'message', endpoint: '', data: 'a' });
|
||||
|
||||
io.sockets.emit('woot', 'b');
|
||||
|
||||
var total = 2;
|
||||
|
||||
cl.get(
|
||||
'/socket.io/{protocol}/xhr-polling/' + sid
|
||||
, function (res, packs) {
|
||||
res.statusCode.should.equal(200);
|
||||
packs.should.have.length(1);
|
||||
packs[0].should.eql({
|
||||
type: 'event'
|
||||
, endpoint: ''
|
||||
, name: 'woot'
|
||||
, args: ['b']
|
||||
});
|
||||
|
||||
--total || finish();
|
||||
}
|
||||
);
|
||||
|
||||
cl2.get(
|
||||
'/socket.io/{protocol}/xhr-polling/' + sid2
|
||||
, function (res, packs) {
|
||||
res.statusCode.should.equal(200);
|
||||
packs.should.have.length(1);
|
||||
packs[0].should.eql({
|
||||
type: 'event'
|
||||
, endpoint: ''
|
||||
, name: 'woot'
|
||||
, args: ['b']
|
||||
});
|
||||
|
||||
--total || finish();
|
||||
}
|
||||
);
|
||||
|
||||
function finish () {
|
||||
cl.end();
|
||||
cl2.end();
|
||||
io.server.close();
|
||||
done();
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user