@wazo/sdk 0.38.22 → 0.39.0-beta.10

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 (883) hide show
  1. package/README.md +62 -293
  2. package/dist/wazo-sdk.js +9 -25
  3. package/esm/__tests__/api-client.test.js +183 -5059
  4. package/esm/__tests__/web-rtc-client.test.js +177 -7930
  5. package/esm/api/agentd.js +23 -832
  6. package/esm/api/amid.js +9 -411
  7. package/esm/api/application.js +60 -829
  8. package/esm/api/auth.js +164 -1213
  9. package/esm/api/call-logd.js +24 -733
  10. package/esm/api/calld.js +114 -1469
  11. package/esm/api/chatd.js +48 -1311
  12. package/esm/api/confd.js +67 -1580
  13. package/esm/api/ctid-ng.js +92 -1343
  14. package/esm/api/dird.js +100 -1590
  15. package/esm/api/webhookd.js +7 -513
  16. package/esm/api-client.js +143 -4880
  17. package/esm/checker/Checker.js +45 -8727
  18. package/esm/checker/checks/aor.js +24 -4924
  19. package/esm/checker/checks/api.js +70 -4968
  20. package/esm/checker/checks/ice-ipv4.js +63 -117
  21. package/esm/checker/checks/index.js +8 -8677
  22. package/esm/checker/checks/symmetric-nat.js +54 -102
  23. package/esm/checker/checks/wazo-websocket.js +34 -999
  24. package/esm/checker/checks/webrtc-transport.js +28 -7845
  25. package/esm/checker/checks/webrtc.js +31 -7852
  26. package/esm/domain/AdHocAPIConference.js +86 -5115
  27. package/esm/domain/Agent.js +27 -61
  28. package/esm/domain/BadResponse.js +20 -43
  29. package/esm/domain/Call.js +120 -210
  30. package/esm/domain/CallLog.js +123 -305
  31. package/esm/domain/CallSession.js +251 -423
  32. package/esm/domain/ChatMessage.js +52 -105
  33. package/esm/domain/ChatRoom.js +28 -60
  34. package/esm/domain/Contact.js +435 -741
  35. package/esm/domain/Country.js +17 -19
  36. package/esm/domain/Device/DebugDevice.js +31 -47
  37. package/esm/domain/Device/Device.js +1 -1
  38. package/esm/domain/DirectorySource.js +1 -1
  39. package/esm/domain/ExternalApp.js +23 -56
  40. package/esm/domain/Features.js +57 -5009
  41. package/esm/domain/ForwardOption.js +35 -70
  42. package/esm/domain/IndirectTransfer.js +38 -97
  43. package/esm/domain/Line.js +37 -88
  44. package/esm/domain/Meeting.js +58 -113
  45. package/esm/domain/MeetingAuthorization.js +38 -68
  46. package/esm/domain/MeetingStatus.js +13 -28
  47. package/esm/domain/NotificationOptions.js +43 -77
  48. package/esm/domain/Phone/CTIPhone.js +245 -5743
  49. package/esm/domain/Phone/Phone.js +1 -2
  50. package/esm/domain/Phone/WebRTCPhone.js +1457 -2671
  51. package/esm/domain/Profile.js +120 -405
  52. package/esm/domain/Recording.js +27 -51
  53. package/esm/domain/Relocation.js +16 -40
  54. package/esm/domain/Room.js +90 -133
  55. package/esm/domain/SFUNotAvailableError.js +5 -8
  56. package/esm/domain/ServerError.js +8 -61
  57. package/esm/domain/Session.js +125 -251
  58. package/esm/domain/SipLine.js +78 -155
  59. package/esm/domain/Subscription.js +39 -83
  60. package/esm/domain/SwitchboardCall.js +51 -143
  61. package/esm/domain/Voicemail.js +57 -122
  62. package/esm/domain/__tests__/Agent.test.js +31 -101
  63. package/esm/domain/__tests__/Call.test.js +24 -232
  64. package/esm/domain/__tests__/CallLog.test.js +60 -386
  65. package/esm/domain/__tests__/CallSession.test.js +74 -502
  66. package/esm/domain/__tests__/Contact.test.js +220 -902
  67. package/esm/domain/__tests__/IndirectTransfer.test.js +63 -546
  68. package/esm/domain/__tests__/Line.test.js +48 -156
  69. package/esm/domain/__tests__/Meeting.test.js +73 -226
  70. package/esm/domain/__tests__/MeetingAuthorization.test.js +45 -105
  71. package/esm/domain/__tests__/Profile.test.js +135 -496
  72. package/esm/domain/__tests__/Room.test.js +227 -719
  73. package/esm/domain/__tests__/Session.test.js +357 -1025
  74. package/esm/domain/__tests__/SipLine.test.js +24 -179
  75. package/esm/domain/__tests__/Voicemail.test.js +82 -200
  76. package/esm/domain/types.js +1 -1
  77. package/esm/index.js +63 -14985
  78. package/esm/lib/WazoSessionDescriptionHandler.js +406 -890
  79. package/esm/pubkey.js +10 -0
  80. package/esm/service/CallApi.js +42 -5014
  81. package/esm/service/IssueReporter.js +278 -360
  82. package/esm/service/__tests__/IssueReporter.test.js +92 -494
  83. package/esm/service/getApiClient.js +53 -4972
  84. package/esm/simple/Auth.js +212 -14747
  85. package/esm/simple/Configuration.js +8 -14796
  86. package/esm/simple/Directory.js +6 -4964
  87. package/esm/simple/Phone.js +309 -14727
  88. package/esm/simple/Websocket.js +68 -1112
  89. package/esm/simple/index.js +125 -14792
  90. package/esm/simple/room/LocalParticipant.js +1 -14797
  91. package/esm/simple/room/Participant.js +274 -14760
  92. package/esm/simple/room/RemoteParticipant.js +6 -14796
  93. package/esm/simple/room/Room.js +648 -14736
  94. package/esm/simple/room/SipRoom.js +111 -14790
  95. package/esm/simple/room/Stream.js +40 -14792
  96. package/esm/simple/room/__tests__/Participant.test.js +68 -14872
  97. package/esm/simple/room/__tests__/RemoteParticipant.test.js +10 -14805
  98. package/esm/simple/utils.js +9 -14799
  99. package/esm/types/WebSocketMessage.js +1 -1
  100. package/esm/types/__tests__/api-client.test.d.ts +2 -0
  101. package/esm/types/__tests__/api-client.test.d.ts.map +1 -0
  102. package/esm/types/__tests__/web-rtc-client.test.d.ts +2 -0
  103. package/esm/types/__tests__/web-rtc-client.test.d.ts.map +1 -0
  104. package/esm/types/api/agentd.d.ts +17 -0
  105. package/esm/types/api/agentd.d.ts.map +1 -0
  106. package/esm/types/api/amid.d.ts +8 -0
  107. package/esm/types/api/amid.d.ts.map +1 -0
  108. package/esm/types/api/application.d.ts +34 -0
  109. package/esm/types/api/application.d.ts.map +1 -0
  110. package/esm/types/api/auth.d.ts +64 -0
  111. package/esm/types/api/auth.d.ts.map +1 -0
  112. package/esm/types/api/call-logd.d.ts +12 -0
  113. package/esm/types/api/call-logd.d.ts.map +1 -0
  114. package/esm/types/api/calld.d.ts +51 -0
  115. package/esm/types/api/calld.d.ts.map +1 -0
  116. package/esm/types/api/chatd.d.ts +42 -0
  117. package/esm/types/api/chatd.d.ts.map +1 -0
  118. package/esm/types/api/confd.d.ts +39 -0
  119. package/esm/types/api/confd.d.ts.map +1 -0
  120. package/esm/types/api/ctid-ng.d.ts +36 -0
  121. package/esm/types/api/ctid-ng.d.ts.map +1 -0
  122. package/esm/types/api/dird.d.ts +38 -0
  123. package/esm/types/api/dird.d.ts.map +1 -0
  124. package/esm/types/api/webhookd.d.ts +24 -0
  125. package/esm/types/api/webhookd.d.ts.map +1 -0
  126. package/esm/types/api-client.d.ts +63 -0
  127. package/esm/types/api-client.d.ts.map +1 -0
  128. package/esm/types/checker/Checker.d.ts +13 -0
  129. package/esm/types/checker/Checker.d.ts.map +1 -0
  130. package/esm/types/checker/checks/aor.d.ts +6 -0
  131. package/esm/types/checker/checks/aor.d.ts.map +1 -0
  132. package/esm/types/checker/checks/api.d.ts +6 -0
  133. package/esm/types/checker/checks/api.d.ts.map +1 -0
  134. package/esm/types/checker/checks/ice-ipv4.d.ts +6 -0
  135. package/esm/types/checker/checks/ice-ipv4.d.ts.map +1 -0
  136. package/esm/types/checker/checks/index.d.ts +9 -0
  137. package/esm/types/checker/checks/index.d.ts.map +1 -0
  138. package/esm/types/checker/checks/symmetric-nat.d.ts +6 -0
  139. package/esm/types/checker/checks/symmetric-nat.d.ts.map +1 -0
  140. package/esm/types/checker/checks/wazo-websocket.d.ts +6 -0
  141. package/esm/types/checker/checks/wazo-websocket.d.ts.map +1 -0
  142. package/esm/types/checker/checks/webrtc-transport.d.ts +7 -0
  143. package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -0
  144. package/esm/types/checker/checks/webrtc.d.ts +6 -0
  145. package/esm/types/checker/checks/webrtc.d.ts.map +1 -0
  146. package/esm/types/domain/AdHocAPIConference.d.ts +54 -0
  147. package/esm/types/domain/AdHocAPIConference.d.ts.map +1 -0
  148. package/esm/types/domain/Agent.d.ts +31 -0
  149. package/esm/types/domain/Agent.d.ts.map +1 -0
  150. package/esm/types/domain/BadResponse.d.ts +11 -0
  151. package/esm/types/domain/BadResponse.d.ts.map +1 -0
  152. package/esm/types/domain/Call.d.ts +79 -0
  153. package/esm/types/domain/Call.d.ts.map +1 -0
  154. package/esm/types/domain/CallLog.d.ts +91 -0
  155. package/esm/types/domain/CallLog.d.ts.map +1 -0
  156. package/esm/types/domain/CallSession.d.ts +120 -0
  157. package/esm/types/domain/CallSession.d.ts.map +1 -0
  158. package/esm/types/domain/ChatMessage.d.ts +41 -0
  159. package/esm/types/domain/ChatMessage.d.ts.map +1 -0
  160. package/esm/types/domain/ChatRoom.d.ts +22 -0
  161. package/esm/types/domain/ChatRoom.d.ts.map +1 -0
  162. package/esm/types/domain/Contact.d.ts +316 -0
  163. package/esm/types/domain/Contact.d.ts.map +1 -0
  164. package/esm/types/domain/Country.d.ts +20 -0
  165. package/esm/types/domain/Country.d.ts.map +1 -0
  166. package/esm/types/domain/Device/DebugDevice.d.ts +14 -0
  167. package/esm/types/domain/Device/DebugDevice.d.ts.map +1 -0
  168. package/esm/types/domain/Device/Device.d.ts +13 -0
  169. package/esm/types/domain/Device/Device.d.ts.map +1 -0
  170. package/esm/types/domain/DirectorySource.d.ts +13 -0
  171. package/esm/types/domain/DirectorySource.d.ts.map +1 -0
  172. package/esm/types/domain/ExternalApp.d.ts +22 -0
  173. package/esm/types/domain/ExternalApp.d.ts.map +1 -0
  174. package/esm/types/domain/Features.d.ts +24 -0
  175. package/esm/types/domain/Features.d.ts.map +1 -0
  176. package/esm/types/domain/ForwardOption.d.ts +27 -0
  177. package/esm/types/domain/ForwardOption.d.ts.map +1 -0
  178. package/esm/types/domain/IndirectTransfer.d.ts +31 -0
  179. package/esm/types/domain/IndirectTransfer.d.ts.map +1 -0
  180. package/esm/types/domain/Line.d.ts +46 -0
  181. package/esm/types/domain/Line.d.ts.map +1 -0
  182. package/esm/types/domain/Meeting.d.ts +45 -0
  183. package/esm/types/domain/Meeting.d.ts.map +1 -0
  184. package/esm/types/domain/MeetingAuthorization.d.ts +26 -0
  185. package/esm/types/domain/MeetingAuthorization.d.ts.map +1 -0
  186. package/esm/types/domain/MeetingStatus.d.ts +10 -0
  187. package/esm/types/domain/MeetingStatus.d.ts.map +1 -0
  188. package/esm/types/domain/NotificationOptions.d.ts +22 -0
  189. package/esm/types/domain/NotificationOptions.d.ts.map +1 -0
  190. package/esm/types/domain/Phone/CTIPhone.d.ts +76 -0
  191. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -0
  192. package/esm/types/domain/Phone/Phone.d.ts +71 -0
  193. package/esm/types/domain/Phone/Phone.d.ts.map +1 -0
  194. package/esm/types/domain/Phone/WebRTCPhone.d.ts +179 -0
  195. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -0
  196. package/esm/types/domain/Profile.d.ts +151 -0
  197. package/esm/types/domain/Profile.d.ts.map +1 -0
  198. package/esm/types/domain/Recording.d.ts +26 -0
  199. package/esm/types/domain/Recording.d.ts.map +1 -0
  200. package/esm/types/domain/Relocation.d.ts +23 -0
  201. package/esm/types/domain/Relocation.d.ts.map +1 -0
  202. package/esm/types/domain/Room.d.ts +35 -0
  203. package/esm/types/domain/Room.d.ts.map +1 -0
  204. package/esm/types/domain/SFUNotAvailableError.d.ts +4 -0
  205. package/esm/types/domain/SFUNotAvailableError.d.ts.map +1 -0
  206. package/esm/types/domain/ServerError.d.ts +6 -0
  207. package/esm/types/domain/ServerError.d.ts.map +1 -0
  208. package/esm/types/domain/Session.d.ts +90 -0
  209. package/esm/types/domain/Session.d.ts.map +1 -0
  210. package/esm/types/domain/SipLine.d.ts +54 -0
  211. package/esm/types/domain/SipLine.d.ts.map +1 -0
  212. package/esm/types/domain/Subscription.d.ts +43 -0
  213. package/esm/types/domain/Subscription.d.ts.map +1 -0
  214. package/esm/types/domain/SwitchboardCall.d.ts +62 -0
  215. package/esm/types/domain/SwitchboardCall.d.ts.map +1 -0
  216. package/esm/types/domain/Voicemail.d.ts +50 -0
  217. package/esm/types/domain/Voicemail.d.ts.map +1 -0
  218. package/esm/types/domain/__tests__/Agent.test.d.ts +2 -0
  219. package/esm/types/domain/__tests__/Agent.test.d.ts.map +1 -0
  220. package/esm/types/domain/__tests__/Call.test.d.ts +2 -0
  221. package/esm/types/domain/__tests__/Call.test.d.ts.map +1 -0
  222. package/esm/types/domain/__tests__/CallLog.test.d.ts +2 -0
  223. package/esm/types/domain/__tests__/CallLog.test.d.ts.map +1 -0
  224. package/esm/types/domain/__tests__/CallSession.test.d.ts +2 -0
  225. package/esm/types/domain/__tests__/CallSession.test.d.ts.map +1 -0
  226. package/esm/types/domain/__tests__/Contact.test.d.ts +2 -0
  227. package/esm/types/domain/__tests__/Contact.test.d.ts.map +1 -0
  228. package/esm/types/domain/__tests__/IndirectTransfer.test.d.ts +2 -0
  229. package/esm/types/domain/__tests__/IndirectTransfer.test.d.ts.map +1 -0
  230. package/esm/types/domain/__tests__/Line.test.d.ts +2 -0
  231. package/esm/types/domain/__tests__/Line.test.d.ts.map +1 -0
  232. package/esm/types/domain/__tests__/Meeting.test.d.ts +2 -0
  233. package/esm/types/domain/__tests__/Meeting.test.d.ts.map +1 -0
  234. package/esm/types/domain/__tests__/MeetingAuthorization.test.d.ts +2 -0
  235. package/esm/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +1 -0
  236. package/esm/types/domain/__tests__/Profile.test.d.ts +2 -0
  237. package/esm/types/domain/__tests__/Profile.test.d.ts.map +1 -0
  238. package/esm/types/domain/__tests__/Room.test.d.ts +2 -0
  239. package/esm/types/domain/__tests__/Room.test.d.ts.map +1 -0
  240. package/esm/types/domain/__tests__/Session.test.d.ts +2 -0
  241. package/esm/types/domain/__tests__/Session.test.d.ts.map +1 -0
  242. package/esm/types/domain/__tests__/SipLine.test.d.ts +2 -0
  243. package/esm/types/domain/__tests__/SipLine.test.d.ts.map +1 -0
  244. package/esm/types/domain/__tests__/Voicemail.test.d.ts +2 -0
  245. package/esm/types/domain/__tests__/Voicemail.test.d.ts.map +1 -0
  246. package/esm/types/domain/types.d.ts +217 -0
  247. package/esm/types/domain/types.d.ts.map +1 -0
  248. package/esm/types/index.d.ts +304 -0
  249. package/esm/types/index.d.ts.map +1 -0
  250. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +30 -0
  251. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -0
  252. package/esm/types/pubkey.d.ts +3 -0
  253. package/esm/types/pubkey.d.ts.map +1 -0
  254. package/esm/types/service/CallApi.d.ts +28 -0
  255. package/esm/types/service/CallApi.d.ts.map +1 -0
  256. package/esm/types/service/IssueReporter.d.ts +40 -0
  257. package/esm/types/service/IssueReporter.d.ts.map +1 -0
  258. package/esm/types/service/__tests__/IssueReporter.test.d.ts +2 -0
  259. package/esm/types/service/__tests__/IssueReporter.test.d.ts.map +1 -0
  260. package/esm/types/service/getApiClient.d.ts +16 -0
  261. package/esm/types/service/getApiClient.d.ts.map +1 -0
  262. package/esm/types/simple/Auth.d.ts +51 -0
  263. package/esm/types/simple/Auth.d.ts.map +1 -0
  264. package/esm/types/simple/Configuration.d.ts +3 -0
  265. package/esm/types/simple/Configuration.d.ts.map +1 -0
  266. package/esm/types/simple/Directory.d.ts +3 -0
  267. package/esm/types/simple/Directory.d.ts.map +1 -0
  268. package/esm/types/simple/Phone.d.ts +115 -0
  269. package/esm/types/simple/Phone.d.ts.map +1 -0
  270. package/esm/types/simple/Websocket.d.ts +19 -0
  271. package/esm/types/simple/Websocket.d.ts.map +1 -0
  272. package/esm/types/simple/index.d.ts +147 -0
  273. package/esm/types/simple/index.d.ts.map +1 -0
  274. package/esm/types/simple/room/LocalParticipant.d.ts +5 -0
  275. package/esm/types/simple/room/LocalParticipant.d.ts.map +1 -0
  276. package/esm/types/simple/room/Participant.d.ts +76 -0
  277. package/esm/types/simple/room/Participant.d.ts.map +1 -0
  278. package/esm/types/simple/room/RemoteParticipant.d.ts +7 -0
  279. package/esm/types/simple/room/RemoteParticipant.d.ts.map +1 -0
  280. package/esm/types/simple/room/Room.d.ts +116 -0
  281. package/esm/types/simple/room/Room.d.ts.map +1 -0
  282. package/esm/types/simple/room/SipRoom.d.ts +14 -0
  283. package/esm/types/simple/room/SipRoom.d.ts.map +1 -0
  284. package/esm/types/simple/room/Stream.d.ts +13 -0
  285. package/esm/types/simple/room/Stream.d.ts.map +1 -0
  286. package/esm/types/simple/room/__tests__/Participant.test.d.ts +2 -0
  287. package/esm/types/simple/room/__tests__/Participant.test.d.ts.map +1 -0
  288. package/esm/types/simple/room/__tests__/RemoteParticipant.test.d.ts +2 -0
  289. package/esm/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +1 -0
  290. package/esm/types/simple/utils.d.ts +3 -0
  291. package/esm/types/simple/utils.d.ts.map +1 -0
  292. package/esm/types/types/WebSocketMessage.d.ts +285 -0
  293. package/esm/types/types/WebSocketMessage.d.ts.map +1 -0
  294. package/esm/types/utils/Emitter.d.ts +18 -0
  295. package/esm/types/utils/Emitter.d.ts.map +1 -0
  296. package/esm/types/utils/Heartbeat.d.ts +21 -0
  297. package/esm/types/utils/Heartbeat.d.ts.map +1 -0
  298. package/esm/types/utils/PhoneNumberUtil.d.ts +8 -0
  299. package/esm/types/utils/PhoneNumberUtil.d.ts.map +1 -0
  300. package/esm/types/utils/__tests__/Heartbeat.test.d.ts +2 -0
  301. package/esm/types/utils/__tests__/Heartbeat.test.d.ts.map +1 -0
  302. package/esm/types/utils/__tests__/PhoneNumberUtil.test.d.ts +2 -0
  303. package/esm/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +1 -0
  304. package/esm/types/utils/__tests__/api-requester.test.d.ts +2 -0
  305. package/esm/types/utils/__tests__/api-requester.test.d.ts.map +1 -0
  306. package/esm/types/utils/__tests__/array.test.d.ts +2 -0
  307. package/esm/types/utils/__tests__/array.test.d.ts.map +1 -0
  308. package/esm/types/utils/__tests__/compare-version.test.d.ts +2 -0
  309. package/esm/types/utils/__tests__/compare-version.test.d.ts.map +1 -0
  310. package/esm/types/utils/__tests__/object.test.d.ts +2 -0
  311. package/esm/types/utils/__tests__/object.test.d.ts.map +1 -0
  312. package/esm/types/utils/__tests__/sdp.test.d.ts +2 -0
  313. package/esm/types/utils/__tests__/sdp.test.d.ts.map +1 -0
  314. package/esm/types/utils/__tests__/string.test.d.ts +2 -0
  315. package/esm/types/utils/__tests__/string.test.d.ts.map +1 -0
  316. package/esm/types/utils/api-requester.d.ts +45 -0
  317. package/esm/types/utils/api-requester.d.ts.map +1 -0
  318. package/esm/types/utils/array.d.ts +2 -0
  319. package/esm/types/utils/array.d.ts.map +1 -0
  320. package/esm/types/utils/compare-version.d.ts +3 -0
  321. package/esm/types/utils/compare-version.d.ts.map +1 -0
  322. package/esm/types/utils/isMobile.d.ts +3 -0
  323. package/esm/types/utils/isMobile.d.ts.map +1 -0
  324. package/esm/types/utils/new-from.d.ts +3 -0
  325. package/esm/types/utils/new-from.d.ts.map +1 -0
  326. package/esm/types/utils/object.d.ts +2 -0
  327. package/esm/types/utils/object.d.ts.map +1 -0
  328. package/esm/types/utils/once.d.ts +2 -0
  329. package/esm/types/utils/once.d.ts.map +1 -0
  330. package/esm/types/utils/sdp.d.ts +13 -0
  331. package/esm/types/utils/sdp.d.ts.map +1 -0
  332. package/esm/types/utils/string.d.ts +2 -0
  333. package/esm/types/utils/string.d.ts.map +1 -0
  334. package/esm/types/utils/update-from.d.ts +3 -0
  335. package/esm/types/utils/update-from.d.ts.map +1 -0
  336. package/esm/types/utils/webrtc.d.ts +15 -0
  337. package/esm/types/utils/webrtc.d.ts.map +1 -0
  338. package/esm/types/web-rtc-client.d.ts +220 -0
  339. package/esm/types/web-rtc-client.d.ts.map +1 -0
  340. package/esm/types/websocket-client.d.ts +134 -0
  341. package/esm/types/websocket-client.d.ts.map +1 -0
  342. package/esm/utils/Emitter.js +17 -27
  343. package/esm/utils/Heartbeat.js +60 -83
  344. package/esm/utils/PhoneNumberUtil.js +48 -63
  345. package/esm/utils/__tests__/Heartbeat.test.js +59 -168
  346. package/esm/utils/__tests__/PhoneNumberUtil.test.js +55 -125
  347. package/esm/utils/__tests__/api-requester.test.js +127 -780
  348. package/esm/utils/__tests__/array.test.js +16 -19
  349. package/esm/utils/__tests__/compare-version.test.js +8 -26
  350. package/esm/utils/__tests__/object.test.js +73 -54
  351. package/esm/utils/__tests__/sdp.test.js +87 -216
  352. package/esm/utils/__tests__/string.test.js +21 -27
  353. package/esm/utils/api-requester.js +197 -675
  354. package/esm/utils/array.js +7 -11
  355. package/esm/utils/compare-version.js +12 -15
  356. package/esm/utils/isMobile.js +0 -2
  357. package/esm/utils/new-from.js +7 -12
  358. package/esm/utils/object.js +9 -23
  359. package/esm/utils/once.js +12 -13
  360. package/esm/utils/sdp.js +87 -131
  361. package/esm/utils/string.js +5 -9
  362. package/esm/utils/update-from.js +9 -16
  363. package/esm/utils/webrtc.js +35 -36
  364. package/esm/web-rtc-client.js +2038 -7677
  365. package/esm/websocket-client.js +352 -944
  366. package/lib/__tests__/api-client.test.js +199 -5067
  367. package/lib/__tests__/web-rtc-client.test.js +191 -7941
  368. package/lib/api/agentd.js +27 -837
  369. package/lib/api/amid.js +18 -415
  370. package/lib/api/application.js +64 -834
  371. package/lib/api/auth.js +166 -1222
  372. package/lib/api/call-logd.js +28 -738
  373. package/lib/api/calld.js +126 -1473
  374. package/lib/api/chatd.js +65 -1316
  375. package/lib/api/confd.js +79 -1584
  376. package/lib/api/ctid-ng.js +96 -1348
  377. package/lib/api/dird.js +105 -1596
  378. package/lib/api/webhookd.js +11 -518
  379. package/lib/api-client.js +139 -4884
  380. package/lib/checker/Checker.js +61 -8739
  381. package/lib/checker/checks/aor.js +37 -4929
  382. package/lib/checker/checks/api.js +81 -4971
  383. package/lib/checker/checks/ice-ipv4.js +66 -118
  384. package/lib/checker/checks/index.js +13 -8687
  385. package/lib/checker/checks/symmetric-nat.js +56 -104
  386. package/lib/checker/checks/wazo-websocket.js +58 -1006
  387. package/lib/checker/checks/webrtc-transport.js +41 -7853
  388. package/lib/checker/checks/webrtc.js +42 -7858
  389. package/lib/domain/AdHocAPIConference.js +80 -5116
  390. package/lib/domain/Agent.js +23 -64
  391. package/lib/domain/BadResponse.js +17 -44
  392. package/lib/domain/Call.js +108 -215
  393. package/lib/domain/CallLog.js +117 -311
  394. package/lib/domain/CallSession.js +221 -424
  395. package/lib/domain/ChatMessage.js +49 -110
  396. package/lib/domain/ChatRoom.js +28 -60
  397. package/lib/domain/Contact.js +409 -742
  398. package/lib/domain/Country.js +19 -21
  399. package/lib/domain/Device/DebugDevice.js +34 -49
  400. package/lib/domain/Device/Device.js +2 -2
  401. package/lib/domain/DirectorySource.js +2 -2
  402. package/lib/domain/ExternalApp.js +24 -56
  403. package/lib/domain/Features.js +68 -5018
  404. package/lib/domain/ForwardOption.js +36 -71
  405. package/lib/domain/IndirectTransfer.js +39 -98
  406. package/lib/domain/Line.js +35 -88
  407. package/lib/domain/Meeting.js +51 -118
  408. package/lib/domain/MeetingAuthorization.js +35 -75
  409. package/lib/domain/MeetingStatus.js +13 -29
  410. package/lib/domain/NotificationOptions.js +45 -77
  411. package/lib/domain/Phone/CTIPhone.js +283 -5755
  412. package/lib/domain/Phone/Phone.js +2 -5
  413. package/lib/domain/Phone/WebRTCPhone.js +1457 -2716
  414. package/lib/domain/Profile.js +127 -406
  415. package/lib/domain/Recording.js +28 -57
  416. package/lib/domain/Relocation.js +15 -43
  417. package/lib/domain/Room.js +73 -134
  418. package/lib/domain/SFUNotAvailableError.js +7 -9
  419. package/lib/domain/ServerError.js +14 -63
  420. package/lib/domain/Session.js +118 -251
  421. package/lib/domain/SipLine.js +70 -155
  422. package/lib/domain/Subscription.js +32 -86
  423. package/lib/domain/SwitchboardCall.js +45 -145
  424. package/lib/domain/Voicemail.js +56 -127
  425. package/lib/domain/__tests__/Agent.test.js +36 -103
  426. package/lib/domain/__tests__/Call.test.js +28 -237
  427. package/lib/domain/__tests__/CallLog.test.js +65 -392
  428. package/lib/domain/__tests__/CallSession.test.js +78 -503
  429. package/lib/domain/__tests__/Contact.test.js +224 -903
  430. package/lib/domain/__tests__/IndirectTransfer.test.js +75 -546
  431. package/lib/domain/__tests__/Line.test.js +52 -157
  432. package/lib/domain/__tests__/Meeting.test.js +78 -232
  433. package/lib/domain/__tests__/MeetingAuthorization.test.js +50 -107
  434. package/lib/domain/__tests__/Profile.test.js +161 -496
  435. package/lib/domain/__tests__/Room.test.js +239 -719
  436. package/lib/domain/__tests__/Session.test.js +350 -1024
  437. package/lib/domain/__tests__/SipLine.test.js +28 -180
  438. package/lib/domain/__tests__/Voicemail.test.js +86 -205
  439. package/lib/domain/types.js +2 -2
  440. package/lib/index.js +105 -15010
  441. package/lib/lib/WazoSessionDescriptionHandler.js +409 -898
  442. package/lib/pubkey.js +12 -0
  443. package/lib/service/CallApi.js +88 -5015
  444. package/lib/service/IssueReporter.js +264 -366
  445. package/lib/service/__tests__/IssueReporter.test.js +97 -500
  446. package/lib/service/getApiClient.js +70 -4990
  447. package/lib/simple/Auth.js +272 -14777
  448. package/lib/simple/Configuration.js +23 -14805
  449. package/lib/simple/Directory.js +18 -4966
  450. package/lib/simple/Phone.js +345 -14746
  451. package/lib/simple/Websocket.js +98 -1117
  452. package/lib/simple/index.js +151 -14800
  453. package/lib/simple/room/LocalParticipant.js +7 -14808
  454. package/lib/simple/room/Participant.js +269 -14778
  455. package/lib/simple/room/RemoteParticipant.js +11 -14806
  456. package/lib/simple/room/Room.js +655 -14761
  457. package/lib/simple/room/SipRoom.js +136 -14805
  458. package/lib/simple/room/Stream.js +43 -14802
  459. package/lib/simple/room/__tests__/Participant.test.js +79 -14879
  460. package/lib/simple/room/__tests__/RemoteParticipant.test.js +14 -14814
  461. package/lib/simple/utils.js +22 -14808
  462. package/lib/types/WebSocketMessage.js +2 -4
  463. package/lib/types/__tests__/api-client.test.d.ts +2 -0
  464. package/lib/types/__tests__/api-client.test.d.ts.map +1 -0
  465. package/lib/types/__tests__/web-rtc-client.test.d.ts +2 -0
  466. package/lib/types/__tests__/web-rtc-client.test.d.ts.map +1 -0
  467. package/lib/types/api/agentd.d.ts +17 -0
  468. package/lib/types/api/agentd.d.ts.map +1 -0
  469. package/lib/types/api/amid.d.ts +8 -0
  470. package/lib/types/api/amid.d.ts.map +1 -0
  471. package/lib/types/api/application.d.ts +34 -0
  472. package/lib/types/api/application.d.ts.map +1 -0
  473. package/lib/types/api/auth.d.ts +64 -0
  474. package/lib/types/api/auth.d.ts.map +1 -0
  475. package/lib/types/api/call-logd.d.ts +12 -0
  476. package/lib/types/api/call-logd.d.ts.map +1 -0
  477. package/lib/types/api/calld.d.ts +51 -0
  478. package/lib/types/api/calld.d.ts.map +1 -0
  479. package/lib/types/api/chatd.d.ts +42 -0
  480. package/lib/types/api/chatd.d.ts.map +1 -0
  481. package/lib/types/api/confd.d.ts +39 -0
  482. package/lib/types/api/confd.d.ts.map +1 -0
  483. package/lib/types/api/ctid-ng.d.ts +36 -0
  484. package/lib/types/api/ctid-ng.d.ts.map +1 -0
  485. package/lib/types/api/dird.d.ts +38 -0
  486. package/lib/types/api/dird.d.ts.map +1 -0
  487. package/lib/types/api/webhookd.d.ts +24 -0
  488. package/lib/types/api/webhookd.d.ts.map +1 -0
  489. package/lib/types/api-client.d.ts +63 -0
  490. package/lib/types/api-client.d.ts.map +1 -0
  491. package/lib/types/checker/Checker.d.ts +13 -0
  492. package/lib/types/checker/Checker.d.ts.map +1 -0
  493. package/lib/types/checker/checks/aor.d.ts +6 -0
  494. package/lib/types/checker/checks/aor.d.ts.map +1 -0
  495. package/lib/types/checker/checks/api.d.ts +6 -0
  496. package/lib/types/checker/checks/api.d.ts.map +1 -0
  497. package/lib/types/checker/checks/ice-ipv4.d.ts +6 -0
  498. package/lib/types/checker/checks/ice-ipv4.d.ts.map +1 -0
  499. package/lib/types/checker/checks/index.d.ts +9 -0
  500. package/lib/types/checker/checks/index.d.ts.map +1 -0
  501. package/lib/types/checker/checks/symmetric-nat.d.ts +6 -0
  502. package/lib/types/checker/checks/symmetric-nat.d.ts.map +1 -0
  503. package/lib/types/checker/checks/wazo-websocket.d.ts +6 -0
  504. package/lib/types/checker/checks/wazo-websocket.d.ts.map +1 -0
  505. package/lib/types/checker/checks/webrtc-transport.d.ts +7 -0
  506. package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -0
  507. package/lib/types/checker/checks/webrtc.d.ts +6 -0
  508. package/lib/types/checker/checks/webrtc.d.ts.map +1 -0
  509. package/lib/types/domain/AdHocAPIConference.d.ts +54 -0
  510. package/lib/types/domain/AdHocAPIConference.d.ts.map +1 -0
  511. package/lib/types/domain/Agent.d.ts +31 -0
  512. package/lib/types/domain/Agent.d.ts.map +1 -0
  513. package/lib/types/domain/BadResponse.d.ts +11 -0
  514. package/lib/types/domain/BadResponse.d.ts.map +1 -0
  515. package/lib/types/domain/Call.d.ts +79 -0
  516. package/lib/types/domain/Call.d.ts.map +1 -0
  517. package/lib/types/domain/CallLog.d.ts +91 -0
  518. package/lib/types/domain/CallLog.d.ts.map +1 -0
  519. package/lib/types/domain/CallSession.d.ts +120 -0
  520. package/lib/types/domain/CallSession.d.ts.map +1 -0
  521. package/lib/types/domain/ChatMessage.d.ts +41 -0
  522. package/lib/types/domain/ChatMessage.d.ts.map +1 -0
  523. package/lib/types/domain/ChatRoom.d.ts +22 -0
  524. package/lib/types/domain/ChatRoom.d.ts.map +1 -0
  525. package/lib/types/domain/Contact.d.ts +316 -0
  526. package/lib/types/domain/Contact.d.ts.map +1 -0
  527. package/lib/types/domain/Country.d.ts +20 -0
  528. package/lib/types/domain/Country.d.ts.map +1 -0
  529. package/lib/types/domain/Device/DebugDevice.d.ts +14 -0
  530. package/lib/types/domain/Device/DebugDevice.d.ts.map +1 -0
  531. package/lib/types/domain/Device/Device.d.ts +13 -0
  532. package/lib/types/domain/Device/Device.d.ts.map +1 -0
  533. package/lib/types/domain/DirectorySource.d.ts +13 -0
  534. package/lib/types/domain/DirectorySource.d.ts.map +1 -0
  535. package/lib/types/domain/ExternalApp.d.ts +22 -0
  536. package/lib/types/domain/ExternalApp.d.ts.map +1 -0
  537. package/lib/types/domain/Features.d.ts +24 -0
  538. package/lib/types/domain/Features.d.ts.map +1 -0
  539. package/lib/types/domain/ForwardOption.d.ts +27 -0
  540. package/lib/types/domain/ForwardOption.d.ts.map +1 -0
  541. package/lib/types/domain/IndirectTransfer.d.ts +31 -0
  542. package/lib/types/domain/IndirectTransfer.d.ts.map +1 -0
  543. package/lib/types/domain/Line.d.ts +46 -0
  544. package/lib/types/domain/Line.d.ts.map +1 -0
  545. package/lib/types/domain/Meeting.d.ts +45 -0
  546. package/lib/types/domain/Meeting.d.ts.map +1 -0
  547. package/lib/types/domain/MeetingAuthorization.d.ts +26 -0
  548. package/lib/types/domain/MeetingAuthorization.d.ts.map +1 -0
  549. package/lib/types/domain/MeetingStatus.d.ts +10 -0
  550. package/lib/types/domain/MeetingStatus.d.ts.map +1 -0
  551. package/lib/types/domain/NotificationOptions.d.ts +22 -0
  552. package/lib/types/domain/NotificationOptions.d.ts.map +1 -0
  553. package/lib/types/domain/Phone/CTIPhone.d.ts +76 -0
  554. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -0
  555. package/lib/types/domain/Phone/Phone.d.ts +71 -0
  556. package/lib/types/domain/Phone/Phone.d.ts.map +1 -0
  557. package/lib/types/domain/Phone/WebRTCPhone.d.ts +179 -0
  558. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -0
  559. package/lib/types/domain/Profile.d.ts +151 -0
  560. package/lib/types/domain/Profile.d.ts.map +1 -0
  561. package/lib/types/domain/Recording.d.ts +26 -0
  562. package/lib/types/domain/Recording.d.ts.map +1 -0
  563. package/lib/types/domain/Relocation.d.ts +23 -0
  564. package/lib/types/domain/Relocation.d.ts.map +1 -0
  565. package/lib/types/domain/Room.d.ts +35 -0
  566. package/lib/types/domain/Room.d.ts.map +1 -0
  567. package/lib/types/domain/SFUNotAvailableError.d.ts +4 -0
  568. package/lib/types/domain/SFUNotAvailableError.d.ts.map +1 -0
  569. package/lib/types/domain/ServerError.d.ts +6 -0
  570. package/lib/types/domain/ServerError.d.ts.map +1 -0
  571. package/lib/types/domain/Session.d.ts +90 -0
  572. package/lib/types/domain/Session.d.ts.map +1 -0
  573. package/lib/types/domain/SipLine.d.ts +54 -0
  574. package/lib/types/domain/SipLine.d.ts.map +1 -0
  575. package/lib/types/domain/Subscription.d.ts +43 -0
  576. package/lib/types/domain/Subscription.d.ts.map +1 -0
  577. package/lib/types/domain/SwitchboardCall.d.ts +62 -0
  578. package/lib/types/domain/SwitchboardCall.d.ts.map +1 -0
  579. package/lib/types/domain/Voicemail.d.ts +50 -0
  580. package/lib/types/domain/Voicemail.d.ts.map +1 -0
  581. package/lib/types/domain/__tests__/Agent.test.d.ts +2 -0
  582. package/lib/types/domain/__tests__/Agent.test.d.ts.map +1 -0
  583. package/lib/types/domain/__tests__/Call.test.d.ts +2 -0
  584. package/lib/types/domain/__tests__/Call.test.d.ts.map +1 -0
  585. package/lib/types/domain/__tests__/CallLog.test.d.ts +2 -0
  586. package/lib/types/domain/__tests__/CallLog.test.d.ts.map +1 -0
  587. package/lib/types/domain/__tests__/CallSession.test.d.ts +2 -0
  588. package/lib/types/domain/__tests__/CallSession.test.d.ts.map +1 -0
  589. package/lib/types/domain/__tests__/Contact.test.d.ts +2 -0
  590. package/lib/types/domain/__tests__/Contact.test.d.ts.map +1 -0
  591. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts +2 -0
  592. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts.map +1 -0
  593. package/lib/types/domain/__tests__/Line.test.d.ts +2 -0
  594. package/lib/types/domain/__tests__/Line.test.d.ts.map +1 -0
  595. package/lib/types/domain/__tests__/Meeting.test.d.ts +2 -0
  596. package/lib/types/domain/__tests__/Meeting.test.d.ts.map +1 -0
  597. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts +2 -0
  598. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +1 -0
  599. package/lib/types/domain/__tests__/Profile.test.d.ts +2 -0
  600. package/lib/types/domain/__tests__/Profile.test.d.ts.map +1 -0
  601. package/lib/types/domain/__tests__/Room.test.d.ts +2 -0
  602. package/lib/types/domain/__tests__/Room.test.d.ts.map +1 -0
  603. package/lib/types/domain/__tests__/Session.test.d.ts +2 -0
  604. package/lib/types/domain/__tests__/Session.test.d.ts.map +1 -0
  605. package/lib/types/domain/__tests__/SipLine.test.d.ts +2 -0
  606. package/lib/types/domain/__tests__/SipLine.test.d.ts.map +1 -0
  607. package/lib/types/domain/__tests__/Voicemail.test.d.ts +2 -0
  608. package/lib/types/domain/__tests__/Voicemail.test.d.ts.map +1 -0
  609. package/lib/types/domain/types.d.ts +217 -0
  610. package/lib/types/domain/types.d.ts.map +1 -0
  611. package/lib/types/index.d.ts +304 -0
  612. package/lib/types/index.d.ts.map +1 -0
  613. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +30 -0
  614. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -0
  615. package/lib/types/pubkey.d.ts +3 -0
  616. package/lib/types/pubkey.d.ts.map +1 -0
  617. package/lib/types/service/CallApi.d.ts +28 -0
  618. package/lib/types/service/CallApi.d.ts.map +1 -0
  619. package/lib/types/service/IssueReporter.d.ts +40 -0
  620. package/lib/types/service/IssueReporter.d.ts.map +1 -0
  621. package/lib/types/service/__tests__/IssueReporter.test.d.ts +2 -0
  622. package/lib/types/service/__tests__/IssueReporter.test.d.ts.map +1 -0
  623. package/lib/types/service/getApiClient.d.ts +16 -0
  624. package/lib/types/service/getApiClient.d.ts.map +1 -0
  625. package/lib/types/simple/Auth.d.ts +51 -0
  626. package/lib/types/simple/Auth.d.ts.map +1 -0
  627. package/lib/types/simple/Configuration.d.ts +3 -0
  628. package/lib/types/simple/Configuration.d.ts.map +1 -0
  629. package/lib/types/simple/Directory.d.ts +3 -0
  630. package/lib/types/simple/Directory.d.ts.map +1 -0
  631. package/lib/types/simple/Phone.d.ts +115 -0
  632. package/lib/types/simple/Phone.d.ts.map +1 -0
  633. package/lib/types/simple/Websocket.d.ts +19 -0
  634. package/lib/types/simple/Websocket.d.ts.map +1 -0
  635. package/lib/types/simple/index.d.ts +147 -0
  636. package/lib/types/simple/index.d.ts.map +1 -0
  637. package/lib/types/simple/room/LocalParticipant.d.ts +5 -0
  638. package/lib/types/simple/room/LocalParticipant.d.ts.map +1 -0
  639. package/lib/types/simple/room/Participant.d.ts +76 -0
  640. package/lib/types/simple/room/Participant.d.ts.map +1 -0
  641. package/lib/types/simple/room/RemoteParticipant.d.ts +7 -0
  642. package/lib/types/simple/room/RemoteParticipant.d.ts.map +1 -0
  643. package/lib/types/simple/room/Room.d.ts +116 -0
  644. package/lib/types/simple/room/Room.d.ts.map +1 -0
  645. package/lib/types/simple/room/SipRoom.d.ts +14 -0
  646. package/lib/types/simple/room/SipRoom.d.ts.map +1 -0
  647. package/lib/types/simple/room/Stream.d.ts +13 -0
  648. package/lib/types/simple/room/Stream.d.ts.map +1 -0
  649. package/lib/types/simple/room/__tests__/Participant.test.d.ts +2 -0
  650. package/lib/types/simple/room/__tests__/Participant.test.d.ts.map +1 -0
  651. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts +2 -0
  652. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +1 -0
  653. package/lib/types/simple/utils.d.ts +3 -0
  654. package/lib/types/simple/utils.d.ts.map +1 -0
  655. package/lib/types/types/WebSocketMessage.d.ts +285 -0
  656. package/lib/types/types/WebSocketMessage.d.ts.map +1 -0
  657. package/lib/types/utils/Emitter.d.ts +18 -0
  658. package/lib/types/utils/Emitter.d.ts.map +1 -0
  659. package/lib/types/utils/Heartbeat.d.ts +21 -0
  660. package/lib/types/utils/Heartbeat.d.ts.map +1 -0
  661. package/lib/types/utils/PhoneNumberUtil.d.ts +8 -0
  662. package/lib/types/utils/PhoneNumberUtil.d.ts.map +1 -0
  663. package/lib/types/utils/__tests__/Heartbeat.test.d.ts +2 -0
  664. package/lib/types/utils/__tests__/Heartbeat.test.d.ts.map +1 -0
  665. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts +2 -0
  666. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +1 -0
  667. package/lib/types/utils/__tests__/api-requester.test.d.ts +2 -0
  668. package/lib/types/utils/__tests__/api-requester.test.d.ts.map +1 -0
  669. package/lib/types/utils/__tests__/array.test.d.ts +2 -0
  670. package/lib/types/utils/__tests__/array.test.d.ts.map +1 -0
  671. package/lib/types/utils/__tests__/compare-version.test.d.ts +2 -0
  672. package/lib/types/utils/__tests__/compare-version.test.d.ts.map +1 -0
  673. package/lib/types/utils/__tests__/object.test.d.ts +2 -0
  674. package/lib/types/utils/__tests__/object.test.d.ts.map +1 -0
  675. package/lib/types/utils/__tests__/sdp.test.d.ts +2 -0
  676. package/lib/types/utils/__tests__/sdp.test.d.ts.map +1 -0
  677. package/lib/types/utils/__tests__/string.test.d.ts +2 -0
  678. package/lib/types/utils/__tests__/string.test.d.ts.map +1 -0
  679. package/lib/types/utils/api-requester.d.ts +45 -0
  680. package/lib/types/utils/api-requester.d.ts.map +1 -0
  681. package/lib/types/utils/array.d.ts +2 -0
  682. package/lib/types/utils/array.d.ts.map +1 -0
  683. package/lib/types/utils/compare-version.d.ts +3 -0
  684. package/lib/types/utils/compare-version.d.ts.map +1 -0
  685. package/lib/types/utils/isMobile.d.ts +3 -0
  686. package/lib/types/utils/isMobile.d.ts.map +1 -0
  687. package/lib/types/utils/new-from.d.ts +3 -0
  688. package/lib/types/utils/new-from.d.ts.map +1 -0
  689. package/lib/types/utils/object.d.ts +2 -0
  690. package/lib/types/utils/object.d.ts.map +1 -0
  691. package/lib/types/utils/once.d.ts +2 -0
  692. package/lib/types/utils/once.d.ts.map +1 -0
  693. package/lib/types/utils/sdp.d.ts +13 -0
  694. package/lib/types/utils/sdp.d.ts.map +1 -0
  695. package/lib/types/utils/string.d.ts +2 -0
  696. package/lib/types/utils/string.d.ts.map +1 -0
  697. package/lib/types/utils/update-from.d.ts +3 -0
  698. package/lib/types/utils/update-from.d.ts.map +1 -0
  699. package/lib/types/utils/webrtc.d.ts +15 -0
  700. package/lib/types/utils/webrtc.d.ts.map +1 -0
  701. package/lib/types/web-rtc-client.d.ts +220 -0
  702. package/lib/types/web-rtc-client.d.ts.map +1 -0
  703. package/lib/types/websocket-client.d.ts +134 -0
  704. package/lib/types/websocket-client.d.ts.map +1 -0
  705. package/lib/utils/Emitter.js +22 -33
  706. package/lib/utils/Heartbeat.js +54 -86
  707. package/lib/utils/PhoneNumberUtil.js +60 -77
  708. package/lib/utils/__tests__/Heartbeat.test.js +73 -170
  709. package/lib/utils/__tests__/PhoneNumberUtil.test.js +57 -131
  710. package/lib/utils/__tests__/api-requester.test.js +139 -784
  711. package/lib/utils/__tests__/array.test.js +18 -21
  712. package/lib/utils/__tests__/compare-version.test.js +12 -27
  713. package/lib/utils/__tests__/object.test.js +75 -56
  714. package/lib/utils/__tests__/sdp.test.js +99 -220
  715. package/lib/utils/__tests__/string.test.js +23 -29
  716. package/lib/utils/api-requester.js +191 -685
  717. package/lib/utils/array.js +10 -14
  718. package/lib/utils/compare-version.js +15 -18
  719. package/lib/utils/isMobile.js +3 -5
  720. package/lib/utils/new-from.js +9 -14
  721. package/lib/utils/object.js +12 -26
  722. package/lib/utils/once.js +15 -15
  723. package/lib/utils/sdp.js +97 -150
  724. package/lib/utils/string.js +8 -12
  725. package/lib/utils/update-from.js +11 -18
  726. package/lib/utils/webrtc.js +38 -39
  727. package/lib/web-rtc-client.js +2070 -7694
  728. package/lib/websocket-client.js +357 -1021
  729. package/package.json +41 -34
  730. package/src/__tests__/{api-client.test.js → api-client.test.ts} +71 -29
  731. package/src/__tests__/{web-rtc-client.test.js → web-rtc-client.test.ts} +95 -35
  732. package/src/api/agentd.ts +37 -0
  733. package/src/api/amid.ts +16 -0
  734. package/src/api/application.ts +96 -0
  735. package/src/api/auth.ts +259 -0
  736. package/src/api/call-logd.ts +38 -0
  737. package/src/api/calld.ts +183 -0
  738. package/src/api/chatd.ts +101 -0
  739. package/src/api/confd.ts +110 -0
  740. package/src/api/ctid-ng.ts +152 -0
  741. package/src/api/dird.ts +146 -0
  742. package/src/api/webhookd.ts +30 -0
  743. package/src/{api-client.js → api-client.ts} +103 -67
  744. package/src/checker/{Checker.js → Checker.ts} +27 -20
  745. package/src/checker/checks/{aor.js → aor.ts} +10 -6
  746. package/src/checker/checks/{api.js → api.ts} +18 -17
  747. package/src/checker/checks/{ice-ipv4.js → ice-ipv4.ts} +23 -26
  748. package/src/checker/checks/{index.js → index.ts} +1 -9
  749. package/src/checker/checks/{symmetric-nat.js → symmetric-nat.ts} +14 -15
  750. package/src/checker/checks/{wazo-websocket.js → wazo-websocket.ts} +7 -5
  751. package/src/checker/checks/{webrtc-transport.js → webrtc-transport.ts} +3 -2
  752. package/src/checker/checks/{webrtc.js → webrtc.ts} +3 -4
  753. package/src/domain/{AdHocAPIConference.js → AdHocAPIConference.ts} +38 -54
  754. package/src/domain/{Agent.js → Agent.ts} +11 -7
  755. package/src/domain/BadResponse.ts +29 -0
  756. package/src/domain/{Call.js → Call.ts} +62 -46
  757. package/src/domain/{CallLog.js → CallLog.ts} +61 -63
  758. package/src/domain/{CallSession.js → CallSession.ts} +55 -52
  759. package/src/domain/{ChatMessage.js → ChatMessage.ts} +32 -21
  760. package/src/domain/{ChatRoom.js → ChatRoom.ts} +15 -11
  761. package/src/domain/{Contact.js → Contact.ts} +380 -262
  762. package/src/domain/Device/{DebugDevice.js → DebugDevice.ts} +3 -5
  763. package/src/domain/Device/{Device.js → Device.ts} +0 -11
  764. package/src/domain/DirectorySource.ts +13 -0
  765. package/src/domain/{ExternalApp.js → ExternalApp.ts} +14 -13
  766. package/src/domain/{Features.js → Features.ts} +43 -17
  767. package/src/domain/{ForwardOption.js → ForwardOption.ts} +16 -16
  768. package/src/domain/{IndirectTransfer.js → IndirectTransfer.ts} +21 -19
  769. package/src/domain/{Line.js → Line.ts} +39 -26
  770. package/src/domain/{Meeting.js → Meeting.ts} +36 -29
  771. package/src/domain/{MeetingAuthorization.js → MeetingAuthorization.ts} +13 -12
  772. package/src/domain/{MeetingStatus.js → MeetingStatus.ts} +2 -6
  773. package/src/domain/{NotificationOptions.js → NotificationOptions.ts} +14 -13
  774. package/src/domain/Phone/{CTIPhone.js → CTIPhone.ts} +90 -60
  775. package/src/domain/Phone/{Phone.js → Phone.ts} +27 -72
  776. package/src/domain/Phone/{WebRTCPhone.js → WebRTCPhone.ts} +456 -422
  777. package/src/domain/{Profile.js → Profile.ts} +117 -100
  778. package/src/domain/{Recording.js → Recording.ts} +25 -16
  779. package/src/domain/{Relocation.js → Relocation.ts} +15 -14
  780. package/src/domain/{Room.js → Room.ts} +58 -27
  781. package/src/domain/{SFUNotAvailableError.js → SFUNotAvailableError.ts} +2 -2
  782. package/src/domain/ServerError.ts +12 -0
  783. package/src/domain/{Session.js → Session.ts} +89 -67
  784. package/src/domain/{SipLine.js → SipLine.ts} +52 -45
  785. package/src/domain/{Subscription.js → Subscription.ts} +22 -13
  786. package/src/domain/{SwitchboardCall.js → SwitchboardCall.ts} +48 -43
  787. package/src/domain/{Voicemail.js → Voicemail.ts} +38 -34
  788. package/src/domain/__tests__/{Agent.test.js → Agent.test.ts} +11 -19
  789. package/src/domain/__tests__/{Call.test.js → Call.test.ts} +12 -9
  790. package/src/domain/__tests__/CallLog.test.ts +65 -0
  791. package/src/domain/__tests__/{CallSession.test.js → CallSession.test.ts} +15 -19
  792. package/src/domain/__tests__/Contact.test.ts +238 -0
  793. package/src/domain/__tests__/{IndirectTransfer.test.js → IndirectTransfer.test.ts} +38 -31
  794. package/src/domain/__tests__/Line.test.ts +53 -0
  795. package/src/domain/__tests__/{Meeting.test.js → Meeting.test.ts} +12 -38
  796. package/src/domain/__tests__/{MeetingAuthorization.test.js → MeetingAuthorization.test.ts} +13 -21
  797. package/src/domain/__tests__/Profile.test.ts +139 -0
  798. package/src/domain/__tests__/{Room.test.js → Room.test.ts} +114 -76
  799. package/src/domain/__tests__/{Session.test.js → Session.test.ts} +137 -162
  800. package/src/domain/__tests__/{SipLine.test.js → SipLine.test.ts} +7 -3
  801. package/src/domain/__tests__/{Voicemail.test.js → Voicemail.test.ts} +26 -20
  802. package/src/domain/types.ts +227 -0
  803. package/src/{index.js → index.ts} +4 -28
  804. package/src/lib/WazoSessionDescriptionHandler.ts +534 -0
  805. package/{config.js → src/pubkey.ts} +3 -3
  806. package/src/service/{CallApi.js → CallApi.ts} +14 -18
  807. package/src/service/{IssueReporter.js → IssueReporter.ts} +105 -56
  808. package/src/service/__tests__/{IssueReporter.test.js → IssueReporter.test.ts} +27 -23
  809. package/src/service/getApiClient.ts +94 -0
  810. package/src/simple/{Auth.js → Auth.ts} +130 -101
  811. package/src/simple/{Configuration.js → Configuration.ts} +2 -3
  812. package/src/simple/{Directory.js → Directory.ts} +2 -3
  813. package/src/simple/Phone.ts +623 -0
  814. package/src/simple/Websocket.ts +119 -0
  815. package/src/simple/{index.js → index.ts} +51 -21
  816. package/src/simple/room/{LocalParticipant.js → LocalParticipant.ts} +1 -3
  817. package/src/simple/room/{Participant.js → Participant.ts} +108 -46
  818. package/src/simple/room/{RemoteParticipant.js → RemoteParticipant.ts} +5 -4
  819. package/src/simple/room/{Room.js → Room.ts} +266 -183
  820. package/src/simple/room/{SipRoom.js → SipRoom.ts} +46 -29
  821. package/src/simple/room/{Stream.js → Stream.ts} +8 -6
  822. package/src/simple/room/__tests__/{Participant.test.js → Participant.test.ts} +9 -15
  823. package/src/simple/room/__tests__/{RemoteParticipant.test.js → RemoteParticipant.test.ts} +5 -1
  824. package/src/simple/utils.ts +12 -0
  825. package/src/types/WebSocketMessage.ts +335 -0
  826. package/src/types/global.d.ts +26 -0
  827. package/src/utils/Emitter.ts +34 -0
  828. package/src/utils/{Heartbeat.js → Heartbeat.ts} +17 -11
  829. package/src/utils/{PhoneNumberUtil.js → PhoneNumberUtil.ts} +12 -18
  830. package/src/utils/__tests__/{Heartbeat.test.js → Heartbeat.test.ts} +0 -15
  831. package/src/utils/__tests__/{PhoneNumberUtil.test.js → PhoneNumberUtil.test.ts} +6 -4
  832. package/src/utils/__tests__/{api-requester.test.js → api-requester.test.ts} +75 -24
  833. package/src/utils/__tests__/{array.test.js → array.test.ts} +10 -2
  834. package/src/utils/__tests__/object.test.ts +77 -0
  835. package/src/utils/__tests__/{sdp.test.js → sdp.test.ts} +15 -37
  836. package/src/utils/__tests__/{string.test.js → string.test.ts} +4 -2
  837. package/src/utils/{api-requester.js → api-requester.ts} +104 -83
  838. package/src/utils/{array.js → array.ts} +2 -2
  839. package/src/utils/{compare-version.js → compare-version.ts} +3 -2
  840. package/src/utils/{isMobile.js → isMobile.ts} +1 -1
  841. package/src/utils/{new-from.js → new-from.ts} +3 -6
  842. package/src/utils/{object.js → object.ts} +3 -6
  843. package/src/utils/{once.js → once.ts} +5 -5
  844. package/src/utils/sdp.ts +119 -0
  845. package/src/utils/{string.js → string.ts} +2 -3
  846. package/src/utils/update-from.ts +11 -0
  847. package/src/utils/{webrtc.js → webrtc.ts} +21 -3
  848. package/src/{web-rtc-client.js → web-rtc-client.ts} +879 -476
  849. package/src/{websocket-client.js → websocket-client.ts} +146 -144
  850. package/esm/simple/Softphone.js +0 -394
  851. package/lib/simple/Softphone.js +0 -396
  852. package/src/api/agentd.js +0 -74
  853. package/src/api/amid.js +0 -13
  854. package/src/api/application.js +0 -137
  855. package/src/api/auth.js +0 -279
  856. package/src/api/call-logd.js +0 -20
  857. package/src/api/calld.js +0 -214
  858. package/src/api/chatd.js +0 -80
  859. package/src/api/confd.js +0 -127
  860. package/src/api/ctid-ng.js +0 -153
  861. package/src/api/dird.js +0 -159
  862. package/src/api/webhookd.js +0 -31
  863. package/src/domain/BadResponse.js +0 -42
  864. package/src/domain/DirectorySource.js +0 -16
  865. package/src/domain/ServerError.js +0 -18
  866. package/src/domain/__tests__/CallLog.test.js +0 -75
  867. package/src/domain/__tests__/Contact.test.js +0 -170
  868. package/src/domain/__tests__/Line.test.js +0 -73
  869. package/src/domain/__tests__/Profile.test.js +0 -104
  870. package/src/domain/types.js +0 -248
  871. package/src/lib/WazoSessionDescriptionHandler.js +0 -467
  872. package/src/service/getApiClient.js +0 -122
  873. package/src/simple/Phone.js +0 -425
  874. package/src/simple/Softphone.js +0 -392
  875. package/src/simple/Websocket.js +0 -86
  876. package/src/simple/utils.js +0 -17
  877. package/src/types/WebSocketMessage.js +0 -232
  878. package/src/utils/Emitter.js +0 -26
  879. package/src/utils/__tests__/object.test.js +0 -35
  880. package/src/utils/sdp.js +0 -140
  881. package/src/utils/update-from.js +0 -15
  882. /package/src/domain/{Country.js → Country.ts} +0 -0
  883. /package/src/utils/__tests__/{compare-version.test.js → compare-version.test.ts} +0 -0
