@subiz/wsclient 4.0.2 → 4.0.4
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 +19 -13
package/package.json
CHANGED
package/webrtc.js
CHANGED
|
@@ -31,6 +31,7 @@ function WebRTCConn(options) {
|
|
|
31
31
|
let activeCalls = {}
|
|
32
32
|
|
|
33
33
|
let dialingRequest = {}
|
|
34
|
+
let answerRequest = {}
|
|
34
35
|
let endRequest = {}
|
|
35
36
|
|
|
36
37
|
let subscribe = realtime.subscribe([
|
|
@@ -70,10 +71,8 @@ function WebRTCConn(options) {
|
|
|
70
71
|
if (!needConnect) return
|
|
71
72
|
peer = new env.RTCPeerConnection(servers)
|
|
72
73
|
let mypeer = peer
|
|
73
|
-
window.peer = peer
|
|
74
74
|
|
|
75
75
|
readyToSendCandidate = new env.Promise((rs) => (readyToSendCandidateResolve = rs))
|
|
76
|
-
|
|
77
76
|
peer.ontrack = (event) => {
|
|
78
77
|
if (peer != mypeer) return // outdated
|
|
79
78
|
onTrack && onTrack(event)
|
|
@@ -150,30 +149,37 @@ function WebRTCConn(options) {
|
|
|
150
149
|
}
|
|
151
150
|
})
|
|
152
151
|
|
|
153
|
-
Object.keys(calls
|
|
152
|
+
Object.keys(calls).map((callid) => {
|
|
154
153
|
let call = calls[callid]
|
|
155
|
-
if (endRequest[callid]
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
154
|
+
if (!endRequest[callid]) return
|
|
155
|
+
if (!call || call.status == 'ended') return
|
|
156
|
+
calls[callid] = Object.assign({}, call, {
|
|
157
|
+
call_id: callid,
|
|
158
|
+
ended: endRequest[callid],
|
|
159
|
+
status: 'ended',
|
|
160
|
+
hangup_code: 'cancel',
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
Object.keys(answerRequest).map((callid) => {
|
|
165
|
+
let call = calls[callid]
|
|
166
|
+
if (!call) return
|
|
167
|
+
call.answer_requested = answerRequest[callid]
|
|
163
168
|
})
|
|
164
169
|
return calls
|
|
165
170
|
}
|
|
166
171
|
|
|
167
172
|
let call = activeCalls[callid]
|
|
173
|
+
if (!call && dialingRequest[callid]) call = dialingRequest[callid]
|
|
168
174
|
if (endRequest[callid] && call && call.status != 'ended') {
|
|
169
|
-
|
|
175
|
+
call = Object.assign({}, call, {
|
|
170
176
|
call_id: callid,
|
|
171
177
|
ended: endRequest[callid],
|
|
172
178
|
status: 'ended',
|
|
173
179
|
hangup_code: 'cancel',
|
|
174
180
|
})
|
|
175
181
|
}
|
|
176
|
-
if (
|
|
182
|
+
if (answerRequest[callid]) call = Object.assign({}, call, {answer_requested: answerRequest[callid]})
|
|
177
183
|
return call
|
|
178
184
|
}
|
|
179
185
|
|