@subiz/wsclient 4.0.19 → 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.
- package/package.json +1 -1
- package/webrtc.js +10 -4
package/package.json
CHANGED
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) =>
|
|
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
|
-
|
|
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
|
}),
|