@subiz/wsclient 4.0.37 → 4.0.38

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.
package/README.md CHANGED
@@ -90,8 +90,10 @@ Only `apiUrls` and the credentials needed by your server are required.
90
90
  There is no topic unsubscribe API. An explicit `reconnect()` replaces the
91
91
  connection without emitting `onInterrupted` for the old connection.
92
92
 
93
- Subscriptions are queued internally and sent one batch at a time. Small batches
94
- wait up to 100 ms from their first queued topic; a queue exceeding 50 topics can
93
+ Subscriptions are queued internally and sent one batch at a time. Duplicate
94
+ subscribers share the pending result, so every caller waits for
95
+ server confirmation and receives failures if the connection stops or is replaced.
96
+ Small batches wait up to 100 ms from their first queued topic; a queue exceeding 50 topics can
95
97
  flush earlier. A pending request can delay later batches. Stopping or replacing
96
98
  the connection also settles subscriptions still waiting in the queue.
97
99
 
@@ -353,7 +355,7 @@ not trigger that fallback. Callback failures are logged and isolated.
353
355
  | Method | Contract |
354
356
  | --- | --- |
355
357
  | `makeCall(number, fromnumber, streamPm, callid, campaignid, outboundcallentryid, channel)` | Requires a Promise for a live audio stream. Optional call ID is generated if absent; the final three arguments add call metadata. Resolves on call end or setup failure. No number fallback is performed here. |
356
- | `answerCall(callid, stream)` | Accepts a stream or Promise. Resolves after answer setup to `{body}` or `{error}`. |
358
+ | `answerCall(callid, stream)` | Accepts a stream or Promise. Resolves after answer setup to `{body}` or `{error}`. If the call ends during setup, resolves to `{error: 'call_ended'}`. |
357
359
  | `listenCall(callid, callback)` | Receive-only setup. Calls `callback(error, connectionId)` once ICE connects or setup fails. |
358
360
  | `joinCall(callid, stream, callback)` | Bidirectional setup with an already acquired stream. Same callback contract as `listenCall`. |
359
361
  | `hangupCall(callid)` | Ends locally and signals server hangup. Returns `undefined`. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/wsclient",
3
- "version": "4.0.37",
3
+ "version": "4.0.38",
4
4
  "main": "realtime.js",
5
5
  "files": [
6
6
  "realtime.js",
package/realtime.js CHANGED
@@ -309,7 +309,7 @@ function Realtime(apiUrls, credential, callAPI, accid, skipautoreconnect) {
309
309
  }
310
310
 
311
311
  // holds all topics that realtime must subscribed
312
- var topics = {}
312
+ var topics = Object.create(null)
313
313
 
314
314
  // stop the connection
315
315
  this.stop = function () {
@@ -344,18 +344,18 @@ function Realtime(apiUrls, credential, callAPI, accid, skipautoreconnect) {
344
344
  if (typeof events === 'string') events = [events]
345
345
  if (!Array.isArray(events)) return Promise.resolve({error: 'param should be an array or string'})
346
346
 
347
- // ignore already subscribed events
347
+ // Share pending subscriptions so duplicate callers also wait for the server.
348
+ var subscribingConn = conn
348
349
  var all = []
349
350
  for (var i = 0; i < events.length; i++) {
350
351
  var topic = events[i]
351
352
  if (!topic) continue
352
- if (topics[topic]) continue
353
- topics[topic] = true // mark so next time we wont subscribe this event (topic) again
354
- all.push(conn.subscribe(topic))
353
+ if (!topics[topic]) topics[topic] = subscribingConn.subscribe(topic)
354
+ all.push(topics[topic])
355
355
  }
356
356
  if (all.length === 0) return Promise.resolve({})
357
357
  return Promise.all(all).then(function () {
358
- if (!conn || conn.getStatus() == 'dead') return {error: 'dead'}
358
+ if (conn !== subscribingConn || subscribingConn.getStatus() == 'dead') return {error: 'dead'}
359
359
  return {}
360
360
  })
361
361
  }
@@ -397,7 +397,7 @@ function Realtime(apiUrls, credential, callAPI, accid, skipautoreconnect) {
397
397
  )
398
398
  conn = myconn
399
399
  var copyTopics = Object.keys(topics)
400
- topics = {}
400
+ topics = Object.create(null)
401
401
  // resubscribe all subscribed events
402
402
  return subscribe(copyTopics)
403
403
  }
package/webrtc.js CHANGED
@@ -1138,7 +1138,7 @@ function WebRTCConn(options) {
1138
1138
  } catch (err) {
1139
1139
  delete answerRequest[callid]
1140
1140
  let reason = failOperation(op, err)
1141
- return reason === 'call_ended' ? {body: getLocalEndedCall(callid)} : {error: reason}
1141
+ return {error: reason}
1142
1142
  } finally {
1143
1143
  op.dispose()
1144
1144
  }