Compare commits

...

28 Commits
1.1.0 ... 1.2.0

Author SHA1 Message Date
Guillermo Rauch
4a0091b25a Release 1.2.0 2014-10-27 15:54:57 -07:00
Guillermo Rauch
a1bf85b57f package: bump socket.io-parser 2014-10-27 11:52:09 -07:00
Guillermo Rauch
62ad812ee5 package: use latest socket.io-client 2014-10-27 11:51:03 -07:00
Guillermo Rauch
9ae8ed6929 package: bump adapter 2014-10-27 11:46:44 -07:00
Guillermo Rauch
4a11c16cc2 package: bump socket.io-client 2014-10-27 11:09:44 -07:00
Guillermo Rauch
b88a758857 package: bump engine.io 2014-10-27 07:47:51 -07:00
Guillermo Rauch
3352d1d726 Merge branch 'master' of github.com:Automattic/socket.io 2014-10-13 08:52:46 -07:00
Guillermo Rauch
e68557fab6 downloads badge 2014-10-13 08:52:36 -07:00
Tony Kovanen
da358084f0 Merge pull request #1773 from AjayMT/master
Fix usage example for Server#close.
2014-09-26 01:13:18 +03:00
Tony Kovanen
1b4f6a5324 Merge pull request #1777 from akamensky/dynamic-cors
Dynamic cors
2014-09-22 13:38:14 -06:00
Tony Kovanen
99346eddc5 Merge pull request #1788 from jamesanthonyferguson/patch-1
Change grammar issues in the chat/README.md
2014-09-22 12:42:59 -06:00
Tony Kovanen
051ffa0440 Merge pull request #1626 from thanpolas/patch-1
http.Server is a constructor
2014-09-22 12:42:10 -06:00
Tony Kovanen
fa4fa3365a Merge pull request #1690 from rase-/fix/resource-option-bc
Fix resource option BC with the set function
2014-09-22 12:27:35 -06:00
Tony Kovanen
bafa184c6b Merge pull request #1792 from rase-/add/autopruning-test
Add room autopruning test
2014-09-22 12:25:23 -06:00
Tony Kovanen
e3149d5833 Bump adapter version. 2014-09-20 11:12:58 -06:00
Tony Kovanen
ae9d5277a9 Add test to check that empty rooms are autopruned. 2014-09-20 11:12:26 -06:00
James Ferguson
2e440722a6 Change grammar issues in the chat/README.md
Added a few periods and commas which were missing. Also added the word each to clarify how multiple users each enter a unique username.
Very minor edit. No source code changed.
2014-09-18 21:41:28 -07:00
Tony Kovanen
3fe6d4e8ec Merge pull request #1784 from matthewcanty/patch-1
Change "there're" to "there are"
2014-09-17 07:41:46 -06:00
Matthew Canty
3b93c1c562 Change "there're" to "there are"
Not a commonly used contraction and looks a bit odd.
2014-09-17 14:01:01 +01:00
akamensky
e89f82a9b0 Added Server#origins(v:Function) description for dynamic CORS 2014-09-12 11:32:20 +08:00
akamensky
1b90ae2587 Added test coverage for Server#origins(function) for dynamic CORS 2014-09-12 11:13:51 +08:00
akamensky
9658e32e7a Added optional Server#origins(function) for dynamic CORS 2014-09-12 10:53:14 +08:00
Tony Kovanen
99d76664aa Merge pull request #1766 from BrianGeppert/master
package: fix main file for example application 'chat'.
2014-09-11 18:05:58 +03:00
Ajay MT
23eefa527a Fix usage example for Server#close. 2014-09-10 18:11:56 +05:30
Brian Geppert
b49b35b26f package: fix main file for example application 'chat'. 2014-09-04 12:10:43 -05:00
Tony Kovanen
b4954d767a Take the instance stored path value into account when attaching to eio if no option specified to attach directly 2014-07-23 19:58:44 +03:00
Thanasis Polychronakis
63e197083b update README http ctor to createServer() 2014-07-01 10:41:53 +03:00
Thanasis Polychronakis
55fb100fc0 http.Server is a constructor
...and thus requires the `new` keyword
2014-06-14 13:52:36 +03:00
8 changed files with 109 additions and 24 deletions

View File

@@ -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
==================

View File

@@ -3,6 +3,7 @@
[![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)
## 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

View File

@@ -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.

View File

@@ -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",

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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"
},

View File

@@ -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){