Skip to content

Commit 66b9e4a

Browse files
[fix] fix JSONP transport in Node.js environment
The commit 99bcc62 resulted in `window is not defined` errors.
1 parent f62fca4 commit 66b9e4a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/transports/polling-jsonp.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ var callbacks;
3030

3131
function empty () { }
3232

33+
/**
34+
* Until https://github.com/tc39/proposal-global is shipped.
35+
*/
36+
function glob () {
37+
return typeof self !== 'undefined' ? self
38+
: typeof window !== 'undefined' ? window
39+
: typeof global !== 'undefined' ? global : {};
40+
}
41+
3342
/**
3443
* JSONP Polling constructor.
3544
*
@@ -46,8 +55,8 @@ function JSONPPolling (opts) {
4655
// we do this here (lazily) to avoid unneeded global pollution
4756
if (!callbacks) {
4857
// we need to consider multiple engines in the same page
49-
if (!window.___eio) window.___eio = [];
50-
callbacks = window.___eio;
58+
var global = glob();
59+
callbacks = global.___eio = (global.___eio || []);
5160
}
5261

5362
// callback identifier

0 commit comments

Comments
 (0)