Compare commits

...

34 Commits
0.7.6 ... 0.7.7

Author SHA1 Message Date
Guillermo Rauch
c3fa1bf5af Release 0.7.7 2011-07-12 05:05:49 -03:00
Guillermo Rauch
8798cfbced Merge pull request #340 from 3rd-Eden/291
It was emitting uknown room, so the messages where never send
2011-07-12 00:55:49 -07:00
Arnout Kazemier
81d71ebb08 Fixed port number 2011-07-12 09:52:53 +02:00
Guillermo Rauch
074e74c6c5 Added test for emitting to closed clients to prevent regression. 2011-07-12 04:35:07 -03:00
Guillermo Rauch
65b8272724 Merge branch 'master' of github.com:LearnBoost/socket.io 2011-07-12 04:29:56 -03:00
Guillermo Rauch
ca3f3379cb Fixed race condition in redis test. 2011-07-12 04:29:30 -03:00
Guillermo Rauch
faad10baee Changed Transport#end instrumentation. 2011-07-12 04:29:11 -03:00
Guillermo Rauch
d3eac92eaa Leveraged $emit instead of emit internally. 2011-07-12 04:28:55 -03:00
Guillermo Rauch
fb5b9bc0b1 Made tests faster. 2011-07-12 03:42:05 -03:00
Guillermo Rauch
34505071f4 Fixed double disconnect events. 2011-07-12 03:41:43 -03:00
Guillermo Rauch
0a2d0b9d0b Fixed disconnect logic 2011-07-12 03:41:15 -03:00
Guillermo Rauch
4495f5987a Simplified remote events handling in Socket. 2011-07-11 23:51:42 -03:00
Guillermo Rauch
aad29d5d92 Fixed double dispatch handling. 2011-07-11 23:51:24 -03:00
Guillermo Rauch
ad8452035d Fixed; increased timeout. 2011-07-11 23:51:08 -03:00
Arnout Kazemier
b2ffed891b Fixed typo 2011-07-11 00:12:27 -07:00
Arnout Kazemier
d39d1401c4 Fixed broken test suite 2011-07-05 00:59:31 +02:00
Arnout Kazemier
159c75096d Removed console statement 2011-07-05 00:38:24 +02:00
Arnout Kazemier
a70347b15f Fixed #285 2011-07-05 00:37:19 +02:00
Arnout Kazemier
1a2c8aa31f It was emitting uknown room, so the messages where never send fixes #291 2011-07-05 00:17:02 +02:00
Guillermo Rauch
7257e1ec36 Merge pull request #329 from 3rd-Eden/remoteAddress
.address() returned server ip >_<, solved with this patch and adjusted th
2011-07-03 05:43:48 -07:00
Arnout Kazemier
af5960bc28 address.remoteAddress -> address.address just like node's 2011-07-02 19:50:18 +02:00
Arnout Kazemier
206cfdf9c6 Merge branch 'master' of github.com:LearnBoost/socket.io into remoteAddress
Conflicts:
	lib/manager.js
