engine.io-client
Advanced tools
Comparing version 0.8.1 to 0.8.2
210
engine.io.js
@@ -61,8 +61,8 @@ !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.eio=e():"undefined"!=typeof global?global.eio=e():"undefined"!=typeof self&&(self.eio=e())}(function(){var define,module,exports; | ||
var util = require('./util') | ||
, transports = require('./transports') | ||
, Emitter = require('./emitter') | ||
, debug = require('debug')('engine.io-client:socket') | ||
, index = require('indexof') | ||
, parser = require('engine.io-parser'); | ||
var util = require('./util'); | ||
var transports = require('./transports'); | ||
var Emitter = require('./emitter'); | ||
var debug = require('debug')('engine.io-client:socket'); | ||
var index = require('indexof'); | ||
var parser = require('engine.io-parser'); | ||
@@ -657,5 +657,5 @@ /** | ||
var util = require('./util') | ||
, parser = require('engine.io-parser') | ||
, Emitter = require('./emitter'); | ||
var util = require('./util'); | ||
var parser = require('engine.io-parser'); | ||
var Emitter = require('./emitter'); | ||
@@ -797,2 +797,3 @@ /** | ||
},{"./emitter":2,"./util":12,"engine.io-parser":16}],6:[function(require,module,exports){ | ||
/** | ||
@@ -802,5 +803,5 @@ * Module dependencies. | ||
var WS = require('./websocket') | ||
, util = require('../util') | ||
, debug = require('debug')('engine.io-client:flashsocket'); | ||
var WS = require('./websocket'); | ||
var util = require('../util'); | ||
var debug = require('debug')('engine.io-client:flashsocket'); | ||
@@ -831,7 +832,7 @@ /** | ||
function FlashWS (options) { | ||
function FlashWS(options){ | ||
WS.call(this, options); | ||
this.flashPath = options.flashPath; | ||
this.policyPort = options.policyPort; | ||
}; | ||
} | ||
@@ -858,3 +859,3 @@ /** | ||
FlashWS.prototype.doOpen = function () { | ||
FlashWS.prototype.doOpen = function(){ | ||
if (!this.check()) { | ||
@@ -866,3 +867,3 @@ // let the probe timeout | ||
// instrument websocketjs logging | ||
function log (type) { | ||
function log(type){ | ||
return function(){ | ||
@@ -872,10 +873,10 @@ var str = Array.prototype.join.call(arguments, ' '); | ||
}; | ||
}; | ||
} | ||
WEB_SOCKET_LOGGER = { log: log('debug'), error: log('error') }; | ||
WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true; | ||
WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true; | ||
global.WEB_SOCKET_LOGGER = { log: log('debug'), error: log('error') }; | ||
global.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true; | ||
global.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true; | ||
if ('undefined' == typeof WEB_SOCKET_SWF_LOCATION) { | ||
WEB_SOCKET_SWF_LOCATION = this.flashPath + 'WebSocketMainInsecure.swf'; | ||
if (!global.WEB_SOCKET_SWF_LOCATION) { | ||
global.WEB_SOCKET_SWF_LOCATION = this.flashPath + 'WebSocketMainInsecure.swf'; | ||
} | ||
@@ -886,3 +887,3 @@ | ||
if ('undefined' == typeof swfobject) { | ||
if (!global.swfobject) { | ||
deps.unshift(this.flashPath + 'swfobject.js'); | ||
@@ -893,4 +894,4 @@ } | ||
load(deps, function () { | ||
self.ready(function () { | ||
load(deps, function(){ | ||
self.ready(function(){ | ||
WebSocket.__addTask(function () { | ||
@@ -910,6 +911,6 @@ self.socket = new WebSocket(self.uri()); | ||
FlashWS.prototype.doClose = function () { | ||
FlashWS.prototype.doClose = function(){ | ||
if (!this.socket) return; | ||
var self = this; | ||
WebSocket.__addTask(function() { | ||
WebSocket.__addTask(function(){ | ||
WS.prototype.doClose.call(self); | ||
@@ -925,5 +926,5 @@ }); | ||
FlashWS.prototype.write = function() { | ||
FlashWS.prototype.write = function(){ | ||
var self = this, args = arguments; | ||
WebSocket.__addTask(function () { | ||
WebSocket.__addTask(function(){ | ||
WS.prototype.write.apply(self, args); | ||
@@ -939,9 +940,9 @@ }); | ||
FlashWS.prototype.ready = function (fn) { | ||
FlashWS.prototype.ready = function(fn){ | ||
if (typeof WebSocket == 'undefined' || | ||
!('__initialize' in WebSocket) || !swfobject) { | ||
!('__initialize' in WebSocket) || !global.swfobject) { | ||
return; | ||
} | ||
if (swfobject.getFlashPlayerVersion().major < 10) { | ||
if (global.swfobject.getFlashPlayerVersion().major < 10) { | ||
return; | ||
@@ -951,7 +952,8 @@ } | ||
function init () { | ||
// Only start downloading the swf file when the checked that this browser | ||
// actually supports it | ||
// only start downloading the swf file when | ||
// we checked that this browser actually supports it | ||
if (!FlashWS.loaded) { | ||
if (843 != self.policyPort) { | ||
WebSocket.loadFlashPolicyFile('xmlsocket://' + self.hostname + ':' + self.policyPort); | ||
var policy = 'xmlsocket://' + self.hostname + ':' + self.policyPort; | ||
WebSocket.loadFlashPolicyFile(policy); | ||
} | ||
@@ -981,3 +983,3 @@ | ||
FlashWS.prototype.check = function () { | ||
FlashWS.prototype.check = function(){ | ||
if ('undefined' == typeof window) { | ||
@@ -1027,3 +1029,3 @@ return false; | ||
function create (path, fn) { | ||
function create(path, fn){ | ||
if (scripts[path]) return fn(); | ||
@@ -1035,3 +1037,3 @@ | ||
debug('loading "%s"', path); | ||
el.onload = el.onreadystatechange = function () { | ||
el.onload = el.onreadystatechange = function(){ | ||
if (loaded || scripts[path]) return; | ||
@@ -1053,3 +1055,3 @@ var rs = el.readyState; | ||
head.insertBefore(el, head.firstChild); | ||
}; | ||
} | ||
@@ -1063,4 +1065,4 @@ /** | ||
function load (arr, fn) { | ||
function process (i) { | ||
function load(arr, fn){ | ||
function process(i){ | ||
if (!arr[i]) return fn(); | ||
@@ -1070,6 +1072,6 @@ create(arr[i], function () { | ||
}); | ||
}; | ||
} | ||
process(0); | ||
}; | ||
} | ||
@@ -1141,4 +1143,4 @@ },{"../util":12,"./websocket":11,"debug":14,"global":19}],7:[function(require,module,exports){ | ||
var Polling = require('./polling') | ||
, util = require('../util'); | ||
var Polling = require('./polling'); | ||
var util = require('../util'); | ||
@@ -1210,3 +1212,3 @@ /** | ||
this.query.j = this.index; | ||
}; | ||
} | ||
@@ -1220,15 +1222,2 @@ /** | ||
/** | ||
* Opens the socket. | ||
* | ||
* @api private | ||
*/ | ||
JSONPPolling.prototype.doOpen = function () { | ||
var self = this; | ||
util.defer(function () { | ||
Polling.prototype.doOpen.call(self); | ||
}); | ||
}; | ||
/** | ||
* Closes the socket | ||
@@ -1270,5 +1259,5 @@ * | ||
script.src = this.uri(); | ||
script.onerror = function(e){ | ||
self.onError('jsonp poll error',e); | ||
} | ||
script.onerror = function(e){ | ||
self.onError('jsonp poll error',e); | ||
}; | ||
@@ -1326,3 +1315,3 @@ var insertAt = document.getElementsByTagName('script')[0]; | ||
fn(); | ||
}; | ||
} | ||
@@ -1352,3 +1341,3 @@ function initIframe () { | ||
self.iframe = iframe; | ||
}; | ||
} | ||
@@ -1380,7 +1369,7 @@ initIframe(); | ||
var XMLHttpRequest = require('xmlhttprequest') | ||
, Polling = require('./polling') | ||
, util = require('../util') | ||
, Emitter = require('../emitter') | ||
, debug = require('debug')('engine.io-client:polling-xhr'); | ||
var XMLHttpRequest = require('xmlhttprequest'); | ||
var Polling = require('./polling'); | ||
var util = require('../util'); | ||
var Emitter = require('../emitter'); | ||
var debug = require('debug')('engine.io-client:polling-xhr'); | ||
@@ -1443,15 +1432,2 @@ /** | ||
/** | ||
* Opens the socket | ||
* | ||
* @api private | ||
*/ | ||
XHR.prototype.doOpen = function(){ | ||
var self = this; | ||
util.defer(function(){ | ||
Polling.prototype.doOpen.call(self); | ||
}); | ||
}; | ||
/** | ||
* Creates a request. | ||
@@ -1564,3 +1540,7 @@ * | ||
} else { | ||
self.onError(xhr.status); | ||
// make sure the `error` event handler that's user-set | ||
// does not throw in the same tick and gets caught here | ||
setTimeout(function(){ | ||
self.onError(xhr.status); | ||
}, 0); | ||
} | ||
@@ -1679,6 +1659,6 @@ } catch (e) { | ||
var Transport = require('../transport') | ||
, util = require('../util') | ||
, parser = require('engine.io-parser') | ||
, debug = require('debug')('engine.io-client:polling'); | ||
var Transport = require('../transport'); | ||
var util = require('../util'); | ||
var parser = require('engine.io-parser'); | ||
var debug = require('debug')('engine.io-client:polling'); | ||
@@ -1914,7 +1894,7 @@ /** | ||
var Transport = require('../transport') | ||
, WebSocket = require('ws') | ||
, parser = require('engine.io-parser') | ||
, util = require('../util') | ||
, debug = require('debug')('engine.io-client:websocket'); | ||
var Transport = require('../transport'); | ||
var WebSocket = require('ws'); | ||
var parser = require('engine.io-parser'); | ||
var util = require('../util'); | ||
var debug = require('debug')('engine.io-client:websocket'); | ||
@@ -1942,3 +1922,3 @@ /** | ||
Transport.call(this, opts); | ||
}; | ||
} | ||
@@ -1986,3 +1966,3 @@ /** | ||
WS.prototype.addEventListeners = function() { | ||
WS.prototype.addEventListeners = function(){ | ||
var self = this; | ||
@@ -2190,19 +2170,2 @@ | ||
/** | ||
* Defers a function to ensure a spinner is not displayed by the browser. | ||
* | ||
* @param {Function} fn | ||
* @api private | ||
*/ | ||
exports.defer = function (fn) { | ||
if (!exports.ua.webkit || 'undefined' != typeof importScripts) { | ||
return fn(); | ||
} | ||
exports.load(function () { | ||
setTimeout(fn, 100); | ||
}); | ||
}; | ||
/** | ||
* JSON parse. | ||
@@ -2249,10 +2212,2 @@ * | ||
/** | ||
* Whether the UA supports CORS for XHR. | ||
* | ||
* @api private | ||
*/ | ||
exports.ua.hasCORS = require('has-cors'); | ||
/** | ||
* Detect webkit. | ||
@@ -2359,3 +2314,3 @@ * | ||
},{"global":19,"has-cors":20}],13:[function(require,module,exports){ | ||
},{"global":19}],13:[function(require,module,exports){ | ||
// browser shim for xmlhttprequest module | ||
@@ -2401,2 +2356,4 @@ var hasCORS = require('has-cors'); | ||
return function(fmt){ | ||
fmt = coerce(fmt); | ||
var curr = new Date; | ||
@@ -2504,5 +2461,16 @@ var ms = curr - (debug[name] || curr); | ||
/** | ||
* Coerce `val`. | ||
*/ | ||
function coerce(val) { | ||
if (val instanceof Error) return val.stack || val.message; | ||
return val; | ||
} | ||
// persist | ||
if (window.localStorage) debug.enable(localStorage.debug); | ||
try { | ||
if (window.localStorage) debug.enable(localStorage.debug); | ||
} catch(e){} | ||
@@ -2509,0 +2477,0 @@ },{}],15:[function(require,module,exports){ |
0.8.2 / 2014-01-18 | ||
================== | ||
* polling-xhr: avoid catching user-thrown errors | ||
* util: remove unused `hasCORS` | ||
* polling: remove deferring for faster startup (fixes #174) | ||
* engine now works perfectly on workers | ||
0.8.1 / 2014-01-17 | ||
@@ -3,0 +11,0 @@ ================== |
@@ -5,8 +5,8 @@ /** | ||
var util = require('./util') | ||
, transports = require('./transports') | ||
, Emitter = require('./emitter') | ||
, debug = require('debug')('engine.io-client:socket') | ||
, index = require('indexof') | ||
, parser = require('engine.io-parser'); | ||
var util = require('./util'); | ||
var transports = require('./transports'); | ||
var Emitter = require('./emitter'); | ||
var debug = require('debug')('engine.io-client:socket'); | ||
var index = require('indexof'); | ||
var parser = require('engine.io-parser'); | ||
@@ -13,0 +13,0 @@ /** |
@@ -6,5 +6,5 @@ | ||
var util = require('./util') | ||
, parser = require('engine.io-parser') | ||
, Emitter = require('./emitter'); | ||
var util = require('./util'); | ||
var parser = require('engine.io-parser'); | ||
var Emitter = require('./emitter'); | ||
@@ -11,0 +11,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
/** | ||
@@ -5,5 +6,5 @@ * Module dependencies. | ||
var WS = require('./websocket') | ||
, util = require('../util') | ||
, debug = require('debug')('engine.io-client:flashsocket'); | ||
var WS = require('./websocket'); | ||
var util = require('../util'); | ||
var debug = require('debug')('engine.io-client:flashsocket'); | ||
@@ -34,7 +35,7 @@ /** | ||
function FlashWS (options) { | ||
function FlashWS(options){ | ||
WS.call(this, options); | ||
this.flashPath = options.flashPath; | ||
this.policyPort = options.policyPort; | ||
}; | ||
} | ||
@@ -61,3 +62,3 @@ /** | ||
FlashWS.prototype.doOpen = function () { | ||
FlashWS.prototype.doOpen = function(){ | ||
if (!this.check()) { | ||
@@ -69,3 +70,3 @@ // let the probe timeout | ||
// instrument websocketjs logging | ||
function log (type) { | ||
function log(type){ | ||
return function(){ | ||
@@ -75,10 +76,10 @@ var str = Array.prototype.join.call(arguments, ' '); | ||
}; | ||
}; | ||
} | ||
WEB_SOCKET_LOGGER = { log: log('debug'), error: log('error') }; | ||
WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true; | ||
WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true; | ||
global.WEB_SOCKET_LOGGER = { log: log('debug'), error: log('error') }; | ||
global.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true; | ||
global.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true; | ||
if ('undefined' == typeof WEB_SOCKET_SWF_LOCATION) { | ||
WEB_SOCKET_SWF_LOCATION = this.flashPath + 'WebSocketMainInsecure.swf'; | ||
if (!global.WEB_SOCKET_SWF_LOCATION) { | ||
global.WEB_SOCKET_SWF_LOCATION = this.flashPath + 'WebSocketMainInsecure.swf'; | ||
} | ||
@@ -89,3 +90,3 @@ | ||
if ('undefined' == typeof swfobject) { | ||
if (!global.swfobject) { | ||
deps.unshift(this.flashPath + 'swfobject.js'); | ||
@@ -96,4 +97,4 @@ } | ||
load(deps, function () { | ||
self.ready(function () { | ||
load(deps, function(){ | ||
self.ready(function(){ | ||
WebSocket.__addTask(function () { | ||
@@ -113,6 +114,6 @@ self.socket = new WebSocket(self.uri()); | ||
FlashWS.prototype.doClose = function () { | ||
FlashWS.prototype.doClose = function(){ | ||
if (!this.socket) return; | ||
var self = this; | ||
WebSocket.__addTask(function() { | ||
WebSocket.__addTask(function(){ | ||
WS.prototype.doClose.call(self); | ||
@@ -128,5 +129,5 @@ }); | ||
FlashWS.prototype.write = function() { | ||
FlashWS.prototype.write = function(){ | ||
var self = this, args = arguments; | ||
WebSocket.__addTask(function () { | ||
WebSocket.__addTask(function(){ | ||
WS.prototype.write.apply(self, args); | ||
@@ -142,9 +143,9 @@ }); | ||
FlashWS.prototype.ready = function (fn) { | ||
FlashWS.prototype.ready = function(fn){ | ||
if (typeof WebSocket == 'undefined' || | ||
!('__initialize' in WebSocket) || !swfobject) { | ||
!('__initialize' in WebSocket) || !global.swfobject) { | ||
return; | ||
} | ||
if (swfobject.getFlashPlayerVersion().major < 10) { | ||
if (global.swfobject.getFlashPlayerVersion().major < 10) { | ||
return; | ||
@@ -154,7 +155,8 @@ } | ||
function init () { | ||
// Only start downloading the swf file when the checked that this browser | ||
// actually supports it | ||
// only start downloading the swf file when | ||
// we checked that this browser actually supports it | ||
if (!FlashWS.loaded) { | ||
if (843 != self.policyPort) { | ||
WebSocket.loadFlashPolicyFile('xmlsocket://' + self.hostname + ':' + self.policyPort); | ||
var policy = 'xmlsocket://' + self.hostname + ':' + self.policyPort; | ||
WebSocket.loadFlashPolicyFile(policy); | ||
} | ||
@@ -184,3 +186,3 @@ | ||
FlashWS.prototype.check = function () { | ||
FlashWS.prototype.check = function(){ | ||
if ('undefined' == typeof window) { | ||
@@ -230,3 +232,3 @@ return false; | ||
function create (path, fn) { | ||
function create(path, fn){ | ||
if (scripts[path]) return fn(); | ||
@@ -238,3 +240,3 @@ | ||
debug('loading "%s"', path); | ||
el.onload = el.onreadystatechange = function () { | ||
el.onload = el.onreadystatechange = function(){ | ||
if (loaded || scripts[path]) return; | ||
@@ -256,3 +258,3 @@ var rs = el.readyState; | ||
head.insertBefore(el, head.firstChild); | ||
}; | ||
} | ||
@@ -266,4 +268,4 @@ /** | ||
function load (arr, fn) { | ||
function process (i) { | ||
function load(arr, fn){ | ||
function process(i){ | ||
if (!arr[i]) return fn(); | ||
@@ -273,5 +275,5 @@ create(arr[i], function () { | ||
}); | ||
}; | ||
} | ||
process(0); | ||
}; | ||
} |
@@ -6,4 +6,4 @@ | ||
var Polling = require('./polling') | ||
, util = require('../util'); | ||
var Polling = require('./polling'); | ||
var util = require('../util'); | ||
@@ -75,3 +75,3 @@ /** | ||
this.query.j = this.index; | ||
}; | ||
} | ||
@@ -85,15 +85,2 @@ /** | ||
/** | ||
* Opens the socket. | ||
* | ||
* @api private | ||
*/ | ||
JSONPPolling.prototype.doOpen = function () { | ||
var self = this; | ||
util.defer(function () { | ||
Polling.prototype.doOpen.call(self); | ||
}); | ||
}; | ||
/** | ||
* Closes the socket | ||
@@ -135,5 +122,5 @@ * | ||
script.src = this.uri(); | ||
script.onerror = function(e){ | ||
self.onError('jsonp poll error',e); | ||
} | ||
script.onerror = function(e){ | ||
self.onError('jsonp poll error',e); | ||
}; | ||
@@ -191,3 +178,3 @@ var insertAt = document.getElementsByTagName('script')[0]; | ||
fn(); | ||
}; | ||
} | ||
@@ -217,3 +204,3 @@ function initIframe () { | ||
self.iframe = iframe; | ||
}; | ||
} | ||
@@ -220,0 +207,0 @@ initIframe(); |
@@ -5,7 +5,7 @@ /** | ||
var XMLHttpRequest = require('xmlhttprequest') | ||
, Polling = require('./polling') | ||
, util = require('../util') | ||
, Emitter = require('../emitter') | ||
, debug = require('debug')('engine.io-client:polling-xhr'); | ||
var XMLHttpRequest = require('xmlhttprequest'); | ||
var Polling = require('./polling'); | ||
var util = require('../util'); | ||
var Emitter = require('../emitter'); | ||
var debug = require('debug')('engine.io-client:polling-xhr'); | ||
@@ -68,15 +68,2 @@ /** | ||
/** | ||
* Opens the socket | ||
* | ||
* @api private | ||
*/ | ||
XHR.prototype.doOpen = function(){ | ||
var self = this; | ||
util.defer(function(){ | ||
Polling.prototype.doOpen.call(self); | ||
}); | ||
}; | ||
/** | ||
* Creates a request. | ||
@@ -189,3 +176,7 @@ * | ||
} else { | ||
self.onError(xhr.status); | ||
// make sure the `error` event handler that's user-set | ||
// does not throw in the same tick and gets caught here | ||
setTimeout(function(){ | ||
self.onError(xhr.status); | ||
}, 0); | ||
} | ||
@@ -192,0 +183,0 @@ } catch (e) { |
@@ -5,6 +5,6 @@ /** | ||
var Transport = require('../transport') | ||
, util = require('../util') | ||
, parser = require('engine.io-parser') | ||
, debug = require('debug')('engine.io-client:polling'); | ||
var Transport = require('../transport'); | ||
var util = require('../util'); | ||
var parser = require('engine.io-parser'); | ||
var debug = require('debug')('engine.io-client:polling'); | ||
@@ -11,0 +11,0 @@ /** |
@@ -5,7 +5,7 @@ /** | ||
var Transport = require('../transport') | ||
, WebSocket = require('ws') | ||
, parser = require('engine.io-parser') | ||
, util = require('../util') | ||
, debug = require('debug')('engine.io-client:websocket'); | ||
var Transport = require('../transport'); | ||
var WebSocket = require('ws'); | ||
var parser = require('engine.io-parser'); | ||
var util = require('../util'); | ||
var debug = require('debug')('engine.io-client:websocket'); | ||
@@ -33,3 +33,3 @@ /** | ||
Transport.call(this, opts); | ||
}; | ||
} | ||
@@ -77,3 +77,3 @@ /** | ||
WS.prototype.addEventListeners = function() { | ||
WS.prototype.addEventListeners = function(){ | ||
var self = this; | ||
@@ -80,0 +80,0 @@ |
@@ -80,19 +80,2 @@ | ||
/** | ||
* Defers a function to ensure a spinner is not displayed by the browser. | ||
* | ||
* @param {Function} fn | ||
* @api private | ||
*/ | ||
exports.defer = function (fn) { | ||
if (!exports.ua.webkit || 'undefined' != typeof importScripts) { | ||
return fn(); | ||
} | ||
exports.load(function () { | ||
setTimeout(fn, 100); | ||
}); | ||
}; | ||
/** | ||
* JSON parse. | ||
@@ -139,10 +122,2 @@ * | ||
/** | ||
* Whether the UA supports CORS for XHR. | ||
* | ||
* @api private | ||
*/ | ||
exports.ua.hasCORS = require('has-cors'); | ||
/** | ||
* Detect webkit. | ||
@@ -149,0 +124,0 @@ * |
{ | ||
"name": "engine.io-client", | ||
"description": "Client for the realtime Engine", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"homepage": "http://socket.io", | ||
@@ -40,3 +40,4 @@ "contributors": [ | ||
"browserify": "2.35.1", | ||
"engine.io": "0.8.1" | ||
"engine.io": "0.8.2", | ||
"express": "3.4.8" | ||
}, | ||
@@ -43,0 +44,0 @@ "scripts": { |
128151
7
4209