Socket
Socket
Sign inDemoInstall

engine.io

Package Overview
Dependencies
4
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.9 to 0.3.10

20

examples/latency/public/engine.io-dev.js

@@ -123,2 +123,3 @@ (function(){var global = this;

if (window.localStorage) debug.enable(localStorage.debug);function require(p, parent){ var path = require.resolve(p) , mod = require.modules[path]; if (!mod) throw new Error('failed to require "' + p + '" from ' + parent); if (!mod.exports) { mod.exports = {}; mod.call(mod.exports, mod, mod.exports, require.relative(path), global); } return mod.exports;}require.modules = {};require.resolve = function(path){ var orig = path , reg = path + '.js' , index = path + '/index.js'; return require.modules[reg] && reg || require.modules[index] && index || orig;};require.register = function(path, fn){ require.modules[path] = fn;};require.relative = function(parent) { return function(p){ if ('debug' == p) return debug; if ('.' != p.charAt(0)) return require(p); var path = parent.split('/') , segs = p.split('/'); path.pop(); for (var i = 0; i < segs.length; i++) { var seg = segs[i]; if ('..' == seg) path.pop(); else if ('.' != seg) path.push(seg); } return require(path.join('/'), parent); };};require.register("engine.io-client.js", function(module, exports, require, global){
/**

@@ -130,3 +131,3 @@ * Client version.

exports.version = '0.3.8pre';
exports.version = '0.3.8';

@@ -568,3 +569,3 @@ /**

opts.secure = uri.protocol == 'https' || uri.protocol == 'wss';
opts.port = uri.port || (opts.secure ? 443 : 80);
opts.port = uri.port;
}

@@ -574,3 +575,3 @@

this.secure = null != opts.secure ? opts.secure : (global.location && 'https:' == location.protocol);
this.host = opts.host || opts.hostname || (global.location ? location.host : 'localhost');
this.host = opts.host || opts.hostname || (global.location ? location.hostname : 'localhost');
this.port = opts.port || (global.location && location.port ? location.port : (this.secure ? 443 : 80));

@@ -592,2 +593,5 @@ this.query = opts.query || {};

this.open();
Socket.sockets.push(this);
Socket.sockets.evs.emit('add', this);
};

@@ -602,2 +606,9 @@

/**
* Static EventEmitter.
*/
Socket.sockets = [];
Socket.sockets.evs = new EventEmitter;
/**
* Creates transport of the given type.

@@ -782,2 +793,4 @@ *

this.emit('packet', packet);
// Socket is live - any packet counts

@@ -908,2 +921,3 @@ this.emit('heartbeat');

var packet = { type: type, data: data };
this.emit('packetCreate', packet);
this.writeBuffer.push(packet);

@@ -910,0 +924,0 @@ this.flush();

0.3.10 / 2012-12-03
===================
* package: bumped `engine.io-client` with `close` fixes
* add packetCreate event [jxck]
* add packet event to socket [jxck]
* transport: remove `Connection` headers and let node handle it
* server: send validation failure reason to clients
* engine: invoking as a function causes attach
* socket: reset `writeBuffer` before send
0.3.9 / 2012-10-23

@@ -3,0 +14,0 @@ ==================

36

lib/engine.io.js

@@ -1,2 +0,1 @@

/**

@@ -7,3 +6,3 @@ * Module dependencies.

var http = require('http')
, debug = require('debug')('engine:core')
, debug = require('debug')('engine:core');

@@ -98,6 +97,6 @@ /**

exports.attach = function (server, options) {
var engine = new exports.Server(options)
, options = options || {}
, path = (options.path || '/engine.io').replace(/\/$/, '')
, resource = options.resource || 'default'
var engine = new exports.Server(options);
var options = options || {};
var path = (options.path || '/engine.io').replace(/\/$/, '');
var resource = options.resource || 'default';

@@ -112,4 +111,4 @@ // normalize path

// cache and clean up listeners
var listeners = server.listeners('request')
, oldListeners = []
var listeners = server.listeners('request');
var oldListeners = [];

@@ -149,4 +148,6 @@ // copy the references onto a new array for node >=0.7

if (~engine.transports.indexOf('flashsocket')
&& false !== options.policyFile) {
// flash policy file
var trns = engine.transports;
var policy = options.policyFile;
if (~trns.indexOf('flashsocket') && false !== policy) {
server.on('connection', function (socket) {

@@ -159,1 +160,16 @@ engine.handleSocket(socket);

};
/**
* Invoking the library as a function delegates to attach
*
* @param {http.Server} server
* @param {Object} options
* @return {Server} engine server
* @api public
*/
module.exports = function() {
return exports.attach.apply(this, arguments);
};
module.exports.__proto__ = exports;

@@ -49,2 +49,18 @@

/**
* Protocol errors mappings.
*/
Server.errors = {
UNKNOWN_TRANSPORT: 0,
UNKNOWN_SID: 1,
BAD_HANDSHAKE_METHOD: 2
};
Server.errorMessages = {
0: 'Transport unknown',
1: 'Session ID unknown',
2: 'Bad handshake method'
};
/**
* Inherits from EventEmitter.

@@ -88,3 +104,3 @@ */

debug('unknown transport "%s"', transport);
return false;
return Server.errors.UNKNOWN_TRANSPORT;
}

@@ -94,6 +110,8 @@

if (req.query.sid) {
return this.clients.hasOwnProperty(req.query.sid);
return this.clients.hasOwnProperty(req.query.sid) ||
Server.errors.UNKNOWN_SID;
} else {
// handshake is GET only
return 'GET' == req.method;
return 'GET' == req.method ||
Server.errors.BAD_HANDSHAKE_METHOD;
}

@@ -144,5 +162,9 @@

if (!this.verify(req)) {
res.writeHead(500);
res.end();
var code = this.verify(req);
if (code !== true) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
code: code,
message: Server.errorMessages[code]
}));
return this;

@@ -205,3 +227,3 @@ }

