Compare commits

...

34 Commits
1.2.0 ... 1.3.1

Author SHA1 Message Date
Guillermo Rauch
3d49cafd03 Release 1.3.1 2015-01-19 11:37:14 +00:00
Guillermo Rauch
77ca2dcbda package: bump engine.io (noop) 2015-01-19 11:11:12 +00:00
Guillermo Rauch
7e4aa4fa64 Release 1.3.0 2015-01-19 10:25:49 +00:00
Guillermo Rauch
b46e480f65 Update Readme.md 2015-01-19 09:26:12 +00:00
Guillermo Rauch
5e92dd8663 package: bump socket.io-client 2015-01-18 19:42:43 +00:00
Guillermo Rauch
f981d3f050 package: bump engine.io 2015-01-18 19:41:45 +00:00
Guillermo Rauch
f57505fee7 Merge branch 'master' of github.com:Automattic/socket.io 2015-01-18 18:53:17 +00:00
Guillermo Rauch
f8f1b132a1 package: bump socket.io-client 2015-01-18 18:52:06 +00:00
Guillermo Rauch
f7f83bc09f package: bump engine.io 2015-01-18 18:51:27 +00:00
Guillermo Rauch
b8ded0d725 Merge pull request #1903 from rase-/add/volatile-tests
Added tests for volatile
2015-01-17 12:23:06 +00:00
Guillermo Rauch
086ccd2708 Merge pull request #1938 from fay-jai/license
update license with up-to-date year range
2015-01-17 12:22:11 +00:00
Guillermo Rauch
864857cb6f Merge pull request #1939 from rase-/add/test-for-emit-after-server-restart
Add test for reconnection after server restarts
2015-01-17 12:21:53 +00:00
Guillermo Rauch
e5a7e422f9 Merge pull request #1943 from eychu/patch-1
Add space in error message
2015-01-17 12:21:38 +00:00
Alexey Chuvashov
f5b75151bd Add space in error message 2015-01-15 01:24:19 +03:00
Tony Kovanen
0523b655da Add test for reconnection after server restarts 2015-01-14 17:22:50 +02:00
Willson Mock
d9415a38e4 update license with up-to-date year range 2015-01-11 00:11:55 -05:00
Roman Shtylman
ca82c09bf2 fix leaving unknown rooms
close #1670
2015-01-10 14:58:50 -08:00
Roman Shtylman
b9aaa1607c Merge pull request #1922 from smart--petea/patch-1
Update Readme.md
2015-01-10 14:48:59 -08:00
Roman Shtylman
d1304c5d82 Merge pull request #1926 from coderaiser/patch-1
package: debug v2.1.0
2015-01-10 14:33:21 -08:00
Guillermo Rauch
bd479a9cd6 Merge pull request #1936 from drewblaisdell/master
Allow null or undefined origins when allowed origins is a function
2015-01-09 16:36:38 -08:00
Drew Blaisdell
a116d7765a Allow null or undefined origins when allowed origins is a function
Requests without an Origin header previously caused an exception to be thrown if the allowed origins passed to the constructor was set to a dynamic function. Omitted origins are now set to an asterisk and passed properly to the origins function.

