Skip to content

Commit 24b6432

Browse files
committed
- due to untrustable close event, we move close event handler to a standalone function, and call it from both close and offline event.
- bump version
1 parent f15cedc commit 24b6432

File tree

9 files changed

+95
-57
lines changed

9 files changed

+95
-57
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Logs
22

3+
## v0.0.16
4+
5+
- due to untrustable `close` event, we move close event handler to a standalone function, and call it from both close and offline event.
6+
7+
38
## v0.0.15
49

510
- fire `offline` event when offline event received from window.

dist/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,28 @@
313313
d._ws = this$._ws;
314314
return d._installEventListeners();
315315
});
316-
window.addEventListener('offline', function(){
317-
this$.fire('offline');
318-
return this$.disconnect();
319-
});
320-
this$._ws.addEventListener('close', function(){
321-
this$._ws = null;
322-
this$._svl.map(function(d){
316+
this$.closeHandler = function(){
317+
if (!this._ws) {
318+
return;
319+
}
320+
this._ws = null;
321+
this._svl.map(function(d){
323322
return d._ws = null;
324323
});
325-
if (this$._s !== 2) {
324+
if (this._s !== 2) {
326325
return rej(err(0));
327326
}
328-
this$._status(0);
329-
if (this$._ctrl.disconnector) {
330-
return this$._ctrl.disconnector.res();
327+
this._status(0);
328+
this.fire('offline');
329+
if (this._ctrl.disconnector) {
330+
return this._ctrl.disconnector.res();
331331
}
332+
};
333+
window.addEventListener('offline', function(){
334+
return this$.disconnect();
335+
});
336+
this$._ws.addEventListener('close', function(){
337+
return this$.closeHandler();
332338
});
333339
this$._ws.addEventListener('open', function(){
334340
if (!this$._ctrl.canceller) {
@@ -407,6 +413,7 @@
407413
};
408414
});
409415
this._ws.close();
416+
this.closeHandler();
410417
return ret;
411418
};
412419
ref$.cancel = function(){

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sdb-client.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@
77
_connection: null,
88
_ws: opt.ws
99
});
10+
this._ws.addEventListener('offline', function(){
11+
if (!(this$._connection && this$._sws)) {
12+
return;
13+
}
14+
this$._connection = null;
15+
this$._sws = null;
16+
return this$.fire('close');
17+
});
1018
this._ws.addEventListener('close', function(){
19+
if (!(this$._connection && this$._sws)) {
20+
return;
21+
}
1122
this$._connection = null;
1223
this$._sws = null;
1324
return this$.fire('close');

0 commit comments

Comments
 (0)