if (!this.verify(req)) {
if (this.verify(req) !== true) {
socket.end();

@@ -208,0 +230,0 @@ return;

@@ -79,2 +79,6 @@ /**

if ('open' == this.readyState) {
// export packet event
debug('packet');
this.emit('packet', packet);
// Reset ping timeout on any packet, incoming data is a good sign of

@@ -276,3 +280,11 @@ // other side's liveness

debug('sending packet "%s" (%s)', type, data);
this.writeBuffer.push({ type: type, data: data });
var packet = { type: type };
if (data) packet.data = data;
// exports packetCreate event
this.emit('packetCreate', packet);
this.writeBuffer.push(packet);
//add send callback to object

@@ -298,4 +310,5 @@ if (callback) {

this.server.emit('flush', this, this.writeBuffer);
this.transport.send(this.writeBuffer);
var wbuf = this.writeBuffer;
this.writeBuffer = [];
this.transport.send(wbuf);
this.emit('drain');

@@ -302,0 +315,0 @@ this.server.emit('drain', this);

@@ -72,7 +72,2 @@

// Keep-Alive is the default in HTTP 1.1
if ('1.1' != this.req.httpVersion) {
headers.Connection = 'Keep-Alive';
}
this.res.writeHead(200, this.headers(this.req, headers));

@@ -79,0 +74,0 @@ this.res.end(data);

@@ -44,7 +44,2 @@

// Keep-Alive is the default in HTTP 1.1
if ('1.1' != this.req.httpVersion) {
headers.Connection = 'Keep-Alive';
}
this.res.writeHead(200, this.headers(this.req, headers));

@@ -51,0 +46,0 @@ this.res.end(data);

{
"name": "engine.io"
, "version": "0.3.9"
, "version": "0.3.10"
, "description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server"

@@ -10,3 +10,3 @@ , "main": "./lib/engine.io"

{ "name": "Afshin Mehrabani", "web": "https://github.com/afshinm" },
{ "name": "Christoph Dorn", "web": "https://github.com/cadorn" }
{ "name": "Christoph Dorn", "web": "https://github.com/cadorn" }
]

@@ -16,3 +16,3 @@ , "dependencies": {

, "ws": "~0.4.21"
, "engine.io-client": "0.3.9"
, "engine.io-client": "0.3.10"
, "base64id": "0.1.0"

@@ -19,0 +19,0 @@ }

@@ -234,2 +234,12 @@ # Engine.IO: the realtime engine

- Called when the write buffer is drained
- `packet`
- Called when a socket reseived a packet (`message`, `ping`)
- **Arguments**
- `type`: packet type
- `data`: packet data (if type is message)
- `packetCreate`
- Called before a socket sends a packet (`message`, `pong`)
- **Arguments**
- `type`: packet type
- `data`: packet data (if type is message)

@@ -236,0 +246,0 @@ ##### Properties

@@ -52,3 +52,5 @@ /*global eio,listen,request,expect*/

request.get(uri, function (res) {
expect(res.status).to.be(500);
expect(res.status).to.be(400);
expect(res.body.code).to.be(0);
expect(res.body.message).to.be('Transport unknown');
server.once('close', done);

@@ -192,3 +194,5 @@ server.close();

request.get('http://localhost:%d/engine.io/default/'.s(port), function (res) {
expect(res.status).to.be(500);
expect(res.status).to.be(400);
expect(res.body.code).to.be(0);
expect(res.body.message).to.be('Transport unknown');
request.get('http://localhost:%d/test'.s(port), function (res) {

@@ -195,0 +199,0 @@ expect(res.status).to.be(200);

@@ -23,3 +23,5 @@ /*global eio,eioc,listen,request,expect*/

.end(function (res) {
expect(res.status).to.be(500);
expect(res.status).to.be(400);
expect(res.body.code).to.be(0);
expect(res.body.message).to.be('Transport unknown');
done();

@@ -36,3 +38,5 @@ });

.end(function (res) {
expect(res.status).to.be(500);
expect(res.status).to.be(400);
expect(res.body.code).to.be(0);
expect(res.body.message).to.be('Transport unknown');
done();

@@ -48,3 +52,5 @@ });

.end(function (res) {
expect(res.status).to.be(500);
expect(res.status).to.be(400);
expect(res.body.code).to.be(1);
expect(res.body.message).to.be('Session ID unknown');
done();

@@ -826,15 +832,11 @@ });

var socket = new eioc.Socket('ws://localhost:%d'.s(port));
var i = 0;
var ic = 0;
var j = 0;
var jc = 0;
var a = 0;
var b = 0;
var c = 0;
var all = 0;
engine.on('connection', function (conn) {
conn.send('b', function (transport) {
jc++;
});
conn.send('a', function (transport) {
ic++;
});
conn.send('a');
conn.send('b');
conn.send('c');
});

@@ -844,15 +846,14 @@

socket.on('message', function (msg) {
if (msg == 'a') {
i++;
} else if (msg == 'b') {
j++;
if (msg === 'a') a ++;
if (msg === 'b') b ++;
if (msg === 'c') c ++;
if(++all === 3) {
expect(a).to.be(1);
expect(b).to.be(1);
expect(c).to.be(1);
done();
}
});
});
setTimeout(function () {
expect(i).to.be(ic);
expect(j).to.be(jc);
done();
}, 100);
});

@@ -918,2 +919,62 @@ });

describe('packet', function() {
it('should emit when socket receives packet', function (done) {
var engine = listen({ allowUpgrades: false }, function (port) {
var socket = new eioc.Socket('ws://localhost:%d'.s(port));
engine.on('connection', function (conn) {
conn.on('packet', function (packet) {
expect(packet.type).to.be('message');
expect(packet.data).to.be('a');
done();
});
});
socket.on('open', function () {
socket.send('a');
});
});
});
it('should emit when receives ping', function (done) {
var engine = listen({ allowUpgrades: false, pingInterval: 4 }, function (port) {
var socket = new eioc.Socket('ws://localhost:%d'.s(port));
engine.on('connection', function (conn) {
conn.on('packet', function (packet) {
conn.close();
expect(packet.type).to.be('ping');
done();
});
});
});
});
});
describe('packetCreate', function() {
it('should emit before socket send message', function (done) {
var engine = listen({ allowUpgrades: false }, function (port) {
var socket = new eioc.Socket('ws://localhost:%d'.s(port));
engine.on('connection', function (conn) {
conn.on('packetCreate', function(packet) {
expect(packet.type).to.be('message');
expect(packet.data).to.be('a');
done();
});
conn.send('a');
});
});
});
it('should emit before send pong', function (done) {
var engine = listen({ allowUpgrades: false, pingInterval: 4 }, function (port) {
var socket = new eioc.Socket('ws://localhost:%d'.s(port));
engine.on('connection', function (conn) {
conn.on('packetCreate', function (packet) {
conn.close();
expect(packet.type).to.be('pong');
done();
});
});
});
});
});
describe('upgrade', function () {

@@ -920,0 +981,0 @@ it('should upgrade', function (done) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc