File tree 3 files changed +17
-17
lines changed
3 files changed +17
-17
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,20 @@ class Socket extends Emitter {
90
90
// set on heartbeat
91
91
this . pingTimeoutTimer = null ;
92
92
93
+ if ( typeof addEventListener === "function" ) {
94
+ addEventListener (
95
+ "beforeunload" ,
96
+ ( ) => {
97
+ if ( this . transport ) {
98
+ // silently close the transport
99
+ this . transport . removeAllListeners ( ) ;
100
+ this . transport . close ( ) ;
101
+ }
102
+ } ,
103
+ false
104
+ ) ;
105
+ }
106
+
93
107
this . open ( ) ;
94
108
}
95
109
Original file line number Diff line number Diff line change @@ -10,12 +10,6 @@ const rEscapedNewline = /\\n/g;
10
10
11
11
let callbacks ;
12
12
13
- /**
14
- * Noop.
15
- */
16
-
17
- function empty ( ) { }
18
-
19
13
class JSONPPolling extends Polling {
20
14
/**
21
15
* JSONP Polling constructor.
@@ -46,17 +40,6 @@ class JSONPPolling extends Polling {
46
40
47
41
// append to query string
48
42
this . query . j = this . index ;
49
-
50
- // prevent spurious errors from being emitted when the window is unloaded
51
- if ( typeof addEventListener === "function" ) {
52
- addEventListener (
53
- "beforeunload" ,
54
- function ( ) {
55
- if ( self . script ) self . script . onerror = empty ;
56
- } ,
57
- false
58
- ) ;
59
- }
60
43
}
61
44
62
45
/**
@@ -73,6 +56,8 @@ class JSONPPolling extends Polling {
73
56
*/
74
57
doClose ( ) {
75
58
if ( this . script ) {
59
+ // prevent spurious errors from being emitted when the window is unloaded
60
+ this . script . onerror = ( ) => { } ;
76
61
this . script . parentNode . removeChild ( this . script ) ;
77
62
this . script = null ;
78
63
}
Original file line number Diff line number Diff line change @@ -201,6 +201,7 @@ class WS extends Transport {
201
201
doClose ( ) {
202
202
if ( typeof this . ws !== "undefined" ) {
203
203
this . ws . close ( ) ;
204
+ this . ws = null ;
204
205
}
205
206
}
206
207
You can’t perform that action at this time.
0 commit comments