@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/src/web-rtc-client.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
/* global window, document, navigator */
|
|
4
4
|
import 'webrtc-adapter';
|
|
5
5
|
import type { InviterInviteOptions } from 'sip.js/lib/api/inviter-invite-options';
|
|
6
|
-
import type { IncomingResponse } from 'sip.js/lib/core/messages/incoming-response';
|
|
7
6
|
import type { InvitationRejectOptions } from 'sip.js/lib/api/invitation-reject-options';
|
|
8
7
|
import type { InviterCancelOptions } from 'sip.js/lib/api/inviter-cancel-options';
|
|
9
8
|
import type { SessionByeOptions } from 'sip.js/lib/api/session-bye-options';
|
|
@@ -28,7 +27,7 @@ import { defaultPeerConnectionConfiguration } from 'sip.js/lib/platform/web/sess
|
|
|
28
27
|
import getStats from 'getstats';
|
|
29
28
|
|
|
30
29
|
import { OutgoingByeRequest, OutgoingInviteRequest, OutgoingRequest } from 'sip.js/lib/core';
|
|
31
|
-
import { Inviter, Invitation, Registerer, Session } from 'sip.js/lib/api';
|
|
30
|
+
import { Inviter, Invitation, Registerer, Session, SessionDescriptionHandlerOptions } from 'sip.js/lib/api';
|
|
32
31
|
import WazoSessionDescriptionHandler, { wazoMediaStreamFactory } from './lib/WazoSessionDescriptionHandler';
|
|
33
32
|
import Emitter from './utils/Emitter';
|
|
34
33
|
import ApiClient from './api-client';
|
|
@@ -36,7 +35,7 @@ import IssueReporter from './service/IssueReporter';
|
|
|
36
35
|
import Heartbeat from './utils/Heartbeat';
|
|
37
36
|
import { getVideoDirection, hasAnActiveVideo } from './utils/sdp';
|
|
38
37
|
import { lastIndexOf } from './utils/array';
|
|
39
|
-
import type { MediaConfig, UserAgentConfigOverrides, WebRtcConfig, UserAgentOptions } from './domain/types';
|
|
38
|
+
import type { MediaConfig, UserAgentConfigOverrides, WebRtcConfig, UserAgentOptions, IncomingResponse, PeerConnection, WazoSession, WazoTransport } from './domain/types';
|
|
40
39
|
|
|
41
40
|
// We need to replace 0.0.0.0 to 127.0.0.1 in the sdp to avoid MOH during a createOffer.
|
|
42
41
|
export const replaceLocalIpModifier = (description: Record<string, any>) => Promise.resolve({ // description is immutable... so we have to clone it or the `type` attribute won't be returned.
|
|
@@ -88,11 +87,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
88
87
|
|
|
89
88
|
hasAudio: boolean;
|
|
90
89
|
|
|
91
|
-
audio:
|
|
90
|
+
audio: MediaTrackConstraintSet | boolean | undefined;
|
|
92
91
|
|
|
93
|
-
audioElements: Record<string, HTMLAudioElement>;
|
|
92
|
+
audioElements: Record<string, HTMLAudioElement & { setSinkId?: (id: string) => void }>;
|
|
94
93
|
|
|
95
|
-
video:
|
|
94
|
+
video: MediaTrackConstraintSet | boolean | undefined;
|
|
96
95
|
|
|
97
96
|
audioStreams: Record<string, any>;
|
|
98
97
|
|
|
@@ -114,7 +113,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
114
113
|
|
|
115
114
|
statsIntervals: Record<string, any>;
|
|
116
115
|
|
|
117
|
-
sipSessions: Record<string,
|
|
116
|
+
sipSessions: Record<string, WazoSession>;
|
|
118
117
|
|
|
119
118
|
conferences: Record<string, boolean>;
|
|
120
119
|
|
|
@@ -180,7 +179,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
180
179
|
return [];
|
|
181
180
|
}
|
|
182
181
|
|
|
183
|
-
constructor(config: WebRtcConfig, session:
|
|
182
|
+
constructor(config: WebRtcConfig, session: WazoSession | null | undefined, uaConfigOverrides?: UserAgentConfigOverrides) {
|
|
184
183
|
super();
|
|
185
184
|
|
|
186
185
|
// For debug purpose
|
|
@@ -266,8 +265,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
266
265
|
method: 'delegate.onInvite',
|
|
267
266
|
clientId: this.clientId,
|
|
268
267
|
id: invitation.id,
|
|
269
|
-
|
|
270
|
-
remoteURI: invitation.remoteURI,
|
|
268
|
+
remoteURI: (invitation as any).remoteURI,
|
|
271
269
|
});
|
|
272
270
|
|
|
273
271
|
this._setupSession(invitation);
|
|
@@ -276,25 +274,26 @@ export default class WebRTCClient extends Emitter {
|
|
|
276
274
|
this.eventEmitter.emit(INVITE, invitation, this.sessionWantsToDoVideo(invitation), shouldAutoAnswer);
|
|
277
275
|
},
|
|
278
276
|
};
|
|
279
|
-
const ua
|
|
277
|
+
const ua = new UserAgent(uaOptions);
|
|
280
278
|
ua.start();
|
|
281
279
|
|
|
282
|
-
if (ua.transport && ua.transport.connectPromise) {
|
|
283
|
-
ua.transport.connectPromise.catch((e: any) => {
|
|
280
|
+
if (ua.transport && (ua.transport as WazoTransport).connectPromise) {
|
|
281
|
+
(ua.transport as WazoTransport).connectPromise.catch((e: any) => {
|
|
284
282
|
logger.warn('Transport connect error', e);
|
|
285
283
|
});
|
|
286
284
|
}
|
|
287
285
|
|
|
288
286
|
ua.transport.onMessage = (rawMessage: string) => {
|
|
289
|
-
const message = Parser.parseMessage(rawMessage, ua.transport.logger);
|
|
287
|
+
const message = Parser.parseMessage(rawMessage, (ua.transport as any).logger);
|
|
290
288
|
// We have to re-sent the message to the UA ...
|
|
289
|
+
// @ts-ignore: private
|
|
291
290
|
ua.onTransportMessage(rawMessage);
|
|
292
291
|
// And now do what we want with the message
|
|
293
292
|
this.eventEmitter.emit(MESSAGE, message);
|
|
294
293
|
|
|
295
294
|
if (message && message.method === C.MESSAGE) {
|
|
296
295
|
// We have to manually reply to MESSAGE with a 200 OK or Asterisk will hangup.
|
|
297
|
-
ua.userAgentCore.replyStateless(message, {
|
|
296
|
+
ua.userAgentCore.replyStateless(message as any, {
|
|
298
297
|
statusCode: 200,
|
|
299
298
|
});
|
|
300
299
|
}
|
|
@@ -319,9 +318,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
319
318
|
logger.info('sdk webrtc connected', { method: 'delegate.onConnect', clientId: this.clientId });
|
|
320
319
|
this.eventEmitter.emit(CONNECTED);
|
|
321
320
|
|
|
322
|
-
// @ts-ignore
|
|
321
|
+
// @ts-ignore: private
|
|
323
322
|
if (!this.isRegistered() && this.registerer?.waiting) {
|
|
324
|
-
// @ts-ignore
|
|
323
|
+
// @ts-ignore: private
|
|
325
324
|
this.registerer.waitingToggle(false);
|
|
326
325
|
}
|
|
327
326
|
|
|
@@ -336,10 +335,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
336
335
|
|
|
337
336
|
if (this.isRegistered()) {
|
|
338
337
|
await this.unregister();
|
|
339
|
-
|
|
340
|
-
// @ts-ignore
|
|
338
|
+
// @ts-ignore: private
|
|
341
339
|
if (this.registerer?.waiting) {
|
|
342
|
-
// @ts-ignore
|
|
340
|
+
// @ts-ignore: private
|
|
343
341
|
this.registerer.waitingToggle(false);
|
|
344
342
|
}
|
|
345
343
|
|
|
@@ -354,7 +352,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
354
352
|
registered: this.isRegistered(),
|
|
355
353
|
connectionPromise: !!this.connectionPromise,
|
|
356
354
|
registerer: !!this.registerer,
|
|
357
|
-
// @ts-ignore
|
|
355
|
+
// @ts-ignore: private
|
|
358
356
|
waiting: this.registerer && this.registerer.waiting,
|
|
359
357
|
tries,
|
|
360
358
|
skipRegister: this.skipRegister,
|
|
@@ -378,7 +376,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
378
376
|
return Promise.resolve();
|
|
379
377
|
}
|
|
380
378
|
|
|
381
|
-
// @ts-ignore
|
|
379
|
+
// @ts-ignore: private
|
|
382
380
|
if (this.connectionPromise || this.registerer?.waiting) {
|
|
383
381
|
logger.info('sdk webrtc registering aborted due to a registration in progress.', { clientId: this.clientId });
|
|
384
382
|
return Promise.resolve();
|
|
@@ -402,9 +400,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
402
400
|
|
|
403
401
|
this.connectionPromise = null;
|
|
404
402
|
|
|
405
|
-
// @ts-ignore
|
|
403
|
+
// @ts-ignore: private
|
|
406
404
|
if (this.registerer && this.registerer.waiting) {
|
|
407
|
-
// @ts-ignore
|
|
405
|
+
// @ts-ignore: private
|
|
408
406
|
this.registerer.waitingToggle(false);
|
|
409
407
|
}
|
|
410
408
|
|
|
@@ -463,14 +461,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
463
461
|
return;
|
|
464
462
|
}
|
|
465
463
|
|
|
466
|
-
// @ts-ignore
|
|
464
|
+
// @ts-ignore: private
|
|
467
465
|
const oldWaitingToggle = registerer.waitingToggle.bind(registerer);
|
|
468
|
-
// @ts-ignore
|
|
466
|
+
// @ts-ignore: private
|
|
469
467
|
const oldUnregistered = registerer.unregistered.bind(registerer);
|
|
470
468
|
|
|
471
|
-
// @ts-ignore
|
|
469
|
+
// @ts-ignore: private
|
|
472
470
|
registerer.waitingToggle = (waiting: boolean) => {
|
|
473
|
-
// @ts-ignore
|
|
471
|
+
// @ts-ignore: private
|
|
474
472
|
if (!registerer || registerer.waiting === waiting) {
|
|
475
473
|
return;
|
|
476
474
|
}
|
|
@@ -478,7 +476,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
478
476
|
oldWaitingToggle(waiting);
|
|
479
477
|
};
|
|
480
478
|
|
|
481
|
-
// @ts-ignore
|
|
479
|
+
// @ts-ignore: private
|
|
482
480
|
registerer.unregistered = () => {
|
|
483
481
|
if (!registerer || registerer.state === RegistererState.Terminated) {
|
|
484
482
|
return;
|
|
@@ -548,7 +546,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
548
546
|
});
|
|
549
547
|
}
|
|
550
548
|
|
|
551
|
-
call(number: string, enableVideo?: boolean, audioOnly = false, conference = false):
|
|
549
|
+
call(number: string, enableVideo?: boolean, audioOnly = false, conference = false): WazoSession | null {
|
|
552
550
|
logger.info('sdk webrtc creating call', {
|
|
553
551
|
clientId: this.clientId,
|
|
554
552
|
number,
|
|
@@ -569,7 +567,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
569
567
|
}
|
|
570
568
|
|
|
571
569
|
const uri = this._makeURI(number);
|
|
572
|
-
let session:
|
|
570
|
+
let session: WazoSession | null = null;
|
|
573
571
|
|
|
574
572
|
if (uri) {
|
|
575
573
|
session = this.userAgent ? new Inviter(this.userAgent, uri, inviterOptions) : null;
|
|
@@ -590,28 +588,26 @@ export default class WebRTCClient extends Emitter {
|
|
|
590
588
|
const inviteOptions: InviterInviteOptions = {
|
|
591
589
|
requestDelegate: {
|
|
592
590
|
onAccept: (response: IncomingResponse) => {
|
|
593
|
-
if (session
|
|
594
|
-
session
|
|
591
|
+
if ((session?.sessionDescriptionHandler as any)?.peerConnection) {
|
|
592
|
+
(session?.sessionDescriptionHandler as any).peerConnection.sfu = conference;
|
|
595
593
|
}
|
|
596
|
-
|
|
597
|
-
this._onAccepted(session, response.session, true);
|
|
594
|
+
this._onAccepted(session as WazoSession, response.session, true);
|
|
598
595
|
},
|
|
599
|
-
onProgress: payload => {
|
|
596
|
+
onProgress: (payload: IncomingResponse) => {
|
|
600
597
|
if (payload.message.statusCode === 183) {
|
|
601
|
-
// @ts-ignore
|
|
602
598
|
this._onEarlyProgress(payload.session);
|
|
603
599
|
}
|
|
604
600
|
},
|
|
605
601
|
onReject: (response: IncomingResponse) => {
|
|
606
602
|
logger.info('on call rejected', {
|
|
607
|
-
id: session
|
|
608
|
-
// @ts-ignore
|
|
609
|
-
fromTag: session
|
|
603
|
+
id: session?.id,
|
|
604
|
+
// @ts-ignore: fromTag does not exist
|
|
605
|
+
fromTag: session?.fromTag,
|
|
610
606
|
});
|
|
611
607
|
|
|
612
|
-
this._stopSendingStats(session);
|
|
608
|
+
this._stopSendingStats(session as WazoSession);
|
|
613
609
|
|
|
614
|
-
this.stopNetworkMonitoring(session);
|
|
610
|
+
this.stopNetworkMonitoring(session as WazoSession);
|
|
615
611
|
this.eventEmitter.emit(REJECTED, session, response);
|
|
616
612
|
},
|
|
617
613
|
},
|
|
@@ -619,8 +615,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
619
615
|
};
|
|
620
616
|
|
|
621
617
|
if (inviteOptions.sessionDescriptionHandlerOptions) {
|
|
622
|
-
|
|
623
|
-
inviteOptions.sessionDescriptionHandlerOptions.audioOnly = audioOnly;
|
|
618
|
+
(inviteOptions.sessionDescriptionHandlerOptions as SessionDescriptionHandlerOptions & { audioOnly?: boolean }).audioOnly = audioOnly;
|
|
624
619
|
}
|
|
625
620
|
inviteOptions.sessionDescriptionHandlerModifiers = [replaceLocalIpModifier];
|
|
626
621
|
|
|
@@ -628,10 +623,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
628
623
|
inviteOptions.sessionDescriptionHandlerModifiers.push(stripVideo);
|
|
629
624
|
}
|
|
630
625
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
626
|
+
if (session) {
|
|
627
|
+
// Do not await invite here or we'll miss the Establishing state transition
|
|
628
|
+
// @ts-ignore: Property 'invitePromise' does not exist
|
|
629
|
+
session.invitePromise = session.invite(inviteOptions).catch((e: Error) => {
|
|
630
|
+
logger.warn('sdk webrtc creating call, error', e);
|
|
631
|
+
});
|
|
632
|
+
}
|
|
635
633
|
|
|
636
634
|
return session;
|
|
637
635
|
}
|
|
@@ -653,7 +651,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
653
651
|
sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false),
|
|
654
652
|
};
|
|
655
653
|
return this._accept(session, options).then(() => {
|
|
656
|
-
// @ts-ignore
|
|
654
|
+
// @ts-ignore: private
|
|
657
655
|
if (session.isCanceled) {
|
|
658
656
|
const message = 'accepted a canceled session (or was canceled during the accept phase).';
|
|
659
657
|
logger.error(message, {
|
|
@@ -672,8 +670,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
672
670
|
});
|
|
673
671
|
}
|
|
674
672
|
|
|
675
|
-
async hangup(session:
|
|
676
|
-
const { state, id }
|
|
673
|
+
async hangup(session: WazoSession): Promise<OutgoingByeRequest | null> {
|
|
674
|
+
const { state, id } = session;
|
|
677
675
|
logger.info('sdk webrtc hangup call', { clientId: this.clientId, id, state });
|
|
678
676
|
|
|
679
677
|
try {
|
|
@@ -705,9 +703,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
705
703
|
return Promise.resolve(null);
|
|
706
704
|
}
|
|
707
705
|
|
|
708
|
-
async getStats(session:
|
|
709
|
-
|
|
710
|
-
const pc: RTCPeerConnection = session.sessionDescriptionHandler.peerConnection;
|
|
706
|
+
async getStats(session: WazoSession): Promise<RTCStatsReport | null> {
|
|
707
|
+
const pc = (session.sessionDescriptionHandler as SessionDescriptionHandler)?.peerConnection as RTCPeerConnection;
|
|
711
708
|
|
|
712
709
|
if (!pc) {
|
|
713
710
|
return null;
|
|
@@ -717,7 +714,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
717
714
|
}
|
|
718
715
|
|
|
719
716
|
// Fetch and emit an event at `interval` with session network stats
|
|
720
|
-
startNetworkMonitoring(session:
|
|
717
|
+
startNetworkMonitoring(session: WazoSession, interval = 1000): void {
|
|
721
718
|
const sessionId = this.getSipSessionId(session);
|
|
722
719
|
logger.info('starting network inspection', {
|
|
723
720
|
id: sessionId,
|
|
@@ -727,7 +724,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
727
724
|
this.networkMonitoringInterval[sessionId] = setInterval(() => this._fetchNetworkStats(sessionId), interval);
|
|
728
725
|
}
|
|
729
726
|
|
|
730
|
-
stopNetworkMonitoring(session:
|
|
727
|
+
stopNetworkMonitoring(session: WazoSession): void {
|
|
731
728
|
const sessionId = this.getSipSessionId(session);
|
|
732
729
|
const exists = (sessionId in this.networkMonitoringInterval);
|
|
733
730
|
logger.info('stopping network inspection', {
|
|
@@ -743,7 +740,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
743
740
|
}
|
|
744
741
|
}
|
|
745
742
|
|
|
746
|
-
async reject(session:
|
|
743
|
+
async reject(session: WazoSession): Promise<void> {
|
|
747
744
|
logger.info('sdk webrtc reject call', {
|
|
748
745
|
clientId: this.clientId,
|
|
749
746
|
id: session.id,
|
|
@@ -788,7 +785,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
788
785
|
if (this.userAgent) {
|
|
789
786
|
this.userAgent.delegate = undefined;
|
|
790
787
|
}
|
|
791
|
-
// @ts-ignore:
|
|
788
|
+
// @ts-ignore: removeAllListeners does not exist
|
|
792
789
|
this.userAgent.stateChange.removeAllListeners();
|
|
793
790
|
await this._disconnectTransport(force);
|
|
794
791
|
|
|
@@ -796,8 +793,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
796
793
|
|
|
797
794
|
try {
|
|
798
795
|
// Prevent `Connect aborted.` error when disconnecting
|
|
799
|
-
|
|
800
|
-
this.userAgent.transport.connectReject = () => {};
|
|
796
|
+
(this.userAgent.transport as WazoTransport & { connectReject: () => void }).connectReject = () => {};
|
|
801
797
|
// Don't wait here, It can take ~30s to stop ...
|
|
802
798
|
this.userAgent.stop().catch(console.error);
|
|
803
799
|
} catch (_) { // Avoid to raise exception when trying to close with hanged-up sessions remaining
|
|
@@ -813,11 +809,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
813
809
|
return null;
|
|
814
810
|
}
|
|
815
811
|
|
|
816
|
-
// @ts-ignore
|
|
812
|
+
// @ts-ignore: private
|
|
817
813
|
return session.remoteIdentity.uri._normal.user;
|
|
818
814
|
}
|
|
819
815
|
|
|
820
|
-
mute(session:
|
|
816
|
+
mute(session: WazoSession): void {
|
|
821
817
|
logger.info('sdk webrtc mute', {
|
|
822
818
|
id: session.id,
|
|
823
819
|
});
|
|
@@ -825,7 +821,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
825
821
|
this._toggleAudio(session, true);
|
|
826
822
|
}
|
|
827
823
|
|
|
828
|
-
unmute(session:
|
|
824
|
+
unmute(session: WazoSession): void {
|
|
829
825
|
logger.info('sdk webrtc unmute', {
|
|
830
826
|
id: session.id,
|
|
831
827
|
});
|
|
@@ -833,14 +829,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
833
829
|
this._toggleAudio(session, false);
|
|
834
830
|
}
|
|
835
831
|
|
|
836
|
-
isAudioMuted(session:
|
|
832
|
+
isAudioMuted(session: WazoSession): boolean {
|
|
837
833
|
if (!session || !session.sessionDescriptionHandler) {
|
|
838
834
|
return false;
|
|
839
835
|
}
|
|
840
836
|
|
|
841
837
|
let muted = true;
|
|
842
|
-
|
|
843
|
-
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
838
|
+
const pc = (session.sessionDescriptionHandler as SessionDescriptionHandler).peerConnection as PeerConnection;
|
|
844
839
|
|
|
845
840
|
if (!pc) {
|
|
846
841
|
return false;
|
|
@@ -851,7 +846,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
851
846
|
return false;
|
|
852
847
|
}
|
|
853
848
|
|
|
854
|
-
pc.getSenders().forEach((sender
|
|
849
|
+
pc.getSenders().forEach((sender) => {
|
|
855
850
|
if (sender && sender.track && sender.track.kind === 'audio') {
|
|
856
851
|
muted = muted && !sender.track.enabled;
|
|
857
852
|
}
|
|
@@ -871,7 +866,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
871
866
|
return muted;
|
|
872
867
|
}
|
|
873
868
|
|
|
874
|
-
toggleCameraOn(session:
|
|
869
|
+
toggleCameraOn(session: WazoSession): void {
|
|
875
870
|
logger.info('sdk webrtc toggle camera on', {
|
|
876
871
|
id: session.id,
|
|
877
872
|
});
|
|
@@ -879,7 +874,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
879
874
|
this._toggleVideo(session, false);
|
|
880
875
|
}
|
|
881
876
|
|
|
882
|
-
toggleCameraOff(session:
|
|
877
|
+
toggleCameraOff(session: WazoSession): void {
|
|
883
878
|
logger.info('sdk webrtc toggle camera off', {
|
|
884
879
|
id: session.id,
|
|
885
880
|
});
|
|
@@ -887,13 +882,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
887
882
|
this._toggleVideo(session, true);
|
|
888
883
|
}
|
|
889
884
|
|
|
890
|
-
hold(session:
|
|
885
|
+
hold(session: WazoSession, isConference = false, hadVideo = false): Promise<OutgoingInviteRequest | void> {
|
|
891
886
|
const sessionId = this.getSipSessionId(session);
|
|
892
887
|
const hasVideo = hadVideo || this.hasLocalVideo(sessionId);
|
|
893
888
|
logger.info('sdk webrtc hold', {
|
|
894
889
|
sessionId,
|
|
895
890
|
keys: Object.keys(this.heldSessions),
|
|
896
|
-
// @ts-ignore
|
|
891
|
+
// @ts-ignore: private
|
|
897
892
|
pendingReinvite: !!session.pendingReinvite,
|
|
898
893
|
isConference,
|
|
899
894
|
hasVideo,
|
|
@@ -903,7 +898,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
903
898
|
return Promise.resolve();
|
|
904
899
|
}
|
|
905
900
|
|
|
906
|
-
// @ts-ignore
|
|
901
|
+
// @ts-ignore: private
|
|
907
902
|
if (session.pendingReinvite) {
|
|
908
903
|
return Promise.resolve();
|
|
909
904
|
}
|
|
@@ -918,10 +913,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
918
913
|
this.mute(session);
|
|
919
914
|
|
|
920
915
|
session.sessionDescriptionHandlerOptionsReInvite = {
|
|
921
|
-
// @ts-ignore
|
|
922
916
|
hold: true,
|
|
923
917
|
conference: isConference,
|
|
924
|
-
};
|
|
918
|
+
} as SessionDescriptionHandlerOptions;
|
|
925
919
|
const options = this.getMediaConfiguration(false, isConference);
|
|
926
920
|
|
|
927
921
|
if (!this._isWeb()) {
|
|
@@ -936,8 +930,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
936
930
|
|
|
937
931
|
// Avoid sdh to create a new stream
|
|
938
932
|
if (session.sessionDescriptionHandler) {
|
|
939
|
-
// @ts-ignore
|
|
940
|
-
session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
|
|
933
|
+
// @ts-ignore: private
|
|
934
|
+
(session.sessionDescriptionHandler as SessionDescriptionHandler).localMediaStreamConstraints = options.constraints;
|
|
941
935
|
}
|
|
942
936
|
|
|
943
937
|
// Send re-INVITE
|
|
@@ -946,19 +940,19 @@ export default class WebRTCClient extends Emitter {
|
|
|
946
940
|
});
|
|
947
941
|
}
|
|
948
942
|
|
|
949
|
-
unhold(session:
|
|
943
|
+
unhold(session: WazoSession, isConference = false): Promise<OutgoingInviteRequest | void> {
|
|
950
944
|
const sessionId = this.getSipSessionId(session);
|
|
951
945
|
const hasVideo = sessionId in this.heldSessions && this.heldSessions[sessionId].hasVideo;
|
|
952
946
|
logger.info('sdk webrtc unhold', {
|
|
953
947
|
sessionId,
|
|
954
948
|
keys: Object.keys(this.heldSessions),
|
|
955
|
-
// @ts-ignore
|
|
949
|
+
// @ts-ignore: private
|
|
956
950
|
pendingReinvite: !!session.pendingReinvite,
|
|
957
951
|
isConference,
|
|
958
952
|
hasVideo,
|
|
959
953
|
});
|
|
960
954
|
|
|
961
|
-
// @ts-ignore
|
|
955
|
+
// @ts-ignore: private
|
|
962
956
|
if (session.pendingReinvite) {
|
|
963
957
|
return Promise.resolve();
|
|
964
958
|
}
|
|
@@ -967,10 +961,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
967
961
|
|
|
968
962
|
delete this.heldSessions[this.getSipSessionId(session)];
|
|
969
963
|
session.sessionDescriptionHandlerOptionsReInvite = {
|
|
970
|
-
// @ts-ignore
|
|
971
964
|
hold: false,
|
|
972
965
|
conference: isConference,
|
|
973
|
-
};
|
|
966
|
+
} as SessionDescriptionHandlerOptions;
|
|
974
967
|
const options = this.getMediaConfiguration(false, isConference);
|
|
975
968
|
|
|
976
969
|
if (!this._isWeb()) {
|
|
@@ -991,19 +984,18 @@ export default class WebRTCClient extends Emitter {
|
|
|
991
984
|
}
|
|
992
985
|
|
|
993
986
|
// Returns true if a re-INVITE is required
|
|
994
|
-
async upgradeToVideo(session:
|
|
995
|
-
|
|
996
|
-
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
987
|
+
async upgradeToVideo(session: WazoSession, constraints: Record<string, any>, isConference: boolean): Promise<MediaStream | undefined> {
|
|
988
|
+
const pc = (session.sessionDescriptionHandler as SessionDescriptionHandler)?.peerConnection;
|
|
997
989
|
// Check if a video sender already exists
|
|
998
990
|
let videoSender;
|
|
999
991
|
|
|
1000
992
|
if (isConference) {
|
|
1001
993
|
// We search for the last transceiver without `video-` in the mid (video- means remote transceiver)
|
|
1002
|
-
const transceivers = pc
|
|
994
|
+
const transceivers = pc?.getTransceivers() || [];
|
|
1003
995
|
const transceiverIdx = lastIndexOf(transceivers, transceiver => transceiver.sender.track === null && transceiver.mid && transceiver.mid.indexOf('video') === -1);
|
|
1004
996
|
videoSender = transceiverIdx !== -1 ? transceivers[transceiverIdx].sender : null;
|
|
1005
997
|
} else {
|
|
1006
|
-
videoSender = pc && pc.getSenders && pc.getSenders().find((sender
|
|
998
|
+
videoSender = pc && pc.getSenders && pc.getSenders().find((sender) => sender.track === null);
|
|
1007
999
|
}
|
|
1008
1000
|
|
|
1009
1001
|
if (!videoSender) {
|
|
@@ -1021,8 +1013,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1021
1013
|
|
|
1022
1014
|
// Add previous local audio track
|
|
1023
1015
|
if (constraints && !constraints.audio) {
|
|
1024
|
-
|
|
1025
|
-
const localVideoStream: MediaStream = session.sessionDescriptionHandler.localMediaStream;
|
|
1016
|
+
const localVideoStream: MediaStream = (session.sessionDescriptionHandler as SessionDescriptionHandler)?.localMediaStream;
|
|
1026
1017
|
const localAudioTrack = localVideoStream.getTracks().find(track => track.kind === 'audio');
|
|
1027
1018
|
|
|
1028
1019
|
if (localAudioTrack) {
|
|
@@ -1040,17 +1031,16 @@ export default class WebRTCClient extends Emitter {
|
|
|
1040
1031
|
return newStream;
|
|
1041
1032
|
}
|
|
1042
1033
|
|
|
1043
|
-
downgradeToAudio(session:
|
|
1034
|
+
downgradeToAudio(session: WazoSession): void {
|
|
1044
1035
|
// Release local video stream when downgrading to audio
|
|
1045
|
-
|
|
1046
|
-
const localStream =
|
|
1047
|
-
|
|
1048
|
-
const pc = session.sessionDescriptionHandler.peerConnection;
|
|
1036
|
+
const sessionDescriptionHandler = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
1037
|
+
const localStream = sessionDescriptionHandler?.localMediaStream;
|
|
1038
|
+
const pc = sessionDescriptionHandler?.peerConnection;
|
|
1049
1039
|
const videoTracks = localStream.getVideoTracks();
|
|
1050
1040
|
|
|
1051
1041
|
// Remove video senders
|
|
1052
|
-
if (pc
|
|
1053
|
-
pc.getSenders().filter((sender
|
|
1042
|
+
if (pc?.getSenders) {
|
|
1043
|
+
pc.getSenders().filter((sender) => sender.track && sender.track.kind === 'video').forEach((videoSender) => {
|
|
1054
1044
|
videoSender.replaceTrack(null);
|
|
1055
1045
|
});
|
|
1056
1046
|
}
|
|
@@ -1067,7 +1057,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1067
1057
|
const {
|
|
1068
1058
|
constraints: newConstraints,
|
|
1069
1059
|
} = this.getMediaConfiguration(video, conference, constraints);
|
|
1070
|
-
let newStream;
|
|
1060
|
+
let newStream: MediaStream & { local?: boolean } | null = null;
|
|
1071
1061
|
|
|
1072
1062
|
try {
|
|
1073
1063
|
newStream = await wazoMediaStreamFactory(newConstraints);
|
|
@@ -1078,7 +1068,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1078
1068
|
return null;
|
|
1079
1069
|
}
|
|
1080
1070
|
|
|
1081
|
-
// @ts-ignore
|
|
1082
1071
|
newStream.local = true;
|
|
1083
1072
|
return newStream;
|
|
1084
1073
|
}
|
|
@@ -1087,7 +1076,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1087
1076
|
return this.heldSessions[sessionId];
|
|
1088
1077
|
}
|
|
1089
1078
|
|
|
1090
|
-
isCallHeld(session:
|
|
1079
|
+
isCallHeld(session: WazoSession): boolean {
|
|
1091
1080
|
return this.getSipSessionId(session) in this.heldSessions;
|
|
1092
1081
|
}
|
|
1093
1082
|
|
|
@@ -1103,7 +1092,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1103
1092
|
return videoDirection === 'sendonly';
|
|
1104
1093
|
}
|
|
1105
1094
|
|
|
1106
|
-
sendDTMF(session:
|
|
1095
|
+
sendDTMF(session: WazoSession, tone: string): boolean {
|
|
1107
1096
|
if (!session.sessionDescriptionHandler) {
|
|
1108
1097
|
return false;
|
|
1109
1098
|
}
|
|
@@ -1125,7 +1114,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1125
1114
|
messager.message();
|
|
1126
1115
|
}
|
|
1127
1116
|
|
|
1128
|
-
transfer(session:
|
|
1117
|
+
transfer(session: WazoSession, target: string): void {
|
|
1129
1118
|
this.hold(session);
|
|
1130
1119
|
logger.info('Transfering a session', {
|
|
1131
1120
|
id: this.getSipSessionId(session),
|
|
@@ -1149,7 +1138,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1149
1138
|
}
|
|
1150
1139
|
|
|
1151
1140
|
// check https://sipjs.com/api/0.12.0/refer/referClientContext/
|
|
1152
|
-
atxfer(session:
|
|
1141
|
+
atxfer(session: WazoSession): Record<string, any> {
|
|
1153
1142
|
this.hold(session);
|
|
1154
1143
|
logger.info('webrtc transfer started', {
|
|
1155
1144
|
id: this.getSipSessionId(session),
|
|
@@ -1179,7 +1168,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1179
1168
|
}
|
|
1180
1169
|
|
|
1181
1170
|
// eslint-disable-next-line @typescript-eslint/default-param-last
|
|
1182
|
-
sendMessage(sipSession:
|
|
1171
|
+
sendMessage(sipSession: WazoSession | null = null, body: string, contentType = 'text/plain'): void {
|
|
1183
1172
|
if (!sipSession) {
|
|
1184
1173
|
return;
|
|
1185
1174
|
}
|
|
@@ -1228,8 +1217,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
1228
1217
|
}
|
|
1229
1218
|
|
|
1230
1219
|
getState(): UserAgentState {
|
|
1231
|
-
// @ts-ignore
|
|
1232
|
-
return this.userAgent ? states[this.userAgent.state] : UserAgentState.Stopped;
|
|
1220
|
+
// @ts-ignore: something fishy here: `states` content doesn't match UserAgentState at all
|
|
1221
|
+
return this.userAgent ? states[this.userAgent.state] as UserAgentState : UserAgentState.Stopped;
|
|
1233
1222
|
}
|
|
1234
1223
|
|
|
1235
1224
|
getContactIdentifier(): string | null {
|
|
@@ -1263,15 +1252,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
1263
1252
|
// audioElement is an array of HTMLAudioElements, and HTMLAudioElement inherits the method from HTMLMediaElement
|
|
1264
1253
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement
|
|
1265
1254
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId
|
|
1266
|
-
// @ts-ignore
|
|
1267
1255
|
if (audioElement.setSinkId) {
|
|
1268
|
-
// @ts-ignore
|
|
1269
1256
|
audioElement.setSinkId(id);
|
|
1270
1257
|
}
|
|
1271
1258
|
});
|
|
1272
1259
|
}
|
|
1273
1260
|
|
|
1274
|
-
async changeAudioInputDevice(id: string, session:
|
|
1261
|
+
async changeAudioInputDevice(id: string, session: WazoSession | null | undefined, force?: boolean): Promise<MediaStream | null> {
|
|
1275
1262
|
const currentId = this.getAudioDeviceId();
|
|
1276
1263
|
logger.info('setting audio input device', {
|
|
1277
1264
|
id,
|
|
@@ -1315,9 +1302,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
1315
1302
|
}
|
|
1316
1303
|
|
|
1317
1304
|
if (session && navigator.mediaDevices) {
|
|
1318
|
-
const sdh = session.sessionDescriptionHandler;
|
|
1319
|
-
|
|
1320
|
-
const pc = sdh.peerConnection;
|
|
1305
|
+
const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
1306
|
+
const pc = sdh?.peerConnection;
|
|
1321
1307
|
const constraints = {
|
|
1322
1308
|
audio: {
|
|
1323
1309
|
deviceId: {
|
|
@@ -1327,7 +1313,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1327
1313
|
};
|
|
1328
1314
|
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
1329
1315
|
const audioTrack = stream.getAudioTracks()[0];
|
|
1330
|
-
const sender = pc && pc.getSenders && pc.getSenders().find((s
|
|
1316
|
+
const sender = pc && pc.getSenders && pc.getSenders().find((s) => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
|
|
1331
1317
|
|
|
1332
1318
|
if (sender) {
|
|
1333
1319
|
if (sender.track) {
|
|
@@ -1343,7 +1329,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1343
1329
|
return null;
|
|
1344
1330
|
}
|
|
1345
1331
|
|
|
1346
|
-
async changeVideoInputDevice(id: string, session?:
|
|
1332
|
+
async changeVideoInputDevice(id: string, session?: WazoSession): Promise<MediaStream | void> {
|
|
1347
1333
|
this.setVideoInputDevice(id);
|
|
1348
1334
|
|
|
1349
1335
|
if (session) {
|
|
@@ -1371,13 +1357,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
1371
1357
|
};
|
|
1372
1358
|
}
|
|
1373
1359
|
|
|
1374
|
-
changeSessionVideoInputDevice(id: string | null | undefined, session:
|
|
1360
|
+
changeSessionVideoInputDevice(id: string | null | undefined, session: WazoSession): Promise<MediaStream | void> {
|
|
1375
1361
|
if (!this.sessionWantsToDoVideo(session)) {
|
|
1376
1362
|
return Promise.resolve();
|
|
1377
1363
|
}
|
|
1378
1364
|
|
|
1379
|
-
const sdh = session.sessionDescriptionHandler;
|
|
1380
|
-
// @ts-ignore
|
|
1365
|
+
const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
1381
1366
|
const pc = sdh.peerConnection;
|
|
1382
1367
|
const sessionId = this.getSipSessionId(session);
|
|
1383
1368
|
const localStream = this.getLocalStream(sessionId);
|
|
@@ -1402,7 +1387,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1402
1387
|
};
|
|
1403
1388
|
return navigator.mediaDevices.getUserMedia(constraints).then(async stream => {
|
|
1404
1389
|
const videoTrack = stream.getVideoTracks()[0];
|
|
1405
|
-
let sender = pc && pc.getSenders && pc.getSenders().find((s
|
|
1390
|
+
let sender = pc && pc.getSenders && pc.getSenders().find((s) => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
|
|
1406
1391
|
let wasTrackEnabled = false;
|
|
1407
1392
|
|
|
1408
1393
|
if (!sender) {
|
|
@@ -1429,21 +1414,19 @@ export default class WebRTCClient extends Emitter {
|
|
|
1429
1414
|
}
|
|
1430
1415
|
|
|
1431
1416
|
getAudioDeviceId(): string | null | undefined {
|
|
1432
|
-
|
|
1433
|
-
return this.audio && typeof this.audio === 'object' && 'deviceId' in this.audio ? this.audio.deviceId.exact : undefined;
|
|
1417
|
+
return this.audio && typeof this.audio === 'object' && 'deviceId' in this.audio ? (this.audio.deviceId as any)?.exact : undefined;
|
|
1434
1418
|
}
|
|
1435
1419
|
|
|
1436
1420
|
getVideoDeviceId(): string | null {
|
|
1437
|
-
|
|
1438
|
-
return this.video && typeof this.video === 'object' && 'deviceId' in this.video ? this.video.deviceId.exact : undefined;
|
|
1421
|
+
return this.video && typeof this.video === 'object' && 'deviceId' in this.video ? (this.video.deviceId as any)?.exact : undefined;
|
|
1439
1422
|
}
|
|
1440
1423
|
|
|
1441
|
-
reinvite(sipSession:
|
|
1424
|
+
reinvite(sipSession: WazoSession, newConstraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
|
|
1442
1425
|
if (!sipSession) {
|
|
1443
1426
|
return Promise.resolve();
|
|
1444
1427
|
}
|
|
1445
1428
|
|
|
1446
|
-
// @ts-ignore
|
|
1429
|
+
// @ts-ignore: private
|
|
1447
1430
|
if (sipSession.pendingReinvite) {
|
|
1448
1431
|
return Promise.resolve();
|
|
1449
1432
|
}
|
|
@@ -1471,10 +1454,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
1471
1454
|
}
|
|
1472
1455
|
|
|
1473
1456
|
sipSession.sessionDescriptionHandlerOptionsReInvite = { ...sipSession.sessionDescriptionHandlerOptionsReInvite,
|
|
1474
|
-
// @ts-ignore
|
|
1475
1457
|
conference,
|
|
1476
1458
|
audioOnly,
|
|
1477
|
-
};
|
|
1459
|
+
} as SessionDescriptionHandlerOptions;
|
|
1478
1460
|
const {
|
|
1479
1461
|
constraints,
|
|
1480
1462
|
} = this.getMediaConfiguration(shouldDoVideo, conference, newConstraints);
|
|
@@ -1483,12 +1465,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
1483
1465
|
onAccept: (response: IncomingResponse) => {
|
|
1484
1466
|
// Update the SDP body to be able to call sessionWantsToDoVideo correctly in `_setup[Local|Remote]Media`.
|
|
1485
1467
|
// Can't set directly sipSession.body because it's a getter.
|
|
1486
|
-
// @ts-ignore
|
|
1468
|
+
// @ts-ignore: private
|
|
1487
1469
|
if (sipSession instanceof Inviter && sipSession.outgoingRequestMessage.body) {
|
|
1488
|
-
// @ts-ignore
|
|
1470
|
+
// @ts-ignore: private
|
|
1489
1471
|
sipSession.outgoingRequestMessage.body.body = response.message.body;
|
|
1490
1472
|
} else if (sipSession instanceof Invitation) {
|
|
1491
|
-
// @ts-ignore
|
|
1473
|
+
// @ts-ignore: private
|
|
1492
1474
|
sipSession.incomingInviteRequest.message.body = response.message.body;
|
|
1493
1475
|
}
|
|
1494
1476
|
|
|
@@ -1503,7 +1485,6 @@ export default class WebRTCClient extends Emitter {
|
|
|
1503
1485
|
this.mute(sipSession);
|
|
1504
1486
|
}
|
|
1505
1487
|
|
|
1506
|
-
// @ts-ignore
|
|
1507
1488
|
this._onAccepted(sipSession, response.session, false, false);
|
|
1508
1489
|
|
|
1509
1490
|
if (shouldDoScreenSharing) {
|
|
@@ -1519,13 +1500,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
1519
1500
|
},
|
|
1520
1501
|
sessionDescriptionHandlerOptions: {
|
|
1521
1502
|
constraints,
|
|
1522
|
-
// @ts-ignore
|
|
1523
1503
|
conference,
|
|
1524
1504
|
audioOnly,
|
|
1525
1505
|
offerOptions: {
|
|
1526
1506
|
iceRestart,
|
|
1527
1507
|
},
|
|
1528
|
-
},
|
|
1508
|
+
} as SessionDescriptionHandlerOptions,
|
|
1529
1509
|
});
|
|
1530
1510
|
}
|
|
1531
1511
|
|
|
@@ -1544,15 +1524,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
1544
1524
|
return null;
|
|
1545
1525
|
}
|
|
1546
1526
|
|
|
1547
|
-
|
|
1548
|
-
return sipSession.sessionDescriptionHandler ? sipSession.sessionDescriptionHandler.peerConnection : null;
|
|
1527
|
+
return sipSession.sessionDescriptionHandler ? (sipSession.sessionDescriptionHandler as SessionDescriptionHandler).peerConnection : null;
|
|
1549
1528
|
}
|
|
1550
1529
|
|
|
1551
1530
|
// Local streams
|
|
1552
1531
|
getLocalStream(sessionId: string): MediaStream | null {
|
|
1553
1532
|
const sipSession = this.sipSessions[sessionId];
|
|
1554
|
-
|
|
1555
|
-
return sipSession?.sessionDescriptionHandler?.localMediaStream || null;
|
|
1533
|
+
return (sipSession?.sessionDescriptionHandler as SessionDescriptionHandler)?.localMediaStream || null;
|
|
1556
1534
|
}
|
|
1557
1535
|
|
|
1558
1536
|
getLocalTracks(sessionId: string): MediaStreamTrack[] {
|
|
@@ -1581,8 +1559,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1581
1559
|
// Remote streams
|
|
1582
1560
|
getRemoteStream(sessionId: string): MediaStream | null {
|
|
1583
1561
|
const sipSession = this.sipSessions[sessionId];
|
|
1584
|
-
|
|
1585
|
-
return sipSession?.sessionDescriptionHandler?.remoteMediaStream || null;
|
|
1562
|
+
return (sipSession?.sessionDescriptionHandler as SessionDescriptionHandler)?.remoteMediaStream || null;
|
|
1586
1563
|
}
|
|
1587
1564
|
|
|
1588
1565
|
getRemoteTracks(sessionId: string): MediaStreamTrack[] {
|
|
@@ -1614,7 +1591,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1614
1591
|
|
|
1615
1592
|
// Useful in a react-native environment when remoteMediaStream is not updated
|
|
1616
1593
|
getRemoteVideoStreamFromPc(sessionId: string): MediaStream | null | undefined {
|
|
1617
|
-
const pc = this.getPeerConnection(sessionId);
|
|
1594
|
+
const pc = this.getPeerConnection(sessionId) as PeerConnection;
|
|
1618
1595
|
|
|
1619
1596
|
if (!pc) {
|
|
1620
1597
|
return null;
|
|
@@ -1631,21 +1608,20 @@ export default class WebRTCClient extends Emitter {
|
|
|
1631
1608
|
return this.hasALocalVideoTrack(sessionId) || this.hasARemoteVideoTrack(sessionId);
|
|
1632
1609
|
}
|
|
1633
1610
|
|
|
1634
|
-
getSipSessionId(sipSession:
|
|
1611
|
+
getSipSessionId(sipSession: WazoSession | null | undefined): string {
|
|
1635
1612
|
if (!sipSession) {
|
|
1636
1613
|
return '';
|
|
1637
1614
|
}
|
|
1638
1615
|
|
|
1639
|
-
|
|
1640
|
-
if (
|
|
1641
|
-
|
|
1642
|
-
return sipSession.message.callId.substring(0, SIP_ID_LENGTH);
|
|
1616
|
+
const message = sipSession.message as Partial<{ callId?: string }>;
|
|
1617
|
+
if (message?.callId) {
|
|
1618
|
+
return message.callId.substring(0, SIP_ID_LENGTH);
|
|
1643
1619
|
}
|
|
1644
1620
|
|
|
1645
1621
|
// For Inviter
|
|
1646
|
-
// @ts-ignore
|
|
1622
|
+
// @ts-ignore: private
|
|
1647
1623
|
if (sipSession instanceof Inviter && sipSession.outgoingRequestMessage) {
|
|
1648
|
-
// @ts-ignore
|
|
1624
|
+
// @ts-ignore: private
|
|
1649
1625
|
return sipSession.outgoingRequestMessage.callId.substring(0, SIP_ID_LENGTH);
|
|
1650
1626
|
}
|
|
1651
1627
|
|
|
@@ -1658,7 +1634,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1658
1634
|
}
|
|
1659
1635
|
|
|
1660
1636
|
// eslint-disable-next-line no-unused-vars
|
|
1661
|
-
sessionWantsToDoVideo(session:
|
|
1637
|
+
sessionWantsToDoVideo(session: WazoSession): boolean {
|
|
1662
1638
|
if (!session) {
|
|
1663
1639
|
return false;
|
|
1664
1640
|
}
|
|
@@ -1701,7 +1677,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1701
1677
|
this.heartbeatCb = cb;
|
|
1702
1678
|
}
|
|
1703
1679
|
|
|
1704
|
-
onCallEnded(session:
|
|
1680
|
+
onCallEnded(session: WazoSession): void {
|
|
1705
1681
|
this._cleanupMedia(session);
|
|
1706
1682
|
|
|
1707
1683
|
delete this.sipSessions[this.getSipSessionId(session)];
|
|
@@ -1718,18 +1694,18 @@ export default class WebRTCClient extends Emitter {
|
|
|
1718
1694
|
return;
|
|
1719
1695
|
}
|
|
1720
1696
|
|
|
1721
|
-
// @ts-ignore
|
|
1697
|
+
// @ts-ignore: private
|
|
1722
1698
|
this.userAgent.attemptReconnection();
|
|
1723
1699
|
}
|
|
1724
1700
|
|
|
1725
|
-
storeSipSession(session:
|
|
1701
|
+
storeSipSession(session: WazoSession): void {
|
|
1726
1702
|
const id = this.getSipSessionId(session);
|
|
1727
1703
|
logger.info('storing sip session', { id, clientId: this.clientId });
|
|
1728
1704
|
|
|
1729
1705
|
this.sipSessions[id] = session;
|
|
1730
1706
|
}
|
|
1731
1707
|
|
|
1732
|
-
getSipSession(id: string):
|
|
1708
|
+
getSipSession(id: string): WazoSession | null | undefined {
|
|
1733
1709
|
return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_LENGTH)] : null;
|
|
1734
1710
|
}
|
|
1735
1711
|
|
|
@@ -1750,7 +1726,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1750
1726
|
});
|
|
1751
1727
|
if (sipSession.sessionDescriptionHandler) {
|
|
1752
1728
|
// eslint-disable-next-line no-underscore-dangle
|
|
1753
|
-
// @ts-ignore
|
|
1729
|
+
// @ts-ignore: protected
|
|
1754
1730
|
sipSession.sessionDescriptionHandler._localMediaStream = newStream;
|
|
1755
1731
|
}
|
|
1756
1732
|
}
|
|
@@ -1785,7 +1761,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1785
1761
|
logger.info('Updating remote stream', {
|
|
1786
1762
|
sessionId,
|
|
1787
1763
|
tracks: remoteStream ? remoteStream.getTracks() : null,
|
|
1788
|
-
receiverTracks: pc && pc.getReceivers ? pc.getReceivers().map((receiver
|
|
1764
|
+
receiverTracks: pc && pc.getReceivers ? pc.getReceivers().map((receiver) => receiver.track) : null,
|
|
1789
1765
|
});
|
|
1790
1766
|
|
|
1791
1767
|
if (!pc || !remoteStream) {
|
|
@@ -1799,7 +1775,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1799
1775
|
});
|
|
1800
1776
|
|
|
1801
1777
|
if (pc.getReceivers) {
|
|
1802
|
-
pc.getReceivers().forEach((receiver
|
|
1778
|
+
pc.getReceivers().forEach((receiver) => {
|
|
1803
1779
|
if (allTracks || receiver.track.kind === 'video') {
|
|
1804
1780
|
remoteStream.addTrack(receiver.track);
|
|
1805
1781
|
}
|
|
@@ -1884,15 +1860,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
1884
1860
|
}
|
|
1885
1861
|
|
|
1886
1862
|
if (this.userAgent?.transport) {
|
|
1887
|
-
|
|
1888
|
-
this.userAgent.transport.configuration.traceSip = true;
|
|
1863
|
+
(this.userAgent.transport as WazoTransport).configuration.traceSip = true;
|
|
1889
1864
|
}
|
|
1890
1865
|
|
|
1891
|
-
// @ts-ignore
|
|
1866
|
+
// @ts-ignore: private
|
|
1892
1867
|
this.userAgent.loggerFactory.builtinEnabled = true;
|
|
1893
|
-
// @ts-ignore
|
|
1868
|
+
// @ts-ignore: private
|
|
1894
1869
|
this.userAgent.loggerFactory.level = 3; // debug
|
|
1895
|
-
// @ts-ignore
|
|
1870
|
+
// @ts-ignore: private
|
|
1896
1871
|
this.userAgent.loggerFactory.connector = logConnector;
|
|
1897
1872
|
}
|
|
1898
1873
|
|
|
@@ -1925,8 +1900,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
1925
1900
|
|
|
1926
1901
|
if (this.userAgent && this.userAgent.transport) {
|
|
1927
1902
|
// Disconnect from WS and triggers events, but do not trigger disconnect if already disconnecting...
|
|
1928
|
-
|
|
1929
|
-
|
|
1903
|
+
const transport = this.userAgent.transport as WazoTransport;
|
|
1904
|
+
// @HEADS UP
|
|
1905
|
+
if (!transport.transitioningState && !transport.disconnectPromise) {
|
|
1930
1906
|
try {
|
|
1931
1907
|
await this.userAgent.transport.disconnect();
|
|
1932
1908
|
} catch (e: any) {
|
|
@@ -1952,7 +1928,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1952
1928
|
}
|
|
1953
1929
|
|
|
1954
1930
|
_getAudioConstraints(): MediaTrackConstraints | boolean {
|
|
1955
|
-
// @ts-ignore
|
|
1931
|
+
// @ts-ignore: media constraints
|
|
1956
1932
|
return this.audio?.deviceId?.exact ? this.audio : true;
|
|
1957
1933
|
}
|
|
1958
1934
|
|
|
@@ -1961,7 +1937,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1961
1937
|
return false;
|
|
1962
1938
|
}
|
|
1963
1939
|
|
|
1964
|
-
// @ts-ignore
|
|
1940
|
+
// @ts-ignore: media constraints
|
|
1965
1941
|
return this.video?.deviceId?.exact ? this.video : true;
|
|
1966
1942
|
}
|
|
1967
1943
|
|
|
@@ -1980,8 +1956,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
1980
1956
|
|
|
1981
1957
|
if (this.isConnecting()) {
|
|
1982
1958
|
logger.info('webrtc sdk, already connecting...');
|
|
1983
|
-
|
|
1984
|
-
this.connectionPromise = this.userAgent.transport.connectPromise;
|
|
1959
|
+
this.connectionPromise = (this.userAgent.transport as WazoTransport).connectPromise;
|
|
1985
1960
|
return Promise.resolve(this.connectionPromise);
|
|
1986
1961
|
}
|
|
1987
1962
|
|
|
@@ -1994,20 +1969,19 @@ export default class WebRTCClient extends Emitter {
|
|
|
1994
1969
|
|
|
1995
1970
|
// Force UA to reconnect
|
|
1996
1971
|
if (this.userAgent && this.userAgent.state !== UserAgentState.Stopped) {
|
|
1997
|
-
// @ts-ignore
|
|
1972
|
+
// @ts-ignore: private
|
|
1998
1973
|
this.userAgent.transitionState(UserAgentState.Stopped);
|
|
1999
1974
|
}
|
|
2000
1975
|
|
|
2001
1976
|
if (this.userAgent.transport && this.userAgent.transport.state !== TransportState.Disconnected) {
|
|
2002
|
-
|
|
2003
|
-
this.userAgent.transport.transitionState(TransportState.Disconnected);
|
|
1977
|
+
(this.userAgent.transport as WazoTransport).transitionState(TransportState.Disconnected);
|
|
2004
1978
|
}
|
|
2005
1979
|
|
|
2006
1980
|
this.connectionPromise = this.userAgent.start().catch(console.error);
|
|
2007
1981
|
return this.connectionPromise;
|
|
2008
1982
|
}
|
|
2009
1983
|
|
|
2010
|
-
_buildConfig(config: WebRtcConfig, session:
|
|
1984
|
+
_buildConfig(config: WebRtcConfig, session: WazoSession | null | undefined): Promise<WebRtcConfig> {
|
|
2011
1985
|
// If no session provided, return the configuration directly
|
|
2012
1986
|
if (!session) {
|
|
2013
1987
|
return new Promise(resolve => resolve(config));
|
|
@@ -2016,13 +1990,10 @@ export default class WebRTCClient extends Emitter {
|
|
|
2016
1990
|
const client = new ApiClient({
|
|
2017
1991
|
server: `${config.host}:${String(config.port || 443)}`,
|
|
2018
1992
|
});
|
|
2019
|
-
|
|
2020
|
-
client.
|
|
2021
|
-
// @ts-ignore
|
|
2022
|
-
client.setRefreshToken(session.refreshToken);
|
|
1993
|
+
client.setToken((session as any).token);
|
|
1994
|
+
client.setRefreshToken((session as any).refreshToken);
|
|
2023
1995
|
|
|
2024
|
-
|
|
2025
|
-
return client.confd.getUserLineSipFromToken(session.uuid).then(sipLine => ({
|
|
1996
|
+
return client.confd.getUserLineSipFromToken((session as any).uuid).then(sipLine => ({
|
|
2026
1997
|
authorizationUser: sipLine.username,
|
|
2027
1998
|
password: sipLine.secret,
|
|
2028
1999
|
uri: `${sipLine.username}@${config.host}`,
|
|
@@ -2065,15 +2036,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
2065
2036
|
|
|
2066
2037
|
const isWeb = this._isWeb();
|
|
2067
2038
|
|
|
2068
|
-
|
|
2069
|
-
const iceGatheringTimeout = 'peerConnectionOptions' in options ? options.peerConnectionOptions.iceGatheringTimeout || DEFAULT_ICE_TIMEOUT : DEFAULT_ICE_TIMEOUT;
|
|
2039
|
+
const iceGatheringTimeout = 'peerConnectionOptions' in options ? (options.peerConnectionOptions as any).iceGatheringTimeout || DEFAULT_ICE_TIMEOUT : DEFAULT_ICE_TIMEOUT;
|
|
2070
2040
|
const sdhOptions: SessionDescriptionHandlerConfiguration = { ...options,
|
|
2071
2041
|
iceGatheringTimeout,
|
|
2072
2042
|
peerConnectionConfiguration: { ...defaultPeerConnectionConfiguration(),
|
|
2073
2043
|
...(options.peerConnectionConfiguration || {}),
|
|
2074
2044
|
},
|
|
2075
2045
|
};
|
|
2076
|
-
return new WazoSessionDescriptionHandler(uaLogger, wazoMediaStreamFactory, sdhOptions, isWeb, session as
|
|
2046
|
+
return new WazoSessionDescriptionHandler(uaLogger, wazoMediaStreamFactory, sdhOptions, isWeb, session as WazoSession);
|
|
2077
2047
|
},
|
|
2078
2048
|
transportOptions: {
|
|
2079
2049
|
traceSip: uaOptionsOverrides?.traceSip || false,
|
|
@@ -2124,7 +2094,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2124
2094
|
}
|
|
2125
2095
|
|
|
2126
2096
|
// Invitation and Inviter extends Session
|
|
2127
|
-
_setupSession(session:
|
|
2097
|
+
_setupSession(session: WazoSession): void {
|
|
2128
2098
|
const sipSessionId = this.getSipSessionId(session);
|
|
2129
2099
|
|
|
2130
2100
|
// When receiving an Invitation, the delegate is not defined.
|
|
@@ -2132,9 +2102,8 @@ export default class WebRTCClient extends Emitter {
|
|
|
2132
2102
|
session.delegate = {};
|
|
2133
2103
|
}
|
|
2134
2104
|
|
|
2135
|
-
session.delegate.onSessionDescriptionHandler = (sdh: SessionDescriptionHandler) => {
|
|
2136
|
-
|
|
2137
|
-
sdh.on('error', e => {
|
|
2105
|
+
session.delegate.onSessionDescriptionHandler = (sdh: SessionDescriptionHandler & { on: (type: string, e: any) => void }) => {
|
|
2106
|
+
sdh.on('error', (e: any) => {
|
|
2138
2107
|
this.eventEmitter.emit(ON_ERROR, e);
|
|
2139
2108
|
});
|
|
2140
2109
|
sdh.peerConnectionDelegate = {
|
|
@@ -2150,13 +2119,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
2150
2119
|
};
|
|
2151
2120
|
};
|
|
2152
2121
|
|
|
2153
|
-
// @ts-ignore
|
|
2122
|
+
// @ts-ignore: protected
|
|
2154
2123
|
const oldInviteRequest = session.onInviteRequest.bind(session);
|
|
2155
2124
|
let hadRemoteVideo = false;
|
|
2156
2125
|
|
|
2157
2126
|
// Monkey patch `onInviteRequest` to be able to know if there was a remote video stream before `onInvite` is called
|
|
2158
2127
|
// Because when `onInvite` is called we already got the video track
|
|
2159
|
-
// @ts-ignore
|
|
2128
|
+
// @ts-ignore: protected
|
|
2160
2129
|
session.onInviteRequest = request => {
|
|
2161
2130
|
hadRemoteVideo = this.hasARemoteVideoTrack(sipSessionId);
|
|
2162
2131
|
oldInviteRequest(request);
|
|
@@ -2167,7 +2136,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2167
2136
|
let updatedNumber = null;
|
|
2168
2137
|
|
|
2169
2138
|
if (session.assertedIdentity) {
|
|
2170
|
-
// @ts-ignore
|
|
2139
|
+
// @ts-ignore: private
|
|
2171
2140
|
updatedNumber = session.assertedIdentity.uri.normal.user;
|
|
2172
2141
|
updatedCalleeName = session.assertedIdentity.displayName || updatedNumber;
|
|
2173
2142
|
}
|
|
@@ -2182,11 +2151,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
2182
2151
|
// Update SDP
|
|
2183
2152
|
// Remote video is handled by the `track` event. Here we're dealing with video stream removal.
|
|
2184
2153
|
if (session instanceof Invitation) {
|
|
2185
|
-
// @ts-ignore
|
|
2154
|
+
// @ts-ignore: private
|
|
2186
2155
|
session.incomingInviteRequest.message.body = request.body;
|
|
2187
|
-
// @ts-ignore
|
|
2156
|
+
// @ts-ignore: private
|
|
2188
2157
|
} else if (session instanceof Inviter && session.outgoingInviteRequest.message.body) {
|
|
2189
|
-
// @ts-ignore
|
|
2158
|
+
// @ts-ignore: private
|
|
2190
2159
|
session.outgoingInviteRequest.message.body.body = request.body;
|
|
2191
2160
|
}
|
|
2192
2161
|
|
|
@@ -2198,7 +2167,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2198
2167
|
};
|
|
2199
2168
|
}
|
|
2200
2169
|
|
|
2201
|
-
_onEarlyProgress(session:
|
|
2170
|
+
_onEarlyProgress(session: WazoSession): void {
|
|
2202
2171
|
this._setupMedias(session);
|
|
2203
2172
|
|
|
2204
2173
|
const sessionId = this.getSipSessionId(session).substr(0, 20);
|
|
@@ -2209,11 +2178,10 @@ export default class WebRTCClient extends Emitter {
|
|
|
2209
2178
|
this.eventEmitter.emit(ON_EARLY_MEDIA, session);
|
|
2210
2179
|
}
|
|
2211
2180
|
|
|
2212
|
-
_onAccepted(session:
|
|
2181
|
+
_onAccepted(session: WazoSession, sessionDialog?: SessionDialog, withEvent = true, initAllTracks = true): void {
|
|
2213
2182
|
logger.info('on call accepted', {
|
|
2214
2183
|
id: session.id,
|
|
2215
2184
|
clientId: this.clientId,
|
|
2216
|
-
// @ts-ignore
|
|
2217
2185
|
remoteTag: session.remoteTag,
|
|
2218
2186
|
});
|
|
2219
2187
|
this.storeSipSession(session);
|
|
@@ -2221,10 +2189,9 @@ export default class WebRTCClient extends Emitter {
|
|
|
2221
2189
|
this._setupMedias(session);
|
|
2222
2190
|
|
|
2223
2191
|
this.updateRemoteStream(this.getSipSessionId(session), initAllTracks);
|
|
2224
|
-
|
|
2225
|
-
const pc = session.sessionDescriptionHandler?.peerConnection;
|
|
2192
|
+
const pc = (session.sessionDescriptionHandler as SessionDescriptionHandler)?.peerConnection;
|
|
2226
2193
|
|
|
2227
|
-
const onTrack = (event:
|
|
2194
|
+
const onTrack = (event: RTCTrackEvent | MediaStreamTrackEvent) => {
|
|
2228
2195
|
const isAudioOnly = this._isAudioOnly(session);
|
|
2229
2196
|
|
|
2230
2197
|
const {
|
|
@@ -2251,14 +2218,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
2251
2218
|
this.eventEmitter.emit(ON_TRACK, session, event);
|
|
2252
2219
|
};
|
|
2253
2220
|
|
|
2254
|
-
|
|
2255
|
-
if (
|
|
2256
|
-
|
|
2257
|
-
session.sessionDescriptionHandler.peerConnection.addEventListener('track', onTrack);
|
|
2221
|
+
const sessionDescriptionHandler = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
2222
|
+
if (sessionDescriptionHandler?.peerConnection) {
|
|
2223
|
+
sessionDescriptionHandler.peerConnection.addEventListener('track', onTrack);
|
|
2258
2224
|
}
|
|
2259
2225
|
|
|
2260
|
-
|
|
2261
|
-
session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
|
|
2226
|
+
sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
|
|
2262
2227
|
|
|
2263
2228
|
if (pc) {
|
|
2264
2229
|
pc.oniceconnectionstatechange = () => {
|
|
@@ -2279,11 +2244,11 @@ export default class WebRTCClient extends Emitter {
|
|
|
2279
2244
|
this._startSendingStats(session);
|
|
2280
2245
|
}
|
|
2281
2246
|
|
|
2282
|
-
_isAudioOnly(session:
|
|
2247
|
+
_isAudioOnly(session: WazoSession): boolean {
|
|
2283
2248
|
return Boolean(session.sessionDescriptionHandlerModifiersReInvite.find(modifier => modifier === stripVideo));
|
|
2284
2249
|
}
|
|
2285
2250
|
|
|
2286
|
-
_setupMedias(session:
|
|
2251
|
+
_setupMedias(session: WazoSession, newStream: MediaStream | null | undefined = null): void {
|
|
2287
2252
|
if (!this._isWeb()) {
|
|
2288
2253
|
logger.info('Setup media on mobile, no need to setup html element, bailing');
|
|
2289
2254
|
return;
|
|
@@ -2305,11 +2270,10 @@ export default class WebRTCClient extends Emitter {
|
|
|
2305
2270
|
}
|
|
2306
2271
|
|
|
2307
2272
|
const audioElement = this.audioElements[sessionId];
|
|
2308
|
-
|
|
2309
|
-
const sipSession = this.sipSessions[session.callId];
|
|
2273
|
+
const sipSession = this.sipSessions[session.callId as string];
|
|
2310
2274
|
const removeStream = this.getRemoteStream(sessionId);
|
|
2311
|
-
|
|
2312
|
-
const earlyStream =
|
|
2275
|
+
const sdh = sipSession.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
2276
|
+
const earlyStream = sdh ? sdh.remoteMediaStream : null;
|
|
2313
2277
|
const stream = newStream || removeStream || earlyStream;
|
|
2314
2278
|
|
|
2315
2279
|
if (!stream) {
|
|
@@ -2345,7 +2309,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2345
2309
|
audioElement.play().catch(() => {});
|
|
2346
2310
|
}
|
|
2347
2311
|
|
|
2348
|
-
_cleanupMedia(session?:
|
|
2312
|
+
_cleanupMedia(session?: WazoSession): void {
|
|
2349
2313
|
const sessionId = this.getSipSessionId(session);
|
|
2350
2314
|
const localStream = this.getLocalStream(sessionId);
|
|
2351
2315
|
|
|
@@ -2383,16 +2347,16 @@ export default class WebRTCClient extends Emitter {
|
|
|
2383
2347
|
stream.getTracks().filter(track => track.enabled).forEach(track => track.stop());
|
|
2384
2348
|
}
|
|
2385
2349
|
|
|
2386
|
-
_toggleAudio(session:
|
|
2387
|
-
|
|
2388
|
-
const pc =
|
|
2350
|
+
_toggleAudio(session: WazoSession, muteAudio: boolean): void {
|
|
2351
|
+
const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
2352
|
+
const pc = (sdh?.peerConnection || null) as PeerConnection;
|
|
2389
2353
|
|
|
2390
2354
|
if (!pc) {
|
|
2391
2355
|
return;
|
|
2392
2356
|
}
|
|
2393
2357
|
|
|
2394
2358
|
if (pc.getSenders) {
|
|
2395
|
-
pc.getSenders().forEach((sender
|
|
2359
|
+
pc.getSenders().forEach((sender) => {
|
|
2396
2360
|
if (sender && sender.track && sender.track.kind === 'audio') {
|
|
2397
2361
|
// eslint-disable-next-line
|
|
2398
2362
|
sender.track.enabled = !muteAudio;
|
|
@@ -2408,12 +2372,12 @@ export default class WebRTCClient extends Emitter {
|
|
|
2408
2372
|
}
|
|
2409
2373
|
}
|
|
2410
2374
|
|
|
2411
|
-
_toggleVideo(session:
|
|
2412
|
-
|
|
2413
|
-
const pc =
|
|
2375
|
+
_toggleVideo(session: WazoSession, muteCamera: boolean): void {
|
|
2376
|
+
const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
2377
|
+
const pc = sdh?.peerConnection as PeerConnection;
|
|
2414
2378
|
|
|
2415
|
-
if (pc
|
|
2416
|
-
pc.getSenders().forEach((sender
|
|
2379
|
+
if (pc?.getSenders) {
|
|
2380
|
+
pc.getSenders().forEach((sender) => {
|
|
2417
2381
|
if (sender && sender.track && sender.track.kind === 'video') {
|
|
2418
2382
|
// eslint-disable-next-line
|
|
2419
2383
|
sender.track.enabled = !muteCamera;
|
|
@@ -2432,13 +2396,13 @@ export default class WebRTCClient extends Emitter {
|
|
|
2432
2396
|
/**
|
|
2433
2397
|
* @param pc RTCPeerConnection
|
|
2434
2398
|
*/
|
|
2435
|
-
_getRemoteStream(pc:
|
|
2399
|
+
_getRemoteStream(pc: PeerConnection): MediaStream | null {
|
|
2436
2400
|
let remoteStream: MediaStream | null = null;
|
|
2437
2401
|
|
|
2438
2402
|
if (pc && pc.getReceivers) {
|
|
2439
2403
|
remoteStream = typeof global !== 'undefined' && global.window && global.window.MediaStream ? new global.window.MediaStream() : new window.MediaStream();
|
|
2440
2404
|
|
|
2441
|
-
pc.getReceivers().forEach((receiver
|
|
2405
|
+
pc.getReceivers().forEach((receiver) => {
|
|
2442
2406
|
const {
|
|
2443
2407
|
track,
|
|
2444
2408
|
} = receiver;
|
|
@@ -2456,15 +2420,15 @@ export default class WebRTCClient extends Emitter {
|
|
|
2456
2420
|
|
|
2457
2421
|
_cleanupRegister(): void {
|
|
2458
2422
|
if (this.registerer) {
|
|
2459
|
-
// @ts-ignore
|
|
2423
|
+
// @ts-ignore: removeAllListeners does not exist
|
|
2460
2424
|
this.registerer.stateChange.removeAllListeners();
|
|
2461
2425
|
this.registerer = null;
|
|
2462
2426
|
}
|
|
2463
2427
|
}
|
|
2464
2428
|
|
|
2465
|
-
_startSendingStats(session:
|
|
2466
|
-
|
|
2467
|
-
const pc =
|
|
2429
|
+
_startSendingStats(session: WazoSession): void {
|
|
2430
|
+
const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
|
|
2431
|
+
const pc = sdh.peerConnection;
|
|
2468
2432
|
|
|
2469
2433
|
if (!pc) {
|
|
2470
2434
|
return;
|
|
@@ -2486,7 +2450,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2486
2450
|
}, SEND_STATS_DELAY);
|
|
2487
2451
|
}
|
|
2488
2452
|
|
|
2489
|
-
_stopSendingStats(session:
|
|
2453
|
+
_stopSendingStats(session: WazoSession): void {
|
|
2490
2454
|
const sessionId = this.getSipSessionId(session);
|
|
2491
2455
|
logger.trace('Check for stopping stats', {
|
|
2492
2456
|
sessionId,
|
|
@@ -2507,25 +2471,23 @@ export default class WebRTCClient extends Emitter {
|
|
|
2507
2471
|
}
|
|
2508
2472
|
|
|
2509
2473
|
async _disconnectTransport(force = false) {
|
|
2510
|
-
|
|
2474
|
+
const transport = this.userAgent?.transport as WazoTransport;
|
|
2475
|
+
|
|
2476
|
+
if (force && transport) {
|
|
2511
2477
|
// Bypass sip.js state machine that prevent to close WS with the state `Connecting`
|
|
2512
|
-
|
|
2513
|
-
this.userAgent.transport.disconnectResolve = () => {};
|
|
2478
|
+
transport.disconnectResolve = () => {};
|
|
2514
2479
|
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
// @ts-ignore
|
|
2518
|
-
this.userAgent.transport._ws.close(1000);
|
|
2480
|
+
if (transport._ws) {
|
|
2481
|
+
transport._ws.close(1000);
|
|
2519
2482
|
}
|
|
2520
2483
|
|
|
2521
2484
|
return;
|
|
2522
2485
|
}
|
|
2523
2486
|
|
|
2524
2487
|
// Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
|
|
2525
|
-
|
|
2526
|
-
if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
|
|
2488
|
+
if (transport && !transport.disconnectPromise) {
|
|
2527
2489
|
try {
|
|
2528
|
-
await
|
|
2490
|
+
await transport.disconnect();
|
|
2529
2491
|
} catch (e: any) {
|
|
2530
2492
|
logger.error('WebRTC transport disconnect, error', e);
|
|
2531
2493
|
}
|
|
@@ -2657,7 +2619,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2657
2619
|
throw new Error(error);
|
|
2658
2620
|
}
|
|
2659
2621
|
|
|
2660
|
-
// @ts-ignore
|
|
2622
|
+
// @ts-ignore: private
|
|
2661
2623
|
if (!session.incomingInviteRequest.acceptable) {
|
|
2662
2624
|
const error = 'Trying to reject a non `acceptable` session';
|
|
2663
2625
|
logger.warn(error, { state: session.state, sessionId: session.id });
|
|
@@ -2677,7 +2639,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2677
2639
|
return;
|
|
2678
2640
|
}
|
|
2679
2641
|
|
|
2680
|
-
// @ts-ignore
|
|
2642
|
+
// @ts-ignore: private
|
|
2681
2643
|
if (!session.incomingInviteRequest.rejectable) {
|
|
2682
2644
|
logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: session.id });
|
|
2683
2645
|
return;
|
|
@@ -2703,7 +2665,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
2703
2665
|
}
|
|
2704
2666
|
}
|
|
2705
2667
|
|
|
2706
|
-
async _bye(session:
|
|
2668
|
+
async _bye(session: WazoSession, options: SessionByeOptions = {}) {
|
|
2707
2669
|
if (session.state !== SessionState.Established) {
|
|
2708
2670
|
logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: session.id });
|
|
2709
2671
|
return null;
|