@wazo/sdk 0.39.14 → 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/amid.js +12 -4
- 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 +23 -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/amid.d.ts.map +1 -1
- 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/amid.js +12 -4
- 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 +23 -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/amid.d.ts.map +1 -1
- 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/amid.ts +13 -4
- 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 +60 -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
|
@@ -81,13 +81,12 @@ describe('Calling fetch', () => {
|
|
|
81
81
|
it('should call fetch without body but query string in get method', async () => {
|
|
82
82
|
jest.mock('node-fetch/src/index', () => {});
|
|
83
83
|
|
|
84
|
-
// @ts-ignore
|
|
85
84
|
global.fetch = jest.fn(() => Promise.resolve({
|
|
86
85
|
json: () => Promise.resolve({}),
|
|
87
86
|
headers: {
|
|
88
87
|
get: () => '',
|
|
89
88
|
},
|
|
90
|
-
}));
|
|
89
|
+
})) as any;
|
|
91
90
|
|
|
92
91
|
await new ApiRequester({
|
|
93
92
|
server,
|
|
@@ -111,7 +110,7 @@ describe('With a refresh token', () => {
|
|
|
111
110
|
it('should retry the call with a new token', async () => {
|
|
112
111
|
jest.mock('node-fetch/src/index', () => {});
|
|
113
112
|
let calls = 0;
|
|
114
|
-
|
|
113
|
+
|
|
115
114
|
global.fetch = jest.fn(() => {
|
|
116
115
|
calls++;
|
|
117
116
|
return Promise.resolve({
|
|
@@ -121,7 +120,7 @@ describe('With a refresh token', () => {
|
|
|
121
120
|
status: calls === 1 ? 401 : 200,
|
|
122
121
|
json: () => Promise.resolve({}),
|
|
123
122
|
});
|
|
124
|
-
});
|
|
123
|
+
}) as any;
|
|
125
124
|
const requester = new ApiRequester({
|
|
126
125
|
server,
|
|
127
126
|
agent: null,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
2
|
import sdpParser from 'sdp-transform';
|
|
3
|
-
import { getCandidates, isSdpValid, parseCandidate, areCandidateValid, fixSdp, fixBundle, toggleVideoDirection, hasAnActiveVideo, addIcesInAllBundles } from '../sdp';
|
|
3
|
+
import { getCandidates, isSdpValid, parseCandidate, areCandidateValid, fixSdp, fixBundle, toggleVideoDirection, hasAnActiveVideo, addIcesInAllBundles, Candidate } from '../sdp';
|
|
4
4
|
|
|
5
5
|
const goodSdp = `
|
|
6
6
|
c=IN IP4 203.0.113.1
|
|
@@ -85,26 +85,22 @@ describe('SDP utils', () => {
|
|
|
85
85
|
expect(candidates[1].type).toBe('relay');
|
|
86
86
|
expect(isSdpValid(goodSdp)).toBeTruthy();
|
|
87
87
|
expect(getCandidates(badMobileSdp).length).toBe(0);
|
|
88
|
-
expect(getCandidates(null).length).toBe(0);
|
|
88
|
+
expect(getCandidates(null as any).length).toBe(0);
|
|
89
89
|
expect(getCandidates('').length).toBe(0);
|
|
90
90
|
expect(getCandidates('nothing!').length).toBe(0);
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
describe('Parsing candidate', () => {
|
|
94
94
|
it('should parse a single candidate', () => {
|
|
95
|
-
const parsed = parseCandidate(candidate)
|
|
96
|
-
// @ts-expect-error
|
|
95
|
+
const parsed = parseCandidate(candidate) as Record<string, any>;
|
|
97
96
|
expect(parsed.type).toBe('relay');
|
|
98
|
-
// @ts-expect-error
|
|
99
97
|
expect(parsed.ip).toBe('14.72.2.1');
|
|
100
98
|
});
|
|
101
99
|
});
|
|
102
100
|
describe('Validating candidates', () => {
|
|
103
101
|
it('should parse a single candidate', () => {
|
|
104
|
-
|
|
105
|
-
expect(areCandidateValid([
|
|
106
|
-
// @ts-expect-error
|
|
107
|
-
expect(areCandidateValid([parseCandidate(candidate)])).toBeTruthy();
|
|
102
|
+
expect(areCandidateValid([])).toBeFalsy();
|
|
103
|
+
expect(areCandidateValid([parseCandidate(candidate) as any])).toBeTruthy();
|
|
108
104
|
});
|
|
109
105
|
});
|
|
110
106
|
describe('Validating sdp', () => {
|
|
@@ -117,14 +113,11 @@ describe('SDP utils', () => {
|
|
|
117
113
|
describe('Fixing sdp', () => {
|
|
118
114
|
it('should fix a SDP without candidate or IN ip', () => {
|
|
119
115
|
const candidates = [parseCandidate(candidate)];
|
|
120
|
-
|
|
121
|
-
const fixedSdp = fixSdp(badMobileSdp, candidates);
|
|
116
|
+
const fixedSdp = fixSdp(badMobileSdp, candidates as Candidate[]);
|
|
122
117
|
const parsed = sdpParser.parse(fixedSdp);
|
|
123
|
-
|
|
124
|
-
expect(parsed.media[0].
|
|
125
|
-
expect(parsed.
|
|
126
|
-
// @ts-expect-error
|
|
127
|
-
expect(parsed.origin.address).toBe('14.72.2.1');
|
|
118
|
+
expect((parsed.media[0] as any).candidates.length).toBe(1);
|
|
119
|
+
expect((parsed.media[0] as any).port).toBe(57021);
|
|
120
|
+
expect((parsed.origin as any).address).toBe('14.72.2.1');
|
|
128
121
|
expect(fixedSdp.indexOf('IN 0.0.0.0')).toBe(-1);
|
|
129
122
|
});
|
|
130
123
|
});
|
|
@@ -132,8 +125,7 @@ describe('SDP utils', () => {
|
|
|
132
125
|
it('should set a bundle for each m section', async () => {
|
|
133
126
|
const invalid = fixBundle(invalidBundle);
|
|
134
127
|
const parsed = sdpParser.parse(invalid);
|
|
135
|
-
|
|
136
|
-
expect(parsed.groups[0].mids).toBe('0 1');
|
|
128
|
+
expect((parsed.groups?.[0] as any).mids).toBe('0 1');
|
|
137
129
|
});
|
|
138
130
|
});
|
|
139
131
|
describe('Deactivate video', () => {
|
|
@@ -160,14 +152,10 @@ a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
|
|
|
160
152
|
a=candidate:3996450952 1 udp 41819903 14.72.21.2 65092 typ relay raddr 0.0.0.0 rport 0 generation 0 network-id 3 network-cost 10
|
|
161
153
|
`;
|
|
162
154
|
const fixedAudioWithoutCandidate = sdpParser.parse(addIcesInAllBundles(audioWithoutCandidate));
|
|
163
|
-
|
|
164
|
-
expect(fixedAudioWithoutCandidate.media[0].candidates[
|
|
165
|
-
|
|
166
|
-
expect(fixedAudioWithoutCandidate.media[
|
|
167
|
-
// @ts-expect-error
|
|
168
|
-
expect(fixedAudioWithoutCandidate.media[1].candidates[0].type).toBe('host');
|
|
169
|
-
// @ts-expect-error
|
|
170
|
-
expect(fixedAudioWithoutCandidate.media[1].candidates[1].type).toBe('relay');
|
|
155
|
+
expect((fixedAudioWithoutCandidate.media[0] as any).candidates[0].type).toBe('host');
|
|
156
|
+
expect((fixedAudioWithoutCandidate.media[0] as any).candidates[1].type).toBe('relay');
|
|
157
|
+
expect((fixedAudioWithoutCandidate.media[1] as any).candidates[0].type).toBe('host');
|
|
158
|
+
expect((fixedAudioWithoutCandidate.media[1] as any).candidates[1].type).toBe('relay');
|
|
171
159
|
// It should not add candidate if already present
|
|
172
160
|
const audioWithCandidate = `
|
|
173
161
|
c=IN IP4 203.0.113.1
|
|
@@ -178,10 +166,8 @@ m=video 54400 RTP/SAVPF 0 96
|
|
|
178
166
|
a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
|
|
179
167
|
`;
|
|
180
168
|
const fixedAudioWithCandidate = sdpParser.parse(addIcesInAllBundles(audioWithCandidate));
|
|
181
|
-
|
|
182
|
-
expect(fixedAudioWithCandidate.media[
|
|
183
|
-
// @ts-expect-error
|
|
184
|
-
expect(fixedAudioWithCandidate.media[1].candidates[0].type).toBe('host');
|
|
169
|
+
expect((fixedAudioWithCandidate.media?.[0] as any).candidates[0].type).toBe('srflx');
|
|
170
|
+
expect((fixedAudioWithCandidate.media?.[1] as any).candidates[0].type).toBe('host');
|
|
185
171
|
});
|
|
186
172
|
});
|
|
187
173
|
});
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/default-param-last */
|
|
2
1
|
/* global window */
|
|
3
|
-
|
|
4
2
|
/* eslint-disable global-require */
|
|
5
|
-
|
|
6
3
|
/* eslint-disable import/no-dynamic-require */
|
|
7
4
|
import { Base64 } from 'js-base64';
|
|
8
5
|
import { AbortController as NodeAbortController } from 'node-abort-controller';
|
|
@@ -265,7 +262,7 @@ export default class ApiRequester {
|
|
|
265
262
|
method: string,
|
|
266
263
|
body: Record<string, any> | null | undefined = null,
|
|
267
264
|
headers: (string | null | undefined) | (Record<string, any> | null | undefined) = null,
|
|
268
|
-
parse: ((...args: Array<any>) => any),
|
|
265
|
+
parse: ((...args: Array<any>) => any) | undefined = undefined,
|
|
269
266
|
) {
|
|
270
267
|
const isTokenNotFound = this._isTokenNotFound(err);
|
|
271
268
|
|
package/src/utils/sdp.ts
CHANGED
|
@@ -1,47 +1,67 @@
|
|
|
1
1
|
import sdpParser from 'sdp-transform';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type Candidate = {
|
|
4
|
+
foundation: string;
|
|
5
|
+
component: number;
|
|
6
|
+
transport: string;
|
|
7
|
+
priority: number | string;
|
|
8
|
+
ip: string;
|
|
9
|
+
port: number;
|
|
10
|
+
type: string;
|
|
11
|
+
raddr?: string | undefined;
|
|
12
|
+
rport?: number | undefined;
|
|
13
|
+
tcptype?: string | undefined;
|
|
14
|
+
generation?: number | undefined;
|
|
15
|
+
'network-id'?: number | undefined;
|
|
16
|
+
'network-cost'?: number | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const getCandidates = (rawSdp?: string): Candidate[] => {
|
|
4
20
|
if (!rawSdp) {
|
|
5
21
|
return [];
|
|
6
22
|
}
|
|
7
23
|
|
|
8
|
-
const sdp
|
|
24
|
+
const sdp = sdpParser.parse(rawSdp);
|
|
9
25
|
|
|
10
26
|
if (!sdp || !sdp.media) {
|
|
11
27
|
return [];
|
|
12
28
|
}
|
|
13
29
|
|
|
14
|
-
|
|
30
|
+
// @ts-ignore: Type 'undefined' is not assignable to type 'Candidate'
|
|
31
|
+
return sdp.media.map((media) => media.candidates).flat().filter((candidate) => !!candidate);
|
|
15
32
|
};
|
|
16
|
-
export const parseCandidate = (candidate?: string):
|
|
33
|
+
export const parseCandidate = (candidate?: string): Candidate | null => {
|
|
17
34
|
if (!candidate) {
|
|
18
35
|
return null;
|
|
19
36
|
}
|
|
20
37
|
|
|
21
|
-
const result
|
|
38
|
+
const result = sdpParser.parse(candidate.indexOf('a=') === 0 ? candidate : `a=${candidate}`);
|
|
39
|
+
// @ts-ignore: heads up -- Property 'candidates' does not exist on type 'SessionDescription'
|
|
22
40
|
return result.candidates ? result.candidates[0] : null;
|
|
23
41
|
};
|
|
24
42
|
|
|
25
|
-
const getSrflxOrRelay = (candidates:
|
|
43
|
+
const getSrflxOrRelay = (candidates: Candidate[]): Candidate[] => candidates.filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
|
|
26
44
|
|
|
27
|
-
export const areCandidateValid = (candidates:
|
|
28
|
-
export const isSdpValid = (sdp: string
|
|
45
|
+
export const areCandidateValid = (candidates: Candidate[]): boolean => (candidates ? getSrflxOrRelay(candidates).length > 0 : false);
|
|
46
|
+
export const isSdpValid = (sdp: string): boolean => {
|
|
29
47
|
const candidates = getCandidates(sdp);
|
|
30
48
|
return areCandidateValid(candidates);
|
|
31
49
|
};
|
|
32
50
|
export const fixBundle = (sdp: string): string => {
|
|
33
|
-
const parsedSdp
|
|
34
|
-
const bundleIndex = parsedSdp.groups
|
|
51
|
+
const parsedSdp = sdpParser.parse(sdp);
|
|
52
|
+
const bundleIndex = parsedSdp.groups?.findIndex((group) => group.type === 'BUNDLE');
|
|
35
53
|
|
|
36
54
|
if (bundleIndex !== -1) {
|
|
37
|
-
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
parsedSdp.groups[bundleIndex].mids = parsedSdp.media.map((media, index) => ('mid' in media ? media.mid : index)).join(' ');
|
|
38
57
|
}
|
|
39
58
|
|
|
40
59
|
return sdpParser.write(parsedSdp);
|
|
41
60
|
};
|
|
42
61
|
export const toggleVideoDirection = (sdp: string, direction: string | null | undefined): string => {
|
|
43
|
-
const parsedSdp
|
|
44
|
-
|
|
62
|
+
const parsedSdp = sdpParser.parse(sdp);
|
|
63
|
+
// @ts-ignore: heads up -- odd rewriting of sdp.media
|
|
64
|
+
parsedSdp.media = parsedSdp.media.map(media => ({ ...media,
|
|
45
65
|
...(media.type === 'video' ? {
|
|
46
66
|
direction,
|
|
47
67
|
} : {}),
|
|
@@ -76,16 +96,17 @@ export const hasAnActiveVideo = (sdp: string | null | undefined): boolean => {
|
|
|
76
96
|
const parsedSdp = sdpParser.parse(sdp);
|
|
77
97
|
return !!parsedSdp.media.find(media => media.type === 'video' && media.port > 10 && (!media.direction || media.direction !== 'inactive'));
|
|
78
98
|
};
|
|
79
|
-
export const fixSdp = (sdp: string, candidates:
|
|
80
|
-
const parsedSdp
|
|
81
|
-
const mainCandidate = getSrflxOrRelay(candidates)[0];
|
|
99
|
+
export const fixSdp = (sdp: string, candidates: Candidate[], forcePort = true): string => {
|
|
100
|
+
const parsedSdp = sdpParser.parse(sdp);
|
|
101
|
+
const mainCandidate = getSrflxOrRelay(candidates as Candidate[])[0];
|
|
82
102
|
const ip = mainCandidate ? mainCandidate.ip : null;
|
|
83
103
|
|
|
84
104
|
if (ip) {
|
|
105
|
+
// @ts-ignore
|
|
85
106
|
parsedSdp.origin.address = ip;
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
parsedSdp.media = parsedSdp.media.map((media
|
|
109
|
+
parsedSdp.media = parsedSdp.media.map((media) => {
|
|
89
110
|
const port = forcePort ? mainCandidate ? mainCandidate.port : media.port : media.port;
|
|
90
111
|
return { ...media,
|
|
91
112
|
port,
|