2011-07-02 17:52:09 +02:00
Arnout Kazemier
65d7229079 .address() returned server ip >_<, solved with this patch and adjusted the test
suite
2011-07-02 17:49:32 +02:00
Guillermo Rauch
c18aa40ba6 Merge pull request #328 from coolbloke1324/master
Client IP instead of server IP for connectionAddress.
2011-07-02 08:41:33 -07:00
coolbloke1324
249f33da16 Updated Manager.prototype.handshakeData to provide connection.remoteAddress instead of .address() because .address() was returning server IP and .remoteAddress returns client IP. 2011-07-02 08:30:18 -07:00
Guillermo Rauch
b9a7c8be90 Merge pull request #325 from 3rd-Eden/ssl
See https://github.com/joyent/node/issues/1055
2011-07-01 12:41:02 -07:00
Arnout Kazemier
e4ac72a316 Unfucked space 2011-07-01 21:26:43 +02:00
Arnout Kazemier
dff9cbfe1b See https://github.com/joyent/node/issues/1055 2011-07-01 21:24:51 +02:00
Guillermo Rauch
29a8fff576 Removed transports definition in chat example. 2011-06-30 18:59:52 -03:00
Guillermo Rauch
e66a68f0fa Fixed room cleanup 2011-06-30 18:59:35 -03:00
Guillermo Rauch
4058eacbd4 Fixed; make sure the client is cleaned up after booting. 2011-06-30 18:58:55 -03:00
Guillermo Rauch
8cbd1544b9 Make sure to mark the client as non-open if the connection is closed. 2011-06-30 18:58:29 -03:00
Guillermo Rauch
f302744fec Removed unneeded buffer declarations. 2011-06-30 18:58:06 -03:00
Guillermo Rauch
a3ba4e2c10 Fixed; make sure to clear socket handlers and subscriptions upon transport close. 2011-06-30 18:19:41 -03:00
14 changed files with 256 additions and 68 deletions

View File

@@ -1,4 +1,26 @@
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
==================

View File

@@ -4,6 +4,7 @@ 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 \

View File

@@ -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);

View File

@@ -324,18 +324,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]]) continue;
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];
@@ -390,6 +378,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);
@@ -433,6 +425,8 @@ Manager.prototype.onClientMessage = function (id, packet) {
*/
Manager.prototype.onClientDisconnect = function (id, reason) {
this.onDisconnect(id);
for (var name in this.namespaces) {
if (this.roomClients[id][name]) {
this.namespaces[name].handleDisconnect(id, reason);
@@ -469,7 +463,7 @@ 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.rooms[room].splice(this.rooms[room].indexOf(id), 1);
}
}
@@ -811,10 +805,21 @@ 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;
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

View File

@@ -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 [];
@@ -109,7 +109,7 @@ SocketNamespace.prototype.__defineGetter__('volatile', function () {
*/
SocketNamespace.prototype.in = function (room) {
this.flags.endpoint = (this.name === '' ? '' : (this.name + '/')) + 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);
}
@@ -287,7 +287,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 +333,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 +343,6 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
if (dataAck)
params.push(ack);
socket.emit.apply(socket, params);
socket.$emit.apply(socket, params);
};
};

View File

@@ -15,7 +15,7 @@ var client = require('socket.io-client');
* Version.
*/
exports.version = '0.7.6';
exports.version = '0.7.7';
/**
* Supported protocol version.

View File

@@ -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.
*
@@ -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);
}

View File

@@ -28,7 +28,6 @@ function Transport (mng, data, req) {
this.id = data.id;
this.disconnected = false;
this.drained = true;
this.buffer = [];
this.handleRequest(req);
};
@@ -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') {
@@ -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;
};

View File

@@ -1,7 +1,7 @@
{
"name": "socket.io"
, "version": "0.7.6"
, "description": "Realtime apps made cross-browser & easy with a WebSocket-like API"
, "version": "0.7.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"]
, "author": "Guillermo Rauch <guillermo@learnboost.com>"
@@ -15,7 +15,7 @@
, "url": "https://github.com/LearnBoost/Socket.IO-node.git"
}
, "dependencies": {
"socket.io-client": "0.7.3"
"socket.io-client": "0.7.4"
, "policyfile": "0.0.3"
, "redis": "0.6.0"
}

View File

@@ -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;
};
/**

View File

@@ -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();
}
});
})
}
};

View File

@@ -233,7 +233,7 @@ module.exports = {
store.destroy();
done();
});
}, 1900);
}, 2000);
});
}

View File

@@ -12,7 +12,7 @@
var sio = require('socket.io')
, should = require('./common')
, parser = sio.parser
, ports = 15400;
, ports = 15800;
/**
* Tests.
@@ -1493,8 +1493,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/);

View File

@@ -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();
};
}
);
});
});
});
}
};