angelia.io 3.4.82 → 3.4.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client/index.js +12 -13
  2. package/package.json +1 -1
package/client/index.js CHANGED
@@ -280,13 +280,6 @@ export default class Client {
280
280
  // to force disconnect
281
281
  this.on('disconnect', this.disconnect)
282
282
 
283
- // to try to close the connection nicely
284
- window.addEventListener(
285
- 'unload',
286
- () => this.disconnect(true),
287
- true,
288
- )
289
-
290
283
  // to send messages fast without waiting for the connection
291
284
  shouldConnect && this.connect()
292
285
  }
@@ -315,9 +308,13 @@ export default class Client {
315
308
  Promise.resolve().then(this.send)
316
309
  }
317
310
  if (c) {
318
- this.messages.push([k, v, this.callback(c)])
311
+ const { i, promise } = this.callback(c)
312
+ this.messages.push([k, v, i])
313
+ return promise
319
314
  } else if (typeof v === 'function') {
320
- this.messages.push([k, this.null, this.callback(v)])
315
+ const { i, promise } = this.callback(v)
316
+ this.messages.push([k, this.null, i])
317
+ return promise
321
318
  } else if (v !== null && v !== undefined) {
322
319
  this.messages.push([k, v])
323
320
  } else {
@@ -362,9 +359,11 @@ export default class Client {
362
359
  // PRIVATE API
363
360
 
364
361
  callback(c) {
362
+ let resolve
363
+ const promise = new Promise(r => (resolve = r))
365
364
  let i = this.callbacks.length
366
- this.callbacks[i] = c
367
- return i
365
+ this.callbacks[i] = (...args) => resolve(c(...args))
366
+ return { i, promise }
368
367
  }
369
368
  oncallback(d) {
370
369
  this.callbacks[d[0]](...d[1])
@@ -381,7 +380,7 @@ export default class Client {
381
380
  e[2]
382
381
  ? (...d) => {
383
382
  this.emit('', [e[2], d])
384
- }
383
+ }
385
384
  : null,
386
385
  )
387
386
  }
@@ -397,7 +396,7 @@ export default class Client {
397
396
  e[2]
398
397
  ? (...d) => {
399
398
  this.emit('', [e[2], d])
400
- }
399
+ }
401
400
  : null,
402
401
  )
403
402
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "3.4.82",
3
+ "version": "3.4.84",
4
4
  "description": "WebSockets Server and Client API for node.js and the browser, with rooms support.",
5
5
  "author": "@titoBouzout @boredofnames",
6
6
  "license": "GPL",