@wazo/sdk 0.43.15 → 0.44.1

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 (899) hide show
  1. package/dist/index.js +10630 -0
  2. package/dist/index.mjs +10541 -0
  3. package/{lib → dist}/types/domain/Contact.d.ts +3 -1
  4. package/dist/types/domain/Contact.d.ts.map +1 -0
  5. package/{lib → dist}/types/index.d.ts +13 -13
  6. package/dist/types/index.d.ts.map +1 -0
  7. package/dist/wazo-sdk.js +69378 -43
  8. package/dist/wazo-sdk.js.LICENSE.txt +684 -0
  9. package/package.json +11 -22
  10. package/esm/__tests__/api-client.test.js +0 -281
  11. package/esm/__tests__/web-rtc-client.test.js +0 -192
  12. package/esm/api/agentd.js +0 -23
  13. package/esm/api/amid.js +0 -17
  14. package/esm/api/application.js +0 -63
  15. package/esm/api/auth.js +0 -198
  16. package/esm/api/call-logd.js +0 -24
  17. package/esm/api/calld.js +0 -120
  18. package/esm/api/chatd.js +0 -50
  19. package/esm/api/confd.js +0 -77
  20. package/esm/api/ctid-ng.js +0 -96
  21. package/esm/api/dird.js +0 -110
  22. package/esm/api/webhookd.js +0 -7
  23. package/esm/api-client.js +0 -41
  24. package/esm/base-api-client.js +0 -125
  25. package/esm/checker/Checker.js +0 -54
  26. package/esm/checker/checks/aor.js +0 -28
  27. package/esm/checker/checks/api.js +0 -76
  28. package/esm/checker/checks/ice-ipv4.js +0 -69
  29. package/esm/checker/checks/index.js +0 -8
  30. package/esm/checker/checks/symmetric-nat.js +0 -59
  31. package/esm/checker/checks/wazo-websocket.js +0 -38
  32. package/esm/checker/checks/webrtc-transport.js +0 -35
  33. package/esm/checker/checks/webrtc.js +0 -40
  34. package/esm/constants.js +0 -11
  35. package/esm/domain/AdHocAPIConference.js +0 -102
  36. package/esm/domain/Agent.js +0 -30
  37. package/esm/domain/BadResponse.js +0 -21
  38. package/esm/domain/Call.js +0 -123
  39. package/esm/domain/CallLog.js +0 -157
  40. package/esm/domain/CallSession.js +0 -253
  41. package/esm/domain/CallerID.js +0 -24
  42. package/esm/domain/ChatMessage.js +0 -55
  43. package/esm/domain/ChatRoom.js +0 -30
  44. package/esm/domain/Contact.js +0 -464
  45. package/esm/domain/Country.js +0 -19
  46. package/esm/domain/Device/DebugDevice.js +0 -32
  47. package/esm/domain/Device/Device.js +0 -1
  48. package/esm/domain/DirectorySource.js +0 -1
  49. package/esm/domain/ExternalApp.js +0 -24
  50. package/esm/domain/Features.js +0 -77
  51. package/esm/domain/ForwardOption.js +0 -37
  52. package/esm/domain/Incall.js +0 -28
  53. package/esm/domain/IndirectTransfer.js +0 -40
  54. package/esm/domain/Line.js +0 -39
  55. package/esm/domain/Meeting.js +0 -61
  56. package/esm/domain/MeetingAuthorization.js +0 -46
  57. package/esm/domain/MeetingStatus.js +0 -14
  58. package/esm/domain/NotificationOptions.js +0 -45
  59. package/esm/domain/Phone/CTIPhone.js +0 -288
  60. package/esm/domain/Phone/Phone.js +0 -1
  61. package/esm/domain/Phone/WebRTCPhone.js +0 -1482
  62. package/esm/domain/Profile.js +0 -128
  63. package/esm/domain/Recording.js +0 -30
  64. package/esm/domain/Relocation.js +0 -20
  65. package/esm/domain/Room.js +0 -97
  66. package/esm/domain/SFUNotAvailableError.js +0 -6
  67. package/esm/domain/ServerError.js +0 -9
  68. package/esm/domain/Session.js +0 -174
  69. package/esm/domain/SipLine.js +0 -82
  70. package/esm/domain/Subscription.js +0 -42
  71. package/esm/domain/SwitchboardCall.js +0 -56
  72. package/esm/domain/Voicemail.js +0 -76
  73. package/esm/domain/__tests__/Agent.test.js +0 -37
  74. package/esm/domain/__tests__/Call.test.js +0 -25
  75. package/esm/domain/__tests__/CallLog.test.js +0 -181
  76. package/esm/domain/__tests__/CallSession.test.js +0 -78
  77. package/esm/domain/__tests__/Contact.test.js +0 -393
  78. package/esm/domain/__tests__/IndirectTransfer.test.js +0 -67
  79. package/esm/domain/__tests__/Line.test.js +0 -52
  80. package/esm/domain/__tests__/Meeting.test.js +0 -77
  81. package/esm/domain/__tests__/MeetingAuthorization.test.js +0 -49
  82. package/esm/domain/__tests__/Profile.test.js +0 -169
  83. package/esm/domain/__tests__/Room.test.js +0 -206
  84. package/esm/domain/__tests__/Session.test.js +0 -382
  85. package/esm/domain/__tests__/SipLine.test.js +0 -27
  86. package/esm/domain/__tests__/Voicemail.test.js +0 -90
  87. package/esm/domain/types.js +0 -2
  88. package/esm/index.js +0 -51
  89. package/esm/lib/WazoSessionDescriptionHandler.js +0 -429
  90. package/esm/pubkey.js +0 -10
  91. package/esm/service/CallApi.js +0 -61
  92. package/esm/service/IssueReporter.js +0 -331
  93. package/esm/service/__tests__/IssueReporter.test.js +0 -112
  94. package/esm/service/__tests__/getApiclient.test.js +0 -37
  95. package/esm/service/getApiClient.js +0 -94
  96. package/esm/simple/Auth.js +0 -384
  97. package/esm/simple/Configuration.js +0 -13
  98. package/esm/simple/Directory.js +0 -11
  99. package/esm/simple/Phone.js +0 -389
  100. package/esm/simple/Websocket.js +0 -81
  101. package/esm/simple/__tests__/Auth.test.js +0 -144
  102. package/esm/simple/index.js +0 -137
  103. package/esm/simple/room/LocalParticipant.js +0 -4
  104. package/esm/simple/room/Participant.js +0 -315
  105. package/esm/simple/room/RemoteParticipant.js +0 -10
  106. package/esm/simple/room/Room.js +0 -714
  107. package/esm/simple/room/SipRoom.js +0 -121
  108. package/esm/simple/room/Stream.js +0 -47
  109. package/esm/simple/room/__tests__/Participant.test.js +0 -71
  110. package/esm/simple/room/__tests__/RemoteParticipant.test.js +0 -12
  111. package/esm/simple/utils.js +0 -10
  112. package/esm/types/WebSocketMessage.js +0 -1
  113. package/esm/types/domain/Contact.d.ts +0 -332
  114. package/esm/types/domain/Contact.d.ts.map +0 -1
  115. package/esm/types/index.d.ts +0 -59
  116. package/esm/types/index.d.ts.map +0 -1
  117. package/esm/utils/Emitter.js +0 -19
  118. package/esm/utils/Heartbeat.js +0 -73
  119. package/esm/utils/PhoneNumberUtil.js +0 -67
  120. package/esm/utils/__tests__/Heartbeat.test.js +0 -65
  121. package/esm/utils/__tests__/PhoneNumberUtil.test.js +0 -70
  122. package/esm/utils/__tests__/api-requester.test.js +0 -166
  123. package/esm/utils/__tests__/array.test.js +0 -18
  124. package/esm/utils/__tests__/compare-version.test.js +0 -10
  125. package/esm/utils/__tests__/object.test.js +0 -76
  126. package/esm/utils/__tests__/sdp.test.js +0 -172
  127. package/esm/utils/__tests__/string.test.js +0 -49
  128. package/esm/utils/api-requester.js +0 -213
  129. package/esm/utils/array.js +0 -9
  130. package/esm/utils/compare-version.js +0 -17
  131. package/esm/utils/isMobile.js +0 -3
  132. package/esm/utils/new-from.js +0 -7
  133. package/esm/utils/object.js +0 -10
  134. package/esm/utils/once.js +0 -15
  135. package/esm/utils/sdp.js +0 -104
  136. package/esm/utils/string.js +0 -12
  137. package/esm/utils/update-from.js +0 -10
  138. package/esm/utils/webrtc.js +0 -37
  139. package/esm/web-rtc-client.js +0 -2200
  140. package/esm/websocket-client.js +0 -385
  141. package/index.js +0 -1
  142. package/lib/__tests__/api-client.test.js +0 -295
  143. package/lib/__tests__/web-rtc-client.test.js +0 -210
  144. package/lib/api/agentd.js +0 -28
  145. package/lib/api/amid.js +0 -28
  146. package/lib/api/application.js +0 -68
  147. package/lib/api/auth.js +0 -210
  148. package/lib/api/call-logd.js +0 -29
  149. package/lib/api/calld.js +0 -134
  150. package/lib/api/chatd.js +0 -68
  151. package/lib/api/confd.js +0 -91
  152. package/lib/api/ctid-ng.js +0 -101
  153. package/lib/api/dird.js +0 -124
  154. package/lib/api/webhookd.js +0 -12
  155. package/lib/api-client.js +0 -37
  156. package/lib/base-api-client.js +0 -133
  157. package/lib/checker/Checker.js +0 -68
  158. package/lib/checker/checks/aor.js +0 -42
  159. package/lib/checker/checks/api.js +0 -90
  160. package/lib/checker/checks/ice-ipv4.js +0 -73
  161. package/lib/checker/checks/index.js +0 -13
  162. package/lib/checker/checks/symmetric-nat.js +0 -61
  163. package/lib/checker/checks/wazo-websocket.js +0 -63
  164. package/lib/checker/checks/webrtc-transport.js +0 -49
  165. package/lib/checker/checks/webrtc.js +0 -54
  166. package/lib/constants.js +0 -14
  167. package/lib/domain/AdHocAPIConference.js +0 -101
  168. package/lib/domain/Agent.js +0 -25
  169. package/lib/domain/BadResponse.js +0 -19
  170. package/lib/domain/Call.js +0 -112
  171. package/lib/domain/CallLog.js +0 -151
  172. package/lib/domain/CallSession.js +0 -224
  173. package/lib/domain/CallerID.js +0 -27
  174. package/lib/domain/ChatMessage.js +0 -53
  175. package/lib/domain/ChatRoom.js +0 -32
  176. package/lib/domain/Contact.js +0 -439
  177. package/lib/domain/Country.js +0 -21
  178. package/lib/domain/Device/DebugDevice.js +0 -35
  179. package/lib/domain/Device/Device.js +0 -2
  180. package/lib/domain/DirectorySource.js +0 -2
  181. package/lib/domain/ExternalApp.js +0 -27
  182. package/lib/domain/Features.js +0 -87
  183. package/lib/domain/ForwardOption.js +0 -41
  184. package/lib/domain/Incall.js +0 -32
  185. package/lib/domain/IndirectTransfer.js +0 -42
  186. package/lib/domain/Line.js +0 -39
  187. package/lib/domain/Meeting.js +0 -55
  188. package/lib/domain/MeetingAuthorization.js +0 -45
  189. package/lib/domain/MeetingStatus.js +0 -15
  190. package/lib/domain/NotificationOptions.js +0 -49
  191. package/lib/domain/Phone/CTIPhone.js +0 -324
  192. package/lib/domain/Phone/Phone.js +0 -2
  193. package/lib/domain/Phone/WebRTCPhone.js +0 -1492
  194. package/lib/domain/Profile.js +0 -138
  195. package/lib/domain/Recording.js +0 -31
  196. package/lib/domain/Relocation.js +0 -18
  197. package/lib/domain/Room.js +0 -81
  198. package/lib/domain/SFUNotAvailableError.js +0 -9
  199. package/lib/domain/ServerError.js +0 -15
  200. package/lib/domain/Session.js +0 -166
  201. package/lib/domain/SipLine.js +0 -76
  202. package/lib/domain/Subscription.js +0 -34
  203. package/lib/domain/SwitchboardCall.js +0 -50
  204. package/lib/domain/Voicemail.js +0 -77
  205. package/lib/domain/__tests__/Agent.test.js +0 -42
  206. package/lib/domain/__tests__/Call.test.js +0 -30
  207. package/lib/domain/__tests__/CallLog.test.js +0 -166
  208. package/lib/domain/__tests__/CallSession.test.js +0 -83
  209. package/lib/domain/__tests__/Contact.test.js +0 -371
  210. package/lib/domain/__tests__/IndirectTransfer.test.js +0 -81
  211. package/lib/domain/__tests__/Line.test.js +0 -57
  212. package/lib/domain/__tests__/Meeting.test.js +0 -82
  213. package/lib/domain/__tests__/MeetingAuthorization.test.js +0 -54
  214. package/lib/domain/__tests__/Profile.test.js +0 -197
  215. package/lib/domain/__tests__/Room.test.js +0 -220
  216. package/lib/domain/__tests__/Session.test.js +0 -378
  217. package/lib/domain/__tests__/SipLine.test.js +0 -32
  218. package/lib/domain/__tests__/Voicemail.test.js +0 -95
  219. package/lib/domain/types.js +0 -38
  220. package/lib/index.js +0 -127
  221. package/lib/lib/WazoSessionDescriptionHandler.js +0 -434
  222. package/lib/pubkey.js +0 -12
  223. package/lib/service/CallApi.js +0 -112
  224. package/lib/service/IssueReporter.js +0 -317
  225. package/lib/service/__tests__/IssueReporter.test.js +0 -117
  226. package/lib/service/__tests__/getApiclient.test.js +0 -42
  227. package/lib/service/getApiClient.js +0 -114
  228. package/lib/simple/Auth.js +0 -433
  229. package/lib/simple/Configuration.js +0 -31
  230. package/lib/simple/Directory.js +0 -29
  231. package/lib/simple/Phone.js +0 -418
  232. package/lib/simple/Websocket.js +0 -116
  233. package/lib/simple/__tests__/Auth.test.js +0 -181
  234. package/lib/simple/index.js +0 -165
  235. package/lib/simple/room/LocalParticipant.js +0 -9
  236. package/lib/simple/room/Participant.js +0 -302
  237. package/lib/simple/room/RemoteParticipant.js +0 -15
  238. package/lib/simple/room/Room.js +0 -711
  239. package/lib/simple/room/SipRoom.js +0 -141
  240. package/lib/simple/room/Stream.js +0 -50
  241. package/lib/simple/room/__tests__/Participant.test.js +0 -85
  242. package/lib/simple/room/__tests__/RemoteParticipant.test.js +0 -17
  243. package/lib/simple/utils.js +0 -27
  244. package/lib/types/WebSocketMessage.js +0 -2
  245. package/lib/types/__tests__/api-client.test.d.ts +0 -2
  246. package/lib/types/__tests__/api-client.test.d.ts.map +0 -1
  247. package/lib/types/__tests__/web-rtc-client.test.d.ts +0 -2
  248. package/lib/types/__tests__/web-rtc-client.test.d.ts.map +0 -1
  249. package/lib/types/api/agentd.d.ts +0 -17
  250. package/lib/types/api/agentd.d.ts.map +0 -1
  251. package/lib/types/api/amid.d.ts +0 -8
  252. package/lib/types/api/amid.d.ts.map +0 -1
  253. package/lib/types/api/application.d.ts +0 -34
  254. package/lib/types/api/application.d.ts.map +0 -1
  255. package/lib/types/api/auth.d.ts +0 -69
  256. package/lib/types/api/auth.d.ts.map +0 -1
  257. package/lib/types/api/call-logd.d.ts +0 -12
  258. package/lib/types/api/call-logd.d.ts.map +0 -1
  259. package/lib/types/api/calld.d.ts +0 -52
  260. package/lib/types/api/calld.d.ts.map +0 -1
  261. package/lib/types/api/chatd.d.ts +0 -29
  262. package/lib/types/api/chatd.d.ts.map +0 -1
  263. package/lib/types/api/confd.d.ts +0 -46
  264. package/lib/types/api/confd.d.ts.map +0 -1
  265. package/lib/types/api/ctid-ng.d.ts +0 -36
  266. package/lib/types/api/ctid-ng.d.ts.map +0 -1
  267. package/lib/types/api/dird.d.ts +0 -33
  268. package/lib/types/api/dird.d.ts.map +0 -1
  269. package/lib/types/api/webhookd.d.ts +0 -24
  270. package/lib/types/api/webhookd.d.ts.map +0 -1
  271. package/lib/types/api-client.d.ts +0 -26
  272. package/lib/types/api-client.d.ts.map +0 -1
  273. package/lib/types/base-api-client.d.ts +0 -43
  274. package/lib/types/base-api-client.d.ts.map +0 -1
  275. package/lib/types/checker/Checker.d.ts +0 -13
  276. package/lib/types/checker/Checker.d.ts.map +0 -1
  277. package/lib/types/checker/checks/aor.d.ts +0 -6
  278. package/lib/types/checker/checks/aor.d.ts.map +0 -1
  279. package/lib/types/checker/checks/api.d.ts +0 -6
  280. package/lib/types/checker/checks/api.d.ts.map +0 -1
  281. package/lib/types/checker/checks/ice-ipv4.d.ts +0 -6
  282. package/lib/types/checker/checks/ice-ipv4.d.ts.map +0 -1
  283. package/lib/types/checker/checks/index.d.ts +0 -9
  284. package/lib/types/checker/checks/index.d.ts.map +0 -1
  285. package/lib/types/checker/checks/symmetric-nat.d.ts +0 -6
  286. package/lib/types/checker/checks/symmetric-nat.d.ts.map +0 -1
  287. package/lib/types/checker/checks/wazo-websocket.d.ts +0 -6
  288. package/lib/types/checker/checks/wazo-websocket.d.ts.map +0 -1
  289. package/lib/types/checker/checks/webrtc-transport.d.ts +0 -7
  290. package/lib/types/checker/checks/webrtc-transport.d.ts.map +0 -1
  291. package/lib/types/checker/checks/webrtc.d.ts +0 -6
  292. package/lib/types/checker/checks/webrtc.d.ts.map +0 -1
  293. package/lib/types/constants.d.ts +0 -12
  294. package/lib/types/constants.d.ts.map +0 -1
  295. package/lib/types/domain/AdHocAPIConference.d.ts +0 -54
  296. package/lib/types/domain/AdHocAPIConference.d.ts.map +0 -1
  297. package/lib/types/domain/Agent.d.ts +0 -31
  298. package/lib/types/domain/Agent.d.ts.map +0 -1
  299. package/lib/types/domain/BadResponse.d.ts +0 -11
  300. package/lib/types/domain/BadResponse.d.ts.map +0 -1
  301. package/lib/types/domain/Call.d.ts +0 -79
  302. package/lib/types/domain/Call.d.ts.map +0 -1
  303. package/lib/types/domain/CallLog.d.ts +0 -88
  304. package/lib/types/domain/CallLog.d.ts.map +0 -1
  305. package/lib/types/domain/CallSession.d.ts +0 -119
  306. package/lib/types/domain/CallSession.d.ts.map +0 -1
  307. package/lib/types/domain/CallerID.d.ts +0 -22
  308. package/lib/types/domain/CallerID.d.ts.map +0 -1
  309. package/lib/types/domain/ChatMessage.d.ts +0 -41
  310. package/lib/types/domain/ChatMessage.d.ts.map +0 -1
  311. package/lib/types/domain/ChatRoom.d.ts +0 -22
  312. package/lib/types/domain/ChatRoom.d.ts.map +0 -1
  313. package/lib/types/domain/Contact.d.ts.map +0 -1
  314. package/lib/types/domain/Country.d.ts +0 -21
  315. package/lib/types/domain/Country.d.ts.map +0 -1
  316. package/lib/types/domain/Device/DebugDevice.d.ts +0 -14
  317. package/lib/types/domain/Device/DebugDevice.d.ts.map +0 -1
  318. package/lib/types/domain/Device/Device.d.ts +0 -13
  319. package/lib/types/domain/Device/Device.d.ts.map +0 -1
  320. package/lib/types/domain/DirectorySource.d.ts +0 -13
  321. package/lib/types/domain/DirectorySource.d.ts.map +0 -1
  322. package/lib/types/domain/ExternalApp.d.ts +0 -22
  323. package/lib/types/domain/ExternalApp.d.ts.map +0 -1
  324. package/lib/types/domain/Features.d.ts +0 -26
  325. package/lib/types/domain/Features.d.ts.map +0 -1
  326. package/lib/types/domain/ForwardOption.d.ts +0 -28
  327. package/lib/types/domain/ForwardOption.d.ts.map +0 -1
  328. package/lib/types/domain/Incall.d.ts +0 -21
  329. package/lib/types/domain/Incall.d.ts.map +0 -1
  330. package/lib/types/domain/IndirectTransfer.d.ts +0 -31
  331. package/lib/types/domain/IndirectTransfer.d.ts.map +0 -1
  332. package/lib/types/domain/Line.d.ts +0 -35
  333. package/lib/types/domain/Line.d.ts.map +0 -1
  334. package/lib/types/domain/Meeting.d.ts +0 -45
  335. package/lib/types/domain/Meeting.d.ts.map +0 -1
  336. package/lib/types/domain/MeetingAuthorization.d.ts +0 -32
  337. package/lib/types/domain/MeetingAuthorization.d.ts.map +0 -1
  338. package/lib/types/domain/MeetingStatus.d.ts +0 -10
  339. package/lib/types/domain/MeetingStatus.d.ts.map +0 -1
  340. package/lib/types/domain/NotificationOptions.d.ts +0 -22
  341. package/lib/types/domain/NotificationOptions.d.ts.map +0 -1
  342. package/lib/types/domain/Phone/CTIPhone.d.ts +0 -79
  343. package/lib/types/domain/Phone/CTIPhone.d.ts.map +0 -1
  344. package/lib/types/domain/Phone/Phone.d.ts +0 -83
  345. package/lib/types/domain/Phone/Phone.d.ts.map +0 -1
  346. package/lib/types/domain/Phone/WebRTCPhone.d.ts +0 -183
  347. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +0 -1
  348. package/lib/types/domain/Profile.d.ts +0 -155
  349. package/lib/types/domain/Profile.d.ts.map +0 -1
  350. package/lib/types/domain/Recording.d.ts +0 -26
  351. package/lib/types/domain/Recording.d.ts.map +0 -1
  352. package/lib/types/domain/Relocation.d.ts +0 -23
  353. package/lib/types/domain/Relocation.d.ts.map +0 -1
  354. package/lib/types/domain/Room.d.ts +0 -33
  355. package/lib/types/domain/Room.d.ts.map +0 -1
  356. package/lib/types/domain/SFUNotAvailableError.d.ts +0 -4
  357. package/lib/types/domain/SFUNotAvailableError.d.ts.map +0 -1
  358. package/lib/types/domain/ServerError.d.ts +0 -6
  359. package/lib/types/domain/ServerError.d.ts.map +0 -1
  360. package/lib/types/domain/Session.d.ts +0 -100
  361. package/lib/types/domain/Session.d.ts.map +0 -1
  362. package/lib/types/domain/SipLine.d.ts +0 -54
  363. package/lib/types/domain/SipLine.d.ts.map +0 -1
  364. package/lib/types/domain/Subscription.d.ts +0 -43
  365. package/lib/types/domain/Subscription.d.ts.map +0 -1
  366. package/lib/types/domain/SwitchboardCall.d.ts +0 -62
  367. package/lib/types/domain/SwitchboardCall.d.ts.map +0 -1
  368. package/lib/types/domain/Voicemail.d.ts +0 -58
  369. package/lib/types/domain/Voicemail.d.ts.map +0 -1
  370. package/lib/types/domain/__tests__/Agent.test.d.ts +0 -2
  371. package/lib/types/domain/__tests__/Agent.test.d.ts.map +0 -1
  372. package/lib/types/domain/__tests__/Call.test.d.ts +0 -2
  373. package/lib/types/domain/__tests__/Call.test.d.ts.map +0 -1
  374. package/lib/types/domain/__tests__/CallLog.test.d.ts +0 -2
  375. package/lib/types/domain/__tests__/CallLog.test.d.ts.map +0 -1
  376. package/lib/types/domain/__tests__/CallSession.test.d.ts +0 -2
  377. package/lib/types/domain/__tests__/CallSession.test.d.ts.map +0 -1
  378. package/lib/types/domain/__tests__/Contact.test.d.ts +0 -2
  379. package/lib/types/domain/__tests__/Contact.test.d.ts.map +0 -1
  380. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts +0 -2
  381. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts.map +0 -1
  382. package/lib/types/domain/__tests__/Line.test.d.ts +0 -2
  383. package/lib/types/domain/__tests__/Line.test.d.ts.map +0 -1
  384. package/lib/types/domain/__tests__/Meeting.test.d.ts +0 -2
  385. package/lib/types/domain/__tests__/Meeting.test.d.ts.map +0 -1
  386. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts +0 -2
  387. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +0 -1
  388. package/lib/types/domain/__tests__/Profile.test.d.ts +0 -2
  389. package/lib/types/domain/__tests__/Profile.test.d.ts.map +0 -1
  390. package/lib/types/domain/__tests__/Room.test.d.ts +0 -2
  391. package/lib/types/domain/__tests__/Room.test.d.ts.map +0 -1
  392. package/lib/types/domain/__tests__/Session.test.d.ts +0 -2
  393. package/lib/types/domain/__tests__/Session.test.d.ts.map +0 -1
  394. package/lib/types/domain/__tests__/SipLine.test.d.ts +0 -2
  395. package/lib/types/domain/__tests__/SipLine.test.d.ts.map +0 -1
  396. package/lib/types/domain/__tests__/Voicemail.test.d.ts +0 -2
  397. package/lib/types/domain/__tests__/Voicemail.test.d.ts.map +0 -1
  398. package/lib/types/domain/types.d.ts +0 -378
  399. package/lib/types/domain/types.d.ts.map +0 -1
  400. package/lib/types/index.d.ts.map +0 -1
  401. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +0 -31
  402. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +0 -1
  403. package/lib/types/pubkey.d.ts +0 -3
  404. package/lib/types/pubkey.d.ts.map +0 -1
  405. package/lib/types/service/CallApi.d.ts +0 -28
  406. package/lib/types/service/CallApi.d.ts.map +0 -1
  407. package/lib/types/service/IssueReporter.d.ts +0 -42
  408. package/lib/types/service/IssueReporter.d.ts.map +0 -1
  409. package/lib/types/service/__tests__/IssueReporter.test.d.ts +0 -2
  410. package/lib/types/service/__tests__/IssueReporter.test.d.ts.map +0 -1
  411. package/lib/types/service/__tests__/getApiclient.test.d.ts +0 -2
  412. package/lib/types/service/__tests__/getApiclient.test.d.ts.map +0 -1
  413. package/lib/types/service/getApiClient.d.ts +0 -21
  414. package/lib/types/service/getApiClient.d.ts.map +0 -1
  415. package/lib/types/simple/Auth.d.ts +0 -75
  416. package/lib/types/simple/Auth.d.ts.map +0 -1
  417. package/lib/types/simple/Configuration.d.ts +0 -7
  418. package/lib/types/simple/Configuration.d.ts.map +0 -1
  419. package/lib/types/simple/Directory.d.ts +0 -7
  420. package/lib/types/simple/Directory.d.ts.map +0 -1
  421. package/lib/types/simple/Phone.d.ts +0 -119
  422. package/lib/types/simple/Phone.d.ts.map +0 -1
  423. package/lib/types/simple/Websocket.d.ts +0 -21
  424. package/lib/types/simple/Websocket.d.ts.map +0 -1
  425. package/lib/types/simple/__tests__/Auth.test.d.ts +0 -2
  426. package/lib/types/simple/__tests__/Auth.test.d.ts.map +0 -1
  427. package/lib/types/simple/index.d.ts +0 -153
  428. package/lib/types/simple/index.d.ts.map +0 -1
  429. package/lib/types/simple/room/LocalParticipant.d.ts +0 -5
  430. package/lib/types/simple/room/LocalParticipant.d.ts.map +0 -1
  431. package/lib/types/simple/room/Participant.d.ts +0 -77
  432. package/lib/types/simple/room/Participant.d.ts.map +0 -1
  433. package/lib/types/simple/room/RemoteParticipant.d.ts +0 -7
  434. package/lib/types/simple/room/RemoteParticipant.d.ts.map +0 -1
  435. package/lib/types/simple/room/Room.d.ts +0 -127
  436. package/lib/types/simple/room/Room.d.ts.map +0 -1
  437. package/lib/types/simple/room/SipRoom.d.ts +0 -14
  438. package/lib/types/simple/room/SipRoom.d.ts.map +0 -1
  439. package/lib/types/simple/room/Stream.d.ts +0 -13
  440. package/lib/types/simple/room/Stream.d.ts.map +0 -1
  441. package/lib/types/simple/room/__tests__/Participant.test.d.ts +0 -2
  442. package/lib/types/simple/room/__tests__/Participant.test.d.ts.map +0 -1
  443. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts +0 -2
  444. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +0 -1
  445. package/lib/types/simple/utils.d.ts +0 -3
  446. package/lib/types/simple/utils.d.ts.map +0 -1
  447. package/lib/types/types/WebSocketMessage.d.ts +0 -285
  448. package/lib/types/types/WebSocketMessage.d.ts.map +0 -1
  449. package/lib/types/utils/Emitter.d.ts +0 -18
  450. package/lib/types/utils/Emitter.d.ts.map +0 -1
  451. package/lib/types/utils/Heartbeat.d.ts +0 -22
  452. package/lib/types/utils/Heartbeat.d.ts.map +0 -1
  453. package/lib/types/utils/PhoneNumberUtil.d.ts +0 -7
  454. package/lib/types/utils/PhoneNumberUtil.d.ts.map +0 -1
  455. package/lib/types/utils/__tests__/Heartbeat.test.d.ts +0 -2
  456. package/lib/types/utils/__tests__/Heartbeat.test.d.ts.map +0 -1
  457. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts +0 -2
  458. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +0 -1
  459. package/lib/types/utils/__tests__/api-requester.test.d.ts +0 -2
  460. package/lib/types/utils/__tests__/api-requester.test.d.ts.map +0 -1
  461. package/lib/types/utils/__tests__/array.test.d.ts +0 -2
  462. package/lib/types/utils/__tests__/array.test.d.ts.map +0 -1
  463. package/lib/types/utils/__tests__/compare-version.test.d.ts +0 -2
  464. package/lib/types/utils/__tests__/compare-version.test.d.ts.map +0 -1
  465. package/lib/types/utils/__tests__/object.test.d.ts +0 -2
  466. package/lib/types/utils/__tests__/object.test.d.ts.map +0 -1
  467. package/lib/types/utils/__tests__/sdp.test.d.ts +0 -2
  468. package/lib/types/utils/__tests__/sdp.test.d.ts.map +0 -1
  469. package/lib/types/utils/__tests__/string.test.d.ts +0 -2
  470. package/lib/types/utils/__tests__/string.test.d.ts.map +0 -1
  471. package/lib/types/utils/api-requester.d.ts +0 -48
  472. package/lib/types/utils/api-requester.d.ts.map +0 -1
  473. package/lib/types/utils/array.d.ts +0 -2
  474. package/lib/types/utils/array.d.ts.map +0 -1
  475. package/lib/types/utils/compare-version.d.ts +0 -3
  476. package/lib/types/utils/compare-version.d.ts.map +0 -1
  477. package/lib/types/utils/isMobile.d.ts +0 -3
  478. package/lib/types/utils/isMobile.d.ts.map +0 -1
  479. package/lib/types/utils/new-from.d.ts +0 -3
  480. package/lib/types/utils/new-from.d.ts.map +0 -1
  481. package/lib/types/utils/object.d.ts +0 -2
  482. package/lib/types/utils/object.d.ts.map +0 -1
  483. package/lib/types/utils/once.d.ts +0 -2
  484. package/lib/types/utils/once.d.ts.map +0 -1
  485. package/lib/types/utils/sdp.d.ts +0 -28
  486. package/lib/types/utils/sdp.d.ts.map +0 -1
  487. package/lib/types/utils/string.d.ts +0 -3
  488. package/lib/types/utils/string.d.ts.map +0 -1
  489. package/lib/types/utils/update-from.d.ts +0 -3
  490. package/lib/types/utils/update-from.d.ts.map +0 -1
  491. package/lib/types/utils/webrtc.d.ts +0 -15
  492. package/lib/types/utils/webrtc.d.ts.map +0 -1
  493. package/lib/types/web-rtc-client.d.ts +0 -198
  494. package/lib/types/web-rtc-client.d.ts.map +0 -1
  495. package/lib/types/websocket-client.d.ts +0 -138
  496. package/lib/types/websocket-client.d.ts.map +0 -1
  497. package/lib/utils/Emitter.js +0 -24
  498. package/lib/utils/Heartbeat.js +0 -66
  499. package/lib/utils/PhoneNumberUtil.js +0 -73
  500. package/lib/utils/__tests__/Heartbeat.test.js +0 -79
  501. package/lib/utils/__tests__/PhoneNumberUtil.test.js +0 -72
  502. package/lib/utils/__tests__/api-requester.test.js +0 -180
  503. package/lib/utils/__tests__/array.test.js +0 -20
  504. package/lib/utils/__tests__/compare-version.test.js +0 -15
  505. package/lib/utils/__tests__/object.test.js +0 -78
  506. package/lib/utils/__tests__/sdp.test.js +0 -188
  507. package/lib/utils/__tests__/string.test.js +0 -51
  508. package/lib/utils/api-requester.js +0 -200
  509. package/lib/utils/array.js +0 -13
  510. package/lib/utils/compare-version.js +0 -19
  511. package/lib/utils/isMobile.js +0 -5
  512. package/lib/utils/new-from.js +0 -9
  513. package/lib/utils/object.js +0 -14
  514. package/lib/utils/once.js +0 -18
  515. package/lib/utils/sdp.js +0 -115
  516. package/lib/utils/string.js +0 -17
  517. package/lib/utils/update-from.js +0 -12
  518. package/lib/utils/webrtc.js +0 -41
  519. package/lib/web-rtc-client.js +0 -2239
  520. package/lib/websocket-client.js +0 -390
  521. package/src/__tests__/api-client.test.ts +0 -315
  522. package/src/__tests__/web-rtc-client.test.ts +0 -198
  523. package/src/api/agentd.ts +0 -37
  524. package/src/api/amid.ts +0 -25
  525. package/src/api/application.ts +0 -96
  526. package/src/api/auth.ts +0 -305
  527. package/src/api/call-logd.ts +0 -38
  528. package/src/api/calld.ts +0 -185
  529. package/src/api/chatd.ts +0 -87
  530. package/src/api/confd.ts +0 -119
  531. package/src/api/ctid-ng.ts +0 -152
  532. package/src/api/dird.ts +0 -143
  533. package/src/api/webhookd.ts +0 -30
  534. package/src/api-client.ts +0 -65
  535. package/src/base-api-client.ts +0 -184
  536. package/src/checker/Checker.ts +0 -73
  537. package/src/checker/checks/aor.ts +0 -34
  538. package/src/checker/checks/api.ts +0 -78
  539. package/src/checker/checks/ice-ipv4.ts +0 -80
  540. package/src/checker/checks/index.ts +0 -9
  541. package/src/checker/checks/symmetric-nat.ts +0 -69
  542. package/src/checker/checks/wazo-websocket.ts +0 -41
  543. package/src/checker/checks/webrtc-transport.ts +0 -42
  544. package/src/checker/checks/webrtc.ts +0 -48
  545. package/src/constants.ts +0 -11
  546. package/src/domain/AdHocAPIConference.ts +0 -166
  547. package/src/domain/Agent.ts +0 -68
  548. package/src/domain/BadResponse.ts +0 -29
  549. package/src/domain/Call.ts +0 -217
  550. package/src/domain/CallLog.ts +0 -265
  551. package/src/domain/CallSession.ts +0 -401
  552. package/src/domain/CallerID.ts +0 -49
  553. package/src/domain/ChatMessage.ts +0 -107
  554. package/src/domain/ChatRoom.ts +0 -55
  555. package/src/domain/Contact.ts +0 -851
  556. package/src/domain/Country.ts +0 -19
  557. package/src/domain/Device/DebugDevice.ts +0 -44
  558. package/src/domain/Device/Device.ts +0 -12
  559. package/src/domain/DirectorySource.ts +0 -13
  560. package/src/domain/ExternalApp.ts +0 -46
  561. package/src/domain/Features.ts +0 -105
  562. package/src/domain/ForwardOption.ts +0 -65
  563. package/src/domain/Incall.ts +0 -50
  564. package/src/domain/IndirectTransfer.ts +0 -73
  565. package/src/domain/Line.ts +0 -79
  566. package/src/domain/Meeting.ts +0 -113
  567. package/src/domain/MeetingAuthorization.ts +0 -81
  568. package/src/domain/MeetingStatus.ts +0 -23
  569. package/src/domain/NotificationOptions.ts +0 -68
  570. package/src/domain/Phone/CTIPhone.ts +0 -381
  571. package/src/domain/Phone/Phone.ts +0 -81
  572. package/src/domain/Phone/WebRTCPhone.ts +0 -1830
  573. package/src/domain/Profile.ts +0 -289
  574. package/src/domain/Recording.ts +0 -60
  575. package/src/domain/Relocation.ts +0 -45
  576. package/src/domain/Room.ts +0 -141
  577. package/src/domain/SFUNotAvailableError.ts +0 -7
  578. package/src/domain/ServerError.ts +0 -12
  579. package/src/domain/Session.ts +0 -297
  580. package/src/domain/SipLine.ts +0 -154
  581. package/src/domain/Subscription.ts +0 -95
  582. package/src/domain/SwitchboardCall.ts +0 -127
  583. package/src/domain/Voicemail.ts +0 -138
  584. package/src/domain/__tests__/Agent.test.ts +0 -38
  585. package/src/domain/__tests__/Call.test.ts +0 -26
  586. package/src/domain/__tests__/CallLog.test.ts +0 -203
  587. package/src/domain/__tests__/CallSession.test.ts +0 -80
  588. package/src/domain/__tests__/Contact.test.ts +0 -407
  589. package/src/domain/__tests__/IndirectTransfer.test.ts +0 -68
  590. package/src/domain/__tests__/Line.test.ts +0 -53
  591. package/src/domain/__tests__/Meeting.test.ts +0 -93
  592. package/src/domain/__tests__/MeetingAuthorization.test.ts +0 -50
  593. package/src/domain/__tests__/Profile.test.ts +0 -170
  594. package/src/domain/__tests__/Room.test.ts +0 -207
  595. package/src/domain/__tests__/Session.test.ts +0 -385
  596. package/src/domain/__tests__/SipLine.test.ts +0 -30
  597. package/src/domain/__tests__/Voicemail.test.ts +0 -91
  598. package/src/domain/types.ts +0 -331
  599. package/src/index.ts +0 -60
  600. package/src/lib/WazoSessionDescriptionHandler.ts +0 -532
  601. package/src/pubkey.ts +0 -11
  602. package/src/service/CallApi.ts +0 -86
  603. package/src/service/IssueReporter.ts +0 -434
  604. package/src/service/__tests__/IssueReporter.test.ts +0 -127
  605. package/src/service/__tests__/getApiclient.test.ts +0 -46
  606. package/src/service/getApiClient.ts +0 -113
  607. package/src/simple/Auth.ts +0 -496
  608. package/src/simple/Configuration.ts +0 -18
  609. package/src/simple/Directory.ts +0 -16
  610. package/src/simple/Phone.ts +0 -531
  611. package/src/simple/Websocket.ts +0 -107
  612. package/src/simple/__tests__/Auth.test.ts +0 -168
  613. package/src/simple/index.ts +0 -153
  614. package/src/simple/room/LocalParticipant.ts +0 -5
  615. package/src/simple/room/Participant.ts +0 -409
  616. package/src/simple/room/RemoteParticipant.ts +0 -15
  617. package/src/simple/room/Room.ts +0 -942
  618. package/src/simple/room/SipRoom.ts +0 -164
  619. package/src/simple/room/Stream.ts +0 -64
  620. package/src/simple/room/__tests__/Participant.test.ts +0 -73
  621. package/src/simple/room/__tests__/RemoteParticipant.test.ts +0 -15
  622. package/src/simple/utils.ts +0 -12
  623. package/src/types/WebSocketMessage.ts +0 -335
  624. package/src/types/global.d.ts +0 -33
  625. package/src/types/wazo.d.ts +0 -1
  626. package/src/utils/Emitter.ts +0 -34
  627. package/src/utils/Heartbeat.ts +0 -102
  628. package/src/utils/PhoneNumberUtil.ts +0 -81
  629. package/src/utils/__tests__/Heartbeat.test.ts +0 -66
  630. package/src/utils/__tests__/PhoneNumberUtil.test.ts +0 -79
  631. package/src/utils/__tests__/api-requester.test.ts +0 -180
  632. package/src/utils/__tests__/array.test.ts +0 -19
  633. package/src/utils/__tests__/compare-version.test.ts +0 -11
  634. package/src/utils/__tests__/object.test.ts +0 -77
  635. package/src/utils/__tests__/sdp.test.ts +0 -173
  636. package/src/utils/__tests__/string.test.ts +0 -55
  637. package/src/utils/api-requester.ts +0 -294
  638. package/src/utils/array.ts +0 -11
  639. package/src/utils/compare-version.ts +0 -21
  640. package/src/utils/isMobile.ts +0 -4
  641. package/src/utils/new-from.ts +0 -7
  642. package/src/utils/object.ts +0 -12
  643. package/src/utils/once.ts +0 -14
  644. package/src/utils/sdp.ts +0 -140
  645. package/src/utils/string.ts +0 -15
  646. package/src/utils/update-from.ts +0 -11
  647. package/src/utils/webrtc.ts +0 -56
  648. package/src/web-rtc-client.ts +0 -2687
  649. package/src/websocket-client.ts +0 -475
  650. /package/{esm → dist}/types/__tests__/api-client.test.d.ts +0 -0
  651. /package/{esm → dist}/types/__tests__/api-client.test.d.ts.map +0 -0
  652. /package/{esm → dist}/types/__tests__/web-rtc-client.test.d.ts +0 -0
  653. /package/{esm → dist}/types/__tests__/web-rtc-client.test.d.ts.map +0 -0
  654. /package/{esm → dist}/types/api/agentd.d.ts +0 -0
  655. /package/{esm → dist}/types/api/agentd.d.ts.map +0 -0
  656. /package/{esm → dist}/types/api/amid.d.ts +0 -0
  657. /package/{esm → dist}/types/api/amid.d.ts.map +0 -0
  658. /package/{esm → dist}/types/api/application.d.ts +0 -0
  659. /package/{esm → dist}/types/api/application.d.ts.map +0 -0
  660. /package/{esm → dist}/types/api/auth.d.ts +0 -0
  661. /package/{esm → dist}/types/api/auth.d.ts.map +0 -0
  662. /package/{esm → dist}/types/api/call-logd.d.ts +0 -0
  663. /package/{esm → dist}/types/api/call-logd.d.ts.map +0 -0
  664. /package/{esm → dist}/types/api/calld.d.ts +0 -0
  665. /package/{esm → dist}/types/api/calld.d.ts.map +0 -0
  666. /package/{esm → dist}/types/api/chatd.d.ts +0 -0
  667. /package/{esm → dist}/types/api/chatd.d.ts.map +0 -0
  668. /package/{esm → dist}/types/api/confd.d.ts +0 -0
  669. /package/{esm → dist}/types/api/confd.d.ts.map +0 -0
  670. /package/{esm → dist}/types/api/ctid-ng.d.ts +0 -0
  671. /package/{esm → dist}/types/api/ctid-ng.d.ts.map +0 -0
  672. /package/{esm → dist}/types/api/dird.d.ts +0 -0
  673. /package/{esm → dist}/types/api/dird.d.ts.map +0 -0
  674. /package/{esm → dist}/types/api/webhookd.d.ts +0 -0
  675. /package/{esm → dist}/types/api/webhookd.d.ts.map +0 -0
  676. /package/{esm → dist}/types/api-client.d.ts +0 -0
  677. /package/{esm → dist}/types/api-client.d.ts.map +0 -0
  678. /package/{esm → dist}/types/base-api-client.d.ts +0 -0
  679. /package/{esm → dist}/types/base-api-client.d.ts.map +0 -0
  680. /package/{esm → dist}/types/checker/Checker.d.ts +0 -0
  681. /package/{esm → dist}/types/checker/Checker.d.ts.map +0 -0
  682. /package/{esm → dist}/types/checker/checks/aor.d.ts +0 -0
  683. /package/{esm → dist}/types/checker/checks/aor.d.ts.map +0 -0
  684. /package/{esm → dist}/types/checker/checks/api.d.ts +0 -0
  685. /package/{esm → dist}/types/checker/checks/api.d.ts.map +0 -0
  686. /package/{esm → dist}/types/checker/checks/ice-ipv4.d.ts +0 -0
  687. /package/{esm → dist}/types/checker/checks/ice-ipv4.d.ts.map +0 -0
  688. /package/{esm → dist}/types/checker/checks/index.d.ts +0 -0
  689. /package/{esm → dist}/types/checker/checks/index.d.ts.map +0 -0
  690. /package/{esm → dist}/types/checker/checks/symmetric-nat.d.ts +0 -0
  691. /package/{esm → dist}/types/checker/checks/symmetric-nat.d.ts.map +0 -0
  692. /package/{esm → dist}/types/checker/checks/wazo-websocket.d.ts +0 -0
  693. /package/{esm → dist}/types/checker/checks/wazo-websocket.d.ts.map +0 -0
  694. /package/{esm → dist}/types/checker/checks/webrtc-transport.d.ts +0 -0
  695. /package/{esm → dist}/types/checker/checks/webrtc-transport.d.ts.map +0 -0
  696. /package/{esm → dist}/types/checker/checks/webrtc.d.ts +0 -0
  697. /package/{esm → dist}/types/checker/checks/webrtc.d.ts.map +0 -0
  698. /package/{esm → dist}/types/constants.d.ts +0 -0
  699. /package/{esm → dist}/types/constants.d.ts.map +0 -0
  700. /package/{esm → dist}/types/domain/AdHocAPIConference.d.ts +0 -0
  701. /package/{esm → dist}/types/domain/AdHocAPIConference.d.ts.map +0 -0
  702. /package/{esm → dist}/types/domain/Agent.d.ts +0 -0
  703. /package/{esm → dist}/types/domain/Agent.d.ts.map +0 -0
  704. /package/{esm → dist}/types/domain/BadResponse.d.ts +0 -0
  705. /package/{esm → dist}/types/domain/BadResponse.d.ts.map +0 -0
  706. /package/{esm → dist}/types/domain/Call.d.ts +0 -0
  707. /package/{esm → dist}/types/domain/Call.d.ts.map +0 -0
  708. /package/{esm → dist}/types/domain/CallLog.d.ts +0 -0
  709. /package/{esm → dist}/types/domain/CallLog.d.ts.map +0 -0
  710. /package/{esm → dist}/types/domain/CallSession.d.ts +0 -0
  711. /package/{esm → dist}/types/domain/CallSession.d.ts.map +0 -0
  712. /package/{esm → dist}/types/domain/CallerID.d.ts +0 -0
  713. /package/{esm → dist}/types/domain/CallerID.d.ts.map +0 -0
  714. /package/{esm → dist}/types/domain/ChatMessage.d.ts +0 -0
  715. /package/{esm → dist}/types/domain/ChatMessage.d.ts.map +0 -0
  716. /package/{esm → dist}/types/domain/ChatRoom.d.ts +0 -0
  717. /package/{esm → dist}/types/domain/ChatRoom.d.ts.map +0 -0
  718. /package/{esm → dist}/types/domain/Country.d.ts +0 -0
  719. /package/{esm → dist}/types/domain/Country.d.ts.map +0 -0
  720. /package/{esm → dist}/types/domain/Device/DebugDevice.d.ts +0 -0
  721. /package/{esm → dist}/types/domain/Device/DebugDevice.d.ts.map +0 -0
  722. /package/{esm → dist}/types/domain/Device/Device.d.ts +0 -0
  723. /package/{esm → dist}/types/domain/Device/Device.d.ts.map +0 -0
  724. /package/{esm → dist}/types/domain/DirectorySource.d.ts +0 -0
  725. /package/{esm → dist}/types/domain/DirectorySource.d.ts.map +0 -0
  726. /package/{esm → dist}/types/domain/ExternalApp.d.ts +0 -0
  727. /package/{esm → dist}/types/domain/ExternalApp.d.ts.map +0 -0
  728. /package/{esm → dist}/types/domain/Features.d.ts +0 -0
  729. /package/{esm → dist}/types/domain/Features.d.ts.map +0 -0
  730. /package/{esm → dist}/types/domain/ForwardOption.d.ts +0 -0
  731. /package/{esm → dist}/types/domain/ForwardOption.d.ts.map +0 -0
  732. /package/{esm → dist}/types/domain/Incall.d.ts +0 -0
  733. /package/{esm → dist}/types/domain/Incall.d.ts.map +0 -0
  734. /package/{esm → dist}/types/domain/IndirectTransfer.d.ts +0 -0
  735. /package/{esm → dist}/types/domain/IndirectTransfer.d.ts.map +0 -0
  736. /package/{esm → dist}/types/domain/Line.d.ts +0 -0
  737. /package/{esm → dist}/types/domain/Line.d.ts.map +0 -0
  738. /package/{esm → dist}/types/domain/Meeting.d.ts +0 -0
  739. /package/{esm → dist}/types/domain/Meeting.d.ts.map +0 -0
  740. /package/{esm → dist}/types/domain/MeetingAuthorization.d.ts +0 -0
  741. /package/{esm → dist}/types/domain/MeetingAuthorization.d.ts.map +0 -0
  742. /package/{esm → dist}/types/domain/MeetingStatus.d.ts +0 -0
  743. /package/{esm → dist}/types/domain/MeetingStatus.d.ts.map +0 -0
  744. /package/{esm → dist}/types/domain/NotificationOptions.d.ts +0 -0
  745. /package/{esm → dist}/types/domain/NotificationOptions.d.ts.map +0 -0
  746. /package/{esm → dist}/types/domain/Phone/CTIPhone.d.ts +0 -0
  747. /package/{esm → dist}/types/domain/Phone/CTIPhone.d.ts.map +0 -0
  748. /package/{esm → dist}/types/domain/Phone/Phone.d.ts +0 -0
  749. /package/{esm → dist}/types/domain/Phone/Phone.d.ts.map +0 -0
  750. /package/{esm → dist}/types/domain/Phone/WebRTCPhone.d.ts +0 -0
  751. /package/{esm → dist}/types/domain/Phone/WebRTCPhone.d.ts.map +0 -0
  752. /package/{esm → dist}/types/domain/Profile.d.ts +0 -0
  753. /package/{esm → dist}/types/domain/Profile.d.ts.map +0 -0
  754. /package/{esm → dist}/types/domain/Recording.d.ts +0 -0
  755. /package/{esm → dist}/types/domain/Recording.d.ts.map +0 -0
  756. /package/{esm → dist}/types/domain/Relocation.d.ts +0 -0
  757. /package/{esm → dist}/types/domain/Relocation.d.ts.map +0 -0
  758. /package/{esm → dist}/types/domain/Room.d.ts +0 -0
  759. /package/{esm → dist}/types/domain/Room.d.ts.map +0 -0
  760. /package/{esm → dist}/types/domain/SFUNotAvailableError.d.ts +0 -0
  761. /package/{esm → dist}/types/domain/SFUNotAvailableError.d.ts.map +0 -0
  762. /package/{esm → dist}/types/domain/ServerError.d.ts +0 -0
  763. /package/{esm → dist}/types/domain/ServerError.d.ts.map +0 -0
  764. /package/{esm → dist}/types/domain/Session.d.ts +0 -0
  765. /package/{esm → dist}/types/domain/Session.d.ts.map +0 -0
  766. /package/{esm → dist}/types/domain/SipLine.d.ts +0 -0
  767. /package/{esm → dist}/types/domain/SipLine.d.ts.map +0 -0
  768. /package/{esm → dist}/types/domain/Subscription.d.ts +0 -0
  769. /package/{esm → dist}/types/domain/Subscription.d.ts.map +0 -0
  770. /package/{esm → dist}/types/domain/SwitchboardCall.d.ts +0 -0
  771. /package/{esm → dist}/types/domain/SwitchboardCall.d.ts.map +0 -0
  772. /package/{esm → dist}/types/domain/Voicemail.d.ts +0 -0
  773. /package/{esm → dist}/types/domain/Voicemail.d.ts.map +0 -0
  774. /package/{esm → dist}/types/domain/__tests__/Agent.test.d.ts +0 -0
  775. /package/{esm → dist}/types/domain/__tests__/Agent.test.d.ts.map +0 -0
  776. /package/{esm → dist}/types/domain/__tests__/Call.test.d.ts +0 -0
  777. /package/{esm → dist}/types/domain/__tests__/Call.test.d.ts.map +0 -0
  778. /package/{esm → dist}/types/domain/__tests__/CallLog.test.d.ts +0 -0
  779. /package/{esm → dist}/types/domain/__tests__/CallLog.test.d.ts.map +0 -0
  780. /package/{esm → dist}/types/domain/__tests__/CallSession.test.d.ts +0 -0
  781. /package/{esm → dist}/types/domain/__tests__/CallSession.test.d.ts.map +0 -0
  782. /package/{esm → dist}/types/domain/__tests__/Contact.test.d.ts +0 -0
  783. /package/{esm → dist}/types/domain/__tests__/Contact.test.d.ts.map +0 -0
  784. /package/{esm → dist}/types/domain/__tests__/IndirectTransfer.test.d.ts +0 -0
  785. /package/{esm → dist}/types/domain/__tests__/IndirectTransfer.test.d.ts.map +0 -0
  786. /package/{esm → dist}/types/domain/__tests__/Line.test.d.ts +0 -0
  787. /package/{esm → dist}/types/domain/__tests__/Line.test.d.ts.map +0 -0
  788. /package/{esm → dist}/types/domain/__tests__/Meeting.test.d.ts +0 -0
  789. /package/{esm → dist}/types/domain/__tests__/Meeting.test.d.ts.map +0 -0
  790. /package/{esm → dist}/types/domain/__tests__/MeetingAuthorization.test.d.ts +0 -0
  791. /package/{esm → dist}/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +0 -0
  792. /package/{esm → dist}/types/domain/__tests__/Profile.test.d.ts +0 -0
  793. /package/{esm → dist}/types/domain/__tests__/Profile.test.d.ts.map +0 -0
  794. /package/{esm → dist}/types/domain/__tests__/Room.test.d.ts +0 -0
  795. /package/{esm → dist}/types/domain/__tests__/Room.test.d.ts.map +0 -0
  796. /package/{esm → dist}/types/domain/__tests__/Session.test.d.ts +0 -0
  797. /package/{esm → dist}/types/domain/__tests__/Session.test.d.ts.map +0 -0
  798. /package/{esm → dist}/types/domain/__tests__/SipLine.test.d.ts +0 -0
  799. /package/{esm → dist}/types/domain/__tests__/SipLine.test.d.ts.map +0 -0
  800. /package/{esm → dist}/types/domain/__tests__/Voicemail.test.d.ts +0 -0
  801. /package/{esm → dist}/types/domain/__tests__/Voicemail.test.d.ts.map +0 -0
  802. /package/{esm → dist}/types/domain/types.d.ts +0 -0
  803. /package/{esm → dist}/types/domain/types.d.ts.map +0 -0
  804. /package/{esm → dist}/types/lib/WazoSessionDescriptionHandler.d.ts +0 -0
  805. /package/{esm → dist}/types/lib/WazoSessionDescriptionHandler.d.ts.map +0 -0
  806. /package/{esm → dist}/types/pubkey.d.ts +0 -0
  807. /package/{esm → dist}/types/pubkey.d.ts.map +0 -0
  808. /package/{esm → dist}/types/service/CallApi.d.ts +0 -0
  809. /package/{esm → dist}/types/service/CallApi.d.ts.map +0 -0
  810. /package/{esm → dist}/types/service/IssueReporter.d.ts +0 -0
  811. /package/{esm → dist}/types/service/IssueReporter.d.ts.map +0 -0
  812. /package/{esm → dist}/types/service/__tests__/IssueReporter.test.d.ts +0 -0
  813. /package/{esm → dist}/types/service/__tests__/IssueReporter.test.d.ts.map +0 -0
  814. /package/{esm → dist}/types/service/__tests__/getApiclient.test.d.ts +0 -0
  815. /package/{esm → dist}/types/service/__tests__/getApiclient.test.d.ts.map +0 -0
  816. /package/{esm → dist}/types/service/getApiClient.d.ts +0 -0
  817. /package/{esm → dist}/types/service/getApiClient.d.ts.map +0 -0
  818. /package/{esm → dist}/types/simple/Auth.d.ts +0 -0
  819. /package/{esm → dist}/types/simple/Auth.d.ts.map +0 -0
  820. /package/{esm → dist}/types/simple/Configuration.d.ts +0 -0
  821. /package/{esm → dist}/types/simple/Configuration.d.ts.map +0 -0
  822. /package/{esm → dist}/types/simple/Directory.d.ts +0 -0
  823. /package/{esm → dist}/types/simple/Directory.d.ts.map +0 -0
  824. /package/{esm → dist}/types/simple/Phone.d.ts +0 -0
  825. /package/{esm → dist}/types/simple/Phone.d.ts.map +0 -0
  826. /package/{esm → dist}/types/simple/Websocket.d.ts +0 -0
  827. /package/{esm → dist}/types/simple/Websocket.d.ts.map +0 -0
  828. /package/{esm → dist}/types/simple/__tests__/Auth.test.d.ts +0 -0
  829. /package/{esm → dist}/types/simple/__tests__/Auth.test.d.ts.map +0 -0
  830. /package/{esm → dist}/types/simple/index.d.ts +0 -0
  831. /package/{esm → dist}/types/simple/index.d.ts.map +0 -0
  832. /package/{esm → dist}/types/simple/room/LocalParticipant.d.ts +0 -0
  833. /package/{esm → dist}/types/simple/room/LocalParticipant.d.ts.map +0 -0
  834. /package/{esm → dist}/types/simple/room/Participant.d.ts +0 -0
  835. /package/{esm → dist}/types/simple/room/Participant.d.ts.map +0 -0
  836. /package/{esm → dist}/types/simple/room/RemoteParticipant.d.ts +0 -0
  837. /package/{esm → dist}/types/simple/room/RemoteParticipant.d.ts.map +0 -0
  838. /package/{esm → dist}/types/simple/room/Room.d.ts +0 -0
  839. /package/{esm → dist}/types/simple/room/Room.d.ts.map +0 -0
  840. /package/{esm → dist}/types/simple/room/SipRoom.d.ts +0 -0
  841. /package/{esm → dist}/types/simple/room/SipRoom.d.ts.map +0 -0
  842. /package/{esm → dist}/types/simple/room/Stream.d.ts +0 -0
  843. /package/{esm → dist}/types/simple/room/Stream.d.ts.map +0 -0
  844. /package/{esm → dist}/types/simple/room/__tests__/Participant.test.d.ts +0 -0
  845. /package/{esm → dist}/types/simple/room/__tests__/Participant.test.d.ts.map +0 -0
  846. /package/{esm → dist}/types/simple/room/__tests__/RemoteParticipant.test.d.ts +0 -0
  847. /package/{esm → dist}/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +0 -0
  848. /package/{esm → dist}/types/simple/utils.d.ts +0 -0
  849. /package/{esm → dist}/types/simple/utils.d.ts.map +0 -0
  850. /package/{esm → dist}/types/types/WebSocketMessage.d.ts +0 -0
  851. /package/{esm → dist}/types/types/WebSocketMessage.d.ts.map +0 -0
  852. /package/{esm → dist}/types/utils/Emitter.d.ts +0 -0
  853. /package/{esm → dist}/types/utils/Emitter.d.ts.map +0 -0
  854. /package/{esm → dist}/types/utils/Heartbeat.d.ts +0 -0
  855. /package/{esm → dist}/types/utils/Heartbeat.d.ts.map +0 -0
  856. /package/{esm → dist}/types/utils/PhoneNumberUtil.d.ts +0 -0
  857. /package/{esm → dist}/types/utils/PhoneNumberUtil.d.ts.map +0 -0
  858. /package/{esm → dist}/types/utils/__tests__/Heartbeat.test.d.ts +0 -0
  859. /package/{esm → dist}/types/utils/__tests__/Heartbeat.test.d.ts.map +0 -0
  860. /package/{esm → dist}/types/utils/__tests__/PhoneNumberUtil.test.d.ts +0 -0
  861. /package/{esm → dist}/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +0 -0
  862. /package/{esm → dist}/types/utils/__tests__/api-requester.test.d.ts +0 -0
  863. /package/{esm → dist}/types/utils/__tests__/api-requester.test.d.ts.map +0 -0
  864. /package/{esm → dist}/types/utils/__tests__/array.test.d.ts +0 -0
  865. /package/{esm → dist}/types/utils/__tests__/array.test.d.ts.map +0 -0
  866. /package/{esm → dist}/types/utils/__tests__/compare-version.test.d.ts +0 -0
  867. /package/{esm → dist}/types/utils/__tests__/compare-version.test.d.ts.map +0 -0
  868. /package/{esm → dist}/types/utils/__tests__/object.test.d.ts +0 -0
  869. /package/{esm → dist}/types/utils/__tests__/object.test.d.ts.map +0 -0
  870. /package/{esm → dist}/types/utils/__tests__/sdp.test.d.ts +0 -0
  871. /package/{esm → dist}/types/utils/__tests__/sdp.test.d.ts.map +0 -0
  872. /package/{esm → dist}/types/utils/__tests__/string.test.d.ts +0 -0
  873. /package/{esm → dist}/types/utils/__tests__/string.test.d.ts.map +0 -0
  874. /package/{esm → dist}/types/utils/api-requester.d.ts +0 -0
  875. /package/{esm → dist}/types/utils/api-requester.d.ts.map +0 -0
  876. /package/{esm → dist}/types/utils/array.d.ts +0 -0
  877. /package/{esm → dist}/types/utils/array.d.ts.map +0 -0
  878. /package/{esm → dist}/types/utils/compare-version.d.ts +0 -0
  879. /package/{esm → dist}/types/utils/compare-version.d.ts.map +0 -0
  880. /package/{esm → dist}/types/utils/isMobile.d.ts +0 -0
  881. /package/{esm → dist}/types/utils/isMobile.d.ts.map +0 -0
  882. /package/{esm → dist}/types/utils/new-from.d.ts +0 -0
  883. /package/{esm → dist}/types/utils/new-from.d.ts.map +0 -0
  884. /package/{esm → dist}/types/utils/object.d.ts +0 -0
  885. /package/{esm → dist}/types/utils/object.d.ts.map +0 -0
  886. /package/{esm → dist}/types/utils/once.d.ts +0 -0
  887. /package/{esm → dist}/types/utils/once.d.ts.map +0 -0
  888. /package/{esm → dist}/types/utils/sdp.d.ts +0 -0
  889. /package/{esm → dist}/types/utils/sdp.d.ts.map +0 -0
  890. /package/{esm → dist}/types/utils/string.d.ts +0 -0
  891. /package/{esm → dist}/types/utils/string.d.ts.map +0 -0
  892. /package/{esm → dist}/types/utils/update-from.d.ts +0 -0
  893. /package/{esm → dist}/types/utils/update-from.d.ts.map +0 -0
  894. /package/{esm → dist}/types/utils/webrtc.d.ts +0 -0
  895. /package/{esm → dist}/types/utils/webrtc.d.ts.map +0 -0
  896. /package/{esm → dist}/types/web-rtc-client.d.ts +0 -0
  897. /package/{esm → dist}/types/web-rtc-client.d.ts.map +0 -0
  898. /package/{esm → dist}/types/websocket-client.d.ts +0 -0
  899. /package/{esm → dist}/types/websocket-client.d.ts.map +0 -0
