mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 16:08:24 -05:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a0091b25a | ||
|
|
a1bf85b57f | ||
|
|
62ad812ee5 | ||
|
|
9ae8ed6929 | ||
|
|
4a11c16cc2 | ||
|
|
b88a758857 | ||
|
|
3352d1d726 | ||
|
|
e68557fab6 | ||
|
|
da358084f0 | ||
|
|
1b4f6a5324 | ||
|
|
99346eddc5 | ||
|
|
051ffa0440 | ||
|
|
fa4fa3365a | ||
|
|
bafa184c6b | ||
|
|
e3149d5833 | ||
|
|
ae9d5277a9 | ||
|
|
2e440722a6 | ||
|
|
3fe6d4e8ec | ||
|
|
3b93c1c562 | ||
|
|
e89f82a9b0 | ||
|
|
1b90ae2587 | ||
|
|
9658e32e7a | ||
|
|
99d76664aa | ||
|
|
23eefa527a | ||
|
|
b49b35b26f | ||
|
|
b4954d767a | ||
|
|
63e197083b | ||
|
|
55fb100fc0 |
15
History.md
15
History.md
@@ -1,4 +1,19 @@
|
||||
|
||||
1.2.0 / 2014-10-27
|
||||
==================
|
||||
|
||||
* package: bump `engine.io`
|
||||
* downloads badge
|
||||
* add test to check that empty rooms are autopruned
|
||||
* added Server#origins(v:Function) description for dynamic CORS
|
||||
* added test coverage for Server#origins(function) for dynamic CORS
|
||||
* added optional Server#origins(function) for dynamic CORS
|
||||
* fix usage example for Server#close
|
||||
* package: fix main file for example application 'chat'
|
||||
* package: bump `socket.io-parser`
|
||||
* update README http ctor to createServer()
|
||||
* bump adapter with a lot of fixes for room bookkeeping
|
||||
|
||||
1.1.0 / 2014-09-04
|
||||
==================
|
||||
|
||||
|
||||
22
Readme.md
22
Readme.md
@@ -3,6 +3,7 @@
|
||||
|
||||
[](http://travis-ci.org/Automattic/socket.io)
|
||||
[](http://badge.fury.io/js/socket.io)
|
||||

|
||||
|
||||
## How to use
|
||||
|
||||
@@ -10,7 +11,7 @@ The following example attaches socket.io to a plain Node.JS
|
||||
HTTP server listening on port `3000`.
|
||||
|
||||
```js
|
||||
var server = require('http').Server();
|
||||
var server = require('http').createServer();
|
||||
var io = require('socket.io')(server);
|
||||
io.on('connection', function(socket){
|
||||
socket.on('event', function(data){});
|
||||
@@ -36,7 +37,7 @@ function.
|
||||
|
||||
```js
|
||||
var app = require('express')();
|
||||
var server = require('http').Server(app);
|
||||
var server = require('http').createServer(app);
|
||||
var io = require('socket.io')(server);
|
||||
io.on('connection', function(){ /* … */ });
|
||||
server.listen(3000);
|
||||
@@ -49,7 +50,7 @@ handler function, but only by calling the `callback` method.
|
||||
|
||||
```js
|
||||
var app = require('koa')();
|
||||
var server = require('http').Server(app.callback());
|
||||
var server = require('http').createServer(app.callback());
|
||||
var io = require('socket.io')(server);
|
||||
io.on('connection', function(){ /* … */ });
|
||||
server.listen(3000);
|
||||
@@ -136,6 +137,15 @@ server.listen(3000);
|
||||
|
||||
If no arguments are supplied this method returns the current value.
|
||||
|
||||
### Server#origins(v:Function):Server
|
||||
|
||||
Sets the allowed origins as dynamic function. Function takes two arguments `origin:String` and `callback(error, success)`, where `success` is a boolean value indicating whether origin is allowed or not.
|
||||
|
||||
__Potential drawbacks__:
|
||||
* in some situations, when it is not possible to determine `origin` it may have value of `*`
|
||||
* As this function will be executed for every request, it is advised to make this function work as fast as possible
|
||||
* If `socket.io` is used together with `Express`, the CORS headers will be affected only for `socket.io` requests. For Express can use [cors](https://github.com/troygoode/node-cors/)
|
||||
|
||||
|
||||
### Server#sockets:Namespace
|
||||
|
||||
@@ -190,17 +200,17 @@ server.listen(3000);
|
||||
Closes socket server
|
||||
|
||||
```js
|
||||
var io = require('socket.io');
|
||||
var Server = require('socket.io');
|
||||
var PORT = 3030;
|
||||
var server = require('http').Server();
|
||||
|
||||
io(PORT);
|
||||
var io = Server(PORT);
|
||||
|
||||
io.close(); // Close current server
|
||||
|
||||
server.listen(PORT); // PORT is free to use
|
||||
|
||||
io(server);
|
||||
io = Server(server);
|
||||
```
|
||||
|
||||
### Server#use
|
||||
|
||||
@@ -13,13 +13,13 @@ $ npm install
|
||||
$ node .
|
||||
```
|
||||
|
||||
And point your browser to `http://localhost:3000`. Optionally specify
|
||||
And point your browser to `http://localhost:3000`. Optionally, specify
|
||||
a port by supplying the `PORT` env variable.
|
||||
|
||||
## Features
|
||||
|
||||
- Multiple users can join a chat room by entering a unique username
|
||||
- Multiple users can join a chat room by each entering a unique username
|
||||
on website load.
|
||||
- Users can type chat messages to the chat room
|
||||
- Users can type chat messages to the chat room.
|
||||
- A notification is sent to all users when a user joins or leaves
|
||||
the chatroom
|
||||
the chatroom.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "socket.io-chat",
|
||||
"version": "0.0.0",
|
||||
"description": "A simple chat client using socket.io",
|
||||
"main": "app.js",
|
||||
"main": "index.js",
|
||||
"author": "Grant Timmerman",
|
||||
"private": true,
|
||||
"license": "BSD",
|
||||
|
||||
@@ -30,7 +30,7 @@ $(function() {
|
||||
if (data.numUsers === 1) {
|
||||
message += "there's 1 participant";
|
||||
} else {
|
||||
message += "there're " + data.numUsers + " participants";
|
||||
message += "there are " + data.numUsers + " participants";
|
||||
}
|
||||
log(message);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ Server.prototype.checkRequest = function(req, fn) {
|
||||
// file:// URLs produce a null Origin which can't be authorized via echo-back
|
||||
if ('null' == origin) origin = '*';
|
||||
|
||||
if (!!origin && typeof(this._origins) == 'function') return this._origins(origin, fn);
|
||||
if (this._origins.indexOf('*:*') !== -1) return fn(null, true);
|
||||
if (origin) {
|
||||
try {
|
||||
@@ -216,7 +217,7 @@ Server.prototype.attach = function(srv, opts){
|
||||
|
||||
// set engine.io path to `/socket.io`
|
||||
opts = opts || {};
|
||||
opts.path = opts.path || '/socket.io';
|
||||
opts.path = opts.path || this.path();
|
||||
// set origins verification
|
||||
opts.allowRequest = this.checkRequest.bind(this);
|
||||
|
||||
|
||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "socket.io",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "node.js realtime framework server",
|
||||
"keywords": [
|
||||
"realtime",
|
||||
@@ -19,10 +19,10 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"engine.io": "1.4.0",
|
||||
"socket.io-parser": "2.2.1",
|
||||
"socket.io-client": "1.1.0",
|
||||
"socket.io-adapter": "0.2.0",
|
||||
"engine.io": "1.4.2",
|
||||
"socket.io-parser": "2.2.2",
|
||||
"socket.io-client": "1.2.0",
|
||||
"socket.io-adapter": "0.3.1",
|
||||
"has-binary-data": "0.1.3",
|
||||
"debug": "0.7.4"
|
||||
},
|
||||
|
||||
@@ -51,10 +51,21 @@ describe('socket.io', function(){
|
||||
expect(srv.eio.maxHttpBufferSize).to.eql(10);
|
||||
});
|
||||
|
||||
it('should be able to set path with setting resource', function() {
|
||||
var srv = io(http());
|
||||
srv.set('resource', '/random');
|
||||
expect(srv.path()).to.be('/random');
|
||||
it('should be able to set path with setting resource', function(done) {
|
||||
var eio = io();
|
||||
var srv = http();
|
||||
|
||||
eio.set('resource', '/random');
|
||||
eio.attach(srv);
|
||||
|
||||
// Check that the server is accessible through the specified path
|
||||
request(srv)
|
||||
.get('/random/socket.io.js')
|
||||
.buffer(true)
|
||||
.end(function(err, res){
|
||||
if (err) return done(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to set origins to engine.io', function() {
|
||||
@@ -259,12 +270,42 @@ describe('socket.io', function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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')
|
||||
return callback(null, true);
|
||||
return callback(null, false);
|
||||
} }).listen('54016');
|
||||
request.get('http://localhost:54016/socket.io/default/')
|
||||
.set('origin', 'http://foo.example')
|
||||
.query({ transport: 'polling' })
|
||||
.end(function (err, res) {
|
||||
expect(res.status).to.be(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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')
|
||||
return callback(null, true);
|
||||
return callback(null, false);
|
||||
} }).listen('54017');
|
||||
request.get('http://localhost:54017/socket.io/default/')
|
||||
.set('origin', 'http://herp.derp')
|
||||
.query({ transport: 'polling' })
|
||||
.end(function (err, res) {
|
||||
expect(res.status).to.be(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('close', function(){
|
||||
|
||||
it('should be able to close sio sending a srv', function(){
|
||||
var PORT = 54016;
|
||||
var PORT = 54018;
|
||||
var srv = http().listen(PORT);
|
||||
var sio = io(srv);
|
||||
var net = require('net');
|
||||
@@ -292,7 +333,7 @@ describe('socket.io', function(){
|
||||
});
|
||||
|
||||
it('should be able to close sio sending a port', function(){
|
||||
var PORT = 54017;
|
||||
var PORT = 54019;
|
||||
var sio = io(PORT);
|
||||
var net = require('net');
|
||||
var server = net.createServer();
|
||||
@@ -1291,6 +1332,24 @@ describe('socket.io', function(){
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes empty 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.nsp.adapter.rooms).to.have.key('a');
|
||||
s.leave('a', function(){
|
||||
expect(s.nsp.adapter.rooms).to.not.have.key('a');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('middleware', function(done){
|
||||
|
||||
Reference in New Issue
Block a user