@subiz/wsclient 4.0.18 → 4.0.20

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 (3) hide show
  1. package/package.json +1 -1
  2. package/webphone.js +6 -4
  3. package/webrtc.js +10 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/wsclient",
3
- "version": "4.0.18",
3
+ "version": "4.0.20",
4
4
  "main": "realtime.js",
5
5
  "scripts": {
6
6
  "test": "node realtime.test.js"
package/webphone.js CHANGED
@@ -129,7 +129,7 @@ function WebPhone(access_token, realtime) {
129
129
  }
130
130
 
131
131
  var base = '0123456789abcdef'
132
- this.makeCall = function (number, fromnumber) {
132
+ this.makeCall = function (number, fromnumber, streamPm) {
133
133
  // '11edc52b-2918-4d71-9058-f7285e29d894'
134
134
  var callid =
135
135
  randomString(8, base) +
@@ -142,12 +142,14 @@ function WebPhone(access_token, realtime) {
142
142
  '-' +
143
143
  randomString(12, base)
144
144
 
145
- current_call_id = callid
146
- return webrtcconn.makeCall(number, fromnumber, getMicroPermissions(), callid)
145
+ current_call_id = callid
146
+
147
+ if (!streamPm) streamPm = getMicroPermissions()
148
+ return webrtcconn.makeCall(number, fromnumber, streamPm, callid)
147
149
  }
148
150
 
149
151
  var current_call_id = ''
150
- this.getCurrentCallId = function () {
152
+ this.getCurrentCallId = function () {
151
153
  return current_call_id
152
154
  }
153
155
 
package/webrtc.js CHANGED
@@ -8,7 +8,8 @@ const servers = {
8
8
  // env = {RTCPeerConnection, RTCIceCandidate, RTCSessionDescription, setTimeout, setInterval, jsonify, parseJSON}
9
9
  // set env._is_webrtc_local to true for local testing
10
10
  function WebRTCConn(options) {
11
- let {apiUrl, access_token, accid, agid, realtime, callAPI, env, onTrack, onEvent} = options
11
+ let {apiUrl, access_token, accid, agid, realtime, callAPI, env, onTrack, onEvent, collect} = options
12
+ if (!collect) collect = function () {}
12
13
  if (!apiUrl) {
13
14
  apiUrl = 'https://callcenter.subiz.com.vn/wc/'
14
15
  if (env._is_webrtc_local) apiUrl = 'http://localhost:8008/'
@@ -390,19 +391,24 @@ function WebRTCConn(options) {
390
391
  }
391
392
 
392
393
  this.listenCall = (callid, cb) => {
394
+ let start = env.Date.now()
393
395
  initSession((err, connId) => {
394
396
  let url = `${apiUrl}listen?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}`
395
- callAPI('post', url, undefined, (body, code) => (code != 200 ? cb(body) : cb()))
397
+ callAPI('post', url, undefined, (body, code) => {
398
+ collect('listen_call', callid, env.Date.now() - start)
399
+ return code != 200 ? cb(body) : cb()
400
+ })
396
401
  })
397
402
  }
398
403
 
399
404
  this.joinCall = (callid, stream, cb) => {
400
- console.time('makecall' + callid)
405
+ let start = env.Date.now()
401
406
  initSession((err, connId) => {
402
407
  call2Connection[callid] = connId
403
408
  streams[connId] = stream
404
409
  let url = `${apiUrl}listen?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&talk=true`
405
410
  callAPI('post', url, undefined, (body, code) => {
411
+ collect('join_call', callid, env.Date.now() - start)
406
412
  if (code != 200) return cb(body, connId)
407
413
  console.timeEnd('makecall' + callid)
408
414
  if (code != 200) return cb(body, connId)
@@ -446,7 +452,6 @@ function WebRTCConn(options) {
446
452
  if (!callid) return rs({body: {}})
447
453
  let connId = call2Connection[callid]
448
454
  if (!connId) return rs({body: {}})
449
-
450
455
  let url = `${apiUrl}dtml?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&key={key}`
451
456
  initSession(() =>
452
457
  callAPI('post', url, undefined, (body, bode) => {
@@ -464,6 +469,7 @@ function WebRTCConn(options) {
464
469
  let url = `${apiUrl}refer?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&number={tonumber}`
465
470
  initSession(() =>
466
471
  callAPI('post', url, undefined, (body, code) => {
472
+ collect('listen_call', callid, env.Date.now() - start)
467
473
  body = parseJSON(body)
468
474
  return code != 200 ? rs({error: body}) : rs({body})
469
475
  }),