engine.io-client
Advanced tools
Comparing version 0.3.10 to 0.4.0
0.4.0 / 2012-12-09 | ||
================== | ||
* *: now based on `component(1)` | ||
* *: module now exports `Socket` | ||
* socket: export constructors, utils and `protocol` | ||
* *: implemented `emitter` component | ||
* *: removed browserbuild and preprocessor instructions | ||
0.3.10 / 2012-12-03 | ||
@@ -3,0 +12,0 @@ =================== |
@@ -7,4 +7,4 @@ /** | ||
, transports = require('./transports') | ||
, debug = require('debug')('engine-client:socket') | ||
, EventEmitter = require('./event-emitter'); | ||
, Emitter = require('./emitter') | ||
, debug = require('debug')('engine-client:socket'); | ||
@@ -18,2 +18,8 @@ /** | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* Socket constructor. | ||
@@ -25,3 +31,5 @@ * | ||
function Socket (opts) { | ||
function Socket(opts){ | ||
if (!(this instanceof Socket)) return new Socket(opts); | ||
if ('string' == typeof opts) { | ||
@@ -60,8 +68,16 @@ var uri = util.parseUri(opts); | ||
/** | ||
* Inherits from EventEmitter. | ||
* Mix in `Emitter`. | ||
*/ | ||
util.inherits(Socket, EventEmitter); | ||
Emitter(Socket.prototype); | ||
/** | ||
* Protocol version. | ||
* | ||
* @api public | ||
*/ | ||
Socket.protocol = 1; | ||
/** | ||
* Static EventEmitter. | ||
@@ -71,5 +87,17 @@ */ | ||
Socket.sockets = []; | ||
Socket.sockets.evs = new EventEmitter; | ||
Socket.sockets.evs = new Emitter; | ||
/** | ||
* Expose deps for legacy compatibility | ||
* and standalone browser access. | ||
*/ | ||
Socket.Socket = Socket; | ||
Socket.Transport = require('./transport'); | ||
Socket.Emitter = require('./emitter'); | ||
Socket.transports = require('./transports'); | ||
Socket.util = require('./util'); | ||
Socket.parser = require('./parser'); | ||
/** | ||
* Creates transport of the given type. | ||
@@ -76,0 +104,0 @@ * |
@@ -8,3 +8,3 @@ | ||
, parser = require('./parser') | ||
, EventEmitter = require('./event-emitter') | ||
, Emitter = require('./emitter'); | ||
@@ -36,6 +36,6 @@ /** | ||
/** | ||
* Inherits from EventEmitter. | ||
* Mix in `Emitter`. | ||
*/ | ||
util.inherits(Transport, EventEmitter); | ||
Emitter(Transport.prototype); | ||
@@ -95,3 +95,3 @@ /** | ||
Transport.prototype.send = function (packets) { | ||
Transport.prototype.send = function(packets){ | ||
if ('open' == this.readyState) { | ||
@@ -102,3 +102,3 @@ this.write(packets); | ||
} | ||
} | ||
}; | ||
@@ -105,0 +105,0 @@ /** |
@@ -7,3 +7,4 @@ | ||
var WS = require('./websocket') | ||
, util = require('../util'); | ||
, util = require('../util') | ||
, debug = require('debug')('engine.io-client:flashsocket'); | ||
@@ -62,5 +63,5 @@ /** | ||
function log (type) { | ||
return function () { | ||
return function(){ | ||
var str = Array.prototype.join.call(arguments, ' '); | ||
// debug: [websocketjs %s] %s, type, str | ||
debug('[websocketjs %s] %s', type, str); | ||
}; | ||
@@ -169,5 +170,5 @@ }; | ||
FlashWS.prototype.check = function () { | ||
// if node | ||
return false; | ||
// end | ||
if ('undefined' != typeof process) { | ||
return false; | ||
} | ||
@@ -220,3 +221,3 @@ if (typeof WebSocket != 'undefined' && !('__initialize' in WebSocket)) { | ||
// debug: loading "%s", path | ||
debug('loading "%s"', path); | ||
el.onload = el.onreadystatechange = function () { | ||
@@ -226,3 +227,3 @@ if (loaded || scripts[path]) return; | ||
if (!rs || 'loaded' == rs || 'complete' == rs) { | ||
// debug: loaded "%s", path | ||
debug('loaded "%s"', path); | ||
el.onload = el.onreadystatechange = null; | ||
@@ -229,0 +230,0 @@ loaded = true; |
@@ -21,2 +21,8 @@ | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* Polling transport polymorphic constructor. | ||
@@ -23,0 +29,0 @@ * Decides on xhr vs jsonp based on feature detection. |
@@ -16,2 +16,8 @@ | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* Cached regular expressions. | ||
@@ -18,0 +24,0 @@ */ |
@@ -6,4 +6,5 @@ /** | ||
var Polling = require('./polling') | ||
, EventEmitter = require('../event-emitter') | ||
, util = require('../util'); | ||
, util = require('../util') | ||
, Emitter = require('../emitter') | ||
, debug = require('debug')('engine.io-client:polling-xhr'); | ||
@@ -18,2 +19,8 @@ /** | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* Obfuscated key for Blue Coat. | ||
@@ -28,3 +35,3 @@ */ | ||
function empty () { } | ||
function empty(){} | ||
@@ -38,3 +45,3 @@ /** | ||
function XHR (opts) { | ||
function XHR(opts){ | ||
Polling.call(this, opts); | ||
@@ -60,5 +67,5 @@ | ||
XHR.prototype.doOpen = function () { | ||
XHR.prototype.doOpen = function(){ | ||
var self = this; | ||
util.defer(function () { | ||
util.defer(function(){ | ||
Polling.prototype.doOpen.call(self); | ||
@@ -75,3 +82,3 @@ }); | ||
XHR.prototype.request = function (opts) { | ||
XHR.prototype.request = function(opts){ | ||
opts = opts || {}; | ||
@@ -91,7 +98,7 @@ opts.uri = this.uri(); | ||
XHR.prototype.doWrite = function (data, fn) { | ||
XHR.prototype.doWrite = function(data, fn){ | ||
var req = this.request({ method: 'POST', data: data }); | ||
var self = this; | ||
req.on('success', fn); | ||
req.on('error', function (err) { | ||
req.on('error', function(err){ | ||
self.onError('xhr post error', err); | ||
@@ -108,10 +115,10 @@ }); | ||
XHR.prototype.doPoll = function () { | ||
// debug: xhr poll | ||
XHR.prototype.doPoll = function(){ | ||
debug('xhr poll'); | ||
var req = this.request(); | ||
var self = this; | ||
req.on('data', function (data) { | ||
req.on('data', function(data){ | ||
self.onData(data); | ||
}); | ||
req.on('error', function (err) { | ||
req.on('error', function(err){ | ||
self.onError('xhr poll error', err); | ||
@@ -129,3 +136,3 @@ }); | ||
function Request (opts) { | ||
function Request(opts){ | ||
this.method = opts.method || 'GET'; | ||
@@ -140,6 +147,6 @@ this.uri = opts.uri; | ||
/** | ||
* Inherits from Polling. | ||
* Mix in `Emitter`. | ||
*/ | ||
util.inherits(Request, EventEmitter); | ||
Emitter(Request.prototype); | ||
@@ -152,3 +159,3 @@ /** | ||
Request.prototype.create = function () { | ||
Request.prototype.create = function(){ | ||
var xhr = this.xhr = util.request(this.xd); | ||
@@ -172,6 +179,6 @@ var self = this; | ||
if (this.xd && global.XDomainRequest && xhr instanceof XDomainRequest) { | ||
xhr.onerror = function (e) { | ||
xhr.onerror = function(e){ | ||
self.onError(e); | ||
}; | ||
xhr.onload = function () { | ||
xhr.onload = function(){ | ||
self.onData(xhr.responseText); | ||
@@ -186,3 +193,3 @@ }; | ||
xhr.onreadystatechange = function () { | ||
xhr.onreadystatechange = function(){ | ||
var data; | ||
@@ -207,3 +214,3 @@ | ||
// debug: sending xhr with url %s | data %s, this.uri, this.data | ||
debug('sending xhr with url %s | data %s', this.uri, this.data); | ||
xhr.send(this.data); | ||
@@ -223,3 +230,3 @@ | ||
Request.prototype.onSuccess = function () { | ||
Request.prototype.onSuccess = function(){ | ||
this.emit('success'); | ||
@@ -235,3 +242,3 @@ this.cleanup(); | ||
Request.prototype.onData = function (data) { | ||
Request.prototype.onData = function(data){ | ||
this.emit('data', data); | ||
@@ -247,3 +254,3 @@ this.onSuccess(); | ||
Request.prototype.onError = function (err) { | ||
Request.prototype.onError = function(err){ | ||
this.emit('error', err); | ||
@@ -259,3 +266,3 @@ this.cleanup(); | ||
Request.prototype.cleanup = function () { | ||
Request.prototype.cleanup = function(){ | ||
// xmlhttprequest | ||
@@ -284,3 +291,3 @@ this.xhr.onreadystatechange = empty; | ||
Request.prototype.abort = function () { | ||
Request.prototype.abort = function(){ | ||
this.cleanup(); | ||
@@ -293,3 +300,3 @@ }; | ||
global.attachEvent('onunload', function () { | ||
global.attachEvent('onunload', function(){ | ||
for (var i in Request.requests) { | ||
@@ -296,0 +303,0 @@ if (Request.requests.hasOwnProperty(i)) { |
@@ -8,2 +8,3 @@ /** | ||
, parser = require('../parser') | ||
, debug = require('debug')('engine.io-client:polling'); | ||
@@ -17,2 +18,8 @@ /** | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* Polling interface. | ||
@@ -24,3 +31,3 @@ * | ||
function Polling (opts) { | ||
function Polling(opts){ | ||
Transport.call(this, opts); | ||
@@ -48,3 +55,3 @@ } | ||
Polling.prototype.doOpen = function () { | ||
Polling.prototype.doOpen = function(){ | ||
this.poll(); | ||
@@ -60,10 +67,10 @@ }; | ||
Polling.prototype.pause = function (onPause) { | ||
var pending = 0 | ||
, self = this | ||
Polling.prototype.pause = function(onPause){ | ||
var pending = 0; | ||
var self = this; | ||
this.readyState = 'pausing'; | ||
function pause () { | ||
// debug: paused | ||
function pause(){ | ||
debug('paused'); | ||
self.readyState = 'paused'; | ||
@@ -77,6 +84,6 @@ onPause(); | ||
if (this.polling) { | ||
// debug: we are currently polling - waiting to pause | ||
debug('we are currently polling - waiting to pause'); | ||
total++; | ||
this.once('pollComplete', function () { | ||
// debug: pre-pause polling complete | ||
this.once('pollComplete', function(){ | ||
debug('pre-pause polling complete'); | ||
--total || pause(); | ||
@@ -87,6 +94,6 @@ }); | ||
if (!this.writable) { | ||
// debug: we are currently writing - waiting to pause | ||
debug('we are currently writing - waiting to pause'); | ||
total++; | ||
this.once('drain', function () { | ||
// debug: pre-pause writing complete | ||
this.once('drain', function(){ | ||
debug('pre-pause writing complete'); | ||
--total || pause(); | ||
@@ -106,4 +113,4 @@ }); | ||
Polling.prototype.poll = function () { | ||
// debug: polling | ||
Polling.prototype.poll = function(){ | ||
debug('polling'); | ||
this.polling = true; | ||
@@ -120,4 +127,4 @@ this.doPoll(); | ||
Polling.prototype.onData = function (data) { | ||
// debug: polling got, data | ||
Polling.prototype.onData = function(data){ | ||
debug('polling got data %s', data); | ||
// decode payload | ||
@@ -149,3 +156,3 @@ var packets = parser.decodePayload(data); | ||
} else { | ||
// debug: ignoring poll - transport state "%s", this.readyState | ||
debug('ignoring poll - transport state "%s"', this.readyState); | ||
} | ||
@@ -160,4 +167,4 @@ }; | ||
Polling.prototype.doClose = function () { | ||
// debug: sending close packet | ||
Polling.prototype.doClose = function(){ | ||
debug('sending close packet'); | ||
this.send([{ type: 'close' }]); | ||
@@ -174,6 +181,6 @@ }; | ||
Polling.prototype.write = function (packets) { | ||
Polling.prototype.write = function(packets){ | ||
var self = this; | ||
this.writable = false; | ||
this.doWrite(parser.encodePayload(packets), function () { | ||
this.doWrite(parser.encodePayload(packets), function(){ | ||
self.writable = true; | ||
@@ -190,6 +197,6 @@ self.emit('drain'); | ||
Polling.prototype.uri = function () { | ||
var query = this.query || {} | ||
, schema = this.secure ? 'https' : 'http' | ||
, port = '' | ||
Polling.prototype.uri = function(){ | ||
var query = this.query || {}; | ||
var schema = this.secure ? 'https' : 'http'; | ||
var port = ''; | ||
@@ -196,0 +203,0 @@ // cache busting is forced for IE / android / iOS6 ಠ_ಠ |
@@ -9,2 +9,3 @@ | ||
, util = require('../util') | ||
, debug = require('debug')('engine.io-client:websocket'); | ||
@@ -18,2 +19,8 @@ /** | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* WebSocket transport constructor. | ||
@@ -25,3 +32,3 @@ * | ||
function WS (opts) { | ||
function WS(opts){ | ||
Transport.call(this, opts); | ||
@@ -50,3 +57,3 @@ }; | ||
WS.prototype.doOpen = function () { | ||
WS.prototype.doOpen = function(){ | ||
if (!this.check()) { | ||
@@ -60,12 +67,12 @@ // let probe timeout | ||
this.socket = new (ws())(this.uri()); | ||
this.socket.onopen = function () { | ||
this.socket.onopen = function(){ | ||
self.onOpen(); | ||
}; | ||
this.socket.onclose = function () { | ||
this.socket.onclose = function(){ | ||
self.onClose(); | ||
}; | ||
this.socket.onmessage = function (ev) { | ||
this.socket.onmessage = function(ev){ | ||
self.onData(ev.data); | ||
}; | ||
this.socket.onerror = function (e) { | ||
this.socket.onerror = function(e){ | ||
self.onError('websocket error', e); | ||
@@ -82,3 +89,3 @@ }; | ||
WS.prototype.write = function (packets) { | ||
WS.prototype.write = function(packets){ | ||
for (var i = 0, l = packets.length; i < l; i++) { | ||
@@ -95,3 +102,3 @@ this.socket.send(parser.encodePacket(packets[i])); | ||
WS.prototype.doClose = function () { | ||
WS.prototype.doClose = function(){ | ||
if (typeof this.socket !== 'undefined') { | ||
@@ -108,6 +115,6 @@ this.socket.close(); | ||
WS.prototype.uri = function () { | ||
var query = this.query || {} | ||
, schema = this.secure ? 'wss' : 'ws' | ||
, port = '' | ||
WS.prototype.uri = function(){ | ||
var query = this.query || {}; | ||
var schema = this.secure ? 'wss' : 'ws'; | ||
var port = ''; | ||
@@ -142,6 +149,6 @@ // avoid port if default for schema | ||
WS.prototype.check = function () { | ||
WS.prototype.check = function(){ | ||
var websocket = ws(); | ||
return !!websocket && !('__initialize' in websocket && this.name === WS.prototype.name); | ||
} | ||
}; | ||
@@ -154,8 +161,8 @@ /** | ||
function ws () { | ||
// if node | ||
return require('ws'); | ||
// end | ||
function ws(){ | ||
if ('undefined' != typeof process) { | ||
return require('ws'); | ||
} | ||
return global.WebSocket || global.MozWebSocket; | ||
} |
@@ -9,2 +9,8 @@ | ||
/** | ||
* Global reference. | ||
*/ | ||
var global = 'undefined' != typeof window ? window : global; | ||
/** | ||
* Inheritance. | ||
@@ -28,4 +34,4 @@ * | ||
exports.keys = Object.keys || function (obj) { | ||
var ret = [] | ||
, has = Object.prototype.hasOwnProperty | ||
var ret = []; | ||
var has = Object.prototype.hasOwnProperty; | ||
@@ -159,3 +165,3 @@ for (var i in obj) { | ||
exports.ua.webkit = 'undefined' != typeof navigator && | ||
exports.ua.webkit = 'undefined' != typeof navigator && | ||
/webkit/i.test(navigator.userAgent); | ||
@@ -169,3 +175,3 @@ | ||
exports.ua.gecko = 'undefined' != typeof navigator && | ||
exports.ua.gecko = 'undefined' != typeof navigator && | ||
/gecko/i.test(navigator.userAgent); | ||
@@ -177,3 +183,3 @@ | ||
exports.ua.android = 'undefined' != typeof navigator && | ||
exports.ua.android = 'undefined' != typeof navigator && | ||
/android/i.test(navigator.userAgent); | ||
@@ -197,6 +203,6 @@ | ||
exports.request = function request (xdomain) { | ||
// if node | ||
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | ||
return new XMLHttpRequest(); | ||
// end | ||
if ('undefined' != typeof process) { | ||
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | ||
return new XMLHttpRequest(); | ||
} | ||
@@ -250,3 +256,3 @@ if (xdomain && 'undefined' != typeof XDomainRequest && !exports.ua.hasCORS) { | ||
* | ||
* @param {Object} | ||
* @param {Object} | ||
* @api private | ||
@@ -253,0 +259,0 @@ */ |
{ | ||
"name": "engine.io-client", | ||
"description": "Client for the realtime Engine", | ||
"main": "./lib/engine.io-client", | ||
"version": "0.3.10", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/LearnBoost/engine.io-client", | ||
"contributors": [ | ||
@@ -14,2 +14,3 @@ { "name": "Guillermo Rauch", "email": "rauchg@gmail.com" }, | ||
"xmlhttprequest": "1.5.0", | ||
"emitter-component": "0.0.6", | ||
"debug": "0.6.0" | ||
@@ -25,6 +26,16 @@ }, | ||
"scripts": { | ||
"engine.io/index.js": "./dist/engine.io-dev.js", | ||
"engine.io-client/index.js": "./dist/engine.io-dev.js" | ||
"engine.io/index.js": "lib/index.js", | ||
"engine.io/parser.js": "lib/parser.js", | ||
"engine.io/socket.js": "lib/socket.js", | ||
"engine.io/transport.js": "lib/transport.js", | ||
"engine.io/emitter.js": "lib/emitter.js", | ||
"engine.io/util.js": "lib/util.js", | ||
"engine.io/transports/index.js": "lib/transports/index.js", | ||
"engine.io/transports/polling.js": "lib/transports/polling.js", | ||
"engine.io/transports/polling-xhr.js": "lib/transports/polling-xhr.js", | ||
"engine.io/transports/polling-jsonp.js": "lib/transports/polling-jsonp.js", | ||
"engine.io/transports/websocket.js": "lib/transports/websocket.js", | ||
"engine.io/transports/flashsocket.js": "lib/transports/flashsocket.js" | ||
} | ||
} | ||
} |
@@ -11,9 +11,28 @@ # Engine.IO client | ||
### With component | ||
Engine.IO is a [component](http://github.com/component/component), which | ||
means you can include it by using `require` on the browser: | ||
```js | ||
var socket = require('engine.io')('ws://localhost'); | ||
socket.onopen = function(){ | ||
socket.onmessage = function(data){}); | ||
socket.onclose = function(){}); | ||
}; | ||
``` | ||
### Standalone | ||
If you decide not to use component you can find a `engine.io.js` file in | ||
this repository, which is a standalone build you can use as follows: | ||
```html | ||
<script src="/path/to/engine.js"></script> | ||
<script src="/path/to/build.js"></script> | ||
<script> | ||
var socket = new eio.Socket({ host: 'localhost', port: 80 }); | ||
socket.onopen = function () { | ||
socket.onmessage = function (data) { }); | ||
socket.onclose = function () { }); | ||
// eio = Socket | ||
var socket = eio('ws://localhost'); | ||
socket.onopen = function(){ | ||
socket.onmessage = function(data){}); | ||
socket.onclose = function(){}); | ||
}; | ||
@@ -23,2 +42,14 @@ </script> | ||
### Node.JS | ||
Add `engine.io-client` to your `package.json` and then: | ||
```js | ||
var socket = require('engine.io-client')('ws://localhost'); | ||
socket.onopen = function(){ | ||
socket.onmessage = function(data){}); | ||
socket.onclose = function(){}); | ||
}; | ||
``` | ||
## Features | ||
@@ -42,19 +73,10 @@ | ||
### Top-level | ||
### Socket | ||
These are exposed in the `eio` global namespace (in the browser), or by | ||
`require('engine.io-client')` (in Node.JS). | ||
The client class. Mixes in [Emitter](http://github.com/component/emitter). | ||
Exposed as `eio` in the browser standalone build. | ||
#### Properties | ||
- `version` _(String)_: client version | ||
- `protocol` _(Number)_: protocol revision number | ||
- `Socket` _(Function)_: client constructor | ||
### Socket | ||
The client class. _Inherits from EventEmitter_. | ||
#### Properties | ||
- `onopen` (_Function_) | ||
@@ -140,4 +162,8 @@ - `open` event handler | ||
`engine.io-client` is used to test | ||
[engine](http://github.com/learnboost/engine.io) | ||
[engine](http://github.com/learnboost/engine.io). Running the `engine.io` | ||
test suite ensures the client works and vice-versa. | ||
Additionally, `engine.io-client` has a standalone test suite you can run | ||
with `make test` or in the browser with `make test-browser`. | ||
## Support | ||
@@ -144,0 +170,0 @@ |
@@ -7,3 +7,3 @@ | ||
// expose the globals that are obtained through `<script>` on the browser | ||
expect = require('expect.js') | ||
eio = require('../lib/engine.io-client') | ||
expect = require('expect.js'); | ||
eio = require('../lib/'); |
describe('engine.io-client', function () { | ||
it('should expose version number', function () { | ||
expect(eio.version).to.match(/[0-9]+\.[0-9]+\.[0-9]+/); | ||
}); | ||
it('should expose protocol number', function () { | ||
@@ -9,0 +5,0 @@ expect(eio.protocol).to.be.a('number'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
34
1
212
7
2
378940
4
12273
+ Addedemitter-component@0.0.6
+ Addedemitter-component@0.0.6(transitive)