mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-12 00:17:56 -05:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f59e4526a | ||
|
|
0a7afa85ea | ||
|
|
1e31769062 | ||
|
|
797c9a3498 | ||
|
|
4f93a0b429 | ||
|
|
3c98130f15 | ||
|
|
9c23308c6e | ||
|
|
955e5e0d91 | ||
|
|
0ef55b26d4 | ||
|
|
4d8e2d342c | ||
|
|
d48f848bb4 |
19
History.md
19
History.md
@@ -1,4 +1,23 @@
|
||||
|
||||
1.7.2 / 2016-12-11
|
||||
===================
|
||||
|
||||
* [chore] Bump engine.io to version 1.8.2 (#2782)
|
||||
* [fix] Fixes socket.use error packet (#2772)
|
||||
|
||||
1.7.1 / 2016-11-28
|
||||
===================
|
||||
|
||||
1.7.0 / 2016-11-27
|
||||
===================
|
||||
|
||||
* [docs] Comment connected socket availability for adapters (#2081)
|
||||
* [docs] Fixed grammar issues in the README.md (#2159)
|
||||
* [feature] serve sourcemap for socket.io-client (#2482)
|
||||
* [feature] Add a `local` flag (#2628)
|
||||
* [chore] Bump engine.io to version 1.8.1 (#2765)
|
||||
* [chore] Update client location and serve minified file (#2766)
|
||||
|
||||
1.6.0 / 2016-11-20
|
||||
==================
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ server.listen(3000);
|
||||
__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/expressjs/cors)
|
||||
* 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/expressjs/cors).
|
||||
|
||||
|
||||
### Server#sockets:Namespace
|
||||
@@ -183,7 +183,7 @@ server.listen(3000);
|
||||
Initializes and retrieves the given `Namespace` by its pathname
|
||||
identifier `nsp`.
|
||||
|
||||
If the namespace was already initialized it returns it right away.
|
||||
If the namespace was already initialized it returns it immediately.
|
||||
|
||||
### Server#emit
|
||||
|
||||
@@ -285,7 +285,7 @@ server.listen(3000);
|
||||
### Namespace#use(fn:Function):Namespace
|
||||
|
||||
Registers a middleware, which is a function that gets executed for
|
||||
every incoming `Socket` and receives as parameter the socket and a
|
||||
every incoming `Socket`, and receives as parameters the socket and a
|
||||
function to optionally defer execution to the next registered
|
||||
middleware.
|
||||
|
||||
@@ -448,7 +448,7 @@ These are reserved events (along with `connect`, `newListener` and `removeListen
|
||||
### Client
|
||||
|
||||
The `Client` class represents an incoming transport (engine.io)
|
||||
connection. A `Client` can be associated with many multiplexed `Socket`
|
||||
connection. A `Client` can be associated with many multiplexed `Socket`s
|
||||
that belong to different `Namespace`s.
|
||||
|
||||
### Client#conn
|
||||
|
||||
44
lib/index.js
44
lib/index.js
@@ -26,6 +26,7 @@ module.exports = Server;
|
||||
*/
|
||||
|
||||
var clientSource = undefined;
|
||||
var clientSourceMap = undefined;
|
||||
|
||||
/**
|
||||
* Server constructor.
|
||||
@@ -97,7 +98,12 @@ Server.prototype.serveClient = function(v){
|
||||
this._serveClient = v;
|
||||
|
||||
if (v && !clientSource) {
|
||||
clientSource = read(require.resolve('socket.io-client/socket.io.js'), 'utf-8');
|
||||
clientSource = read(require.resolve('socket.io-client/dist/socket.io.min.js'), 'utf-8');
|
||||
try {
|
||||
clientSourceMap = read(require.resolve('socket.io-client/dist/socket.io.js.map'), 'utf-8');
|
||||
} catch(err) {
|
||||
debug('could not load sourcemap file');
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -255,11 +261,14 @@ Server.prototype.attach = function(srv, opts){
|
||||
Server.prototype.attachServe = function(srv){
|
||||
debug('attaching client serving req handler');
|
||||
var url = this._path + '/socket.io.js';
|
||||
var urlMap = this._path + '/socket.io.js.map';
|
||||
var evs = srv.listeners('request').slice(0);
|
||||
var self = this;
|
||||
srv.removeAllListeners('request');
|
||||
srv.on('request', function(req, res) {
|
||||
if (0 === req.url.indexOf(url)) {
|
||||
if (0 === req.url.indexOf(urlMap)) {
|
||||
self.serveMap(req, res);
|
||||
} else if (0 === req.url.indexOf(url)) {
|
||||
self.serve(req, res);
|
||||
} else {
|
||||
for (var i = 0; i < evs.length; i++) {
|
||||
@@ -295,10 +304,41 @@ Server.prototype.serve = function(req, res){
|
||||
debug('serve client source');
|
||||
res.setHeader('Content-Type', 'application/javascript');
|
||||
res.setHeader('ETag', expectedEtag);
|
||||
res.setHeader('X-SourceMap', 'socket.io.js.map');
|
||||
res.writeHead(200);
|
||||
res.end(clientSource);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles a request serving `/socket.io.js.map`
|
||||
*
|
||||
* @param {http.Request} req
|
||||
* @param {http.Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Server.prototype.serveMap = function(req, res){
|
||||
// Per the standard, ETags must be quoted:
|
||||
// https://tools.ietf.org/html/rfc7232#section-2.3
|
||||
var expectedEtag = '"' + clientVersion + '"';
|
||||
|
||||
var etag = req.headers['if-none-match'];
|
||||
if (etag) {
|
||||
if (expectedEtag == etag) {
|
||||
debug('serve client 304');
|
||||
res.writeHead(304);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
debug('serve client sourcemap');
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('ETag', expectedEtag);
|
||||
res.writeHead(200);
|
||||
res.end(clientSourceMap);
|
||||
};
|
||||
|
||||
/**
|
||||
* Binds socket.io to an engine.io instance.
|
||||
*
|
||||
|
||||
@@ -31,7 +31,8 @@ exports.events = [
|
||||
|
||||
exports.flags = [
|
||||
'json',
|
||||
'volatile'
|
||||
'volatile',
|
||||
'local'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -283,6 +283,8 @@ Socket.prototype.leaveAll = function(){
|
||||
/**
|
||||
* Called by `Namespace` upon successful
|
||||
* middleware execution (ie: authorization).
|
||||
* Socket is added to namespace array before
|
||||
* call to join, so adapters can access it.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
@@ -496,7 +498,7 @@ Socket.prototype.dispatch = function(event){
|
||||
this.run(event, function(err){
|
||||
process.nextTick(function(){
|
||||
if (err) {
|
||||
return self.emit('error', err.data || err.message);
|
||||
return self.error(err.data || err.message);
|
||||
}
|
||||
emit.apply(self, event);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "socket.io",
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.2",
|
||||
"description": "node.js realtime framework server",
|
||||
"keywords": [
|
||||
"realtime",
|
||||
@@ -25,11 +25,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "2.3.3",
|
||||
"engine.io": "1.8.0",
|
||||
"engine.io": "1.8.2",
|
||||
"has-binary": "0.1.7",
|
||||
"object-assign": "4.1.0",
|
||||
"socket.io-adapter": "0.5.0",
|
||||
"socket.io-client": "1.6.0",
|
||||
"socket.io-client": "1.7.2",
|
||||
"socket.io-parser": "2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -2273,9 +2273,14 @@ describe('socket.io', function(){
|
||||
var sio = io(srv);
|
||||
|
||||
srv.listen(function(){
|
||||
var socket = client(srv, { multiplex: false });
|
||||
var clientSocket = client(srv, { multiplex: false });
|
||||
|
||||
socket.emit('join', 'woot');
|
||||
clientSocket.emit('join', 'woot');
|
||||
|
||||
clientSocket.on('error', function(err){
|
||||
expect(err).to.be('Authentication error');
|
||||
done();
|
||||
});
|
||||
|
||||
sio.on('connection', function(socket){
|
||||
socket.use(function(event, next){
|
||||
@@ -2288,10 +2293,6 @@ describe('socket.io', function(){
|
||||
socket.on('join', function(){
|
||||
done(new Error('nope'));
|
||||
});
|
||||
socket.on('error', function(err){
|
||||
expect(err).to.be('Authentication error');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2301,9 +2302,14 @@ describe('socket.io', function(){
|
||||
var sio = io(srv);
|
||||
|
||||
srv.listen(function(){
|
||||
var socket = client(srv, { multiplex: false });
|
||||
var clientSocket = client(srv, { multiplex: false });
|
||||
|
||||
socket.emit('join', 'woot');
|
||||
clientSocket.emit('join', 'woot');
|
||||
|
||||
clientSocket.on('error', function(err){
|
||||
expect(err).to.eql({ a: 'b', c: 3 });
|
||||
done();
|
||||
});
|
||||
|
||||
sio.on('connection', function(socket){
|
||||
socket.use(function(event, next){
|
||||
@@ -2315,10 +2321,6 @@ describe('socket.io', function(){
|
||||
socket.on('join', function(){
|
||||
done(new Error('nope'));
|
||||
});
|
||||
socket.on('error', function(err){
|
||||
expect(err).to.eql({ a: 'b', c: 3 });
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user