Skip to content

Commit

Permalink
[fix] fix JSONP transport in Node.js environment
Browse files Browse the repository at this point in the history
The commit 99bcc62 resulted in `window is not defined` errors.
  • Loading branch information
darrachequesne committed Nov 19, 2018
1 parent f62fca4 commit 66b9e4a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/transports/polling-jsonp.js
Expand Up @@ -30,6 +30,15 @@ var callbacks;

function empty () { }

/**
* Until https://github.com/tc39/proposal-global is shipped.
*/
function glob () {
return typeof self !== 'undefined' ? self
: typeof window !== 'undefined' ? window
: typeof global !== 'undefined' ? global : {};
}

/**
* JSONP Polling constructor.
*
Expand All @@ -46,8 +55,8 @@ function JSONPPolling (opts) {
// we do this here (lazily) to avoid unneeded global pollution
if (!callbacks) {
// we need to consider multiple engines in the same page
if (!window.___eio) window.___eio = [];
callbacks = window.___eio;
var global = glob();
callbacks = global.___eio = (global.___eio || []);
}

// callback identifier
Expand Down

0 comments on commit 66b9e4a

Please sign in to comment.