@subiz/wsclient 4.0.5 → 4.0.7

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/package.json +2 -2
  2. package/webrtc.js +7 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/wsclient",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "main": "realtime.js",
5
5
  "scripts": {
6
6
  "test": "node realtime.test.js"
@@ -14,7 +14,7 @@
14
14
  "homepage": "https://github.com/subiz/wsclient#readme",
15
15
  "description": "",
16
16
  "devDependencies": {
17
- "tape": "^5.6.1"
17
+ "tape": "^5.6.3"
18
18
  },
19
19
  "dependencies": {
20
20
  "@subiz/flow": "^1.0.9",
package/webrtc.js CHANGED
@@ -4,9 +4,9 @@ const servers = {
4
4
  iceServers: [{urls: ['stun:stun.l.google.com:19302?transport=tcp']}],
5
5
  }
6
6
 
7
- // let connId = 'webrtc' + sb.randomString(20)
7
+ // let connId = 'webrtc' + randomString(20)
8
8
  // env = {RTCPeerConnection, RTCIceCandidate, RTCSessionDescription, setTimeout, setInterval, jsonify, parseJSON}
9
- // setting env._is_webrtc_local to true for local testing
9
+ // set env._is_webrtc_local to true for local testing
10
10
  function WebRTCConn(options) {
11
11
  let {apiUrl, access_token, accid, agid, connId, realtime, callAPI, env, onTrack, onEvent} = options
12
12
  if (!apiUrl) {
@@ -243,8 +243,8 @@ function WebRTCConn(options) {
243
243
  }
244
244
  })
245
245
 
246
- this.makeCall = (number, fromnumber, stream) => {
247
- let callid = 'webcall-' + randomString(30)
246
+ this.makeCall = (number, fromnumber, stream, callid) => {
247
+ if (!callid) callid = 'webcall-' + randomString(30)
248
248
  let now = env.Date.now()
249
249
  let call = {
250
250
  account_id: accid,
@@ -294,8 +294,9 @@ function WebRTCConn(options) {
294
294
  }
295
295
  call.status = 'ended'
296
296
  call.ended = env.Date.now()
297
- callAPI('post', `${apiUrl}hangup?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}`)
298
297
  publish({type: 'call_ended', data: {call_info: {call_id: callid}}})
298
+
299
+ callAPI('post', `${apiUrl}hangup?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}`)
299
300
  }
300
301
 
301
302
  this.listenCall = (callid, cb) => {
@@ -319,7 +320,7 @@ function WebRTCConn(options) {
319
320
 
320
321
  this.answerCall = (callid, stream) => {
321
322
  let call = activeCalls[callid]
322
- if (!call || call.status == 'ended') return Promise.resolve({error: 'call_ended'})
323
+ if (call && call.status == 'ended') return Promise.resolve({error: 'call_ended'})
323
324
  let now = env.Date.now()
324
325
  if (answerRequest[callid]) return Promise.resolve({body: call})
325
326
  answerRequest[callid] = now