Compare commits

...

76 Commits
1.4.8 ... 1.5.0

Author SHA1 Message Date
Damien Arrachequesne
c94058f9b0 [chore] release 1.5.0 (#2711) 2016-10-07 00:13:33 +02:00
Damien Arrachequesne
43d9a4b55d [feature] Add a 'disconnecting' event to access to socket.rooms upon disconnection (#2332) 2016-10-06 23:23:26 +02:00
Alejandro Oviedo
df916172dd [chore] Link build badge to master branch (#2549) 2016-10-06 23:12:15 +02:00
Damien Arrachequesne
271c625243 [chore] Restrict files included in npm package (#2709) 2016-10-06 23:11:33 +02:00
Damien Arrachequesne
628fe8f1b2 [chore] Point towards current master of socket.io-client (#2710) 2016-10-06 23:10:54 +02:00
Damien Arrachequesne
db62e1bf67 [chore] Remove unused zuul-ngrok dependency (#2708) 2016-10-06 23:10:33 +02:00
YasharF
ba4c7921ef [chore] Bump engine.io to 1.7.0 (#2707) 2016-10-06 10:03:55 +02:00
Damien Arrachequesne
30ea0b8d7d Merge pull request #2599 from boazsegev/patch-1
Documentation update to help new programmers
2016-08-05 21:07:30 +02:00
Bo
2d141aff7c Prevent mixup for new programmers
The documentation, inadvertently, causes confusion for newer programmers, hindering their learning curve and ability to learn `socket.io` faster.

This proposed change aims at preventing this confusion to allow new programmers easier access to resources, especially when searching the web for more information.

The name `socket` in the documentation refers to the API gateway, or abstraction layer, related to the `client` and other properties. However, in the rest of the programming world, `sockets` usually refer to Berklee sockets or the lower-level communication channel that is used to implement Protocols such as the Websocket Protocol and HTTP.

New programmers often search for more informations using the `sockets` keyword when they are grappling with learning the `socket.io` API.

A good example is the stack overflow site, where newer programmers incorrectly tag their questions `sockets` and in turn don't get a fast response to their questions.

By simply changing the name of the variable used to describe socket.io's "Socket" class instances from `socket` to `client`, this mixup should be mitigated considerably.
2016-06-26 14:32:37 -04:00
Guillermo Rauch
40763d3962 1.4.8 2016-06-23 19:24:38 -07:00
Guillermo Rauch
e3207005da 1.4.7 2016-06-23 17:31:33 -07:00
Naoyuki Kanezawa
0c6d50d9c0 Merge pull request #2416 from nus-fboa2016-si/chatexample
updated express version to express 4
2016-04-12 03:58:08 +09:00
Naoyuki Kanezawa
881f16553c Merge pull request #2508 from tw0517tw/quote-exec
add quote to exec paths, prevent error when spaces in path
2016-04-12 03:57:43 +09:00
Guillermo Rauch
e5a8d4d2d9 Merge pull request #2520 from nkzawa/fix/ignore-dist
Ignore dist directory for now
2016-04-11 08:45:11 -07:00
Guillermo Rauch
fb0253edea Merge pull request #2422 from nus-fboa2016-si/queryStringFix
Fix for Issue #331 on socket.io-client
2016-04-11 08:44:59 -07:00
tw0517tw
3c5f5a0864 use a bigger timeout for slower machine 2016-04-11 22:31:47 +08:00
tw0517tw
a23d26a617 add quote to exec paths, prevent error when spaces in path 2016-04-11 22:21:34 +08:00
Zhu Liang
910b5d77a6 fixed version notation 2016-04-11 22:19:49 +08:00
Naoyuki Kanezawa
438ad63cdf Merge pull request #2420 from revington/test-node-v5-stable
[Travis] Add Node 5.x (Stable) to the test matrix
2016-04-11 23:09:41 +09:00
Naoyuki Kanezawa
7e9a67d8ee Merge pull request #2415 from nus-fboa2016-si/documentation
Documentation
2016-04-11 23:05:33 +09:00
Naoyuki Kanezawa
0ae070885d Merge pull request #2477 from callahad/chat-layout-fix
Fix chat display in Firefox
2016-04-11 23:00:07 +09:00
Naoyuki Kanezawa
36d99d8d84 Merge pull request #2492 from westy92/master
Update package.json
2016-04-11 22:20:46 +09:00
nkzawa
0e63b0910e ignore dist for now 2016-04-11 22:11:19 +09:00
Guillermo Rauch
3c7350fa58 Merge pull request #2509 from tw0517tw/patch-1
stop prepend /# before id when no namespace
2016-04-10 11:24:42 -07:00
Guillermo Rauch
aadd5da655 Merge pull request #2496 from nus-fboa2016-si/compat-test
Added test for compat version transformed by babel
2016-04-02 18:31:30 -07:00
吳東曄 Wu, Dung-Ie
6d4128750b stop append /# before id when no namespace 2016-04-02 01:55:53 +08:00
Zhu Liang
6edcd1c6ba styling fixes 2016-03-31 12:55:42 +08:00
Zhu Liang
6b2394e612 disable loading lib by default to avoid syntax error due to lib containing new es6 syntax 2016-03-31 03:54:32 +08:00
Zhu Liang
677af3fa11 changed env var name, added testing documentation to readme 2016-03-21 13:11:03 +08:00
Zhu Liang
a1ff739b36 babel transpile before test, print error 2016-03-19 20:19:08 +08:00
Zhu Liang
de5b588e17 explicit distinction between current and compat in test so we can serve either compat or current as default 2016-03-19 20:13:57 +08:00
Zhu Liang
5a20c1195b set env vars in travis 2016-03-19 19:49:41 +08:00
Zhu Liang
5253bc400b use multiple npm scripts 2016-03-19 19:41:14 +08:00
Zhu Liang
1245a5639e added compat test 2016-03-19 19:21:54 +08:00
Zhu Liang
88161539a1 implement compat test using env variable 2016-03-17 13:42:29 +08:00
Zhu Liang
d99d4d15ae add compat test for babel-transformed codes 2016-03-17 13:11:20 +08:00
Seth Westphal
06ecfe5444 Explicit local gulp is unnecesary 2016-03-16 13:01:49 -05:00
Seth Westphal
e90b4eba1e Update repository URL 2016-03-16 12:58:59 -05:00
Guillermo Rauch
c7de1a1adf Merge pull request #2471 from nus-fboa2016-si/gulp-rebased
Add gulp and babel
2016-03-12 20:04:48 -08:00
Dan Callahan
7bae6ac636 Fix chat display in Firefox 2016-03-08 19:50:55 -06:00
Diga Widyaprana
355b5156fe Remove node 0.8 from travis 2016-03-09 09:36:51 +08:00
Diga Widyaprana
3e168ee0b8 Redirect make tasks to gulp 2016-03-06 11:40:57 +08:00
Diga Widyaprana
ed9ab77dcb Minor fixes to gulp tasks
- Only provide entry point as first argument of gulp.src
- {read:false} option for mocha tests
- change timeout:2000 to slow:200 to mirror makefile's mocha options
- replace var with const where appropriate
2016-03-06 11:40:57 +08:00
Diga Widyaprana
1104cd135e Use local instead of global gulp in npm test 2016-03-06 11:40:57 +08:00
Diga Widyaprana
0be915cd0f Add gulp task clean to clean transpile output
- Work done by @YijinL. Part of @05ad308
2016-03-06 11:40:57 +08:00
Diga Widyaprana
c6dd41b915 Minor refactoring to transpile task
- Transpiling is now gulp transpile
- Default redirects to transpile
- Refactor transpile output directory to a separate constant
- Work by @YijinL in @05ad308
2016-03-06 11:32:40 +08:00
Diga Widyaprana
0f14312d7b Add gulp help
Work was done by @YijinL in 2 separate commits (@9204125 and @05ad308)
2016-03-06 11:32:09 +08:00
Diga Widyaprana
97bd95f036 Don't use dynamic dependencies 2016-03-04 18:06:00 +08:00
Diga Widyaprana
11e0f19272 Inline babel configuration 2016-03-04 18:06:00 +08:00
Yijin
e388a3319d npm test script to use gulp 2016-03-04 18:06:00 +08:00
Zheng Weihan
b551ce9835 added test-cov task. 2016-03-04 18:06:00 +08:00
Zhu Liang
0bac96a6b2 added comment for babel 2016-03-04 14:46:08 +08:00
Zhu Liang
1d07b10339 integrated babel into gulp 2016-03-04 14:46:08 +08:00
Zheng Weihan
398b5479f0 delete unused dependency 2016-03-04 14:45:55 +08:00
Zheng Weihan
d9eb729eab implement gulp build system for test. 2016-03-04 14:45:03 +08:00
whattokingu
f9db72997f Merge pull request #10 from whattokingu/queryStringFix
Query string fix
2016-02-14 13:57:06 +08:00
Zheng Weihan
1293505dc2 update tests. 2016-02-14 13:48:28 +08:00
Zheng Weihan
f4e9e71c56 Merge branch 'queryStringFix' of https://github.com/whattokingu/socket.io into queryStringFix
# By whattokingu
# Via whattokingu
* 'queryStringFix' of https://github.com/whattokingu/socket.io:
  conform to style guide

Conflicts:
	lib/client.js
2016-02-14 13:47:59 +08:00
Zheng Weihan
045674de97 remove unnecessary decoder. url.parse already decodes string.
add test to test decoding function.
2016-02-14 13:46:26 +08:00
whattokingu
7091acf24c Merge pull request #9 from whattokingu/queryStringFix
Query string fix
2016-02-13 14:41:15 +08:00
whattokingu
19341051e8 conform to style guide 2016-02-13 14:35:12 +08:00
Zheng Weihan
e141e09aaf change decodeUriComponents calls 2016-02-13 14:28:21 +08:00
Zheng Weihan
5fabe4e780 call decodeURIComponent on query received from client.
update package.son to point to latest commit in socket.o-client package (with URI encoder)
2016-02-13 14:10:20 +08:00
whattokingu
7760a71d90 Merge pull request #8 from whattokingu/queryStringFix
add comments to code
2016-02-04 13:28:29 +08:00
Zheng Weihan
c077357eff add comments to code 2016-02-04 13:27:36 +08:00
whattokingu
2f26a2bdb4 Merge pull request #7 from whattokingu/queryStringFix
add test for issue #331 on socket.io-client.
2016-01-31 15:45:35 +08:00
Zheng Weihan
13af610f6d add test for issue #331 on socket.io-client. 2016-01-31 15:44:39 +08:00
whattokingu
abcedf53ec Merge pull request #6 from whattokingu/queryStringFix
sync to master branch
2016-01-31 11:23:02 +08:00
Zheng Weihan
24456fdcbe Merge branch 'master' into queryStringFix
* master:
  Release 1.4.5
  package: bump `engine.io`
  add a test for graceful shutdown
2016-01-31 11:21:30 +08:00
Pedro Narciso García Revington
25116ab179 test node 5 (stable) 2016-01-30 21:53:04 +01:00
Zhu Liang
a116d52e30 updated express version to express 4 2016-01-30 11:57:31 +08:00
whattokingu
cecf5f127e Merge pull request #5 from whattokingu/documentation
Added Documentation
2016-01-30 11:31:11 +08:00
Zheng Weihan
1c467e15e6 Issue #2400, added documentation 2016-01-30 11:28:40 +08:00
whattokingu
a110542563 Merge pull request #4 from whattokingu/queryStringFix
Fix for Issue #331 on socket.io-client
2016-01-30 10:16:19 +08:00
Zheng Weihan
7d55724468 refactor parsing of URL in CONNECT packet to use 'url' library. 2016-01-30 09:47:28 +08:00
Zheng Weihan
1d84c55743 fix to issue #331 on socket.o-client.
Parses CONNECT packet for query string and replaces query in socket.handshake.
2016-01-28 14:40:05 +08:00
14 changed files with 280 additions and 73 deletions

3
.gitignore vendored
View File

@@ -9,4 +9,5 @@ lib-cov
benchmarks/*.png
node_modules
coverage
.idea
.idea
dist

View File

@@ -1,4 +0,0 @@
support
test
examples
.gitignore

View File

@@ -3,14 +3,22 @@ before_install:
- npm install -g npm@'>=1.4.3'
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.12"
- "4"
- "node"
git:
depth: 1
matrix:
include:
- node_js: '0.10'
env: TEST_VERSION=compat
- node_js: '0.12'
env: TEST_VERSION=compat
- node_js: '4'
env: TEST_VERSION=compat
#matrix:
#fast_finish: true
#allow_failures:

View File

@@ -1,4 +1,20 @@
1.5.0 / 2016-10-06
==================
* [feature] stop append /# before id when no namespace (#2508)
* [feature] Add a 'disconnecting' event to access to socket.rooms upon disconnection (#2332)
* [fix] Fix query string management (#2422)
* [fix] add quote to exec paths, prevent error when spaces in path (#2508)
* [docs] Prevent mixup for new programmers (#2599)
* [example] Fix chat display in Firefox (#2477)
* [chore] Add gulp & babel in the build process (#2471)
* [chore] Bump engine.io to 1.7.0 (#2707)
* [chore] Remove unused zuul-ngrok dependency (#2708)
* [chore] Point towards current master of socket.io-client (#2710)
* [chore] Restrict files included in npm package (#2709)
* [chore] Link build badge to master branch (#2549)
1.4.8 / 2016-06-23
==================

View File

@@ -1,15 +1,8 @@
REPORTER = dot
test:
@./node_modules/.bin/mocha \
--reporter $(REPORTER) \
--slow 200ms \
--bail
@./node_modules/.bin/gulp test
test-cov:
@./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \
--reporter $(REPORTER) \
test/
@./node_modules/.bin/gulp test-cov
.PHONY: test

View File

@@ -1,7 +1,7 @@
# socket.io
[![Build Status](https://secure.travis-ci.org/socketio/socket.io.svg)](https://travis-ci.org/socketio/socket.io)
[![Build Status](https://secure.travis-ci.org/socketio/socket.io.svg?branch=master)](https://travis-ci.org/socketio/socket.io)
[![Dependency Status](https://david-dm.org/socketio/socket.io.svg)](https://david-dm.org/socketio/socket.io)
[![devDependency Status](https://david-dm.org/socketio/socket.io/dev-status.svg)](https://david-dm.org/socketio/socket.io#info=devDependencies)
![NPM version](https://badge.fury.io/js/socket.io.svg)
@@ -16,9 +16,9 @@ HTTP server listening on port `3000`.
```js
var server = require('http').createServer();
var io = require('socket.io')(server);
io.on('connection', function(socket){
socket.on('event', function(data){});
socket.on('disconnect', function(){});
io.on('connection', function(client){
client.on('event', function(data){});
client.on('disconnect', function(){});
});
server.listen(3000);
```
@@ -27,7 +27,7 @@ server.listen(3000);
```js
var io = require('socket.io')();
io.on('connection', function(socket){});
io.on('connection', function(client){});
io.listen(3000);
```
@@ -200,7 +200,7 @@ server.listen(3000);
### Server#close
Closes socket server
Closes socket.io server
```js
var Server = require('socket.io');
@@ -300,10 +300,13 @@ server.listen(3000);
A `Socket` is the fundamental class for interacting with browser
clients. A `Socket` belongs to a certain `Namespace` (by default `/`)
and uses an underlying `Client` to communicate.
It should be noted the `Socket` doesn't relate directly to the actual
underlying TCP/IP `socket` and it is only the name of the class.
### Socket#rooms:Object
A hash of strings identifying the rooms this socket is in, indexed by
A hash of strings identifying the rooms this client is in, indexed by
room name.
### Socket#client:Client
@@ -313,7 +316,8 @@ server.listen(3000);
### Socket#conn:Socket
A reference to the underlying `Client` transport connection (engine.io
`Socket` object).
`Socket` object). This allows access to the IO transport layer, which
still (mostly) asbtracts the actual TCP/IP socket.
### Socket#request:Request
@@ -323,30 +327,30 @@ server.listen(3000);
### Socket#id:String
A unique identifier for the socket session, that comes from the
A unique identifier for the session, that comes from the
underlying `Client`.
### Socket#emit(name:String[, …]):Socket
Emits an event to the socket identified by the string `name`. Any
other parameters can be included.
Emits an event identified by the string `name` to the client.
Any other parameters can be included.
All datastructures are supported, including `Buffer`. JavaScript
functions can't be serialized/deserialized.
```js
var io = require('socket.io')();
io.on('connection', function(socket){
socket.emit('an event', { some: 'data' });
io.on('connection', function(client){
client.emit('an event', { some: 'data' });
});
```
### Socket#join(name:String[, fn:Function]):Socket
Adds the socket to the `room`, and fires optionally a callback `fn`
Adds the client to the `room`, and fires optionally a callback `fn`
with `err` signature (if any).
The socket is automatically a member of a room identified with its
The client is automatically a member of a room identified with its
session id (see `Socket#id`).
The mechanics of joining rooms are handled by the `Adapter`
@@ -355,7 +359,7 @@ server.listen(3000);
### Socket#leave(name:String[, fn:Function]):Socket
Removes the socket from `room`, and fires optionally a callback `fn`
Removes the client from `room`, and fires optionally a callback `fn`
with `err` signature (if any).
**Rooms are left automatically upon disconnection**.
@@ -367,14 +371,14 @@ server.listen(3000);
### Socket#to(room:String):Socket
Sets a modifier for a subsequent event emission that the event will
only be _broadcasted_ to sockets that have joined the given `room`.
only be _broadcasted_ to clients that have joined the given `room`.
To emit to multiple rooms, you can call `to` several times.
```js
var io = require('socket.io')();
io.on('connection', function(socket){
socket.to('others').emit('an event', { some: 'data' });
io.on('connection', function(client){
client.to('others').emit('an event', { some: 'data' });
});
```
@@ -389,10 +393,33 @@ server.listen(3000);
```js
var io = require('socket.io')();
io.on('connection', function(socket){
socket.compress(false).emit('an event', { some: 'data' });
io.on('connection', function(client){
client.compress(false).emit('an event', { some: 'data' });
});
```
### Socket#disconnect(close:Boolean):Socket
Disconnects this client. If value of close is `true`, closes the underlying connection.
Otherwise, it just disconnects the namespace.
#### Events
- `disconnect`
- Fired upon disconnection.
- **Arguments**
- `String`: the reason of the disconnection (either client or server-side)
- `error`
- Fired when an error occurs.
- **Arguments**
- `Object`: error data
- `disconnecting`
- Fired when the client is going to be disconnected (but hasn't left its `rooms` yet).
- **Arguments**
- `String`: the reason of the disconnection (either client or server-side)
These are reserved events (along with `connect`, `newListener` and `removeListener`) which cannot be used as event names.
### Client
@@ -422,6 +449,17 @@ To see the output from all of Socket.IO's debugging scopes you can use:
DEBUG=socket.io* node myapp
```
## Testing
```
npm test
```
This runs the `gulp` task `test`. By default the test will be run with the source code in `lib` directory.
Set the environmental variable `TEST_VERSION` to `compat` to test the transpiled es5-compat version of the code.
The `gulp` task `test` will always transpile the source code into es5 and export to `dist` first before running the test.
## License
MIT

View File

@@ -7,6 +7,6 @@
"private": true,
"license": "BSD",
"dependencies": {
"express": "3.4.8"
"express": "4.13.4"
}
}
}

View File

@@ -128,7 +128,6 @@ ul {
}
.username {
float: left;
font-weight: 700;
overflow: hidden;
padding-right: 15px;

69
gulpfile.js Normal file
View File

@@ -0,0 +1,69 @@
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const babel = require("gulp-babel");
const istanbul = require('gulp-istanbul');
const help = require('gulp-task-listing');
const del = require('del');
gulp.task('help', help);
gulp.task('default', ['transpile']);
const TRANSPILE_DEST_DIR = './dist';
// By default, individual js files are transformed by babel and exported to /dist
gulp.task('transpile', function () {
return gulp.src("lib/*.js")
.pipe(babel({ "presets": ["es2015"] }))
.pipe(gulp.dest(TRANSPILE_DEST_DIR));
});
gulp.task('clean', function () {
return del([TRANSPILE_DEST_DIR]);
})
gulp.task('test', ['transpile'], function(){
return gulp.src('test/socket.io.js', {read: false})
.pipe(mocha({
slow: 200,
reporter: 'spec',
bail: true,
timeout: 10000
}))
.once('error', function (err) {
console.error(err.stack);
process.exit(1);
})
.once('end', function () {
process.exit();
});
});
gulp.task('set-compat-node-env', function() {
process.env.TEST_VERSION = 'compat';
});
gulp.task('test-compat', ['set-compat-node-env', 'test']);
gulp.task('istanbul-pre-test', function () {
return gulp.src(['lib/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('test-cov', ['istanbul-pre-test'], function(){
return gulp.src('test/socket.io.js', {read: false})
.pipe(mocha({
reporter: 'dot'
}))
.pipe(istanbul.writeReports())
.once('error', function (err){
console.error(err.stack);
process.exit(1);
})
.once('end', function (){
process.exit();
});
});

View File

@@ -5,6 +5,7 @@
var parser = require('socket.io-parser');
var debug = require('debug')('socket.io:client');
var url = require('url');
/**
* Module exports.
@@ -58,7 +59,7 @@ Client.prototype.setup = function(){
* @api private
*/
Client.prototype.connect = function(name){
Client.prototype.connect = function(name, query){
debug('connecting to namespace %s', name);
var nsp = this.server.nsps[name];
if (!nsp) {
@@ -72,7 +73,7 @@ Client.prototype.connect = function(name){
}
var self = this;
var socket = nsp.add(this, function(){
var socket = nsp.add(this, query, function(){
self.sockets[socket.id] = socket;
self.nsps[nsp.name] = socket;
@@ -186,7 +187,7 @@ Client.prototype.ondata = function(data){
Client.prototype.ondecoded = function(packet) {
if (parser.CONNECT == packet.type) {
this.connect(packet.nsp);
this.connect(url.parse(packet.nsp).pathname, url.parse(packet.nsp, true).query);
} else {
var socket = this.nsps[packet.nsp];
if (socket) {

View File

@@ -150,9 +150,9 @@ Namespace.prototype['in'] = function(name){
* @api private
*/
Namespace.prototype.add = function(client, fn){
Namespace.prototype.add = function(client, query, fn){
debug('adding socket to nsp %s', this.name);
var socket = new Socket(this, client);
var socket = new Socket(this, client, query);
var self = this;
this.run(socket, function(err){
process.nextTick(function(){

View File

@@ -25,6 +25,7 @@ exports.events = [
'error',
'connect',
'disconnect',
'disconnecting',
'newListener',
'removeListener'
];
@@ -55,18 +56,18 @@ var emit = Emitter.prototype.emit;
* @api public
*/
function Socket(nsp, client){
function Socket(nsp, client, query){
this.nsp = nsp;
this.server = nsp.server;
this.adapter = this.nsp.adapter;
this.id = nsp.name + '#' + client.id;
this.id = nsp.name !== '/' ? nsp.name + '#' + client.id : client.id;
this.client = client;
this.conn = client.conn;
this.rooms = {};
this.acks = {};
this.connected = true;
this.disconnected = false;
this.handshake = this.buildHandshake();
this.handshake = this.buildHandshake(query);
}
/**
@@ -103,7 +104,19 @@ Socket.prototype.__defineGetter__('request', function(){
* @api private
*/
Socket.prototype.buildHandshake = function(){
Socket.prototype.buildHandshake = function(query){
var self = this;
function buildQuery(){
var requestQuery = url.parse(self.request.url, true).query;
//if socket-specific query exist, replace query strings in requestQuery
if(query){
query.t = requestQuery.t;
query.EIO = requestQuery.EIO;
query.transport = requestQuery.transport;
return query;
}
return requestQuery || {};
}
return {
headers: this.request.headers,
time: (new Date) + '',
@@ -112,7 +125,7 @@ Socket.prototype.buildHandshake = function(){
secure: !!this.request.connection.encrypted,
issued: +(new Date),
url: this.request.url,
query: url.parse(this.request.url, true).query || {}
query: buildQuery()
};
};
@@ -416,6 +429,7 @@ Socket.prototype.onerror = function(err){
Socket.prototype.onclose = function(reason){
if (!this.connected) return this;
debug('closing socket - reason %s', reason);
this.emit('disconnecting', reason);
this.leaveAll();
this.nsp.remove(this);
this.client.remove(this);

View File

@@ -1,6 +1,6 @@
{
"name": "socket.io",
"version": "1.4.8",
"version": "1.5.0",
"description": "node.js realtime framework server",
"keywords": [
"realtime",
@@ -12,29 +12,38 @@
"io"
],
"main": "./lib/index",
"files": [
"lib/"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/Automattic/socket.io"
"url": "git://github.com/socketio/socket.io"
},
"scripts": {
"test": "mocha --reporter dot --slow 200ms --bail"
"test": "gulp test"
},
"dependencies": {
"engine.io": "1.6.11",
"engine.io": "1.7.0",
"socket.io-parser": "2.2.6",
"socket.io-client": "1.4.8",
"socket.io-client": "1.5.0",
"socket.io-adapter": "0.4.0",
"has-binary": "0.1.7",
"debug": "2.2.0"
},
"devDependencies": {
"babel-preset-es2015": "6.3.13",
"del": "2.2.0",
"expect.js": "0.3.1",
"gulp": "3.9.0",
"gulp-babel": "6.1.1",
"gulp-istanbul": "0.10.3",
"gulp-mocha": "2.2.0",
"gulp-task-listing": "1.0.1",
"istanbul": "0.4.1",
"mocha": "2.3.4",
"superagent": "1.6.1",
"supertest": "1.1.0",
"zuul-ngrok": "3.2.0"
"supertest": "1.1.0"
},
"contributors": [
{

View File

@@ -1,6 +1,12 @@
var testVersion = process.env.TEST_VERSION;
var http = require('http').Server;
var io = require('..');
var io;
if (testVersion === 'compat') {
console.log('testing compat version');
io = require('../dist');
} else {
io = require('../lib');
}
var fs = require('fs');
var join = require('path').join;
var exec = require('child_process').exec;
@@ -415,8 +421,8 @@ describe('socket.io', function(){
describe('graceful close', function(){
function fixture(filename) {
return process.execPath + ' ' +
join(__dirname, 'fixtures', filename);
return '"' + process.execPath + '" "' +
join(__dirname, 'fixtures', filename) + '"';
}
it('should stop socket and timers', function(done){
@@ -426,9 +432,18 @@ describe('socket.io', function(){
});
describe('namespaces', function(){
var Socket = require('../lib/socket');
var Namespace = require('../lib/namespace');
var Socket;
if (testVersion === 'compat') {
Socket = require('../dist/socket');
} else {
Socket = require('../lib/socket');
}
var Namespace;
if (testVersion === 'compat') {
Namespace = require('../dist/namespace');
} else {
Namespace = require('../lib/namespace');
}
it('should be accessible through .sockets', function(){
var sio = io();
expect(sio.sockets).to.be.a(Namespace);
@@ -629,6 +644,31 @@ describe('socket.io', function(){
});
});
it('should fire a `disconnecting` event just before leaving all 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(){
s.disconnect();
});
var total = 2;
s.on('disconnecting', function(reason){
expect(Object.keys(s.rooms)).to.eql([s.id, 'a']);
total--;
});
s.on('disconnect', function(reason){
expect(Object.keys(s.rooms)).to.eql([]);
--total || done();
});
});
});
});
it('should return error connecting to non-existent namespace', function(done){
var srv = http();
var sio = io(srv);
@@ -651,7 +691,7 @@ describe('socket.io', function(){
var clientSocket2 = client(srv);
sio.on('connection', function() {
connections++;
if(connections === 2) {
if (connections === 2) {
done();
}
});
@@ -785,7 +825,7 @@ describe('socket.io', function(){
setTimeout(function() {
sio.of('/chat').emit('ev', 'data');
sio.of('/chat').volatile.emit('ev', 'data');
}, 20);
}, 50);
});
var socket = client(srv, '/chat');
@@ -797,7 +837,7 @@ describe('socket.io', function(){
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
}, 500);
});
it('should emit volatile event', function(done) {
@@ -810,7 +850,7 @@ describe('socket.io', function(){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
sio.of('/chat').volatile.emit('ev', 'data');
}, 20);
}, 100);
});
var socket = client(srv, '/chat');
@@ -822,7 +862,7 @@ describe('socket.io', function(){
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
}, 500);
});
it('should enable compression by default', function(done){
@@ -1139,7 +1179,7 @@ describe('socket.io', function(){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
}, 20);
}, 100);
});
var socket = client(srv, { transports: ['polling'] });
@@ -1151,7 +1191,7 @@ describe('socket.io', function(){
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
}, 500);
});
it('should emit volatile event (ws)', function(done) {
@@ -1190,7 +1230,7 @@ describe('socket.io', function(){
setTimeout(function() {
s.volatile.emit('ev', 'data');
s.volatile.emit('ev', 'data');
}, 20);
}, 100);
});
var socket = client(srv, { transports: ['polling'] });
@@ -1202,7 +1242,7 @@ describe('socket.io', function(){
setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
}, 500);
});
it('should emit only one consecutive volatile event (ws)', function(done) {
@@ -1518,6 +1558,24 @@ describe('socket.io', function(){
});
});
});
it('should see query parameters sent from secondary namespace connections in handshake object', function(done){
var srv = http();
var sio = io(srv);
var addr = srv.listen().address();
var url = 'ws://localhost:' + addr.port;
var client1 = ioc(url);
var client2 = ioc(url + '/connection2', {query: {key1: 'aa', key2: '&=bb'}});
sio.on('connection', function(s){
});
sio.of('/connection2').on('connection', function(s){
expect(s.handshake.query.key1).to.be('aa');
expect(s.handshake.query.key2).to.be('&=bb');
done();
});
});
it('should handle very large json', function(done){
this.timeout(30000);
@@ -2036,7 +2094,12 @@ describe('socket.io', function(){
});
describe('middleware', function(done){
var Socket = require('../lib/socket');
var Socket;
if (testVersion === 'compat') {
Socket = require('../dist/socket');
} else {
Socket = require('../lib/socket');
}
it('should call functions', function(done){
var srv = http();