mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 07:58:13 -05:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d49cafd03 | ||
|
|
77ca2dcbda | ||
|
|
7e4aa4fa64 | ||
|
|
b46e480f65 | ||
|
|
5e92dd8663 | ||
|
|
f981d3f050 | ||
|
|
f57505fee7 | ||
|
|
f8f1b132a1 | ||
|
|
f7f83bc09f | ||
|
|
b8ded0d725 | ||
|
|
086ccd2708 | ||
|
|
864857cb6f | ||
|
|
e5a7e422f9 | ||
|
|
f5b75151bd | ||
|
|
0523b655da | ||
|
|
d9415a38e4 | ||
|
|
ca82c09bf2 | ||
|
|
b9aaa1607c | ||
|
|
d1304c5d82 | ||
|
|
bd479a9cd6 | ||
|
|
a116d7765a | ||
|
|
1c6620d564 | ||
|
|
dba462e6da | ||
|
|
19c4422361 | ||
|
|
8242dd01ef | ||
|
|
17960ed038 | ||
|
|
d9996f0470 |
19
History.md
19
History.md
@@ -1,4 +1,23 @@
|
||||
|
||||
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
|
||||
==================
|
||||
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -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
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# socket.io
|
||||
|
||||
[](http://travis-ci.org/Automattic/socket.io)
|
||||
[](http://badge.fury.io/js/socket.io)
|
||||

|
||||

|
||||

|
||||
|
||||
## 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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "socket.io",
|
||||
"version": "1.2.1",
|
||||
"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.3",
|
||||
"engine.io": "1.5.1",
|
||||
"socket.io-parser": "2.2.2",
|
||||
"socket.io-client": "1.2.1",
|
||||
"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",
|
||||
|
||||
@@ -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');
|
||||
@@ -302,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(){
|
||||
@@ -447,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);
|
||||
@@ -456,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);
|
||||
@@ -800,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);
|
||||
@@ -1022,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);
|
||||
@@ -1035,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;
|
||||
@@ -1086,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(){
|
||||
@@ -1385,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){
|
||||
|
||||
Reference in New Issue
Block a user