A test for this case is included in this commit.
2015-01-09 16:30:08 -08:00
Guillermo Rauch
1c6620d564 everything is fixed 2015-01-09 16:25:42 -08:00
Guillermo Rauch
dba462e6da fix tests on 0.11 2015-01-09 16:24:24 -08:00
Guillermo Rauch
19c4422361 package: fix npm test to run on windows 2015-01-09 13:57:45 -08:00
coderaiser
8242dd01ef package: debug v2.1.0 2014-12-26 14:16:27 +02:00
Badarau Petru
17960ed038 Update Readme.md
underylings to underlyings
2014-12-22 07:17:01 +02:00
Tony Kovanen
d9996f0470 Added tests for volatile 2014-12-08 11:19:49 +02:00
Guillermo Rauch
24d06d76dd Release 1.2.1 2014-11-21 04:59:14 +01:00
Guillermo Rauch
4e4bbf918e fix protocol violations and improve error handling (fixes #1880) 2014-11-21 04:16:37 +01:00
Guillermo Rauch
b49f5c82f2 syntax 2014-11-21 04:15:42 +01:00
Guillermo Rauch
5bd67195de Merge branch 'master' of github.com:Automattic/socket.io 2014-11-21 02:57:35 +01:00
Guillermo Rauch
73fe547956 package: bump engine.io for websocket leak fix 2014-11-21 02:56:28 +01:00
Guillermo Rauch
973e6cc982 Merge pull request #1813 from ogwiz2/patch-1
Made comments more consistent
2014-11-12 10:04:09 +01:00
Alex Jeng
136fe960b7 Made comments more consistent 2014-10-05 22:10:13 -07:00
8 changed files with 387 additions and 22 deletions

View File

@@ -1,4 +1,30 @@
1.3.1 / 2015-01-19
==================
* no change on this release
* package: bump `engine.io`
1.3.0 / 2015-01-19
==================
* package: bump `engine.io`
* add test for reconnection after server restarts [rase-]
* update license with up-to-date year range [fay-jai]
* fix leaving unknown rooms [defunctzombie]
* allow null origins when allowed origins is a function [drewblaisdell]
* fix tests on node 0.11
* package: fix `npm test` to run on windows
* package: bump `debug` v2.1.0 [coderaiser]
* added tests for volatile [rase-]
1.2.1 / 2014-11-21
==================
* fix protocol violations and improve error handling (GH-1880)
* package: bump `engine.io` for websocket leak fix [3rd-Eden]
* style tweaks
1.2.0 / 2014-10-27
==================

View File

@@ -1,6 +1,6 @@
(The MIT License)
Copyright (c) 2014 Automattic <dev@cloudup.com>
Copyright (c) 2014-2015 Automattic <dev@cloudup.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -2,8 +2,8 @@
# socket.io
[![Build Status](https://secure.travis-ci.org/Automattic/socket.io.svg)](http://travis-ci.org/Automattic/socket.io)
[![NPM version](https://badge.fury.io/js/socket.io.svg)](http://badge.fury.io/js/socket.io)
![Downloads](http://img.shields.io/npm/dm/socket.io.svg)
![NPM version](https://badge.fury.io/js/socket.io.svg)
![Downloads](http://img.shields.io/npm/dm/socket.io.svg?style=flat)
## How to use
@@ -274,7 +274,7 @@ server.listen(3000);
### Socket#conn:Socket
A reference to the underyling `Client` transport connection (engine.io
A reference to the underlying `Client` transport connection (engine.io
`Socket` object).
### Socket#request:Request

View File

@@ -42,9 +42,12 @@ function Client(server, conn){
Client.prototype.setup = function(){
this.onclose = this.onclose.bind(this);
this.ondata = this.ondata.bind(this);
this.onerror = this.onerror.bind(this);
this.ondecoded = this.ondecoded.bind(this);
this.decoder.on('decoded', this.ondecoded);
this.conn.on('data', this.ondata);
this.conn.on('error', this.onerror);
this.conn.on('close', this.onclose);
};
@@ -167,7 +170,12 @@ Client.prototype.packet = function(packet, preEncoded, volatile){
*/
Client.prototype.ondata = function(data){
this.decoder.add(data);
// try/catch is needed for protocol violations (GH-1880)
try {
this.decoder.add(data);
} catch(e) {
this.onerror(e);
}
};
/**
@@ -189,6 +197,20 @@ Client.prototype.ondecoded = function(packet) {
}
};
/**
* Handles an error.
*
* @param {Objcet} error object
* @api private
*/
Client.prototype.onerror = function(err){
this.sockets.forEach(function(socket){
socket.onerror(err);
});
this.onclose('client error');
};
/**
* Called upon transport close.
*
@@ -219,6 +241,7 @@ Client.prototype.onclose = function(reason){
Client.prototype.destroy = function(){
this.conn.removeListener('data', this.ondata);
this.conn.removeListener('error', this.onerror);
this.conn.removeListener('close', this.onclose);
this.decoder.removeListener('decoded', this.ondecoded);
};

View File

@@ -62,7 +62,7 @@ Server.prototype.checkRequest = function(req, fn) {
var origin = req.headers.origin || req.headers.referer;
// file:// URLs produce a null Origin which can't be authorized via echo-back
if ('null' == origin) origin = '*';
if ('null' == origin || null == origin) origin = '*';
if (!!origin && typeof(this._origins) == 'function') return this._origins(origin, fn);
if (this._origins.indexOf('*:*') !== -1) return fn(null, true);
@@ -194,7 +194,7 @@ Server.prototype.origins = function(v){
Server.prototype.listen =
Server.prototype.attach = function(srv, opts){
if ('function' == typeof srv) {
var msg = 'You are trying to attach socket.io to an express' +
var msg = 'You are trying to attach socket.io to an express ' +
'request handler function. Please pass a http.Server instance.';
throw new Error(msg);
}

View File

@@ -242,7 +242,10 @@ Socket.prototype.leave = function(room, fn){
this.adapter.del(this.id, room, function(err){
if (err) return fn && fn(err);
debug('left room %s', room);
self.rooms.splice(self.rooms.indexOf(room), 1);
var idx = self.rooms.indexOf(room);
if (idx >= 0) {
self.rooms.splice(idx, 1);
}
fn && fn(null);
});
return this;
@@ -380,10 +383,21 @@ Socket.prototype.ondisconnect = function(){
this.onclose('client namespace disconnect');
};
/**
* Handles a client error.
*
* @api private
*/
Socket.prototype.onerror = function(err){
this.emit('error', err);
};
/**
* Called upon closing. Called by `Client`.
*
* @param {String} reason
* @param {Error} optional error object
* @api private
*/

View File

@@ -1,6 +1,6 @@
{
"name": "socket.io",
"version": "1.2.0",
"version": "1.3.1",
"description": "node.js realtime framework server",
"keywords": [
"realtime",
@@ -16,15 +16,15 @@
"url": "git://github.com/Automattic/socket.io"
},
"scripts": {
"test": "make test"
"test": "mocha --reporter dot --slow 200ms --bail"
},
"dependencies": {
"engine.io": "1.4.2",
"engine.io": "1.5.1",
"socket.io-parser": "2.2.2",
"socket.io-client": "1.2.0",
"socket.io-client": "1.3.1",
"socket.io-adapter": "0.3.1",
"has-binary-data": "0.1.3",
"debug": "0.7.4"
"debug": "2.1.0"
},
"devDependencies": {
"mocha": "1.16.2",

View File

@@ -7,7 +7,7 @@ var ioc = require('socket.io-client');
var request = require('supertest');
var expect = require('expect.js');
// creates a socket.io client for the given server
// Creates a socket.io client for the given server
function client(srv, nsp, opts){
if ('object' == typeof nsp) {
opts = nsp;
@@ -15,7 +15,7 @@ function client(srv, nsp, opts){
}
var addr = srv.address();
if (!addr) addr = srv.listen().address();
var url = 'ws://' + addr.address + ':' + addr.port + (nsp || '');
var url = 'ws://localhost:' + addr.port + (nsp || '');
return ioc(url, opts);
}
@@ -127,7 +127,7 @@ describe('socket.io', function(){
expect(s.handshake.time.split(' ').length > 0); // Is "multipart" string representation
// Address, xdomain, secure, issued and url set
expect(s.handshake.address).to.be('127.0.0.1');
expect(s.handshake.address).to.contain('127.0.0.1');
expect(s.handshake.xdomain).to.be.a('boolean');
expect(s.handshake.secure).to.be.a('boolean');
expect(s.handshake.issued).to.be.a('number');
@@ -273,8 +273,9 @@ describe('socket.io', function(){
it('should allow request when origin defined as function and same is supplied', function(done) {
var sockets = io({ origins: function(origin,callback){
if(origin == 'http://foo.example')
if (origin == 'http://foo.example') {
return callback(null, true);
}
return callback(null, false);
} }).listen('54016');
request.get('http://localhost:54016/socket.io/default/')
@@ -288,8 +289,9 @@ describe('socket.io', function(){
it('should allow request when origin defined as function and different is supplied', function(done) {
var sockets = io({ origins: function(origin,callback){
if(origin == 'http://foo.example')
if (origin == 'http://foo.example') {
return callback(null, true);
}
return callback(null, false);
} }).listen('54017');
request.get('http://localhost:54017/socket.io/default/')
@@ -300,6 +302,21 @@ describe('socket.io', function(){
done();
});
});
it('should allow request when origin defined as function and no origin is supplied', function(done) {
var sockets = io({ origins: function(origin,callback){
if (origin == '*') {
return callback(null, true);
}
return callback(null, false);
} }).listen('54021');
request.get('http://localhost:54021/socket.io/default/')
.query({ transport: 'polling' })
.end(function (err, res) {
expect(res.status).to.be(200);
done();
});
});
});
describe('close', function(){
@@ -445,7 +462,7 @@ describe('socket.io', function(){
var c1 = client(srv, '/');
var c2 = client(srv, '/abc');
});
it('should be equivalent for "" and "/" on client', function(done){
var srv = http();
var sio = io(srv);
@@ -454,7 +471,7 @@ describe('socket.io', function(){
});
var c1 = client(srv, '');
});
it('should work with `of` and many sockets', function(done){
var srv = http();
var sio = io(srv);
@@ -637,6 +654,39 @@ describe('socket.io', function(){
});
});
it('should error with null messages', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);
sio.on('connection', function(s){
s.on('message', function(a){
expect(a).to.be(null);
done();
});
socket.send(null);
});
});
});
it('should handle transport null messages', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);
sio.on('connection', function(s){
s.on('error', function(err){
expect(err).to.be.an(Error);
s.on('disconnect', function(reason){
expect(reason).to.be('client error');
done();
});
});
s.client.ondata(null);
});
});
});
it('should emit events', function(done){
var srv = http();
var sio = io(srv);
@@ -765,6 +815,208 @@ describe('socket.io', function(){
});
});
it('should not emit volatile event after regular event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
});
var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});
it('should not emit volatile event after regular event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
});
var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});
it('should emit volatile event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
}, 20);
});
var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});
it('should emit volatile event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
}, 20);
});
var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});
it('should emit only one consecutive volatile event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
s.volatile.emit('ev', 'data');
}, 20);
});
var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});
it('should emit only one consecutive volatile event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
s.volatile.emit('ev', 'data');
}, 20);
});
var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});
it('should emit regular events after trying a failed volatile event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
s.emit('ev', 'data');
}, 20);
});
var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(2);
done();
}, 200);
});
it('should emit regular events after trying a failed volatile event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });
var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
s.emit('ev', 'data');
}, 20);
});
var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});
setTimeout(function() {
expect(counter).to.be(2);
done();
}, 200);
});
it('should emit message events through `send`', function(done){
var srv = http();
var sio = io(srv);
@@ -987,7 +1239,7 @@ describe('socket.io', function(){
var sio = io(srv);
srv.listen(function() {
var addr = srv.listen().address();
var url = 'ws://' + addr.address + ':' + addr.port + '?key1=1&key2=2';
var url = 'ws://localhost:' + addr.port + '?key1=1&key2=2';
var socket = ioc(url);
sio.on('connection', function(s) {
var parsed = require('url').parse(s.request.url);
@@ -1000,7 +1252,7 @@ describe('socket.io', function(){
});
it('should handle very large json', function(done){
this.timeout();
this.timeout(30000);
var srv = http();
var sio = io(srv);
var received = 0;
@@ -1051,6 +1303,32 @@ describe('socket.io', function(){
});
});
});
it('should be able to emit after server close and restart', function(done){
var srv = http();
var sio = io(srv);
sio.on('connection', function(socket){
socket.on('ev', function(data){
expect(data).to.be('payload');
done();
});
});
srv.listen(function(){
var port = srv.address().port;
var clientSocket = client(srv, { reconnectionAttempts: 10, reconnectionDelay: 100 });
clientSocket.once('connect', function(){
srv.close(function(){
srv.listen(port, function(){
clientSocket.on('reconnect', function(){
clientSocket.emit('ev', 'payload');
});
});
});
});
});
});
});
describe('messaging many', function(){
@@ -1350,6 +1628,30 @@ describe('socket.io', function(){
});
});
});
it('should properly cleanup left rooms', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);
sio.on('connection', function(s){
s.join('a', function(){
expect(s.rooms).to.eql([s.id, 'a']);
s.join('b', function(){
expect(s.rooms).to.eql([s.id, 'a', 'b']);
s.leave('unknown', function(){
expect(s.rooms).to.eql([s.id, 'a', 'b']);
s.leaveAll();
expect(s.rooms).to.eql([]);
done();
});
});
});
});
});
});
});
describe('middleware', function(done){