@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.
Files changed (288) hide show
  1. package/README.md +2 -2
  2. package/dist/wazo-sdk.js +12 -12
  3. package/esm/__tests__/api-client.test.js +0 -10
  4. package/esm/__tests__/web-rtc-client.test.js +2 -15
  5. package/esm/api/amid.js +12 -4
  6. package/esm/api/chatd.js +0 -1
  7. package/esm/api/dird.js +7 -10
  8. package/esm/checker/checks/ice-ipv4.js +2 -3
  9. package/esm/checker/checks/symmetric-nat.js +7 -4
  10. package/esm/domain/AdHocAPIConference.js +1 -1
  11. package/esm/domain/CallLog.js +1 -1
  12. package/esm/domain/Contact.js +2 -1
  13. package/esm/domain/MeetingAuthorization.js +6 -0
  14. package/esm/domain/Phone/CTIPhone.js +2 -0
  15. package/esm/domain/Phone/WebRTCPhone.js +23 -18
  16. package/esm/domain/Session.js +2 -2
  17. package/esm/domain/__tests__/Agent.test.js +0 -2
  18. package/esm/domain/__tests__/Call.test.js +0 -1
  19. package/esm/domain/__tests__/CallLog.test.js +0 -1
  20. package/esm/domain/__tests__/CallSession.test.js +1 -2
  21. package/esm/domain/__tests__/Contact.test.js +2 -4
  22. package/esm/domain/__tests__/IndirectTransfer.test.js +0 -1
  23. package/esm/domain/__tests__/Profile.test.js +0 -1
  24. package/esm/domain/__tests__/Room.test.js +1 -25
  25. package/esm/domain/__tests__/Session.test.js +13 -14
  26. package/esm/domain/__tests__/SipLine.test.js +2 -3
  27. package/esm/index.js +42 -88
  28. package/esm/lib/WazoSessionDescriptionHandler.js +9 -15
  29. package/esm/service/IssueReporter.js +1 -3
  30. package/esm/service/__tests__/IssueReporter.test.js +0 -1
  31. package/esm/simple/Phone.js +1 -1
  32. package/esm/simple/Websocket.js +2 -2
  33. package/esm/simple/index.js +5 -4
  34. package/esm/simple/room/Room.js +15 -15
  35. package/esm/simple/room/SipRoom.js +1 -1
  36. package/esm/simple/room/Stream.js +1 -2
  37. package/esm/simple/room/__tests__/Participant.test.js +0 -2
  38. package/esm/simple/room/__tests__/RemoteParticipant.test.js +1 -2
  39. package/esm/types/api/amid.d.ts.map +1 -1
  40. package/esm/types/api/auth.d.ts +2 -2
  41. package/esm/types/api/auth.d.ts.map +1 -1
  42. package/esm/types/api/call-logd.d.ts +3 -3
  43. package/esm/types/api/call-logd.d.ts.map +1 -1
  44. package/esm/types/api/chatd.d.ts +9 -22
  45. package/esm/types/api/chatd.d.ts.map +1 -1
  46. package/esm/types/api/dird.d.ts +21 -14
  47. package/esm/types/api/dird.d.ts.map +1 -1
  48. package/esm/types/checker/checks/ice-ipv4.d.ts.map +1 -1
  49. package/esm/types/checker/checks/index.d.ts +1 -1
  50. package/esm/types/checker/checks/symmetric-nat.d.ts.map +1 -1
  51. package/esm/types/checker/checks/webrtc-transport.d.ts +2 -2
  52. package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -1
  53. package/esm/types/domain/Agent.d.ts +1 -1
  54. package/esm/types/domain/Agent.d.ts.map +1 -1
  55. package/esm/types/domain/CallLog.d.ts +14 -26
  56. package/esm/types/domain/CallLog.d.ts.map +1 -1
  57. package/esm/types/domain/CallSession.d.ts +3 -4
  58. package/esm/types/domain/CallSession.d.ts.map +1 -1
  59. package/esm/types/domain/Contact.d.ts +8 -0
  60. package/esm/types/domain/Contact.d.ts.map +1 -1
  61. package/esm/types/domain/MeetingAuthorization.d.ts +6 -0
  62. package/esm/types/domain/MeetingAuthorization.d.ts.map +1 -1
  63. package/esm/types/domain/Phone/CTIPhone.d.ts +2 -0
  64. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  65. package/esm/types/domain/Phone/Phone.d.ts +12 -2
  66. package/esm/types/domain/Phone/Phone.d.ts.map +1 -1
  67. package/esm/types/domain/Phone/WebRTCPhone.d.ts +24 -20
  68. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  69. package/esm/types/domain/Room.d.ts +10 -12
  70. package/esm/types/domain/Room.d.ts.map +1 -1
  71. package/esm/types/domain/Session.d.ts +1 -1
  72. package/esm/types/domain/Session.d.ts.map +1 -1
  73. package/esm/types/domain/SipLine.d.ts +3 -3
  74. package/esm/types/domain/SipLine.d.ts.map +1 -1
  75. package/esm/types/domain/types.d.ts +64 -10
  76. package/esm/types/domain/types.d.ts.map +1 -1
  77. package/esm/types/index.d.ts +51 -314
  78. package/esm/types/index.d.ts.map +1 -1
  79. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +5 -4
  80. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
  81. package/esm/types/service/CallApi.d.ts +3 -3
  82. package/esm/types/service/CallApi.d.ts.map +1 -1
  83. package/esm/types/service/IssueReporter.d.ts.map +1 -1
  84. package/esm/types/simple/Auth.d.ts +0 -40
  85. package/esm/types/simple/Auth.d.ts.map +1 -1
  86. package/esm/types/simple/Phone.d.ts +0 -113
  87. package/esm/types/simple/Phone.d.ts.map +1 -1
  88. package/esm/types/simple/Websocket.d.ts +0 -16
  89. package/esm/types/simple/Websocket.d.ts.map +1 -1
  90. package/esm/types/simple/index.d.ts +8 -8
  91. package/esm/types/simple/index.d.ts.map +1 -1
  92. package/esm/types/simple/room/Participant.d.ts +4 -3
  93. package/esm/types/simple/room/Participant.d.ts.map +1 -1
  94. package/esm/types/simple/room/Room.d.ts +29 -18
  95. package/esm/types/simple/room/Room.d.ts.map +1 -1
  96. package/esm/types/simple/room/SipRoom.d.ts +1 -1
  97. package/esm/types/simple/room/SipRoom.d.ts.map +1 -1
  98. package/esm/types/simple/room/Stream.d.ts +1 -1
  99. package/esm/types/simple/room/Stream.d.ts.map +1 -1
  100. package/esm/types/utils/PhoneNumberUtil.d.ts +1 -1
  101. package/esm/types/utils/PhoneNumberUtil.d.ts.map +1 -1
  102. package/esm/types/utils/api-requester.d.ts +1 -1
  103. package/esm/types/utils/api-requester.d.ts.map +1 -1
  104. package/esm/types/utils/sdp.d.ts +20 -5
  105. package/esm/types/utils/sdp.d.ts.map +1 -1
  106. package/esm/types/web-rtc-client.d.ts +51 -49
  107. package/esm/types/web-rtc-client.d.ts.map +1 -1
  108. package/esm/types/websocket-client.d.ts.map +1 -1
  109. package/esm/utils/__tests__/PhoneNumberUtil.test.js +0 -6
  110. package/esm/utils/__tests__/api-requester.test.js +0 -2
  111. package/esm/utils/__tests__/sdp.test.js +4 -18
  112. package/esm/utils/api-requester.js +1 -2
  113. package/esm/utils/sdp.js +8 -3
  114. package/esm/web-rtc-client.js +99 -136
  115. package/esm/websocket-client.js +1 -2
  116. package/index.js +1 -0
  117. package/lib/__tests__/api-client.test.js +0 -10
  118. package/lib/__tests__/web-rtc-client.test.js +2 -15
  119. package/lib/api/amid.js +12 -4
  120. package/lib/api/chatd.js +0 -1
  121. package/lib/api/dird.js +19 -22
  122. package/lib/checker/checks/ice-ipv4.js +2 -3
  123. package/lib/checker/checks/symmetric-nat.js +7 -4
  124. package/lib/domain/AdHocAPIConference.js +1 -1
  125. package/lib/domain/CallLog.js +1 -1
  126. package/lib/domain/Contact.js +2 -1
  127. package/lib/domain/MeetingAuthorization.js +6 -0
  128. package/lib/domain/Phone/CTIPhone.js +2 -0
  129. package/lib/domain/Phone/WebRTCPhone.js +23 -18
  130. package/lib/domain/Session.js +2 -2
  131. package/lib/domain/__tests__/Agent.test.js +0 -2
  132. package/lib/domain/__tests__/Call.test.js +0 -1
  133. package/lib/domain/__tests__/CallLog.test.js +0 -1
  134. package/lib/domain/__tests__/CallSession.test.js +1 -2
  135. package/lib/domain/__tests__/Contact.test.js +2 -4
  136. package/lib/domain/__tests__/IndirectTransfer.test.js +0 -1
  137. package/lib/domain/__tests__/Profile.test.js +0 -1
  138. package/lib/domain/__tests__/Room.test.js +1 -25
  139. package/lib/domain/__tests__/Session.test.js +13 -14
  140. package/lib/domain/__tests__/SipLine.test.js +2 -3
  141. package/lib/index.js +93 -99
  142. package/lib/lib/WazoSessionDescriptionHandler.js +9 -15
  143. package/lib/service/IssueReporter.js +1 -3
  144. package/lib/service/__tests__/IssueReporter.test.js +0 -1
  145. package/lib/simple/Phone.js +1 -1
  146. package/lib/simple/Websocket.js +2 -2
  147. package/lib/simple/index.js +2 -1
  148. package/lib/simple/room/Room.js +17 -15
  149. package/lib/simple/room/SipRoom.js +1 -1
  150. package/lib/simple/room/Stream.js +1 -2
  151. package/lib/simple/room/__tests__/Participant.test.js +0 -2
  152. package/lib/simple/room/__tests__/RemoteParticipant.test.js +1 -2
  153. package/lib/types/api/amid.d.ts.map +1 -1
  154. package/lib/types/api/auth.d.ts +2 -2
  155. package/lib/types/api/auth.d.ts.map +1 -1
  156. package/lib/types/api/call-logd.d.ts +3 -3
  157. package/lib/types/api/call-logd.d.ts.map +1 -1
  158. package/lib/types/api/chatd.d.ts +9 -22
  159. package/lib/types/api/chatd.d.ts.map +1 -1
  160. package/lib/types/api/dird.d.ts +21 -14
  161. package/lib/types/api/dird.d.ts.map +1 -1
  162. package/lib/types/checker/checks/ice-ipv4.d.ts.map +1 -1
  163. package/lib/types/checker/checks/index.d.ts +1 -1
  164. package/lib/types/checker/checks/symmetric-nat.d.ts.map +1 -1
  165. package/lib/types/checker/checks/webrtc-transport.d.ts +2 -2
  166. package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -1
  167. package/lib/types/domain/Agent.d.ts +1 -1
  168. package/lib/types/domain/Agent.d.ts.map +1 -1
  169. package/lib/types/domain/CallLog.d.ts +14 -26
  170. package/lib/types/domain/CallLog.d.ts.map +1 -1
  171. package/lib/types/domain/CallSession.d.ts +3 -4
  172. package/lib/types/domain/CallSession.d.ts.map +1 -1
  173. package/lib/types/domain/Contact.d.ts +8 -0
  174. package/lib/types/domain/Contact.d.ts.map +1 -1
  175. package/lib/types/domain/MeetingAuthorization.d.ts +6 -0
  176. package/lib/types/domain/MeetingAuthorization.d.ts.map +1 -1
  177. package/lib/types/domain/Phone/CTIPhone.d.ts +2 -0
  178. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  179. package/lib/types/domain/Phone/Phone.d.ts +12 -2
  180. package/lib/types/domain/Phone/Phone.d.ts.map +1 -1
  181. package/lib/types/domain/Phone/WebRTCPhone.d.ts +24 -20
  182. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  183. package/lib/types/domain/Room.d.ts +10 -12
  184. package/lib/types/domain/Room.d.ts.map +1 -1
  185. package/lib/types/domain/Session.d.ts +1 -1
  186. package/lib/types/domain/Session.d.ts.map +1 -1
  187. package/lib/types/domain/SipLine.d.ts +3 -3
  188. package/lib/types/domain/SipLine.d.ts.map +1 -1
  189. package/lib/types/domain/types.d.ts +64 -10
  190. package/lib/types/domain/types.d.ts.map +1 -1
  191. package/lib/types/index.d.ts +51 -314
  192. package/lib/types/index.d.ts.map +1 -1
  193. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +5 -4
  194. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
  195. package/lib/types/service/CallApi.d.ts +3 -3
  196. package/lib/types/service/CallApi.d.ts.map +1 -1
  197. package/lib/types/service/IssueReporter.d.ts.map +1 -1
  198. package/lib/types/simple/Auth.d.ts +0 -40
  199. package/lib/types/simple/Auth.d.ts.map +1 -1
  200. package/lib/types/simple/Phone.d.ts +0 -113
  201. package/lib/types/simple/Phone.d.ts.map +1 -1
  202. package/lib/types/simple/Websocket.d.ts +0 -16
  203. package/lib/types/simple/Websocket.d.ts.map +1 -1
  204. package/lib/types/simple/index.d.ts +8 -8
  205. package/lib/types/simple/index.d.ts.map +1 -1
  206. package/lib/types/simple/room/Participant.d.ts +4 -3
  207. package/lib/types/simple/room/Participant.d.ts.map +1 -1
  208. package/lib/types/simple/room/Room.d.ts +29 -18
  209. package/lib/types/simple/room/Room.d.ts.map +1 -1
  210. package/lib/types/simple/room/SipRoom.d.ts +1 -1
  211. package/lib/types/simple/room/SipRoom.d.ts.map +1 -1
  212. package/lib/types/simple/room/Stream.d.ts +1 -1
  213. package/lib/types/simple/room/Stream.d.ts.map +1 -1
  214. package/lib/types/utils/PhoneNumberUtil.d.ts +1 -1
  215. package/lib/types/utils/PhoneNumberUtil.d.ts.map +1 -1
  216. package/lib/types/utils/api-requester.d.ts +1 -1
  217. package/lib/types/utils/api-requester.d.ts.map +1 -1
  218. package/lib/types/utils/sdp.d.ts +20 -5
  219. package/lib/types/utils/sdp.d.ts.map +1 -1
  220. package/lib/types/web-rtc-client.d.ts +51 -49
  221. package/lib/types/web-rtc-client.d.ts.map +1 -1
  222. package/lib/types/websocket-client.d.ts.map +1 -1
  223. package/lib/utils/__tests__/PhoneNumberUtil.test.js +0 -6
  224. package/lib/utils/__tests__/api-requester.test.js +0 -2
  225. package/lib/utils/__tests__/sdp.test.js +6 -18
  226. package/lib/utils/api-requester.js +2 -3
  227. package/lib/utils/sdp.js +9 -3
  228. package/lib/web-rtc-client.js +105 -140
  229. package/lib/websocket-client.js +1 -2
  230. package/package.json +5 -18
  231. package/src/__tests__/api-client.test.ts +10 -19
  232. package/src/__tests__/web-rtc-client.test.ts +13 -25
  233. package/src/api/amid.ts +13 -4
  234. package/src/api/auth.ts +2 -5
  235. package/src/api/call-logd.ts +3 -3
  236. package/src/api/chatd.ts +10 -24
  237. package/src/api/dird.ts +33 -39
  238. package/src/checker/checks/ice-ipv4.ts +4 -5
  239. package/src/checker/checks/symmetric-nat.ts +11 -7
  240. package/src/checker/checks/webrtc-transport.ts +2 -2
  241. package/src/domain/AdHocAPIConference.ts +1 -1
  242. package/src/domain/Agent.ts +1 -1
  243. package/src/domain/CallLog.ts +19 -27
  244. package/src/domain/CallSession.ts +3 -4
  245. package/src/domain/Contact.ts +3 -1
  246. package/src/domain/MeetingAuthorization.ts +13 -0
  247. package/src/domain/Phone/CTIPhone.ts +4 -0
  248. package/src/domain/Phone/Phone.ts +11 -2
  249. package/src/domain/Phone/WebRTCPhone.ts +60 -52
  250. package/src/domain/Room.ts +12 -14
  251. package/src/domain/Session.ts +3 -3
  252. package/src/domain/SipLine.ts +3 -3
  253. package/src/domain/__tests__/Agent.test.ts +3 -5
  254. package/src/domain/__tests__/Call.test.ts +4 -5
  255. package/src/domain/__tests__/CallLog.test.ts +1 -3
  256. package/src/domain/__tests__/CallSession.test.ts +10 -11
  257. package/src/domain/__tests__/Contact.test.ts +2 -4
  258. package/src/domain/__tests__/IndirectTransfer.test.ts +6 -7
  259. package/src/domain/__tests__/Profile.test.ts +3 -4
  260. package/src/domain/__tests__/Room.test.ts +27 -51
  261. package/src/domain/__tests__/Session.test.ts +27 -28
  262. package/src/domain/__tests__/SipLine.test.ts +4 -5
  263. package/src/domain/types.ts +64 -11
  264. package/src/index.ts +51 -111
  265. package/src/lib/WazoSessionDescriptionHandler.ts +24 -30
  266. package/src/service/CallApi.ts +3 -3
  267. package/src/service/IssueReporter.ts +3 -5
  268. package/src/service/__tests__/IssueReporter.test.ts +1 -2
  269. package/src/simple/Auth.ts +1 -41
  270. package/src/simple/Phone.ts +9 -116
  271. package/src/simple/Websocket.ts +4 -20
  272. package/src/simple/index.ts +8 -7
  273. package/src/simple/room/Participant.ts +4 -3
  274. package/src/simple/room/Room.ts +44 -36
  275. package/src/simple/room/SipRoom.ts +4 -4
  276. package/src/simple/room/Stream.ts +2 -3
  277. package/src/simple/room/__tests__/Participant.test.ts +2 -4
  278. package/src/simple/room/__tests__/RemoteParticipant.test.ts +4 -3
  279. package/src/types/wazo.d.ts +1 -0
  280. package/src/utils/PhoneNumberUtil.ts +1 -1
  281. package/src/utils/__tests__/PhoneNumberUtil.test.ts +0 -6
  282. package/src/utils/__tests__/api-requester.test.ts +3 -4
  283. package/src/utils/__tests__/sdp.test.ts +16 -30
  284. package/src/utils/api-requester.ts +1 -4
  285. package/src/utils/sdp.ts +38 -17
  286. package/src/web-rtc-client.ts +196 -234
  287. package/src/websocket-client.ts +2 -3
  288. 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
