socket.io
Advanced tools
Comparing version 1.4.8 to 1.5.0
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 | ||
@@ -3,0 +19,0 @@ ================== |
@@ -8,2 +8,3 @@ | ||
var debug = require('debug')('socket.io:client'); | ||
var url = require('url'); | ||
@@ -62,3 +63,3 @@ /** | ||
Client.prototype.connect = function(name){ | ||
Client.prototype.connect = function(name, query){ | ||
debug('connecting to namespace %s', name); | ||
@@ -77,3 +78,3 @@ var nsp = this.server.nsps[name]; | ||
var self = this; | ||
var socket = nsp.add(this, function(){ | ||
var socket = nsp.add(this, query, function(){ | ||
self.sockets[socket.id] = socket; | ||
@@ -192,3 +193,3 @@ self.nsps[nsp.name] = socket; | ||
if (parser.CONNECT == packet.type) { | ||
this.connect(packet.nsp); | ||
this.connect(url.parse(packet.nsp).pathname, url.parse(packet.nsp, true).query); | ||
} else { | ||
@@ -195,0 +196,0 @@ var socket = this.nsps[packet.nsp]; |
@@ -153,5 +153,5 @@ | ||
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; | ||
@@ -158,0 +158,0 @@ this.run(socket, function(err){ |
@@ -28,2 +28,3 @@ | ||
'disconnect', | ||
'disconnecting', | ||
'newListener', | ||
@@ -59,7 +60,7 @@ 'removeListener' | ||
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; | ||
@@ -71,3 +72,3 @@ this.conn = client.conn; | ||
this.disconnected = false; | ||
this.handshake = this.buildHandshake(); | ||
this.handshake = this.buildHandshake(query); | ||
} | ||
@@ -109,3 +110,15 @@ | ||
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 { | ||
@@ -119,3 +132,3 @@ headers: this.request.headers, | ||
url: this.request.url, | ||
query: url.parse(this.request.url, true).query || {} | ||
query: buildQuery() | ||
}; | ||
@@ -424,2 +437,3 @@ }; | ||
debug('closing socket - reason %s', reason); | ||
this.emit('disconnecting', reason); | ||
this.leaveAll(); | ||
@@ -426,0 +440,0 @@ this.nsp.remove(this); |
{ | ||
"name": "socket.io", | ||
"version": "1.4.8", | ||
"version": "1.5.0", | ||
"description": "node.js realtime framework server", | ||
@@ -15,14 +15,17 @@ "keywords": [ | ||
"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", | ||
@@ -33,8 +36,14 @@ "has-binary": "0.1.7", | ||
"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" | ||
}, | ||
@@ -41,0 +50,0 @@ "contributors": [ |
# 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) | ||
@@ -19,5 +19,5 @@ [![devDependency Status](https://david-dm.org/socketio/socket.io/dev-status.svg)](https://david-dm.org/socketio/socket.io#info=devDependencies) | ||
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(){}); | ||
}); | ||
@@ -31,3 +31,3 @@ server.listen(3000); | ||
var io = require('socket.io')(); | ||
io.on('connection', function(socket){}); | ||
io.on('connection', function(client){}); | ||
io.listen(3000); | ||
@@ -205,3 +205,3 @@ ``` | ||
Closes socket server | ||
Closes socket.io server | ||
@@ -306,6 +306,9 @@ ```js | ||
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. | ||
@@ -320,3 +323,4 @@ | ||
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. | ||
@@ -331,3 +335,3 @@ ### Socket#request:Request | ||
A unique identifier for the socket session, that comes from the | ||
A unique identifier for the session, that comes from the | ||
underlying `Client`. | ||
@@ -337,4 +341,4 @@ | ||
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. | ||
@@ -346,4 +350,4 @@ All datastructures are supported, including `Buffer`. JavaScript | ||
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' }); | ||
}); | ||
@@ -354,6 +358,6 @@ ``` | ||
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`). | ||
@@ -367,3 +371,3 @@ | ||
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). | ||
@@ -380,3 +384,3 @@ | ||
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`. | ||
@@ -387,4 +391,4 @@ To emit to multiple rooms, you can call `to` several times. | ||
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' }); | ||
}); | ||
@@ -404,7 +408,30 @@ ``` | ||
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 | ||
@@ -438,4 +465,15 @@ | ||
## 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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63457
1182
466
12
8
2
+ Addedaccepts@1.3.3(transitive)
+ Addedbase64-arraybuffer@0.1.5(transitive)
+ Addedengine.io@1.7.0(transitive)
+ Addedengine.io-client@1.7.0(transitive)
+ Addedengine.io-parser@1.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednegotiator@0.6.1(transitive)
+ Addedsocket.io-client@1.5.0(transitive)
+ Addedws@1.1.1(transitive)
+ Addedwtf-8@1.0.0(transitive)
- Removedaccepts@1.1.4(transitive)
- Removedbase64-arraybuffer@0.1.2(transitive)
- Removedengine.io@1.6.11(transitive)
- Removedengine.io-client@1.6.11(transitive)
- Removedengine.io-parser@1.2.4(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
- Removednegotiator@0.4.9(transitive)
- Removedsocket.io-client@1.4.8(transitive)
- Removedutf8@2.1.0(transitive)
- Removedws@1.0.11.1.0(transitive)
Updatedengine.io@1.7.0
Updatedsocket.io-client@1.5.0