@subiz/wsclient 4.0.25 → 4.0.27
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 +13 -4
package/package.json
CHANGED
package/webrtc.js
CHANGED
|
@@ -5,7 +5,7 @@ const servers = {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
// let connId = 'webrtc' + randomString(20)
|
|
8
|
-
// env = {RTCPeerConnection, RTCIceCandidate, RTCSessionDescription, setTimeout, setInterval, jsonify, parseJSON}
|
|
8
|
+
// env = {RTCPeerConnection, RTCIceCandidate, RTCSessionDescription, setTimeout, setInterval, clearInterval, jsonify, parseJSON}
|
|
9
9
|
// set env._is_webrtc_local to true for local testing
|
|
10
10
|
function WebRTCConn(options) {
|
|
11
11
|
let {apiUrl, access_token, accid, agid, realtime, callAPI, env, onTrack, onEvent, collect} = options
|
|
@@ -15,6 +15,7 @@ function WebRTCConn(options) {
|
|
|
15
15
|
if (env._is_webrtc_local) apiUrl = 'http://localhost:8008/'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
dead = false
|
|
18
19
|
callAPI = callAPI || xhrsend // allow hook
|
|
19
20
|
let parseJSON = (str) => {
|
|
20
21
|
try {
|
|
@@ -48,6 +49,7 @@ function WebRTCConn(options) {
|
|
|
48
49
|
|
|
49
50
|
peer.onicecandidate = (event) => {
|
|
50
51
|
if (!event.candidate) return
|
|
52
|
+
if (dead) return
|
|
51
53
|
let url = `${apiUrl}ice-candidates?x-access-token=${access_token}&connection_id=${connId}&account_id=${accid}`
|
|
52
54
|
callAPI('post', url, jsonify(event.candidate))
|
|
53
55
|
}
|
|
@@ -86,6 +88,7 @@ function WebRTCConn(options) {
|
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
let syncCallWithServer = () => {
|
|
91
|
+
if (dead) return env.clearInterval(_syncCallInterval)
|
|
89
92
|
let url = `${apiUrl}calls?x-access-token=${access_token}&account_id=${accid}`
|
|
90
93
|
callAPI('get', url, undefined, function (body, code) {
|
|
91
94
|
if (code != 200) return
|
|
@@ -141,9 +144,10 @@ function WebRTCConn(options) {
|
|
|
141
144
|
})
|
|
142
145
|
}
|
|
143
146
|
syncCallWithServer()
|
|
144
|
-
env.setInterval(syncCallWithServer, 10000)
|
|
147
|
+
let _syncCallInterval = env.setInterval(syncCallWithServer, 10000)
|
|
145
148
|
|
|
146
149
|
let cleanEndedCall = () => {
|
|
150
|
+
if (dead) return env.clearInterval(_endcalInterval)
|
|
147
151
|
Object.keys(endRequest).map((callid) => {
|
|
148
152
|
if (env.Date.now() - endRequest[callid] > 60000) delete endRequest[callid]
|
|
149
153
|
})
|
|
@@ -166,7 +170,7 @@ function WebRTCConn(options) {
|
|
|
166
170
|
if (env.Date.now() - call.ended > 60000) delete call2Connection[callid]
|
|
167
171
|
})
|
|
168
172
|
}
|
|
169
|
-
env.setInterval(cleanEndedCall, 120000)
|
|
173
|
+
let _endcalInterval = env.setInterval(cleanEndedCall, 120000)
|
|
170
174
|
|
|
171
175
|
let endcallCb = {}
|
|
172
176
|
let publish = (ev) => {
|
|
@@ -197,6 +201,10 @@ function WebRTCConn(options) {
|
|
|
197
201
|
onEvent && onEvent(ev)
|
|
198
202
|
}
|
|
199
203
|
|
|
204
|
+
this.shutdown = () => {
|
|
205
|
+
dead = true
|
|
206
|
+
}
|
|
207
|
+
|
|
200
208
|
this.matchCall = (callid) => {
|
|
201
209
|
if (!callid || callid == '*' || callid == '-') {
|
|
202
210
|
let calls = Object.assign({}, serverCalls)
|
|
@@ -252,6 +260,7 @@ function WebRTCConn(options) {
|
|
|
252
260
|
}
|
|
253
261
|
|
|
254
262
|
realtime.onEvent((ev) => {
|
|
263
|
+
if (dead) return
|
|
255
264
|
if (!ev || !ev.type || !ev.data) return
|
|
256
265
|
if (env._is_webrtc_local && ev.user_id != '8') return // local
|
|
257
266
|
if (!env._is_webrtc_local && ev.user_id != '9') return // prod
|
|
@@ -424,7 +433,7 @@ function WebRTCConn(options) {
|
|
|
424
433
|
initSession((err, connId) => {
|
|
425
434
|
call2Connection[callid] = connId
|
|
426
435
|
streams[connId] = stream
|
|
427
|
-
let url = `${apiUrl}listen?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&talk=true&account_id
|
|
436
|
+
let url = `${apiUrl}listen?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&talk=true&account_id=${accid}`
|
|
428
437
|
callAPI('post', url, undefined, (body, code) => {
|
|
429
438
|
if (code != 200) logError(accid, agid, body, 'joinCall:413')
|
|
430
439
|
collect('join_call', callid, env.Date.now() - start)
|