@subiz/wsclient 4.0.20 → 4.0.21
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/common.js +39 -1
- package/package.json +1 -1
- package/webrtc.js +14 -7
package/common.js
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
function logError(accid, userid, message, line) {
|
|
2
|
+
// 24-01-11 04:07:05 app ERROR api-8948967b6-qtpfx subiz /app/vendor/github.com/subiz/log/error.go:271 {"id":141534190473829746,"class":500,"code":"locked_account,internal","number":"8f2b97e9","fields":{"ip":"\"171.224.84.93\"","no_report":"true","user_agent":"\"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36\""}}
|
|
3
|
+
let ts = displayUTCLogTime(new Date())
|
|
4
|
+
let msg = JSON.stringify({
|
|
5
|
+
id: Date.now(),
|
|
6
|
+
class: 400,
|
|
7
|
+
code: 'frontend_error',
|
|
8
|
+
number: line
|
|
9
|
+
.split('')
|
|
10
|
+
.map((c) => c.charCodeAt(0).toString(16).padStart(2, '0'))
|
|
11
|
+
.join(''),
|
|
12
|
+
fields: {
|
|
13
|
+
message: JSON.stringify(message),
|
|
14
|
+
user_id: userid,
|
|
15
|
+
url: JSON.stringify(location.href),
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
xhrsend('POST', 'https://track.subiz.net/collect', `${ts} app ERROR dashboard ${accid} ${line} ${msg}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function displayUTCLogTime(date) {
|
|
23
|
+
let yyyy = date.getUTCFullYear().toString()
|
|
24
|
+
let yy = yyyy.substr(2, 2)
|
|
25
|
+
let mm = date.getUTCMonth() + 1
|
|
26
|
+
let dd = date.getUTCDate()
|
|
27
|
+
let hh = date.getUTCHours()
|
|
28
|
+
let MM = date.getUTCMinutes()
|
|
29
|
+
let ss = date.getUTCSeconds()
|
|
30
|
+
|
|
31
|
+
return `${yy}-${pad(mm)}-${pad(dd)} ${pad(hh)}:${pad(MM)}:${pad(ss)}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function pad(v) {
|
|
35
|
+
if (v < 10) return `0${v}`
|
|
36
|
+
return `${v}`
|
|
37
|
+
}
|
|
38
|
+
|
|
1
39
|
function dofetch(method, url, body, cb) {
|
|
2
40
|
let headers = {}
|
|
3
41
|
if (body) headers['content-type'] = 'text/plain'
|
|
@@ -78,4 +116,4 @@ function randomString(len, base) {
|
|
|
78
116
|
return str
|
|
79
117
|
}
|
|
80
118
|
|
|
81
|
-
module.exports = {xhrsend, parseJSON, Pubsub, randomString}
|
|
119
|
+
module.exports = {xhrsend, parseJSON, Pubsub, randomString, logError}
|
package/package.json
CHANGED
package/webrtc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var flow = require('@subiz/flow')
|
|
2
|
-
var {xhrsend, randomString} = require('./common.js')
|
|
2
|
+
var {logError, xhrsend, randomString} = require('./common.js')
|
|
3
3
|
const servers = {
|
|
4
4
|
iceServers: [{urls: ['stun:stun.l.google.com:19302']}],
|
|
5
5
|
}
|
|
@@ -291,7 +291,10 @@ function WebRTCConn(options) {
|
|
|
291
291
|
peer.setLocalDescription(answer).then(() => {
|
|
292
292
|
let url = `${apiUrl}finish?x-access-token=${access_token}&connection_id=${connId}&version=2&negotiation_id=${negid}`
|
|
293
293
|
callAPI('post', url, jsonify(answer), function (body, code) {
|
|
294
|
-
if (code !== 200)
|
|
294
|
+
if (code !== 200) {
|
|
295
|
+
logError(accid, agid, body, 'finish:295')
|
|
296
|
+
return console.error('CANNOT FINISH', body)
|
|
297
|
+
}
|
|
295
298
|
return
|
|
296
299
|
})
|
|
297
300
|
}),
|
|
@@ -303,7 +306,7 @@ function WebRTCConn(options) {
|
|
|
303
306
|
if (!callid) return
|
|
304
307
|
let type = ev.type
|
|
305
308
|
if (type === 'call_invited') {
|
|
306
|
-
if (
|
|
309
|
+
if (agid == call_info.from_number) return // ignore our own invite
|
|
307
310
|
serverCalls[callid] = call_info
|
|
308
311
|
return publish(ev)
|
|
309
312
|
}
|
|
@@ -359,6 +362,7 @@ function WebRTCConn(options) {
|
|
|
359
362
|
if (campaignid) url += `&campaign_id=${campaignid}`
|
|
360
363
|
callAPI('post', url, undefined, (body, code) => {
|
|
361
364
|
if (code != 200) {
|
|
365
|
+
logError(accid, agid, body, 'makeCall:365')
|
|
362
366
|
delete dialingRequest[callid]
|
|
363
367
|
endRequest[callid] = env.Date.now()
|
|
364
368
|
publish({created: env.Date.now(), type: 'call_ended', data: {call_info: {call_id: callid}}})
|
|
@@ -395,6 +399,7 @@ function WebRTCConn(options) {
|
|
|
395
399
|
initSession((err, connId) => {
|
|
396
400
|
let url = `${apiUrl}listen?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}`
|
|
397
401
|
callAPI('post', url, undefined, (body, code) => {
|
|
402
|
+
if (code != 200) logError(accid, agid, body, 'listenCall:399')
|
|
398
403
|
collect('listen_call', callid, env.Date.now() - start)
|
|
399
404
|
return code != 200 ? cb(body) : cb()
|
|
400
405
|
})
|
|
@@ -408,10 +413,9 @@ function WebRTCConn(options) {
|
|
|
408
413
|
streams[connId] = stream
|
|
409
414
|
let url = `${apiUrl}listen?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&talk=true`
|
|
410
415
|
callAPI('post', url, undefined, (body, code) => {
|
|
416
|
+
if (code != 200) logError(accid, agid, body, 'joinCall:413')
|
|
411
417
|
collect('join_call', callid, env.Date.now() - start)
|
|
412
418
|
if (code != 200) return cb(body, connId)
|
|
413
|
-
console.timeEnd('makecall' + callid)
|
|
414
|
-
if (code != 200) return cb(body, connId)
|
|
415
419
|
checkIceConnected(peers[connId], () => cb(undefined, connId))
|
|
416
420
|
})
|
|
417
421
|
})
|
|
@@ -436,6 +440,7 @@ function WebRTCConn(options) {
|
|
|
436
440
|
callAPI('post', url, undefined, (body, code) => {
|
|
437
441
|
body = parseJSON(body)
|
|
438
442
|
if (code != 200) {
|
|
443
|
+
logError(accid, agid, body, 'answerCall:442')
|
|
439
444
|
delete answerRequest[callid]
|
|
440
445
|
endRequest[callid] = now
|
|
441
446
|
publish({created: env.Date.now(), type: 'call_ended', data: {call_info: {call_id: callid}}})
|
|
@@ -454,7 +459,8 @@ function WebRTCConn(options) {
|
|
|
454
459
|
if (!connId) return rs({body: {}})
|
|
455
460
|
let url = `${apiUrl}dtml?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&key={key}`
|
|
456
461
|
initSession(() =>
|
|
457
|
-
callAPI('post', url, undefined, (body,
|
|
462
|
+
callAPI('post', url, undefined, (body, code) => {
|
|
463
|
+
if (code != 200) logError(accid, agid, body, 'sendDtmf:463')
|
|
458
464
|
body = parseJSON(body)
|
|
459
465
|
return code != 200 ? rs({error: body}) : rs({body})
|
|
460
466
|
}),
|
|
@@ -469,7 +475,8 @@ function WebRTCConn(options) {
|
|
|
469
475
|
let url = `${apiUrl}refer?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&number={tonumber}`
|
|
470
476
|
initSession(() =>
|
|
471
477
|
callAPI('post', url, undefined, (body, code) => {
|
|
472
|
-
|
|
478
|
+
if (code != 200) logError(accid, agid, body, 'transferCall:478')
|
|
479
|
+
collect('transfer_call', callid, env.Date.now() - start)
|
|
473
480
|
body = parseJSON(body)
|
|
474
481
|
return code != 200 ? rs({error: body}) : rs({body})
|
|
475
482
|
}),
|