@subiz/wsclient 4.0.10 → 4.0.12
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 +29 -17
package/package.json
CHANGED
package/webrtc.js
CHANGED
|
@@ -222,7 +222,17 @@ function WebRTCConn(options) {
|
|
|
222
222
|
readyToSendCandidateResolve()
|
|
223
223
|
if (pendingStream && pendingStream != currentStream) {
|
|
224
224
|
currentStream = pendingStream
|
|
225
|
-
currentStream.getTracks().forEach((track) =>
|
|
225
|
+
currentStream.getTracks().forEach((track) => {
|
|
226
|
+
let replaced = false
|
|
227
|
+
peer.getSenders().forEach((sender) => {
|
|
228
|
+
if (!sender.track) return
|
|
229
|
+
if (sender.track.kind != track.kind) return
|
|
230
|
+
sender.replaceTrack(track)
|
|
231
|
+
replaced = true
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
if (!replaced) peer.addTrack(track, currentStream)
|
|
235
|
+
})
|
|
226
236
|
}
|
|
227
237
|
pendingStream = undefined
|
|
228
238
|
return peer.createAnswer()
|
|
@@ -257,7 +267,7 @@ function WebRTCConn(options) {
|
|
|
257
267
|
}
|
|
258
268
|
})
|
|
259
269
|
|
|
260
|
-
this.makeCall = (number, fromnumber,
|
|
270
|
+
this.makeCall = (number, fromnumber, streamPm, callid) => {
|
|
261
271
|
if (!callid) callid = 'webcall-' + randomString(30)
|
|
262
272
|
let now = env.Date.now()
|
|
263
273
|
let call = {
|
|
@@ -273,26 +283,28 @@ function WebRTCConn(options) {
|
|
|
273
283
|
dialingRequest[callid] = call
|
|
274
284
|
publish({type: 'call_ringing', data: {call_info: {call_id: callid}}}) // fake dialing
|
|
275
285
|
return new env.Promise((rs) => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
endRequest[callid] = env.Date.now()
|
|
280
|
-
publish({type: 'call_ended', data: {call_info: {call_id: callid}}})
|
|
281
|
-
return rs({error: err})
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
let url = `${apiUrl}call?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&number=${number}&from_number=${fromnumber}`
|
|
285
|
-
callAPI('post', url, undefined, (body, code) => {
|
|
286
|
-
if (code != 200) {
|
|
286
|
+
streamPm.then(stream => {
|
|
287
|
+
this.joinCall(callid, stream, (err) => {
|
|
288
|
+
if (err) {
|
|
287
289
|
delete dialingRequest[callid]
|
|
288
290
|
endRequest[callid] = env.Date.now()
|
|
289
291
|
publish({type: 'call_ended', data: {call_info: {call_id: callid}}})
|
|
290
292
|
return rs({error: err})
|
|
291
293
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
|
|
295
|
+
let url = `${apiUrl}call?x-access-token=${access_token}&connection_id=${connId}&call_id=${callid}&number=${number}&from_number=${fromnumber}`
|
|
296
|
+
callAPI('post', url, undefined, (body, code) => {
|
|
297
|
+
if (code != 200) {
|
|
298
|
+
delete dialingRequest[callid]
|
|
299
|
+
endRequest[callid] = env.Date.now()
|
|
300
|
+
publish({type: 'call_ended', data: {call_info: {call_id: callid}}})
|
|
301
|
+
return rs({error: err})
|
|
302
|
+
}
|
|
303
|
+
body = parseJSON(body)
|
|
304
|
+
if (body) activeCalls[callid] = body
|
|
305
|
+
delete dialingRequest[callid]
|
|
306
|
+
rs({body})
|
|
307
|
+
})
|
|
296
308
|
})
|
|
297
309
|
})
|
|
298
310
|
})
|