@wazo/sdk 0.39.15 → 0.40.0
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/README.md +2 -2
- package/dist/wazo-sdk.js +12 -12
- package/esm/__tests__/api-client.test.js +0 -10
- package/esm/__tests__/web-rtc-client.test.js +2 -15
- package/esm/api/chatd.js +0 -1
- package/esm/api/dird.js +7 -10
- package/esm/checker/checks/ice-ipv4.js +2 -3
- package/esm/checker/checks/symmetric-nat.js +7 -4
- package/esm/domain/AdHocAPIConference.js +1 -1
- package/esm/domain/CallLog.js +1 -1
- package/esm/domain/Contact.js +2 -1
- package/esm/domain/MeetingAuthorization.js +6 -0
- package/esm/domain/Phone/CTIPhone.js +2 -0
- package/esm/domain/Phone/WebRTCPhone.js +16 -18
- package/esm/domain/Session.js +2 -2
- package/esm/domain/__tests__/Agent.test.js +0 -2
- package/esm/domain/__tests__/Call.test.js +0 -1
- package/esm/domain/__tests__/CallLog.test.js +0 -1
- package/esm/domain/__tests__/CallSession.test.js +1 -2
- package/esm/domain/__tests__/Contact.test.js +2 -4
- package/esm/domain/__tests__/IndirectTransfer.test.js +0 -1
- package/esm/domain/__tests__/Profile.test.js +0 -1
- package/esm/domain/__tests__/Room.test.js +1 -25
- package/esm/domain/__tests__/Session.test.js +13 -14
- package/esm/domain/__tests__/SipLine.test.js +2 -3
- package/esm/index.js +42 -88
- package/esm/lib/WazoSessionDescriptionHandler.js +9 -15
- package/esm/service/IssueReporter.js +1 -3
- package/esm/service/__tests__/IssueReporter.test.js +0 -1
- package/esm/simple/Phone.js +1 -1
- package/esm/simple/Websocket.js +2 -2
- package/esm/simple/index.js +5 -4
- package/esm/simple/room/Room.js +15 -15
- package/esm/simple/room/SipRoom.js +1 -1
- package/esm/simple/room/Stream.js +1 -2
- package/esm/simple/room/__tests__/Participant.test.js +0 -2
- package/esm/simple/room/__tests__/RemoteParticipant.test.js +1 -2
- package/esm/types/api/auth.d.ts +2 -2
- package/esm/types/api/auth.d.ts.map +1 -1
- package/esm/types/api/call-logd.d.ts +3 -3
- package/esm/types/api/call-logd.d.ts.map +1 -1
- package/esm/types/api/chatd.d.ts +9 -22
- package/esm/types/api/chatd.d.ts.map +1 -1
- package/esm/types/api/dird.d.ts +21 -14
- package/esm/types/api/dird.d.ts.map +1 -1
- package/esm/types/checker/checks/ice-ipv4.d.ts.map +1 -1
- package/esm/types/checker/checks/index.d.ts +1 -1
- package/esm/types/checker/checks/symmetric-nat.d.ts.map +1 -1
- package/esm/types/checker/checks/webrtc-transport.d.ts +2 -2
- package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -1
- package/esm/types/domain/Agent.d.ts +1 -1
- package/esm/types/domain/Agent.d.ts.map +1 -1
- package/esm/types/domain/CallLog.d.ts +14 -26
- package/esm/types/domain/CallLog.d.ts.map +1 -1
- package/esm/types/domain/CallSession.d.ts +3 -4
- package/esm/types/domain/CallSession.d.ts.map +1 -1
- package/esm/types/domain/Contact.d.ts +8 -0
- package/esm/types/domain/Contact.d.ts.map +1 -1
- package/esm/types/domain/MeetingAuthorization.d.ts +6 -0
- package/esm/types/domain/MeetingAuthorization.d.ts.map +1 -1
- package/esm/types/domain/Phone/CTIPhone.d.ts +2 -0
- package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
- package/esm/types/domain/Phone/Phone.d.ts +12 -2
- package/esm/types/domain/Phone/Phone.d.ts.map +1 -1
- package/esm/types/domain/Phone/WebRTCPhone.d.ts +24 -20
- package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/esm/types/domain/Room.d.ts +10 -12
- package/esm/types/domain/Room.d.ts.map +1 -1
- package/esm/types/domain/Session.d.ts +1 -1
- package/esm/types/domain/Session.d.ts.map +1 -1
- package/esm/types/domain/SipLine.d.ts +3 -3
- package/esm/types/domain/SipLine.d.ts.map +1 -1
- package/esm/types/domain/types.d.ts +64 -10
- package/esm/types/domain/types.d.ts.map +1 -1
- package/esm/types/index.d.ts +51 -314
- package/esm/types/index.d.ts.map +1 -1
- package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +5 -4
- package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
- package/esm/types/service/CallApi.d.ts +3 -3
- package/esm/types/service/CallApi.d.ts.map +1 -1
- package/esm/types/service/IssueReporter.d.ts.map +1 -1
- package/esm/types/simple/Auth.d.ts +0 -40
- package/esm/types/simple/Auth.d.ts.map +1 -1
- package/esm/types/simple/Phone.d.ts +0 -113
- package/esm/types/simple/Phone.d.ts.map +1 -1
- package/esm/types/simple/Websocket.d.ts +0 -16
- package/esm/types/simple/Websocket.d.ts.map +1 -1
- package/esm/types/simple/index.d.ts +8 -8
- package/esm/types/simple/index.d.ts.map +1 -1
- package/esm/types/simple/room/Participant.d.ts +4 -3
- package/esm/types/simple/room/Participant.d.ts.map +1 -1
- package/esm/types/simple/room/Room.d.ts +29 -18
- package/esm/types/simple/room/Room.d.ts.map +1 -1
- package/esm/types/simple/room/SipRoom.d.ts +1 -1
- package/esm/types/simple/room/SipRoom.d.ts.map +1 -1
- package/esm/types/simple/room/Stream.d.ts +1 -1
- package/esm/types/simple/room/Stream.d.ts.map +1 -1
- package/esm/types/utils/PhoneNumberUtil.d.ts +1 -1
- package/esm/types/utils/PhoneNumberUtil.d.ts.map +1 -1
- package/esm/types/utils/api-requester.d.ts +1 -1
- package/esm/types/utils/api-requester.d.ts.map +1 -1
- package/esm/types/utils/sdp.d.ts +20 -5
- package/esm/types/utils/sdp.d.ts.map +1 -1
- package/esm/types/web-rtc-client.d.ts +51 -49
- package/esm/types/web-rtc-client.d.ts.map +1 -1
- package/esm/types/websocket-client.d.ts.map +1 -1
- package/esm/utils/__tests__/PhoneNumberUtil.test.js +0 -6
- package/esm/utils/__tests__/api-requester.test.js +0 -2
- package/esm/utils/__tests__/sdp.test.js +4 -18
- package/esm/utils/api-requester.js +1 -2
- package/esm/utils/sdp.js +8 -3
- package/esm/web-rtc-client.js +99 -136
- package/esm/websocket-client.js +1 -2
- package/index.js +1 -0
- package/lib/__tests__/api-client.test.js +0 -10
- package/lib/__tests__/web-rtc-client.test.js +2 -15
- package/lib/api/chatd.js +0 -1
- package/lib/api/dird.js +19 -22
- package/lib/checker/checks/ice-ipv4.js +2 -3
- package/lib/checker/checks/symmetric-nat.js +7 -4
- package/lib/domain/AdHocAPIConference.js +1 -1
- package/lib/domain/CallLog.js +1 -1
- package/lib/domain/Contact.js +2 -1
- package/lib/domain/MeetingAuthorization.js +6 -0
- package/lib/domain/Phone/CTIPhone.js +2 -0
- package/lib/domain/Phone/WebRTCPhone.js +16 -18
- package/lib/domain/Session.js +2 -2
- package/lib/domain/__tests__/Agent.test.js +0 -2
- package/lib/domain/__tests__/Call.test.js +0 -1
- package/lib/domain/__tests__/CallLog.test.js +0 -1
- package/lib/domain/__tests__/CallSession.test.js +1 -2
- package/lib/domain/__tests__/Contact.test.js +2 -4
- package/lib/domain/__tests__/IndirectTransfer.test.js +0 -1
- package/lib/domain/__tests__/Profile.test.js +0 -1
- package/lib/domain/__tests__/Room.test.js +1 -25
- package/lib/domain/__tests__/Session.test.js +13 -14
- package/lib/domain/__tests__/SipLine.test.js +2 -3
- package/lib/index.js +93 -99
- package/lib/lib/WazoSessionDescriptionHandler.js +9 -15
- package/lib/service/IssueReporter.js +1 -3
- package/lib/service/__tests__/IssueReporter.test.js +0 -1
- package/lib/simple/Phone.js +1 -1
- package/lib/simple/Websocket.js +2 -2
- package/lib/simple/index.js +2 -1
- package/lib/simple/room/Room.js +17 -15
- package/lib/simple/room/SipRoom.js +1 -1
- package/lib/simple/room/Stream.js +1 -2
- package/lib/simple/room/__tests__/Participant.test.js +0 -2
- package/lib/simple/room/__tests__/RemoteParticipant.test.js +1 -2
- package/lib/types/api/auth.d.ts +2 -2
- package/lib/types/api/auth.d.ts.map +1 -1
- package/lib/types/api/call-logd.d.ts +3 -3
- package/lib/types/api/call-logd.d.ts.map +1 -1
- package/lib/types/api/chatd.d.ts +9 -22
- package/lib/types/api/chatd.d.ts.map +1 -1
- package/lib/types/api/dird.d.ts +21 -14
- package/lib/types/api/dird.d.ts.map +1 -1
- package/lib/types/checker/checks/ice-ipv4.d.ts.map +1 -1
- package/lib/types/checker/checks/index.d.ts +1 -1
- package/lib/types/checker/checks/symmetric-nat.d.ts.map +1 -1
- package/lib/types/checker/checks/webrtc-transport.d.ts +2 -2
- package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -1
- package/lib/types/domain/Agent.d.ts +1 -1
- package/lib/types/domain/Agent.d.ts.map +1 -1
- package/lib/types/domain/CallLog.d.ts +14 -26
- package/lib/types/domain/CallLog.d.ts.map +1 -1
- package/lib/types/domain/CallSession.d.ts +3 -4
- package/lib/types/domain/CallSession.d.ts.map +1 -1
- package/lib/types/domain/Contact.d.ts +8 -0
- package/lib/types/domain/Contact.d.ts.map +1 -1
- package/lib/types/domain/MeetingAuthorization.d.ts +6 -0
- package/lib/types/domain/MeetingAuthorization.d.ts.map +1 -1
- package/lib/types/domain/Phone/CTIPhone.d.ts +2 -0
- package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
- package/lib/types/domain/Phone/Phone.d.ts +12 -2
- package/lib/types/domain/Phone/Phone.d.ts.map +1 -1
- package/lib/types/domain/Phone/WebRTCPhone.d.ts +24 -20
- package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/lib/types/domain/Room.d.ts +10 -12
- package/lib/types/domain/Room.d.ts.map +1 -1
- package/lib/types/domain/Session.d.ts +1 -1
- package/lib/types/domain/Session.d.ts.map +1 -1
- package/lib/types/domain/SipLine.d.ts +3 -3
- package/lib/types/domain/SipLine.d.ts.map +1 -1
- package/lib/types/domain/types.d.ts +64 -10
- package/lib/types/domain/types.d.ts.map +1 -1
- package/lib/types/index.d.ts +51 -314
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +5 -4
- package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
- package/lib/types/service/CallApi.d.ts +3 -3
- package/lib/types/service/CallApi.d.ts.map +1 -1
- package/lib/types/service/IssueReporter.d.ts.map +1 -1
- package/lib/types/simple/Auth.d.ts +0 -40
- package/lib/types/simple/Auth.d.ts.map +1 -1
- package/lib/types/simple/Phone.d.ts +0 -113
- package/lib/types/simple/Phone.d.ts.map +1 -1
- package/lib/types/simple/Websocket.d.ts +0 -16
- package/lib/types/simple/Websocket.d.ts.map +1 -1
- package/lib/types/simple/index.d.ts +8 -8
- package/lib/types/simple/index.d.ts.map +1 -1
- package/lib/types/simple/room/Participant.d.ts +4 -3
- package/lib/types/simple/room/Participant.d.ts.map +1 -1
- package/lib/types/simple/room/Room.d.ts +29 -18
- package/lib/types/simple/room/Room.d.ts.map +1 -1
- package/lib/types/simple/room/SipRoom.d.ts +1 -1
- package/lib/types/simple/room/SipRoom.d.ts.map +1 -1
- package/lib/types/simple/room/Stream.d.ts +1 -1
- package/lib/types/simple/room/Stream.d.ts.map +1 -1
- package/lib/types/utils/PhoneNumberUtil.d.ts +1 -1
- package/lib/types/utils/PhoneNumberUtil.d.ts.map +1 -1
- package/lib/types/utils/api-requester.d.ts +1 -1
- package/lib/types/utils/api-requester.d.ts.map +1 -1
- package/lib/types/utils/sdp.d.ts +20 -5
- package/lib/types/utils/sdp.d.ts.map +1 -1
- package/lib/types/web-rtc-client.d.ts +51 -49
- package/lib/types/web-rtc-client.d.ts.map +1 -1
- package/lib/types/websocket-client.d.ts.map +1 -1
- package/lib/utils/__tests__/PhoneNumberUtil.test.js +0 -6
- package/lib/utils/__tests__/api-requester.test.js +0 -2
- package/lib/utils/__tests__/sdp.test.js +6 -18
- package/lib/utils/api-requester.js +2 -3
- package/lib/utils/sdp.js +9 -3
- package/lib/web-rtc-client.js +105 -140
- package/lib/websocket-client.js +1 -2
- package/package.json +5 -18
- package/src/__tests__/api-client.test.ts +10 -19
- package/src/__tests__/web-rtc-client.test.ts +13 -25
- package/src/api/auth.ts +2 -5
- package/src/api/call-logd.ts +3 -3
- package/src/api/chatd.ts +10 -24
- package/src/api/dird.ts +33 -39
- package/src/checker/checks/ice-ipv4.ts +4 -5
- package/src/checker/checks/symmetric-nat.ts +11 -7
- package/src/checker/checks/webrtc-transport.ts +2 -2
- package/src/domain/AdHocAPIConference.ts +1 -1
- package/src/domain/Agent.ts +1 -1
- package/src/domain/CallLog.ts +19 -27
- package/src/domain/CallSession.ts +3 -4
- package/src/domain/Contact.ts +3 -1
- package/src/domain/MeetingAuthorization.ts +13 -0
- package/src/domain/Phone/CTIPhone.ts +4 -0
- package/src/domain/Phone/Phone.ts +11 -2
- package/src/domain/Phone/WebRTCPhone.ts +51 -52
- package/src/domain/Room.ts +12 -14
- package/src/domain/Session.ts +3 -3
- package/src/domain/SipLine.ts +3 -3
- package/src/domain/__tests__/Agent.test.ts +3 -5
- package/src/domain/__tests__/Call.test.ts +4 -5
- package/src/domain/__tests__/CallLog.test.ts +1 -3
- package/src/domain/__tests__/CallSession.test.ts +10 -11
- package/src/domain/__tests__/Contact.test.ts +2 -4
- package/src/domain/__tests__/IndirectTransfer.test.ts +6 -7
- package/src/domain/__tests__/Profile.test.ts +3 -4
- package/src/domain/__tests__/Room.test.ts +27 -51
- package/src/domain/__tests__/Session.test.ts +27 -28
- package/src/domain/__tests__/SipLine.test.ts +4 -5
- package/src/domain/types.ts +64 -11
- package/src/index.ts +51 -111
- package/src/lib/WazoSessionDescriptionHandler.ts +24 -30
- package/src/service/CallApi.ts +3 -3
- package/src/service/IssueReporter.ts +3 -5
- package/src/service/__tests__/IssueReporter.test.ts +1 -2
- package/src/simple/Auth.ts +1 -41
- package/src/simple/Phone.ts +9 -116
- package/src/simple/Websocket.ts +4 -20
- package/src/simple/index.ts +8 -7
- package/src/simple/room/Participant.ts +4 -3
- package/src/simple/room/Room.ts +44 -36
- package/src/simple/room/SipRoom.ts +4 -4
- package/src/simple/room/Stream.ts +2 -3
- package/src/simple/room/__tests__/Participant.test.ts +2 -4
- package/src/simple/room/__tests__/RemoteParticipant.test.ts +4 -3
- package/src/types/wazo.d.ts +1 -0
- package/src/utils/PhoneNumberUtil.ts +1 -1
- package/src/utils/__tests__/PhoneNumberUtil.test.ts +0 -6
- package/src/utils/__tests__/api-requester.test.ts +3 -4
- package/src/utils/__tests__/sdp.test.ts +16 -30
- package/src/utils/api-requester.ts +1 -4
- package/src/utils/sdp.ts +38 -17
- package/src/web-rtc-client.ts +196 -234
- package/src/websocket-client.ts +2 -3
- package/lib/.DS_Store +0 -0
package/esm/web-rtc-client.js
CHANGED
|
@@ -189,7 +189,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
189
189
|
method: 'delegate.onInvite',
|
|
190
190
|
clientId: this.clientId,
|
|
191
191
|
id: invitation.id,
|
|
192
|
-
// @ts-ignore
|
|
193
192
|
remoteURI: invitation.remoteURI,
|
|
194
193
|
});
|
|
195
194
|
this._setupSession(invitation);
|
|
@@ -207,6 +206,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
207
206
|
ua.transport.onMessage = (rawMessage) => {
|
|
208
207
|
const message = Parser.parseMessage(rawMessage, ua.transport.logger);
|
|
209
208
|
// We have to re-sent the message to the UA ...
|
|
209
|
+
// @ts-ignore: private
|
|
210
210
|
ua.onTransportMessage(rawMessage);
|
|
211
211
|
// And now do what we want with the message
|
|
212
212
|
this.eventEmitter.emit(MESSAGE, message);
|
|
@@ -231,9 +231,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
231
231
|
onConnect() {
|
|
232
232
|
logger.info('sdk webrtc connected', { method: 'delegate.onConnect', clientId: this.clientId });
|
|
233
233
|
this.eventEmitter.emit(CONNECTED);
|
|
234
|
-
// @ts-ignore
|
|
234
|
+
// @ts-ignore: private
|
|
235
235
|
if (!this.isRegistered() && this.registerer?.waiting) {
|
|
236
|
-
// @ts-ignore
|
|
236
|
+
// @ts-ignore: private
|
|
237
237
|
this.registerer.waitingToggle(false);
|
|
238
238
|
}
|
|
239
239
|
return this.register();
|
|
@@ -245,9 +245,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
245
245
|
this.eventEmitter.emit(DISCONNECTED, error);
|
|
246
246
|
if (this.isRegistered()) {
|
|
247
247
|
await this.unregister();
|
|
248
|
-
// @ts-ignore
|
|
248
|
+
// @ts-ignore: private
|
|
249
249
|
if (this.registerer?.waiting) {
|
|
250
|
-
// @ts-ignore
|
|
250
|
+
// @ts-ignore: private
|
|
251
251
|
this.registerer.waitingToggle(false);
|
|
252
252
|
}
|
|
253
253
|
this.eventEmitter.emit(UNREGISTERED);
|
|
@@ -260,7 +260,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
260
260
|
registered: this.isRegistered(),
|
|
261
261
|
connectionPromise: !!this.connectionPromise,
|
|
262
262
|
registerer: !!this.registerer,
|
|
263
|
-
// @ts-ignore
|
|
263
|
+
// @ts-ignore: private
|
|
264
264
|
waiting: this.registerer && this.registerer.waiting,
|
|
265
265
|
tries,
|
|
266
266
|
skipRegister: this.skipRegister,
|
|
@@ -279,7 +279,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
279
279
|
logger.info('sdk webrtc registering aborted, already registered or no UA can be created');
|
|
280
280
|
return Promise.resolve();
|
|
281
281
|
}
|
|
282
|
-
// @ts-ignore
|
|
282
|
+
// @ts-ignore: private
|
|
283
283
|
if (this.connectionPromise || this.registerer?.waiting) {
|
|
284
284
|
logger.info('sdk webrtc registering aborted due to a registration in progress.', { clientId: this.clientId });
|
|
285
285
|
return Promise.resolve();
|
|
@@ -298,9 +298,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
298
298
|
return;
|
|
299
299
|
}
|
|
300
300
|
this.connectionPromise = null;
|
|
301
|
-
// @ts-ignore
|
|
301
|
+
// @ts-ignore: private
|
|
302
302
|
if (this.registerer && this.registerer.waiting) {
|
|
303
|
-
// @ts-ignore
|
|
303
|
+
// @ts-ignore: private
|
|
304
304
|
this.registerer.waitingToggle(false);
|
|
305
305
|
}
|
|
306
306
|
if (tries <= MAX_REGISTER_TRIES) {
|
|
@@ -352,19 +352,19 @@ export default class WebRTCClient extends Emitter {
|
|
|
352
352
|
if (!registerer) {
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
|
-
// @ts-ignore
|
|
355
|
+
// @ts-ignore: private
|
|
356
356
|
const oldWaitingToggle = registerer.waitingToggle.bind(registerer);
|
|
357
|
-
// @ts-ignore
|
|
357
|
+
// @ts-ignore: private
|
|
358
358
|
const oldUnregistered = registerer.unregistered.bind(registerer);
|
|
359
|
-
// @ts-ignore
|
|
359
|
+
// @ts-ignore: private
|
|
360
360
|
registerer.waitingToggle = (waiting) => {
|
|
361
|
-
// @ts-ignore
|
|
361
|
+
// @ts-ignore: private
|
|
362
362
|
if (!registerer || registerer.waiting === waiting) {
|
|
363
363
|
return;
|
|
364
364
|
}
|
|
365
365
|
oldWaitingToggle(waiting);
|
|
366
366
|
};
|
|
367
|
-
// @ts-ignore
|
|
367
|
+
// @ts-ignore: private
|
|
368
368
|
registerer.unregistered = () => {
|
|
369
369
|
if (!registerer || registerer.state === RegistererState.Terminated) {
|
|
370
370
|
return;
|
|
@@ -441,7 +441,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
441
441
|
inviterOptions.sessionDescriptionHandlerModifiersReInvite = [stripVideo];
|
|
442
442
|
}
|
|
443
443
|
const uri = this._makeURI(number);
|
|
444
|
-
let session;
|
|
444
|
+
let session = null;
|
|
445
445
|
if (uri) {
|
|
446
446
|
session = this.userAgent ? new Inviter(this.userAgent, uri, inviterOptions) : null;
|
|
447
447
|
}
|
|
@@ -458,23 +458,21 @@ export default class WebRTCClient extends Emitter {
|
|
|
458
458
|
const inviteOptions = {
|
|
459
459
|
requestDelegate: {
|
|
460
460
|
onAccept: (response) => {
|
|
461
|
-
if (session
|
|
462
|
-
session
|
|
461
|
+
if (session?.sessionDescriptionHandler?.peerConnection) {
|
|
462
|
+
(session?.sessionDescriptionHandler).peerConnection.sfu = conference;
|
|
463
463
|
}
|
|
464
|
-
// @ts-ignore
|
|
465
464
|
this._onAccepted(session, response.session, true);
|
|
466
465
|
},
|
|
467
|
-
onProgress: payload => {
|
|
466
|
+
onProgress: (payload) => {
|
|
468
467
|
if (payload.message.statusCode === 183) {
|
|
469
|
-
// @ts-ignore
|
|
470
468
|
this._onEarlyProgress(payload.session);
|
|
471
469
|
}
|
|
472
470
|
},
|
|
473
471
|
onReject: (response) => {
|
|
474
472
|
logger.info('on call rejected', {
|
|
475
|
-
id: session
|
|
476
|
-
// @ts-ignore
|
|
477
|
-
fromTag: session
|
|
473
|
+
id: session?.id,
|
|
474
|
+
// @ts-ignore: fromTag does not exist
|
|
475
|
+
fromTag: session?.fromTag,
|
|
478
476
|
});
|
|
479
477
|
this._stopSendingStats(session);
|
|
480
478
|
this.stopNetworkMonitoring(session);
|
|
@@ -484,17 +482,19 @@ export default class WebRTCClient extends Emitter {
|
|
|
484
482
|
sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false, conference),
|
|
485
483
|
};
|
|
486
484
|
if (inviteOptions.sessionDescriptionHandlerOptions) {
|
|
487
|
-
// @ts-ignore
|
|
488
485
|
inviteOptions.sessionDescriptionHandlerOptions.audioOnly = audioOnly;
|
|
489
486
|
}
|
|
490
487
|
inviteOptions.sessionDescriptionHandlerModifiers = [replaceLocalIpModifier];
|
|
491
488
|
if (audioOnly) {
|
|
492
489
|
inviteOptions.sessionDescriptionHandlerModifiers.push(stripVideo);
|
|
493
490
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
491
|
+
if (session) {
|
|
492
|
+
// Do not await invite here or we'll miss the Establishing state transition
|
|
493
|
+
// @ts-ignore: Property 'invitePromise' does not exist
|
|
494
|
+
session.invitePromise = session.invite(inviteOptions).catch((e) => {
|
|
495
|
+
logger.warn('sdk webrtc creating call, error', e);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
498
|
return session;
|
|
499
499
|
}
|
|
500
500
|
answer(session, enableVideo) {
|
|
@@ -512,7 +512,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
512
512
|
sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false),
|
|
513
513
|
};
|
|
514
514
|
return this._accept(session, options).then(() => {
|
|
515
|
-
// @ts-ignore
|
|
515
|
+
// @ts-ignore: private
|
|
516
516
|
if (session.isCanceled) {
|
|
517
517
|
const message = 'accepted a canceled session (or was canceled during the accept phase).';
|
|
518
518
|
logger.error(message, {
|
|
@@ -555,8 +555,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
555
555
|
return Promise.resolve(null);
|
|
556
556
|
}
|
|
557
557
|
async getStats(session) {
|
|
558
|
-
|
|
559
|
-
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
558
|
+
const pc = session.sessionDescriptionHandler?.peerConnection;
|
|
560
559
|
if (!pc) {
|
|
561
560
|
return null;
|
|
562
561
|
}
|
|
@@ -625,13 +624,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
625
624
|
if (this.userAgent) {
|
|
626
625
|
this.userAgent.delegate = undefined;
|
|
627
626
|
}
|
|
628
|
-
// @ts-ignore:
|
|
627
|
+
// @ts-ignore: removeAllListeners does not exist
|
|
629
628
|
this.userAgent.stateChange.removeAllListeners();
|
|
630
629
|
await this._disconnectTransport(force);
|
|
631
630
|
this._cleanupRegister();
|
|
632
631
|
try {
|
|
633
632
|
// Prevent `Connect aborted.` error when disconnecting
|
|
634
|
-
// @ts-ignore
|
|
635
633
|
this.userAgent.transport.connectReject = () => { };
|
|
636
634
|
// Don't wait here, It can take ~30s to stop ...
|
|
637
635
|
this.userAgent.stop().catch(console.error);
|
|
@@ -646,7 +644,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
646
644
|
if (!session) {
|
|
647
645
|
return null;
|
|
648
646
|
}
|
|
649
|
-
// @ts-ignore
|
|
647
|
+
// @ts-ignore: private
|
|
650
648
|
return session.remoteIdentity.uri._normal.user;
|
|
651
649
|
}
|
|
652
650
|
mute(session) {
|
|
@@ -666,7 +664,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
666
664
|
return false;
|
|
667
665
|
}
|
|
668
666
|
let muted = true;
|
|
669
|
-
// @ts-ignore
|
|
670
667
|
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
671
668
|
if (!pc) {
|
|
672
669
|
return false;
|
|
@@ -711,7 +708,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
711
708
|
logger.info('sdk webrtc hold', {
|
|
712
709
|
sessionId,
|
|
713
710
|
keys: Object.keys(this.heldSessions),
|
|
714
|
-
// @ts-ignore
|
|
711
|
+
// @ts-ignore: private
|
|
715
712
|
pendingReinvite: !!session.pendingReinvite,
|
|
716
713
|
isConference,
|
|
717
714
|
hasVideo,
|
|
@@ -719,7 +716,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
719
716
|
if (sessionId in this.heldSessions) {
|
|
720
717
|
return Promise.resolve();
|
|
721
718
|
}
|
|
722
|
-
// @ts-ignore
|
|
719
|
+
// @ts-ignore: private
|
|
723
720
|
if (session.pendingReinvite) {
|
|
724
721
|
return Promise.resolve();
|
|
725
722
|
}
|
|
@@ -731,7 +728,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
731
728
|
// `sendonly` direction
|
|
732
729
|
this.mute(session);
|
|
733
730
|
session.sessionDescriptionHandlerOptionsReInvite = {
|
|
734
|
-
// @ts-ignore
|
|
735
731
|
hold: true,
|
|
736
732
|
conference: isConference,
|
|
737
733
|
};
|
|
@@ -746,7 +742,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
746
742
|
};
|
|
747
743
|
// Avoid sdh to create a new stream
|
|
748
744
|
if (session.sessionDescriptionHandler) {
|
|
749
|
-
// @ts-ignore
|
|
745
|
+
// @ts-ignore: private
|
|
750
746
|
session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
|
|
751
747
|
}
|
|
752
748
|
// Send re-INVITE
|
|
@@ -760,19 +756,18 @@ export default class WebRTCClient extends Emitter {
|
|
|
760
756
|
logger.info('sdk webrtc unhold', {
|
|
761
757
|
sessionId,
|
|
762
758
|
keys: Object.keys(this.heldSessions),
|
|
763
|
-
// @ts-ignore
|
|
759
|
+
// @ts-ignore: private
|
|
764
760
|
pendingReinvite: !!session.pendingReinvite,
|
|
765
761
|
isConference,
|
|
766
762
|
hasVideo,
|
|
767
763
|
});
|
|
768
|
-
// @ts-ignore
|
|
764
|
+
// @ts-ignore: private
|
|
769
765
|
if (session.pendingReinvite) {
|
|
770
766
|
return Promise.resolve();
|
|
771
767
|
}
|
|
772
768
|
this.unmute(session);
|
|
773
769
|
delete this.heldSessions[this.getSipSessionId(session)];
|
|
774
770
|
session.sessionDescriptionHandlerOptionsReInvite = {
|
|
775
|
-
// @ts-ignore
|
|
776
771
|
hold: false,
|
|
777
772
|
conference: isConference,
|
|
778
773
|
};
|
|
@@ -794,13 +789,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
794
789
|
}
|
|
795
790
|
// Returns true if a re-INVITE is required
|
|
796
791
|
async upgradeToVideo(session, constraints, isConference) {
|
|
797
|
-
|
|
798
|
-
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
792
|
+
const pc = session.sessionDescriptionHandler?.peerConnection;
|
|
799
793
|
// Check if a video sender already exists
|
|
800
794
|
let videoSender;
|
|
801
795
|
if (isConference) {
|
|
802
796
|
// We search for the last transceiver without `video-` in the mid (video- means remote transceiver)
|
|
803
|
-
const transceivers = pc
|
|
797
|
+
const transceivers = pc?.getTransceivers() || [];
|
|
804
798
|
const transceiverIdx = lastIndexOf(transceivers, transceiver => transceiver.sender.track === null && transceiver.mid && transceiver.mid.indexOf('video') === -1);
|
|
805
799
|
videoSender = transceiverIdx !== -1 ? transceivers[transceiverIdx].sender : null;
|
|
806
800
|
}
|
|
@@ -819,8 +813,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
819
813
|
}
|
|
820
814
|
// Add previous local audio track
|
|
821
815
|
if (constraints && !constraints.audio) {
|
|
822
|
-
|
|
823
|
-
const localVideoStream = session.sessionDescriptionHandler.localMediaStream;
|
|
816
|
+
const localVideoStream = session.sessionDescriptionHandler?.localMediaStream;
|
|
824
817
|
const localAudioTrack = localVideoStream.getTracks().find(track => track.kind === 'audio');
|
|
825
818
|
if (localAudioTrack) {
|
|
826
819
|
newStream.addTrack(localAudioTrack);
|
|
@@ -835,13 +828,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
835
828
|
}
|
|
836
829
|
downgradeToAudio(session) {
|
|
837
830
|
// Release local video stream when downgrading to audio
|
|
838
|
-
|
|
839
|
-
const localStream =
|
|
840
|
-
|
|
841
|
-
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
831
|
+
const sessionDescriptionHandler = session.sessionDescriptionHandler;
|
|
832
|
+
const localStream = sessionDescriptionHandler?.localMediaStream;
|
|
833
|
+
const pc = sessionDescriptionHandler?.peerConnection;
|
|
842
834
|
const videoTracks = localStream.getVideoTracks();
|
|
843
835
|
// Remove video senders
|
|
844
|
-
if (pc
|
|
836
|
+
if (pc?.getSenders) {
|
|
845
837
|
pc.getSenders().filter((sender) => sender.track && sender.track.kind === 'video').forEach((videoSender) => {
|
|
846
838
|
videoSender.replaceTrack(null);
|
|
847
839
|
});
|
|
@@ -855,7 +847,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
855
847
|
async getStreamFromConstraints(constraints, conference = false) {
|
|
856
848
|
const video = constraints && constraints.video;
|
|
857
849
|
const { constraints: newConstraints, } = this.getMediaConfiguration(video, conference, constraints);
|
|
858
|
-
let newStream;
|
|
850
|
+
let newStream = null;
|
|
859
851
|
try {
|
|
860
852
|
newStream = await wazoMediaStreamFactory(newConstraints);
|
|
861
853
|
}
|
|
@@ -864,7 +856,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
864
856
|
if (!newStream) {
|
|
865
857
|
return null;
|
|
866
858
|
}
|
|
867
|
-
// @ts-ignore
|
|
868
859
|
newStream.local = true;
|
|
869
860
|
return newStream;
|
|
870
861
|
}
|
|
@@ -995,7 +986,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
995
986
|
logger.warn('pingServer: null fromURI');
|
|
996
987
|
}
|
|
997
988
|
getState() {
|
|
998
|
-
// @ts-ignore
|
|
989
|
+
// @ts-ignore: something fishy here: `states` content doesn't match UserAgentState at all
|
|
999
990
|
return this.userAgent ? states[this.userAgent.state] : UserAgentState.Stopped;
|
|
1000
991
|
}
|
|
1001
992
|
getContactIdentifier() {
|
|
@@ -1026,9 +1017,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1026
1017
|
// audioElement is an array of HTMLAudioElements, and HTMLAudioElement inherits the method from HTMLMediaElement
|
|
1027
1018
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement
|
|
1028
1019
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId
|
|
1029
|
-
// @ts-ignore
|
|
1030
1020
|
if (audioElement.setSinkId) {
|
|
1031
|
-
// @ts-ignore
|
|
1032
1021
|
audioElement.setSinkId(id);
|
|
1033
1022
|
}
|
|
1034
1023
|
});
|
|
@@ -1070,8 +1059,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1070
1059
|
}
|
|
1071
1060
|
if (session && navigator.mediaDevices) {
|
|
1072
1061
|
const sdh = session.sessionDescriptionHandler;
|
|
1073
|
-
|
|
1074
|
-
const pc = sdh.peerConnection;
|
|
1062
|
+
const pc = sdh?.peerConnection;
|
|
1075
1063
|
const constraints = {
|
|
1076
1064
|
audio: {
|
|
1077
1065
|
deviceId: {
|
|
@@ -1120,7 +1108,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1120
1108
|
return Promise.resolve();
|
|
1121
1109
|
}
|
|
1122
1110
|
const sdh = session.sessionDescriptionHandler;
|
|
1123
|
-
// @ts-ignore
|
|
1124
1111
|
const pc = sdh.peerConnection;
|
|
1125
1112
|
const sessionId = this.getSipSessionId(session);
|
|
1126
1113
|
const localStream = this.getLocalStream(sessionId);
|
|
@@ -1164,18 +1151,16 @@ export default class WebRTCClient extends Emitter {
|
|
|
1164
1151
|
});
|
|
1165
1152
|
}
|
|
1166
1153
|
getAudioDeviceId() {
|
|
1167
|
-
|
|
1168
|
-
return this.audio && typeof this.audio === 'object' && 'deviceId' in this.audio ? this.audio.deviceId.exact : undefined;
|
|
1154
|
+
return this.audio && typeof this.audio === 'object' && 'deviceId' in this.audio ? this.audio.deviceId?.exact : undefined;
|
|
1169
1155
|
}
|
|
1170
1156
|
getVideoDeviceId() {
|
|
1171
|
-
|
|
1172
|
-
return this.video && typeof this.video === 'object' && 'deviceId' in this.video ? this.video.deviceId.exact : undefined;
|
|
1157
|
+
return this.video && typeof this.video === 'object' && 'deviceId' in this.video ? this.video.deviceId?.exact : undefined;
|
|
1173
1158
|
}
|
|
1174
1159
|
reinvite(sipSession, newConstraints = null, conference = false, audioOnly = false, iceRestart = false) {
|
|
1175
1160
|
if (!sipSession) {
|
|
1176
1161
|
return Promise.resolve();
|
|
1177
1162
|
}
|
|
1178
|
-
// @ts-ignore
|
|
1163
|
+
// @ts-ignore: private
|
|
1179
1164
|
if (sipSession.pendingReinvite) {
|
|
1180
1165
|
return Promise.resolve();
|
|
1181
1166
|
}
|
|
@@ -1200,7 +1185,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1200
1185
|
sipSession.sessionDescriptionHandlerModifiersReInvite = modifiers.filter(modifier => modifier !== stripVideo);
|
|
1201
1186
|
}
|
|
1202
1187
|
sipSession.sessionDescriptionHandlerOptionsReInvite = { ...sipSession.sessionDescriptionHandlerOptionsReInvite,
|
|
1203
|
-
// @ts-ignore
|
|
1204
1188
|
conference,
|
|
1205
1189
|
audioOnly,
|
|
1206
1190
|
};
|
|
@@ -1210,13 +1194,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
1210
1194
|
onAccept: (response) => {
|
|
1211
1195
|
// Update the SDP body to be able to call sessionWantsToDoVideo correctly in `_setup[Local|Remote]Media`.
|
|
1212
1196
|
// Can't set directly sipSession.body because it's a getter.
|
|
1213
|
-
// @ts-ignore
|
|
1197
|
+
// @ts-ignore: private
|
|
1214
1198
|
if (sipSession instanceof Inviter && sipSession.outgoingRequestMessage.body) {
|
|
1215
|
-
// @ts-ignore
|
|
1199
|
+
// @ts-ignore: private
|
|
1216
1200
|
sipSession.outgoingRequestMessage.body.body = response.message.body;
|
|
1217
1201
|
}
|
|
1218
1202
|
else if (sipSession instanceof Invitation) {
|
|
1219
|
-
// @ts-ignore
|
|
1203
|
+
// @ts-ignore: private
|
|
1220
1204
|
sipSession.incomingInviteRequest.message.body = response.message.body;
|
|
1221
1205
|
}
|
|
1222
1206
|
logger.info('on re-INVITE accepted', {
|
|
@@ -1228,7 +1212,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1228
1212
|
if (wasMuted) {
|
|
1229
1213
|
this.mute(sipSession);
|
|
1230
1214
|
}
|
|
1231
|
-
// @ts-ignore
|
|
1232
1215
|
this._onAccepted(sipSession, response.session, false, false);
|
|
1233
1216
|
if (shouldDoScreenSharing) {
|
|
1234
1217
|
this.eventEmitter.emit(ON_SCREEN_SHARING_REINVITE, sipSession, response, desktop);
|
|
@@ -1242,7 +1225,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1242
1225
|
},
|
|
1243
1226
|
sessionDescriptionHandlerOptions: {
|
|
1244
1227
|
constraints,
|
|
1245
|
-
// @ts-ignore
|
|
1246
1228
|
conference,
|
|
1247
1229
|
audioOnly,
|
|
1248
1230
|
offerOptions: {
|
|
@@ -1263,13 +1245,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
1263
1245
|
if (!sipSession) {
|
|
1264
1246
|
return null;
|
|
1265
1247
|
}
|
|
1266
|
-
// @ts-ignore
|
|
1267
1248
|
return sipSession.sessionDescriptionHandler ? sipSession.sessionDescriptionHandler.peerConnection : null;
|
|
1268
1249
|
}
|
|
1269
1250
|
// Local streams
|
|
1270
1251
|
getLocalStream(sessionId) {
|
|
1271
1252
|
const sipSession = this.sipSessions[sessionId];
|
|
1272
|
-
// @ts-ignore
|
|
1273
1253
|
return sipSession?.sessionDescriptionHandler?.localMediaStream || null;
|
|
1274
1254
|
}
|
|
1275
1255
|
getLocalTracks(sessionId) {
|
|
@@ -1292,7 +1272,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1292
1272
|
// Remote streams
|
|
1293
1273
|
getRemoteStream(sessionId) {
|
|
1294
1274
|
const sipSession = this.sipSessions[sessionId];
|
|
1295
|
-
// @ts-ignore
|
|
1296
1275
|
return sipSession?.sessionDescriptionHandler?.remoteMediaStream || null;
|
|
1297
1276
|
}
|
|
1298
1277
|
getRemoteTracks(sessionId) {
|
|
@@ -1333,15 +1312,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
1333
1312
|
if (!sipSession) {
|
|
1334
1313
|
return '';
|
|
1335
1314
|
}
|
|
1336
|
-
|
|
1337
|
-
if (
|
|
1338
|
-
|
|
1339
|
-
return sipSession.message.callId.substring(0, SIP_ID_LENGTH);
|
|
1315
|
+
const message = sipSession.message;
|
|
1316
|
+
if (message?.callId) {
|
|
1317
|
+
return message.callId.substring(0, SIP_ID_LENGTH);
|
|
1340
1318
|
}
|
|
1341
1319
|
// For Inviter
|
|
1342
|
-
// @ts-ignore
|
|
1320
|
+
// @ts-ignore: private
|
|
1343
1321
|
if (sipSession instanceof Inviter && sipSession.outgoingRequestMessage) {
|
|
1344
|
-
// @ts-ignore
|
|
1322
|
+
// @ts-ignore: private
|
|
1345
1323
|
return sipSession.outgoingRequestMessage.callId.substring(0, SIP_ID_LENGTH);
|
|
1346
1324
|
}
|
|
1347
1325
|
// For Invitation
|
|
@@ -1394,7 +1372,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1394
1372
|
if (!this.userAgent) {
|
|
1395
1373
|
return;
|
|
1396
1374
|
}
|
|
1397
|
-
// @ts-ignore
|
|
1375
|
+
// @ts-ignore: private
|
|
1398
1376
|
this.userAgent.attemptReconnection();
|
|
1399
1377
|
}
|
|
1400
1378
|
storeSipSession(session) {
|
|
@@ -1419,7 +1397,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1419
1397
|
});
|
|
1420
1398
|
if (sipSession.sessionDescriptionHandler) {
|
|
1421
1399
|
// eslint-disable-next-line no-underscore-dangle
|
|
1422
|
-
// @ts-ignore
|
|
1400
|
+
// @ts-ignore: protected
|
|
1423
1401
|
sipSession.sessionDescriptionHandler._localMediaStream = newStream;
|
|
1424
1402
|
}
|
|
1425
1403
|
}
|
|
@@ -1533,14 +1511,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
1533
1511
|
return;
|
|
1534
1512
|
}
|
|
1535
1513
|
if (this.userAgent?.transport) {
|
|
1536
|
-
// @ts-ignore
|
|
1537
1514
|
this.userAgent.transport.configuration.traceSip = true;
|
|
1538
1515
|
}
|
|
1539
|
-
// @ts-ignore
|
|
1516
|
+
// @ts-ignore: private
|
|
1540
1517
|
this.userAgent.loggerFactory.builtinEnabled = true;
|
|
1541
|
-
// @ts-ignore
|
|
1518
|
+
// @ts-ignore: private
|
|
1542
1519
|
this.userAgent.loggerFactory.level = 3; // debug
|
|
1543
|
-
// @ts-ignore
|
|
1520
|
+
// @ts-ignore: private
|
|
1544
1521
|
this.userAgent.loggerFactory.connector = logConnector;
|
|
1545
1522
|
}
|
|
1546
1523
|
_onHeartbeat(message) {
|
|
@@ -1567,8 +1544,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
1567
1544
|
}
|
|
1568
1545
|
if (this.userAgent && this.userAgent.transport) {
|
|
1569
1546
|
// Disconnect from WS and triggers events, but do not trigger disconnect if already disconnecting...
|
|
1570
|
-
|
|
1571
|
-
|
|
1547
|
+
const transport = this.userAgent.transport;
|
|
1548
|
+
// @HEADS UP
|
|
1549
|
+
if (!transport.transitioningState && !transport.disconnectPromise) {
|
|
1572
1550
|
try {
|
|
1573
1551
|
await this.userAgent.transport.disconnect();
|
|
1574
1552
|
}
|
|
@@ -1590,14 +1568,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
1590
1568
|
return this.hasAudio;
|
|
1591
1569
|
}
|
|
1592
1570
|
_getAudioConstraints() {
|
|
1593
|
-
// @ts-ignore
|
|
1571
|
+
// @ts-ignore: media constraints
|
|
1594
1572
|
return this.audio?.deviceId?.exact ? this.audio : true;
|
|
1595
1573
|
}
|
|
1596
1574
|
_getVideoConstraints(video = false) {
|
|
1597
1575
|
if (!video) {
|
|
1598
1576
|
return false;
|
|
1599
1577
|
}
|
|
1600
|
-
// @ts-ignore
|
|
1578
|
+
// @ts-ignore: media constraints
|
|
1601
1579
|
return this.video?.deviceId?.exact ? this.video : true;
|
|
1602
1580
|
}
|
|
1603
1581
|
_connectIfNeeded() {
|
|
@@ -1612,7 +1590,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1612
1590
|
}
|
|
1613
1591
|
if (this.isConnecting()) {
|
|
1614
1592
|
logger.info('webrtc sdk, already connecting...');
|
|
1615
|
-
// @ts-ignore
|
|
1616
1593
|
this.connectionPromise = this.userAgent.transport.connectPromise;
|
|
1617
1594
|
return Promise.resolve(this.connectionPromise);
|
|
1618
1595
|
}
|
|
@@ -1623,11 +1600,10 @@ export default class WebRTCClient extends Emitter {
|
|
|
1623
1600
|
logger.info('WebRTC UA needs to connect');
|
|
1624
1601
|
// Force UA to reconnect
|
|
1625
1602
|
if (this.userAgent && this.userAgent.state !== UserAgentState.Stopped) {
|
|
1626
|
-
// @ts-ignore
|
|
1603
|
+
// @ts-ignore: private
|
|
1627
1604
|
this.userAgent.transitionState(UserAgentState.Stopped);
|
|
1628
1605
|
}
|
|
1629
1606
|
if (this.userAgent.transport && this.userAgent.transport.state !== TransportState.Disconnected) {
|
|
1630
|
-
// @ts-ignore
|
|
1631
1607
|
this.userAgent.transport.transitionState(TransportState.Disconnected);
|
|
1632
1608
|
}
|
|
1633
1609
|
this.connectionPromise = this.userAgent.start().catch(console.error);
|
|
@@ -1641,11 +1617,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
1641
1617
|
const client = new ApiClient({
|
|
1642
1618
|
server: `${config.host}:${String(config.port || 443)}`,
|
|
1643
1619
|
});
|
|
1644
|
-
// @ts-ignore
|
|
1645
1620
|
client.setToken(session.token);
|
|
1646
|
-
// @ts-ignore
|
|
1647
1621
|
client.setRefreshToken(session.refreshToken);
|
|
1648
|
-
// @ts-ignore
|
|
1649
1622
|
return client.confd.getUserLineSipFromToken(session.uuid).then(sipLine => ({
|
|
1650
1623
|
authorizationUser: sipLine.username,
|
|
1651
1624
|
password: sipLine.secret,
|
|
@@ -1681,7 +1654,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1681
1654
|
sessionDescriptionHandlerFactory: (session, options = {}) => {
|
|
1682
1655
|
const uaLogger = session.userAgent.getLogger('sip.WazoSessionDescriptionHandler');
|
|
1683
1656
|
const isWeb = this._isWeb();
|
|
1684
|
-
// @ts-ignore
|
|
1685
1657
|
const iceGatheringTimeout = 'peerConnectionOptions' in options ? options.peerConnectionOptions.iceGatheringTimeout || DEFAULT_ICE_TIMEOUT : DEFAULT_ICE_TIMEOUT;
|
|
1686
1658
|
const sdhOptions = { ...options,
|
|
1687
1659
|
iceGatheringTimeout,
|
|
@@ -1743,8 +1715,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1743
1715
|
session.delegate = {};
|
|
1744
1716
|
}
|
|
1745
1717
|
session.delegate.onSessionDescriptionHandler = (sdh) => {
|
|
1746
|
-
|
|
1747
|
-
sdh.on('error', e => {
|
|
1718
|
+
sdh.on('error', (e) => {
|
|
1748
1719
|
this.eventEmitter.emit(ON_ERROR, e);
|
|
1749
1720
|
});
|
|
1750
1721
|
sdh.peerConnectionDelegate = {
|
|
@@ -1759,12 +1730,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
1759
1730
|
},
|
|
1760
1731
|
};
|
|
1761
1732
|
};
|
|
1762
|
-
// @ts-ignore
|
|
1733
|
+
// @ts-ignore: protected
|
|
1763
1734
|
const oldInviteRequest = session.onInviteRequest.bind(session);
|
|
1764
1735
|
let hadRemoteVideo = false;
|
|
1765
1736
|
// Monkey patch `onInviteRequest` to be able to know if there was a remote video stream before `onInvite` is called
|
|
1766
1737
|
// Because when `onInvite` is called we already got the video track
|
|
1767
|
-
// @ts-ignore
|
|
1738
|
+
// @ts-ignore: protected
|
|
1768
1739
|
session.onInviteRequest = request => {
|
|
1769
1740
|
hadRemoteVideo = this.hasARemoteVideoTrack(sipSessionId);
|
|
1770
1741
|
oldInviteRequest(request);
|
|
@@ -1773,7 +1744,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1773
1744
|
let updatedCalleeName = null;
|
|
1774
1745
|
let updatedNumber = null;
|
|
1775
1746
|
if (session.assertedIdentity) {
|
|
1776
|
-
// @ts-ignore
|
|
1747
|
+
// @ts-ignore: private
|
|
1777
1748
|
updatedNumber = session.assertedIdentity.uri.normal.user;
|
|
1778
1749
|
updatedCalleeName = session.assertedIdentity.displayName || updatedNumber;
|
|
1779
1750
|
}
|
|
@@ -1786,12 +1757,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
1786
1757
|
// Update SDP
|
|
1787
1758
|
// Remote video is handled by the `track` event. Here we're dealing with video stream removal.
|
|
1788
1759
|
if (session instanceof Invitation) {
|
|
1789
|
-
// @ts-ignore
|
|
1760
|
+
// @ts-ignore: private
|
|
1790
1761
|
session.incomingInviteRequest.message.body = request.body;
|
|
1791
|
-
// @ts-ignore
|
|
1762
|
+
// @ts-ignore: private
|
|
1792
1763
|
}
|
|
1793
1764
|
else if (session instanceof Inviter && session.outgoingInviteRequest.message.body) {
|
|
1794
|
-
// @ts-ignore
|
|
1765
|
+
// @ts-ignore: private
|
|
1795
1766
|
session.outgoingInviteRequest.message.body.body = request.body;
|
|
1796
1767
|
}
|
|
1797
1768
|
this.updateRemoteStream(sipSessionId, false);
|
|
@@ -1812,13 +1783,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
1812
1783
|
logger.info('on call accepted', {
|
|
1813
1784
|
id: session.id,
|
|
1814
1785
|
clientId: this.clientId,
|
|
1815
|
-
// @ts-ignore
|
|
1816
1786
|
remoteTag: session.remoteTag,
|
|
1817
1787
|
});
|
|
1818
1788
|
this.storeSipSession(session);
|
|
1819
1789
|
this._setupMedias(session);
|
|
1820
1790
|
this.updateRemoteStream(this.getSipSessionId(session), initAllTracks);
|
|
1821
|
-
// @ts-ignore
|
|
1822
1791
|
const pc = session.sessionDescriptionHandler?.peerConnection;
|
|
1823
1792
|
const onTrack = (event) => {
|
|
1824
1793
|
const isAudioOnly = this._isAudioOnly(session);
|
|
@@ -1837,13 +1806,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
1837
1806
|
}
|
|
1838
1807
|
this.eventEmitter.emit(ON_TRACK, session, event);
|
|
1839
1808
|
};
|
|
1840
|
-
|
|
1841
|
-
if (
|
|
1842
|
-
|
|
1843
|
-
session.sessionDescriptionHandler.peerConnection.addEventListener('track', onTrack);
|
|
1809
|
+
const sessionDescriptionHandler = session.sessionDescriptionHandler;
|
|
1810
|
+
if (sessionDescriptionHandler?.peerConnection) {
|
|
1811
|
+
sessionDescriptionHandler.peerConnection.addEventListener('track', onTrack);
|
|
1844
1812
|
}
|
|
1845
|
-
|
|
1846
|
-
session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
|
|
1813
|
+
sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
|
|
1847
1814
|
if (pc) {
|
|
1848
1815
|
pc.oniceconnectionstatechange = () => {
|
|
1849
1816
|
logger.info('on ice connection state changed', {
|
|
@@ -1880,11 +1847,10 @@ export default class WebRTCClient extends Emitter {
|
|
|
1880
1847
|
this.createAudioElementFor(sessionId);
|
|
1881
1848
|
}
|
|
1882
1849
|
const audioElement = this.audioElements[sessionId];
|
|
1883
|
-
// @ts-ignore
|
|
1884
1850
|
const sipSession = this.sipSessions[session.callId];
|
|
1885
1851
|
const removeStream = this.getRemoteStream(sessionId);
|
|
1886
|
-
|
|
1887
|
-
const earlyStream =
|
|
1852
|
+
const sdh = sipSession.sessionDescriptionHandler;
|
|
1853
|
+
const earlyStream = sdh ? sdh.remoteMediaStream : null;
|
|
1888
1854
|
const stream = newStream || removeStream || earlyStream;
|
|
1889
1855
|
if (!stream) {
|
|
1890
1856
|
logger.info('Setup media no stream to attach, bailing');
|
|
@@ -1944,8 +1910,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
1944
1910
|
stream.getTracks().filter(track => track.enabled).forEach(track => track.stop());
|
|
1945
1911
|
}
|
|
1946
1912
|
_toggleAudio(session, muteAudio) {
|
|
1947
|
-
|
|
1948
|
-
const pc =
|
|
1913
|
+
const sdh = session.sessionDescriptionHandler;
|
|
1914
|
+
const pc = (sdh?.peerConnection || null);
|
|
1949
1915
|
if (!pc) {
|
|
1950
1916
|
return;
|
|
1951
1917
|
}
|
|
@@ -1967,9 +1933,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
1967
1933
|
}
|
|
1968
1934
|
}
|
|
1969
1935
|
_toggleVideo(session, muteCamera) {
|
|
1970
|
-
|
|
1971
|
-
const pc =
|
|
1972
|
-
if (pc
|
|
1936
|
+
const sdh = session.sessionDescriptionHandler;
|
|
1937
|
+
const pc = sdh?.peerConnection;
|
|
1938
|
+
if (pc?.getSenders) {
|
|
1973
1939
|
pc.getSenders().forEach((sender) => {
|
|
1974
1940
|
if (sender && sender.track && sender.track.kind === 'video') {
|
|
1975
1941
|
// eslint-disable-next-line
|
|
@@ -2007,14 +1973,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
2007
1973
|
}
|
|
2008
1974
|
_cleanupRegister() {
|
|
2009
1975
|
if (this.registerer) {
|
|
2010
|
-
// @ts-ignore
|
|
1976
|
+
// @ts-ignore: removeAllListeners does not exist
|
|
2011
1977
|
this.registerer.stateChange.removeAllListeners();
|
|
2012
1978
|
this.registerer = null;
|
|
2013
1979
|
}
|
|
2014
1980
|
}
|
|
2015
1981
|
_startSendingStats(session) {
|
|
2016
|
-
|
|
2017
|
-
const pc =
|
|
1982
|
+
const sdh = session.sessionDescriptionHandler;
|
|
1983
|
+
const pc = sdh.peerConnection;
|
|
2018
1984
|
if (!pc) {
|
|
2019
1985
|
return;
|
|
2020
1986
|
}
|
|
@@ -2046,22 +2012,19 @@ export default class WebRTCClient extends Emitter {
|
|
|
2046
2012
|
return UserAgent.makeURI(`sip:${target}@${this.config.host}`);
|
|
2047
2013
|
}
|
|
2048
2014
|
async _disconnectTransport(force = false) {
|
|
2049
|
-
|
|
2015
|
+
const transport = this.userAgent?.transport;
|
|
2016
|
+
if (force && transport) {
|
|
2050
2017
|
// Bypass sip.js state machine that prevent to close WS with the state `Connecting`
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
if (this.userAgent.transport._ws) {
|
|
2055
|
-
// @ts-ignore
|
|
2056
|
-
this.userAgent.transport._ws.close(1000);
|
|
2018
|
+
transport.disconnectResolve = () => { };
|
|
2019
|
+
if (transport._ws) {
|
|
2020
|
+
transport._ws.close(1000);
|
|
2057
2021
|
}
|
|
2058
2022
|
return;
|
|
2059
2023
|
}
|
|
2060
2024
|
// Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
|
|
2061
|
-
|
|
2062
|
-
if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
|
|
2025
|
+
if (transport && !transport.disconnectPromise) {
|
|
2063
2026
|
try {
|
|
2064
|
-
await
|
|
2027
|
+
await transport.disconnect();
|
|
2065
2028
|
}
|
|
2066
2029
|
catch (e) {
|
|
2067
2030
|
logger.error('WebRTC transport disconnect, error', e);
|
|
@@ -2175,7 +2138,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2175
2138
|
logger.warn(error, { state: session.state, sessionId: session.id });
|
|
2176
2139
|
throw new Error(error);
|
|
2177
2140
|
}
|
|
2178
|
-
// @ts-ignore
|
|
2141
|
+
// @ts-ignore: private
|
|
2179
2142
|
if (!session.incomingInviteRequest.acceptable) {
|
|
2180
2143
|
const error = 'Trying to reject a non `acceptable` session';
|
|
2181
2144
|
logger.warn(error, { state: session.state, sessionId: session.id });
|
|
@@ -2193,7 +2156,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2193
2156
|
logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: session.id });
|
|
2194
2157
|
return;
|
|
2195
2158
|
}
|
|
2196
|
-
// @ts-ignore
|
|
2159
|
+
// @ts-ignore: private
|
|
2197
2160
|
if (!session.incomingInviteRequest.rejectable) {
|
|
2198
2161
|
logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: session.id });
|
|
2199
2162
|
return;
|