Skip to content

Commit d416b09

Browse files
committed
- prevent calling close and send without _ws
- make `close-handler` work only if event source = `_ws` - use `on` instead of `addEventListener` for `offline` event - bump version
1 parent 24b6432 commit d416b09

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed

CHANGELOG.md

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

3+
## v0.0.17
4+
5+
- prevent calling `close` and `send` without `_ws`
6+
- make `close-handler` work only if event source = `_ws`
7+
- use `on` instead of `addEventListener` for `offline` event
8+
9+
310
## v0.0.16
411

512
- due to untrustable `close` event, we move close event handler to a standalone function, and call it from both close and offline event.

dist/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,13 @@
173173
}
174174
return this._ws.removeEventListener(t, this._hdr.get(cb), o);
175175
}, ref$.close = function(c, r){
176-
return this._ws.close(c, r);
176+
if (this._ws) {
177+
return this._ws.close(c, r);
178+
}
177179
}, ref$.send = function(d){
178-
return this._ws.send(this._scope + "|" + d);
180+
if (this._ws) {
181+
return this._ws.send(this._scope + "|" + d);
182+
}
179183
}, ref$);
180184
Object.defineProperties(ews.prototype, {
181185
bufferedAmount: {
@@ -302,6 +306,7 @@
302306
var this$ = this;
303307
opt == null && (opt = {});
304308
return new Promise(function(res, rej){
309+
var that;
305310
if (this$._ws) {
306311
return rej(err(1011));
307312
}
@@ -313,10 +318,13 @@
313318
d._ws = this$._ws;
314319
return d._installEventListeners();
315320
});
316-
this$.closeHandler = function(){
321+
this$.closeHandler = function(_ws){
317322
if (!this._ws) {
318323
return;
319324
}
325+
if (this._ws !== _ws) {
326+
return;
327+
}
320328
this._ws = null;
321329
this._svl.map(function(d){
322330
return d._ws = null;
@@ -333,8 +341,9 @@
333341
window.addEventListener('offline', function(){
334342
return this$.disconnect();
335343
});
344+
that = this$;
336345
this$._ws.addEventListener('close', function(){
337-
return this$.closeHandler();
346+
return that.closeHandler(this);
338347
});
339348
this$._ws.addEventListener('open', function(){
340349
if (!this$._ctrl.canceller) {
@@ -413,7 +422,7 @@
413422
};
414423
});
415424
this._ws.close();
416-
this.closeHandler();
425+
this.closeHandler(this._ws);
417426
return ret;
418427
};
419428
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
_connection: null,
88
_ws: opt.ws
99
});
10-
this._ws.addEventListener('offline', function(){
10+
this._ws.on('offline', function(){
1111
if (!(this$._connection && this$._sws)) {
1212
return;
1313
}

0 commit comments

Comments
 (0)