@@ -1,2239 +0,0 @@
1
- "use strict";
2
- /* eslint-disable class-methods-use-this, no-param-reassign, max-classes-per-file, no-underscore-dangle */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
- return new (P || (P = Promise))(function (resolve, reject) {
29
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
- step((generator = generator.apply(thisArg, _arguments || [])).next());
33
- });
34
- };
35
- var __rest = (this && this.__rest) || function (s, e) {
36
- var t = {};
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
- t[p] = s[p];
39
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
- t[p[i]] = s[p[i]];
43
- }
44
- return t;
45
- };
46
- var __importDefault = (this && this.__importDefault) || function (mod) {
47
- return (mod && mod.__esModule) ? mod : { "default": mod };
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.CanceledCallError = exports.transportEvents = exports.events = exports.replaceLocalIpModifier = void 0;
51
- /* global window, document, navigator */
52
- require("webrtc-adapter");
53
- const user_agent_state_1 = require("sip.js/lib/api/user-agent-state");
54
- const parser_1 = require("sip.js/lib/core/messages/parser");
55
- const constants_1 = require("sip.js/lib/core/messages/methods/constants");
56
- const uri_1 = require("sip.js/lib/grammar/uri");
57
- const user_agent_1 = require("sip.js/lib/api/user-agent");
58
- const modifiers_1 = require("sip.js/lib/platform/web/modifiers/modifiers");
59
- const session_dialog_1 = require("sip.js/lib/core/dialogs/session-dialog");
60
- const messager_1 = require("sip.js/lib/api/messager");
61
- const registerer_state_1 = require("sip.js/lib/api/registerer-state");
62
- const session_state_1 = require("sip.js/lib/api/session-state");
63
- const transport_state_1 = require("sip.js/lib/api/transport-state");
64
- const peer_connection_configuration_default_1 = require("sip.js/lib/platform/web/session-description-handler/peer-connection-configuration-default");
65
- const getstats_1 = __importDefault(require("getstats"));
66
- const api_1 = require("sip.js/lib/api");
67
- const WazoSessionDescriptionHandler_1 = __importStar(require("./lib/WazoSessionDescriptionHandler"));
68
- const Emitter_1 = __importDefault(require("./utils/Emitter"));
69
- const api_client_1 = __importDefault(require("./api-client"));
70
- const IssueReporter_1 = __importDefault(require("./service/IssueReporter"));
71
- const Heartbeat_1 = __importDefault(require("./utils/Heartbeat"));
72
- const sdp_1 = require("./utils/sdp");
73
- const array_1 = require("./utils/array");
74
- // We need to replace 0.0.0.0 to 127.0.0.1 in the sdp to avoid MOH during a createOffer.
75
- const replaceLocalIpModifier = (description) => Promise.resolve(Object.assign(Object.assign({}, JSON.parse(JSON.stringify(description))), { sdp: description.sdp.replace('c=IN IP4 0.0.0.0', 'c=IN IP4 127.0.0.1') }));
76
- exports.replaceLocalIpModifier = replaceLocalIpModifier;
77
- const DEFAULT_ICE_TIMEOUT = 3000;
78
- const SEND_STATS_DELAY = 5000;
79
- const states = ['STATUS_NULL', 'STATUS_NEW', 'STATUS_CONNECTING', 'STATUS_CONNECTED', 'STATUS_COMPLETED'];
80
- const logger = IssueReporter_1.default ? IssueReporter_1.default.loggerFor('webrtc-client') : console;
81
- const statsLogger = IssueReporter_1.default ? IssueReporter_1.default.loggerFor('webrtc-stats') : console;
82
- // events
83
- const REGISTERED = 'registered';
84
- const UNREGISTERED = 'unregistered';
85
- const REGISTRATION_FAILED = 'registrationFailed';
86
- const INVITE = 'invite';
87
- const CONNECTED = 'connected';
88
- const DISCONNECTED = 'disconnected';
89
- const TRANSPORT_ERROR = 'transportError';
90
- const MESSAGE = 'message';
91
- const ACCEPTED = 'accepted';
92
- const REJECTED = 'rejected';
93
- const ON_TRACK = 'onTrack';
94
- const ON_PROGRESS = 'onProgress';
95
- const ON_EARLY_MEDIA = 'onEarlyMedia';
96
- const ON_REINVITE = 'reinvite';
97
- const ON_ERROR = 'onError';
98
- const ON_SCREEN_SHARING_REINVITE = 'onScreenSharingReinvite';
99
- const ON_NETWORK_STATS = 'onNetworkStats';
100
- const ON_DISCONNECTED = 'onDisconnected';
101
- exports.events = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
102
- exports.transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
103
- class CanceledCallError extends Error {
104
- }
105
- exports.CanceledCallError = CanceledCallError;
106
- const MAX_REGISTER_TRIES = 5;
107
- // setting a 24hr timeout and letting the backend define the actual value
108
- const NO_ANSWER_TIMEOUT = 60 * 60 * 24; // in seconds
109
- class WebRTCClient extends Emitter_1.default {
110
- static isAPrivateIp(ip) {
111
- const regex = /^(?:10|127|172\.(?:1[6-9]|2[0-9]|3[01])|192\.168)\..*/;
112
- return regex.exec(ip) == null;
113
- }
114
- static getIceServers(ip) {
115
- if (WebRTCClient.isAPrivateIp(ip)) {
116
- return [{
117
- urls: ['stun:stun.l.google.com:19302', 'stun:stun4.l.google.com:19302'],
118
- }];
119
- }
120
- return [];
121
- }
122
- constructor(config, session, uaConfigOverrides) {
123
- super();
124
- // For debug purpose
125
- this.clientId = Math.ceil(Math.random() * 1000);
126
- logger.info('sdk webrtc constructor', { clientId: this.clientId });
127
- this.uaConfigOverrides = uaConfigOverrides;
128
- this.config = config;
129
- this.skipRegister = config.skipRegister;
130
- this._buildConfig(config, session).then((newConfig) => {
131
- this.config = newConfig;
132
- this.userAgent = this.createUserAgent(uaConfigOverrides);
133
- });
134
- this.audioOutputDeviceId = config.audioDeviceOutput;
135
- this.audioOutputVolume = config.audioOutputVolume || 1;
136
- if (config.media) {
137
- this.configureMedia(config.media);
138
- this.setMediaConstraints({
139
- audio: config.media.audio,
140
- video: config.media.video,
141
- });
142
- }
143
- this.heldSessions = {};
144
- this.statsIntervals = {};
145
- this.connectionPromise = null;
146
- this.sipSessions = {};
147
- this.conferences = {};
148
- this.networkMonitoringInterval = {};
149
- this.sessionNetworkStats = {};
150
- this.forceClosed = false;
151
- this._boundOnHeartbeat = this._onHeartbeat.bind(this);
152
- this.heartbeat = new Heartbeat_1.default(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
153
- this.heartbeat.setSendHeartbeat(this.pingServer.bind(this));
154
- this.heartbeat.setOnHeartbeatTimeout(this._onHeartbeatTimeout.bind(this));
155
- // sugar
156
- this.REGISTERED = REGISTERED;
157
- this.UNREGISTERED = UNREGISTERED;
158
- this.REGISTRATION_FAILED = REGISTRATION_FAILED;
159
- this.INVITE = INVITE;
160
- this.CONNECTED = CONNECTED;
161
- this.DISCONNECTED = DISCONNECTED;
162
- this.TRANSPORT_ERROR = TRANSPORT_ERROR;
163
- this.MESSAGE = MESSAGE;
164
- this.ACCEPTED = ACCEPTED;
165
- this.REJECTED = REJECTED;
166
- this.ON_TRACK = ON_TRACK;
167
- this.ON_REINVITE = ON_REINVITE;
168
- this.ON_ERROR = ON_ERROR;
169
- this.ON_SCREEN_SHARING_REINVITE = ON_SCREEN_SHARING_REINVITE;
170
- this.ON_NETWORK_STATS = ON_NETWORK_STATS;
171
- this.ON_DISCONNECTED = ON_DISCONNECTED;
172
- this.ON_EARLY_MEDIA = ON_EARLY_MEDIA;
173
- this.ON_PROGRESS = ON_PROGRESS;
174
- }
175
- configureMedia(media) {
176
- this.hasAudio = !!media.audio;
177
- this.audioStreams = {};
178
- this.audioElements = {};
179
- }
180
- setMediaConstraints(media) {
181
- this.video = media.video;
182
- this.audio = media.audio;
183
- }
184
- createUserAgent(uaConfigOverrides) {
185
- var _a;
186
- const uaOptions = this._createUaOptions(uaConfigOverrides);
187
- logger.info('sdk webrtc, creating UA', {
188
- uaOptions: Object.assign(Object.assign({}, uaOptions), { authorizationPassword: `${(_a = uaOptions === null || uaOptions === void 0 ? void 0 : uaOptions.authorizationPassword) === null || _a === void 0 ? void 0 : _a.slice(0, 5)}xxxx` }),
189
- clientId: this.clientId,
190
- });
191
- uaOptions.delegate = {
192
- onConnect: this.onConnect.bind(this),
193
- onDisconnect: this.onDisconnect.bind(this),
194
- onInvite: (invitation) => {
195
- logger.info('sdk webrtc on invite', {
196
- method: 'delegate.onInvite',
197
- clientId: this.clientId,
198
- id: this.getSipSessionId(invitation),
199
- remoteURI: invitation.remoteURI,
200
- });
201
- this._setupSession(invitation);
202
- const shouldAutoAnswer = !!invitation.request.getHeader('alert-info');
203
- this.eventEmitter.emit(INVITE, invitation, this.sessionWantsToDoVideo(invitation), shouldAutoAnswer);
204
- },
205
- };
206
- const ua = new user_agent_1.UserAgent(uaOptions);
207
- ua.start();
208
- if (ua.transport && ua.transport.connectPromise) {
209
- ua.transport.connectPromise.catch((e) => {
210
- logger.warn('Transport connect error', e);
211
- });
212
- }
213
- ua.transport.onMessage = (rawMessage) => {
214
- const message = parser_1.Parser.parseMessage(rawMessage, ua.transport.logger);
215
- // We have to re-sent the message to the UA ...
216
- // @ts-ignore: private
217
- ua.onTransportMessage(rawMessage);
218
- // And now do what we want with the message
219
- this.eventEmitter.emit(MESSAGE, message);
220
- if (message && message.method === constants_1.C.MESSAGE) {
221
- // We have to manually reply to MESSAGE with a 200 OK or Asterisk will hangup.
222
- ua.userAgentCore.replyStateless(message, {
223
- statusCode: 200,
224
- });
225
- }
226
- };
227
- return ua;
228
- }
229
- isConnected() {
230
- var _a;
231
- return Boolean((_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.isConnected());
232
- }
233
- isConnecting() {
234
- var _a, _b;
235
- return ((_b = (_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.state) === transport_state_1.TransportState.Connecting;
236
- }
237
- isRegistered() {
238
- return Boolean(this.registerer && this.registerer.state === registerer_state_1.RegistererState.Registered);
239
- }
240
- onConnect() {
241
- var _a;
242
- logger.info('sdk webrtc connected', { method: 'delegate.onConnect', clientId: this.clientId });
243
- this.eventEmitter.emit(CONNECTED);
244
- // @ts-ignore: private
245
- if (!this.isRegistered() && ((_a = this.registerer) === null || _a === void 0 ? void 0 : _a.waiting)) {
246
- // @ts-ignore: private
247
- this.registerer.waitingToggle(false);
248
- }
249
- return this.register();
250
- }
251
- onDisconnect(error) {
252
- return __awaiter(this, void 0, void 0, function* () {
253
- var _a;
254
- logger.info('sdk webrtc disconnected', { method: 'delegate.onConnect', clientId: this.clientId, error });
255
- this.connectionPromise = null;
256
- // The UA will attempt to reconnect automatically when an error occurred
257
- this.eventEmitter.emit(DISCONNECTED, error);
258
- if (this.isRegistered()) {
259
- yield this.unregister();
260
- // @ts-ignore: private
261
- if ((_a = this.registerer) === null || _a === void 0 ? void 0 : _a.waiting) {
262
- // @ts-ignore: private
263
- this.registerer.waitingToggle(false);
264
- }
265
- this.eventEmitter.emit(UNREGISTERED);
266
- }
267
- });
268
- }
269
- register() {
270
- return __awaiter(this, arguments, void 0, function* (tries = 0) {
271
- var _a;
272
- const logInfo = {
273
- clientId: this.clientId,
274
- userAgent: !!this.userAgent,
275
- registered: this.isRegistered(),
276
- connectionPromise: !!this.connectionPromise,
277
- registerer: !!this.registerer,
278
- // @ts-ignore: private
279
- waiting: this.registerer && this.registerer.waiting,
280
- tries,
281
- skipRegister: this.skipRegister,
282
- };
283
- this.forceClosed = false;
284
- if (this.skipRegister) {
285
- logger.info('sdk webrtc skip register...', logInfo);
286
- return Promise.resolve();
287
- }
288
- logger.info('sdk webrtc registering...', logInfo);
289
- if (!this.userAgent) {
290
- logger.info('sdk webrtc recreating User Agent');
291
- this.userAgent = this.createUserAgent(this.uaConfigOverrides);
292
- }
293
- if (!this.userAgent || this.isRegistered()) {
294
- logger.info('sdk webrtc registering aborted, already registered or no UA can be created');
295
- return Promise.resolve();
296
- }
297
- // @ts-ignore: private
298
- if (this.connectionPromise || ((_a = this.registerer) === null || _a === void 0 ? void 0 : _a.waiting)) {
299
- logger.info('sdk webrtc registering aborted due to a registration in progress.', { clientId: this.clientId });
300
- return Promise.resolve();
301
- }
302
- const registerOptions = this._isWeb() ? {} : {
303
- extraContactHeaderParams: ['mobility=mobile'],
304
- };
305
- const onRegisterFailed = () => {
306
- logger.info('sdk webrtc registering failed', {
307
- tries,
308
- clientId: this.clientId,
309
- registerer: !!this.registerer,
310
- forceClosed: this.forceClosed,
311
- });
312
- if (this.forceClosed) {
313
- return;
314
- }
315
- this.connectionPromise = null;
316
- // @ts-ignore: private
317
- if (this.registerer && this.registerer.waiting) {
318
- // @ts-ignore: private
319
- this.registerer.waitingToggle(false);
320
- }
321
- if (tries <= MAX_REGISTER_TRIES) {
322
- logger.info('sdk webrtc registering, retrying...', { clientId: this.clientId, tries });
323
- setTimeout(() => this.register(tries + 1), 300);
324
- }
325
- };
326
- return this._connectIfNeeded().then(() => {
327
- // Avoid race condition with the close method called just before register and setting userAgent to null
328
- // during the resolution of the promise.
329
- if (!this.userAgent) {
330
- logger.info('sdk webrtc recreating User Agent after connection');
331
- this.userAgent = this.createUserAgent(this.uaConfigOverrides);
332
- }
333
- logger.info('sdk webrtc registering, transport connected', { registerOptions, ua: !!this.userAgent, clientId: this.clientId });
334
- this.registerer = new api_1.Registerer(this.userAgent, registerOptions);
335
- this.connectionPromise = null;
336
- this._monkeyPatchRegisterer(this.registerer);
337
- // Bind registerer events
338
- this.registerer.stateChange.addListener(newState => {
339
- logger.info('sdk webrtc registering, state changed', { newState, clientId: this.clientId });
340
- if (newState === registerer_state_1.RegistererState.Registered && this.registerer && this.registerer.state === registerer_state_1.RegistererState.Registered) {
341
- this.eventEmitter.emit(REGISTERED);
342
- }
343
- else if (newState === registerer_state_1.RegistererState.Unregistered) {
344
- this.eventEmitter.emit(UNREGISTERED);
345
- }
346
- });
347
- const options = {
348
- requestDelegate: {
349
- onReject: (response) => {
350
- logger.error('sdk webrtc registering, rejected', { clientId: this.clientId, response });
351
- onRegisterFailed();
352
- },
353
- },
354
- };
355
- return this.registerer.register(options).catch(e => {
356
- logger.error('sdk webrtc registering, error', e);
357
- this.eventEmitter.emit(REGISTRATION_FAILED);
358
- return e;
359
- });
360
- }).catch(error => {
361
- logger.error('sdk webrtc registering, transport error', error);
362
- onRegisterFailed();
363
- });
364
- });
365
- }
366
- // Monkey patching sip.js to avoid issues during register.onReject
367
- _monkeyPatchRegisterer(registerer) {
368
- if (!registerer) {
369
- return;
370
- }
371
- // @ts-ignore: private
372
- const oldWaitingToggle = registerer.waitingToggle.bind(registerer);
373
- // @ts-ignore: private
374
- const oldUnregistered = registerer.unregistered.bind(registerer);
375
- // @ts-ignore: private
376
- registerer.waitingToggle = (waiting) => {
377
- // @ts-ignore: private
378
- if (!registerer || registerer.waiting === waiting) {
379
- return;
380
- }
381
- oldWaitingToggle(waiting);
382
- };
383
- // @ts-ignore: private
384
- registerer.unregistered = () => {
385
- if (!registerer || registerer.state === registerer_state_1.RegistererState.Terminated) {
386
- return;
387
- }
388
- oldUnregistered();
389
- };
390
- }
391
- unregister() {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- logger.info('sdk webrtc unregistering..', {
394
- clientId: this.clientId,
395
- userAgent: !!this.userAgent,
396
- registerer: !!this.registerer,
397
- });
398
- try {
399
- return new Promise((resolve, reject) => {
400
- if (!this.registerer) {
401
- return resolve();
402
- }
403
- const onRegisterStateChange = (state) => {
404
- if (state === registerer_state_1.RegistererState.Unregistered) {
405
- logger.info('sdk webrtc unregistered', { clientId: this.clientId });
406
- if (this.registerer) {
407
- this.registerer.stateChange.addListener(onRegisterStateChange);
408
- }
409
- this._cleanupRegister();
410
- resolve();
411
- }
412
- };
413
- this.registerer.stateChange.addListener(onRegisterStateChange);
414
- this.registerer.unregister().then().catch(e => {
415
- logger.error('sdk webrtc unregistering, promise error', e);
416
- this._cleanupRegister();
417
- reject();
418
- });
419
- });
420
- }
421
- catch (e) {
422
- logger.error('sdk webrtc unregistering, error', e);
423
- // Avoid issue with `undefined is not an object (evaluating 'new.target.prototype')` when triggering a new
424
- // error when the registerer is in a bad state
425
- this._cleanupRegister();
426
- }
427
- });
428
- }
429
- stop() {
430
- logger.info('sdk webrtc stop', { clientId: this.clientId, userAgent: !!this.userAgent });
431
- if (!this.userAgent) {
432
- return Promise.resolve();
433
- }
434
- return this.userAgent.stop().then(() => {
435
- return this._cleanupRegister();
436
- }).catch(e => {
437
- logger.warn('sdk webrtc stop, error', {
438
- message: e.message,
439
- stack: e.stack,
440
- });
441
- });
442
- }
443
- call(number, enableVideo, audioOnly = false, conference = false, options = {}) {
444
- logger.info('sdk webrtc creating call', {
445
- clientId: this.clientId,
446
- number,
447
- enableVideo,
448
- audioOnly,
449
- conference,
450
- options,
451
- });
452
- const inviterOptions = Object.assign({ sessionDescriptionHandlerOptionsReInvite: {
453
- conference,
454
- audioOnly,
455
- }, earlyMedia: true }, options);
456
- if (audioOnly) {
457
- inviterOptions.sessionDescriptionHandlerModifiersReInvite = [modifiers_1.stripVideo];
458
- }
459
- const uri = this._makeURI(number);
460
- let session = null;
461
- if (uri) {
462
- session = this.userAgent ? new api_1.Inviter(this.userAgent, uri, inviterOptions) : null;
463
- }
464
- else {
465
- logger.error('Null URI');
466
- }
467
- if (session) {
468
- this.storeSipSession(session);
469
- this._setupSession(session);
470
- }
471
- if (conference) {
472
- this.conferences[this.getSipSessionId(session)] = true;
473
- }
474
- const inviteOptions = {
475
- requestDelegate: {
476
- onAccept: (response) => {
477
- var _a;
478
- if ((_a = session === null || session === void 0 ? void 0 : session.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.peerConnection) {
479
- (session === null || session === void 0 ? void 0 : session.sessionDescriptionHandler).peerConnection.sfu = conference;
480
- }
481
- this._onAccepted(session, response.session, true);
482
- },
483
- onProgress: (payload) => {
484
- this._onProgress(payload.session, payload.message.statusCode === 183);
485
- },
486
- onReject: (response) => {
487
- logger.info('on call rejected', {
488
- id: this.getSipSessionId(session),
489
- // @ts-ignore: fromTag does not exist
490
- fromTag: session === null || session === void 0 ? void 0 : session.fromTag,
491
- });
492
- this._stopSendingStats(session);
493
- this.stopNetworkMonitoring(session);
494
- this.eventEmitter.emit(REJECTED, session, response);
495
- },
496
- },
497
- sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false, conference),
498
- };
499
- if (inviteOptions.sessionDescriptionHandlerOptions) {
500
- inviteOptions.sessionDescriptionHandlerOptions.audioOnly = audioOnly;
501
- }
502
- inviteOptions.sessionDescriptionHandlerModifiers = [exports.replaceLocalIpModifier];
503
- if (audioOnly) {
504
- inviteOptions.sessionDescriptionHandlerModifiers.push(modifiers_1.stripVideo);
505
- }
506
- if (session) {
507
- // Do not await invite here or we'll miss the Establishing state transition
508
- // @ts-ignore: Property 'invitePromise' does not exist
509
- session.invitePromise = session.invite(inviteOptions).catch((e) => {
510
- logger.warn('sdk webrtc creating call, error', e);
511
- });
512
- }
513
- return session;
514
- }
515
- answer(session, enableVideo) {
516
- logger.info('sdk webrtc answer call', {
517
- clientId: this.clientId,
518
- id: this.getSipSessionId(session),
519
- enableVideo,
520
- });
521
- if (!session || !session.accept) {
522
- const error = 'No session to answer, or not an invitation';
523
- logger.warn(error);
524
- return Promise.reject(new Error(error));
525
- }
526
- const options = {
527
- sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false),
528
- };
529
- return this._accept(session, options).then(() => {
530
- // @ts-ignore: private
531
- if (session.isCanceled) {
532
- const message = 'accepted a canceled session (or was canceled during the accept phase).';
533
- logger.error(message, {
534
- id: this.getSipSessionId(session),
535
- });
536
- this.onCallEnded(session);
537
- throw new CanceledCallError(message);
538
- }
539
- logger.info('sdk webrtc answer, accepted.');
540
- this._onAccepted(session);
541
- }).catch(e => {
542
- logger.error(`answer call error for ${this.getSipSessionId(session)}`, e);
543
- throw e;
544
- });
545
- }
546
- hangup(session) {
547
- return __awaiter(this, void 0, void 0, function* () {
548
- const { state, id } = session;
549
- logger.info('sdk webrtc hangup call', { clientId: this.clientId, id, state });
550
- try {
551
- this._stopSendingStats(session);
552
- this._cleanupMedia(session);
553
- delete this.sipSessions[this.getSipSessionId(session)];
554
- // Check if Invitation or Inviter (Invitation = incoming call)
555
- const isInviter = session instanceof api_1.Inviter;
556
- // @see github.com/onsip/SIP.js/blob/f11dfd584bc9788ccfc94e03034020672b738975/src/platform/web/simple-user/simple-user.ts#L1004
557
- const actions = {
558
- [session_state_1.SessionState.Initial]: isInviter ? this._cancel.bind(this, session) : this._reject.bind(this, session),
559
- [session_state_1.SessionState.Establishing]: isInviter ? this._cancel.bind(this, session) : this._reject.bind(this, session),
560
- [session_state_1.SessionState.Established]: this._bye.bind(this, session),
561
- };
562
- // Handle different session status
563
- if (actions[state]) {
564
- return yield actions[state]();
565
- }
566
- return yield this._bye(session);
567
- }
568
- catch (error) {
569
- logger.warn('sdk webrtc hangup, error', error);
570
- }
571
- return Promise.resolve(null);
572
- });
573
- }
574
- getStats(session) {
575
- return __awaiter(this, void 0, void 0, function* () {
576
- var _a;
577
- const pc = (_a = session.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.peerConnection;
578
- if (!pc) {
579
- return null;
580
- }
581
- return pc.getStats(null);
582
- });
583
- }
584
- // Fetch and emit an event at `interval` with session network stats
585
- startNetworkMonitoring(session, interval = 1000) {
586
- const sessionId = this.getSipSessionId(session);
587
- logger.info('starting network inspection', {
588
- id: sessionId,
589
- clientId: this.clientId,
590
- });
591
- this.sessionNetworkStats[sessionId] = [];
592
- this.networkMonitoringInterval[sessionId] = setInterval(() => this._fetchNetworkStats(sessionId), interval);
593
- }
594
- stopNetworkMonitoring(session) {
595
- const sessionId = this.getSipSessionId(session);
596
- const exists = (sessionId in this.networkMonitoringInterval);
597
- logger.info('stopping network inspection', {
598
- clientId: this.clientId,
599
- id: sessionId,
600
- exists,
601
- });
602
- if (exists) {
603
- clearInterval(this.networkMonitoringInterval[sessionId]);
604
- delete this.networkMonitoringInterval[sessionId];
605
- delete this.sessionNetworkStats[sessionId];
606
- }
607
- }
608
- reject(session) {
609
- return __awaiter(this, void 0, void 0, function* () {
610
- logger.info('sdk webrtc reject call', {
611
- clientId: this.clientId,
612
- id: this.getSipSessionId(session),
613
- });
614
- try {
615
- if (session instanceof api_1.Invitation) {
616
- return this._reject(session);
617
- }
618
- if (session instanceof api_1.Inviter) {
619
- return this._cancel(session);
620
- }
621
- }
622
- catch (e) {
623
- logger.warn('Error when rejecting call', e.message, e.stack);
624
- }
625
- });
626
- }
627
- close() {
628
- return __awaiter(this, arguments, void 0, function* (force = false) {
629
- logger.info('sdk webrtc closing client', {
630
- clientId: this.clientId,
631
- userAgent: !!this.userAgent,
632
- force,
633
- });
634
- this.forceClosed = force;
635
- this._cleanupMedia();
636
- this.connectionPromise = null;
637
- Object.values(this.audioElements).forEach((audioElement) => {
638
- // eslint-disable-next-line
639
- audioElement.srcObject = null;
640
- audioElement.pause();
641
- });
642
- this.audioElements = {};
643
- if (!this.userAgent) {
644
- return;
645
- }
646
- this.stopHeartbeat();
647
- if (this.userAgent) {
648
- this.userAgent.delegate = undefined;
649
- }
650
- // @ts-ignore: removeAllListeners does not exist
651
- this.userAgent.stateChange.removeAllListeners();
652
- yield this._disconnectTransport(force);
653
- this._cleanupRegister();
654
- try {
655
- // Prevent `Connect aborted.` error when disconnecting
656
- this.userAgent.transport.connectReject = () => { };
657
- // Don't wait here, It can take ~30s to stop ...
658
- this.userAgent.stop().catch(console.error);
659
- }
660
- catch (_) { // Avoid to raise exception when trying to close with hanged-up sessions remaining
661
- // eg: "INVITE not rejectable in state Completed"
662
- }
663
- this.userAgent = null;
664
- logger.info('sdk webrtc client closed', { clientId: this.clientId });
665
- });
666
- }
667
- getNumber(session) {
668
- if (!session) {
669
- return null;
670
- }
671
- // @ts-ignore: private
672
- return session.remoteIdentity.uri._normal.user;
673
- }
674
- mute(session) {
675
- logger.info('sdk webrtc mute', {
676
- id: this.getSipSessionId(session),
677
- });
678
- this._toggleAudio(session, true);
679
- }
680
- unmute(session) {
681
- logger.info('sdk webrtc unmute', {
682
- id: this.getSipSessionId(session),
683
- });
684
- this._toggleAudio(session, false);
685
- }
686
- isAudioMuted(session) {
687
- if (!session || !session.sessionDescriptionHandler) {
688
- return false;
689
- }
690
- let muted = true;
691
- const pc = session.sessionDescriptionHandler.peerConnection;
692
- if (!pc) {
693
- return false;
694
- }
695
- if (pc.getSenders) {
696
- if (!pc.getSenders().length) {
697
- return false;
698
- }
699
- pc.getSenders().forEach((sender) => {
700
- if (sender && sender.track && sender.track.kind === 'audio') {
701
- muted = muted && !sender.track.enabled;
702
- }
703
- });
704
- }
705
- else {
706
- if (!pc.getLocalStreams().length) {
707
- return false;
708
- }
709
- pc.getLocalStreams().forEach((stream) => {
710
- stream.getAudioTracks().forEach(track => {
711
- muted = muted && !track.enabled;
712
- });
713
- });
714
- }
715
- return muted;
716
- }
717
- toggleCameraOn(session) {
718
- logger.info('sdk webrtc toggle camera on', {
719
- id: this.getSipSessionId(session),
720
- });
721
- this._toggleVideo(session, false);
722
- }
723
- toggleCameraOff(session) {
724
- logger.info('sdk webrtc toggle camera off', {
725
- id: this.getSipSessionId(session),
726
- });
727
- this._toggleVideo(session, true);
728
- }
729
- hold(session, isConference = false, hadVideo = false) {
730
- const sessionId = this.getSipSessionId(session);
731
- const hasVideo = hadVideo || this.hasLocalVideo(sessionId);
732
- logger.info('sdk webrtc hold', {
733
- sessionId,
734
- keys: Object.keys(this.heldSessions),
735
- // @ts-ignore: private
736
- pendingReinvite: !!session.pendingReinvite,
737
- isConference,
738
- hasVideo,
739
- });
740
- if (sessionId in this.heldSessions) {
741
- return Promise.resolve();
742
- }
743
- // @ts-ignore: private
744
- if (session.pendingReinvite) {
745
- return Promise.resolve();
746
- }
747
- this.heldSessions[sessionId] = {
748
- hasVideo,
749
- isConference,
750
- };
751
- // We should also mute the call, because when holding a call during a voicemail, the audio is still sent with the
752
- // `sendonly` direction
753
- this.mute(session);
754
- session.sessionDescriptionHandlerOptionsReInvite = {
755
- hold: true,
756
- conference: isConference,
757
- };
758
- const options = this.getMediaConfiguration(false, isConference);
759
- if (!this._isWeb()) {
760
- options.sessionDescriptionHandlerModifiers = [modifiers_1.holdModifier];
761
- }
762
- options.sessionDescriptionHandlerOptions = {
763
- constraints: options.constraints,
764
- hold: true,
765
- conference: isConference,
766
- };
767
- // Avoid sdh to create a new stream
768
- if (session.sessionDescriptionHandler) {
769
- // @ts-ignore: private
770
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
771
- }
772
- // Send re-INVITE
773
- return session.invite(options).catch((e) => {
774
- logger.warn('sdk webrtc re-invite during hold, error', e);
775
- });
776
- }
777
- unhold(session, isConference = false) {
778
- const sessionId = this.getSipSessionId(session);
779
- const hasVideo = sessionId in this.heldSessions && this.heldSessions[sessionId].hasVideo;
780
- logger.info('sdk webrtc unhold', {
781
- sessionId,
782
- keys: Object.keys(this.heldSessions),
783
- // @ts-ignore: private
784
- pendingReinvite: !!session.pendingReinvite,
785
- isConference,
786
- hasVideo,
787
- });
788
- // @ts-ignore: private
789
- if (session.pendingReinvite) {
790
- return Promise.resolve();
791
- }
792
- this.unmute(session);
793
- delete this.heldSessions[this.getSipSessionId(session)];
794
- session.sessionDescriptionHandlerOptionsReInvite = {
795
- hold: false,
796
- conference: isConference,
797
- };
798
- const options = this.getMediaConfiguration(false, isConference);
799
- if (!this._isWeb()) {
800
- // We should sent an empty `sessionDescriptionHandlerModifiers` or sip.js will take the last sent modifiers
801
- // (eg: holdModifier)
802
- options.sessionDescriptionHandlerModifiers = [];
803
- }
804
- options.sessionDescriptionHandlerOptions = {
805
- constraints: options.constraints,
806
- hold: false,
807
- conference: isConference,
808
- };
809
- // Send re-INVITE
810
- return session.invite(options).catch((e) => {
811
- logger.warn('sdk webrtc re-invite during resume, error', e);
812
- });
813
- }
814
- // Returns true if a re-INVITE is required
815
- upgradeToVideo(session, constraints, isConference) {
816
- return __awaiter(this, void 0, void 0, function* () {
817
- var _a, _b;
818
- const pc = (_a = session.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.peerConnection;
819
- // Check if a video sender already exists
820
- let videoSender;
821
- if (isConference) {
822
- // We search for the last transceiver without `video-` in the mid (video- means remote transceiver)
823
- const transceivers = (pc === null || pc === void 0 ? void 0 : pc.getTransceivers()) || [];
824
- const transceiverIdx = (0, array_1.lastIndexOf)(transceivers, transceiver => transceiver.sender.track === null && transceiver.mid && transceiver.mid.indexOf('video') === -1);
825
- videoSender = transceiverIdx !== -1 ? transceivers[transceiverIdx].sender : null;
826
- }
827
- else {
828
- videoSender = pc && pc.getSenders && pc.getSenders().find((sender) => sender.track === null);
829
- }
830
- if (!videoSender) {
831
- // When no video sender found, it means that we're in the first video upgrade in 1:1
832
- return;
833
- }
834
- // Reuse bidirectional video stream
835
- const newStream = yield this.getStreamFromConstraints(constraints);
836
- if (!newStream) {
837
- console.warn(`Can't create media stream with: ${JSON.stringify(constraints || {})}`);
838
- return;
839
- }
840
- // Add previous local audio track
841
- if (constraints && !constraints.audio) {
842
- const localVideoStream = (_b = session.sessionDescriptionHandler) === null || _b === void 0 ? void 0 : _b.localMediaStream;
843
- const localAudioTrack = localVideoStream.getTracks().find(track => track.kind === 'audio');
844
- if (localAudioTrack) {
845
- newStream.addTrack(localAudioTrack);
846
- }
847
- }
848
- const videoTrack = newStream.getVideoTracks()[0];
849
- if (videoTrack) {
850
- videoSender.replaceTrack(videoTrack);
851
- }
852
- this.setLocalMediaStream(this.getSipSessionId(session), newStream);
853
- return newStream;
854
- });
855
- }
856
- downgradeToAudio(session) {
857
- // Release local video stream when downgrading to audio
858
- const sessionDescriptionHandler = session.sessionDescriptionHandler;
859
- const localStream = sessionDescriptionHandler === null || sessionDescriptionHandler === void 0 ? void 0 : sessionDescriptionHandler.localMediaStream;
860
- const pc = sessionDescriptionHandler === null || sessionDescriptionHandler === void 0 ? void 0 : sessionDescriptionHandler.peerConnection;
861
- const videoTracks = localStream.getVideoTracks();
862
- // Remove video senders
863
- if (pc === null || pc === void 0 ? void 0 : pc.getSenders) {
864
- pc.getSenders().filter((sender) => sender.track && sender.track.kind === 'video').forEach((videoSender) => {
865
- videoSender.replaceTrack(null);
866
- });
867
- }
868
- videoTracks.forEach((videoTrack) => {
869
- videoTrack.enabled = false;
870
- videoTrack.stop();
871
- localStream.removeTrack(videoTrack);
872
- });
873
- }
874
- getStreamFromConstraints(constraints_1) {
875
- return __awaiter(this, arguments, void 0, function* (constraints, conference = false) {
876
- const video = constraints && constraints.video;
877
- const { constraints: newConstraints, } = this.getMediaConfiguration(video, conference, constraints);
878
- let newStream = null;
879
- try {
880
- newStream = yield (0, WazoSessionDescriptionHandler_1.wazoMediaStreamFactory)(newConstraints);
881
- }
882
- catch (e) { // Nothing to do when the user cancel the screensharing prompt
883
- }
884
- if (!newStream) {
885
- return null;
886
- }
887
- newStream.local = true;
888
- return newStream;
889
- });
890
- }
891
- getHeldSession(sessionId) {
892
- return this.heldSessions[sessionId];
893
- }
894
- isCallHeld(session) {
895
- return this.getSipSessionId(session) in this.heldSessions;
896
- }
897
- isVideoRemotelyHeld(sessionId) {
898
- const pc = this.getPeerConnection(sessionId);
899
- const sdp = pc && pc.remoteDescription ? pc.remoteDescription.sdp : null;
900
- if (!sdp) {
901
- return false;
902
- }
903
- const videoDirection = (0, sdp_1.getVideoDirection)(sdp);
904
- return videoDirection === 'sendonly';
905
- }
906
- sendDTMF(session, tone) {
907
- if (!session.sessionDescriptionHandler) {
908
- return false;
909
- }
910
- logger.info('Sending DTMF', {
911
- id: this.getSipSessionId(session),
912
- tone,
913
- });
914
- return session.sessionDescriptionHandler.sendDtmf(tone);
915
- }
916
- message(destination, message) {
917
- const uri = this._makeURI(destination);
918
- if (!this.userAgent || !uri) {
919
- logger.warn('Null value on message', { uri, userAgent: this.userAgent });
920
- return;
921
- }
922
- const messager = new messager_1.Messager(this.userAgent, uri, message);
923
- messager.message();
924
- }
925
- transfer(session, target) {
926
- this.hold(session);
927
- logger.info('Transfering a session', {
928
- id: this.getSipSessionId(session),
929
- target,
930
- });
931
- const options = {
932
- requestDelegate: {
933
- onAccept: () => {
934
- this.hangup(session);
935
- },
936
- },
937
- };
938
- setTimeout(() => {
939
- const uri = this._makeURI(target);
940
- if (!uri) {
941
- logger.warn('transfer timeout: null URI');
942
- return;
943
- }
944
- session.refer(uri, options);
945
- }, 50);
946
- }
947
- // check https://sipjs.com/api/0.12.0/refer/referClientContext/
948
- atxfer(session) {
949
- this.hold(session);
950
- logger.info('webrtc transfer started', {
951
- id: this.getSipSessionId(session),
952
- });
953
- const result = {
954
- newSession: null,
955
- init: (target) => __awaiter(this, void 0, void 0, function* () {
956
- logger.info('webrtc transfer initialized', {
957
- id: this.getSipSessionId(session),
958
- target,
959
- });
960
- result.newSession = yield this.call(target);
961
- }),
962
- complete: () => {
963
- logger.info('webrtc transfer completed', {
964
- id: this.getSipSessionId(session),
965
- referId: this.getSipSessionId(result.newSession),
966
- });
967
- session.refer(result.newSession);
968
- },
969
- cancel: () => {
970
- this.hangup(result.newSession);
971
- this.unhold(session);
972
- },
973
- };
974
- return result;
975
- }
976
- // eslint-disable-next-line @typescript-eslint/default-param-last
977
- sendMessage(sipSession = null, body, contentType = 'text/plain') {
978
- if (!sipSession) {
979
- return;
980
- }
981
- logger.info('send WebRTC message', {
982
- sipId: this.getSipSessionId(sipSession),
983
- contentType,
984
- });
985
- try {
986
- sipSession.message({
987
- requestOptions: {
988
- body: {
989
- content: body,
990
- contentType,
991
- // @HEADSUP: contentDisposition is a required string, setting it to '' arbitrarily
992
- contentDisposition: '',
993
- },
994
- },
995
- });
996
- }
997
- catch (e) {
998
- console.warn(e);
999
- }
1000
- }
1001
- pingServer() {
1002
- var _a;
1003
- if (!this.isConnected()) {
1004
- return;
1005
- }
1006
- const core = (_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.userAgentCore;
1007
- const fromURI = this._makeURI(this.config.authorizationUser || '');
1008
- const toURI = new uri_1.URI('sip', '', this.config.host);
1009
- if (fromURI) {
1010
- const message = core === null || core === void 0 ? void 0 : core.makeOutgoingRequestMessage('OPTIONS', toURI, fromURI, toURI, {});
1011
- if (message) {
1012
- return core === null || core === void 0 ? void 0 : core.request(message);
1013
- }
1014
- logger.warn('pingServer: null message');
1015
- }
1016
- logger.warn('pingServer: null fromURI');
1017
- }
1018
- getState() {
1019
- // @ts-ignore: something fishy here: `states` content doesn't match UserAgentState at all
1020
- return this.userAgent ? states[this.userAgent.state] : user_agent_state_1.UserAgentState.Stopped;
1021
- }
1022
- getContactIdentifier() {
1023
- return this.userAgent ? `${this.userAgent.configuration.contactName}/${this.userAgent.contact.uri}` : null;
1024
- }
1025
- isFirefox() {
1026
- return this._isWeb() && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
1027
- }
1028
- changeAudioOutputVolume(volume) {
1029
- logger.info('Changing audio output volume', {
1030
- volume,
1031
- });
1032
- Object.values(this.audioElements).forEach(audioElement => {
1033
- if (audioElement instanceof HTMLAudioElement) {
1034
- // eslint-disable-next-line no-param-reassign
1035
- audioElement.volume = volume;
1036
- }
1037
- });
1038
- this.audioOutputVolume = volume;
1039
- }
1040
- changeAudioOutputDevice(id) {
1041
- return __awaiter(this, void 0, void 0, function* () {
1042
- logger.info('Changing audio output device', {
1043
- id,
1044
- });
1045
- this.audioOutputDeviceId = id;
1046
- const promises = [];
1047
- Object.values(this.audioElements).forEach(audioElement => promises.push(audioElement.setSinkId(id)));
1048
- yield Promise.allSettled(promises);
1049
- });
1050
- }
1051
- changeAudioInputDevice(id, session, force) {
1052
- return __awaiter(this, void 0, void 0, function* () {
1053
- const currentId = this.getAudioDeviceId();
1054
- logger.info('setting audio input device', {
1055
- id,
1056
- currentId,
1057
- session: !!session,
1058
- });
1059
- if (!force && id === currentId) {
1060
- return null;
1061
- }
1062
- // in order to handle an audio track change for default devices
1063
- // we need the actual id of the device (not 'default')
1064
- let deviceId = id;
1065
- if (id === 'default' && navigator.mediaDevices) {
1066
- const devices = yield navigator.mediaDevices.enumerateDevices();
1067
- const defaultDevice = devices.find(device => device.deviceId === 'default');
1068
- if (defaultDevice) {
1069
- const deviceLabel = defaultDevice.label.replace('Default - ', '');
1070
- const targetDevice = devices.find(device => device.label === deviceLabel);
1071
- if (targetDevice) {
1072
- deviceId = targetDevice.deviceId;
1073
- if (!force && deviceId === currentId) {
1074
- return null;
1075
- }
1076
- }
1077
- }
1078
- }
1079
- // let's update the local audio value
1080
- if (this.audio) {
1081
- this.audio = {
1082
- deviceId: {
1083
- exact: deviceId,
1084
- },
1085
- };
1086
- }
1087
- if (session && navigator.mediaDevices) {
1088
- const sdh = session.sessionDescriptionHandler;
1089
- const pc = sdh === null || sdh === void 0 ? void 0 : sdh.peerConnection;
1090
- const constraints = {
1091
- audio: {
1092
- deviceId: {
1093
- exact: deviceId,
1094
- },
1095
- },
1096
- };
1097
- const stream = yield navigator.mediaDevices.getUserMedia(constraints);
1098
- const audioTrack = stream.getAudioTracks()[0];
1099
- const sender = pc && pc.getSenders && pc.getSenders().find((s) => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
1100
- if (sender) {
1101
- if (sender.track) {
1102
- audioTrack.enabled = sender.track.enabled;
1103
- }
1104
- sender.replaceTrack(audioTrack);
1105
- }
1106
- return stream;
1107
- }
1108
- return null;
1109
- });
1110
- }
1111
- changeVideoInputDevice(id, session) {
1112
- return __awaiter(this, void 0, void 0, function* () {
1113
- this.setVideoInputDevice(id);
1114
- if (session) {
1115
- return this.changeSessionVideoInputDevice(id, session);
1116
- }
1117
- });
1118
- }
1119
- setVideoInputDevice(id) {
1120
- const currentId = this.getVideoDeviceId();
1121
- logger.info('setting video input device', {
1122
- id,
1123
- currentId,
1124
- });
1125
- if (id === currentId) {
1126
- return null;
1127
- }
1128
- // let's make sure we don't lose other video constraints settings -- width, height, frameRate...
1129
- const videoObject = typeof this.video === 'object' ? this.video : {};
1130
- this.video = Object.assign(Object.assign({}, videoObject), { deviceId: {
1131
- exact: id,
1132
- } });
1133
- }
1134
- changeSessionVideoInputDevice(id, session) {
1135
- if (!this.sessionWantsToDoVideo(session)) {
1136
- return Promise.resolve();
1137
- }
1138
- const sdh = session.sessionDescriptionHandler;
1139
- const pc = sdh.peerConnection;
1140
- const sessionId = this.getSipSessionId(session);
1141
- const localStream = this.getLocalStream(sessionId);
1142
- logger.info('changing video input device', {
1143
- id,
1144
- sessionId,
1145
- });
1146
- // Release old video stream
1147
- if (localStream) {
1148
- localStream.getVideoTracks()
1149
- .filter((track) => track.enabled)
1150
- .forEach((track) => track.stop());
1151
- }
1152
- const constraints = {
1153
- video: id ? {
1154
- deviceId: {
1155
- exact: id,
1156
- },
1157
- } : true,
1158
- };
1159
- return navigator.mediaDevices.getUserMedia(constraints).then((stream) => __awaiter(this, void 0, void 0, function* () {
1160
- const videoTrack = stream.getVideoTracks()[0];
1161
- let sender = pc && pc.getSenders && pc.getSenders().find((s) => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
1162
- let wasTrackEnabled = false;
1163
- if (!sender) {
1164
- sender = pc && pc.getSenders && pc.getSenders().find((s) => !s.track);
1165
- }
1166
- if (sender) {
1167
- // No video track means video not enabled
1168
- wasTrackEnabled = sender.track ? sender.track.enabled : false;
1169
- videoTrack.enabled = wasTrackEnabled;
1170
- if (!wasTrackEnabled) {
1171
- videoTrack.stop();
1172
- }
1173
- sender.replaceTrack(wasTrackEnabled ? videoTrack : null);
1174
- }
1175
- // let's update the local stream
1176
- this.eventEmitter.emit('onVideoInputChange', stream);
1177
- this.setLocalMediaStream(sessionId, stream);
1178
- return stream;
1179
- }));
1180
- }
1181
- getAudioDeviceId() {
1182
- var _a;
1183
- return this.audio && typeof this.audio === 'object' && 'deviceId' in this.audio ? (_a = this.audio.deviceId) === null || _a === void 0 ? void 0 : _a.exact : undefined;
1184
- }
1185
- getVideoDeviceId() {
1186
- var _a;
1187
- return this.video && typeof this.video === 'object' && 'deviceId' in this.video ? (_a = this.video.deviceId) === null || _a === void 0 ? void 0 : _a.exact : undefined;
1188
- }
1189
- reinvite(sipSession, newConstraints = null, conference = false, audioOnly = false, iceRestart = false) {
1190
- if (!sipSession) {
1191
- return Promise.resolve();
1192
- }
1193
- // @ts-ignore: private
1194
- if (sipSession.pendingReinvite) {
1195
- return Promise.resolve();
1196
- }
1197
- const wasMuted = this.isAudioMuted(sipSession);
1198
- const shouldDoVideo = newConstraints ? newConstraints.video : this.sessionWantsToDoVideo(sipSession);
1199
- const shouldDoScreenSharing = newConstraints && newConstraints.screen;
1200
- const desktop = newConstraints && newConstraints.desktop;
1201
- logger.info('Sending reinvite', {
1202
- clientId: this.clientId,
1203
- id: this.getSipSessionId(sipSession),
1204
- newConstraints,
1205
- conference,
1206
- audioOnly,
1207
- wasMuted,
1208
- shouldDoVideo,
1209
- shouldDoScreenSharing,
1210
- desktop,
1211
- });
1212
- // When upgrading to video, remove the `stripVideo` modifiers
1213
- if (newConstraints && newConstraints.video) {
1214
- const modifiers = sipSession.sessionDescriptionHandlerModifiersReInvite;
1215
- sipSession.sessionDescriptionHandlerModifiersReInvite = modifiers.filter(modifier => modifier !== modifiers_1.stripVideo);
1216
- }
1217
- sipSession.sessionDescriptionHandlerOptionsReInvite = Object.assign(Object.assign({}, sipSession.sessionDescriptionHandlerOptionsReInvite), { conference,
1218
- audioOnly });
1219
- const { constraints, } = this.getMediaConfiguration(shouldDoVideo, conference, newConstraints);
1220
- return sipSession.invite({
1221
- requestDelegate: {
1222
- onAccept: (response) => {
1223
- // Update the SDP body to be able to call sessionWantsToDoVideo correctly in `_setup[Local|Remote]Media`.
1224
- // Can't set directly sipSession.body because it's a getter.
1225
- // @ts-ignore: private
1226
- if (sipSession instanceof api_1.Inviter && sipSession.outgoingRequestMessage.body) {
1227
- // @ts-ignore: private
1228
- sipSession.outgoingRequestMessage.body.body = response.message.body;
1229
- }
1230
- else if (sipSession instanceof api_1.Invitation) {
1231
- // @ts-ignore: private
1232
- sipSession.incomingInviteRequest.message.body = response.message.body;
1233
- }
1234
- logger.info('on re-INVITE accepted', {
1235
- id: this.getSipSessionId(sipSession),
1236
- wasMuted,
1237
- shouldDoScreenSharing,
1238
- });
1239
- this.updateRemoteStream(this.getSipSessionId(sipSession), false);
1240
- if (wasMuted) {
1241
- this.mute(sipSession);
1242
- }
1243
- this._onAccepted(sipSession, response.session, false, false);
1244
- if (shouldDoScreenSharing) {
1245
- this.eventEmitter.emit(ON_SCREEN_SHARING_REINVITE, sipSession, response, desktop);
1246
- }
1247
- return this.eventEmitter.emit(ON_REINVITE, sipSession, response);
1248
- },
1249
- },
1250
- sessionDescriptionHandlerModifiers: [exports.replaceLocalIpModifier],
1251
- requestOptions: {
1252
- extraHeaders: [`Subject: ${shouldDoScreenSharing ? 'screenshare' : 'upgrade-video'}`],
1253
- },
1254
- sessionDescriptionHandlerOptions: {
1255
- constraints,
1256
- conference,
1257
- audioOnly,
1258
- offerOptions: {
1259
- iceRestart,
1260
- },
1261
- },
1262
- });
1263
- }
1264
- getUserMedia(constraints) {
1265
- return __awaiter(this, void 0, void 0, function* () {
1266
- const newConstraints = {
1267
- audio: this._getAudioConstraints(),
1268
- video: this._getVideoConstraints(constraints.video),
1269
- };
1270
- return navigator.mediaDevices.getUserMedia(newConstraints);
1271
- });
1272
- }
1273
- getPeerConnection(sessionId) {
1274
- const sipSession = this.sipSessions[sessionId];
1275
- if (!sipSession) {
1276
- return null;
1277
- }
1278
- return sipSession.sessionDescriptionHandler ? sipSession.sessionDescriptionHandler.peerConnection : null;
1279
- }
1280
- // Local streams
1281
- getLocalStream(sessionId) {
1282
- var _a;
1283
- const sipSession = this.sipSessions[sessionId];
1284
- return ((_a = sipSession === null || sipSession === void 0 ? void 0 : sipSession.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.localMediaStream) || null;
1285
- }
1286
- getLocalTracks(sessionId) {
1287
- const localStream = this.getLocalStream(sessionId);
1288
- if (!localStream) {
1289
- return [];
1290
- }
1291
- return localStream.getTracks();
1292
- }
1293
- hasLocalVideo(sessionId) {
1294
- return this.getLocalTracks(sessionId).some(this._isVideoTrack);
1295
- }
1296
- // Check if we have at least one video track, even muted or not live
1297
- hasALocalVideoTrack(sessionId) {
1298
- return this.getLocalTracks(sessionId).some(track => track.kind === 'video');
1299
- }
1300
- getLocalVideoStream(sessionId) {
1301
- return this.hasLocalVideo(sessionId) ? this.getLocalStream(sessionId) : null;
1302
- }
1303
- // Remote streams
1304
- getRemoteStream(sessionId) {
1305
- var _a;
1306
- const sipSession = this.sipSessions[sessionId];
1307
- return ((_a = sipSession === null || sipSession === void 0 ? void 0 : sipSession.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.remoteMediaStream) || null;
1308
- }
1309
- getRemoteTracks(sessionId) {
1310
- const remoteStream = this.getRemoteStream(sessionId);
1311
- if (!remoteStream) {
1312
- return [];
1313
- }
1314
- return remoteStream.getTracks();
1315
- }
1316
- hasRemoteVideo(sessionId) {
1317
- return this.getRemoteTracks(sessionId).some(this._isVideoTrack);
1318
- }
1319
- // Check if we have at least one video track, even muted or not live
1320
- hasARemoteVideoTrack(sessionId) {
1321
- return this.getRemoteTracks(sessionId).some(track => track.kind === 'video');
1322
- }
1323
- getRemoteVideoStream(sessionId) {
1324
- if (this.isVideoRemotelyHeld(sessionId)) {
1325
- return null;
1326
- }
1327
- return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
1328
- }
1329
- // Useful in a react-native environment when remoteMediaStream is not updated
1330
- getRemoteVideoStreamFromPc(sessionId) {
1331
- const pc = this.getPeerConnection(sessionId);
1332
- if (!pc) {
1333
- return null;
1334
- }
1335
- return pc.getRemoteStreams().find((stream) => !!stream.getVideoTracks().length);
1336
- }
1337
- hasVideo(sessionId) {
1338
- return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
1339
- }
1340
- hasAVideoTrack(sessionId) {
1341
- return this.hasALocalVideoTrack(sessionId) || this.hasARemoteVideoTrack(sessionId);
1342
- }
1343
- getSipSessionId(sipSession) {
1344
- if (!sipSession) {
1345
- return '';
1346
- }
1347
- // For Inviter
1348
- // @ts-ignore: private
1349
- if (sipSession instanceof api_1.Inviter && sipSession.outgoingRequestMessage) {
1350
- // @ts-ignore: private
1351
- return sipSession.outgoingRequestMessage.callId;
1352
- }
1353
- // For Invitation
1354
- // @ts-ignore: private
1355
- if (sipSession instanceof api_1.Invitation && sipSession.incomingInviteRequest.message) {
1356
- // @ts-ignore: private
1357
- return sipSession.incomingInviteRequest.message.callId;
1358
- }
1359
- // For EarlyMedia
1360
- // @ts-ignore: private
1361
- if (sipSession instanceof session_dialog_1.SessionDialog) {
1362
- // @ts-ignore: private
1363
- return sipSession.dialogState.callId;
1364
- }
1365
- return '';
1366
- }
1367
- waitForRegister() {
1368
- return __awaiter(this, void 0, void 0, function* () {
1369
- return new Promise(resolve => this.on(REGISTERED, resolve));
1370
- });
1371
- }
1372
- // eslint-disable-next-line no-unused-vars
1373
- sessionWantsToDoVideo(session) {
1374
- if (!session) {
1375
- return false;
1376
- }
1377
- const { body, } = session.request || session;
1378
- // Sometimes with InviteClientContext the body is in the body attribute ...
1379
- const sdp = typeof body === 'object' && body ? body.body : body;
1380
- return (0, sdp_1.hasAnActiveVideo)(sdp);
1381
- }
1382
- hasHeartbeat() {
1383
- return this.heartbeat.hasHeartbeat;
1384
- }
1385
- startHeartbeat() {
1386
- logger.info('sdk webrtc start heartbeat', { userAgent: !!this.userAgent, clientId: this.clientId });
1387
- if (!this.userAgent) {
1388
- this.heartbeat.stop();
1389
- return;
1390
- }
1391
- this.eventEmitter.off(MESSAGE, this._boundOnHeartbeat);
1392
- this.eventEmitter.on(MESSAGE, this._boundOnHeartbeat);
1393
- this.heartbeat.start();
1394
- }
1395
- stopHeartbeat() {
1396
- logger.info('sdk webrtc stop heartbeat', { clientId: this.clientId });
1397
- this.heartbeat.stop();
1398
- }
1399
- setOnHeartbeatTimeout(cb) {
1400
- this.heartbeatTimeoutCb = cb;
1401
- }
1402
- setOnHeartbeatCallback(cb) {
1403
- this.heartbeatCb = cb;
1404
- }
1405
- onCallEnded(session) {
1406
- this._cleanupMedia(session);
1407
- delete this.sipSessions[this.getSipSessionId(session)];
1408
- this._stopSendingStats(session);
1409
- this.stopNetworkMonitoring(session);
1410
- }
1411
- attemptReconnection() {
1412
- logger.info('attempt reconnection', { clientId: this.clientId, userAgent: !!this.userAgent });
1413
- if (!this.userAgent) {
1414
- return;
1415
- }
1416
- // @ts-ignore: private
1417
- this.userAgent.attemptReconnection();
1418
- }
1419
- storeSipSession(session) {
1420
- const id = this.getSipSessionId(session);
1421
- logger.info('storing sip session', { id, clientId: this.clientId });
1422
- this.sipSessions[id] = session;
1423
- }
1424
- getSipSession(id) {
1425
- return id in this.sipSessions ? this.sipSessions[id] : null;
1426
- }
1427
- getSipSessionIds() {
1428
- return Object.keys(this.sipSessions);
1429
- }
1430
- setLocalMediaStream(sipSessionId, newStream) {
1431
- const sipSession = this.sipSessions[sipSessionId];
1432
- if (!sipSession) {
1433
- return;
1434
- }
1435
- logger.info('setting local media stream', {
1436
- sipSessionId,
1437
- tracks: newStream ? newStream.getTracks() : null,
1438
- });
1439
- if (sipSession.sessionDescriptionHandler) {
1440
- // eslint-disable-next-line no-underscore-dangle
1441
- // @ts-ignore: protected
1442
- sipSession.sessionDescriptionHandler._localMediaStream = newStream;
1443
- }
1444
- }
1445
- updateLocalStream(sipSessionId, newStream) {
1446
- return __awaiter(this, void 0, void 0, function* () {
1447
- const sipSession = this.sipSessions[sipSessionId];
1448
- if (!sipSession) {
1449
- return;
1450
- }
1451
- const oldStream = this.getLocalStream(sipSessionId);
1452
- logger.info('updating local stream', {
1453
- sipSessionId,
1454
- oldStream: !!oldStream,
1455
- tracks: newStream.getTracks(),
1456
- });
1457
- if (oldStream) {
1458
- this._cleanupStream(oldStream);
1459
- }
1460
- this.setLocalMediaStream(sipSessionId, newStream);
1461
- // Update the local video element
1462
- yield this._setupMedias(sipSession, newStream);
1463
- });
1464
- }
1465
- updateRemoteStream(sessionId, allTracks = true) {
1466
- const remoteStream = this.getRemoteStream(sessionId);
1467
- const pc = this.getPeerConnection(sessionId);
1468
- logger.info('Updating remote stream', {
1469
- sessionId,
1470
- tracks: remoteStream ? remoteStream.getTracks() : null,
1471
- receiverTracks: pc && pc.getReceivers ? pc.getReceivers().map((receiver) => receiver.track) : null,
1472
- });
1473
- if (!pc || !remoteStream) {
1474
- return;
1475
- }
1476
- remoteStream.getTracks().forEach(track => {
1477
- if (allTracks || track.kind === 'video') {
1478
- remoteStream.removeTrack(track);
1479
- }
1480
- });
1481
- if (pc.getReceivers) {
1482
- pc.getReceivers().forEach((receiver) => {
1483
- if (allTracks || receiver.track.kind === 'video') {
1484
- remoteStream.addTrack(receiver.track);
1485
- }
1486
- });
1487
- }
1488
- }
1489
- getMediaConfiguration(enableVideo, conference = false, constraints = null) {
1490
- const screenSharing = constraints && 'screen' in constraints ? constraints.screen : false;
1491
- const isDesktop = constraints && 'desktop' in constraints ? constraints.desktop : false;
1492
- const withAudio = constraints && 'audio' in constraints ? constraints.audio : true;
1493
- const mandatoryVideo = constraints && typeof constraints.video === 'object' ? constraints.video.mandatory : {};
1494
- logger.info('Retrieving media a configuration', {
1495
- enableVideo,
1496
- screenSharing,
1497
- isDesktop,
1498
- withAudio,
1499
- constraints,
1500
- });
1501
- return {
1502
- constraints: {
1503
- // Exact constraint are not supported with `getDisplayMedia` and we must have a video=false in desktop screenshare
1504
- audio: screenSharing ? !isDesktop : withAudio ? this._getAudioConstraints() : false,
1505
- video: screenSharing ? isDesktop ? {
1506
- mandatory: Object.assign({ chromeMediaSource: 'desktop' }, (mandatoryVideo || {})),
1507
- } : {
1508
- cursor: 'always',
1509
- } : this._getVideoConstraints(enableVideo),
1510
- screen: screenSharing,
1511
- desktop: isDesktop,
1512
- conference,
1513
- },
1514
- enableVideo,
1515
- conference,
1516
- offerOptions: {
1517
- OfferToReceiveAudio: this._hasAudio(),
1518
- OfferToReceiveVideo: enableVideo,
1519
- mandatory: {
1520
- OfferToReceiveAudio: this._hasAudio(),
1521
- OfferToReceiveVideo: enableVideo,
1522
- },
1523
- },
1524
- };
1525
- }
1526
- isConference(sessionId) {
1527
- return sessionId in this.conferences;
1528
- }
1529
- createAudioElementFor(sessionId) {
1530
- return __awaiter(this, void 0, void 0, function* () {
1531
- const audio = document.createElement('audio');
1532
- audio.setAttribute('id', `audio-${sessionId}`);
1533
- logger.info('creating audio element', { sessionId, audioOutputDeviceId: this.audioOutputDeviceId });
1534
- if (this.audioOutputDeviceId) {
1535
- yield audio.setSinkId(this.audioOutputDeviceId);
1536
- }
1537
- if (document.body) {
1538
- document.body.appendChild(audio);
1539
- }
1540
- this.audioElements[sessionId] = audio;
1541
- audio.volume = this.audioOutputVolume;
1542
- audio.autoplay = true;
1543
- return audio;
1544
- });
1545
- }
1546
- _onTransportError() {
1547
- logger.error('on transport error');
1548
- this.eventEmitter.emit(TRANSPORT_ERROR);
1549
- this.attemptReconnection();
1550
- }
1551
- enableLogger(logConnector) {
1552
- var _a;
1553
- if (!this.userAgent) {
1554
- return;
1555
- }
1556
- if ((_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.transport) {
1557
- this.userAgent.transport.configuration.traceSip = true;
1558
- }
1559
- // @ts-ignore: private
1560
- this.userAgent.loggerFactory.builtinEnabled = true;
1561
- // @ts-ignore: private
1562
- this.userAgent.loggerFactory.level = 3; // debug
1563
- // @ts-ignore: private
1564
- this.userAgent.loggerFactory.connector = logConnector;
1565
- }
1566
- _onHeartbeat(message) {
1567
- const body = message && typeof message === 'object' ? message.data : message;
1568
- if (body && body.indexOf('200 OK') !== -1) {
1569
- if (this.hasHeartbeat()) {
1570
- logger.info('on heartbeat received from Asterisk', {
1571
- hasHeartbeat: this.hasHeartbeat(),
1572
- });
1573
- this.heartbeat.onHeartbeat();
1574
- if (this.heartbeatCb) {
1575
- this.heartbeatCb();
1576
- }
1577
- }
1578
- }
1579
- }
1580
- _onHeartbeatTimeout() {
1581
- return __awaiter(this, void 0, void 0, function* () {
1582
- logger.warn('sdk webrtc heartbeat timed out', {
1583
- userAgent: !!this.userAgent,
1584
- cb: !!this.heartbeatTimeoutCb,
1585
- });
1586
- if (this.heartbeatTimeoutCb) {
1587
- this.heartbeatTimeoutCb();
1588
- }
1589
- if (this.userAgent && this.userAgent.transport) {
1590
- // Disconnect from WS and triggers events, but do not trigger disconnect if already disconnecting...
1591
- const transport = this.userAgent.transport;
1592
- // @HEADS UP
1593
- if (!transport.transitioningState && !transport.disconnectPromise) {
1594
- try {
1595
- yield this.userAgent.transport.disconnect();
1596
- }
1597
- catch (e) {
1598
- logger.error('Transport disconnection after heartbeat timeout, error', e);
1599
- }
1600
- }
1601
- // We can invoke disconnect() with an error that can be catcher by `onDisconnect`, so we have to trigger it here.
1602
- this._onTransportError();
1603
- }
1604
- });
1605
- }
1606
- _isWeb() {
1607
- return typeof window === 'object' && typeof document === 'object';
1608
- }
1609
- _isVideoTrack(track) {
1610
- return track.kind === 'video' && track.readyState === 'live';
1611
- }
1612
- _hasAudio() {
1613
- return this.hasAudio;
1614
- }
1615
- _getAudioConstraints() {
1616
- var _a, _b;
1617
- // @ts-ignore: media constraints
1618
- return ((_b = (_a = this.audio) === null || _a === void 0 ? void 0 : _a.deviceId) === null || _b === void 0 ? void 0 : _b.exact) ? this.audio : true;
1619
- }
1620
- _getVideoConstraints(video = false) {
1621
- var _a, _b;
1622
- if (!video) {
1623
- return false;
1624
- }
1625
- // @ts-ignore: media constraints
1626
- return ((_b = (_a = this.video) === null || _a === void 0 ? void 0 : _a.deviceId) === null || _b === void 0 ? void 0 : _b.exact) ? this.video : true;
1627
- }
1628
- _connectIfNeeded() {
1629
- logger.info('connect if needed, checking', { connected: this.isConnected(), clientId: this.clientId });
1630
- if (!this.userAgent) {
1631
- logger.info('need to recreate User Agent');
1632
- this.userAgent = this.createUserAgent(this.uaConfigOverrides);
1633
- }
1634
- if (this.isConnected()) {
1635
- logger.info('webrtc sdk, already connected');
1636
- return Promise.resolve();
1637
- }
1638
- if (this.isConnecting()) {
1639
- logger.info('webrtc sdk, already connecting...');
1640
- this.connectionPromise = this.userAgent.transport.connectPromise;
1641
- return Promise.resolve(this.connectionPromise);
1642
- }
1643
- if (this.connectionPromise) {
1644
- logger.info('webrtc sdk, connection promise connecting...');
1645
- return this.connectionPromise;
1646
- }
1647
- logger.info('WebRTC UA needs to connect');
1648
- // Force UA to reconnect
1649
- if (this.userAgent && this.userAgent.state !== user_agent_state_1.UserAgentState.Stopped) {
1650
- // @ts-ignore: private
1651
- this.userAgent.transitionState(user_agent_state_1.UserAgentState.Stopped);
1652
- }
1653
- if (this.userAgent.transport && this.userAgent.transport.state !== transport_state_1.TransportState.Disconnected) {
1654
- this.userAgent.transport.transitionState(transport_state_1.TransportState.Disconnected);
1655
- }
1656
- this.connectionPromise = this.userAgent.start().catch(console.error);
1657
- return this.connectionPromise;
1658
- }
1659
- _buildConfig(config, session) {
1660
- // If no session provided, return the configuration directly
1661
- if (!session) {
1662
- return new Promise(resolve => resolve(config));
1663
- }
1664
- const client = new api_client_1.default({
1665
- server: `${config.host}:${String(config.port || 443)}`,
1666
- });
1667
- client.setToken(session.token);
1668
- client.setRefreshToken(session.refreshToken);
1669
- return client.confd.getUserLineSipFromToken(session.uuid).then(sipLine => (Object.assign({ authorizationUser: sipLine.username, password: sipLine.secret, uri: `${sipLine.username}@${config.host}` }, config)));
1670
- }
1671
- _createUaOptions(uaOptionsOverrides = {}) {
1672
- let { host, } = this.config;
1673
- let port = this.config.port || 443;
1674
- if (this.config.websocketSip) {
1675
- const webSocketSip = this.config.websocketSip.split(':');
1676
- [host] = webSocketSip;
1677
- port = Number(webSocketSip[1]);
1678
- }
1679
- const { userUuid } = this.config;
1680
- const uaOptions = {
1681
- noAnswerTimeout: NO_ANSWER_TIMEOUT,
1682
- authorizationUsername: this.config.authorizationUser,
1683
- authorizationPassword: this.config.password,
1684
- displayName: this.config.displayName,
1685
- hackIpInContact: true,
1686
- logBuiltinEnabled: this.config.log ? this.config.log.builtinEnabled : null,
1687
- logLevel: this.config.log ? this.config.log.logLevel : null,
1688
- logConnector: this.config.log ? this.config.log.connector : null,
1689
- uri: this._makeURI(this.config.authorizationUser || ''),
1690
- userAgentString: this.config.userAgentString || 'wazo-sdk',
1691
- reconnectionAttempts: 10000,
1692
- reconnectionDelay: 5,
1693
- sessionDescriptionHandlerFactory: (session, options = {}) => {
1694
- const uaLogger = session.userAgent.getLogger('sip.WazoSessionDescriptionHandler');
1695
- const isWeb = this._isWeb();
1696
- const iceGatheringTimeout = 'peerConnectionOptions' in options ? options.peerConnectionOptions.iceGatheringTimeout || DEFAULT_ICE_TIMEOUT : DEFAULT_ICE_TIMEOUT;
1697
- const sdhOptions = Object.assign(Object.assign({}, options), { iceGatheringTimeout, peerConnectionConfiguration: Object.assign(Object.assign({}, (0, peer_connection_configuration_default_1.defaultPeerConnectionConfiguration)()), (options.peerConnectionConfiguration || {})) });
1698
- return new WazoSessionDescriptionHandler_1.default(uaLogger, WazoSessionDescriptionHandler_1.wazoMediaStreamFactory, sdhOptions, isWeb, session);
1699
- },
1700
- transportOptions: {
1701
- traceSip: (uaOptionsOverrides === null || uaOptionsOverrides === void 0 ? void 0 : uaOptionsOverrides.traceSip) || false,
1702
- wsServers: `wss://${host}:${port}/api/asterisk/ws${userUuid ? `?userUuid=${userUuid}` : ''}`,
1703
- },
1704
- sessionDescriptionHandlerFactoryOptions: {
1705
- modifiers: [exports.replaceLocalIpModifier],
1706
- alwaysAcquireMediaFirst: this.isFirefox(),
1707
- constraints: {
1708
- audio: this._getAudioConstraints(),
1709
- video: this._getVideoConstraints(),
1710
- },
1711
- peerConnectionOptions: {
1712
- iceCheckingTimeout: this.config.iceCheckingTimeout || 1000,
1713
- iceGatheringTimeout: this.config.iceCheckingTimeout || 1000,
1714
- rtcConfiguration: Object.assign(Object.assign({ rtcpMuxPolicy: 'require', iceServers: WebRTCClient.getIceServers(this.config.host) }, this._getRtcOptions()), ((uaOptionsOverrides === null || uaOptionsOverrides === void 0 ? void 0 : uaOptionsOverrides.peerConnectionOptions) || {})),
1715
- },
1716
- // Configuration used in SDH to create the PeerConnection
1717
- peerConnectionConfiguration: Object.assign({ rtcpMuxPolicy: 'require', iceServers: WebRTCClient.getIceServers(this.config.host) }, ((uaOptionsOverrides === null || uaOptionsOverrides === void 0 ? void 0 : uaOptionsOverrides.peerConnectionOptions) || {})),
1718
- },
1719
- };
1720
- uaOptionsOverrides === null || uaOptionsOverrides === void 0 ? true : delete uaOptionsOverrides.traceSip;
1721
- return Object.assign(Object.assign({}, uaOptions), uaOptionsOverrides);
1722
- }
1723
- // eslint-disable-next-line no-unused-vars
1724
- _getRtcOptions() {
1725
- return {
1726
- mandatory: {
1727
- OfferToReceiveAudio: this._hasAudio(),
1728
- OfferToReceiveVideo: false,
1729
- },
1730
- };
1731
- }
1732
- // Invitation and Inviter extends Session
1733
- _setupSession(session) {
1734
- const sipSessionId = this.getSipSessionId(session);
1735
- // When receiving an Invitation, the delegate is not defined.
1736
- if (!session.delegate) {
1737
- session.delegate = {};
1738
- }
1739
- session.delegate.onSessionDescriptionHandler = (sdh) => {
1740
- sdh.on('error', (e) => {
1741
- this.eventEmitter.emit(ON_ERROR, e);
1742
- });
1743
- sdh.peerConnectionDelegate = {
1744
- onicecandidateerror: (error) => {
1745
- logger.error('on icecandidate error', {
1746
- address: error.address,
1747
- port: error.port,
1748
- errorCode: error.errorCode,
1749
- errorText: error.errorText,
1750
- url: error.url,
1751
- });
1752
- },
1753
- };
1754
- };
1755
- // @ts-ignore: protected
1756
- const oldInviteRequest = session.onInviteRequest.bind(session);
1757
- let hadRemoteVideo = false;
1758
- // Monkey patch `onInviteRequest` to be able to know if there was a remote video stream before `onInvite` is called
1759
- // Because when `onInvite` is called we already got the video track
1760
- // @ts-ignore: protected
1761
- session.onInviteRequest = request => {
1762
- hadRemoteVideo = this.hasARemoteVideoTrack(sipSessionId);
1763
- oldInviteRequest(request);
1764
- };
1765
- session.delegate.onInvite = (request) => __awaiter(this, void 0, void 0, function* () {
1766
- let updatedCalleeName = null;
1767
- let updatedNumber = null;
1768
- if (session.assertedIdentity) {
1769
- // @ts-ignore: private
1770
- updatedNumber = session.assertedIdentity.uri.normal.user;
1771
- updatedCalleeName = session.assertedIdentity.displayName || updatedNumber;
1772
- }
1773
- logger.info('re-invite received', {
1774
- updatedCalleeName,
1775
- updatedNumber,
1776
- hadRemoteVideo,
1777
- });
1778
- // Useful to know if it's a video upgrade or an unhold from a remote peer with a video stream
1779
- // Update SDP
1780
- // Remote video is handled by the `track` event. Here we're dealing with video stream removal.
1781
- if (session instanceof api_1.Invitation) {
1782
- // @ts-ignore: private
1783
- session.incomingInviteRequest.message.body = request.body;
1784
- // @ts-ignore: private
1785
- }
1786
- else if (session instanceof api_1.Inviter && session.outgoingInviteRequest.message.body) {
1787
- // @ts-ignore: private
1788
- session.outgoingInviteRequest.message.body.body = request.body;
1789
- }
1790
- this.updateRemoteStream(sipSessionId, false);
1791
- yield this._setupMedias(session);
1792
- return this.eventEmitter.emit(ON_REINVITE, session, request, updatedCalleeName, updatedNumber, hadRemoteVideo);
1793
- });
1794
- }
1795
- _onProgress(session_1) {
1796
- return __awaiter(this, arguments, void 0, function* (session, early = false) {
1797
- yield this._setupMedias(session);
1798
- const sessionId = this.getSipSessionId(session);
1799
- this.updateRemoteStream(sessionId);
1800
- logger.info('progress received', {
1801
- sessionId,
1802
- early,
1803
- });
1804
- this.eventEmitter.emit(early ? ON_EARLY_MEDIA : ON_PROGRESS, session);
1805
- });
1806
- }
1807
- _onAccepted(session_1, sessionDialog_1) {
1808
- return __awaiter(this, arguments, void 0, function* (session, sessionDialog, withEvent = true, initAllTracks = true) {
1809
- var _a;
1810
- logger.info('on call accepted', {
1811
- id: this.getSipSessionId(session),
1812
- clientId: this.clientId,
1813
- remoteTag: session.remoteTag,
1814
- });
1815
- this.storeSipSession(session);
1816
- yield this._setupMedias(session);
1817
- this.updateRemoteStream(this.getSipSessionId(session), initAllTracks);
1818
- const pc = (_a = session.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.peerConnection;
1819
- const onTrack = (event) => {
1820
- const isAudioOnly = this._isAudioOnly(session);
1821
- const { kind, label, readyState, id, muted, } = event.track;
1822
- logger.info('on track event', {
1823
- isAudioOnly,
1824
- kind,
1825
- label,
1826
- readyState,
1827
- id,
1828
- muted,
1829
- });
1830
- // Stop video track in audio only mode
1831
- if (isAudioOnly && kind === 'video') {
1832
- event.track.stop();
1833
- }
1834
- this.eventEmitter.emit(ON_TRACK, session, event);
1835
- };
1836
- const sessionDescriptionHandler = session.sessionDescriptionHandler;
1837
- if (sessionDescriptionHandler === null || sessionDescriptionHandler === void 0 ? void 0 : sessionDescriptionHandler.peerConnection) {
1838
- sessionDescriptionHandler.peerConnection.addEventListener('track', onTrack);
1839
- }
1840
- sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
1841
- if (pc) {
1842
- pc.oniceconnectionstatechange = () => {
1843
- logger.info('on ice connection state changed', {
1844
- state: pc.iceConnectionState,
1845
- });
1846
- if (pc.iceConnectionState === 'disconnected') {
1847
- this.eventEmitter.emit(ON_DISCONNECTED);
1848
- }
1849
- };
1850
- }
1851
- if (withEvent) {
1852
- this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
1853
- }
1854
- this._startSendingStats(session);
1855
- });
1856
- }
1857
- _isAudioOnly(session) {
1858
- return Boolean(session.sessionDescriptionHandlerModifiersReInvite.find(modifier => modifier === modifiers_1.stripVideo));
1859
- }
1860
- _setupMedias(session_1) {
1861
- return __awaiter(this, arguments, void 0, function* (session, newStream = null) {
1862
- if (!this._isWeb()) {
1863
- logger.info('Setup media on mobile, no need to setup html element, bailing');
1864
- return;
1865
- }
1866
- // Safari hack, because you cannot call .play() from a non user action
1867
- const sessionId = this.getSipSessionId(session);
1868
- const isConference = this.isConference(sessionId);
1869
- if (sessionId in this.audioElements) {
1870
- logger.info('html element already exists for session', {
1871
- sessionId,
1872
- });
1873
- return;
1874
- }
1875
- if (this._hasAudio() && this._isWeb() && !(sessionId in this.audioElements)) {
1876
- yield this.createAudioElementFor(sessionId);
1877
- }
1878
- const audioElement = this.audioElements[sessionId];
1879
- const sipSession = this.sipSessions[session.callId];
1880
- const removeStream = this.getRemoteStream(sessionId);
1881
- const sdh = sipSession === null || sipSession === void 0 ? void 0 : sipSession.sessionDescriptionHandler;
1882
- const earlyStream = sdh ? sdh.remoteMediaStream : null;
1883
- const stream = newStream || removeStream || earlyStream;
1884
- if (!stream) {
1885
- logger.info('Setup media no stream to attach, bailing');
1886
- return;
1887
- }
1888
- const shouldPause = audioElement.currentTime > 0 && !audioElement.paused && !audioElement.ended && audioElement.readyState > 2;
1889
- logger.info('setting up media', {
1890
- sessionId,
1891
- streams: {
1892
- new: !!newStream,
1893
- remove: !!removeStream,
1894
- early: !!earlyStream,
1895
- },
1896
- hasAudio: this._hasAudio(),
1897
- isConference,
1898
- shouldPause,
1899
- });
1900
- if (isConference) {
1901
- // Conference local stream is handled in Room
1902
- return;
1903
- }
1904
- if (shouldPause) {
1905
- audioElement.pause();
1906
- }
1907
- audioElement.srcObject = stream;
1908
- audioElement.volume = this.audioOutputVolume;
1909
- audioElement.play().catch(() => { });
1910
- });
1911
- }
1912
- _cleanupMedia(session) {
1913
- const sessionId = this.getSipSessionId(session);
1914
- const localStream = this.getLocalStream(sessionId);
1915
- if (localStream) {
1916
- this._cleanupStream(localStream);
1917
- }
1918
- const cleanLocalElement = (id) => {
1919
- const element = this.audioElements[id];
1920
- if (!element) {
1921
- return;
1922
- }
1923
- element.pause();
1924
- if (element.parentNode) {
1925
- element.parentNode.removeChild(element);
1926
- }
1927
- element.srcObject = null;
1928
- delete this.audioElements[id];
1929
- };
1930
- if (this._hasAudio() && this._isWeb()) {
1931
- if (session) {
1932
- cleanLocalElement(this.getSipSessionId(session));
1933
- }
1934
- else {
1935
- Object.keys(this.audioElements).forEach(id => cleanLocalElement(id));
1936
- }
1937
- }
1938
- }
1939
- _cleanupStream(stream) {
1940
- stream.getTracks().filter(track => track.enabled).forEach(track => track.stop());
1941
- }
1942
- _toggleAudio(session, muteAudio) {
1943
- const sdh = session.sessionDescriptionHandler;
1944
- const pc = ((sdh === null || sdh === void 0 ? void 0 : sdh.peerConnection) || null);
1945
- if (!pc) {
1946
- return;
1947
- }
1948
- if (pc.getSenders) {
1949
- pc.getSenders().forEach((sender) => {
1950
- if (sender && sender.track && sender.track.kind === 'audio') {
1951
- // eslint-disable-next-line
1952
- sender.track.enabled = !muteAudio;
1953
- }
1954
- });
1955
- }
1956
- else {
1957
- pc.getLocalStreams().forEach((stream) => {
1958
- stream.getAudioTracks().forEach(track => {
1959
- // eslint-disable-next-line
1960
- track.enabled = !muteAudio;
1961
- });
1962
- });
1963
- }
1964
- }
1965
- _toggleVideo(session, muteCamera) {
1966
- const sdh = session.sessionDescriptionHandler;
1967
- const pc = sdh === null || sdh === void 0 ? void 0 : sdh.peerConnection;
1968
- if (pc === null || pc === void 0 ? void 0 : pc.getSenders) {
1969
- pc.getSenders().forEach((sender) => {
1970
- if (sender && sender.track && sender.track.kind === 'video') {
1971
- // eslint-disable-next-line
1972
- sender.track.enabled = !muteCamera;
1973
- }
1974
- });
1975
- }
1976
- else {
1977
- pc.getLocalStreams().forEach((stream) => {
1978
- stream.getVideoTracks().forEach(track => {
1979
- // eslint-disable-next-line
1980
- track.enabled = !muteCamera;
1981
- });
1982
- });
1983
- }
1984
- }
1985
- /**
1986
- * @param pc RTCPeerConnection
1987
- */
1988
- _getRemoteStream(pc) {
1989
- let remoteStream = null;
1990
- if (pc && pc.getReceivers) {
1991
- remoteStream = typeof global !== 'undefined' && global.window && global.window.MediaStream ? new global.window.MediaStream() : new window.MediaStream();
1992
- pc.getReceivers().forEach((receiver) => {
1993
- const { track, } = receiver;
1994
- if (track && remoteStream) {
1995
- remoteStream.addTrack(track);
1996
- }
1997
- });
1998
- }
1999
- else if (pc) {
2000
- [remoteStream] = pc.getRemoteStreams();
2001
- }
2002
- return remoteStream;
2003
- }
2004
- _cleanupRegister() {
2005
- if (this.registerer) {
2006
- // @ts-ignore: removeAllListeners does not exist
2007
- this.registerer.stateChange.removeAllListeners();
2008
- this.registerer = null;
2009
- }
2010
- }
2011
- _startSendingStats(session) {
2012
- const sdh = session.sessionDescriptionHandler;
2013
- const pc = sdh.peerConnection;
2014
- if (!pc) {
2015
- return;
2016
- }
2017
- const sessionId = this.getSipSessionId(session);
2018
- (0, getstats_1.default)(pc, (result) => {
2019
- const { results, internal, nomore } = result, stats = __rest(result, ["results", "internal", "nomore"]);
2020
- this.statsIntervals[sessionId] = nomore;
2021
- statsLogger.trace('stats', Object.assign({ sessionId }, stats));
2022
- }, SEND_STATS_DELAY);
2023
- }
2024
- _stopSendingStats(session) {
2025
- const sessionId = this.getSipSessionId(session);
2026
- logger.trace('Check for stopping stats', {
2027
- sessionId,
2028
- ids: Object.keys(this.statsIntervals),
2029
- });
2030
- if (sessionId in this.statsIntervals) {
2031
- logger.trace('Stop sending stats for call', {
2032
- sessionId,
2033
- });
2034
- this.statsIntervals[sessionId]();
2035
- delete this.statsIntervals[sessionId];
2036
- }
2037
- }
2038
- _makeURI(target) {
2039
- return user_agent_1.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
2040
- }
2041
- _disconnectTransport() {
2042
- return __awaiter(this, arguments, void 0, function* (force = false) {
2043
- var _a;
2044
- const transport = (_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.transport;
2045
- if (force && transport) {
2046
- // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
2047
- transport.disconnectResolve = () => { };
2048
- if (transport._ws) {
2049
- transport._ws.close(1000);
2050
- }
2051
- return;
2052
- }
2053
- // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
2054
- if (transport && !transport.disconnectPromise) {
2055
- try {
2056
- yield transport.disconnect();
2057
- }
2058
- catch (e) {
2059
- logger.error('WebRTC transport disconnect, error', e);
2060
- }
2061
- }
2062
- });
2063
- }
2064
- _fetchNetworkStats(sessionId) {
2065
- return __awaiter(this, void 0, void 0, function* () {
2066
- const session = this.getSipSession(sessionId);
2067
- const stats = session ? yield this.getStats(session) : null;
2068
- if (!stats || !(sessionId in this.sessionNetworkStats)) {
2069
- return Promise.resolve(null);
2070
- }
2071
- const networkStats = {
2072
- audioBytesSent: 0,
2073
- videoBytesSent: 0,
2074
- videoBytesReceived: 0,
2075
- audioBytesReceived: 0,
2076
- };
2077
- const nbStats = this.sessionNetworkStats[sessionId].length;
2078
- const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
2079
- const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
2080
- const lastAudioContentSent = lastNetworkStats ? lastNetworkStats.audioContentSent : 0;
2081
- const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
2082
- const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
2083
- const lastAudioContentReceived = lastNetworkStats ? lastNetworkStats.audioContentReceived : 0;
2084
- const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
2085
- const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
2086
- const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
2087
- let audioBytesSent = 0; // content + header
2088
- let audioBytesReceived = 0; // content + header
2089
- let audioContentSent = 0; // useful to detect blank call
2090
- let audioContentReceived = 0;
2091
- let videoBytesSent = 0;
2092
- let videoBytesReceived = 0;
2093
- let transportSent = 0;
2094
- let transportReceived = 0;
2095
- let packetsLost = 0;
2096
- stats.forEach(report => {
2097
- if (report.type === 'outbound-rtp' && report.kind === 'audio') {
2098
- audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
2099
- audioContentSent += Number(report.bytesSent);
2100
- }
2101
- if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
2102
- audioBytesSent += Number(report.bytesSent);
2103
- }
2104
- if (report.type === 'outbound-rtp' && report.kind === 'video') {
2105
- videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
2106
- }
2107
- if (report.type === 'inbound-rtp' && report.kind === 'audio') {
2108
- packetsLost += Number(report.packetsLost);
2109
- networkStats.packetsReceived = Number(report.packetsReceived);
2110
- audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
2111
- audioContentReceived += Number(report.bytesReceived);
2112
- }
2113
- if (report.type === 'inbound-rtp' && report.kind === 'video') {
2114
- videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
2115
- }
2116
- if (report.type === 'outbound-rtp' && report.kind === 'video') {
2117
- if ('framesPerSecond' in report) {
2118
- networkStats.framesPerSecond = Number(report.framesPerSecond);
2119
- }
2120
- if ('framerateMean' in report) {
2121
- // framerateMean is only available in FF
2122
- networkStats.framesPerSecond = Math.round(report.framerateMean);
2123
- }
2124
- }
2125
- if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
2126
- packetsLost += Number(report.packetsLost);
2127
- networkStats.roundTripTime = Number(report.roundTripTime);
2128
- networkStats.jitter = Number(report.jitter);
2129
- }
2130
- if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
2131
- packetsLost += Number(report.packetsLost);
2132
- }
2133
- if (report.type === 'transport') {
2134
- transportSent += Number(report.bytesSent);
2135
- transportReceived += Number(report.bytesReceived);
2136
- }
2137
- });
2138
- networkStats.packetsLost = packetsLost;
2139
- networkStats.totalAudioBytesSent = audioBytesSent;
2140
- networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
2141
- networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
2142
- networkStats.audioBytesReceived = audioBytesReceived;
2143
- networkStats.totalAudioContentSent = audioContentSent;
2144
- networkStats.audioContentSent = audioContentSent - lastAudioContentSent;
2145
- networkStats.totalAudioBytesReceived = audioContentReceived - lastAudioContentReceived;
2146
- networkStats.audioContentReceived = audioContentReceived;
2147
- networkStats.totalVideoBytesSent = videoBytesSent;
2148
- networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
2149
- networkStats.totalVideoBytesReceived = videoBytesReceived;
2150
- networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
2151
- networkStats.totalTransportSent = transportSent - lastTransportSent;
2152
- networkStats.transportSent = transportSent;
2153
- networkStats.totalTransportReceived = transportReceived;
2154
- networkStats.transportReceived = transportReceived - lastTransportReceived;
2155
- networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived + networkStats.transportSent;
2156
- if (this.sessionNetworkStats[sessionId]) {
2157
- this.eventEmitter.emit(ON_NETWORK_STATS, session, networkStats, this.sessionNetworkStats[sessionId]);
2158
- if (sessionId in this.sessionNetworkStats) {
2159
- this.sessionNetworkStats[sessionId].push(networkStats);
2160
- }
2161
- }
2162
- });
2163
- }
2164
- _accept(session_1) {
2165
- return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2166
- if (session.state === session_state_1.SessionState.Terminated || session.state === session_state_1.SessionState.Terminating) {
2167
- const error = 'Trying to accept a terminated sipSession.';
2168
- logger.warn(error, { state: session.state, sessionId: this.getSipSessionId(session) });
2169
- throw new Error(error);
2170
- }
2171
- if (session.state !== session_state_1.SessionState.Initial) {
2172
- const error = 'Trying to accept a non Initial sipSession.';
2173
- logger.warn(error, { state: session.state, sessionId: this.getSipSessionId(session) });
2174
- throw new Error(error);
2175
- }
2176
- // @ts-ignore: private
2177
- if (!session.incomingInviteRequest.acceptable) {
2178
- const error = 'Trying to reject a non `acceptable` session';
2179
- logger.warn(error, { state: session.state, sessionId: this.getSipSessionId(session) });
2180
- throw new Error(error);
2181
- }
2182
- try {
2183
- return yield session.accept(options);
2184
- }
2185
- catch (e) {
2186
- logger.warn('Session accept, error', e);
2187
- }
2188
- });
2189
- }
2190
- _reject(session_1) {
2191
- return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2192
- if (session.state !== session_state_1.SessionState.Initial && session.state !== session_state_1.SessionState.Establishing) {
2193
- logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: this.getSipSessionId(session) });
2194
- return;
2195
- }
2196
- // @ts-ignore: private
2197
- if (!session.incomingInviteRequest.rejectable) {
2198
- logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: this.getSipSessionId(session) });
2199
- return;
2200
- }
2201
- try {
2202
- return yield session.reject(options);
2203
- }
2204
- catch (e) {
2205
- logger.warn('Session reject, error', e);
2206
- }
2207
- });
2208
- }
2209
- _cancel(session_1) {
2210
- return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2211
- if (session.state !== session_state_1.SessionState.Initial && session.state !== session_state_1.SessionState.Establishing) {
2212
- logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: this.getSipSessionId(session) });
2213
- return;
2214
- }
2215
- try {
2216
- return yield session.cancel(options);
2217
- }
2218
- catch (e) {
2219
- logger.warn('Session cancel, error', e);
2220
- }
2221
- });
2222
- }
2223
- _bye(session_1) {
2224
- return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2225
- if (session.state !== session_state_1.SessionState.Established) {
2226
- logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: this.getSipSessionId(session) });
2227
- return null;
2228
- }
2229
- try {
2230
- return yield session.bye(options);
2231
- }
2232
- catch (e) {
2233
- logger.warn('Session bye, error', e);
2234
- }
2235
- return null;
2236
- });
2237
- }
2238
- }
2239
- exports.default = WebRTCClient;