@@ -1,12 +1,10 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
  /* eslint-disable no-underscore-dangle */
3
- // @flow
4
3
  import type { Message } from 'sip.js/lib/api/message';
5
- import type { Session } from 'sip.js/lib/core/session';
6
- import { Invitation } from 'sip.js/lib/api/invitation';
7
4
  import { SessionState } from 'sip.js/lib/api/session-state';
8
5
  import type { IncomingRequestMessage } from 'sip.js/lib/core/messages/incoming-request-message';
9
-
6
+ import { OutgoingInviteRequest } from 'sip.js/lib/core';
7
+ import { Inviter, Invitation, Session } from 'sip.js/lib/api';
10
8
  import CallSession from '../CallSession';
11
9
  import type { Phone, AvailablePhoneOptions } from './Phone';
12
10
  import WazoWebRTCClient from '../../web-rtc-client';
@@ -55,68 +53,26 @@ export const ON_CHAT = 'phone/ON_CHAT';
55
53
  export const ON_SIGNAL = 'phone/ON_SIGNAL';
56
54
  export const ON_DISCONNECTED = 'onDisconnected';
57
55
  export const ON_EARLY_MEDIA = 'onEarlyMedia';
58
-
59
56
  export const MESSAGE_TYPE_CHAT = 'message/TYPE_CHAT';
