Compare commits

...

83 Commits

Author SHA1 Message Date
Guillermo Rauch
de9e8dffe1 Release 0.9.10 2012-08-10 13:34:50 -07:00
Guillermo Rauch
3a3044ebba Merge pull request #972 from Coreh/express-3.x-readme
Add express 3.0 instructions on Readme.md
2012-08-10 10:17:55 -07:00
Guillermo Rauch
d10b4dd1bd Merge pull request #985 from GICodeWarrior/log-case-fix
Don't lowercase log messages
2012-08-08 18:03:57 -07:00
Rusty Burchfield
12beee2d63 Don't lowercase log messages
Lowercasing log messages is unnecessary.  It makes some messages difficult to
read, and others difficult to search for.
2012-08-08 11:32:57 -07:00
Guillermo Rauch
875f14d16b Revert "Fix infinite recursion in Websocket parsers."
This reverts commit c218468f67.
2012-08-07 13:18:41 -07:00
Guillermo Rauch
8ca8990a0c Merge pull request #983 from GICodeWarrior/parser-recursion
Fix infinite recursion in Websocket parsers.
2012-08-06 13:16:37 -07:00
Rusty Burchfield
c218468f67 Fix infinite recursion in Websocket parsers.
If a client is feeding messages faster than server can handle them, infinite
recursion occurs.  Basically, the "overflow" data gets added to the parser and
it immediately parses a new message.

