mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 07:58:13 -05:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d99e30fca7 | ||
|
|
561dd6fd79 | ||
|
|
e9e2a91cea | ||
|
|
8a3a111a7f | ||
|
|
bd87e4dc35 | ||
|
|
71c253e992 | ||
|
|
a5cf4f57a0 | ||
|
|
a079cbc7f9 | ||
|
|
14a9fdb64f | ||
|
|
6159df3937 | ||
|
|
6f7bab5dfd | ||
|
|
7d2b44e176 | ||
|
|
0b5fdf995a | ||
|
|
a66bea5b33 | ||
|
|
a1a88aaaaf | ||
|
|
3f817c3a18 | ||
|
|
99bbd74d14 | ||
|
|
398511ddee | ||
|
|
fdf7937815 | ||
|
|
475909e642 | ||
|
|
95acec8b94 | ||
|
|
5812ddf2b0 | ||
|
|
1bbc3951bd | ||
|
|
039eed2c2a | ||
|
|
6de022b180 | ||
|
|
a06331d29f | ||
|
|
e639685370 | ||
|
|
1f2e681ce2 | ||
|
|
397944fcbe | ||
|
|
27dada65b9 | ||
|
|
99f1ac9aae | ||
|
|
ee8d0fbae0 | ||
|
|
8e08a6d419 | ||
|
|
318ae87f50 | ||
|
|
2c1b61148d | ||
|
|
507054c0a8 | ||
|
|
dfceb006d7 | ||
|
|
4d83456f74 | ||
|
|
201aad83b1 | ||
|
|
72eb61d01f | ||
|
|
163a2a696e | ||
|
|
199a479ebc | ||
|
|
d383ff9662 | ||
|
|
416b550189 | ||
|
|
536b338a01 | ||
|
|
a06ae10895 | ||
|
|
35a85084b1 | ||
|
|
0c2b44a846 | ||
|
|
0f6ee2dbd9 |
32
History.md
32
History.md
@@ -1,4 +1,36 @@
|
||||
|
||||
1.0.6 / 2014-06-19
|
||||
==================
|
||||
|
||||
* package: bump `socket.io-client`
|
||||
|
||||
1.0.5 / 2014-06-16
|
||||
==================
|
||||
|
||||
* package: bump `engine.io` to fix jsonp `\n` bug and CORS warnings
|
||||
* index: fix typo [yanatan16]
|
||||
* add `removeListener` to blacklisted events
|
||||
* examples: clearer instructions to install chat example
|
||||
* index: fix namespace `connectBuffer` issue
|
||||
|
||||
1.0.4 / 2014-06-02
|
||||
==================
|
||||
|
||||
* package: bump socket.io-client
|
||||
|
||||
1.0.3 / 2014-05-31
|
||||
==================
|
||||
|
||||
* package: bump `socket.io-client`
|
||||
* package: bump `socket.io-parser` for binary ACK fix
|
||||
* package: bump `engine.io` for binary UTF8 fix
|
||||
* example: fix XSS in chat example
|
||||
|
||||
1.0.2 / 2014-05-28
|
||||
==================
|
||||
|
||||
* package: bump `socket.io-parser` for windows fix
|
||||
|
||||
1.0.1 / 2014-05-28
|
||||
==================
|
||||
|
||||
|
||||
11
Readme.md
11
Readme.md
@@ -1,10 +1,7 @@
|
||||
### This Readme corresponds to the upcoming 1.0 release. Please refer to http://socket.io for the current 0.9.x documentation.
|
||||
|
||||
<hr />
|
||||
|
||||
# socket.io
|
||||
|
||||
[](http://travis-ci.org/LearnBoost/socket.io)
|
||||
[](http://travis-ci.org/Automattic/socket.io)
|
||||
[](http://badge.fury.io/js/socket.io)
|
||||
|
||||
## How to use
|
||||
@@ -129,7 +126,7 @@ server.listen(3000);
|
||||
|
||||
Sets the adapter `v`. Defaults to an instance of the `Adapter` that
|
||||
ships with socket.io which is memory based. See
|
||||
[socket.io-adapter](https://github.com/learnboost/socket.io-adapter).
|
||||
[socket.io-adapter](https://github.com/Automattic/socket.io-adapter).
|
||||
|
||||
If no arguments are supplied this method returns the current value.
|
||||
|
||||
@@ -288,7 +285,7 @@ server.listen(3000);
|
||||
|
||||
The mechanics of joining rooms are handled by the `Adapter`
|
||||
that has been configured (see `Server#adapter` above), defaulting to
|
||||
[socket.io-adapter](https://github.com/socket.io/socket.io-adapter).
|
||||
[socket.io-adapter](https://github.com/Automattic/socket.io-adapter).
|
||||
|
||||
### Socket#leave(name:String[, fn:Function]):Socket
|
||||
|
||||
@@ -299,7 +296,7 @@ server.listen(3000);
|
||||
|
||||
The mechanics of leaving rooms are handled by the `Adapter`
|
||||
that has been configured (see `Server#adapter` above), defaulting to
|
||||
[socket.io-adapter](https://github.com/socket.io/socket.io-adapter).
|
||||
[socket.io-adapter](https://github.com/Automattic/socket.io-adapter).
|
||||
|
||||
### Socket#to(room:String):Socket
|
||||
### Socket#in(room:String):Socket
|
||||
|
||||
@@ -6,6 +6,9 @@ A simple chat demo for socket.io
|
||||
## How to use
|
||||
|
||||
```
|
||||
$ cd socket.io
|
||||
$ npm install
|
||||
$ cd examples/chat
|
||||
$ npm install
|
||||
$ node .
|
||||
```
|
||||
|
||||
@@ -70,8 +70,8 @@ $(function() {
|
||||
|
||||
// Log a message
|
||||
function log (message, options) {
|
||||
var el = '<li class="log">' + message + '</li>';
|
||||
addMessageElement(el, options);
|
||||
var $el = $('<li>').addClass('log').text(message);
|
||||
addMessageElement($el, options);
|
||||
}
|
||||
|
||||
// Adds the visual chat message to the message list
|
||||
@@ -84,16 +84,17 @@ $(function() {
|
||||
$typingMessages.remove();
|
||||
}
|
||||
|
||||
var colorStyle = 'style="color:' + getUsernameColor(data.username) + '"';
|
||||
var usernameDiv = '<span class="username"' + colorStyle + '>' +
|
||||
data.username + '</span>';
|
||||
var messageBodyDiv = '<span class="messageBody">' +
|
||||
data.message + '</span>';
|
||||
var $usernameDiv = $('<span class="username"/>')
|
||||
.text(data.username)
|
||||
.css('color', getUsernameColor(data.username));
|
||||
var $messageBodyDiv = $('<span class="messageBody">')
|
||||
.text(data.message);
|
||||
|
||||
var typingClass = data.typing ? 'typing' : '';
|
||||
var messageDiv = '<li class="message ' + typingClass + '">' +
|
||||
usernameDiv + messageBodyDiv + '</li>';
|
||||
var $messageDiv = $(messageDiv).data('username', data.username);
|
||||
var $messageDiv = $('<li class="message"/>')
|
||||
.data('username', data.username)
|
||||
.addClass(typingClass)
|
||||
.append($usernameDiv, $messageBodyDiv);
|
||||
|
||||
addMessageElement($messageDiv, options);
|
||||
}
|
||||
@@ -145,7 +146,7 @@ $(function() {
|
||||
|
||||
// Prevents input from having injected markup
|
||||
function cleanInput (input) {
|
||||
return $('<div/>').text(input).html() || input;
|
||||
return $('<div/>').text(input).text();
|
||||
}
|
||||
|
||||
// Updates the typing event
|
||||
|
||||
@@ -25,6 +25,7 @@ html, body {
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
/* Pages */
|
||||
|
||||
@@ -68,7 +68,7 @@ Client.prototype.connect = function(name){
|
||||
self.sockets.push(socket);
|
||||
self.nsps[nsp.name] = socket;
|
||||
|
||||
if ('/' == nsp.name) {
|
||||
if ('/' == nsp.name && self.connectBuffer) {
|
||||
self.connectBuffer.forEach(self.connect, self);
|
||||
delete self.connectBuffer;
|
||||
}
|
||||
@@ -199,9 +199,10 @@ Client.prototype.onclose = function(reason){
|
||||
this.destroy();
|
||||
|
||||
// `nsps` and `sockets` are cleaned up seamlessly
|
||||
this.sockets.forEach(function(socket){
|
||||
var socket;
|
||||
while (socket = this.sockets.shift()) {
|
||||
socket.onclose(reason);
|
||||
});
|
||||
}
|
||||
|
||||
this.decoder.destroy(); // clean up decoder
|
||||
};
|
||||
|
||||
@@ -159,7 +159,9 @@ Server.prototype.adapter = function(v){
|
||||
if (!arguments.length) return this._adapter;
|
||||
this._adapter = v;
|
||||
for (var i in this.nsps) {
|
||||
this.nsps[i].initAdapter();
|
||||
if (this.nsps.hasOwnProperty(i)) {
|
||||
this.nsps[i].initAdapter();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,8 @@ exports.events = [
|
||||
'error',
|
||||
'connect',
|
||||
'disconnect',
|
||||
'newListener'
|
||||
'newListener',
|
||||
'removeListener'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -293,6 +294,10 @@ Socket.prototype.onpacket = function(packet){
|
||||
this.onack(packet);
|
||||
break;
|
||||
|
||||
case parser.BINARY_ACK:
|
||||
this.onack(packet);
|
||||
break;
|
||||
|
||||
case parser.DISCONNECT:
|
||||
this.ondisconnect();
|
||||
break;
|
||||
@@ -336,9 +341,11 @@ Socket.prototype.ack = function(id){
|
||||
if (sent) return;
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
debug('sending ack %j', args);
|
||||
|
||||
var type = hasBin(args) ? parser.BINARY_ACK : parser.ACK;
|
||||
self.packet({
|
||||
id: id,
|
||||
type: parser.ACK,
|
||||
type: type,
|
||||
data: args
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "socket.io",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.6",
|
||||
"description": "node.js realtime framework server",
|
||||
"keywords": [
|
||||
"realtime",
|
||||
@@ -19,9 +19,9 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"engine.io": "1.2.1",
|
||||
"socket.io-parser": "2.1.4",
|
||||
"socket.io-client": "1.0.1",
|
||||
"engine.io": "1.3.1",
|
||||
"socket.io-parser": "2.2.0",
|
||||
"socket.io-client": "1.0.6",
|
||||
"socket.io-adapter": "0.2.0",
|
||||
"has-binary-data": "0.1.1",
|
||||
"debug": "0.7.4"
|
||||
|
||||
BIN
test/fixtures/big.jpg
vendored
Normal file
BIN
test/fixtures/big.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 MiB |
174066
test/fixtures/big.json
vendored
Normal file
174066
test/fixtures/big.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -395,10 +395,55 @@ describe('socket.io', function(){
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should disconnect both default and custom namespace upon disconnect', function(done){
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
srv.listen(function(){
|
||||
var lolcats = client(srv, '/lolcats');
|
||||
var total = 2;
|
||||
var totald = 2;
|
||||
var s;
|
||||
sio.of('/', function(socket){
|
||||
socket.on('disconnect', function(reason){
|
||||
--totald || done();
|
||||
});
|
||||
--total || close();
|
||||
});
|
||||
sio.of('/lolcats', function(socket){
|
||||
s = socket;
|
||||
socket.on('disconnect', function(reason){
|
||||
--totald || done();
|
||||
});
|
||||
--total || close();
|
||||
});
|
||||
function close(){
|
||||
s.disconnect(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('socket', function(){
|
||||
|
||||
it('should not fire events more than once after manually reconnecting', function(done) {
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
srv.listen(function(){
|
||||
var clientSocket = client(srv, { reconnection: false });
|
||||
clientSocket.on('connect', function init() {
|
||||
clientSocket.removeListener('connect', init);
|
||||
clientSocket.io.engine.close();
|
||||
|
||||
clientSocket.connect();
|
||||
clientSocket.on('connect', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should receive events', function(done){
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
@@ -446,6 +491,28 @@ describe('socket.io', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit events with utf8 multibyte character', function(done) {
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
srv.listen(function(){
|
||||
var socket = client(srv);
|
||||
var i = 0;
|
||||
socket.on('hoot', function(a){
|
||||
expect(a).to.be('utf8 — string');
|
||||
i++;
|
||||
|
||||
if (3 == i) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
sio.on('connection', function(s){
|
||||
s.emit('hoot', 'utf8 — string');
|
||||
s.emit('hoot', 'utf8 — string');
|
||||
s.emit('hoot', 'utf8 — string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit events with binary data', function(done){
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
@@ -570,6 +637,30 @@ describe('socket.io', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('should receive all events emitted from namespaced client immediately and in order', function(done) {
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
var total = 0;
|
||||
srv.listen(function(){
|
||||
sio.of('/chat', function(s){
|
||||
s.on('hi', function(letter){
|
||||
total++;
|
||||
if (total == 2 && letter == 'b') {
|
||||
done();
|
||||
} else if (total == 1 && letter != 'a') {
|
||||
throw new Error('events out of order');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var chat = client(srv, '/chat');
|
||||
chat.emit('hi', 'a');
|
||||
setTimeout(function() {
|
||||
chat.emit('hi', 'b');
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit events with callbacks', function(done){
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
@@ -746,6 +837,59 @@ describe('socket.io', function(){
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle very large json', function(done){
|
||||
this.timeout();
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
var received = 0;
|
||||
srv.listen(function(){
|
||||
var socket = client(srv);
|
||||
socket.on('big', function(a){
|
||||
expect(Buffer.isBuffer(a.json)).to.be(false);
|
||||
if (++received == 3)
|
||||
done();
|
||||
else
|
||||
socket.emit('big', a);
|
||||
});
|
||||
sio.on('connection', function(s){
|
||||
fs.readFile(join(__dirname, 'fixtures', 'big.json'), function(err, data){
|
||||
if (err) return done(err);
|
||||
data = JSON.parse(data);
|
||||
s.emit('big', {hello: 'friend', json: data});
|
||||
});
|
||||
s.on('big', function(a){
|
||||
s.emit('big', a);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle very large binary data', function(done){
|
||||
var srv = http();
|
||||
var sio = io(srv);
|
||||
var received = 0;
|
||||
srv.listen(function(){
|
||||
var socket = client(srv);
|
||||
socket.on('big', function(a){
|
||||
expect(Buffer.isBuffer(a.image)).to.be(true);
|
||||
if (++received == 3)
|
||||
done();
|
||||
else
|
||||
socket.emit('big', a);
|
||||
});
|
||||
sio.on('connection', function(s){
|
||||
fs.readFile(join(__dirname, 'fixtures', 'big.jpg'), function(err, data){
|
||||
if (err) return done(err);
|
||||
s.emit('big', {hello: 'friend', image: data});
|
||||
});
|
||||
s.on('big', function(a){
|
||||
expect(Buffer.isBuffer(a.image)).to.be(true);
|
||||
s.emit('big', a);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('messaging many', function(){
|
||||
|
||||
Reference in New Issue
Block a user