60
57
  export const MESSAGE_TYPE_SIGNAL = 'message/TYPE_SIGNAL';
61
-
62
- export const events = [
63
- ON_USER_AGENT,
64
- ON_REGISTERED,
65
- ON_UNREGISTERED,
66
- ON_PROGRESS,
67
- ON_CALL_ACCEPTED,
68
- ON_CALL_ANSWERED,
69
- ON_CALL_INCOMING,
70
- ON_CALL_OUTGOING,
71
- ON_CALL_MUTED,
72
- ON_CALL_UNMUTED,
73
- ON_CALL_RESUMED,
74
- ON_CALL_HELD,
75
- ON_CALL_UNHELD,
76
- ON_CAMERA_DISABLED,
77
- ON_CALL_FAILED,
78
- ON_CALL_ENDED,
79
- ON_CALL_REJECTED,
80
- ON_MESSAGE,
81
- ON_REINVITE,
82
- ON_TRACK,
83
- ON_AUDIO_STREAM,
84
- ON_VIDEO_STREAM,
85
- ON_REMOVE_STREAM,
86
- ON_SHARE_SCREEN_ENDED,
87
- ON_TERMINATE_SOUND,
88
- ON_PLAY_RING_SOUND,
89
- ON_PLAY_INBOUND_CALL_SIGNAL_SOUND,
90
- ON_PLAY_HANGUP_SOUND,
91
- ON_PLAY_PROGRESS_SOUND,
92
- ON_VIDEO_INPUT_CHANGE,
93
- ON_SHARE_SCREEN_STARTED,
94
- ON_CALL_ERROR,
95
- ON_CHAT,
96
- ON_SIGNAL,
97
- ON_NETWORK_STATS,
98
- ON_DISCONNECTED,
99
- ON_EARLY_MEDIA,
100
- ];
101
-
58
+ export const events = [ON_USER_AGENT, ON_REGISTERED, ON_UNREGISTERED, ON_PROGRESS, ON_CALL_ACCEPTED, ON_CALL_ANSWERED, ON_CALL_INCOMING, ON_CALL_OUTGOING, ON_CALL_MUTED, ON_CALL_UNMUTED, ON_CALL_RESUMED, ON_CALL_HELD, ON_CALL_UNHELD, ON_CAMERA_DISABLED, ON_CALL_FAILED, ON_CALL_ENDED, ON_CALL_REJECTED, ON_MESSAGE, ON_REINVITE, ON_TRACK, ON_AUDIO_STREAM, ON_VIDEO_STREAM, ON_REMOVE_STREAM, ON_SHARE_SCREEN_ENDED, ON_TERMINATE_SOUND, ON_PLAY_RING_SOUND, ON_PLAY_INBOUND_CALL_SIGNAL_SOUND, ON_PLAY_HANGUP_SOUND, ON_PLAY_PROGRESS_SOUND, ON_VIDEO_INPUT_CHANGE, ON_SHARE_SCREEN_STARTED, ON_CALL_ERROR, ON_CHAT, ON_SIGNAL, ON_NETWORK_STATS, ON_DISCONNECTED, ON_EARLY_MEDIA];
102
59
  const logger = IssueReporter.loggerFor('webrtc-phone');