The fix pushes the processing of the next message (in this edge case) onto the
event queue.  This prevents the stack from recursing indefinitely.  This also
prevents a fast client from starving other clients.
2012-08-06 13:03:51 -07:00
Guillermo Rauch
4164e3bd7e Merge pull request #981 from doozr/honour-flash-settings
Honour flash settings
2012-08-06 08:59:17 -07:00
Guillermo Rauch
46227e7ac9 Merge pull request #980 from doozr/jsonp-error-crash
Always set the HTTP response in case an error should be returned to the client
2012-08-06 08:58:57 -07:00
Craig Andrews
d723d363b2 Always set the HTTP response in case an error should be returned to the client 2012-08-06 14:16:06 +01:00
Craig Andrews
fa1c1b2ada Create or destroy the flash policy server on configuration change 2012-08-06 14:14:15 +01:00
Craig Andrews
d32a848c3f Honour configuration to disable flash policy server 2012-08-06 14:14:14 +01:00
Guillermo Rauch
48ad0d3d1d Release 0.9.9 2012-08-01 15:14:02 -07:00
Guillermo Rauch
281a467960 manager: added response to sync disconnect xhrs 2012-08-01 15:08:06 -07:00
Guillermo Rauch
1fa74a46a3 Revert "Fix disconnectSync getting ignored"
This reverts commit f48b40e134.
2012-08-01 11:58:28 -07:00
Guillermo Rauch
ca4e3f32a3 Merge pull request #975 from huancz/master
fix issue #961 - restore compatibility with earlier node releases (up to 0.4.x)
2012-07-31 08:34:22 -07:00
Guillermo Rauch
9dd8134e6a Merge pull request #970 from renier/master
Codebase needs a license file (#965)
2012-07-31 08:32:07 -07:00
Renier Morales
180f1c91b9 Put license text in its own file (#965) 2012-07-31 11:07:21 -04:00
Marco Aurélio
bddf652c25 Add express 3.0 instructions on Readme.md 2012-07-30 15:53:47 -03:00
Guillermo Rauch
c795e4cf1a Merge pull request #971 from Coreh/express-3.x-warn
Add warning to .listen() to ease the migration to Express 3.x
2012-07-30 11:49:53 -07:00
Marco Aurélio
6afbb34581 Add warning to .listen() to ease the migration to Express 3.x 2012-07-30 15:43:00 -03:00
Guillermo Rauch
ac39dbc721 Merge pull request #964 from crickeys/xhr_polling_disconnectSync
Fix disconnectSync getting ignored
2012-07-27 10:06:03 -07:00
Petr Běhan
a5c5c20438 restore compatibility with node 0.4.x 2012-07-27 15:38:57 +02:00
Brian Gruber
f48b40e134 Fix disconnectSync getting ignored
If using xhr-polling and a browser closes a tab or window, the
disconnectSync in the socket.io-client method is called which sends an
XHR request to the server indicating a disconnect. This line would cause
that to be ignored and so the server would have to wait for a timeout to
mark them as disconnect. This was possibly because it was sent from a
different tcp socket than the current connection.
2012-07-26 21:19:00 -05:00
Guillermo Rauch
1679fd564c Release 0.9.8 2012-07-24 17:36:30 -07:00
Guillermo Rauch
bb900d445a Release 0.9.7 2012-07-24 11:16:20 -07:00
Guillermo Rauch
c6fed55f53 tests: fixed tests for 0.8 2012-07-24 10:39:23 -07:00
Guillermo Rauch
6adebc85fc Merge pull request #958 from xaroth8088/master
Prevent crash when socket leaves a room twice.
2012-07-22 11:26:21 -07:00
xaroth8088
7a087bcc94 Prevent crash when socket leaves a room twice. 2012-07-22 11:09:06 -07:00
Guillermo Rauch
18422183c8 Merge pull request #957 from xaroth8088/master
Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc.
2012-07-21 11:44:28 -07:00
xaroth8088
aeb904f58b Corrects unsafe usage of for..in, permitting socket.io to be used in environments where Object, Function, etc. have been extended.
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
2012-07-21 11:30:15 -07:00
xaroth8088
9c0b9de7f0 Revert "Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc."
This reverts commit 81552c11ca.
2012-07-21 11:21:11 -07:00
xaroth8088
81552c11ca Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc.
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
2012-07-21 10:29:20 -07:00
Guillermo Rauch
e1fe76aebe Fix for node 0.8 with gzip compression. Thanks @vadimi 2012-07-09 16:58:02 -07:00
Guillermo Rauch
8197a0c854 Merge pull request #929 from sjonnet19/patch-1
Update redis to support Node 0.8.x
2012-06-26 06:29:08 -07:00
Shawn Jonnet
2b91f1407f Update redis to support Node 0.8.x 2012-06-25 23:30:24 -03:00
Guillermo Rauch
3b9715e8e7 Merge pull request #869 from MrSwitch/master
Small change to demo copy
2012-05-03 06:24:15 -07:00
Andrew Dodson
4e13cfb03e Update copy 2012-05-03 12:16:01 +10:00
Guillermo Rauch
39671e81a5 Merge pull request #868 from bodash/patch-1
I continued to have websocket connection issues in Safari when using SSL...
2012-05-02 12:21:24 -07:00
bodash
ffa8994a23 I continued to have websocket connection issues in Safari when using SSL that terminated at a load balancer. The shorthand logic that was here was nice and compact but didn't seem to work. Took the "intent" of the short hand and made it a bit more verbose and now it works. 2012-05-02 13:18:46 -06:00
Guillermo Rauch
de1afe1317 Merge pull request #857 from martinthomson/bug/856
Fix for ID generation vulnerability #856
2012-04-26 15:49:24 -07:00
Martin Thomson
aaad106b90 Adding node 0.4 backward compat for id gen 2012-04-26 15:08:19 -07:00
Martin Thomson
f850ddccd0 Removing more fixes for other bug 2012-04-26 14:35:17 -07:00
Martin Thomson
8d269aae4c Removing fixes for other bug 2012-04-26 14:33:37 -07:00
Martin Thomson
67b4eb9abd Making ID generation securely random 2012-04-26 14:28:00 -07:00
Guillermo Rauch
fe6dd87443 Merge pull request #848 from mbrevoort/redisStoreRaceCondition
Fix Redis Store race condition in manager onOpen unsubscribe callback
2012-04-23 15:30:30 -07:00
Mike Brevoort
d9aeaa494f Fix Redis Store race condition in manager onOpen unsubscribe callback 2012-04-23 16:06:31 -06:00
Guillermo Rauch
2024d45383 Merge pull request #841 from TooTallNate/master
fix for EventEmitters always reusing the same Array instance for listeners
2012-04-19 13:30:13 -07:00
Nathan Rajlich
e1884859bc fix for EventEmitters always reusing the same Array instance for listeners
This fixes node v0.7.x.

The node commits that broke this old behavior is here:
  78dc13fbf9%5E...928ea564d16da47e615ddac627e0b4d4a40d8196
2012-04-19 13:18:22 -07:00
Guillermo Rauch
0242a2ddf3 Merge branch 'master' of github.com:LearnBoost/socket.io 2012-04-17 19:51:49 -03:00
Guillermo Rauch
dbe6d5f740 Release 0.9.6 2012-04-17 19:51:37 -03:00
Guillermo Rauch
e98fc7bc86 Fixed XSS in jsonp-polling. 2012-04-17 19:48:32 -03:00
Guillermo Rauch
9bbf17f31e Merge pull request #827 from crickeys/patch-4
Fixes when browser doesn't send origin header, defaults to empty string ...
2012-04-11 15:02:50 -07:00
crickeys
1a5a87af13 Fixes when browser doesn't send origin header, defaults to empty string instead of UNDEFINED (which would throw an error on the origin.match(/^https/) below 2012-04-11 14:41:07 -05:00
Guillermo Rauch
a4e53a642b Release 0.9.5 2012-04-05 14:37:18 -03:00
Guillermo Rauch
6f36d8c2ff Added test for polling with connection close. 2012-04-05 14:32:10 -03:00
Guillermo Rauch
09fb16b443 Ensure close upon request close. 2012-04-05 14:31:50 -03:00
Guillermo Rauch
330407cc9d Fix disconnection reason being lost for polling transports. 2012-04-05 14:31:32 -03:00
Guillermo Rauch
2075307f23 Ensure that polling transports work with Connection: close 2012-04-05 14:31:13 -03:00
Guillermo Rauch
d7b06edaca Log disconnection reason 2012-04-05 14:31:01 -03:00
Guillermo Rauch
46fdcf00b3 Release 0.9.4 2012-04-01 01:50:50 -03:00
Guillermo Rauch
147b9bb941 Release 0.9.4 2012-04-01 01:49:51 -03:00
Guillermo Rauch
02a3da487c Merge branch 'master' of github.com:LearnBoost/socket.io 2012-04-01 01:48:25 -03:00
Guillermo Rauch
087c686ad0 Release 0.9.4 2012-04-01 01:48:13 -03:00
Guillermo Rauch
16205fc522 Merge pull request #809 from DanielBaulig/issue795-fix
Issue795 fix
2012-03-28 12:58:45 -07:00
Guillermo Rauch
a232159ce8 Release 0.9.3 2012-03-28 09:28:05 -03:00
Guillermo Rauch
b9c3255b7c Merge pull request #806 from mixu/upstream/fix-ff-xhr-post-syntax
Fix "syntax error" message on FF, resulting from FF trying to parse the POST result as XML due to it not having a response content-type
2012-03-27 16:54:29 -07:00
Mikito Takada
d80010dcf0 Firefox will try to parse the response from POST requests, causing a syntax error message in the Web Console. Basically an addition to https://github.com/LearnBoost/socket.io/pull/501 2012-03-27 16:43:17 -07:00
Daniel Baulig
00694a8a98 Fix issue #795 2012-03-19 22:03:31 +01:00
Daniel Baulig
da95094998 Add disconnect from namespace test-case for issue #795 2012-03-19 21:54:20 +01:00
Guillermo Rauch
e7d7582f84 Release 0.9.2 2012-03-13 11:00:50 -03:00
Guillermo Rauch
df5f23d309 More sensible close timeout default (fixes disconnect issue) 2012-03-13 10:49:06 -03:00
Guillermo Rauch
e018ba91eb Merge branch 'master' of github.com:LearnBoost/socket.io 2012-03-09 08:47:01 -03:00
Guillermo Rauch
c59aa6ff2c Getting ready for 1.0 2012-03-09 08:42:24 -03:00
Guillermo Rauch
9431709298 Merge pull request #787 from MatthewMueller/master
io.configure('development', function() {...}) will trigger if NODE_ENV is not defined.
2012-03-09 02:17:15 -08:00
Matt Mueller
a29525e043 NODE_ENV in configure now defaults to development, which is consistent with express 2012-03-09 02:10:58 -08:00
Guillermo Rauch
5312e154b3 Release 0.9.1-1 2012-03-02 08:41:17 -03:00
Guillermo Rauch
480b86f382 Bumped client with NPM dependency fix. 2012-03-02 08:40:41 -03:00
Guillermo Rauch
c0e2c3012f Release 0.9.1 2012-03-02 08:20:38 -03:00
Guillermo Rauch
97b04c4152 Merge branch 'master' of github.com:LearnBoost/socket.io 2012-03-02 07:50:59 -03:00
Guillermo Rauch
c8306e207d Temporarily removing node 0.4 from travis-ci 2012-02-29 11:01:11 -03:00
Guillermo Rauch
de5c0b3554 Merge pull request #771 from felixge/heartbeat
Make heartbeat timeout > heartbeat interval
2012-02-29 05:43:24 -08:00
Felix Geisendörfer
57a0b24060 Make heartbeat timeout > heartbeat interval
Otherwise clients would detect timeouts before a heartbeat has a chance
of reaching them. The new values themselves were suggested by @rauchg. I
myself think that the heartbeat timeout should probably only be ~10s larger
than the interval.
2012-02-29 14:15:37 +01:00
24 changed files with 369 additions and 70 deletions

View File

@@ -1,6 +1,5 @@
language: node_js
node_js:
- 0.4
- 0.6
notifications:

View File

@@ -1,4 +1,80 @@
0.9.10 / 2012-08-10
===================
* Don't lowercase log messages
* Always set the HTTP response in case an error should be returned to the client
* Create or destroy the flash policy server on configuration change
* Honour configuration to disable flash policy server
* Add express 3.0 instructions on Readme.md
* Bump client
0.9.9 / 2012-08-01
==================
* Fixed sync disconnect xhrs handling
* Put license text in its own file (#965)
* Add warning to .listen() to ease the migration to Express 3.x
* Restored compatibility with node 0.4.x
0.9.8 / 2012-07-24
==================
* Bumped client.
0.9.7 / 2012-07-24
==================
* Prevent crash when socket leaves a room twice.
* Corrects unsafe usage of for..in
* Fix for node 0.8 with `gzip compression` [vadimi]
* Update redis to support Node 0.8.x
* Made ID generation securely random
* Fix Redis Store race condition in manager onOpen unsubscribe callback
* Fix for EventEmitters always reusing the same Array instance for listeners
0.9.6 / 2012-04-17
==================
* Fixed XSS in jsonp-polling.
0.9.5 / 2012-04-05
==================
* Added test for polling and socket close.
* Ensure close upon request close.
* Fix disconnection reason being lost for polling transports.
* Ensure that polling transports work with Connection: close.
* Log disconnection reason.
0.9.4 / 2012-04-01
==================
* Disconnecting from namespace improvement (#795) [DanielBaulig]
* Bumped client with polling reconnection loop (#438)
0.9.3 / 2012-03-28
==================
* Fix "Syntax error" on FF Web Console with XHR Polling [mikito]
0.9.2 / 2012-03-13
==================
* More sensible close `timeout default` (fixes disconnect issue)
0.9.1-1 / 2012-03-02
====================
* Bumped client with NPM dependency fix.
0.9.1 / 2012-03-02
==================
* Changed heartbeat timeout and interval defaults (60 and 25 seconds)
* Make tests work both on 0.4 and 0.6
* Updated client (improvements + bug fixes).
0.9.0 / 2012-02-26
==================

22
LICENSE Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -6,7 +6,9 @@ horizontal scalability, automatic JSON encoding/decoding, and more.
## How to Install
npm install socket.io
```bash
npm install socket.io
```
## How to use
@@ -19,6 +21,25 @@ var io = require('socket.io');
Next, attach it to a HTTP/HTTPS server. If you're using the fantastic `express`
web framework:
#### Express 3.x
```js
var app = express()
, server = require('http').createServer(app)
, io = io.listen(server);
server.listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
```
#### Express 2.x
```js
var app = express.createServer()
, io = io.listen(app);
@@ -102,10 +123,10 @@ io.sockets.on('connection', function (socket) {
var socket = io.connect('http://localhost');
socket.on('connect', function () {
socket.emit('set nickname', confirm('What is your nickname?'));
socket.emit('set nickname', prompt('What is your nickname?'));
socket.on('ready', function () {
console.log('Connected !');
socket.emit('msg', confirm('What is your message?'));
socket.emit('msg', prompt('What is your message?'));
});
});
</script>

View File

@@ -11,6 +11,7 @@
var fs = require('fs')
, url = require('url')
, tty = require('tty')
, crypto = require('crypto')
, util = require('./util')
, store = require('./store')
, client = require('socket.io-client')
@@ -44,7 +45,8 @@ var defaultTransports = exports.defaultTransports = [
*/
var parent = module.parent.exports
, protocol = parent.protocol;
, protocol = parent.protocol
, jsonpolling_re = /^\d+$/;
/**
* Manager constructor.
@@ -71,9 +73,9 @@ function Manager (server, options) {
, blacklist: ['disconnect']
, 'log level': 3
, 'log colors': tty.isatty(process.stdout.fd)
, 'close timeout': 25
, 'heartbeat timeout': 15
, 'heartbeat interval': 20
, 'close timeout': 60
, 'heartbeat interval': 25
, 'heartbeat timeout': 60
, 'polling duration': 20
, 'flash policy server': true
, 'flash policy port': 10843
@@ -91,7 +93,9 @@ function Manager (server, options) {
};
for (var i in options) {
this.settings[i] = options[i];
if (options.hasOwnProperty(i)) {
this.settings[i] = options[i];
}
}
var self = this;
@@ -108,8 +112,7 @@ function Manager (server, options) {
});
// reset listeners
this.oldListeners = server.listeners('request');
server.removeAllListeners('request');
this.oldListeners = server.listeners('request').splice(0);
server.on('request', function (req, res) {
self.handleRequest(req, res);
@@ -128,11 +131,21 @@ function Manager (server, options) {
});
for (var i in transports) {
if (transports[i].init) {
transports[i].init(this);
if (transports.hasOwnProperty(i)) {
if (transports[i].init) {
transports[i].init(this);
}
}
}
// forward-compatibility with 1.0
var self = this;
this.sockets.on('connection', function (conn) {
self.emit('connection', conn);
});
this.sequenceNumber = Date.now() | 0;
this.log.info('socket.io started');
};
@@ -252,7 +265,7 @@ Manager.prototype.disabled = function (key) {
Manager.prototype.configure = function (env, fn) {
if ('function' == typeof env) {
env.call(this);
} else if (env == process.env.NODE_ENV) {
} else if (env == (process.env.NODE_ENV || 'development')) {
fn.call(this);
}
@@ -337,12 +350,21 @@ Manager.prototype.onConnect = function (id) {
Manager.prototype.onOpen = function (id) {
this.open[id] = true;
// if we were buffering messages for the client, clear them
if (this.closed[id]) {
var self = this;
this.store.unsubscribe('dispatch:' + id, function () {
delete self.closed[id];
var transport = self.transports[id];
if (self.closed[id] && self.closed[id].length && transport) {
// if we have buffered messages that accumulate between calling
// onOpen an this async callback, send them if the transport is
// still open, otherwise leave them buffered
if (transport.open) {
transport.payload(self.closed[id]);
self.closed[id] = [];
}
}
});
}
@@ -413,7 +435,10 @@ Manager.prototype.onLeave = function (id, room) {
if (!this.rooms[room].length) {
delete this.rooms[room];
}
delete this.roomClients[id][room];
if (this.roomClients[id]) {
delete this.roomClients[id][room];
}
}
};
@@ -471,8 +496,10 @@ Manager.prototype.onClientMessage = function (id, packet) {
Manager.prototype.onClientDisconnect = function (id, reason) {
for (var name in this.namespaces) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id] !== 'undefined' &&
typeof this.roomClients[id][name] !== 'undefined');
if (this.namespaces.hasOwnProperty(name)) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id] !== 'undefined' &&
typeof this.roomClients[id][name] !== 'undefined');
}
}
this.onDisconnect(id);
@@ -506,7 +533,9 @@ Manager.prototype.onDisconnect = function (id, local) {
if (this.roomClients[id]) {
for (var room in this.roomClients[id]) {
this.onLeave(id, room);
if (this.roomClients[id].hasOwnProperty(room)) {
this.onLeave(id, room);
}
}
delete this.roomClients[id]
}
@@ -610,12 +639,15 @@ Manager.prototype.handleClient = function (data, req) {
, store = this.store
, self = this;
// handle sync disconnect xhrs
if (undefined != data.query.disconnect) {
if (this.transports[data.id] && this.transports[data.id].open) {
this.transports[data.id].onForcedDisconnect();
} else {
this.store.publish('disconnect-force:' + data.id);
}
req.res.writeHead(200);
req.res.end();
return;
}
@@ -656,11 +688,13 @@ Manager.prototype.handleClient = function (data, req) {
// initialize the socket for all namespaces
for (var i in this.namespaces) {
var socket = this.namespaces[i].socket(data.id, true);
if (this.namespaces.hasOwnProperty(i)) {
var socket = this.namespaces[i].socket(data.id, true);
// echo back connect packet and fire connection event
if (i === '') {
this.namespaces[i].handlePacket(data.id, { type: 'connect' });
// echo back connect packet and fire connection event
if (i === '') {
this.namespaces[i].handlePacket(data.id, { type: 'connect' });
}
}
}
@@ -688,8 +722,22 @@ Manager.prototype.handleClient = function (data, req) {
*/
Manager.prototype.generateId = function () {
return Math.abs(Math.random() * Math.random() * Date.now() | 0).toString()
+ Math.abs(Math.random() * Math.random() * Date.now() | 0).toString();
var rand = new Buffer(15); // multiple of 3 for base64
if (!rand.writeInt32BE) {
return Math.abs(Math.random() * Math.random() * Date.now() | 0).toString()
+ Math.abs(Math.random() * Math.random() * Date.now() | 0).toString();
}
this.sequenceNumber = (this.sequenceNumber + 1) | 0;
rand.writeInt32BE(this.sequenceNumber, 11);
if (crypto.randomBytes) {
crypto.randomBytes(12).copy(rand);
} else {
// not secure for node 0.4
[0, 4, 8].forEach(function(i) {
rand.writeInt32BE(Math.random() * Math.pow(2, 32) | 0, i);
});
}
return rand.toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
};
/**
@@ -706,7 +754,7 @@ Manager.prototype.handleHandshake = function (data, req, res) {
};
function writeErr (status, message) {
if (data.query.jsonp) {
if (data.query.jsonp && jsonpolling_re.test(data.query.jsonp)) {
res.writeHead(200, { 'Content-Type': 'application/javascript' });
res.end('io.j[' + data.query.jsonp + '](new Error("' + message + '"));');
} else {
@@ -745,7 +793,7 @@ Manager.prototype.handleHandshake = function (data, req, res) {
, self.transports(data).join(',')
].join(':');
if (data.query.jsonp) {
if (data.query.jsonp && jsonpolling_re.test(data.query.jsonp)) {
hs = 'io.j[' + data.query.jsonp + '](' + JSON.stringify(hs) + ');';
res.writeHead(200, { 'Content-Type': 'application/javascript' });
} else {

View File

@@ -15,7 +15,7 @@ var client = require('socket.io-client');
* Version.
*/
exports.version = '0.9.0';
exports.version = '0.9.10';
/**
* Supported protocol version.
@@ -39,6 +39,13 @@ exports.clientVersion = client.version;
*/
exports.listen = function (server, options, fn) {
if ('function' == typeof server) {
console.warn('Socket.IO\'s `listen()` method expects an `http.Server` instance\n'
+ 'as its first parameter. Are you migrating from Express 2.x to 3.x?\n'
+ 'If so, check out the "Socket.IO compatibility" section at:\n'
+ 'https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x');
}
if ('function' == typeof options) {
fn = options;
options = {};

View File

@@ -291,12 +291,19 @@ Socket.prototype.disconnect = function () {
if (!this.disconnected) {
this.log.info('booting client');
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
this.manager.transports[this.id].onForcedDisconnect();
if ('' === this.namespace.name) {
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
this.manager.transports[this.id].onForcedDisconnect();
} else {
this.manager.onClientDisconnect(this.id);
this.manager.store.publish('disconnect:' + this.id);
}
} else {
this.manager.onClientDisconnect(this.id);
this.manager.store.publish('disconnect:' + this.id);
this.packet({type: 'disconnect'});
this.manager.onLeave(this.id, this.namespace.name);
this.$emit('disconnect', 'booted');
}
}
return this;

View File

@@ -178,7 +178,7 @@ Static.prototype.gzip = function (data, callback) {
buffer.length = 0;
});
gzip.on('exit', function () {
gzip.on('close', function () {
if (err) return callback(err);
var size = 0

View File

@@ -455,7 +455,7 @@ Transport.prototype.onClose = function () {
Transport.prototype.end = function (reason) {
if (!this.disconnected) {
this.log.info('transport end');
this.log.info('transport end (' + reason + ')');
var local = this.manager.transports[this.id];

View File

@@ -1,4 +1,3 @@
/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
@@ -53,9 +52,16 @@ FlashSocket.prototype.name = 'flashsocket';
FlashSocket.init = function (manager) {
var server;
function create () {
// Drop out immediately if the user has
// disabled the flash policy server
if (!manager.get('flash policy server')) {
return;
}
server = require('policyfile').createServer({
log: function(msg){
manager.log.info(msg.toLowerCase());
manager.log.info(msg);
}
}, manager.get('origins'));
@@ -93,6 +99,23 @@ FlashSocket.init = function (manager) {
}
});
// create or destroy the server
manager.on('set:flash policy server', function (value, key) {
var transports = manager.get('transports');
if (~transports.indexOf('flashsocket')) {
if (server && !value) {
// destroy the server
try {
server.close();
}
catch (e) { /* ignore exception. could e.g. be that the server isn't started yet */ }
}
} else if (!server && value) {
// create the server
create();
}
});
// only start the server
manager.on('set:transports', function (value, key){
if (!server && ~manager.get('transports').indexOf('flashsocket')) {

View File

@@ -43,6 +43,18 @@ HTTPPolling.prototype.__proto__ = HTTPTransport.prototype;
HTTPPolling.prototype.name = 'httppolling';
/**
* Override setHandlers
*
* @api private
*/
HTTPPolling.prototype.setHandlers = function () {
HTTPTransport.prototype.setHandlers.call(this);
this.socket.removeListener('end', this.bound.end);
this.socket.removeListener('close', this.bound.close);
};
/**
* Removes heartbeat timeouts for polling.
*/
@@ -128,8 +140,8 @@ HTTPPolling.prototype.write = function (data, close) {
* @api private
*/
HTTPPolling.prototype.end = function () {
HTTPPolling.prototype.end = function (reason) {
this.clearPollTimeout();
return HTTPTransport.prototype.end.call(this);
return HTTPTransport.prototype.end.call(this, reason);
};

View File

@@ -42,11 +42,15 @@ HTTPTransport.prototype.__proto__ = Transport.prototype;
*/
HTTPTransport.prototype.handleRequest = function (req) {
// Always set the response in case an error is returned to the client
this.response = req.res;
if (req.method == 'POST') {
var buffer = ''
, res = req.res
, origin = req.headers.origin
, headers = { 'Content-Length': 1 }
, headers = { 'Content-Length': 1, 'Content-Type': 'text/plain; charset=UTF-8' }
, self = this;
req.on('data', function (data) {
@@ -68,6 +72,7 @@ HTTPTransport.prototype.handleRequest = function (req) {
// prevent memory leaks for uncompleted requests
req.on('close', function () {
buffer = '';
self.onClose();
});
if (origin) {
@@ -76,8 +81,6 @@ HTTPTransport.prototype.handleRequest = function (req) {
headers['Access-Control-Allow-Credentials'] = 'true';
}
} else {
this.response = req.res;
Transport.prototype.handleRequest.call(this, req);
}
};

View File

@@ -10,6 +10,7 @@
*/
var HTTPPolling = require('./http-polling');
var jsonpolling_re = /^\d+$/
/**
* Export the constructor.
@@ -29,7 +30,7 @@ function JSONPPolling (mng, data, req) {
this.head = 'io.j[0](';
this.foot = ');';
if (data.query.i) {
if (data.query.i && jsonpolling_re.test(data.query.i)) {
this.head = 'io.j[' + data.query.i + '](';
}
};

View File

@@ -1,4 +1,3 @@
/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
@@ -89,11 +88,14 @@ WebSocket.prototype.onSocketConnect = function () {
}
var origin = this.req.headers['origin']
, location = ((this.manager.settings['match origin protocol'] ?
origin.match(/^https/) : this.socket.encrypted) ?
'wss' : 'ws')
+ '://' + this.req.headers.host + this.req.url
, waitingForNonce = false;
, waitingForNonce = false;
if(this.manager.settings['match origin protocol']){
location = (origin.indexOf('https')>-1 ? 'wss' : 'ws') + '://' + this.req.headers.host + this.req.url;
}else if(this.socket.encrypted){
location = 'wss://' + this.req.headers.host + this.req.url;
}else{
location = 'ws://' + this.req.headers.host + this.req.url;
}
if (this.req.headers['sec-websocket-key1']) {
// If we don't have the nonce yet, wait for it (HAProxy compatibility).

View File

@@ -1,4 +1,3 @@
/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
@@ -98,7 +97,7 @@ WebSocket.prototype.onSocketConnect = function () {
return;
}
var origin = this.req.headers['origin']
var origin = this.req.headers['origin'] || ''
, location = ((this.manager.settings['match origin protocol'] ?
origin.match(/^https/) : this.socket.encrypted) ?
'wss' : 'ws')

View File

@@ -1,6 +1,6 @@
{
"name": "socket.io"
, "version": "0.9.0"
, "version": "0.9.10"
, "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,13 +16,13 @@
, "url": "https://github.com/LearnBoost/socket.io.git"
}
, "dependencies": {
"socket.io-client": "0.9.0"
"socket.io-client": "0.9.10"
, "policyfile": "0.0.4"
, "redis": "0.6.7"
, "redis": "0.7.2"
}
, "devDependencies": {
"expresso": "0.9.2"
, "should": "0.0.4"
, "should": "*"
, "benchmark": "0.2.2"
, "microtime": "0.1.3-1"
, "colors": "0.5.1"

View File

@@ -103,7 +103,11 @@ HTTPClient.prototype.end = function () {
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();
if (self.agent.sockets[socket][i]._handle.socket) {
self.agent.sockets[socket][i]._handle.socket.end();
} else {
self.agent.sockets[socket][i]._handle.owner.end();
}
}
}
});

View File

@@ -282,5 +282,46 @@ module.exports = {
}
});
});
},
'disconnecting from namespace only': function (done) {
var cl = client(++ports)
, io = create(cl)
, ws1
, ws2;
io.of('/foo').on('connection', function (socket) {
socket.disconnect();
});
cl.handshake(function (sid) {
ws1 = websocket(cl, sid);
ws1.on('open', function () {
ws1.packet({
type: 'connect'
, endpoint: '/bar'
});
cl.handshake(function (sid) {
ws2 = websocket(cl, sid);
ws2.on('open', function () {
ws2.packet({
type: 'connect'
, endpoint: '/foo'
});
});
ws2.on('message', function (data) {
if ('disconnect' === data.type) {
cl.end();
ws1.finishClose();
ws2.finishClose();
io.server.close();
data.endpoint.should.eql('/foo');
done();
}
});
});
});
});
}
};

View File

@@ -95,7 +95,7 @@ module.exports = {
'decoding json packet with message id and ack data': function () {
parser.decodePacket('4:1+::{"a":"b"}').should.eql({
type: 'json'
, id: 1
, id: '1'
, ack: 'data'
, endpoint: ''
, data: { a: 'b' }
@@ -114,7 +114,7 @@ module.exports = {
'decoding an event packet with message id and ack': function () {
parser.decodePacket('5:1+::{"name":"tobi"}').should.eql({
type: 'event'
, id: 1
, id: '1'
, ack: 'data'
, endpoint: ''
, name: 'tobi'
@@ -143,7 +143,7 @@ module.exports = {
'decoding a message packet with id and endpoint': function () {
parser.decodePacket('3:5:/tobi').should.eql({
type: 'message'
, id: 5
, id: '5'
, ack: true
, endpoint: '/tobi'
, data: ''
@@ -245,7 +245,7 @@ module.exports = {
'encoding json packet with message id and ack data': function () {
parser.encodePacket({
type: 'json'
, id: 1
, id: '1'
, ack: 'data'
, endpoint: ''
, data: { a: 'b' }
@@ -264,7 +264,7 @@ module.exports = {
'encoding an event packet with message id and ack': function () {
parser.encodePacket({
type: 'event'
, id: 1
, id: '1'
, ack: 'data'
, endpoint: ''
, name: 'tobi'
@@ -292,7 +292,7 @@ module.exports = {
'encoding a message packet with id and endpoint': function () {
parser.encodePacket({
type: 'message'
, id: 5
, id: '5'
, ack: true
, endpoint: '/tobi'
, data: ''

View File

@@ -452,7 +452,7 @@ module.exports = {
cl.get('/socket.io/socket.io.js', function (res, data) {
res.headers['content-type'].should.eql('application/javascript');
res.headers['content-length'].should.eql(13);
res.headers['content-length'].should.eql('13');
res.headers.etag.should.eql('1.0');
data.should.eql('custom_client');

View File

@@ -104,7 +104,7 @@ module.exports = {
netConnection(port, function (err, data){
should.strictEqual(err, null);
data.toString().should.include.string('<cross-domain-policy>');
data.toString().should.match(/<cross-domain-policy>/);
this.destroy();
io.flashPolicyServer.close();
@@ -133,7 +133,7 @@ module.exports = {
netConnection(next, function (err, data){
should.strictEqual(err, null);
data.toString().should.include.string('<cross-domain-policy>');
data.toString().should.match(/<cross-domain-policy>/);
this.destroy();
io.flashPolicyServer.close();
@@ -159,7 +159,7 @@ module.exports = {
server.origins.should.not.contain('google.com:80');
server.origins.should.contain('foo.bar:80');
server.origins.should.contain('socket.io:1337');
server.buffer.toString('utf8').should.include.string('socket.io');
server.buffer.toString('utf8').should.match(/socket\.io/);
io.flashPolicyServer.close();
done();

View File

@@ -257,7 +257,7 @@ module.exports = {
, sid;
io.configure(function () {
io.set('close timeout', .05);
io.set('close timeout', .1);
});
io.sockets.on('connection', function (socket) {
@@ -625,7 +625,7 @@ module.exports = {
io.configure(function () {
io.set('polling duration', .2);
io.set('close timeout', .2);
io.set('close timeout', .5);
});
io.sockets.on('connection', function (socket) {

View File

@@ -25,7 +25,7 @@ module.exports = {
, ws;
io.set('transports', ['websocket']);
io.sockets.on('connection', function (socket) {
io.on('connection', function (socket) {
socket.manager.transports[socket.id].name.should.equal('websocket');
ws.finishClose();
cl.end();

View File

@@ -289,6 +289,40 @@ module.exports = {
});
},
'test that connection close does not mean disconnect': function (done) {
var cl = client(++ports)
, io = create(cl)
, sid
, end
, disconnected = false
io.configure(function () {
io.set('polling duration', .2);
io.set('close timeout', .5);
});
io.sockets.on('connection', function (client) {
end = function () {
cl.end();
console.log('ending');
client.on('disconnect', function () {
disconnected = true;
});
}
});
cl.handshake(function (sid) {
cl.get('/socket.io/{protocol}/xhr-polling/' + sid);
setTimeout(end, 30);
setTimeout(function () {
console.log('finished');
disconnected.should.be.false;
io.server.close();
done();
}, 100);
});
},
'test sending back data': function (done) {
var cl = client(++ports)
, io = create(cl);
@@ -1317,7 +1351,7 @@ module.exports = {
msgs.should.have.length(1);
msgs[0].should.eql({
type: 'ack'
, ackId: 1
, ackId: '1'
, endpoint: ''
, args: []
});