diff --git a/README.md b/README.md index 34740530..7a0704c7 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ socket.on('open', function(){ binary is encoded into base64 strings, and decoded when binary types are supported. - With browsers that don't support ArrayBuffer, an object { base64: true, - data: dataAsBase64String } is emitted in onmessage + data: dataAsBase64String } is emitted on the `message` event. ## API @@ -111,12 +111,6 @@ Exposed as `eio` in the browser standalone build. #### Properties - `protocol` _(Number)_: protocol revision number -- `onopen` (_Function_) - - `open` event handler -- `onmessage` (_Function_) - - `message` event handler -- `onclose` (_Function_) - - `message` event handler - `binaryType` _(String)_ : can be set to 'arraybuffer' or 'blob' in browsers, and `buffer` or `arraybuffer` in Node. Blob is only used in browser if it's supported. diff --git a/lib/transports/polling-jsonp.js b/lib/transports/polling-jsonp.js index 95aea5ff..96e342ab 100644 --- a/lib/transports/polling-jsonp.js +++ b/lib/transports/polling-jsonp.js @@ -68,6 +68,13 @@ function JSONPPolling (opts) { // append to query string this.query.j = this.index; + + // prevent spurious errors from being emitted when the window is unloaded + if (global.document && global.addEventListener) { + global.addEventListener('beforeunload', function () { + if (self.script) self.script.onerror = empty; + }); + } } /** @@ -83,7 +90,7 @@ inherit(JSONPPolling, Polling); JSONPPolling.prototype.supportsBinary = false; /** - * Closes the socket + * Closes the socket. * * @api private */ @@ -109,7 +116,7 @@ JSONPPolling.prototype.doClose = function () { */ JSONPPolling.prototype.doPoll = function () { - var self = this; + var self = this; var script = document.createElement('script'); if (this.script) { diff --git a/lib/transports/polling-xhr.js b/lib/transports/polling-xhr.js index 5dfc04f9..0a2cb02b 100755 --- a/lib/transports/polling-xhr.js +++ b/lib/transports/polling-xhr.js @@ -287,15 +287,15 @@ Request.prototype.abort = function(){ }; /** - * Cleanup is needed for IE that leaks memory unless we abort the request - * before unload. It is also needed to prevent spurious errors from being - * emimtted. + * Aborts pending requests when unloading the window. This is needed to prevent + * memory leaks (e.g. when using IE) and to ensure that no spurious error is + * emitted. */ if (global.document) { Request.requestsCount = 0; Request.requests = {}; - if (global.document.attachEvent) { + if (global.attachEvent) { global.attachEvent('onunload', unloadHandler); } else if (global.addEventListener) { global.addEventListener('beforeunload', unloadHandler); diff --git a/package.json b/package.json index a2033103..0c36dd9d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "xmlhttprequest": "https://github.com/LearnBoost/node-XMLHttpRequest/archive/0f36d0b5ebc03d85f860d42a64ae9791e1daa433.tar.gz", "emitter": "http://github.com/component/emitter/archive/1.0.1.tar.gz", "indexof": "0.0.1", - "engine.io-parser": "1.0.3", + "engine.io-parser": "1.0.4", "debug": "0.7.4", "parseuri": "0.0.2", "parsejson": "0.0.1",