103
-
104
60
  export default class WebRTCPhone extends Emitter implements Phone {
105
61
  client: WazoWebRTCClient;
106
62
 
107
63
  allowVideo: boolean;
108
64
 
109
- callSessions: { [string]: CallSession };
65
+ callSessions: Record<string, CallSession>;
110
66
 
111
67
  incomingSessions: string[];
112
68
 
113
- currentSipSession: Session;
69
+ currentSipSession: Invitation | Inviter | undefined;
114
70
 
115
- currentCallSession: ?CallSession;
71
+ currentCallSession: CallSession | null | undefined;
116
72
 
117
- audioOutputDeviceId: ?string;
73
+ audioOutputDeviceId: string | null | undefined;
118
74
 
119
- audioRingDeviceId: ?string;
75
+ audioRingDeviceId: string | null | undefined;
120
76
 
121
77
  audioOutputVolume: number;
122
78
 
@@ -124,26 +80,20 @@ export default class WebRTCPhone extends Emitter implements Phone {
124
80
 
125
81
  ringingEnabled: boolean;
126
82
 
127
- acceptedSessions: Object;
83
+ acceptedSessions: Record<string, any>;
128
84
 
129
- rejectedSessions: Object;
85
+ rejectedSessions: Record<string, any>;
130
86
 
131
- ignoredSessions: Object;
87
+ ignoredSessions: Record<string, any>;
132
88
 
133
- currentScreenShare: Object;
89
+ currentScreenShare: Record<string, any> | null;
134
90
 
135
- lastScreenShare: Object;
91
+ lastScreenShare: Record<string, any> | null;
136
92
 
137
93
  shouldSendReinvite: boolean;
138
94
 
139
- constructor(
140
- client: WazoWebRTCClient,
141
- audioOutputDeviceId: ?string,
142
- allowVideo: boolean = false,
143
- audioRingDeviceId?: string,
144
- ) {
95
+ constructor(client: WazoWebRTCClient, audioOutputDeviceId: string | null | undefined, allowVideo = false, audioRingDeviceId?: string) {
145
96
  super();
146
-
147
97
  this.client = client;
148
98
  this.allowVideo = allowVideo;
149
99
  this.callSessions = {};
@@ -154,25 +104,28 @@ export default class WebRTCPhone extends Emitter implements Phone {
154
104
  this.incomingSessions = [];
155
105
  this.ringingEnabled = true;
156
106
  this.shouldSendReinvite = false;
157
-
158
107
  this.bindClientEvents();
159
-
160
108
  this.acceptedSessions = {};
161
109
  this.rejectedSessions = {};
162
110
  this.ignoredSessions = {};
163
111
  }
164
112
 
165
113
  register() {
114
+ logger.info('WebRTC register', { client: !!this.client });
166
115
  if (!this.client) {
167
116
  return Promise.resolve();
168
117
  }
169
118
 
170
119
  return this.client.register().then(() => {
120
+ logger.info('WebRTC register, registered');
171
121
  return this.bindClientEvents();
172
122
  }).catch(error => {
173
123
  // Avoid exception on `t.server.scheme` in sip transport when losing the webrtc socket connection
174
124
  console.error('register error', error, error.message, error.stack);
175
- logger.error('WebRTC register error', { message: error.message, stack: error.stack });
125
+ logger.error('WebRTC register error', {
126
+ message: error.message,
127
+ stack: error.stack,
128
+ });
176
129
  });
177
130
  }
178
131
 
@@ -180,6 +133,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
180
133
  if (!this.client || !this.client.isRegistered()) {
181
134
  return null;
182
135
  }
136
+
183
137
  return this.client.unregister();
184
138
  }
185
139
 
@@ -187,6 +141,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
187
141
  if (!this.client) {
188
142
  return;
189
143
  }
144
+
190
145
  logger.info('WebRTC phone stop');
191
146
  this.client.stop();
192
147
  }
@@ -199,8 +154,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
199
154
  return true;
200
155
  }
201
156
 
202
- async sendReinvite(callSession: ?CallSession, constraints: ?Object = null, conference: boolean = false,
203
- audioOnly: boolean = false, iceRestart: boolean = false) {
157
+ async sendReinvite(callSession: CallSession | null | undefined, constraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
204
158
  const sipSession = this.findSipSession(callSession);
205
159
  logger.info('WebRTC phone - send reinvite', {
206
160
  sessionId: sipSession ? sipSession.id : null,
@@ -211,24 +165,25 @@ export default class WebRTCPhone extends Emitter implements Phone {
211
165
  });
212
166
 
213
167
  if (!sipSession) {
214
- return false;
168
+ return;
215
169
  }
216
170
 
217
- // $FlowFixMe
218
- const shouldScreenShare = constraints && constraints.screen;
219
- const isUpgrade = shouldScreenShare || (constraints && constraints.video);
171
+ const shouldScreenShare = constraints?.screen;
172
+ const isUpgrade = shouldScreenShare || constraints?.video;
220
173
 
221
174
  // Downgrade
222
175
  if (constraints && !isUpgrade) {
223
176
  // No reinvite needed
224
177
  this._downgradeToAudio(callSession);
225
- return false;
178
+
179
+ return;
226
180
  }
227
181
 
228
182
  if (isUpgrade) {
229
183
  const shouldReinvite = await this._upgradeToVideo(callSession, constraints, conference);
184
+
230
185
  if (!shouldReinvite) {
231
- return false;
186
+ return;
232
187
  }
233
188
  }
234
189
 
@@ -236,11 +191,15 @@ export default class WebRTCPhone extends Emitter implements Phone {
236
191
  }
237
192
 
238
193
  getUserAgent() {
239
- return (this.client && this.client.config && this.client.config.userAgentString) || 'webrtc-phone';
194
+ return this.client?.config?.userAgentString || 'webrtc-phone';
240
195
  }
241
196
 
242
197
  startHeartbeat() {
243
- logger.info('WebRTC phone - start heartbeat', { client: !!this.client, hasHeartbeat: this.client.hasHeartbeat() });
198
+ logger.info('WebRTC phone - start heartbeat', {
199
+ client: !!this.client,
200
+ hasHeartbeat: this.client.hasHeartbeat(),
201
+ });
202
+
244
203
  if (!this.client || this.client.hasHeartbeat()) {
245
204
  return;
246
205
  }
@@ -249,7 +208,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
249
208
  }
250
209
 
251
210
  stopHeartbeat() {
252
- logger.info('WebRTC phone - stopHeartbeat', { client: !!this.client });
211
+ logger.info('WebRTC phone - stopHeartbeat', {
212
+ client: !!this.client,
213
+ });
214
+
253
215
  if (!this.client) {
254
216
  return;
255
217
  }
@@ -257,19 +219,23 @@ export default class WebRTCPhone extends Emitter implements Phone {
257
219
  this.client.stopHeartbeat();
258
220
  }
259
221
 
260
- setOnHeartbeatTimeout(cb: Function) {
222
+ setOnHeartbeatTimeout(cb: (...args: Array<any>) => any) {
261
223
  this.client.setOnHeartbeatTimeout(cb);
262
224
  }
263
225
 
264
- setOnHeartbeatCallback(cb: Function) {
226
+ setOnHeartbeatCallback(cb: (...args: Array<any>) => any) {
265
227
  this.client.setOnHeartbeatCallback(cb);
266
228
  }
267
229
 
268
230
  reconnect() {
269
- logger.info('WebRTC phone - reconnect', { client: !!this.client });
231
+ logger.info('WebRTC phone - reconnect', {
232
+ client: !!this.client,
233
+ });
234
+
270
235
  if (!this.client) {
271
236
  return;
272
237
  }
238
+
273
239
  this.client.attemptReconnection();
274
240
  }
275
241
 
@@ -291,6 +257,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
291
257
  if (!this.client) {
292
258
  return Promise.reject(new Error('No webrtc client'));
293
259
  }
260
+
294
261
  return this.client.onConnect();
295
262
  }
296
263
 
@@ -298,21 +265,26 @@ export default class WebRTCPhone extends Emitter implements Phone {
298
265
  if (!this.client) {
299
266
  return Promise.reject(new Error('No webrtc client'));
300
267
  }
268
+
301
269
  return this.client.onDisconnect();
302
270
  }
303
271
 
304
- _downgradeToAudio(callSession: ?CallSession, withMessage: boolean = true) {
272
+ _downgradeToAudio(callSession: CallSession | null | undefined, withMessage = true) {
305
273
  const sipSession = this.findSipSession(callSession);
274
+
306
275
  if (!sipSession) {
307
276
  return false;
308
277
  }
309
278
 
310
- logger.info('Downgrade to video', { id: callSession ? callSession.getId() : null, withMessage });
311
-
279
+ logger.info('Downgrade to video', {
280
+ id: callSession ? callSession.getId() : null,
281
+ withMessage,
282
+ });
312
283
  this.client.downgradeToAudio(sipSession);
313
284
 
314
285
  if (callSession) {
315
286
  callSession.cameraEnabled = false;
287
+
316
288
  this._updateCallSession(callSession);
317
289
  }
318
290
 
@@ -324,8 +296,9 @@ export default class WebRTCPhone extends Emitter implements Phone {
324
296
  }
325
297
 
326
298
  // Returns true if we need to send a re-INVITE request
327
- async _upgradeToVideo(callSession: ?CallSession, constraints: ?Object, isConference: boolean): Promise<boolean> {
299
+ async _upgradeToVideo(callSession: CallSession | null | undefined, constraints: Record<string, any>, isConference: boolean): Promise<boolean> {
328
300
  const sipSession = this.findSipSession(callSession);
301
+
329
302
  if (!sipSession) {
330
303
  return Promise.resolve(false);
331
304
  }
@@ -335,16 +308,16 @@ export default class WebRTCPhone extends Emitter implements Phone {
335
308
  constraints,
336
309
  isConference,
337
310
  });
338
-
339
311
  const shouldScreenShare = constraints && !!constraints.screen;
340
312
  const desktop = constraints && constraints.desktop;
341
313
  const options = sipSession.sessionDescriptionHandlerOptionsReInvite;
342
- const wasAudioOnly = options && options.audioOnly;
343
-
314
+ // @ts-ignore
315
+ const wasAudioOnly = options?.audioOnly;
344
316
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
345
317
 
346
318
  if (callSession) {
347
319
  callSession.cameraEnabled = true;
320
+
348
321
  this._updateCallSession(callSession);
349
322
  }
350
323
 
@@ -368,13 +341,12 @@ export default class WebRTCPhone extends Emitter implements Phone {
368
341
  return false;
369
342
  }
370
343
 
371
- _sendReinviteMessage(callSession: ?CallSession, isUpgrade: boolean) {
344
+ _sendReinviteMessage(callSession: CallSession | null | undefined, isUpgrade: boolean) {
372
345
  const sipSession = this.findSipSession(callSession);
373
346
  logger.info('Sending reinvite message', {
374
347
  id: callSession ? callSession.getId() : null,
375
348
  isUpgrade,
376
349
  });
377
-
378
350
  // Have to send the message after a delay due to latency to update the remote peer
379
351
  setTimeout(() => {
380
352
  this.sendMessage(sipSession, JSON.stringify({
@@ -382,7 +354,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
382
354
  content: {
383
355
  type: ON_MESSAGE_TRACK_UPDATED,
384
356
  update: isUpgrade ? 'upgrade' : 'downgrade',
385
- sipCallId: this.getSipSessionId(sipSession),
357
+ sipCallId: sipSession && this.getSipSessionId(sipSession),
386
358
  callId: callSession ? callSession.callId : null,
387
359
  number: callSession ? callSession.number : null,
388
360
  callerNumber: callSession ? callSession.callerNumber : null,
@@ -391,18 +363,23 @@ export default class WebRTCPhone extends Emitter implements Phone {
391
363
  }, 2500);
392
364
  }
393
365
 
394
- _bindEvents(sipSession: Session) {
395
- if (sipSession._onCancel) {
366
+ _bindEvents(sipSession: Invitation | Inviter) {
367
+ const sipSessionId = this.getSipSessionId(sipSession);
368
+
369
+ if (sipSession instanceof Invitation) {
396
370
  // Monkey patch to know when canceled with the CANCEL message
397
371
  const onCancel = sipSession._onCancel.bind(sipSession);
398
- sipSession._onCancel = (message: IncomingRequestMessage) => {
399
- logger.trace('on sip session canceled', { callId: message.callId });
400
372
 
373
+ sipSession._onCancel = (message: IncomingRequestMessage) => {
374
+ logger.trace('on sip session canceled', {
375
+ callId: message.callId,
376
+ sipSessionId,
377
+ });
401
378
  onCancel(message);
402
379
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
403
380
  const callSession = this._createCallSession(sipSession);
404
- delete this.callSessions[callSession.getId()];
405
381
 
382
+ delete this.callSessions[sipSessionId];
406
383
  this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
407
384
  };
408
385
  } else if (sipSession instanceof Invitation) {
@@ -416,29 +393,36 @@ export default class WebRTCPhone extends Emitter implements Phone {
416
393
  // No need to trigger progress for an invitation (eg: when we answer the call).
417
394
  return;
418
395
  }
396
+
419
397
  // When receiving a progress event, we know we are the caller so we have to force incoming to false
420
- return this.eventEmitter.emit(
421
- ON_PROGRESS,
422
- this._createCallSession(sipSession, null, { incoming: false, ringing: true }),
423
- this.audioOutputDeviceId,
424
- this.audioOutputVolume,
425
- );
426
- case SessionState.Terminating:
427
- logger.info('WebRTC phone - call terminating', { sipId: sipSession.id });
398
+ return this.eventEmitter.emit(ON_PROGRESS, this._createCallSession(sipSession, null, {
399
+ incoming: false,
400
+ ringing: true,
401
+ }), this.audioOutputDeviceId, this.audioOutputVolume);
428
402
 
403
+ case SessionState.Terminating:
404
+ logger.info('WebRTC phone - call terminating', {
405
+ sipId: sipSession.id,
406
+ });
429
407
  this.eventEmitter.emit(ON_CALL_ENDING, this._createCallSession(sipSession));
430
-
431
408
  break;
432
- case SessionState.Terminated: {
433
- logger.info('WebRTC phone - call terminated', { sipId: sipSession.id });
409
+
410
+ case SessionState.Terminated:
411
+ {
412
+ logger.info('WebRTC phone - call terminated', {
413
+ sipId: sipSession.id,
414
+ });
434
415
 
435
416
  // Should be called before `_onCallTerminated` or the callCount will not decrement...
436
417
  const callSession = this._createCallSession(sipSession);
418
+
437
419
  callSession.endTime = new Date();
420
+
438
421
  const wasCurrentSession = this._onCallTerminated(sipSession);
439
422
 
440
423
  return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
441
424
  }
425
+
442
426
  default:
443
427
  break;
444
428
  }
@@ -449,12 +433,15 @@ export default class WebRTCPhone extends Emitter implements Phone {
449
433
  }
450
434
 
451
435
  // Video events
452
- const { peerConnection } = sipSession.sessionDescriptionHandler;
453
- peerConnection.ontrack = rawEvent => {
436
+ const {
437
+ // @ts-ignore
438
+ peerConnection,
439
+ } = sipSession.sessionDescriptionHandler;
440
+
441
+ peerConnection.ontrack = (rawEvent: any) => {
454
442
  const event = rawEvent;
455
443
  const [stream] = event.streams;
456
444
  const kind = event && event.track && event.track.kind;
457
-
458
445
  logger.info('on track stream called on the peer connection', {
459
446
  callId: this.getSipSessionId(sipSession),
460
447
  streamId: stream ? stream.id : null,
@@ -474,29 +461,31 @@ export default class WebRTCPhone extends Emitter implements Phone {
474
461
  return this.eventEmitter.emit(ON_VIDEO_STREAM, stream, event.track.id, event, sipSession);
475
462
  };
476
463
 
477
- peerConnection.onremovestream = event => {
464
+ peerConnection.onremovestream = (event: any) => {
478
465
  logger.info('on remove stream called on the peer connection', {
479
466
  id: event.stream.id,
480
467
  tracks: event.stream.getTracks(),
481
468
  });
482
-
483
469
  this.eventEmitter.emit(ON_REMOVE_STREAM, event.stream);
484
470
  };
485
471
  }
486
472
 
487
- async startScreenSharing(constraints: Object, callSession?: CallSession) {
488
- logger.info('WebRTC - start screen sharing', { constraints, id: callSession ? callSession.getId() : null });
489
-
473
+ async startScreenSharing(constraints: Record<string, any>, callSession?: CallSession): Promise<MediaStream> {
474
+ logger.info('WebRTC - start screen sharing', {
475
+ constraints,
476
+ id: callSession ? callSession.getId() : null,
477
+ });
490
478
  const screenShareStream = await this.client.getStreamFromConstraints(constraints);
479
+
491
480
  if (!screenShareStream) {
492
481
  throw new Error(`Can't create media stream for screensharing with: ${JSON.stringify(constraints)}`);
493
482
  }
494
483
 
495
484
  const screenTrack = screenShareStream.getVideoTracks()[0];
496
485
  const sipSession = this.currentSipSession;
497
- const pc = this.client.getPeerConnection(this.getSipSessionId(sipSession));
498
- const sender = pc && pc.getSenders && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
499
- const localStream = this.client.getLocalStream(this.getSipSessionId(sipSession));
486
+ const pc = sipSession && this.client.getPeerConnection(this.getSipSessionId(sipSession));
487
+ const sender = pc && pc.getSenders && pc.getSenders().find((s: any) => s && s.track && s.track.kind === 'video');
488
+ const localStream = sipSession && this.client.getLocalStream(this.getSipSessionId(sipSession));
500
489
  const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
501
490
  const hadVideo = !!videoTrack;
502
491
 
@@ -515,12 +504,12 @@ export default class WebRTCPhone extends Emitter implements Phone {
515
504
  sender.replaceTrack(screenTrack);
516
505
  }
517
506
 
518
- this._onScreenSharing(screenShareStream, sipSession, callSession, hadVideo, constraints.desktop);
507
+ this._onScreenSharing(screenShareStream, sipSession as Inviter | Invitation, callSession, hadVideo, constraints.desktop);
519
508
 
520
509
  return screenShareStream;
521
510
  }
522
511
 
523
- async stopScreenSharing(restoreLocalStream: boolean = true, callSession?: ?CallSession) {
512
+ async stopScreenSharing(restoreLocalStream = true, callSession?: CallSession | null | undefined): Promise<OutgoingInviteRequest | void> {
524
513
  if (!this.currentScreenShare) {
525
514
  return;
526
515
  }
@@ -528,57 +517,49 @@ export default class WebRTCPhone extends Emitter implements Phone {
528
517
  logger.info('WebRTC phone - stop screen sharing', {
529
518
  restoreLocalStream,
530
519
  });
531
-
532
- let reinvited = false;
520
+ let reinvited: OutgoingInviteRequest | void;
533
521
 
534
522
  try {
535
523
  if (this.currentScreenShare.stream) {
536
- this.currentScreenShare.stream.getTracks().forEach(track => track.stop());
524
+ this.currentScreenShare.stream.getTracks().forEach((track: MediaStreamTrack) => track.stop());
537
525
  }
538
526
 
539
527
  if (restoreLocalStream) {
540
528
  const targetCallSession = callSession || this.currentCallSession;
541
529
  const conference = this.isConference(targetCallSession);
542
-
543
530
  // When stopping screenshare and we had video before that, we have to re-upgrade
544
531
  // When upgrading directly to screenshare (eg: we don't have a videoLocalStream to replace)
545
532
  // We have to downgrade to audio.
546
533
  const screenshareStopped = this.currentScreenShare.hadVideo;
547
- const constraints = { audio: false, video: screenshareStopped };
534
+ const constraints = {
535
+ audio: false,
536
+ video: screenshareStopped,
537
+ };
548
538
 
549
539
  // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
550
540
  this._downgradeToAudio(targetCallSession, false);
541
+
551
542
  // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
552
543
  await new Promise(resolve => setTimeout(resolve, 500));
553
-
554
544
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
555
545
  }
556
- } catch (e) {
546
+ } catch (e: any) {
557
547
  console.warn(e);
558
548
  }
559
549
 
560
550
  const sipSession = this.currentSipSession;
561
-
562
- this.eventEmitter.emit(
563
- ON_SHARE_SCREEN_ENDED,
564
- callSession ? this._createCallSession(sipSession, callSession, { screensharing: false }) : null,
565
- );
566
-
551
+ this.eventEmitter.emit(ON_SHARE_SCREEN_ENDED, callSession && sipSession ? this._createCallSession(sipSession, callSession, {
552
+ screensharing: false,
553
+ }) : null);
567
554
  this.currentScreenShare = null;
568
-
569
555
  return reinvited;
570
556
  }
571
557
 
572
- _onScreenSharing(screenStream: Object,
573
- sipSession: Session,
574
- callSession: ?CallSession,
575
- hadVideo: boolean,
576
- desktop?: ?boolean = false) {
558
+ _onScreenSharing(screenStream: MediaStream, sipSession: Invitation | Inviter, callSession: CallSession | null | undefined, hadVideo: boolean, desktop?: boolean | null | undefined) {
577
559
  const screenTrack = screenStream.getVideoTracks()[0];
578
560
  const sipSessionId = this.getSipSessionId(sipSession);
579
561
  const pc = this.client.getPeerConnection(sipSessionId);
580
- const sender = pc && pc.getSenders && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
581
-
562
+ const sender = pc && pc.getSenders && pc.getSenders().find((s: any) => s && s.track && s.track.kind === 'video');
582
563
  logger.info('WebRTC phone - on screensharing', {
583
564
  hadVideo,
584
565
  id: this.getSipSessionId(sipSession),
@@ -592,11 +573,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
592
573
  id: this.getSipSessionId(sipSession),
593
574
  screenTrack,
594
575
  });
595
-
596
- this.eventEmitter.emit(
597
- ON_SHARE_SCREEN_ENDING,
598
- this._createCallSession(sipSession, callSession),
599
- );
576
+ this.eventEmitter.emit(ON_SHARE_SCREEN_ENDING, this._createCallSession(sipSession, callSession));
600
577
  };
601
578
  }
602
579
 
@@ -607,38 +584,41 @@ export default class WebRTCPhone extends Emitter implements Phone {
607
584
  sipSessionId,
608
585
  desktop,
609
586
  };
610
-
611
587
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), screenStream);
612
-
613
- this.eventEmitter.emit(
614
- ON_SHARE_SCREEN_STARTED,
615
- this._createCallSession(sipSession, callSession, { screensharing: true }),
616
- screenStream,
617
- );
588
+ this.eventEmitter.emit(ON_SHARE_SCREEN_STARTED, this._createCallSession(sipSession, callSession, {
589
+ screensharing: true,
590
+ }), screenStream);
618
591
  }
619
592
 
620
- _onCallAccepted(sipSession: Session, cameraEnabled: boolean): CallSession {
621
- logger.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
593
+ _onCallAccepted(sipSession: Inviter | Invitation, cameraEnabled: boolean): CallSession {
594
+ logger.info('WebRTC phone - on call accepted', {
595
+ sipId: sipSession.id,
596
+ cameraEnabled,
597
+ });
622
598
 
623
599
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
600
+
624
601
  this.currentSipSession = sipSession;
625
602
  this.currentCallSession = callSession;
626
-
627
603
  this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call accepted');
628
604
  const sipSessionId = this.getSipSessionId(sipSession);
605
+
629
606
  if (sipSessionId) {
630
607
  this.removeIncomingSessions(sipSessionId);
631
608
  }
632
609
 
633
610
  callSession.answerTime = new Date();
611
+
634
612
  this._updateCallSession(callSession);
635
- this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
636
613
 
614
+ this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
637
615
  return callSession;
638
616
  }
639
617
 
640
618
  changeAudioDevice(id: string) {
641
- logger.info('WebRTC phone - change audio device', { deviceId: id });
619
+ logger.info('WebRTC phone - change audio device', {
620
+ deviceId: id,
621
+ });
642
622
  this.audioOutputDeviceId = id;
643
623
  this.client.changeAudioOutputDevice(id);
644
624
  }
@@ -648,52 +628,63 @@ export default class WebRTCPhone extends Emitter implements Phone {
648
628
  }
649
629
 
650
630
  changeRingDevice(id: string) {
651
- logger.info('WebRTC phone - changing ring device', { id });
652
-
631
+ logger.info('WebRTC phone - changing ring device', {
632
+ id,
633
+ });
653
634
  this.audioRingDeviceId = id;
654
635
  }
655
636
 
656
637
  // volume is a value between 0 and 1
657
638
  changeAudioVolume(volume: number) {
658
- logger.info('WebRTC phone - changing audio volume', { volume });
659
-
639
+ logger.info('WebRTC phone - changing audio volume', {
640
+ volume,
641
+ });
660
642
  this.audioOutputVolume = volume;
661
643
  this.client.changeAudioOutputVolume(volume);
662
644
  }
663
645
 
664
646
  // volume is a value between 0 and 1
665
647
  changeRingVolume(volume: number) {
666
- logger.info('WebRTC phone - changing ring volume', { volume });
667
-
648
+ logger.info('WebRTC phone - changing ring volume', {
649
+ volume,
650
+ });
668
651
  this.audioRingVolume = volume;
669
652
  }
670
653
 
671
- changeAudioInputDevice(id: string, force: ?boolean) {
672
- logger.info('WebRTC phone - changeAudio input device', { deviceId: id });
673
-
654
+ changeAudioInputDevice(id: string, force?: boolean) {
655
+ logger.info('WebRTC phone - changeAudio input device', {
656
+ deviceId: id,
657
+ });
674
658
  return this.client.changeAudioInputDevice(id, this.currentSipSession, force);
675
659
  }
676
660
 
677
- changeVideoInputDevice(id: ?string) {
678
- logger.info('WebRTC phone - change video input device', { deviceId: id });
679
-
661
+ async changeVideoInputDevice(id: string): Promise<void | MediaStream | null | undefined> {
662
+ logger.info('WebRTC phone - change video input device', {
663
+ deviceId: id,
664
+ });
680
665
  return this.client.changeVideoInputDevice(id, this.currentSipSession);
681
666
  }
682
667
 
683
- changeSessionVideoInputDevice(id: ?string) {
684
- logger.info('WebRTC phone - change session video input device', { deviceId: id });
685
-
686
- return this.client.changeSessionVideoInputDevice(id, this.currentSipSession);
668
+ changeSessionVideoInputDevice(id: string | null | undefined) {
669
+ logger.info('WebRTC phone - change session video input device', {
670
+ deviceId: id,
671
+ });
672
+ return this.currentSipSession && this.client.changeSessionVideoInputDevice(id, this.currentSipSession);
687
673
  }
688
674
 
689
- _onCallTerminated(sipSession: Session) {
690
- logger.info('WebRTC phone - on call terminated', { sipId: sipSession.id });
691
-
675
+ _onCallTerminated(sipSession: Invitation | Inviter): boolean {
692
676
  const sipSessionId = this.getSipSessionId(sipSession);
677
+
678
+ logger.info('WebRTC phone - on call terminated', {
679
+ sipId: sipSession.id,
680
+ sipSessionId,
681
+ ids: Object.keys(this.callSessions),
682
+ });
683
+
693
684
  const callSession = this._createCallSession(sipSession);
685
+
694
686
  const isCurrentSession = this.isCurrentCallSipSession(callSession);
695
687
  const isCurrentIncomingCall = callSession.is(this.getIncomingCallSession());
696
-
697
688
  // If the terminated call was an incoming call, we have to re-trigger if it's was the first incoming call
698
689
  // Otherwise, we have to re-trigger an incoming call event if another call is incoming
699
690
  const shouldRetrigger = isCurrentSession ? this.incomingSessions.length : isCurrentIncomingCall;
@@ -711,7 +702,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
711
702
  this.removeIncomingSessions(sipSessionId);
712
703
  }
713
704
 
714
- delete this.callSessions[callSession.getId()];
705
+ delete this.callSessions[sipSessionId];
715
706
 
716
707
  if (isCurrentSession) {
717
708
  this.currentSipSession = undefined;
@@ -719,14 +710,12 @@ export default class WebRTCPhone extends Emitter implements Phone {
719
710
  }
720
711
 
721
712
  const hasIncomingCallSession = this.hasIncomingCallSession();
722
-
723
713
  // Re-trigger incoming call event for remaining incoming calls
724
714
  logger.info('WebRTC phone - check to re-trigger incoming call', {
725
715
  sipId: sipSession.id,
726
716
  shouldRetrigger,
727
717
  hasIncomingCallSession,
728
718
  });
729
-
730
719
  this.client.onCallEnded(sipSession);
731
720
 
732
721
  if (hasIncomingCallSession && shouldRetrigger) {
@@ -737,22 +726,19 @@ export default class WebRTCPhone extends Emitter implements Phone {
737
726
  if (!this.currentCallSession) {
738
727
  this.eventEmitter.emit(ON_PLAY_RING_SOUND, this.audioRingDeviceId, this.audioRingVolume, nextCallSession);
739
728
  } else {
740
- this.eventEmitter.emit(ON_PLAY_INBOUND_CALL_SIGNAL_SOUND,
741
- this.audioOutputDeviceId,
742
- this.audioOutputVolume,
743
- nextCallSession);
729
+ this.eventEmitter.emit(ON_PLAY_INBOUND_CALL_SIGNAL_SOUND, this.audioOutputDeviceId, this.audioOutputVolume, nextCallSession);
744
730
  }
745
731
  }
746
732
 
747
- // $FlowFixMe
748
- this.eventEmitter.emit(ON_CALL_INCOMING, nextCallSession, nextCallSession.cameraEnabled);
733
+ this.eventEmitter.emit(ON_CALL_INCOMING, nextCallSession, nextCallSession?.cameraEnabled);
749
734
  }, 100);
750
735
  }
751
736
 
752
737
  if (callSession.getId() in this.ignoredSessions) {
753
- return;
738
+ return false;
754
739
  }
755
740
 
741
+ // @ts-ignore
756
742
  if (!sipSession.isCanceled) {
757
743
  setTimeout(() => {
758
744
  this.eventEmitter.emit(ON_PLAY_HANGUP_SOUND, this.audioOutputDeviceId, this.audioOutputVolume, callSession);
@@ -764,6 +750,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
764
750
 
765
751
  setActiveSipSession(callSession: CallSession) {
766
752
  const sipSessionId = this.findSipSession(callSession);
753
+
767
754
  if (!sipSessionId) {
768
755
  return;
769
756
  }
@@ -780,17 +767,20 @@ export default class WebRTCPhone extends Emitter implements Phone {
780
767
  // Maybe due to https://github.com/react-native-webrtc/react-native-webrtc/issues/401
781
768
  hasActiveRemoteVideoStream() {
782
769
  const sipSession = this.currentSipSession;
770
+
783
771
  if (!sipSession) {
784
772
  return false;
785
773
  }
786
774
 
787
- const { peerConnection } = sipSession.sessionDescriptionHandler;
788
- const remoteStream = peerConnection.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
789
-
775
+ const {
776
+ // @ts-ignore
777
+ peerConnection,
778
+ } = sipSession.sessionDescriptionHandler;
779
+ const remoteStream: MediaStream = peerConnection.getRemoteStreams().find((stream: MediaStream) => !!stream.getVideoTracks().length);
790
780
  return remoteStream && remoteStream.getVideoTracks().some(track => !track.muted);
791
781
  }
792
782
 
793
- callCount() {
783
+ callCount(): number {
794
784
  return Object.keys(this.callSessions).length;
795
785
  }
796
786
 
@@ -811,33 +801,30 @@ export default class WebRTCPhone extends Emitter implements Phone {
811
801
  }
812
802
 
813
803
  // Deprecated
814
- getLocalStreamForCall(callSession: CallSession): ?MediaStream {
804
+ getLocalStreamForCall(callSession: CallSession): MediaStream | null | undefined {
815
805
  logger.warn('WebRTCPhone.getLocalStreamForCall is deprecated, use WebRTCPhone.getLocalStream instead');
816
-
817
806
  return this.getLocalStream(callSession);
818
807
  }
819
808
 
820
809
  // Deprecated
821
- getRemoteStreamForCall(callSession: CallSession): ?MediaStream {
810
+ getRemoteStreamForCall(callSession: CallSession): MediaStream | null | undefined {
822
811
  logger.warn('WebRTCPhone.getRemoteStreamForCall is deprecated, use WebRTCPhone.getRemoteStream instead');
823
-
824
812
  return this.getRemoteVideoStream(callSession);
825
813
  }
826
814
 
827
- getRemoteStreamsForCall(callSession: CallSession): ?MediaStream {
815
+ getRemoteStreamsForCall(callSession: CallSession): MediaStream | null | undefined {
828
816
  logger.warn('WebRTCPhone.getRemoteStreamsForCall is deprecated, use WebRTCPhone.getRemoteStreams instead');
829
-
830
817
  return this.getRemoteStream(callSession);
831
818
  }
832
819
 
833
820
  accept(callSession: CallSession, cameraEnabled?: boolean): Promise<string | null> {
834
- logger.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
821
+ logger.info('WebRTC phone - accept call', {
822
+ id: callSession ? callSession.getId() : 'n/a',
823
+ cameraEnabled,
824
+ });
825
+
835
826
  if (this.currentSipSession) {
836
- this.holdSipSession(
837
- this.currentSipSession,
838
- this.currentCallSession,
839
- true,
840
- );
827
+ this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
841
828
  }
842
829
 
843
830
  if (!callSession) {
@@ -846,34 +833,33 @@ export default class WebRTCPhone extends Emitter implements Phone {
846
833
  }
847
834
 
848
835
  const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
836
+
849
837
  if (sipSessionId && !(sipSessionId in this.callSessions)) {
850
- logger.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
838
+ logger.warn('Call session already ended or not found, can\'t accept it.', {
839
+ sipSessionId,
840
+ });
851
841
  return Promise.resolve(null);
852
842
  }
853
843
 
854
844
  if (callSession.getId() in this.acceptedSessions) {
855
- logger.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
845
+ logger.warn('CallSession already accepted.', {
846
+ id: callSession ? callSession.getId() : 'n/a',
847
+ });
856
848
  return Promise.resolve(callSession.sipCallId);
857
849
  }
858
850
 
859
851
  this.shouldSendReinvite = false;
860
852
  callSession.answerTime = new Date();
853
+
861
854
  this._updateCallSession(callSession);
862
- this.acceptedSessions[callSession.getId()] = true;
863
855
 
856
+ this.acceptedSessions[callSession.getId()] = true;
864
857
  this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
858
+ const sipSession = this.client.getSipSession(callSession.getId()) as Invitation;
865
859
 
866
- const sipSession = this.client.getSipSession(callSession.getId());
867
860
  if (sipSession) {
868
- if (sipSession.state === SessionState.Terminated || sipSession.state === SessionState.Terminating) {
869
- logger.warn('Trying to answer a terminated sipSession.');
870
-
871
- return Promise.resolve(null);
872
- }
873
-
874
861
  logger.info('accept call, session found', { sipId: sipSession.id });
875
862
 
876
- // $FlowFixMe
877
863
  return this.client.answer(sipSession, this.allowVideo ? cameraEnabled : false).then(() => {
878
864
  return callSession.sipCallId;
879
865
  }).catch(e => {
@@ -883,7 +869,16 @@ export default class WebRTCPhone extends Emitter implements Phone {
883
869
  });
884
870
  }
885
871
 
886
- logger.warn('no CallSession found to accept.', { id: callSession ? callSession.getId() : 'n/a' });
872
+ const error = 'No CallSession found to accept.';
873
+
874
+ logger.warn(error, {
875
+ id: callSession ? callSession.getId() : 'n/a',
876
+ ids: this.client.getSipSessionIds(),
877
+ });
878
+
879
+ if (callSession) {
880
+ this.eventEmitter.emit(ON_CALL_ERROR, new Error(error), callSession);
881
+ }
887
882
 
888
883
  return Promise.resolve(null);
889
884
  }
@@ -893,80 +888,87 @@ export default class WebRTCPhone extends Emitter implements Phone {
893
888
  }
894
889
 
895
890
  async reject(callSession: CallSession): Promise<void> {
896
- logger.info('reject WebRTC called', { id: callSession.getId() });
897
-
891
+ logger.info('reject WebRTC called', {
892
+ id: callSession.getId(),
893
+ });
898
894
  this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call rejected locally');
895
+
899
896
  if (!callSession || callSession.getId() in this.rejectedSessions) {
900
897
  return;
901
898
  }
902
899
 
903
900
  this.shouldSendReinvite = false;
904
901
  this.rejectedSessions[callSession.getId()] = true;
905
-
906
902
  const sipSession = this.findSipSession(callSession);
907
- if (sipSession) {
908
- logger.info('WebRTC rejecting', { sipId: sipSession.id });
909
903
 
904
+ if (sipSession) {
905
+ logger.info('WebRTC rejecting', {
906
+ sipId: sipSession.id,
907
+ });
910
908
  this.client.hangup(sipSession);
911
909
  }
912
910
  }
913
911
 
914
912
  async ignore(callSession: CallSession): Promise<void> {
915
- logger.info('WebRTC ignore', { id: callSession.getId() });
916
-
913
+ logger.info('WebRTC ignore', {
914
+ id: callSession.getId(),
915
+ });
917
916
  // kill the ring
918
917
  this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'ignoring call');
919
918
  this.ignoredSessions[callSession.getId()] = true;
920
919
  callSession.ignore();
921
920
  }
922
921
 
923
- atxfer(callSession: CallSession): ?Object {
924
- const sipSession = this.findSipSession(callSession);
922
+ atxfer(callSession: CallSession): Record<string, any> | null | undefined {
923
+ const sipSession = this.findSipSession(callSession) as Inviter;
925
924
 
926
925
  if (sipSession) {
927
- logger.info('WebRTC atxfer', { sipId: sipSession.id });
928
-
926
+ logger.info('WebRTC atxfer', {
927
+ sipId: sipSession.id,
928
+ });
929
929
  return this.client.atxfer(sipSession);
930
930
  }
931
931
  }
932
932
 
933
- hold(callSession: CallSession, withEvent: boolean = true): ?Promise<any> {
934
- logger.info('WebRTC hold', { id: callSession.getId() });
935
-
933
+ hold(callSession: CallSession, withEvent = true): Promise<OutgoingInviteRequest | void> | null | undefined {
934
+ logger.info('WebRTC hold', {
935
+ id: callSession.getId(),
936
+ });
936
937
  const sipSession = this.findSipSession(callSession);
937
-
938
938
  return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
939
939
  }
940
940
 
941
941
  // @Deprecated
942
- unhold(callSession: CallSession, withEvent: boolean = true): ?Promise<any> {
942
+ unhold(callSession: CallSession, withEvent = true): Promise<MediaStream | void | null> {
943
943
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
944
-
945
944
  return this.resume(callSession, withEvent);
946
945
  }
947
946
 
948
- resume(callSession?: CallSession, withEvent: boolean = true): Promise<any> {
949
- logger.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
950
-
947
+ resume(callSession?: CallSession, withEvent = true): Promise<MediaStream | void | null> {
948
+ logger.info('WebRTC resume called', {
949
+ id: callSession ? callSession.getId() : null,
950
+ });
951
951
  const sipSession = this.findSipSession(callSession);
952
+
952
953
  if (!sipSession) {
953
954
  return new Promise((resolve, reject) => reject(new Error('No session to resume')));
954
955
  }
955
956
 
956
- logger.info('WebRTC resuming', { sipId: sipSession.id });
957
+ logger.info('WebRTC resuming', {
958
+ sipId: sipSession.id,
959
+ });
957
960
 
958
961
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
959
962
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
960
- logger.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
961
- this.holdSipSession(
962
- this.currentSipSession,
963
- this.currentCallSession,
964
- withEvent,
965
- );
963
+ logger.info('WebRTC hold call after resume', {
964
+ id: this.currentSipSession.id,
965
+ });
966
+ this.holdSipSession(this.currentSipSession, this.currentCallSession, withEvent);
966
967
  }
967
968
 
968
969
  const promise = this.unholdSipSession(sipSession, callSession, withEvent);
969
970
  this.currentSipSession = sipSession;
971
+
970
972
  if (callSession) {
971
973
  this.currentCallSession = callSession;
972
974
  }
@@ -974,18 +976,17 @@ export default class WebRTCPhone extends Emitter implements Phone {
974
976
  return promise;
975
977
  }
976
978
 
977
- async holdSipSession(
978
- sipSession: Session,
979
- callSession: ?CallSession,
980
- withEvent: boolean = true,
981
- ): Promise<any> {
979
+ async holdSipSession(sipSession: Inviter | Invitation, callSession: CallSession | null | undefined, withEvent = true): Promise<OutgoingInviteRequest | void> {
982
980
  if (!sipSession) {
983
981
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
984
982
  }
983
+
985
984
  const sessionId = this.getSipSessionId(sipSession);
986
985
  const hasVideo = this.client.hasLocalVideo(sessionId);
987
-
988
- logger.info('WebRTC hold sip session', { sipId: sipSession.id, hasVideo });
986
+ logger.info('WebRTC hold sip session', {
987
+ sipId: sipSession.id,
988
+ hasVideo,
989
+ });
989
990
 
990
991
  // Stop screenshare if needed
991
992
  if (this.currentScreenShare && this.currentScreenShare.sipSessionId === sessionId) {
@@ -999,8 +1000,8 @@ export default class WebRTCPhone extends Emitter implements Phone {
999
1000
  }
1000
1001
 
1001
1002
  const isConference = !!callSession && callSession.isConference();
1002
-
1003
1003
  const promise = this.client.hold(sipSession, isConference, hasVideo);
1004
+
1004
1005
  if (withEvent) {
1005
1006
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
1006
1007
  }
@@ -1008,21 +1009,20 @@ export default class WebRTCPhone extends Emitter implements Phone {
1008
1009
  return promise;
1009
1010
  }
1010
1011
 
1011
- async unholdSipSession(
1012
- sipSession: Session,
1013
- callSession: ?CallSession,
1014
- withEvent: boolean = true,
1015
- ): Promise<any> {
1012
+ async unholdSipSession(sipSession: Inviter | Invitation, callSession: CallSession | null | undefined, withEvent = true): Promise<MediaStream | void | null> {
1016
1013
  if (!sipSession) {
1017
1014
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
1018
1015
  }
1019
1016
 
1020
1017
  const isConference = !!callSession && callSession.isConference();
1021
-
1022
1018
  const sessionId = this.getSipSessionId(sipSession);
1023
- logger.info('WebRTC unhold sip session', { sessionId, isConference });
1024
-
1025
- const { hasVideo } = this.client.getHeldSession(sessionId) || {};
1019
+ logger.info('WebRTC unhold sip session', {
1020
+ sessionId,
1021
+ isConference,
1022
+ });
1023
+ const {
1024
+ hasVideo,
1025
+ } = this.client.getHeldSession(sessionId) || {};
1026
1026
  const wasScreensharing = this.lastScreenShare && this.lastScreenShare.sipSessionId === sessionId;
1027
1027
  const wasDesktop = this.lastScreenShare && this.lastScreenShare.desktop;
1028
1028
  const promise = this.client.unhold(sipSession, isConference);
@@ -1034,20 +1034,22 @@ export default class WebRTCPhone extends Emitter implements Phone {
1034
1034
  screen: wasScreensharing,
1035
1035
  desktop: wasDesktop,
1036
1036
  };
1037
-
1038
1037
  await this.client.upgradeToVideo(sipSession, constraints, isConference);
1039
1038
  }
1040
1039
 
1041
- const onScreenSharing = stream => {
1040
+ const onScreenSharing = (stream: MediaStream | null | undefined) => {
1042
1041
  const hadVideo = this.lastScreenShare && this.lastScreenShare.hadVideo;
1042
+
1043
1043
  if (stream) {
1044
1044
  this._onScreenSharing(stream, sipSession, callSession, hadVideo);
1045
1045
  }
1046
+
1046
1047
  this.lastScreenShare = null;
1047
1048
  };
1048
1049
 
1049
1050
  if (withEvent) {
1050
1051
  const updatedCallSession = this._createCallSession(sipSession, callSession);
1052
+
1051
1053
  // Deprecated event
1052
1054
  this.eventEmitter.emit(ON_CALL_UNHELD, updatedCallSession);
1053
1055
  this.eventEmitter.emit(ON_CALL_RESUMED, updatedCallSession);
@@ -1055,6 +1057,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1055
1057
 
1056
1058
  return promise.then(() => {
1057
1059
  const stream = callSession ? this.getLocalVideoStream(callSession) : null;
1060
+
1058
1061
  if (wasScreensharing) {
1059
1062
  onScreenSharing(stream);
1060
1063
  }
@@ -1063,17 +1066,24 @@ export default class WebRTCPhone extends Emitter implements Phone {
1063
1066
  });
1064
1067
  }
1065
1068
 
1066
- mute(callSession: ?CallSession, withEvent: boolean = true): void {
1067
- logger.info('WebRTC mute called', { id: callSession ? callSession.getId() : null });
1068
-
1069
+ mute(callSession: CallSession | null | undefined, withEvent = true): void {
1070
+ logger.info('WebRTC mute called', {
1071
+ id: callSession ? callSession.getId() : null,
1072
+ });
1069
1073
  const sipSession = this.findSipSession(callSession);
1074
+
1070
1075
  if (!sipSession) {
1071
1076
  return;
1072
1077
  }
1073
1078
 
1074
- logger.info('WebRTC muting', { sipId: sipSession.id });
1079
+ logger.info('WebRTC muting', {
1080
+ sipId: sipSession.id,
1081
+ });
1075
1082
  this.client.mute(sipSession);
1076
- const newCallSession = this._createCallSession(sipSession, callSession, { muted: true });
1083
+
1084
+ const newCallSession = this._createCallSession(sipSession, callSession, {
1085
+ muted: true,
1086
+ });
1077
1087
 
1078
1088
  if (this.currentCallSession && newCallSession.is(this.currentCallSession)) {
1079
1089
  this.currentCallSession = newCallSession;
@@ -1084,17 +1094,24 @@ export default class WebRTCPhone extends Emitter implements Phone {
1084
1094
  }
1085
1095
  }
1086
1096
 
1087
- unmute(callSession: ?CallSession, withEvent: boolean = true): void {
1088
- logger.info('WebRTC unmute called', { id: callSession ? callSession.getId() : null });
1089
-
1097
+ unmute(callSession: CallSession | null | undefined, withEvent = true): void {
1098
+ logger.info('WebRTC unmute called', {
1099
+ id: callSession ? callSession.getId() : null,
1100
+ });
1090
1101
  const sipSession = this.findSipSession(callSession);
1102
+
1091
1103
  if (!sipSession) {
1092
1104
  return;
1093
1105
  }
1094
1106
 
1095
- logger.info('WebRTC unmuting', { sipId: sipSession.id });
1107
+ logger.info('WebRTC unmuting', {
1108
+ sipId: sipSession.id,
1109
+ });
1096
1110
  this.client.unmute(sipSession);
1097
- const newCallSession = this._createCallSession(sipSession, callSession, { muted: false });
1111
+
1112
+ const newCallSession = this._createCallSession(sipSession, callSession, {
1113
+ muted: false,
1114
+ });
1098
1115
 
1099
1116
  if (this.currentCallSession && newCallSession.is(this.currentCallSession)) {
1100
1117
  this.currentCallSession = newCallSession;
@@ -1107,6 +1124,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1107
1124
 
1108
1125
  isAudioMuted(callSession: CallSession): boolean {
1109
1126
  const sipSession = this.findSipSession(callSession);
1127
+
1110
1128
  if (!sipSession) {
1111
1129
  return true;
1112
1130
  }
@@ -1116,42 +1134,57 @@ export default class WebRTCPhone extends Emitter implements Phone {
1116
1134
 
1117
1135
  turnCameraOn(callSession?: CallSession): void {
1118
1136
  const sipSession = this.findSipSession(callSession);
1137
+
1119
1138
  if (!sipSession) {
1120
1139
  return;
1121
1140
  }
1122
- logger.info('WebRTC turn camera on', { sipId: sipSession.id });
1123
1141
 
1142
+ logger.info('WebRTC turn camera on', {
1143
+ sipId: sipSession.id,
1144
+ });
1124
1145
  this.client.toggleCameraOn(sipSession);
1125
-
1126
1146
  this.eventEmitter.emit(ON_CAMERA_RESUMED, this._createCameraResumedCallSession(sipSession, callSession));
1127
1147
  }
1128
1148
 
1129
1149
  turnCameraOff(callSession?: CallSession): void {
1130
1150
  const sipSession = this.findSipSession(callSession);
1151
+
1131
1152
  if (!sipSession) {
1132
1153
  return;
1133
1154
  }
1134
- logger.info('WebRTC turn camera off', { sipId: sipSession.id });
1135
1155
 
1156
+ logger.info('WebRTC turn camera off', {
1157
+ sipId: sipSession.id,
1158
+ });
1136
1159
  this.client.toggleCameraOff(sipSession);
1137
1160
  this.eventEmitter.emit(ON_CAMERA_DISABLED, this._createCameraDisabledCallSession(sipSession, callSession));
1138
1161
  }
1139
1162
 
1140
- sendKey(callSession: ?CallSession, tone: string): void {
1163
+ sendKey(callSession: CallSession | null | undefined, tone: string): void {
1141
1164
  const sipSession = this.findSipSession(callSession);
1165
+
1142
1166
  if (!sipSession) {
1143
1167
  return;
1144
1168
  }
1145
1169
 
1146
- logger.info('WebRTC send key', { sipId: sipSession.id, tone });
1170
+ logger.info('WebRTC send key', {
1171
+ sipId: sipSession.id,
1172
+ tone,
1173
+ });
1147
1174
  this.client.sendDTMF(sipSession, tone);
1148
1175
  }
1149
1176
 
1150
1177
  // Should be async to match CTIPhone definition
1151
1178
  // @TODO: line is not used here
1152
- async makeCall(number: string, line: any, cameraEnabled?: boolean,
1153
- audioOnly: boolean = false, conference: boolean = false): Promise<?CallSession> {
1154
- logger.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled, audioOnly, conference });
1179
+ async makeCall(number: string, line: any, cameraEnabled?: boolean, audioOnly = false, conference = false): Promise<CallSession | null | undefined> {
1180
+ logger.info('make WebRTC call', {
1181
+ number,
1182
+ lineId: line ? line.id : null,
1183
+ cameraEnabled,
1184
+ audioOnly,
1185
+ conference,
1186
+ });
1187
+
1155
1188
  if (!number) {
1156
1189
  return Promise.resolve(null);
1157
1190
  }
@@ -1159,39 +1192,43 @@ export default class WebRTCPhone extends Emitter implements Phone {
1159
1192
  if (!this.client.isRegistered()) {
1160
1193
  await this.client.register();
1161
1194
  }
1195
+
1162
1196
  if (this.currentSipSession) {
1163
- this.holdSipSession(
1164
- this.currentSipSession,
1165
- this.currentCallSession,
1166
- true,
1167
- ).catch(e => {
1197
+ this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
1168
1198
  logger.warn('Unable to hold current session when making another call', e);
1169
1199
  });
1170
1200
  }
1171
1201
 
1172
- let sipSession: Session;
1202
+ let sipSession: Inviter | Invitation;
1203
+
1173
1204
  try {
1174
1205
  sipSession = this.client.call(number, this.allowVideo ? cameraEnabled : false, audioOnly, conference);
1206
+
1175
1207
  this._bindEvents(sipSession);
1176
- } catch (error) {
1177
- console.warn(error);
1178
- logger.warn('make WebRTC call, error', { message: error.message, stack: error.stack });
1208
+ } catch (error: any) {
1209
+ logger.warn('make WebRTC call, error', {
1210
+ message: error.message,
1211
+ stack: error.stack,
1212
+ });
1179
1213
  return Promise.resolve(null);
1180
1214
  }
1215
+
1181
1216
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
1217
+
1182
1218
  callSession.setIsConference(conference);
1183
1219
  callSession.creationTime = new Date();
1220
+
1184
1221
  this._updateCallSession(callSession);
1185
1222
 
1186
1223
  this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
1187
-
1188
1224
  this.currentSipSession = sipSession;
1189
1225
  this.currentCallSession = callSession;
1190
-
1191
1226
  this.eventEmitter.emit(ON_CALL_OUTGOING, callSession);
1192
1227
 
1193
1228
  // If an invite promise exists, catch exceptions on it to trigger error like OverConstraintsError.
1229
+ // @ts-ignore
1194
1230
  if (sipSession.invitePromise) {
1231
+ // @ts-ignore
1195
1232
  sipSession.invitePromise.catch(error => {
1196
1233
  this.eventEmitter.emit(ON_CALL_ERROR, error, callSession);
1197
1234
  });
@@ -1200,21 +1237,23 @@ export default class WebRTCPhone extends Emitter implements Phone {
1200
1237
  return Promise.resolve(callSession);
1201
1238
  }
1202
1239
 
1203
- transfer(callSession: ?CallSession, target: string): void {
1240
+ transfer(callSession: CallSession | null | undefined, target: string): void {
1204
1241
  const sipSession = this.findSipSession(callSession);
1242
+
1205
1243
  if (!sipSession) {
1206
1244
  return;
1207
1245
  }
1208
1246
 
1209
- logger.info('WebRTC transfer', { sipId: sipSession.id, target });
1210
-
1247
+ logger.info('WebRTC transfer', {
1248
+ sipId: sipSession.id,
1249
+ target,
1250
+ });
1211
1251
  this.client.transfer(sipSession, target);
1212
1252
  }
1213
1253
 
1214
1254
  async indirectTransfer(source: CallSession, destination: CallSession): Promise<boolean> {
1215
1255
  const sipSession = this.client.getSipSession(source.sipCallId);
1216
1256
  const sipSessionTarget = this.client.getSipSession(destination.sipCallId);
1217
-
1218
1257
  logger.info('WebRTC indirect transfer', {
1219
1258
  sipId: sipSession ? sipSession.id : null,
1220
1259
  target: sipSessionTarget ? sipSessionTarget.id : null,
@@ -1236,7 +1275,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1236
1275
  },
1237
1276
  };
1238
1277
 
1239
- return sipSessionTarget.refer(sipSession, options);
1278
+ return sipSessionTarget.refer((sipSession as Session), options);
1240
1279
  });
1241
1280
  }
1242
1281
 
@@ -1246,60 +1285,63 @@ export default class WebRTCPhone extends Emitter implements Phone {
1246
1285
 
1247
1286
  confirmCTIIndirectTransfer() {}
1248
1287
 
1249
- async hangup(callSession: ?CallSession): Promise<boolean> {
1288
+ async hangup(callSession?: CallSession | null): Promise<boolean> {
1250
1289
  const sipSession = this.findSipSession(callSession);
1290
+
1251
1291
  if (!sipSession) {
1252
- console.error('Call is unknown to the WebRTC phone', callSession ? callSession.sipCallId : null,
1253
- callSession ? callSession.callId : null);
1292
+ console.error('Call is unknown to the WebRTC phone', callSession ? callSession.sipCallId : null, callSession ? callSession.callId : null);
1254
1293
  return false;
1255
1294
  }
1256
-
1257
- logger.info('WebRTC hangup', { sipId: sipSession.id });
1258
-
1259
1295
  const sipSessionId = this.getSipSessionId(sipSession);
1260
1296
 
1297
+ logger.info('WebRTC hangup', {
1298
+ sipId: sipSession.id,
1299
+ sipSessionId,
1300
+ });
1261
1301
  await this.client.hangup(sipSession);
1302
+
1262
1303
  if (callSession) {
1263
1304
  // Removal of `this.callSessions` will be done in `_onCallTerminated`.
1264
1305
  this.endCurrentCall(callSession);
1265
1306
  } else if (sipSessionId) {
1266
- if (callSession) {
1267
- delete this.callSessions[callSession.getId()];
1268
- }
1307
+ delete this.callSessions[sipSessionId];
1269
1308
  }
1270
1309
 
1271
1310
  this.shouldSendReinvite = false;
1272
1311
  return true;
1273
1312
  }
1274
1313
 
1275
- async getStats(callSession: ?CallSession): Promise<?Object> {
1314
+ async getStats(callSession: CallSession | null | undefined): Promise<RTCStatsReport | null | undefined> {
1276
1315
  const sipSession = this.findSipSession(callSession);
1277
-
1278
1316
  return sipSession ? this.client.getStats(sipSession) : null;
1279
1317
  }
1280
1318
 
1281
- startNetworkMonitoring(callSession: ?CallSession, interval: number = 1000) {
1319
+ startNetworkMonitoring(callSession: CallSession | null | undefined, interval = 1000) {
1282
1320
  const sipSession = this.findSipSession(callSession);
1283
-
1284
1321
  return sipSession ? this.client.startNetworkMonitoring(sipSession, interval) : null;
1285
1322
  }
1286
1323
 
1287
- stopNetworkMonitoring(callSession: ?CallSession) {
1324
+ stopNetworkMonitoring(callSession: CallSession | null | undefined) {
1288
1325
  const sipSession = this.findSipSession(callSession);
1289
-
1290
1326
  return sipSession ? this.client.stopNetworkMonitoring(sipSession) : null;
1291
1327
  }
1292
1328
 
1293
- forceCancel(sipSession: Session): void {
1329
+ forceCancel(sipSession: Inviter): void {
1330
+ // @ts-ignore
1294
1331
  if (!sipSession || !sipSession.outgoingInviteRequest) {
1295
1332
  return;
1296
1333
  }
1297
- sipSession.outgoingInviteRequest.cancel();
1334
+
1335
+ try {
1336
+ // @ts-ignore
1337
+ sipSession.outgoingInviteRequest.cancel();
1338
+ } catch (e) {
1339
+ logger.info('force cancel, error', e);
1340
+ }
1298
1341
  }
1299
1342
 
1300
1343
  endCurrentCall(callSession: CallSession): void {
1301
1344
  const isCurrent = this.isCurrentCallSipSession(callSession);
1302
-
1303
1345
  logger.info('Ending current call', {
1304
1346
  id: callSession ? callSession.getId() : null,
1305
1347
  isCurrent,
@@ -1315,7 +1357,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1315
1357
 
1316
1358
  onConnectionMade(): void {}
1317
1359
 
1318
- isConference(callSession: ?CallSession): boolean {
1360
+ isConference(callSession: CallSession | null | undefined): boolean {
1319
1361
  if (!callSession) {
1320
1362
  return false;
1321
1363
  }
@@ -1323,23 +1365,19 @@ export default class WebRTCPhone extends Emitter implements Phone {
1323
1365
  return this.client && this.client.isConference(callSession.sipCallId);
1324
1366
  }
1325
1367
 
1326
- async close(force: boolean = false): Promise<void> {
1368
+ async close(force = false): Promise<void> {
1327
1369
  logger.info('WebRTC close');
1328
1370
 
1329
1371
  try {
1330
- await Promise.race([
1331
- this.unregister(),
1332
- new Promise((resolve, reject) => setTimeout(() => reject(new Error('Unregister, timed out')), 3000)),
1333
- ]);
1334
- } catch (e) {
1372
+ await Promise.race([this.unregister(), new Promise((resolve, reject) => setTimeout(() => reject(new Error('Unregister, timed out')), 3000))]);
1373
+ } catch (e: any) {
1335
1374
  logger.error('WebRTC close, unregister error', e);
1336
1375
  }
1337
1376
 
1338
1377
  this.client.close(force);
1339
1378
  this.unbind();
1340
-
1341
1379
  this.incomingSessions = [];
1342
- this.currentSipSession = null;
1380
+ this.currentSipSession = undefined;
1343
1381
  this.currentCallSession = null;
1344
1382
  this.shouldSendReinvite = false;
1345
1383
  this.rejectedSessions = {};
@@ -1359,7 +1397,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1359
1397
  this.ringingEnabled = false;
1360
1398
  }
1361
1399
 
1362
- getCurrentCallSession(): ?CallSession {
1400
+ getCurrentCallSession(): CallSession | null | undefined {
1363
1401
  if (!this.currentSipSession) {
1364
1402
  return null;
1365
1403
  }
@@ -1371,13 +1409,14 @@ export default class WebRTCPhone extends Emitter implements Phone {
1371
1409
  return this.incomingSessions.length > 0;
1372
1410
  }
1373
1411
 
1374
- getIncomingCallSession(): ?CallSession {
1412
+ getIncomingCallSession(): CallSession | null | undefined {
1375
1413
  if (!this.hasIncomingCallSession()) {
1376
1414
  return null;
1377
1415
  }
1378
1416
 
1379
1417
  const sessionId = this.incomingSessions[0];
1380
1418
  const sipSession = this.client.getSipSession(sessionId);
1419
+
1381
1420
  if (!sipSession) {
1382
1421
  return null;
1383
1422
  }
@@ -1385,41 +1424,42 @@ export default class WebRTCPhone extends Emitter implements Phone {
1385
1424
  return this._createCallSession(sipSession);
1386
1425
  }
1387
1426
 
1388
- sendMessage(sipSession: Session = null, body: string, contentType: string = 'text/plain') {
1427
+ // eslint-disable-next-line @typescript-eslint/default-param-last
1428
+ sendMessage(sipSession: Invitation | Inviter | null = null, body: string, contentType = 'text/plain'): void {
1389
1429
  return this.client.sendMessage(sipSession, body, contentType);
1390
1430
  }
1391
1431
 
1392
- getLocalStream(callSession: CallSession): ?MediaStream {
1432
+ getLocalStream(callSession: CallSession): MediaStream | null | undefined {
1393
1433
  return callSession ? this.client.getLocalStream(callSession.sipCallId) : null;
1394
1434
  }
1395
1435
 
1396
- getLocalVideoStream(callSession: CallSession): ?MediaStream {
1436
+ getLocalVideoStream(callSession: CallSession): MediaStream | null | undefined {
1397
1437
  return callSession ? this.client.getLocalVideoStream(callSession.sipCallId) : null;
1398
1438
  }
1399
1439
 
1400
1440
  // Deprecated
1401
- getLocalMediaStream(callSession: CallSession) {
1441
+ getLocalMediaStream(callSession: CallSession): MediaStream | null | undefined {
1402
1442
  logger.warn('WebRTCPhone.getLocalMediaStream is deprecated, use WebRTCPhone.getLocalStream instead');
1403
1443
  return this.getLocalStream(callSession);
1404
1444
  }
1405
1445
 
1406
- hasLocalVideo(callSession: CallSession) {
1407
- return callSession ? this.client.hasLocalVideo(callSession.sipCallId) : null;
1446
+ hasLocalVideo(callSession: CallSession): boolean {
1447
+ return callSession ? this.client.hasLocalVideo(callSession.sipCallId) : false;
1408
1448
  }
1409
1449
 
1410
- hasALocalVideoTrack(callSession: CallSession) {
1411
- return callSession ? this.client.hasALocalVideoTrack(callSession.sipCallId) : null;
1450
+ hasALocalVideoTrack(callSession: CallSession): boolean {
1451
+ return callSession ? this.client.hasALocalVideoTrack(callSession.sipCallId) : false;
1412
1452
  }
1413
1453
 
1414
- getRemoteStream(callSession: CallSession): ?MediaStream {
1454
+ getRemoteStream(callSession: CallSession): MediaStream | null | undefined {
1415
1455
  return callSession ? this.client.getRemoteStream(callSession.sipCallId) : null;
1416
1456
  }
1417
1457
 
1418
- getRemoteVideoStream(callSession: CallSession): ?MediaStream {
1458
+ getRemoteVideoStream(callSession: CallSession): MediaStream | null | undefined {
1419
1459
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
1420
1460
  }
1421
1461
 
1422
- getRemoteVideoStreamFromPc(callSession: CallSession): ?MediaStream {
1462
+ getRemoteVideoStreamFromPc(callSession: CallSession): MediaStream | null | undefined {
1423
1463
  return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
1424
1464
  }
1425
1465
 
@@ -1427,24 +1467,29 @@ export default class WebRTCPhone extends Emitter implements Phone {
1427
1467
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
1428
1468
  }
1429
1469
 
1430
- setMediaConstraints(media: MediaStreamConstraints) {
1470
+ setMediaConstraints(media: MediaStreamConstraints): void {
1431
1471
  this.client.setMediaConstraints(media);
1432
1472
  }
1433
1473
 
1434
- isVideoRemotelyHeld(callSession: CallSession) {
1435
- return callSession ? this.client.isVideoRemotelyHeld(callSession.sipCallId) : null;
1474
+ isVideoRemotelyHeld(callSession: CallSession): boolean {
1475
+ return callSession ? this.client.isVideoRemotelyHeld(callSession.sipCallId) : false;
1436
1476
  }
1437
1477
 
1438
1478
  bindClientEvents() {
1439
1479
  this.client.unbind();
1440
-
1441
- this.client.on(this.client.INVITE, (sipSession: Session, wantsToDoVideo: boolean) => {
1480
+ this.client.on(this.client.INVITE, (sipSession: Invitation | Inviter, wantsToDoVideo: boolean) => {
1442
1481
  const autoAnswer = sipSession.request.getHeader('Answer-Mode') === 'Auto';
1443
1482
  const withVideo = this.allowVideo ? wantsToDoVideo : false;
1444
- logger.info('WebRTC invite received', { sipId: sipSession.id, withVideo, autoAnswer });
1483
+ logger.info('WebRTC invite received', {
1484
+ sipId: sipSession.id,
1485
+ withVideo,
1486
+ autoAnswer,
1487
+ });
1445
1488
 
1446
1489
  const callSession = this._createIncomingCallSession(sipSession, withVideo, null, autoAnswer);
1490
+
1447
1491
  this.incomingSessions.push(callSession.getId());
1492
+
1448
1493
  this._bindEvents(sipSession);
1449
1494
 
1450
1495
  this.client.storeSipSession(sipSession);
@@ -1454,18 +1499,15 @@ export default class WebRTCPhone extends Emitter implements Phone {
1454
1499
  this.eventEmitter.emit(ON_PLAY_RING_SOUND, this.audioRingDeviceId, this.audioRingVolume, callSession);
1455
1500
  }
1456
1501
  } else {
1457
- this.eventEmitter.emit(ON_PLAY_INBOUND_CALL_SIGNAL_SOUND,
1458
- this.audioOutputDeviceId,
1459
- this.audioOutputVolume,
1460
- callSession);
1502
+ this.eventEmitter.emit(ON_PLAY_INBOUND_CALL_SIGNAL_SOUND, this.audioOutputDeviceId, this.audioOutputVolume, callSession);
1461
1503
  }
1462
1504
 
1463
1505
  callSession.creationTime = new Date();
1506
+
1464
1507
  this._updateCallSession(callSession);
1465
1508
 
1466
1509
  this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
1467
1510
  });
1468
-
1469
1511
  this.client.on(this.client.ON_REINVITE, (...args) => {
1470
1512
  logger.info('WebRTC on reinvite', {
1471
1513
  sessionId: args[0].id,
@@ -1473,9 +1515,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1473
1515
  updatedCalleeName: args[2],
1474
1516
  updatedNumber: args[3],
1475
1517
  });
1476
-
1477
1518
  const sipSession = args[0];
1478
-
1479
1519
  // Give some time for the stream to be mounted.
1480
1520
  // if `_createCallSession` is called too soon `hasVideo` will return false because the stream doesn't exists yet
1481
1521
  setTimeout(() => {
@@ -1485,15 +1525,18 @@ export default class WebRTCPhone extends Emitter implements Phone {
1485
1525
  this.eventEmitter.emit.apply(this.eventEmitter, [this.client.ON_REINVITE, ...args]);
1486
1526
  }, 2000);
1487
1527
  });
1488
-
1489
- this.client.on(this.client.ACCEPTED, (sipSession: Session) => {
1528
+ this.client.on(this.client.ACCEPTED, (sipSession: Inviter | Invitation) => {
1490
1529
  const sessionId = this.getSipSessionId(sipSession);
1491
- const hasSession = sessionId in this.callSessions;
1492
-
1493
- logger.info('WebRTC call accepted', { sipId: sessionId, hasSession });
1530
+ const hasSession = (sessionId in this.callSessions);
1531
+ logger.info('WebRTC call accepted', {
1532
+ sipId: sessionId,
1533
+ hasSession,
1534
+ });
1494
1535
 
1495
1536
  if (!hasSession) {
1496
- logger.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
1537
+ logger.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', {
1538
+ sessionId,
1539
+ });
1497
1540
  return;
1498
1541
  }
1499
1542
 
@@ -1504,36 +1547,38 @@ export default class WebRTCPhone extends Emitter implements Phone {
1504
1547
  }
1505
1548
  });
1506
1549
  this.client.on('ended', () => {});
1507
-
1508
1550
  this.client.on(this.client.ON_ERROR, e => {
1509
1551
  logger.error('WebRTC error', e);
1510
1552
  this.eventEmitter.emit(ON_CALL_ERROR, e);
1511
1553
  });
1512
-
1513
1554
  this.client.on(this.client.REJECTED, session => {
1514
1555
  logger.info('WebRTC call rejected', session.id);
1556
+
1515
1557
  const callSession = this._createCallSession(session);
1558
+
1559
+ // `_createCallSession` add the CallSession in `this.callSessions`.
1560
+ // so we have to remove it or `callCount` will always return 1 even if the call was rejected
1561
+ delete this.callSessions[this.getSipSessionId(session)];
1562
+
1516
1563
  callSession.endTime = new Date();
1517
- this._updateCallSession(callSession);
1518
1564
 
1519
1565
  this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
1520
1566
  });
1521
-
1522
1567
  this.client.on(this.client.UNREGISTERED, () => {
1523
1568
  logger.info('WebRTC unregistered');
1524
1569
  this.eventEmitter.emit(ON_UNREGISTERED);
1525
1570
  });
1526
-
1527
1571
  this.client.on(this.client.ON_DISCONNECTED, () => {
1528
1572
  logger.info('WebRTC disconnected');
1529
1573
  this.eventEmitter.emit(ON_DISCONNECTED);
1530
1574
  });
1531
1575
  this.client.on(this.client.ON_EARLY_MEDIA, session => {
1532
1576
  logger.info('WebRTC early media');
1577
+
1533
1578
  const callSession = this._createCallSession(session);
1579
+
1534
1580
  this.eventEmitter.emit(ON_EARLY_MEDIA, callSession);
1535
1581
  });
1536
-
1537
1582
  this.client.on(this.client.REGISTERED, () => {
1538
1583
  logger.info('WebRTC registered', {
1539
1584
  shouldSendReinvite: this.shouldSendReinvite,
@@ -1545,31 +1590,30 @@ export default class WebRTCPhone extends Emitter implements Phone {
1545
1590
 
1546
1591
  // If the phone registered with a current callSession (eg: when switching network):
1547
1592
  // send a reinvite to renegociate ICE with new IP
1548
- if (this.shouldSendReinvite && this.currentSipSession
1549
- && this.currentSipSession.state === SessionState.Established) {
1593
+ if (this.shouldSendReinvite && this.currentSipSession && this.currentSipSession.state === SessionState.Established) {
1550
1594
  this.shouldSendReinvite = false;
1551
- const pc = this.currentSipSession.sessionDescriptionHandler.peerConnection;
1595
+ // @ts-ignore
1596
+ const pc = this.currentSipSession?.sessionDescriptionHandler?.peerConnection;
1552
1597
  const isConference = pc ? pc.sfu : false;
1553
1598
  const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
1554
1599
 
1555
1600
  try {
1556
1601
  // Send reinvite with iceRestart
1557
1602
  this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
1558
- } catch (e) {
1559
- logger.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
1603
+ } catch (e: any) {
1604
+ logger.error('WebRTC reinvite after register, error', {
1605
+ message: e.message,
1606
+ stack: e.stack,
1607
+ });
1560
1608
  }
1561
1609
  }
1562
1610
  });
1563
-
1564
1611
  this.client.on(this.client.CONNECTED, () => {
1565
1612
  logger.info('WebRTC client connected');
1566
-
1567
1613
  this.stopHeartbeat();
1568
1614
  });
1569
-
1570
1615
  this.client.on(this.client.DISCONNECTED, () => {
1571
1616
  logger.info('WebRTC client disconnected');
1572
-
1573
1617
  this.eventEmitter.emit(ON_UNREGISTERED);
1574
1618
 
1575
1619
  // Do not trigger heartbeat if already running
@@ -1580,71 +1624,62 @@ export default class WebRTCPhone extends Emitter implements Phone {
1580
1624
  // Tell to send reinvite when reconnecting
1581
1625
  this.shouldSendReinvite = true;
1582
1626
  });
1583
-
1584
1627
  this.client.on(this.client.ON_TRACK, (session, event) => {
1585
1628
  this.eventEmitter.emit(ON_TRACK, session, event);
1586
1629
  });
1587
-
1588
1630
  this.client.on('onVideoInputChange', stream => {
1589
1631
  this.eventEmitter.emit(ON_VIDEO_INPUT_CHANGE, stream);
1590
1632
  });
1591
-
1592
1633
  this.client.on(this.client.MESSAGE, (message: Message) => {
1593
1634
  this._onMessage(message);
1635
+
1594
1636
  this.eventEmitter.emit(ON_MESSAGE, message);
1595
1637
  });
1596
-
1597
1638
  this.client.on(this.client.ON_NETWORK_STATS, (session, stats, previousStats) => {
1598
1639
  const callSession = this.getCallSession(this.getSipSessionId(session));
1599
-
1600
1640
  this.eventEmitter.emit(ON_NETWORK_STATS, callSession, stats, previousStats);
1601
1641
  });
1602
-
1603
1642
  // Used when upgrading directly in screenshare mode
1604
- this.client.on(this.client.ON_SCREEN_SHARING_REINVITE, (sipSession: Session, response: any, desktop: boolean) => {
1643
+ this.client.on(this.client.ON_SCREEN_SHARING_REINVITE, (sipSession: Inviter | Invitation, response: any, desktop: boolean) => {
1605
1644
  const sipSessionId = this.getSipSessionId(sipSession);
1606
1645
  const localStream = this.client.getLocalStream(sipSessionId);
1607
1646
  const callSession = this.callSessions[sipSessionId];
1608
-
1609
1647
  logger.info('Updrading directly in screensharing mode', {
1610
1648
  sipSessionId,
1611
- tracks: localStream ? localStream.getTracks() : null,
1649
+ tracks: localStream?.getTracks() || null,
1612
1650
  });
1613
1651
 
1614
- this._onScreenSharing(localStream, sipSession, callSession, false, desktop);
1652
+ this._onScreenSharing(localStream as MediaStream, sipSession, callSession, false, desktop);
1615
1653
  });
1616
1654
  }
1617
1655
 
1618
1656
  // Find a corresponding sipSession from a CallSession
1619
- findSipSession(callSession: ?CallSession): ?Session {
1657
+ findSipSession(callSession: CallSession | null | undefined): Invitation | Inviter | null | undefined {
1620
1658
  const keys = this.client.getSipSessionIds();
1621
1659
  const keyIndex = keys.findIndex(sessionId => callSession && callSession.isId(sessionId));
1622
1660
 
1623
1661
  if (keyIndex === -1) {
1624
- const currentSipSessionId = this.currentSipSession
1625
- ? this.getSipSessionId(this.currentSipSession)
1626
- : this.client.getSipSessionIds()[0];
1662
+ const currentSipSessionId = this.currentSipSession ? this.getSipSessionId(this.currentSipSession) : this.client.getSipSessionIds()[0];
1627
1663
  return currentSipSessionId ? this.client.getSipSession(currentSipSessionId) : null;
1628
1664
  }
1629
1665
 
1630
1666
  return this.client.getSipSession(keys[keyIndex]);
1631
1667
  }
1632
1668
 
1633
- getCallSession(sipSessionId: string): ?CallSession {
1669
+ getCallSession(sipSessionId: string): CallSession | null | undefined {
1634
1670
  return this.callSessions[sipSessionId];
1635
1671
  }
1636
1672
 
1637
- getSipSessionId(sipSession: Session) {
1673
+ getSipSessionId(sipSession: Inviter | Invitation): string {
1638
1674
  return this.client.getSipSessionId(sipSession);
1639
1675
  }
1640
1676
 
1641
- getSipSessionIdFromCallSession(callSession: CallSession) {
1677
+ getSipSessionIdFromCallSession(callSession: CallSession): string | null {
1642
1678
  const sipSession = this.findSipSession(callSession);
1643
-
1644
1679
  return sipSession ? this.getSipSessionId(sipSession) : null;
1645
1680
  }
1646
1681
 
1647
- _updateCallSession(callSession: CallSession) {
1682
+ _updateCallSession(callSession: CallSession): void {
1648
1683
  const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
1649
1684
 
1650
1685
  if (sipSessionId) {
@@ -1652,7 +1687,8 @@ export default class WebRTCPhone extends Emitter implements Phone {
1652
1687
  }
1653
1688
  }
1654
1689
 
1655
- _onMessage(message: Message) {
1690
+ _onMessage(message: Message): void {
1691
+ // @ts-ignore
1656
1692
  if (!message || message.method !== 'MESSAGE') {
1657
1693
  return;
1658
1694
  }
@@ -1660,19 +1696,24 @@ export default class WebRTCPhone extends Emitter implements Phone {
1660
1696
  let body;
1661
1697
 
1662
1698
  try {
1699
+ // @ts-ignore
1663
1700
  body = JSON.parse(message.body);
1664
- } catch (e) {
1701
+ } catch (e: any) {
1665
1702
  return;
1666
1703
  }
1667
1704
 
1668
- const { type, content } = body;
1705
+ const {
1706
+ type,
1707
+ content,
1708
+ } = body;
1669
1709
 
1670
1710
  switch (type) {
1671
1711
  case MESSAGE_TYPE_CHAT:
1672
1712
  this.eventEmitter.emit(ON_CHAT, content);
1673
1713
  break;
1674
1714
 
1675
- case MESSAGE_TYPE_SIGNAL: {
1715
+ case MESSAGE_TYPE_SIGNAL:
1716
+ {
1676
1717
  this.eventEmitter.emit(ON_SIGNAL, content);
1677
1718
  break;
1678
1719
  }
@@ -1681,12 +1722,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1681
1722
  }
1682
1723
  }
1683
1724
 
1684
- _createIncomingCallSession(
1685
- sipSession: Session,
1686
- cameraEnabled: boolean,
1687
- fromSession?: ?CallSession,
1688
- autoAnswer: boolean = false,
1689
- ): CallSession {
1725
+ _createIncomingCallSession(sipSession: Invitation | Inviter, cameraEnabled: boolean, fromSession?: CallSession | null | undefined, autoAnswer = false): CallSession {
1690
1726
  return this._createCallSession(sipSession, fromSession, {
1691
1727
  incoming: true,
1692
1728
  ringing: true,
@@ -1695,82 +1731,80 @@ export default class WebRTCPhone extends Emitter implements Phone {
1695
1731
  });
1696
1732
  }
1697
1733
 
1698
- _createOutgoingCallSession(
1699
- sipSession: Session,
1700
- cameraEnabled: boolean,
1701
- fromSession?: CallSession,
1702
- ): CallSession {
1703
- return this._createCallSession(sipSession, fromSession, { incoming: false, ringing: true, cameraEnabled });
1734
+ _createOutgoingCallSession(sipSession: Invitation | Inviter, cameraEnabled: boolean, fromSession?: CallSession): CallSession {
1735
+ return this._createCallSession(sipSession, fromSession, {
1736
+ incoming: false,
1737
+ ringing: true,
1738
+ cameraEnabled,
1739
+ });
1704
1740
  }
1705
1741
 
1706
- _createAcceptedCallSession(
1707
- sipSession: Session,
1708
- cameraEnabled?: boolean,
1709
- fromSession?: CallSession,
1710
- ): CallSession {
1742
+ _createAcceptedCallSession(sipSession: Invitation | Inviter, cameraEnabled?: boolean, fromSession?: CallSession): CallSession {
1711
1743
  return this._createCallSession(sipSession, fromSession, {
1712
1744
  cameraEnabled: cameraEnabled !== undefined ? cameraEnabled : false,
1713
1745
  });
1714
1746
  }
1715
1747
 
1716
- _createMutedCallSession(sipSession: Session, fromSession?: CallSession): CallSession {
1748
+ _createMutedCallSession(sipSession: Invitation | Inviter, fromSession?: CallSession): CallSession {
1717
1749
  return this._createCallSession(sipSession, fromSession, {
1718
1750
  muted: true,
1719
1751
  });
1720
1752
  }
1721
1753
 
1722
- _createUnmutedCallSession(sipSession: Session, fromSession?: CallSession): CallSession {
1754
+ _createUnmutedCallSession(sipSession: Invitation | Inviter, fromSession?: CallSession): CallSession {
1723
1755
  return this._createCallSession(sipSession, fromSession, {
1724
1756
  muted: false,
1725
1757
  });
1726
1758
  }
1727
1759
 
1728
- _createCameraResumedCallSession(sipSession: Session, fromSession?: CallSession): CallSession {
1760
+ _createCameraResumedCallSession(sipSession: Invitation | Inviter, fromSession?: CallSession): CallSession {
1729
1761
  return this._createCallSession(sipSession, fromSession, {
1730
1762
  videoMuted: false,
1731
1763
  });
1732
1764
  }
1733
1765
 
1734
- _createCameraDisabledCallSession(sipSession: Session, fromSession?: CallSession): CallSession {
1766
+ _createCameraDisabledCallSession(sipSession: Invitation | Inviter, fromSession?: CallSession): CallSession {
1735
1767
  return this._createCallSession(sipSession, fromSession, {
1736
1768
  videoMuted: true,
1737
1769
  });
1738
1770
  }
1739
1771
 
1740
- _createCallSession(sipSession: Session, fromSession?: ?CallSession, extra: Object = {}): CallSession {
1772
+ _createCallSession(sipSession: Invitation | Inviter, fromSession?: CallSession | null | undefined, extra: Record<string, any> = {}): CallSession {
1741
1773
  // eslint-disable-next-line
1742
1774
  const identity = sipSession ? sipSession.remoteIdentity || sipSession.assertedIdentity : null;
1775
+ // @ts-ignore
1743
1776
  const number = identity ? identity.uri._normal.user : null;
1744
- const { state } = sipSession || {};
1777
+ const {
1778
+ state,
1779
+ } = sipSession || {};
1745
1780
  const sessionId = this.getSipSessionId(sipSession);
1746
1781
  fromSession = fromSession || this.callSessions[sessionId];
1747
-
1748
1782
  const callSession = new CallSession({
1749
1783
  callId: fromSession && fromSession.callId,
1750
1784
  sipCallId: sessionId,
1751
1785
  sipStatus: state,
1752
1786
  displayName: identity ? identity.displayName || number : number,
1787
+ // @ts-ignore: @HEADSUP: startTime should be a number, not a date
1753
1788
  startTime: fromSession ? fromSession.startTime : new Date(),
1754
1789
  creationTime: fromSession ? fromSession.creationTime : null,
1755
1790
  answerTime: fromSession ? fromSession.answerTime : null,
1756
1791
  endTime: fromSession ? fromSession.endTime : null,
1757
1792
  answered: state === SessionState.Established,
1758
1793
  paused: this.client.isCallHeld(sipSession),
1759
- isCaller: fromSession ? fromSession.isCaller : ('incoming' in extra ? !extra.incoming : false),
1794
+ isCaller: fromSession ? fromSession.isCaller : 'incoming' in extra ? !extra.incoming : false,
1760
1795
  cameraEnabled: fromSession ? fromSession.isCameraEnabled() : this.client.hasVideo(sessionId),
1761
1796
  number,
1762
1797
  ringing: false,
1763
1798
  muted: fromSession ? fromSession.isMuted() : this.client.isAudioMuted(sipSession),
1764
1799
  videoMuted: fromSession ? fromSession.isVideoMuted() : false,
1765
1800
  recording: fromSession ? fromSession.isRecording() : false,
1766
- recordingPaused: false, // @TODO
1801
+ recordingPaused: false,
1767
1802
  sipSession,
1768
1803
  conference: !!fromSession && fromSession.isConference(),
1769
1804
  ...extra,
1770
1805
  });
1771
-
1772
- this.callSessions[callSession.getId()] = callSession;
1773
-
1806
+ this.callSessions[sessionId] = callSession;
1774
1807
  return callSession;
1775
1808
  }
1809
+
1776
1810
  }