mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 16:08:24 -05:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ed6b79781 | ||
|
|
946418e70e | ||
|
|
2bb60ac40b | ||
|
|
e20777d21d | ||
|
|
311ef7e7e7 | ||
|
|
9e92075cbb | ||
|
|
63043b3d5d | ||
|
|
92a3cce272 | ||
|
|
8339c96e84 | ||
|
|
a125fcb1a4 | ||
|
|
97f634f18f | ||
|
|
82266cf202 | ||
|
|
be94641651 | ||
|
|
703d1d778e | ||
|
|
70c61fa84d | ||
|
|
3a07cc29bd | ||
|
|
89a5134b66 | ||
|
|
6ca42fdc8f | ||
|
|
a9f81a59c2 | ||
|
|
8a90bf5234 | ||
|
|
357a9cb870 | ||
|
|
8253ed573a | ||
|
|
3f55d82bf7 | ||
|
|
08467d4e12 | ||
|
|
cb70f7873f | ||
|
|
57b0ce73c7 | ||
|
|
25f97431d4 | ||
|
|
f931af5758 | ||
|
|
c88ea9ed61 | ||
|
|
2bdee1b28f | ||
|
|
a1f0b6c361 | ||
|
|
c1e64b90a4 | ||
|
|
79c3d84a98 | ||
|
|
f6c376d087 | ||
|
|
bc15077ecc | ||
|
|
28bf55e572 | ||
|
|
f213d69e17 | ||
|
|
aa6f228ccf | ||
|
|
553b9e9d68 | ||
|
|
ec6e43d7ee | ||
|
|
48140cf8a0 | ||
|
|
796bc9e95b |
@@ -1,4 +1,13 @@
|
||||
|
||||
0.8.7 / 2011-11-05
|
||||
==================
|
||||
|
||||
* Fixed memory leaks in closed clients.
|
||||
* Fixed memory leaks in namespaces.
|
||||
* Fixed websocket handling for malformed requests from proxies. [einaros]
|
||||
* Node 0.6 compatibility. [einaros] [3rd-Eden]
|
||||
* Adapted tests and examples.
|
||||
|
||||
0.8.6 / 2011-10-27
|
||||
==================
|
||||
|
||||
|
||||
3
Makefile
3
Makefile
@@ -6,13 +6,12 @@ run-tests:
|
||||
@./node_modules/.bin/expresso \
|
||||
-t 3000 \
|
||||
-I support \
|
||||
-I lib \
|
||||
--serial \
|
||||
$(TESTFLAGS) \
|
||||
$(TESTS)
|
||||
|
||||
test:
|
||||
@$(MAKE) TESTS="$(ALL_TESTS)" run-tests
|
||||
@$(MAKE) NODE_PATH=lib TESTS="$(ALL_TESTS)" run-tests
|
||||
|
||||
test-cov:
|
||||
@TESTFLAGS=--cov $(MAKE) test
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
|
||||
/**
|
||||
* Bootstrap app.
|
||||
*/
|
||||
|
||||
require.paths.unshift(__dirname + '/../../lib/');
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
@@ -12,7 +5,7 @@ require.paths.unshift(__dirname + '/../../lib/');
|
||||
var express = require('express')
|
||||
, stylus = require('stylus')
|
||||
, nib = require('nib')
|
||||
, sio = require('socket.io');
|
||||
, sio = require('../../lib/socket.io');
|
||||
|
||||
/**
|
||||
* App.
|
||||
@@ -25,7 +18,7 @@ var app = express.createServer();
|
||||
*/
|
||||
|
||||
app.configure(function () {
|
||||
app.use(stylus.middleware({ src: __dirname + '/public', compile: compile }))
|
||||
app.use(stylus.middleware({ src: __dirname + '/public', compile: compile }));
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
app.set('views', __dirname);
|
||||
app.set('view engine', 'jade');
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
, "description": "example chat application with socket.io"
|
||||
, "version": "0.0.1"
|
||||
, "dependencies": {
|
||||
"express": "2.3.11"
|
||||
, "jade": "0.12.1"
|
||||
, "stylus": "0.13.3"
|
||||
, "nib": "0.0.8"
|
||||
"express": "2.5.0"
|
||||
, "jade": "0.16.4"
|
||||
, "stylus": "0.19.0"
|
||||
, "nib": "0.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
|
||||
/**
|
||||
* Bootstrap app.
|
||||
*/
|
||||
|
||||
require.paths.unshift(__dirname + '/../../lib/');
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
@@ -12,7 +5,7 @@ require.paths.unshift(__dirname + '/../../lib/');
|
||||
var express = require('express')
|
||||
, stylus = require('stylus')
|
||||
, nib = require('nib')
|
||||
, sio = require('socket.io')
|
||||
, sio = require('../../lib/socket.io')
|
||||
, irc = require('./irc');
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* From https://github.com/felixge/nodelog/
|
||||
*/
|
||||
|
||||
var sys = require('sys');
|
||||
var sys = require('util');
|
||||
var tcp = require('net');
|
||||
var irc = exports;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
"name": "socket.io-irc"
|
||||
, "version": "0.0.1"
|
||||
, "dependencies": {
|
||||
"express": "2.3.11"
|
||||
, "jade": "0.12.1"
|
||||
, "stylus": "0.13.3"
|
||||
, "nib": "0.0.8"
|
||||
"express": "2.5.0"
|
||||
, "jade": "0.16.4"
|
||||
, "stylus": "0.19.0"
|
||||
, "nib": "0.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,11 @@ function Manager (server, options) {
|
||||
|
||||
var self = this;
|
||||
|
||||
// default error handler
|
||||
server.on('error', function(err) {
|
||||
self.log.warn('error raised: ' + err);
|
||||
});
|
||||
|
||||
this.initStore();
|
||||
|
||||
this.on('set:store', function() {
|
||||
@@ -262,7 +267,6 @@ Manager.prototype.initStore = function () {
|
||||
this.connected = {};
|
||||
this.open = {};
|
||||
this.closed = {};
|
||||
this.closedA = [];
|
||||
this.rooms = {};
|
||||
this.roomClients = {};
|
||||
|
||||
@@ -334,8 +338,6 @@ Manager.prototype.onOpen = function (id) {
|
||||
if (this.closed[id]) {
|
||||
var self = this;
|
||||
|
||||
this.closedA.splice(this.closedA.indexOf(id), 1);
|
||||
|
||||
this.store.unsubscribe('dispatch:' + id, function () {
|
||||
delete self.closed[id];
|
||||
});
|
||||
@@ -424,7 +426,6 @@ Manager.prototype.onClose = function (id) {
|
||||
}
|
||||
|
||||
this.closed[id] = [];
|
||||
this.closedA.push(id);
|
||||
|
||||
var self = this;
|
||||
|
||||
@@ -467,9 +468,7 @@ Manager.prototype.onClientMessage = function (id, packet) {
|
||||
|
||||
Manager.prototype.onClientDisconnect = function (id, reason) {
|
||||
for (var name in this.namespaces) {
|
||||
if (this.roomClients[id][name]) {
|
||||
this.namespaces[name].handleDisconnect(id, reason);
|
||||
}
|
||||
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id][name] !== 'undefined');
|
||||
}
|
||||
|
||||
this.onDisconnect(id);
|
||||
@@ -499,7 +498,6 @@ Manager.prototype.onDisconnect = function (id, local) {
|
||||
|
||||
if (this.closed[id]) {
|
||||
delete this.closed[id];
|
||||
this.closedA.splice(this.closedA.indexOf(id), 1);
|
||||
}
|
||||
|
||||
if (this.roomClients[id]) {
|
||||
|
||||
@@ -224,9 +224,9 @@ SocketNamespace.prototype.authorization = function (fn) {
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.handleDisconnect = function (sid, reason) {
|
||||
SocketNamespace.prototype.handleDisconnect = function (sid, reason, raiseOnDisconnect) {
|
||||
if (this.sockets[sid] && this.sockets[sid].readable) {
|
||||
this.sockets[sid].onDisconnect(reason);
|
||||
if (raiseOnDisconnect) this.sockets[sid].onDisconnect(reason);
|
||||
delete this.sockets[sid];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ var client = require('socket.io-client');
|
||||
* Version.
|
||||
*/
|
||||
|
||||
exports.version = '0.8.6';
|
||||
exports.version = '0.8.7';
|
||||
|
||||
/**
|
||||
* Supported protocol version.
|
||||
|
||||
@@ -49,9 +49,9 @@ FlashSocket.prototype.name = 'flashsocket';
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var server;
|
||||
|
||||
FlashSocket.init = function (manager) {
|
||||
var server;
|
||||
function create () {
|
||||
server = require('policyfile').createServer({
|
||||
log: function(msg){
|
||||
@@ -80,10 +80,15 @@ FlashSocket.init = function (manager) {
|
||||
// destory the server and create a new server
|
||||
manager.on('set:flash policy port', function (value, key) {
|
||||
var transports = manager.get('transports');
|
||||
|
||||
if (server && server.port !== value && ~transports.indexOf('flashsocket')) {
|
||||
// destroy the server and rebuild it on a new port
|
||||
server.close();
|
||||
if (~transports.indexOf('flashsocket')) {
|
||||
if (server) {
|
||||
if (server.port === value) return;
|
||||
// destroy the server and rebuild it on a new port
|
||||
try {
|
||||
server.close();
|
||||
}
|
||||
catch (e) { /* ignore exception. could e.g. be that the server isn't started yet */ }
|
||||
}
|
||||
create();
|
||||
}
|
||||
});
|
||||
@@ -94,7 +99,6 @@ FlashSocket.init = function (manager) {
|
||||
create();
|
||||
}
|
||||
});
|
||||
|
||||
// check if we need to initialize at start
|
||||
if (~manager.get('transports').indexOf('flashsocket')){
|
||||
create();
|
||||
|
||||
@@ -91,7 +91,8 @@ WebSocket.prototype.protocolVersion = '07-12';
|
||||
WebSocket.prototype.onSocketConnect = function () {
|
||||
var self = this;
|
||||
|
||||
if (this.req.headers.upgrade.toLowerCase() !== 'websocket') {
|
||||
if (typeof this.req.headers.upgrade === 'undefined' ||
|
||||
this.req.headers.upgrade.toLowerCase() !== 'websocket') {
|
||||
this.log.warn(this.name + ' connection invalid');
|
||||
this.end();
|
||||
return;
|
||||
|
||||
@@ -91,7 +91,8 @@ WebSocket.prototype.protocolVersion = '16';
|
||||
WebSocket.prototype.onSocketConnect = function () {
|
||||
var self = this;
|
||||
|
||||
if (this.req.headers.upgrade.toLowerCase() !== 'websocket') {
|
||||
if (typeof this.req.headers.upgrade === 'undefined' ||
|
||||
this.req.headers.upgrade.toLowerCase() !== 'websocket') {
|
||||
this.log.warn(this.name + ' connection invalid');
|
||||
this.end();
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "socket.io"
|
||||
, "version": "0.8.6"
|
||||
, "version": "0.8.7"
|
||||
, "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"]
|
||||
@@ -16,12 +16,12 @@
|
||||
, "url": "https://github.com/LearnBoost/socket.io.git"
|
||||
}
|
||||
, "dependencies": {
|
||||
"socket.io-client": "0.8.6"
|
||||
"socket.io-client": "0.8.7"
|
||||
, "policyfile": "0.0.4"
|
||||
, "redis": "0.6.7"
|
||||
}
|
||||
, "devDependencies": {
|
||||
"expresso": "0.7.7"
|
||||
"expresso": "0.9.2"
|
||||
, "should": "0.0.4"
|
||||
, "assertvanish": "0.0.3-1"
|
||||
, "benchmark": "0.2.2"
|
||||
|
||||
@@ -5,7 +5,7 @@ var events = require('events');
|
||||
var http = require('http');
|
||||
var net = require('net');
|
||||
var urllib = require('url');
|
||||
var sys = require('sys');
|
||||
var sys = require('util');
|
||||
|
||||
var FRAME_NO = 0;
|
||||
var FRAME_LO = 1;
|
||||
@@ -347,7 +347,6 @@ var WebSocket = function(url, proto, opts) {
|
||||
// that we've closed.
|
||||
var finishClose = self.finishClose = function() {
|
||||
readyState = CLOSED;
|
||||
|
||||
if (stream) {
|
||||
stream.end();
|
||||
stream.destroy();
|
||||
@@ -469,29 +468,45 @@ var WebSocket = function(url, proto, opts) {
|
||||
// that http.Client passes its constructor arguments through,
|
||||
// un-inspected to net.Stream.connect(). The latter accepts a
|
||||
// string as its first argument to connect to a UNIX socket.
|
||||
var httpClient = undefined;
|
||||
var opt = {};
|
||||
var agent = null;
|
||||
switch (getUrlScheme(url)) {
|
||||
case 'ws':
|
||||
var u = urllib.parse(url);
|
||||
httpClient = http.createClient(u.port || 80, u.hostname);
|
||||
httpPath = (u.pathname || '/') + (u.search || '');
|
||||
httpHeaders.Host = u.hostname + (u.port ? (":" + u.port) : "");
|
||||
agent = new http.Agent({
|
||||
host: u.hostname,
|
||||
port: u.port || 80
|
||||
});
|
||||
opt.agent = agent;
|
||||
opt.host = u.hostname;
|
||||
opt.port = u.port || 80;
|
||||
opt.path = (u.pathname || '/') + (u.search || '');
|
||||
opt.headers = httpHeaders;
|
||||
break;
|
||||
|
||||
case 'ws+unix':
|
||||
var sockPath = url.substring('ws+unix://'.length, url.length);
|
||||
httpClient = http.createClient(sockPath);
|
||||
httpHeaders.Host = 'localhost';
|
||||
var u = urllib.parse(url);
|
||||
agent = new http.Agent({
|
||||
host: 'localhost',
|
||||
port: sockPath
|
||||
});
|
||||
opt.agent = agent;
|
||||
opt.host = 'localhost';
|
||||
opt.path = sockPath;
|
||||
opt.headers = httpHeaders;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error('Invalid URL scheme \'' + urlScheme + '\' specified.');
|
||||
}
|
||||
|
||||
httpClient.on('upgrade', (function() {
|
||||
var httpReq = http.request(opt, function() { });
|
||||
var upgradeHandler = (function() {
|
||||
var data = undefined;
|
||||
|
||||
return function(req, s, head) {
|
||||
req.socket.setNoDelay(true);
|
||||
stream = s;
|
||||
|
||||
if (readyState == CLOSED) {
|
||||
@@ -554,7 +569,7 @@ var WebSocket = function(url, proto, opts) {
|
||||
//
|
||||
// XXX: This is lame. We should only remove the listeners
|
||||
// that we added.
|
||||
httpClient.removeAllListeners('upgrade');
|
||||
httpReq.removeAllListeners('upgrade');
|
||||
stream.removeAllListeners('data');
|
||||
stream.on('data', dataListener);
|
||||
|
||||
@@ -582,13 +597,9 @@ var WebSocket = function(url, proto, opts) {
|
||||
|
||||
stream.emit('data', head);
|
||||
};
|
||||
})());
|
||||
httpClient.on('error', function(e) {
|
||||
httpClient.end();
|
||||
errorListener(e);
|
||||
});
|
||||
|
||||
var httpReq = httpClient.request(httpPath, httpHeaders);
|
||||
})();
|
||||
agent.on('upgrade', upgradeHandler); // node v0.4
|
||||
httpReq.on('upgrade', upgradeHandler); // node v0.5+
|
||||
|
||||
httpReq.write(challenge, 'binary');
|
||||
httpReq.end();
|
||||
|
||||
@@ -91,8 +91,21 @@ HTTPClient.prototype.request = function (path, opts, fn) {
|
||||
*/
|
||||
|
||||
HTTPClient.prototype.end = function () {
|
||||
this.agent.sockets.forEach(function (socket) {
|
||||
socket.end();
|
||||
// node <v0.5 compat
|
||||
if (this.agent.sockets.forEach) {
|
||||
this.agent.sockets.forEach(function (socket) {
|
||||
if (socket.end) socket.end();
|
||||
});
|
||||
return;
|
||||
}
|
||||
// node >=v0.5 compat
|
||||
var self = this;
|
||||
Object.keys(this.agent.sockets).forEach(function (socket) {
|
||||
for (var i = 0, l = self.agent.sockets[socket].length; i < l; ++i) {
|
||||
if (self.agent.sockets[socket][i]._handle) {
|
||||
self.agent.sockets[socket][i]._handle.socket.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -55,16 +55,16 @@ mask = function(buf, maskString) {
|
||||
getHybiLengthAsHexString = function(len, masked) {
|
||||
if (len < 126) {
|
||||
var buf = new Buffer(1);
|
||||
buf[0] = (masked ? 0x80 : 0) | len;
|
||||
buf[0] = (masked ? 0x80 : 0) | len;
|
||||
}
|
||||
else if (len < 65536) {
|
||||
var buf = new Buffer(3);
|
||||
buf[0] = (masked ? 0x80 : 0) | 126;
|
||||
buf[0] = (masked ? 0x80 : 0) | 126;
|
||||
getBufferFromHexString(pack(4, len)).copy(buf, 1);
|
||||
}
|
||||
else {
|
||||
var buf = new Buffer(9);
|
||||
buf[0] = (masked ? 0x80 : 0) | 127;
|
||||
buf[0] = (masked ? 0x80 : 0) | 127;
|
||||
getBufferFromHexString(pack(16, len)).copy(buf, 1);
|
||||
}
|
||||
return getHexStringFromBuffer(buf);
|
||||
|
||||
@@ -116,10 +116,10 @@ module.exports = {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
done();
|
||||
} catch (e) {
|
||||
e.should.match(/EACCES/);
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -117,6 +117,7 @@ module.exports = {
|
||||
io.disable('foo');
|
||||
|
||||
calls.should.eql(3);
|
||||
|
||||
done();
|
||||
},
|
||||
|
||||
@@ -426,8 +427,8 @@ module.exports = {
|
||||
|
||||
'test disabling heartbeats': function (done) {
|
||||
var port = ++ports
|
||||
, io = sio.listen(port)
|
||||
, cl = client(port)
|
||||
, io = create(cl)
|
||||
, messages = 0
|
||||
, beat = false
|
||||
, ws;
|
||||
@@ -446,9 +447,8 @@ module.exports = {
|
||||
|
||||
socket.on('disconnect', function (reason) {
|
||||
beat.should.be.false;
|
||||
|
||||
cl.end();
|
||||
ws.finishClose();
|
||||
cl.end();
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
@@ -505,8 +505,10 @@ module.exports = {
|
||||
io.rooms.foo.length.should.equal(2);
|
||||
io.rooms.bar.length.should.equal(2);
|
||||
|
||||
io.server.close();
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
'test passing options directly to the Manager through listen': function (done) {
|
||||
@@ -515,8 +517,10 @@ module.exports = {
|
||||
|
||||
io.get('resource').should.equal('/my resource');
|
||||
io.get('custom').should.equal('opt');
|
||||
io.server.close();
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
'test disabling the log': function (done) {
|
||||
@@ -535,8 +539,10 @@ module.exports = {
|
||||
console.log = _console;
|
||||
calls.should.equal(0);
|
||||
|
||||
io.server.close();
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
'test disabling logging with colors': function (done) {
|
||||
@@ -558,7 +564,9 @@ module.exports = {
|
||||
console.log = _console;
|
||||
calls.should.equal(2);
|
||||
|
||||
io.server.close();
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -131,7 +131,7 @@ module.exports = {
|
||||
if (data.endpoint == '/a') {
|
||||
data.type.should.eql('error');
|
||||
data.reason.should.eql('unauthorized')
|
||||
|
||||
|
||||
cl.end();
|
||||
ws.finishClose();
|
||||
io.server.close()
|
||||
@@ -154,6 +154,9 @@ module.exports = {
|
||||
|
||||
io.of('a')
|
||||
.on('connection', function (socket){
|
||||
if (connect < 2) {
|
||||
return;
|
||||
}
|
||||
socket.broadcast.emit('b', 'test');
|
||||
socket.broadcast.json.emit('json', {foo:'bar'});
|
||||
socket.broadcast.send('foo');
|
||||
@@ -163,7 +166,6 @@ module.exports = {
|
||||
connect.should.equal(2);
|
||||
message.should.equal(1);
|
||||
events.should.equal(2);
|
||||
|
||||
cl.end();
|
||||
ws1.finishClose();
|
||||
ws2.finishClose();
|
||||
@@ -173,16 +175,19 @@ module.exports = {
|
||||
|
||||
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') {
|
||||
if (connect == 0) {
|
||||
cl.handshake(function (sid) {
|
||||
ws2 = websocket(cl, sid);
|
||||
ws2.on('open', function () {
|
||||
ws2.packet({
|
||||
type: 'connect'
|
||||
, endpoint: 'a'
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
++connect;
|
||||
if (++calls === expected) finish();
|
||||
}
|
||||
@@ -197,17 +202,12 @@ module.exports = {
|
||||
if (++calls === expected) finish();
|
||||
}
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
ws2 = websocket(cl, sid);
|
||||
|
||||
ws2.on('open', function () {
|
||||
ws2.packet({
|
||||
type: 'connect'
|
||||
, endpoint: 'a'
|
||||
});
|
||||
ws1.on('open', function() {
|
||||
ws1.packet({
|
||||
type: 'connect'
|
||||
, endpoint: 'a'
|
||||
});
|
||||
})
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
/**
|
||||
* Test dependencies.
|
||||
*/
|
||||
|
||||
var sio = require('socket.io')
|
||||
, should = require('./common');
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
};
|
||||
@@ -30,8 +30,10 @@ module.exports = {
|
||||
(!!io.static.has('/static/flashsocket/WebSocketMain.swf')).should.be.true;
|
||||
(!!io.static.has('/static/flashsocket/WebSocketMainInsecure.swf')).should.be.true;
|
||||
|
||||
io.server.close();
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
'test that static files are correctly looked up': function (done) {
|
||||
@@ -41,8 +43,10 @@ module.exports = {
|
||||
(!!io.static.has('/socket.io.js')).should.be.true;
|
||||
(!!io.static.has('/invalidfilehereplease.js')).should.be.false;
|
||||
|
||||
io.server.close();
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
'test that the client is served': function (done) {
|
||||
|
||||
@@ -250,8 +250,7 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test the disconnection event when the client sends ?disconnect req':
|
||||
function (done) {
|
||||
'test the disconnection event when the client sends ?disconnect req': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, disconnected = false
|
||||
@@ -279,12 +278,17 @@ module.exports = {
|
||||
msgs.should.have.length(1);
|
||||
msgs[0].should.eql({ type: 'disconnect', endpoint: '' });
|
||||
disconnected.should.be.true;
|
||||
cl.end();
|
||||
io.server.close();
|
||||
cl.end();
|
||||
done();
|
||||
});
|
||||
|
||||
cl.get('/socket.io/{protocol}/jsonp-polling/' + sid + '/?disconnect');
|
||||
// with the new http bits in node 0.5, there's no guarantee that
|
||||
// the previous request is actually dispatched (and received) before the following
|
||||
// reset call is sent. to not waste more time on a workaround, a timeout is added.
|
||||
setTimeout(function() {
|
||||
cl.get('/socket.io/{protocol}/jsonp-polling/' + sid + '/?disconnect');
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -236,140 +236,12 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test sending undeliverable volatile messages': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, messages = 0
|
||||
, messaged = false
|
||||
, s;
|
||||
|
||||
io.configure(function () {
|
||||
io.set('close timeout', .05);
|
||||
});
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
s = socket;
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
messaged.should.be.false;
|
||||
cl.end();
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
var ws = websocket(cl, sid);
|
||||
ws.on('message', function (msg) {
|
||||
msg.type.should.eql('connect');
|
||||
ws.finishClose();
|
||||
|
||||
setTimeout(function () {
|
||||
s.volatile.send('ah wha wha');
|
||||
|
||||
ws = websocket(cl, sid);
|
||||
ws.on('message', function () {
|
||||
messaged = true;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
ws.finishClose();
|
||||
}, 10);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'test sending undeliverable volatile json': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, messaged = false
|
||||
, s;
|
||||
|
||||
io.configure(function () {
|
||||
io.set('close timeout', .05);
|
||||
});
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
s = socket;
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
messaged.should.be.false;
|
||||
cl.end();
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
var ws = websocket(cl, sid);
|
||||
ws.on('message', function () {
|
||||
ws.finishClose();
|
||||
|
||||
setTimeout(function () {
|
||||
s.volatile.json.send({ a: 'b' });
|
||||
|
||||
ws = websocket(cl, sid);
|
||||
ws.on('message', function () {
|
||||
messaged = true;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
ws.finishClose();
|
||||
}, 10);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'test sending undeliverable volatile events': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, messaged = false
|
||||
, s;
|
||||
|
||||
io.configure(function () {
|
||||
io.set('close timeout', .05);
|
||||
});
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
s = socket;
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
messaged.should.be.false;
|
||||
cl.end();
|
||||
io.server.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
cl.handshake(function (sid) {
|
||||
var ws = websocket(cl, sid);
|
||||
ws.on('message', function () {
|
||||
ws.finishClose();
|
||||
|
||||
setTimeout(function () {
|
||||
s.volatile.emit({ a: 'b' });
|
||||
|
||||
ws = websocket(cl, sid);
|
||||
ws.on('message', function () {
|
||||
messaged = true;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
ws.finishClose();
|
||||
}, 10);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'test sending deliverable volatile messages': function (done) {
|
||||
var cl = client(++ports)
|
||||
, io = create(cl)
|
||||
, messages = 0
|
||||
, messaged = false;
|
||||
|
||||
|
||||
io.configure(function () {
|
||||
io.set('close timeout', .05);
|
||||
});
|
||||
|
||||
@@ -220,7 +220,12 @@ module.exports = {
|
||||
done();
|
||||
});
|
||||
|
||||
cl.get('/socket.io/{protocol}/xhr-polling/' + sid + '/?disconnect');
|
||||
// with the new http bits in node 0.5, there's no guarantee that
|
||||
// the previous request is actually dispatched (and received) before the following
|
||||
// reset call is sent. to not waste more time on a workaround, a timeout is added.
|
||||
setTimeout(function() {
|
||||
cl.get('/socket.io/{protocol}/xhr-polling/' + sid + '/?disconnect');
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user