- // @ts-ignore
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
- // @ts-expect-error
105
- expect(areCandidateValid([null])).toBeFalsy();
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
- // @ts-expect-error
121
- const fixedSdp = fixSdp(badMobileSdp, candidates);
116
+ const fixedSdp = fixSdp(badMobileSdp, candidates as Candidate[]);
122
117
  const parsed = sdpParser.parse(fixedSdp);
123
- // @ts-expect-error
124
- expect(parsed.media[0].candidates.length).toBe(1);
125
- expect(parsed.media[0].port).toBe(57021);
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
- // @ts-expect-error
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
- // @ts-expect-error
164
- expect(fixedAudioWithoutCandidate.media[0].candidates[0].type).toBe('host');
165
- // @ts-expect-error
166
- expect(fixedAudioWithoutCandidate.media[0].candidates[1].type).toBe('relay');
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
- // @ts-expect-error
182
- expect(fixedAudioWithCandidate.media[0].candidates[0].type).toBe('srflx');
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 const getCandidates = (rawSdp: string | null | undefined): Record<string, any>[] => {
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: any = sdpParser.parse(rawSdp);
24
+ const sdp = sdpParser.parse(rawSdp);
9
25
 
10
26
  if (!sdp || !sdp.media) {
11
27
  return [];
12
28
  }
13
29
 
14
- return sdp.media.map((media: any) => media.candidates).flat().filter((candidate: any) => !!candidate);
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): Record<string, any> | null => {
33
+ export const parseCandidate = (candidate?: string): Candidate | null => {
17
34
  if (!candidate) {
18
35
  return null;
19
36
  }
20
37
 
21
- const result: any = sdpParser.parse(candidate.indexOf('a=') === 0 ? candidate : `a=${candidate}`);
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: Record<string, any>[]): Record<string, any>[] => candidates.filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
43
+ const getSrflxOrRelay = (candidates: Candidate[]): Candidate[] => candidates.filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
26
44
 
27
- export const areCandidateValid = (candidates: Record<string, any>[]): boolean => getSrflxOrRelay(candidates).length > 0;
28
- export const isSdpValid = (sdp: string | null | undefined): boolean => {
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: any = sdpParser.parse(sdp);
34
- const bundleIndex = parsedSdp.groups.findIndex((group: any) => group.type === 'BUNDLE');
51
+ const parsedSdp = sdpParser.parse(sdp);
52
+ const bundleIndex = parsedSdp.groups?.findIndex((group) => group.type === 'BUNDLE');
35
53
 
36
54
  if (bundleIndex !== -1) {
37
- parsedSdp.groups[bundleIndex].mids = parsedSdp.media.map((media: any, index: any) => ('mid' in media ? media.mid : index)).join(' ');
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: any = sdpParser.parse(sdp);
44
- parsedSdp.media = parsedSdp.media.map((media: any) => ({ ...media,
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: Record<string, any>[], forcePort = true): string => {
80
- const parsedSdp: any = sdpParser.parse(sdp);
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: any) => {
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,