@wazo/sdk 0.43.14 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (887) hide show
  1. package/README.md +84 -57
  2. package/dist/index.js +10630 -0
  3. package/dist/index.mjs +10541 -0
  4. package/dist/types/api-client.d.ts +26 -0
  5. package/dist/types/api-client.d.ts.map +1 -0
  6. package/{lib/types/api-client.d.ts → dist/types/base-api-client.d.ts} +3 -24
  7. package/dist/types/base-api-client.d.ts.map +1 -0
  8. package/dist/types/constants.d.ts +12 -0
  9. package/dist/types/constants.d.ts.map +1 -0
  10. package/{lib → dist}/types/domain/Contact.d.ts +3 -1
  11. package/dist/types/domain/Contact.d.ts.map +1 -0
  12. package/{lib → dist}/types/index.d.ts +14 -13
  13. package/dist/types/index.d.ts.map +1 -0
  14. package/dist/types/service/__tests__/getApiclient.test.d.ts +2 -0
  15. package/dist/types/service/__tests__/getApiclient.test.d.ts.map +1 -0
  16. package/{lib → dist}/types/service/getApiClient.d.ts +5 -2
  17. package/dist/types/service/getApiClient.d.ts.map +1 -0
  18. package/{esm → dist}/types/simple/index.d.ts +1 -1
  19. package/{lib → dist}/types/utils/api-requester.d.ts.map +1 -1
  20. package/dist/wazo-sdk.js +69378 -43
  21. package/dist/wazo-sdk.js.LICENSE.txt +684 -0
  22. package/package.json +10 -21
  23. package/esm/__tests__/api-client.test.js +0 -281
  24. package/esm/__tests__/web-rtc-client.test.js +0 -192
  25. package/esm/api/agentd.js +0 -23
  26. package/esm/api/amid.js +0 -17
  27. package/esm/api/application.js +0 -63
  28. package/esm/api/auth.js +0 -198
  29. package/esm/api/call-logd.js +0 -24
  30. package/esm/api/calld.js +0 -120
  31. package/esm/api/chatd.js +0 -50
  32. package/esm/api/confd.js +0 -77
  33. package/esm/api/ctid-ng.js +0 -96
  34. package/esm/api/dird.js +0 -110
  35. package/esm/api/webhookd.js +0 -7
  36. package/esm/api-client.js +0 -166
  37. package/esm/checker/Checker.js +0 -54
  38. package/esm/checker/checks/aor.js +0 -28
  39. package/esm/checker/checks/api.js +0 -76
  40. package/esm/checker/checks/ice-ipv4.js +0 -69
  41. package/esm/checker/checks/index.js +0 -8
  42. package/esm/checker/checks/symmetric-nat.js +0 -59
  43. package/esm/checker/checks/wazo-websocket.js +0 -38
  44. package/esm/checker/checks/webrtc-transport.js +0 -35
  45. package/esm/checker/checks/webrtc.js +0 -40
  46. package/esm/domain/AdHocAPIConference.js +0 -102
  47. package/esm/domain/Agent.js +0 -30
  48. package/esm/domain/BadResponse.js +0 -21
  49. package/esm/domain/Call.js +0 -123
  50. package/esm/domain/CallLog.js +0 -157
  51. package/esm/domain/CallSession.js +0 -253
  52. package/esm/domain/CallerID.js +0 -24
  53. package/esm/domain/ChatMessage.js +0 -55
  54. package/esm/domain/ChatRoom.js +0 -30
  55. package/esm/domain/Contact.js +0 -464
  56. package/esm/domain/Country.js +0 -19
  57. package/esm/domain/Device/DebugDevice.js +0 -32
  58. package/esm/domain/Device/Device.js +0 -1
  59. package/esm/domain/DirectorySource.js +0 -1
  60. package/esm/domain/ExternalApp.js +0 -24
  61. package/esm/domain/Features.js +0 -77
  62. package/esm/domain/ForwardOption.js +0 -37
  63. package/esm/domain/Incall.js +0 -28
  64. package/esm/domain/IndirectTransfer.js +0 -40
  65. package/esm/domain/Line.js +0 -39
  66. package/esm/domain/Meeting.js +0 -61
  67. package/esm/domain/MeetingAuthorization.js +0 -46
  68. package/esm/domain/MeetingStatus.js +0 -14
  69. package/esm/domain/NotificationOptions.js +0 -45
  70. package/esm/domain/Phone/CTIPhone.js +0 -288
  71. package/esm/domain/Phone/Phone.js +0 -1
  72. package/esm/domain/Phone/WebRTCPhone.js +0 -1482
  73. package/esm/domain/Profile.js +0 -128
  74. package/esm/domain/Recording.js +0 -30
  75. package/esm/domain/Relocation.js +0 -20
  76. package/esm/domain/Room.js +0 -97
  77. package/esm/domain/SFUNotAvailableError.js +0 -6
  78. package/esm/domain/ServerError.js +0 -9
  79. package/esm/domain/Session.js +0 -174
  80. package/esm/domain/SipLine.js +0 -82
  81. package/esm/domain/Subscription.js +0 -42
  82. package/esm/domain/SwitchboardCall.js +0 -56
  83. package/esm/domain/Voicemail.js +0 -76
  84. package/esm/domain/__tests__/Agent.test.js +0 -37
  85. package/esm/domain/__tests__/Call.test.js +0 -25
  86. package/esm/domain/__tests__/CallLog.test.js +0 -181
  87. package/esm/domain/__tests__/CallSession.test.js +0 -78
  88. package/esm/domain/__tests__/Contact.test.js +0 -393
  89. package/esm/domain/__tests__/IndirectTransfer.test.js +0 -67
  90. package/esm/domain/__tests__/Line.test.js +0 -52
  91. package/esm/domain/__tests__/Meeting.test.js +0 -77
  92. package/esm/domain/__tests__/MeetingAuthorization.test.js +0 -49
  93. package/esm/domain/__tests__/Profile.test.js +0 -169
  94. package/esm/domain/__tests__/Room.test.js +0 -206
  95. package/esm/domain/__tests__/Session.test.js +0 -382
  96. package/esm/domain/__tests__/SipLine.test.js +0 -27
  97. package/esm/domain/__tests__/Voicemail.test.js +0 -90
  98. package/esm/domain/types.js +0 -2
  99. package/esm/index.js +0 -50
  100. package/esm/lib/WazoSessionDescriptionHandler.js +0 -429
  101. package/esm/pubkey.js +0 -10
  102. package/esm/service/CallApi.js +0 -61
  103. package/esm/service/IssueReporter.js +0 -331
  104. package/esm/service/__tests__/IssueReporter.test.js +0 -112
  105. package/esm/service/getApiClient.js +0 -92
  106. package/esm/simple/Auth.js +0 -384
  107. package/esm/simple/Configuration.js +0 -13
  108. package/esm/simple/Directory.js +0 -11
  109. package/esm/simple/Phone.js +0 -389
  110. package/esm/simple/Websocket.js +0 -81
  111. package/esm/simple/__tests__/Auth.test.js +0 -144
  112. package/esm/simple/index.js +0 -137
  113. package/esm/simple/room/LocalParticipant.js +0 -4
  114. package/esm/simple/room/Participant.js +0 -315
  115. package/esm/simple/room/RemoteParticipant.js +0 -10
  116. package/esm/simple/room/Room.js +0 -714
  117. package/esm/simple/room/SipRoom.js +0 -121
  118. package/esm/simple/room/Stream.js +0 -47
  119. package/esm/simple/room/__tests__/Participant.test.js +0 -71
  120. package/esm/simple/room/__tests__/RemoteParticipant.test.js +0 -12
  121. package/esm/simple/utils.js +0 -10
  122. package/esm/types/WebSocketMessage.js +0 -1
  123. package/esm/types/api-client.d.ts +0 -64
  124. package/esm/types/api-client.d.ts.map +0 -1
  125. package/esm/types/domain/Contact.d.ts +0 -332
  126. package/esm/types/domain/Contact.d.ts.map +0 -1
  127. package/esm/types/index.d.ts +0 -58
  128. package/esm/types/index.d.ts.map +0 -1
  129. package/esm/types/service/getApiClient.d.ts +0 -18
  130. package/esm/types/service/getApiClient.d.ts.map +0 -1
  131. package/esm/types/utils/api-requester.d.ts.map +0 -1
  132. package/esm/utils/Emitter.js +0 -19
  133. package/esm/utils/Heartbeat.js +0 -73
  134. package/esm/utils/PhoneNumberUtil.js +0 -67
  135. package/esm/utils/__tests__/Heartbeat.test.js +0 -65
  136. package/esm/utils/__tests__/PhoneNumberUtil.test.js +0 -70
  137. package/esm/utils/__tests__/api-requester.test.js +0 -166
  138. package/esm/utils/__tests__/array.test.js +0 -18
  139. package/esm/utils/__tests__/compare-version.test.js +0 -10
  140. package/esm/utils/__tests__/object.test.js +0 -76
  141. package/esm/utils/__tests__/sdp.test.js +0 -172
  142. package/esm/utils/__tests__/string.test.js +0 -49
  143. package/esm/utils/api-requester.js +0 -214
  144. package/esm/utils/array.js +0 -9
  145. package/esm/utils/compare-version.js +0 -17
  146. package/esm/utils/isMobile.js +0 -3
  147. package/esm/utils/new-from.js +0 -7
  148. package/esm/utils/object.js +0 -10
  149. package/esm/utils/once.js +0 -15
  150. package/esm/utils/sdp.js +0 -104
  151. package/esm/utils/string.js +0 -12
  152. package/esm/utils/update-from.js +0 -10
  153. package/esm/utils/webrtc.js +0 -37
  154. package/esm/web-rtc-client.js +0 -2200
  155. package/esm/websocket-client.js +0 -385
  156. package/index.js +0 -1
  157. package/lib/__tests__/api-client.test.js +0 -295
  158. package/lib/__tests__/web-rtc-client.test.js +0 -210
  159. package/lib/api/agentd.js +0 -28
  160. package/lib/api/amid.js +0 -28
  161. package/lib/api/application.js +0 -68
  162. package/lib/api/auth.js +0 -210
  163. package/lib/api/call-logd.js +0 -29
  164. package/lib/api/calld.js +0 -134
  165. package/lib/api/chatd.js +0 -68
  166. package/lib/api/confd.js +0 -91
  167. package/lib/api/ctid-ng.js +0 -101
  168. package/lib/api/dird.js +0 -124
  169. package/lib/api/webhookd.js +0 -12
  170. package/lib/api-client.js +0 -164
  171. package/lib/checker/Checker.js +0 -68
  172. package/lib/checker/checks/aor.js +0 -42
  173. package/lib/checker/checks/api.js +0 -90
  174. package/lib/checker/checks/ice-ipv4.js +0 -73
  175. package/lib/checker/checks/index.js +0 -13
  176. package/lib/checker/checks/symmetric-nat.js +0 -61
  177. package/lib/checker/checks/wazo-websocket.js +0 -63
  178. package/lib/checker/checks/webrtc-transport.js +0 -49
  179. package/lib/checker/checks/webrtc.js +0 -54
  180. package/lib/domain/AdHocAPIConference.js +0 -101
  181. package/lib/domain/Agent.js +0 -25
  182. package/lib/domain/BadResponse.js +0 -19
  183. package/lib/domain/Call.js +0 -112
  184. package/lib/domain/CallLog.js +0 -151
  185. package/lib/domain/CallSession.js +0 -224
  186. package/lib/domain/CallerID.js +0 -27
  187. package/lib/domain/ChatMessage.js +0 -53
  188. package/lib/domain/ChatRoom.js +0 -32
  189. package/lib/domain/Contact.js +0 -439
  190. package/lib/domain/Country.js +0 -21
  191. package/lib/domain/Device/DebugDevice.js +0 -35
  192. package/lib/domain/Device/Device.js +0 -2
  193. package/lib/domain/DirectorySource.js +0 -2
  194. package/lib/domain/ExternalApp.js +0 -27
  195. package/lib/domain/Features.js +0 -87
  196. package/lib/domain/ForwardOption.js +0 -41
  197. package/lib/domain/Incall.js +0 -32
  198. package/lib/domain/IndirectTransfer.js +0 -42
  199. package/lib/domain/Line.js +0 -39
  200. package/lib/domain/Meeting.js +0 -55
  201. package/lib/domain/MeetingAuthorization.js +0 -45
  202. package/lib/domain/MeetingStatus.js +0 -15
  203. package/lib/domain/NotificationOptions.js +0 -49
  204. package/lib/domain/Phone/CTIPhone.js +0 -324
  205. package/lib/domain/Phone/Phone.js +0 -2
  206. package/lib/domain/Phone/WebRTCPhone.js +0 -1492
  207. package/lib/domain/Profile.js +0 -138
  208. package/lib/domain/Recording.js +0 -31
  209. package/lib/domain/Relocation.js +0 -18
  210. package/lib/domain/Room.js +0 -81
  211. package/lib/domain/SFUNotAvailableError.js +0 -9
  212. package/lib/domain/ServerError.js +0 -15
  213. package/lib/domain/Session.js +0 -166
  214. package/lib/domain/SipLine.js +0 -76
  215. package/lib/domain/Subscription.js +0 -34
  216. package/lib/domain/SwitchboardCall.js +0 -50
  217. package/lib/domain/Voicemail.js +0 -77
  218. package/lib/domain/__tests__/Agent.test.js +0 -42
  219. package/lib/domain/__tests__/Call.test.js +0 -30
  220. package/lib/domain/__tests__/CallLog.test.js +0 -166
  221. package/lib/domain/__tests__/CallSession.test.js +0 -83
  222. package/lib/domain/__tests__/Contact.test.js +0 -371
  223. package/lib/domain/__tests__/IndirectTransfer.test.js +0 -81
  224. package/lib/domain/__tests__/Line.test.js +0 -57
  225. package/lib/domain/__tests__/Meeting.test.js +0 -82
  226. package/lib/domain/__tests__/MeetingAuthorization.test.js +0 -54
  227. package/lib/domain/__tests__/Profile.test.js +0 -197
  228. package/lib/domain/__tests__/Room.test.js +0 -220
  229. package/lib/domain/__tests__/Session.test.js +0 -378
  230. package/lib/domain/__tests__/SipLine.test.js +0 -32
  231. package/lib/domain/__tests__/Voicemail.test.js +0 -95
  232. package/lib/domain/types.js +0 -38
  233. package/lib/index.js +0 -125
  234. package/lib/lib/WazoSessionDescriptionHandler.js +0 -434
  235. package/lib/pubkey.js +0 -12
  236. package/lib/service/CallApi.js +0 -112
  237. package/lib/service/IssueReporter.js +0 -317
  238. package/lib/service/__tests__/IssueReporter.test.js +0 -117
  239. package/lib/service/getApiClient.js +0 -112
  240. package/lib/simple/Auth.js +0 -433
  241. package/lib/simple/Configuration.js +0 -31
  242. package/lib/simple/Directory.js +0 -29
  243. package/lib/simple/Phone.js +0 -418
  244. package/lib/simple/Websocket.js +0 -116
  245. package/lib/simple/__tests__/Auth.test.js +0 -181
  246. package/lib/simple/index.js +0 -165
  247. package/lib/simple/room/LocalParticipant.js +0 -9
  248. package/lib/simple/room/Participant.js +0 -302
  249. package/lib/simple/room/RemoteParticipant.js +0 -15
  250. package/lib/simple/room/Room.js +0 -711
  251. package/lib/simple/room/SipRoom.js +0 -141
  252. package/lib/simple/room/Stream.js +0 -50
  253. package/lib/simple/room/__tests__/Participant.test.js +0 -85
  254. package/lib/simple/room/__tests__/RemoteParticipant.test.js +0 -17
  255. package/lib/simple/utils.js +0 -27
  256. package/lib/types/WebSocketMessage.js +0 -2
  257. package/lib/types/__tests__/api-client.test.d.ts +0 -2
  258. package/lib/types/__tests__/api-client.test.d.ts.map +0 -1
  259. package/lib/types/__tests__/web-rtc-client.test.d.ts +0 -2
  260. package/lib/types/__tests__/web-rtc-client.test.d.ts.map +0 -1
  261. package/lib/types/api/agentd.d.ts +0 -17
  262. package/lib/types/api/agentd.d.ts.map +0 -1
  263. package/lib/types/api/amid.d.ts +0 -8
  264. package/lib/types/api/amid.d.ts.map +0 -1
  265. package/lib/types/api/application.d.ts +0 -34
  266. package/lib/types/api/application.d.ts.map +0 -1
  267. package/lib/types/api/auth.d.ts +0 -69
  268. package/lib/types/api/auth.d.ts.map +0 -1
  269. package/lib/types/api/call-logd.d.ts +0 -12
  270. package/lib/types/api/call-logd.d.ts.map +0 -1
  271. package/lib/types/api/calld.d.ts +0 -52
  272. package/lib/types/api/calld.d.ts.map +0 -1
  273. package/lib/types/api/chatd.d.ts +0 -29
  274. package/lib/types/api/chatd.d.ts.map +0 -1
  275. package/lib/types/api/confd.d.ts +0 -46
  276. package/lib/types/api/confd.d.ts.map +0 -1
  277. package/lib/types/api/ctid-ng.d.ts +0 -36
  278. package/lib/types/api/ctid-ng.d.ts.map +0 -1
  279. package/lib/types/api/dird.d.ts +0 -33
  280. package/lib/types/api/dird.d.ts.map +0 -1
  281. package/lib/types/api/webhookd.d.ts +0 -24
  282. package/lib/types/api/webhookd.d.ts.map +0 -1
  283. package/lib/types/api-client.d.ts.map +0 -1
  284. package/lib/types/checker/Checker.d.ts +0 -13
  285. package/lib/types/checker/Checker.d.ts.map +0 -1
  286. package/lib/types/checker/checks/aor.d.ts +0 -6
  287. package/lib/types/checker/checks/aor.d.ts.map +0 -1
  288. package/lib/types/checker/checks/api.d.ts +0 -6
  289. package/lib/types/checker/checks/api.d.ts.map +0 -1
  290. package/lib/types/checker/checks/ice-ipv4.d.ts +0 -6
  291. package/lib/types/checker/checks/ice-ipv4.d.ts.map +0 -1
  292. package/lib/types/checker/checks/index.d.ts +0 -9
  293. package/lib/types/checker/checks/index.d.ts.map +0 -1
  294. package/lib/types/checker/checks/symmetric-nat.d.ts +0 -6
  295. package/lib/types/checker/checks/symmetric-nat.d.ts.map +0 -1
  296. package/lib/types/checker/checks/wazo-websocket.d.ts +0 -6
  297. package/lib/types/checker/checks/wazo-websocket.d.ts.map +0 -1
  298. package/lib/types/checker/checks/webrtc-transport.d.ts +0 -7
  299. package/lib/types/checker/checks/webrtc-transport.d.ts.map +0 -1
  300. package/lib/types/checker/checks/webrtc.d.ts +0 -6
  301. package/lib/types/checker/checks/webrtc.d.ts.map +0 -1
  302. package/lib/types/domain/AdHocAPIConference.d.ts +0 -54
  303. package/lib/types/domain/AdHocAPIConference.d.ts.map +0 -1
  304. package/lib/types/domain/Agent.d.ts +0 -31
  305. package/lib/types/domain/Agent.d.ts.map +0 -1
  306. package/lib/types/domain/BadResponse.d.ts +0 -11
  307. package/lib/types/domain/BadResponse.d.ts.map +0 -1
  308. package/lib/types/domain/Call.d.ts +0 -79
  309. package/lib/types/domain/Call.d.ts.map +0 -1
  310. package/lib/types/domain/CallLog.d.ts +0 -88
  311. package/lib/types/domain/CallLog.d.ts.map +0 -1
  312. package/lib/types/domain/CallSession.d.ts +0 -119
  313. package/lib/types/domain/CallSession.d.ts.map +0 -1
  314. package/lib/types/domain/CallerID.d.ts +0 -22
  315. package/lib/types/domain/CallerID.d.ts.map +0 -1
  316. package/lib/types/domain/ChatMessage.d.ts +0 -41
  317. package/lib/types/domain/ChatMessage.d.ts.map +0 -1
  318. package/lib/types/domain/ChatRoom.d.ts +0 -22
  319. package/lib/types/domain/ChatRoom.d.ts.map +0 -1
  320. package/lib/types/domain/Contact.d.ts.map +0 -1
  321. package/lib/types/domain/Country.d.ts +0 -21
  322. package/lib/types/domain/Country.d.ts.map +0 -1
  323. package/lib/types/domain/Device/DebugDevice.d.ts +0 -14
  324. package/lib/types/domain/Device/DebugDevice.d.ts.map +0 -1
  325. package/lib/types/domain/Device/Device.d.ts +0 -13
  326. package/lib/types/domain/Device/Device.d.ts.map +0 -1
  327. package/lib/types/domain/DirectorySource.d.ts +0 -13
  328. package/lib/types/domain/DirectorySource.d.ts.map +0 -1
  329. package/lib/types/domain/ExternalApp.d.ts +0 -22
  330. package/lib/types/domain/ExternalApp.d.ts.map +0 -1
  331. package/lib/types/domain/Features.d.ts +0 -26
  332. package/lib/types/domain/Features.d.ts.map +0 -1
  333. package/lib/types/domain/ForwardOption.d.ts +0 -28
  334. package/lib/types/domain/ForwardOption.d.ts.map +0 -1
  335. package/lib/types/domain/Incall.d.ts +0 -21
  336. package/lib/types/domain/Incall.d.ts.map +0 -1
  337. package/lib/types/domain/IndirectTransfer.d.ts +0 -31
  338. package/lib/types/domain/IndirectTransfer.d.ts.map +0 -1
  339. package/lib/types/domain/Line.d.ts +0 -35
  340. package/lib/types/domain/Line.d.ts.map +0 -1
  341. package/lib/types/domain/Meeting.d.ts +0 -45
  342. package/lib/types/domain/Meeting.d.ts.map +0 -1
  343. package/lib/types/domain/MeetingAuthorization.d.ts +0 -32
  344. package/lib/types/domain/MeetingAuthorization.d.ts.map +0 -1
  345. package/lib/types/domain/MeetingStatus.d.ts +0 -10
  346. package/lib/types/domain/MeetingStatus.d.ts.map +0 -1
  347. package/lib/types/domain/NotificationOptions.d.ts +0 -22
  348. package/lib/types/domain/NotificationOptions.d.ts.map +0 -1
  349. package/lib/types/domain/Phone/CTIPhone.d.ts +0 -79
  350. package/lib/types/domain/Phone/CTIPhone.d.ts.map +0 -1
  351. package/lib/types/domain/Phone/Phone.d.ts +0 -83
  352. package/lib/types/domain/Phone/Phone.d.ts.map +0 -1
  353. package/lib/types/domain/Phone/WebRTCPhone.d.ts +0 -183
  354. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +0 -1
  355. package/lib/types/domain/Profile.d.ts +0 -155
  356. package/lib/types/domain/Profile.d.ts.map +0 -1
  357. package/lib/types/domain/Recording.d.ts +0 -26
  358. package/lib/types/domain/Recording.d.ts.map +0 -1
  359. package/lib/types/domain/Relocation.d.ts +0 -23
  360. package/lib/types/domain/Relocation.d.ts.map +0 -1
  361. package/lib/types/domain/Room.d.ts +0 -33
  362. package/lib/types/domain/Room.d.ts.map +0 -1
  363. package/lib/types/domain/SFUNotAvailableError.d.ts +0 -4
  364. package/lib/types/domain/SFUNotAvailableError.d.ts.map +0 -1
  365. package/lib/types/domain/ServerError.d.ts +0 -6
  366. package/lib/types/domain/ServerError.d.ts.map +0 -1
  367. package/lib/types/domain/Session.d.ts +0 -100
  368. package/lib/types/domain/Session.d.ts.map +0 -1
  369. package/lib/types/domain/SipLine.d.ts +0 -54
  370. package/lib/types/domain/SipLine.d.ts.map +0 -1
  371. package/lib/types/domain/Subscription.d.ts +0 -43
  372. package/lib/types/domain/Subscription.d.ts.map +0 -1
  373. package/lib/types/domain/SwitchboardCall.d.ts +0 -62
  374. package/lib/types/domain/SwitchboardCall.d.ts.map +0 -1
  375. package/lib/types/domain/Voicemail.d.ts +0 -58
  376. package/lib/types/domain/Voicemail.d.ts.map +0 -1
  377. package/lib/types/domain/__tests__/Agent.test.d.ts +0 -2
  378. package/lib/types/domain/__tests__/Agent.test.d.ts.map +0 -1
  379. package/lib/types/domain/__tests__/Call.test.d.ts +0 -2
  380. package/lib/types/domain/__tests__/Call.test.d.ts.map +0 -1
  381. package/lib/types/domain/__tests__/CallLog.test.d.ts +0 -2
  382. package/lib/types/domain/__tests__/CallLog.test.d.ts.map +0 -1
  383. package/lib/types/domain/__tests__/CallSession.test.d.ts +0 -2
  384. package/lib/types/domain/__tests__/CallSession.test.d.ts.map +0 -1
  385. package/lib/types/domain/__tests__/Contact.test.d.ts +0 -2
  386. package/lib/types/domain/__tests__/Contact.test.d.ts.map +0 -1
  387. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts +0 -2
  388. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts.map +0 -1
  389. package/lib/types/domain/__tests__/Line.test.d.ts +0 -2
  390. package/lib/types/domain/__tests__/Line.test.d.ts.map +0 -1
  391. package/lib/types/domain/__tests__/Meeting.test.d.ts +0 -2
  392. package/lib/types/domain/__tests__/Meeting.test.d.ts.map +0 -1
  393. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts +0 -2
  394. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +0 -1
  395. package/lib/types/domain/__tests__/Profile.test.d.ts +0 -2
  396. package/lib/types/domain/__tests__/Profile.test.d.ts.map +0 -1
  397. package/lib/types/domain/__tests__/Room.test.d.ts +0 -2
  398. package/lib/types/domain/__tests__/Room.test.d.ts.map +0 -1
  399. package/lib/types/domain/__tests__/Session.test.d.ts +0 -2
  400. package/lib/types/domain/__tests__/Session.test.d.ts.map +0 -1
  401. package/lib/types/domain/__tests__/SipLine.test.d.ts +0 -2
  402. package/lib/types/domain/__tests__/SipLine.test.d.ts.map +0 -1
  403. package/lib/types/domain/__tests__/Voicemail.test.d.ts +0 -2
  404. package/lib/types/domain/__tests__/Voicemail.test.d.ts.map +0 -1
  405. package/lib/types/domain/types.d.ts +0 -378
  406. package/lib/types/domain/types.d.ts.map +0 -1
  407. package/lib/types/index.d.ts.map +0 -1
  408. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +0 -31
  409. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +0 -1
  410. package/lib/types/pubkey.d.ts +0 -3
  411. package/lib/types/pubkey.d.ts.map +0 -1
  412. package/lib/types/service/CallApi.d.ts +0 -28
  413. package/lib/types/service/CallApi.d.ts.map +0 -1
  414. package/lib/types/service/IssueReporter.d.ts +0 -42
  415. package/lib/types/service/IssueReporter.d.ts.map +0 -1
  416. package/lib/types/service/__tests__/IssueReporter.test.d.ts +0 -2
  417. package/lib/types/service/__tests__/IssueReporter.test.d.ts.map +0 -1
  418. package/lib/types/service/getApiClient.d.ts.map +0 -1
  419. package/lib/types/simple/Auth.d.ts +0 -75
  420. package/lib/types/simple/Auth.d.ts.map +0 -1
  421. package/lib/types/simple/Configuration.d.ts +0 -7
  422. package/lib/types/simple/Configuration.d.ts.map +0 -1
  423. package/lib/types/simple/Directory.d.ts +0 -7
  424. package/lib/types/simple/Directory.d.ts.map +0 -1
  425. package/lib/types/simple/Phone.d.ts +0 -119
  426. package/lib/types/simple/Phone.d.ts.map +0 -1
  427. package/lib/types/simple/Websocket.d.ts +0 -21
  428. package/lib/types/simple/Websocket.d.ts.map +0 -1
  429. package/lib/types/simple/__tests__/Auth.test.d.ts +0 -2
  430. package/lib/types/simple/__tests__/Auth.test.d.ts.map +0 -1
  431. package/lib/types/simple/index.d.ts +0 -153
  432. package/lib/types/simple/index.d.ts.map +0 -1
  433. package/lib/types/simple/room/LocalParticipant.d.ts +0 -5
  434. package/lib/types/simple/room/LocalParticipant.d.ts.map +0 -1
  435. package/lib/types/simple/room/Participant.d.ts +0 -77
  436. package/lib/types/simple/room/Participant.d.ts.map +0 -1
  437. package/lib/types/simple/room/RemoteParticipant.d.ts +0 -7
  438. package/lib/types/simple/room/RemoteParticipant.d.ts.map +0 -1
  439. package/lib/types/simple/room/Room.d.ts +0 -127
  440. package/lib/types/simple/room/Room.d.ts.map +0 -1
  441. package/lib/types/simple/room/SipRoom.d.ts +0 -14
  442. package/lib/types/simple/room/SipRoom.d.ts.map +0 -1
  443. package/lib/types/simple/room/Stream.d.ts +0 -13
  444. package/lib/types/simple/room/Stream.d.ts.map +0 -1
  445. package/lib/types/simple/room/__tests__/Participant.test.d.ts +0 -2
  446. package/lib/types/simple/room/__tests__/Participant.test.d.ts.map +0 -1
  447. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts +0 -2
  448. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +0 -1
  449. package/lib/types/simple/utils.d.ts +0 -3
  450. package/lib/types/simple/utils.d.ts.map +0 -1
  451. package/lib/types/types/WebSocketMessage.d.ts +0 -285
  452. package/lib/types/types/WebSocketMessage.d.ts.map +0 -1
  453. package/lib/types/utils/Emitter.d.ts +0 -18
  454. package/lib/types/utils/Emitter.d.ts.map +0 -1
  455. package/lib/types/utils/Heartbeat.d.ts +0 -22
  456. package/lib/types/utils/Heartbeat.d.ts.map +0 -1
  457. package/lib/types/utils/PhoneNumberUtil.d.ts +0 -7
  458. package/lib/types/utils/PhoneNumberUtil.d.ts.map +0 -1
  459. package/lib/types/utils/__tests__/Heartbeat.test.d.ts +0 -2
  460. package/lib/types/utils/__tests__/Heartbeat.test.d.ts.map +0 -1
  461. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts +0 -2
  462. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +0 -1
  463. package/lib/types/utils/__tests__/api-requester.test.d.ts +0 -2
  464. package/lib/types/utils/__tests__/api-requester.test.d.ts.map +0 -1
  465. package/lib/types/utils/__tests__/array.test.d.ts +0 -2
  466. package/lib/types/utils/__tests__/array.test.d.ts.map +0 -1
  467. package/lib/types/utils/__tests__/compare-version.test.d.ts +0 -2
  468. package/lib/types/utils/__tests__/compare-version.test.d.ts.map +0 -1
  469. package/lib/types/utils/__tests__/object.test.d.ts +0 -2
  470. package/lib/types/utils/__tests__/object.test.d.ts.map +0 -1
  471. package/lib/types/utils/__tests__/sdp.test.d.ts +0 -2
  472. package/lib/types/utils/__tests__/sdp.test.d.ts.map +0 -1
  473. package/lib/types/utils/__tests__/string.test.d.ts +0 -2
  474. package/lib/types/utils/__tests__/string.test.d.ts.map +0 -1
  475. package/lib/types/utils/api-requester.d.ts +0 -48
  476. package/lib/types/utils/array.d.ts +0 -2
  477. package/lib/types/utils/array.d.ts.map +0 -1
  478. package/lib/types/utils/compare-version.d.ts +0 -3
  479. package/lib/types/utils/compare-version.d.ts.map +0 -1
  480. package/lib/types/utils/isMobile.d.ts +0 -3
  481. package/lib/types/utils/isMobile.d.ts.map +0 -1
  482. package/lib/types/utils/new-from.d.ts +0 -3
  483. package/lib/types/utils/new-from.d.ts.map +0 -1
  484. package/lib/types/utils/object.d.ts +0 -2
  485. package/lib/types/utils/object.d.ts.map +0 -1
  486. package/lib/types/utils/once.d.ts +0 -2
  487. package/lib/types/utils/once.d.ts.map +0 -1
  488. package/lib/types/utils/sdp.d.ts +0 -28
  489. package/lib/types/utils/sdp.d.ts.map +0 -1
  490. package/lib/types/utils/string.d.ts +0 -3
  491. package/lib/types/utils/string.d.ts.map +0 -1
  492. package/lib/types/utils/update-from.d.ts +0 -3
  493. package/lib/types/utils/update-from.d.ts.map +0 -1
  494. package/lib/types/utils/webrtc.d.ts +0 -15
  495. package/lib/types/utils/webrtc.d.ts.map +0 -1
  496. package/lib/types/web-rtc-client.d.ts +0 -198
  497. package/lib/types/web-rtc-client.d.ts.map +0 -1
  498. package/lib/types/websocket-client.d.ts +0 -138
  499. package/lib/types/websocket-client.d.ts.map +0 -1
  500. package/lib/utils/Emitter.js +0 -24
  501. package/lib/utils/Heartbeat.js +0 -66
  502. package/lib/utils/PhoneNumberUtil.js +0 -73
  503. package/lib/utils/__tests__/Heartbeat.test.js +0 -79
  504. package/lib/utils/__tests__/PhoneNumberUtil.test.js +0 -72
  505. package/lib/utils/__tests__/api-requester.test.js +0 -180
  506. package/lib/utils/__tests__/array.test.js +0 -20
  507. package/lib/utils/__tests__/compare-version.test.js +0 -15
  508. package/lib/utils/__tests__/object.test.js +0 -78
  509. package/lib/utils/__tests__/sdp.test.js +0 -188
  510. package/lib/utils/__tests__/string.test.js +0 -51
  511. package/lib/utils/api-requester.js +0 -201
  512. package/lib/utils/array.js +0 -13
  513. package/lib/utils/compare-version.js +0 -19
  514. package/lib/utils/isMobile.js +0 -5
  515. package/lib/utils/new-from.js +0 -9
  516. package/lib/utils/object.js +0 -14
  517. package/lib/utils/once.js +0 -18
  518. package/lib/utils/sdp.js +0 -115
  519. package/lib/utils/string.js +0 -17
  520. package/lib/utils/update-from.js +0 -12
  521. package/lib/utils/webrtc.js +0 -41
  522. package/lib/web-rtc-client.js +0 -2239
  523. package/lib/websocket-client.js +0 -390
  524. package/src/__tests__/api-client.test.ts +0 -315
  525. package/src/__tests__/web-rtc-client.test.ts +0 -198
  526. package/src/api/agentd.ts +0 -37
  527. package/src/api/amid.ts +0 -25
  528. package/src/api/application.ts +0 -96
  529. package/src/api/auth.ts +0 -305
  530. package/src/api/call-logd.ts +0 -38
  531. package/src/api/calld.ts +0 -185
  532. package/src/api/chatd.ts +0 -87
  533. package/src/api/confd.ts +0 -119
  534. package/src/api/ctid-ng.ts +0 -152
  535. package/src/api/dird.ts +0 -143
  536. package/src/api/webhookd.ts +0 -30
  537. package/src/api-client.ts +0 -233
  538. package/src/checker/Checker.ts +0 -73
  539. package/src/checker/checks/aor.ts +0 -34
  540. package/src/checker/checks/api.ts +0 -78
  541. package/src/checker/checks/ice-ipv4.ts +0 -80
  542. package/src/checker/checks/index.ts +0 -9
  543. package/src/checker/checks/symmetric-nat.ts +0 -69
  544. package/src/checker/checks/wazo-websocket.ts +0 -41
  545. package/src/checker/checks/webrtc-transport.ts +0 -42
  546. package/src/checker/checks/webrtc.ts +0 -48
  547. package/src/domain/AdHocAPIConference.ts +0 -166
  548. package/src/domain/Agent.ts +0 -68
  549. package/src/domain/BadResponse.ts +0 -29
  550. package/src/domain/Call.ts +0 -217
  551. package/src/domain/CallLog.ts +0 -265
  552. package/src/domain/CallSession.ts +0 -401
  553. package/src/domain/CallerID.ts +0 -49
  554. package/src/domain/ChatMessage.ts +0 -107
  555. package/src/domain/ChatRoom.ts +0 -55
  556. package/src/domain/Contact.ts +0 -851
  557. package/src/domain/Country.ts +0 -19
  558. package/src/domain/Device/DebugDevice.ts +0 -44
  559. package/src/domain/Device/Device.ts +0 -12
  560. package/src/domain/DirectorySource.ts +0 -13
  561. package/src/domain/ExternalApp.ts +0 -46
  562. package/src/domain/Features.ts +0 -105
  563. package/src/domain/ForwardOption.ts +0 -65
  564. package/src/domain/Incall.ts +0 -50
  565. package/src/domain/IndirectTransfer.ts +0 -73
  566. package/src/domain/Line.ts +0 -79
  567. package/src/domain/Meeting.ts +0 -113
  568. package/src/domain/MeetingAuthorization.ts +0 -81
  569. package/src/domain/MeetingStatus.ts +0 -23
  570. package/src/domain/NotificationOptions.ts +0 -68
  571. package/src/domain/Phone/CTIPhone.ts +0 -381
  572. package/src/domain/Phone/Phone.ts +0 -81
  573. package/src/domain/Phone/WebRTCPhone.ts +0 -1830
  574. package/src/domain/Profile.ts +0 -289
  575. package/src/domain/Recording.ts +0 -60
  576. package/src/domain/Relocation.ts +0 -45
  577. package/src/domain/Room.ts +0 -141
  578. package/src/domain/SFUNotAvailableError.ts +0 -7
  579. package/src/domain/ServerError.ts +0 -12
  580. package/src/domain/Session.ts +0 -297
  581. package/src/domain/SipLine.ts +0 -154
  582. package/src/domain/Subscription.ts +0 -95
  583. package/src/domain/SwitchboardCall.ts +0 -127
  584. package/src/domain/Voicemail.ts +0 -138
  585. package/src/domain/__tests__/Agent.test.ts +0 -38
  586. package/src/domain/__tests__/Call.test.ts +0 -26
  587. package/src/domain/__tests__/CallLog.test.ts +0 -203
  588. package/src/domain/__tests__/CallSession.test.ts +0 -80
  589. package/src/domain/__tests__/Contact.test.ts +0 -407
  590. package/src/domain/__tests__/IndirectTransfer.test.ts +0 -68
  591. package/src/domain/__tests__/Line.test.ts +0 -53
  592. package/src/domain/__tests__/Meeting.test.ts +0 -93
  593. package/src/domain/__tests__/MeetingAuthorization.test.ts +0 -50
  594. package/src/domain/__tests__/Profile.test.ts +0 -170
  595. package/src/domain/__tests__/Room.test.ts +0 -207
  596. package/src/domain/__tests__/Session.test.ts +0 -385
  597. package/src/domain/__tests__/SipLine.test.ts +0 -30
  598. package/src/domain/__tests__/Voicemail.test.ts +0 -91
  599. package/src/domain/types.ts +0 -331
  600. package/src/index.ts +0 -59
  601. package/src/lib/WazoSessionDescriptionHandler.ts +0 -532
  602. package/src/pubkey.ts +0 -11
  603. package/src/service/CallApi.ts +0 -86
  604. package/src/service/IssueReporter.ts +0 -434
  605. package/src/service/__tests__/IssueReporter.test.ts +0 -127
  606. package/src/service/getApiClient.ts +0 -106
  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 -295
  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/checker/Checker.d.ts +0 -0
  677. /package/{esm → dist}/types/checker/Checker.d.ts.map +0 -0
  678. /package/{esm → dist}/types/checker/checks/aor.d.ts +0 -0
  679. /package/{esm → dist}/types/checker/checks/aor.d.ts.map +0 -0
  680. /package/{esm → dist}/types/checker/checks/api.d.ts +0 -0
  681. /package/{esm → dist}/types/checker/checks/api.d.ts.map +0 -0
  682. /package/{esm → dist}/types/checker/checks/ice-ipv4.d.ts +0 -0
  683. /package/{esm → dist}/types/checker/checks/ice-ipv4.d.ts.map +0 -0
  684. /package/{esm → dist}/types/checker/checks/index.d.ts +0 -0
  685. /package/{esm → dist}/types/checker/checks/index.d.ts.map +0 -0
  686. /package/{esm → dist}/types/checker/checks/symmetric-nat.d.ts +0 -0
  687. /package/{esm → dist}/types/checker/checks/symmetric-nat.d.ts.map +0 -0
  688. /package/{esm → dist}/types/checker/checks/wazo-websocket.d.ts +0 -0
  689. /package/{esm → dist}/types/checker/checks/wazo-websocket.d.ts.map +0 -0
  690. /package/{esm → dist}/types/checker/checks/webrtc-transport.d.ts +0 -0
  691. /package/{esm → dist}/types/checker/checks/webrtc-transport.d.ts.map +0 -0
  692. /package/{esm → dist}/types/checker/checks/webrtc.d.ts +0 -0
  693. /package/{esm → dist}/types/checker/checks/webrtc.d.ts.map +0 -0
  694. /package/{esm → dist}/types/domain/AdHocAPIConference.d.ts +0 -0
  695. /package/{esm → dist}/types/domain/AdHocAPIConference.d.ts.map +0 -0
  696. /package/{esm → dist}/types/domain/Agent.d.ts +0 -0
  697. /package/{esm → dist}/types/domain/Agent.d.ts.map +0 -0
  698. /package/{esm → dist}/types/domain/BadResponse.d.ts +0 -0
  699. /package/{esm → dist}/types/domain/BadResponse.d.ts.map +0 -0
  700. /package/{esm → dist}/types/domain/Call.d.ts +0 -0
  701. /package/{esm → dist}/types/domain/Call.d.ts.map +0 -0
  702. /package/{esm → dist}/types/domain/CallLog.d.ts +0 -0
  703. /package/{esm → dist}/types/domain/CallLog.d.ts.map +0 -0
  704. /package/{esm → dist}/types/domain/CallSession.d.ts +0 -0
  705. /package/{esm → dist}/types/domain/CallSession.d.ts.map +0 -0
  706. /package/{esm → dist}/types/domain/CallerID.d.ts +0 -0
  707. /package/{esm → dist}/types/domain/CallerID.d.ts.map +0 -0
  708. /package/{esm → dist}/types/domain/ChatMessage.d.ts +0 -0
  709. /package/{esm → dist}/types/domain/ChatMessage.d.ts.map +0 -0
  710. /package/{esm → dist}/types/domain/ChatRoom.d.ts +0 -0
  711. /package/{esm → dist}/types/domain/ChatRoom.d.ts.map +0 -0
  712. /package/{esm → dist}/types/domain/Country.d.ts +0 -0
  713. /package/{esm → dist}/types/domain/Country.d.ts.map +0 -0
  714. /package/{esm → dist}/types/domain/Device/DebugDevice.d.ts +0 -0
  715. /package/{esm → dist}/types/domain/Device/DebugDevice.d.ts.map +0 -0
  716. /package/{esm → dist}/types/domain/Device/Device.d.ts +0 -0
  717. /package/{esm → dist}/types/domain/Device/Device.d.ts.map +0 -0
  718. /package/{esm → dist}/types/domain/DirectorySource.d.ts +0 -0
  719. /package/{esm → dist}/types/domain/DirectorySource.d.ts.map +0 -0
  720. /package/{esm → dist}/types/domain/ExternalApp.d.ts +0 -0
  721. /package/{esm → dist}/types/domain/ExternalApp.d.ts.map +0 -0
  722. /package/{esm → dist}/types/domain/Features.d.ts +0 -0
  723. /package/{esm → dist}/types/domain/Features.d.ts.map +0 -0
  724. /package/{esm → dist}/types/domain/ForwardOption.d.ts +0 -0
  725. /package/{esm → dist}/types/domain/ForwardOption.d.ts.map +0 -0
  726. /package/{esm → dist}/types/domain/Incall.d.ts +0 -0
  727. /package/{esm → dist}/types/domain/Incall.d.ts.map +0 -0
  728. /package/{esm → dist}/types/domain/IndirectTransfer.d.ts +0 -0
  729. /package/{esm → dist}/types/domain/IndirectTransfer.d.ts.map +0 -0
  730. /package/{esm → dist}/types/domain/Line.d.ts +0 -0
  731. /package/{esm → dist}/types/domain/Line.d.ts.map +0 -0
  732. /package/{esm → dist}/types/domain/Meeting.d.ts +0 -0
  733. /package/{esm → dist}/types/domain/Meeting.d.ts.map +0 -0
  734. /package/{esm → dist}/types/domain/MeetingAuthorization.d.ts +0 -0
  735. /package/{esm → dist}/types/domain/MeetingAuthorization.d.ts.map +0 -0
  736. /package/{esm → dist}/types/domain/MeetingStatus.d.ts +0 -0
  737. /package/{esm → dist}/types/domain/MeetingStatus.d.ts.map +0 -0
  738. /package/{esm → dist}/types/domain/NotificationOptions.d.ts +0 -0
  739. /package/{esm → dist}/types/domain/NotificationOptions.d.ts.map +0 -0
  740. /package/{esm → dist}/types/domain/Phone/CTIPhone.d.ts +0 -0
  741. /package/{esm → dist}/types/domain/Phone/CTIPhone.d.ts.map +0 -0
  742. /package/{esm → dist}/types/domain/Phone/Phone.d.ts +0 -0
  743. /package/{esm → dist}/types/domain/Phone/Phone.d.ts.map +0 -0
  744. /package/{esm → dist}/types/domain/Phone/WebRTCPhone.d.ts +0 -0
  745. /package/{esm → dist}/types/domain/Phone/WebRTCPhone.d.ts.map +0 -0
  746. /package/{esm → dist}/types/domain/Profile.d.ts +0 -0
  747. /package/{esm → dist}/types/domain/Profile.d.ts.map +0 -0
  748. /package/{esm → dist}/types/domain/Recording.d.ts +0 -0
  749. /package/{esm → dist}/types/domain/Recording.d.ts.map +0 -0
  750. /package/{esm → dist}/types/domain/Relocation.d.ts +0 -0
  751. /package/{esm → dist}/types/domain/Relocation.d.ts.map +0 -0
  752. /package/{esm → dist}/types/domain/Room.d.ts +0 -0
  753. /package/{esm → dist}/types/domain/Room.d.ts.map +0 -0
  754. /package/{esm → dist}/types/domain/SFUNotAvailableError.d.ts +0 -0
  755. /package/{esm → dist}/types/domain/SFUNotAvailableError.d.ts.map +0 -0
  756. /package/{esm → dist}/types/domain/ServerError.d.ts +0 -0
  757. /package/{esm → dist}/types/domain/ServerError.d.ts.map +0 -0
  758. /package/{esm → dist}/types/domain/Session.d.ts +0 -0
  759. /package/{esm → dist}/types/domain/Session.d.ts.map +0 -0
  760. /package/{esm → dist}/types/domain/SipLine.d.ts +0 -0
  761. /package/{esm → dist}/types/domain/SipLine.d.ts.map +0 -0
  762. /package/{esm → dist}/types/domain/Subscription.d.ts +0 -0
  763. /package/{esm → dist}/types/domain/Subscription.d.ts.map +0 -0
  764. /package/{esm → dist}/types/domain/SwitchboardCall.d.ts +0 -0
  765. /package/{esm → dist}/types/domain/SwitchboardCall.d.ts.map +0 -0
  766. /package/{esm → dist}/types/domain/Voicemail.d.ts +0 -0
  767. /package/{esm → dist}/types/domain/Voicemail.d.ts.map +0 -0
  768. /package/{esm → dist}/types/domain/__tests__/Agent.test.d.ts +0 -0
  769. /package/{esm → dist}/types/domain/__tests__/Agent.test.d.ts.map +0 -0
  770. /package/{esm → dist}/types/domain/__tests__/Call.test.d.ts +0 -0
  771. /package/{esm → dist}/types/domain/__tests__/Call.test.d.ts.map +0 -0
  772. /package/{esm → dist}/types/domain/__tests__/CallLog.test.d.ts +0 -0
  773. /package/{esm → dist}/types/domain/__tests__/CallLog.test.d.ts.map +0 -0
  774. /package/{esm → dist}/types/domain/__tests__/CallSession.test.d.ts +0 -0
  775. /package/{esm → dist}/types/domain/__tests__/CallSession.test.d.ts.map +0 -0
  776. /package/{esm → dist}/types/domain/__tests__/Contact.test.d.ts +0 -0
  777. /package/{esm → dist}/types/domain/__tests__/Contact.test.d.ts.map +0 -0
  778. /package/{esm → dist}/types/domain/__tests__/IndirectTransfer.test.d.ts +0 -0
  779. /package/{esm → dist}/types/domain/__tests__/IndirectTransfer.test.d.ts.map +0 -0
  780. /package/{esm → dist}/types/domain/__tests__/Line.test.d.ts +0 -0
  781. /package/{esm → dist}/types/domain/__tests__/Line.test.d.ts.map +0 -0
  782. /package/{esm → dist}/types/domain/__tests__/Meeting.test.d.ts +0 -0
  783. /package/{esm → dist}/types/domain/__tests__/Meeting.test.d.ts.map +0 -0
  784. /package/{esm → dist}/types/domain/__tests__/MeetingAuthorization.test.d.ts +0 -0
  785. /package/{esm → dist}/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +0 -0
  786. /package/{esm → dist}/types/domain/__tests__/Profile.test.d.ts +0 -0
  787. /package/{esm → dist}/types/domain/__tests__/Profile.test.d.ts.map +0 -0
  788. /package/{esm → dist}/types/domain/__tests__/Room.test.d.ts +0 -0
  789. /package/{esm → dist}/types/domain/__tests__/Room.test.d.ts.map +0 -0
  790. /package/{esm → dist}/types/domain/__tests__/Session.test.d.ts +0 -0
  791. /package/{esm → dist}/types/domain/__tests__/Session.test.d.ts.map +0 -0
  792. /package/{esm → dist}/types/domain/__tests__/SipLine.test.d.ts +0 -0
  793. /package/{esm → dist}/types/domain/__tests__/SipLine.test.d.ts.map +0 -0
  794. /package/{esm → dist}/types/domain/__tests__/Voicemail.test.d.ts +0 -0
  795. /package/{esm → dist}/types/domain/__tests__/Voicemail.test.d.ts.map +0 -0
  796. /package/{esm → dist}/types/domain/types.d.ts +0 -0
  797. /package/{esm → dist}/types/domain/types.d.ts.map +0 -0
  798. /package/{esm → dist}/types/lib/WazoSessionDescriptionHandler.d.ts +0 -0
  799. /package/{esm → dist}/types/lib/WazoSessionDescriptionHandler.d.ts.map +0 -0
  800. /package/{esm → dist}/types/pubkey.d.ts +0 -0
  801. /package/{esm → dist}/types/pubkey.d.ts.map +0 -0
  802. /package/{esm → dist}/types/service/CallApi.d.ts +0 -0
  803. /package/{esm → dist}/types/service/CallApi.d.ts.map +0 -0
  804. /package/{esm → dist}/types/service/IssueReporter.d.ts +0 -0
  805. /package/{esm → dist}/types/service/IssueReporter.d.ts.map +0 -0
  806. /package/{esm → dist}/types/service/__tests__/IssueReporter.test.d.ts +0 -0
  807. /package/{esm → dist}/types/service/__tests__/IssueReporter.test.d.ts.map +0 -0
  808. /package/{esm → dist}/types/simple/Auth.d.ts +0 -0
  809. /package/{esm → dist}/types/simple/Auth.d.ts.map +0 -0
  810. /package/{esm → dist}/types/simple/Configuration.d.ts +0 -0
  811. /package/{esm → dist}/types/simple/Configuration.d.ts.map +0 -0
  812. /package/{esm → dist}/types/simple/Directory.d.ts +0 -0
  813. /package/{esm → dist}/types/simple/Directory.d.ts.map +0 -0
  814. /package/{esm → dist}/types/simple/Phone.d.ts +0 -0
  815. /package/{esm → dist}/types/simple/Phone.d.ts.map +0 -0
  816. /package/{esm → dist}/types/simple/Websocket.d.ts +0 -0
  817. /package/{esm → dist}/types/simple/Websocket.d.ts.map +0 -0
  818. /package/{esm → dist}/types/simple/__tests__/Auth.test.d.ts +0 -0
  819. /package/{esm → dist}/types/simple/__tests__/Auth.test.d.ts.map +0 -0
  820. /package/{esm → dist}/types/simple/index.d.ts.map +0 -0
  821. /package/{esm → dist}/types/simple/room/LocalParticipant.d.ts +0 -0
  822. /package/{esm → dist}/types/simple/room/LocalParticipant.d.ts.map +0 -0
  823. /package/{esm → dist}/types/simple/room/Participant.d.ts +0 -0
  824. /package/{esm → dist}/types/simple/room/Participant.d.ts.map +0 -0
  825. /package/{esm → dist}/types/simple/room/RemoteParticipant.d.ts +0 -0
  826. /package/{esm → dist}/types/simple/room/RemoteParticipant.d.ts.map +0 -0
  827. /package/{esm → dist}/types/simple/room/Room.d.ts +0 -0
  828. /package/{esm → dist}/types/simple/room/Room.d.ts.map +0 -0
  829. /package/{esm → dist}/types/simple/room/SipRoom.d.ts +0 -0
  830. /package/{esm → dist}/types/simple/room/SipRoom.d.ts.map +0 -0
  831. /package/{esm → dist}/types/simple/room/Stream.d.ts +0 -0
  832. /package/{esm → dist}/types/simple/room/Stream.d.ts.map +0 -0
  833. /package/{esm → dist}/types/simple/room/__tests__/Participant.test.d.ts +0 -0
  834. /package/{esm → dist}/types/simple/room/__tests__/Participant.test.d.ts.map +0 -0
  835. /package/{esm → dist}/types/simple/room/__tests__/RemoteParticipant.test.d.ts +0 -0
  836. /package/{esm → dist}/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +0 -0
  837. /package/{esm → dist}/types/simple/utils.d.ts +0 -0
  838. /package/{esm → dist}/types/simple/utils.d.ts.map +0 -0
  839. /package/{esm → dist}/types/types/WebSocketMessage.d.ts +0 -0
  840. /package/{esm → dist}/types/types/WebSocketMessage.d.ts.map +0 -0
  841. /package/{esm → dist}/types/utils/Emitter.d.ts +0 -0
  842. /package/{esm → dist}/types/utils/Emitter.d.ts.map +0 -0
  843. /package/{esm → dist}/types/utils/Heartbeat.d.ts +0 -0
  844. /package/{esm → dist}/types/utils/Heartbeat.d.ts.map +0 -0
  845. /package/{esm → dist}/types/utils/PhoneNumberUtil.d.ts +0 -0
  846. /package/{esm → dist}/types/utils/PhoneNumberUtil.d.ts.map +0 -0
  847. /package/{esm → dist}/types/utils/__tests__/Heartbeat.test.d.ts +0 -0
  848. /package/{esm → dist}/types/utils/__tests__/Heartbeat.test.d.ts.map +0 -0
  849. /package/{esm → dist}/types/utils/__tests__/PhoneNumberUtil.test.d.ts +0 -0
  850. /package/{esm → dist}/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +0 -0
  851. /package/{esm → dist}/types/utils/__tests__/api-requester.test.d.ts +0 -0
  852. /package/{esm → dist}/types/utils/__tests__/api-requester.test.d.ts.map +0 -0
  853. /package/{esm → dist}/types/utils/__tests__/array.test.d.ts +0 -0
  854. /package/{esm → dist}/types/utils/__tests__/array.test.d.ts.map +0 -0
  855. /package/{esm → dist}/types/utils/__tests__/compare-version.test.d.ts +0 -0
  856. /package/{esm → dist}/types/utils/__tests__/compare-version.test.d.ts.map +0 -0
  857. /package/{esm → dist}/types/utils/__tests__/object.test.d.ts +0 -0
  858. /package/{esm → dist}/types/utils/__tests__/object.test.d.ts.map +0 -0
  859. /package/{esm → dist}/types/utils/__tests__/sdp.test.d.ts +0 -0
  860. /package/{esm → dist}/types/utils/__tests__/sdp.test.d.ts.map +0 -0
  861. /package/{esm → dist}/types/utils/__tests__/string.test.d.ts +0 -0
  862. /package/{esm → dist}/types/utils/__tests__/string.test.d.ts.map +0 -0
  863. /package/{esm → dist}/types/utils/api-requester.d.ts +0 -0
  864. /package/{esm → dist}/types/utils/array.d.ts +0 -0
  865. /package/{esm → dist}/types/utils/array.d.ts.map +0 -0
  866. /package/{esm → dist}/types/utils/compare-version.d.ts +0 -0
  867. /package/{esm → dist}/types/utils/compare-version.d.ts.map +0 -0
  868. /package/{esm → dist}/types/utils/isMobile.d.ts +0 -0
  869. /package/{esm → dist}/types/utils/isMobile.d.ts.map +0 -0
  870. /package/{esm → dist}/types/utils/new-from.d.ts +0 -0
  871. /package/{esm → dist}/types/utils/new-from.d.ts.map +0 -0
  872. /package/{esm → dist}/types/utils/object.d.ts +0 -0
  873. /package/{esm → dist}/types/utils/object.d.ts.map +0 -0
  874. /package/{esm → dist}/types/utils/once.d.ts +0 -0
  875. /package/{esm → dist}/types/utils/once.d.ts.map +0 -0
  876. /package/{esm → dist}/types/utils/sdp.d.ts +0 -0
  877. /package/{esm → dist}/types/utils/sdp.d.ts.map +0 -0
  878. /package/{esm → dist}/types/utils/string.d.ts +0 -0
  879. /package/{esm → dist}/types/utils/string.d.ts.map +0 -0
  880. /package/{esm → dist}/types/utils/update-from.d.ts +0 -0
  881. /package/{esm → dist}/types/utils/update-from.d.ts.map +0 -0
  882. /package/{esm → dist}/types/utils/webrtc.d.ts +0 -0
  883. /package/{esm → dist}/types/utils/webrtc.d.ts.map +0 -0
  884. /package/{esm → dist}/types/web-rtc-client.d.ts +0 -0
  885. /package/{esm → dist}/types/web-rtc-client.d.ts.map +0 -0
  886. /package/{esm → dist}/types/websocket-client.d.ts +0 -0
  887. /package/{esm → dist}/types/websocket-client.d.ts.map +0 -0
@@ -1,1482 +0,0 @@
1
- import { SessionState } from 'sip.js/lib/api/session-state';
2
- import { Invitation } from 'sip.js/lib/api';
3
- import CallSession from '../CallSession';
4
- import Emitter from '../../utils/Emitter';
5
- import IssueReporter from '../../service/IssueReporter';
6
- export const ON_USER_AGENT = 'onUserAgent';
7
- export const ON_REGISTERED = 'onRegistered';
8
- export const ON_UNREGISTERED = 'onUnRegistered';
9
- export const ON_PROGRESS = 'onProgress';
10
- export const ON_CALL_ACCEPTED = 'onCallAccepted';
11
- export const ON_CALL_ANSWERED = 'onCallAnswered';
12
- export const ON_CALL_INCOMING = 'onCallIncoming';
13
- export const ON_CALL_OUTGOING = 'onCallOutgoing';
14
- export const ON_CALL_MUTED = 'onCallMuted';
15
- export const ON_CALL_UNMUTED = 'onCallUnmuted';
16
- export const ON_CALL_RESUMED = 'onCallResumed';
17
- export const ON_CALL_HELD = 'onCallHeld';
18
- export const ON_CALL_UNHELD = 'onCallUnHeld';
19
- export const ON_CAMERA_DISABLED = 'onCameraDisabled';
20
- export const ON_CAMERA_RESUMED = 'onCameraResumed';
21
- export const ON_CALL_CANCELED = 'onCallCanceled';
22
- export const ON_CALL_FAILED = 'onCallFailed';
23
- export const ON_CALL_REJECTED = 'onCallRejected';
24
- export const ON_CALL_ENDED = 'onCallEnded';
25
- export const ON_CALL_ENDING = 'onCallEnding';
26
- export const ON_MESSAGE = 'onMessage';
27
- export const ON_REINVITE = 'reinvite';
28
- export const ON_TRACK = 'onTrack';
29
- export const ON_AUDIO_STREAM = 'onAudioStream';
30
- export const ON_VIDEO_STREAM = 'onVideoStream';
31
- export const ON_REMOVE_STREAM = 'onRemoveStream';
32
- export const ON_SHARE_SCREEN_STARTED = 'onScreenShareStarted';
33
- export const ON_SHARE_SCREEN_ENDING = 'onScreenShareEnding';
34
- export const ON_SHARE_SCREEN_ENDED = 'onScreenShareEnded';
35
- export const ON_TERMINATE_SOUND = 'terminateSound';
36
- export const ON_PLAY_RING_SOUND = 'playRingingSound';
37
- export const ON_PLAY_INBOUND_CALL_SIGNAL_SOUND = 'playInboundCallSignalSound';
38
- export const ON_PLAY_HANGUP_SOUND = 'playHangupSound';
39
- export const ON_PLAY_PROGRESS_SOUND = 'playProgressSound';
40
- export const ON_VIDEO_INPUT_CHANGE = 'videoInputChange';
41
- export const ON_CALL_ERROR = 'onCallError';
42
- export const ON_MESSAGE_TRACK_UPDATED = 'onTrackUpdated';
43
- export const ON_NETWORK_STATS = 'onNetworkStats';
44
- export const ON_CHAT = 'phone/ON_CHAT';
45
- export const ON_SIGNAL = 'phone/ON_SIGNAL';
46
- export const ON_DISCONNECTED = 'onDisconnected';
47
- export const ON_EARLY_MEDIA = 'onEarlyMedia';
48
- export const MESSAGE_TYPE_CHAT = 'message/TYPE_CHAT';
49
- export const MESSAGE_TYPE_SIGNAL = 'message/TYPE_SIGNAL';
50
- export const events = [ON_USER_AGENT, ON_REGISTERED, ON_UNREGISTERED, ON_PROGRESS, ON_CALL_ACCEPTED, ON_CALL_ANSWERED, ON_CALL_INCOMING, ON_CALL_OUTGOING, ON_CALL_MUTED, ON_CALL_UNMUTED, ON_CALL_RESUMED, ON_CALL_HELD, ON_CALL_UNHELD, ON_CAMERA_DISABLED, ON_CALL_FAILED, ON_CALL_ENDED, ON_CALL_REJECTED, ON_MESSAGE, ON_REINVITE, ON_TRACK, ON_AUDIO_STREAM, ON_VIDEO_STREAM, ON_REMOVE_STREAM, ON_SHARE_SCREEN_ENDED, ON_TERMINATE_SOUND, ON_PLAY_RING_SOUND, ON_PLAY_INBOUND_CALL_SIGNAL_SOUND, ON_PLAY_HANGUP_SOUND, ON_PLAY_PROGRESS_SOUND, ON_VIDEO_INPUT_CHANGE, ON_SHARE_SCREEN_STARTED, ON_CALL_ERROR, ON_CHAT, ON_SIGNAL, ON_NETWORK_STATS, ON_DISCONNECTED, ON_EARLY_MEDIA];
51
- const logger = IssueReporter.loggerFor('webrtc-phone');
52
- export default class WebRTCPhone extends Emitter {
53
- client;
54
- allowVideo;
55
- callSessions;
56
- incomingSessions;
57
- currentSipSession;
58
- currentCallSession;
59
- audioOutputDeviceId;
60
- audioRingDeviceId;
61
- audioOutputVolume;
62
- audioRingVolume;
63
- ringingEnabled;
64
- acceptedSessions;
65
- rejectedSessions;
66
- ignoredSessions;
67
- currentScreenShare;
68
- lastScreenShare;
69
- shouldSendReinvite;
70
- constructor(client, audioOutputDeviceId, allowVideo = false, audioRingDeviceId) {
71
- super();
72
- this.client = client;
73
- this.allowVideo = allowVideo;
74
- this.callSessions = {};
75
- this.audioOutputDeviceId = audioOutputDeviceId;
76
- this.audioRingDeviceId = audioRingDeviceId || audioOutputDeviceId;
77
- this.audioOutputVolume = 1;
78
- this.audioRingVolume = 1;
79
- this.incomingSessions = [];
80
- this.ringingEnabled = true;
81
- this.shouldSendReinvite = false;
82
- this.bindClientEvents();
83
- this.acceptedSessions = {};
84
- this.rejectedSessions = {};
85
- this.ignoredSessions = {};
86
- }
87
- register() {
88
- logger.info('WebRTC register', { client: !!this.client });
89
- if (!this.client) {
90
- return Promise.resolve();
91
- }
92
- return this.client.register().then(() => {
93
- logger.info('WebRTC register, registered');
94
- return this.bindClientEvents();
95
- }).catch(error => {
96
- // Avoid exception on `t.server.scheme` in sip transport when losing the webrtc socket connection
97
- console.error('register error', error, error.message, error.stack);
98
- logger.error('WebRTC register error', {
99
- message: error.message,
100
- stack: error.stack,
101
- });
102
- });
103
- }
104
- unregister() {
105
- if (!this.client || !this.client.isRegistered()) {
106
- return null;
107
- }
108
- return this.client.unregister();
109
- }
110
- stop() {
111
- if (!this.client) {
112
- return;
113
- }
114
- logger.info('WebRTC phone stop');
115
- this.client.stop();
116
- }
117
- removeIncomingSessions(id) {
118
- this.incomingSessions = this.incomingSessions.filter(sessionId => sessionId !== id);
119
- }
120
- isWebRTC() {
121
- return true;
122
- }
123
- async sendReinvite(callSession, constraints = null, conference = false, audioOnly = false, iceRestart = false) {
124
- const sipSession = this.findSipSession(callSession);
125
- logger.info('WebRTC phone - send reinvite', {
126
- sessionId: this.getSipSessionId(sipSession),
127
- constraints,
128
- audioOnly,
129
- conference,
130
- iceRestart,
131
- });
132
- if (!sipSession) {
133
- return;
134
- }
135
- const shouldScreenShare = constraints?.screen;
136
- const isUpgrade = shouldScreenShare || constraints?.video;
137
- // Downgrade
138
- if (constraints && !isUpgrade) {
139
- // No reinvite needed
140
- this._downgradeToAudio(callSession);
141
- return;
142
- }
143
- if (isUpgrade) {
144
- const shouldReinvite = await this._upgradeToVideo(callSession, constraints, conference);
145
- if (!shouldReinvite) {
146
- return;
147
- }
148
- }
149
- return this.client.reinvite(sipSession, constraints, conference, audioOnly, iceRestart);
150
- }
151
- getUserAgent() {
152
- return this.client?.config?.userAgentString || 'webrtc-phone';
153
- }
154
- startHeartbeat() {
155
- logger.info('WebRTC phone - start heartbeat', {
156
- client: !!this.client,
157
- hasHeartbeat: this.client.hasHeartbeat(),
158
- });
159
- if (!this.client || this.client.hasHeartbeat()) {
160
- return;
161
- }
162
- this.client.startHeartbeat();
163
- }
164
- stopHeartbeat() {
165
- logger.info('WebRTC phone - stopHeartbeat', {
166
- client: !!this.client,
167
- });
168
- if (!this.client) {
169
- return;
170
- }
171
- this.client.stopHeartbeat();
172
- }
173
- setOnHeartbeatTimeout(cb) {
174
- this.client.setOnHeartbeatTimeout(cb);
175
- }
176
- setOnHeartbeatCallback(cb) {
177
- this.client.setOnHeartbeatCallback(cb);
178
- }
179
- reconnect() {
180
- logger.info('WebRTC phone - reconnect', {
181
- client: !!this.client,
182
- });
183
- if (!this.client) {
184
- return;
185
- }
186
- this.client.attemptReconnection();
187
- }
188
- getOptions() {
189
- return {
190
- accept: true,
191
- decline: true,
192
- mute: true,
193
- hold: true,
194
- transfer: true,
195
- sendKey: true,
196
- addParticipant: false,
197
- record: true,
198
- merge: true,
199
- };
200
- }
201
- onConnect() {
202
- if (!this.client) {
203
- return Promise.reject(new Error('No webrtc client'));
204
- }
205
- return this.client.onConnect();
206
- }
207
- onDisconnect() {
208
- if (!this.client) {
209
- return Promise.reject(new Error('No webrtc client'));
210
- }
211
- return this.client.onDisconnect();
212
- }
213
- _downgradeToAudio(callSession, withMessage = true) {
214
- const sipSession = this.findSipSession(callSession);
215
- if (!sipSession) {
216
- return false;
217
- }
218
- logger.info('Downgrade to audio', {
219
- id: callSession ? callSession.getId() : null,
220
- withMessage,
221
- });
222
- this.client.downgradeToAudio(sipSession);
223
- if (callSession) {
224
- callSession.cameraEnabled = false;
225
- this._updateCallSession(callSession);
226
- }
227
- if (withMessage) {
228
- this._sendReinviteMessage(callSession, false);
229
- }
230
- return true;
231
- }
232
- // Returns true if we need to send a re-INVITE request
233
- async _upgradeToVideo(callSession, constraints, isConference) {
234
- const sipSession = this.findSipSession(callSession);
235
- if (!sipSession) {
236
- return Promise.resolve(false);
237
- }
238
- logger.info('Upgrade to video', {
239
- id: callSession ? callSession.getId() : null,
240
- constraints,
241
- isConference,
242
- });
243
- const shouldScreenShare = constraints && !!constraints.screen;
244
- const desktop = constraints && constraints.desktop;
245
- const options = sipSession.sessionDescriptionHandlerOptionsReInvite;
246
- const wasAudioOnly = options?.audioOnly;
247
- const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
248
- if (callSession) {
249
- callSession.cameraEnabled = true;
250
- this._updateCallSession(callSession);
251
- }
252
- // If no stream is returned, it means we have to reinvite
253
- if (!newStream) {
254
- return true;
255
- }
256
- this._sendReinviteMessage(callSession, true);
257
- if (shouldScreenShare) {
258
- this._onScreenSharing(newStream, sipSession, callSession, false, desktop);
259
- }
260
- // We have to reinvite to change the direction on the bundle when upgrading from an audioOnly conference
261
- if (isConference && wasAudioOnly) {
262
- return true;
263
- }
264
- // No reinvite needed here
265
- return false;
266
- }
267
- _sendReinviteMessage(callSession, isUpgrade) {
268
- const sipSession = this.findSipSession(callSession);
269
- logger.info('Sending reinvite message', {
270
- id: callSession ? callSession.getId() : null,
271
- isUpgrade,
272
- });
273
- // Have to send the message after a delay due to latency to update the remote peer
274
- setTimeout(() => {
275
- this.sendMessage(sipSession, JSON.stringify({
276
- type: MESSAGE_TYPE_SIGNAL,
277
- content: {
278
- type: ON_MESSAGE_TRACK_UPDATED,
279
- update: isUpgrade ? 'upgrade' : 'downgrade',
280
- sipCallId: sipSession && this.getSipSessionId(sipSession),
281
- callId: callSession ? callSession.callId : null,
282
- number: callSession ? callSession.number : null,
283
- callerNumber: callSession ? callSession.callerNumber : null,
284
- },
285
- }));
286
- }, 2500);
287
- }
288
- _bindEvents(sipSession) {
289
- const sipSessionId = this.getSipSessionId(sipSession);
290
- if (sipSession instanceof Invitation) {
291
- // Monkey patch to know when canceled with the CANCEL message
292
- const onCancel = sipSession._onCancel.bind(sipSession);
293
- sipSession._onCancel = (message) => {
294
- logger.trace('on sip session canceled', {
295
- callId: message.callId,
296
- sipSessionId,
297
- });
298
- onCancel(message);
299
- const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
300
- const callSession = this._createCallSession(sipSession);
301
- if (sipSessionId) {
302
- delete this.callSessions[sipSessionId];
303
- }
304
- this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
305
- };
306
- }
307
- sipSession.stateChange.addListener((newState) => {
308
- switch (newState) {
309
- case SessionState.Terminating:
310
- logger.info('WebRTC phone - call terminating', {
311
- sipId: this.getSipSessionId(sipSession),
312
- });
313
- this.eventEmitter.emit(ON_CALL_ENDING, this._createCallSession(sipSession));
314
- break;
315
- case SessionState.Terminated:
316
- {
317
- logger.info('WebRTC phone - call terminated', {
318
- sipId: this.getSipSessionId(sipSession),
319
- });
320
- // Should be called before `_onCallTerminated` or the callCount will not decrement...
321
- const callSession = this._createCallSession(sipSession);
322
- callSession.endTime = new Date();
323
- const wasCurrentSession = this._onCallTerminated(sipSession);
324
- return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
325
- }
326
- default:
327
- break;
328
- }
329
- });
330
- if (!sipSession.sessionDescriptionHandler) {
331
- return;
332
- }
333
- // Video events
334
- const sdh = sipSession.sessionDescriptionHandler;
335
- const peerConnection = sdh.peerConnection;
336
- if (!peerConnection) {
337
- logger.info('null peer connection');
338
- return;
339
- }
340
- peerConnection.ontrack = (rawEvent) => {
341
- const event = rawEvent;
342
- const [stream] = event.streams;
343
- const kind = event && event.track && event.track.kind;
344
- logger.info('on track stream called on the peer connection', {
345
- callId: this.getSipSessionId(sipSession),
346
- streamId: stream ? stream.id : null,
347
- tracks: stream ? stream.getTracks() : null,
348
- kind,
349
- });
350
- if (kind === 'audio') {
351
- return this.eventEmitter.emit(ON_AUDIO_STREAM, stream);
352
- }
353
- return this.eventEmitter.emit(ON_VIDEO_STREAM, stream, event.track.id, event, sipSession);
354
- };
355
- peerConnection.onremovestream = (event) => {
356
- logger.info('on remove stream called on the peer connection', {
357
- id: event.stream.id,
358
- tracks: event.stream.getTracks(),
359
- });
360
- this.eventEmitter.emit(ON_REMOVE_STREAM, event.stream);
361
- };
362
- }
363
- async startScreenSharing(constraints, callSession) {
364
- logger.info('WebRTC - start screen sharing', {
365
- constraints,
366
- id: callSession ? callSession.getId() : null,
367
- });
368
- const screenShareStream = await this.client.getStreamFromConstraints(constraints);
369
- if (!screenShareStream) {
370
- throw new Error(`Can't create media stream for screensharing with: ${JSON.stringify(constraints)}`);
371
- }
372
- const screenTrack = screenShareStream.getVideoTracks()[0];
373
- const sipSession = this.currentSipSession;
374
- const pc = sipSession && this.client.getPeerConnection(this.getSipSessionId(sipSession));
375
- const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
376
- const localStream = sipSession && this.client.getLocalStream(this.getSipSessionId(sipSession));
377
- const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
378
- const hadVideo = !!videoTrack;
379
- // Stop local video tracks
380
- if (videoTrack && localStream) {
381
- videoTrack.enabled = false;
382
- videoTrack.stop();
383
- localStream.removeTrack(videoTrack);
384
- }
385
- if (localStream) {
386
- localStream.addTrack(screenTrack);
387
- }
388
- if (sender) {
389
- sender.replaceTrack(screenTrack);
390
- }
391
- this._onScreenSharing(screenShareStream, sipSession, callSession, hadVideo, constraints.desktop);
392
- return screenShareStream;
393
- }
394
- async stopScreenSharing(restoreLocalStream = true, callSession) {
395
- if (!this.currentScreenShare) {
396
- return;
397
- }
398
- logger.info('WebRTC phone - stop screen sharing', {
399
- restoreLocalStream,
400
- });
401
- let reinvited = null;
402
- try {
403
- if (this.currentScreenShare.stream) {
404
- this.currentScreenShare.stream.getTracks()
405
- .filter((track) => track.enabled && track.kind === 'video')
406
- .forEach((track) => track.stop());
407
- }
408
- if (restoreLocalStream) {
409
- const targetCallSession = callSession || this.currentCallSession;
410
- const conference = this.isConference(targetCallSession);
411
- // When stopping screenshare and we had video before that, we have to re-upgrade
412
- // When upgrading directly to screenshare (eg: we don't have a videoLocalStream to replace)
413
- // We have to downgrade to audio.
414
- const screenshareStopped = this.currentScreenShare.hadVideo;
415
- const constraints = {
416
- audio: false,
417
- video: screenshareStopped,
418
- };
419
- // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
420
- this._downgradeToAudio(targetCallSession, false);
421
- // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
422
- await new Promise(resolve => setTimeout(resolve, 500));
423
- reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
424
- }
425
- }
426
- catch (e) {
427
- console.warn(e);
428
- }
429
- const sipSession = this.currentSipSession;
430
- this.eventEmitter.emit(ON_SHARE_SCREEN_ENDED, callSession && sipSession ? this._createCallSession(sipSession, callSession, {
431
- screensharing: false,
432
- }) : null);
433
- this.currentScreenShare = null;
434
- return reinvited;
435
- }
436
- _onScreenSharing(screenStream, sipSession, callSession, hadVideo, desktop) {
437
- const screenTrack = screenStream.getVideoTracks()[0];
438
- const sipSessionId = this.getSipSessionId(sipSession);
439
- const pc = this.client.getPeerConnection(sipSessionId);
440
- const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
441
- logger.info('WebRTC phone - on screensharing', {
442
- hadVideo,
443
- id: this.getSipSessionId(sipSession),
444
- screenTrack,
445
- });
446
- if (screenTrack) {
447
- screenTrack.onended = () => {
448
- logger.info('WebRTC phone - on screenshare ended', {
449
- hadVideo,
450
- id: this.getSipSessionId(sipSession),
451
- screenTrack,
452
- });
453
- this.eventEmitter.emit(ON_SHARE_SCREEN_ENDING, this._createCallSession(sipSession, callSession));
454
- };
455
- }
456
- this.currentScreenShare = {
457
- stream: screenStream,
458
- hadVideo,
459
- sender,
460
- sipSessionId,
461
- desktop,
462
- };
463
- this.client.setLocalMediaStream(this.getSipSessionId(sipSession), screenStream);
464
- this.eventEmitter.emit(ON_SHARE_SCREEN_STARTED, this._createCallSession(sipSession, callSession, {
465
- screensharing: true,
466
- }), screenStream);
467
- }
468
- _onCallAccepted(sipSession, cameraEnabled) {
469
- logger.info('WebRTC phone - on call accepted', {
470
- sipId: this.getSipSessionId(sipSession),
471
- cameraEnabled,
472
- });
473
- const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
474
- if (this.currentSipSession && !this.isCurrentCallSipSession(callSession)) {
475
- logger.info('WebRTC phone - on call accepted with another ongoing call, holding it', {
476
- sipId: this.getSipSessionId(sipSession),
477
- cameraEnabled,
478
- });
479
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
480
- }
481
- this.currentSipSession = sipSession;
482
- this.currentCallSession = callSession;
483
- this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call accepted');
484
- const sipSessionId = this.getSipSessionId(sipSession);
485
- if (sipSessionId) {
486
- this.removeIncomingSessions(sipSessionId);
487
- }
488
- callSession.answerTime = new Date();
489
- this._updateCallSession(callSession);
490
- this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
491
- return callSession;
492
- }
493
- async changeAudioDevice(id) {
494
- logger.info('WebRTC phone - change audio device', {
495
- deviceId: id,
496
- });
497
- this.audioOutputDeviceId = id;
498
- return this.client.changeAudioOutputDevice(id);
499
- }
500
- createAudioElementFor(sessionId) {
501
- return this.client.createAudioElementFor(sessionId);
502
- }
503
- changeRingDevice(id) {
504
- logger.info('WebRTC phone - changing ring device', {
505
- id,
506
- });
507
- this.audioRingDeviceId = id;
508
- }
509
- // volume is a value between 0 and 1
510
- changeAudioVolume(volume) {
511
- logger.info('WebRTC phone - changing audio volume', {
512
- volume,
513
- });
514
- this.audioOutputVolume = volume;
515
- this.client.changeAudioOutputVolume(volume);
516
- }
517
- // volume is a value between 0 and 1
518
- changeRingVolume(volume) {
519
- logger.info('WebRTC phone - changing ring volume', {
520
- volume,
521
- });
522
- this.audioRingVolume = volume;
523
- }
524
- changeAudioInputDevice(id, force) {
525
- logger.info('WebRTC phone - changeAudio input device', {
526
- deviceId: id,
527
- });
528
- return this.client.changeAudioInputDevice(id, this.currentSipSession, force);
529
- }
530
- async changeVideoInputDevice(id) {
531
- logger.info('WebRTC phone - change video input device', {
532
- deviceId: id,
533
- });
534
- return this.client.changeVideoInputDevice(id, this.currentSipSession);
535
- }
536
- changeSessionVideoInputDevice(id) {
537
- logger.info('WebRTC phone - change session video input device', {
538
- deviceId: id,
539
- });
540
- return this.currentSipSession && this.client.changeSessionVideoInputDevice(id, this.currentSipSession);
541
- }
542
- _onCallTerminated(sipSession) {
543
- const sipSessionId = this.getSipSessionId(sipSession);
544
- logger.info('WebRTC phone - on call terminated', {
545
- sipId: this.getSipSessionId(sipSession),
546
- sipSessionId,
547
- ids: Object.keys(this.callSessions),
548
- });
549
- const callSession = this._createCallSession(sipSession);
550
- const isCurrentSession = this.isCurrentCallSipSession(callSession);
551
- const isCurrentIncomingCall = callSession.is(this.getIncomingCallSession());
552
- // If the terminated call was an incoming call, we have to re-trigger if it's was the first incoming call
553
- // Otherwise, we have to re-trigger an incoming call event if another call is incoming
554
- const shouldRetrigger = isCurrentSession ? this.incomingSessions.length : isCurrentIncomingCall;
555
- // Terminate incoming sound only for the ringing call
556
- // (so another terminated call won't stop the incoming call sound)
557
- if (isCurrentIncomingCall) {
558
- setTimeout(() => {
559
- // Avoid race condition when the other is calling and hanging up immediately
560
- this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call terminated');
561
- }, 5);
562
- }
563
- if (sipSessionId) {
564
- this.removeIncomingSessions(sipSessionId);
565
- delete this.callSessions[sipSessionId];
566
- }
567
- if (isCurrentSession) {
568
- this.currentSipSession = undefined;
569
- this.currentCallSession = undefined;
570
- }
571
- const hasIncomingCallSession = this.hasIncomingCallSession();
572
- // Re-trigger incoming call event for remaining incoming calls
573
- logger.info('WebRTC phone - check to re-trigger incoming call', {
574
- sipId: this.getSipSessionId(sipSession),
575
- shouldRetrigger,
576
- hasIncomingCallSession,
577
- });
578
- this.client.onCallEnded(sipSession);
579
- if (hasIncomingCallSession && shouldRetrigger) {
580
- const nextCallSession = this.getIncomingCallSession();
581
- // Avoid race condition
582
- setTimeout(() => {
583
- if (this.ringingEnabled) {
584
- if (!this.currentCallSession) {
585
- this.eventEmitter.emit(ON_PLAY_RING_SOUND, this.audioRingDeviceId, this.audioRingVolume, nextCallSession);
586
- }
587
- else {
588
- this.eventEmitter.emit(ON_PLAY_INBOUND_CALL_SIGNAL_SOUND, this.audioOutputDeviceId, this.audioOutputVolume, nextCallSession);
589
- }
590
- }
591
- this.eventEmitter.emit(ON_CALL_INCOMING, nextCallSession, nextCallSession?.cameraEnabled);
592
- }, 100);
593
- }
594
- if (callSession.getId() in this.ignoredSessions) {
595
- return false;
596
- }
597
- // @ts-ignore: does not exist
598
- if (!sipSession.isCanceled) {
599
- setTimeout(() => {
600
- this.eventEmitter.emit(ON_PLAY_HANGUP_SOUND, this.audioOutputDeviceId, this.audioOutputVolume, callSession);
601
- }, 10);
602
- }
603
- return isCurrentSession;
604
- }
605
- setActiveSipSession(callSession) {
606
- const sipSessionId = this.findSipSession(callSession);
607
- if (!sipSessionId) {
608
- return;
609
- }
610
- this.currentSipSession = sipSessionId;
611
- this.currentCallSession = callSession;
612
- }
613
- hasAnActiveCall() {
614
- return !!this.currentSipSession;
615
- }
616
- // /!\ In some case with react-native webrtc the session will have only one audio stream set
617
- // Maybe due to https://github.com/react-native-webrtc/react-native-webrtc/issues/401
618
- hasActiveRemoteVideoStream() {
619
- const sipSession = this.currentSipSession;
620
- if (!sipSession) {
621
- return false;
622
- }
623
- const sdh = sipSession.sessionDescriptionHandler;
624
- const peerConnection = sdh.peerConnection;
625
- const remoteStream = peerConnection.getRemoteStreams().find((stream) => !!stream.getVideoTracks().length);
626
- return remoteStream && remoteStream.getVideoTracks().some(track => !track.muted);
627
- }
628
- callCount() {
629
- return Object.keys(this.callSessions).length;
630
- }
631
- isCurrentCallSipSession(callSession) {
632
- if (!this.currentSipSession) {
633
- return false;
634
- }
635
- return this.currentSipSession && this.getSipSessionId(this.currentSipSession) === callSession.getId();
636
- }
637
- hasVideo(callSession) {
638
- return this.client.hasVideo(callSession.getId());
639
- }
640
- hasAVideoTrack(callSession) {
641
- return this.client.hasAVideoTrack(callSession.getId());
642
- }
643
- // Deprecated
644
- getLocalStreamForCall(callSession) {
645
- logger.warn('WebRTCPhone.getLocalStreamForCall is deprecated, use WebRTCPhone.getLocalStream instead');
646
- return this.getLocalStream(callSession);
647
- }
648
- // Deprecated
649
- getRemoteStreamForCall(callSession) {
650
- logger.warn('WebRTCPhone.getRemoteStreamForCall is deprecated, use WebRTCPhone.getRemoteStream instead');
651
- return this.getRemoteVideoStream(callSession);
652
- }
653
- getRemoteStreamsForCall(callSession) {
654
- logger.warn('WebRTCPhone.getRemoteStreamsForCall is deprecated, use WebRTCPhone.getRemoteStreams instead');
655
- return this.getRemoteStream(callSession);
656
- }
657
- accept(callSession, cameraEnabled) {
658
- logger.info('WebRTC phone - accept call', {
659
- id: callSession ? callSession.getId() : 'n/a',
660
- cameraEnabled,
661
- });
662
- if (this.currentSipSession && !this.isCurrentCallSipSession(callSession)) {
663
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
664
- }
665
- if (!callSession) {
666
- logger.warn('no CallSession to accept.');
667
- return Promise.resolve(null);
668
- }
669
- const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
670
- if (sipSessionId && !(sipSessionId in this.callSessions)) {
671
- logger.warn('Call session already ended or not found, can\'t accept it.', {
672
- sipSessionId,
673
- });
674
- return Promise.resolve(null);
675
- }
676
- if (callSession.getId() in this.acceptedSessions) {
677
- logger.warn('CallSession already accepted.', {
678
- id: callSession ? callSession.getId() : 'n/a',
679
- });
680
- return Promise.resolve(callSession.sipCallId);
681
- }
682
- this.shouldSendReinvite = false;
683
- callSession.answerTime = new Date();
684
- this._updateCallSession(callSession);
685
- this.acceptedSessions[callSession.getId()] = true;
686
- this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
687
- const sipSession = this.client.getSipSession(callSession.getId());
688
- if (sipSession) {
689
- logger.info('accept call, session found', { sipId: this.getSipSessionId(sipSession) });
690
- return this.client.answer(sipSession, this.allowVideo ? cameraEnabled : false).then(() => {
691
- return callSession.sipCallId;
692
- }).catch(e => {
693
- logger.error(e);
694
- this.endCurrentCall(callSession);
695
- throw e;
696
- });
697
- }
698
- const error = 'No CallSession found to accept.';
699
- logger.warn(error, {
700
- id: callSession ? callSession.getId() : 'n/a',
701
- ids: this.client.getSipSessionIds(),
702
- });
703
- if (callSession) {
704
- this.eventEmitter.emit(ON_CALL_ERROR, new Error(error), callSession);
705
- }
706
- return Promise.resolve(null);
707
- }
708
- isAccepted(callSession) {
709
- return callSession && callSession.getId() in this.acceptedSessions;
710
- }
711
- async reject(callSession) {
712
- logger.info('reject WebRTC called', {
713
- id: callSession.getId(),
714
- });
715
- this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call rejected locally');
716
- if (!callSession || callSession.getId() in this.rejectedSessions) {
717
- return;
718
- }
719
- this.shouldSendReinvite = false;
720
- this.rejectedSessions[callSession.getId()] = true;
721
- const sipSession = this.findSipSession(callSession);
722
- if (sipSession) {
723
- logger.info('WebRTC rejecting', {
724
- sipId: this.getSipSessionId(sipSession),
725
- });
726
- this.client.hangup(sipSession);
727
- }
728
- }
729
- async ignore(callSession) {
730
- logger.info('WebRTC ignore', {
731
- id: callSession.getId(),
732
- });
733
- // kill the ring
734
- this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'ignoring call');
735
- this.ignoredSessions[callSession.getId()] = true;
736
- callSession.ignore();
737
- }
738
- atxfer(callSession) {
739
- const sipSession = this.findSipSession(callSession);
740
- if (sipSession) {
741
- logger.info('WebRTC atxfer', {
742
- sipId: this.getSipSessionId(sipSession),
743
- });
744
- return this.client.atxfer(sipSession);
745
- }
746
- }
747
- hold(callSession, withEvent = true) {
748
- logger.info('WebRTC hold', {
749
- id: callSession.getId(),
750
- });
751
- const sipSession = this.findSipSession(callSession);
752
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
753
- }
754
- // @Deprecated
755
- unhold(callSession, withEvent = true) {
756
- console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
757
- return this.resume(callSession, withEvent);
758
- }
759
- resume(callSession, withEvent = true) {
760
- logger.info('WebRTC resume called', {
761
- id: callSession ? callSession.getId() : null,
762
- });
763
- const sipSession = this.findSipSession(callSession);
764
- if (!sipSession) {
765
- return new Promise((resolve, reject) => reject(new Error('No session to resume')));
766
- }
767
- logger.info('WebRTC resuming', {
768
- sipId: this.getSipSessionId(sipSession),
769
- });
770
- // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
771
- if (this.currentSipSession && this.getSipSessionId(this.currentSipSession) !== this.getSipSessionId(sipSession)) {
772
- logger.info('WebRTC hold call after resume', {
773
- id: this.getSipSessionId(this.currentSipSession),
774
- });
775
- this.holdSipSession(this.currentSipSession, this.currentCallSession, withEvent);
776
- }
777
- const promise = this.unholdSipSession(sipSession, callSession, withEvent);
778
- this.currentSipSession = sipSession;
779
- if (callSession) {
780
- this.currentCallSession = callSession;
781
- }
782
- return promise;
783
- }
784
- async holdSipSession(sipSession, callSession, withEvent = true) {
785
- if (!sipSession) {
786
- return new Promise((resolve, reject) => reject(new Error('No session to hold')));
787
- }
788
- const sessionId = this.getSipSessionId(sipSession);
789
- const hasVideo = this.client.hasLocalVideo(sessionId);
790
- logger.info('WebRTC hold sip session', {
791
- sipId: this.getSipSessionId(sipSession),
792
- hasVideo,
793
- });
794
- // Stop screenshare if needed
795
- if (this.currentScreenShare && this.currentScreenShare.sipSessionId === sessionId) {
796
- this.lastScreenShare = this.currentScreenShare;
797
- await this.stopScreenSharing(false, callSession);
798
- }
799
- // Downgrade to audio if needed
800
- if (hasVideo) {
801
- await this.client.downgradeToAudio(sipSession);
802
- }
803
- const isConference = !!callSession && callSession.isConference();
804
- const promise = this.client.hold(sipSession, isConference, hasVideo);
805
- if (withEvent) {
806
- this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
807
- }
808
- return promise;
809
- }
810
- async unholdSipSession(sipSession, callSession, withEvent = true) {
811
- if (!sipSession) {
812
- return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
813
- }
814
- const isConference = !!callSession && callSession.isConference();
815
- const sessionId = this.getSipSessionId(sipSession);
816
- logger.info('WebRTC unhold sip session', {
817
- sessionId,
818
- isConference,
819
- });
820
- const { hasVideo, } = this.client.getHeldSession(sessionId) || {};
821
- const wasScreensharing = this.lastScreenShare && this.lastScreenShare.sipSessionId === sessionId;
822
- const wasDesktop = this.lastScreenShare && this.lastScreenShare.desktop;
823
- const promise = this.client.unhold(sipSession, isConference);
824
- if (hasVideo) {
825
- const constraints = {
826
- audio: false,
827
- video: true,
828
- screen: wasScreensharing,
829
- desktop: wasDesktop,
830
- };
831
- await this.client.upgradeToVideo(sipSession, constraints, isConference);
832
- }
833
- const onScreenSharing = (stream) => {
834
- const hadVideo = this.lastScreenShare && this.lastScreenShare.hadVideo;
835
- if (stream) {
836
- this._onScreenSharing(stream, sipSession, callSession, hadVideo);
837
- }
838
- this.lastScreenShare = null;
839
- };
840
- if (withEvent) {
841
- // Calling webRtcClient.unhold will unmute the call; let's make sure the call session reflects that state
842
- if (callSession) {
843
- callSession.muted = false;
844
- }
845
- const updatedCallSession = this._createCallSession(sipSession, callSession);
846
- // Deprecated event
847
- this.eventEmitter.emit(ON_CALL_UNHELD, updatedCallSession);
848
- this.eventEmitter.emit(ON_CALL_RESUMED, updatedCallSession);
849
- }
850
- return promise.then(() => {
851
- const stream = callSession ? this.getLocalVideoStream(callSession) : null;
852
- if (wasScreensharing) {
853
- onScreenSharing(stream);
854
- }
855
- return stream;
856
- });
857
- }
858
- mute(callSession, withEvent = true) {
859
- logger.info('WebRTC mute called', {
860
- id: callSession ? callSession.getId() : null,
861
- });
862
- const sipSession = this.findSipSession(callSession);
863
- if (!sipSession) {
864
- return;
865
- }
866
- logger.info('WebRTC muting', {
867
- sipId: this.getSipSessionId(sipSession),
868
- });
869
- this.client.mute(sipSession);
870
- const newCallSession = this._createCallSession(sipSession, callSession, {
871
- muted: true,
872
- });
873
- if (this.currentCallSession && newCallSession.is(this.currentCallSession)) {
874
- this.currentCallSession = newCallSession;
875
- }
876
- if (withEvent) {
877
- this.eventEmitter.emit(ON_CALL_MUTED, newCallSession);
878
- }
879
- }
880
- unmute(callSession, withEvent = true) {
881
- logger.info('WebRTC unmute called', {
882
- id: callSession ? callSession.getId() : null,
883
- });
884
- const sipSession = this.findSipSession(callSession);
885
- if (!sipSession) {
886
- return;
887
- }
888
- logger.info('WebRTC unmuting', {
889
- sipId: this.getSipSessionId(sipSession),
890
- });
891
- this.client.unmute(sipSession);
892
- const newCallSession = this._createCallSession(sipSession, callSession, {
893
- muted: false,
894
- });
895
- if (this.currentCallSession && newCallSession.is(this.currentCallSession)) {
896
- this.currentCallSession = newCallSession;
897
- }
898
- if (withEvent) {
899
- this.eventEmitter.emit(ON_CALL_UNMUTED, newCallSession);
900
- }
901
- }
902
- isAudioMuted(callSession) {
903
- const sipSession = this.findSipSession(callSession);
904
- if (!sipSession) {
905
- return true;
906
- }
907
- return this.client.isAudioMuted(sipSession);
908
- }
909
- turnCameraOn(callSession) {
910
- const sipSession = this.findSipSession(callSession);
911
- if (!sipSession) {
912
- return;
913
- }
914
- logger.info('WebRTC turn camera on', {
915
- sipId: this.getSipSessionId(sipSession),
916
- });
917
- this.client.toggleCameraOn(sipSession);
918
- this.eventEmitter.emit(ON_CAMERA_RESUMED, this._createCameraResumedCallSession(sipSession, callSession));
919
- }
920
- turnCameraOff(callSession) {
921
- const sipSession = this.findSipSession(callSession);
922
- if (!sipSession) {
923
- return;
924
- }
925
- logger.info('WebRTC turn camera off', {
926
- sipId: this.getSipSessionId(sipSession),
927
- });
928
- this.client.toggleCameraOff(sipSession);
929
- this.eventEmitter.emit(ON_CAMERA_DISABLED, this._createCameraDisabledCallSession(sipSession, callSession));
930
- }
931
- sendKey(callSession, tone) {
932
- const sipSession = this.findSipSession(callSession);
933
- if (!sipSession) {
934
- return;
935
- }
936
- logger.info('WebRTC send key', {
937
- sipId: this.getSipSessionId(sipSession),
938
- tone,
939
- });
940
- this.client.sendDTMF(sipSession, tone);
941
- }
942
- // Should be async to match CTIPhone definition
943
- // @TODO: line is not used here
944
- async makeCall(number, line, cameraEnabled, audioOnly = false, conference = false, options = {}) {
945
- logger.info('make WebRTC call', {
946
- number,
947
- lineId: line ? line.id : null,
948
- cameraEnabled,
949
- audioOnly,
950
- conference,
951
- options,
952
- });
953
- if (!number) {
954
- return Promise.resolve(null);
955
- }
956
- if (!this.client.isRegistered()) {
957
- await this.client.register();
958
- }
959
- if (this.currentSipSession) {
960
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
961
- logger.warn('Unable to hold current session when making another call', e);
962
- });
963
- }
964
- let sipSession;
965
- try {
966
- sipSession = this.client.call(number, this.allowVideo ? cameraEnabled : false, audioOnly, conference, options);
967
- this._bindEvents(sipSession);
968
- }
969
- catch (error) {
970
- logger.warn('make WebRTC call, error', {
971
- message: error.message,
972
- stack: error.stack,
973
- });
974
- return Promise.resolve(null);
975
- }
976
- const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
977
- callSession.setIsConference(conference);
978
- callSession.creationTime = new Date();
979
- this._updateCallSession(callSession);
980
- this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
981
- this.currentSipSession = sipSession;
982
- this.currentCallSession = callSession;
983
- this.eventEmitter.emit(ON_CALL_OUTGOING, callSession);
984
- // If an invite promise exists, catch exceptions on it to trigger error like OverConstraintsError.
985
- // @ts-ignore: does not exist
986
- if (sipSession.invitePromise) {
987
- // @ts-ignore: does not exist
988
- sipSession.invitePromise.catch(error => {
989
- this.eventEmitter.emit(ON_CALL_ERROR, error, callSession);
990
- });
991
- }
992
- return Promise.resolve(callSession);
993
- }
994
- transfer(callSession, target) {
995
- const sipSession = this.findSipSession(callSession);
996
- if (!sipSession) {
997
- return;
998
- }
999
- logger.info('WebRTC transfer', {
1000
- sipId: this.getSipSessionId(sipSession),
1001
- target,
1002
- });
1003
- this.client.transfer(sipSession, target);
1004
- }
1005
- async indirectTransfer(source, destination) {
1006
- const sipSession = this.client.getSipSession(source.sipCallId);
1007
- const sipSessionTarget = this.client.getSipSession(destination.sipCallId);
1008
- logger.info('WebRTC indirect transfer', {
1009
- sipId: sipSession ? this.getSipSessionId(sipSession) : null,
1010
- target: sipSessionTarget ? this.getSipSessionId(sipSessionTarget) : null,
1011
- });
1012
- if (!sipSessionTarget) {
1013
- return Promise.reject();
1014
- }
1015
- return new Promise(resolve => {
1016
- const options = {
1017
- requestDelegate: {
1018
- onAccept: () => {
1019
- // Wait a little so the REFER will take effect
1020
- setTimeout(() => {
1021
- this.hangup(destination).then(resolve);
1022
- }, 200);
1023
- },
1024
- },
1025
- };
1026
- return sipSessionTarget.refer(sipSession, options);
1027
- });
1028
- }
1029
- initiateCTIIndirectTransfer() { return Promise.resolve(null); }
1030
- cancelCTIIndirectTransfer() { }
1031
- confirmCTIIndirectTransfer() { }
1032
- async hangup(callSession) {
1033
- const sipSession = this.findSipSession(callSession);
1034
- if (!sipSession) {
1035
- console.error('Call is unknown to the WebRTC phone', callSession ? callSession.sipCallId : null, callSession ? callSession.callId : null);
1036
- return false;
1037
- }
1038
- const sipSessionId = this.getSipSessionId(sipSession);
1039
- logger.info('WebRTC hangup', {
1040
- sipId: this.getSipSessionId(sipSession),
1041
- sipSessionId,
1042
- });
1043
- await this.client.hangup(sipSession);
1044
- if (callSession) {
1045
- // Removal of `this.callSessions` will be done in `_onCallTerminated`.
1046
- this.endCurrentCall(callSession);
1047
- }
1048
- else if (sipSessionId) {
1049
- delete this.callSessions[sipSessionId];
1050
- }
1051
- this.shouldSendReinvite = false;
1052
- return true;
1053
- }
1054
- async getStats(callSession) {
1055
- const sipSession = this.findSipSession(callSession);
1056
- return sipSession ? this.client.getStats(sipSession) : null;
1057
- }
1058
- startNetworkMonitoring(callSession, interval = 1000) {
1059
- const sipSession = this.findSipSession(callSession);
1060
- return sipSession ? this.client.startNetworkMonitoring(sipSession, interval) : null;
1061
- }
1062
- stopNetworkMonitoring(callSession) {
1063
- const sipSession = this.findSipSession(callSession);
1064
- return sipSession ? this.client.stopNetworkMonitoring(sipSession) : null;
1065
- }
1066
- forceCancel(sipSession) {
1067
- // @ts-ignore: private
1068
- if (!sipSession || !sipSession.outgoingInviteRequest) {
1069
- return;
1070
- }
1071
- try {
1072
- // @ts-ignore: private
1073
- sipSession.outgoingInviteRequest.cancel();
1074
- }
1075
- catch (e) {
1076
- logger.info('force cancel, error', e);
1077
- }
1078
- }
1079
- endCurrentCall(callSession) {
1080
- const isCurrent = this.isCurrentCallSipSession(callSession);
1081
- logger.info('Ending current call', {
1082
- id: callSession ? callSession.getId() : null,
1083
- isCurrent,
1084
- });
1085
- if (isCurrent) {
1086
- this.currentSipSession = undefined;
1087
- this.currentCallSession = undefined;
1088
- }
1089
- this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'locally ended');
1090
- }
1091
- onConnectionMade() { }
1092
- isConference(callSession) {
1093
- if (!callSession) {
1094
- return false;
1095
- }
1096
- return this.client && this.client.isConference(callSession.sipCallId);
1097
- }
1098
- async close(force = false) {
1099
- logger.info('WebRTC close');
1100
- try {
1101
- await Promise.race([
1102
- this.unregister(),
1103
- new Promise((resolve, reject) => setTimeout(() => reject(new Error('Unregister, timed out')), 3000)),
1104
- ]);
1105
- }
1106
- catch (e) {
1107
- logger.error('WebRTC close, unregister error', e);
1108
- }
1109
- await this.client.close(force);
1110
- this.unbind();
1111
- this.incomingSessions = [];
1112
- this.currentSipSession = undefined;
1113
- this.currentCallSession = undefined;
1114
- this.shouldSendReinvite = false;
1115
- this.rejectedSessions = {};
1116
- }
1117
- isRegistered() {
1118
- return this.client && this.client.isRegistered();
1119
- }
1120
- enableRinging() {
1121
- logger.info('WebRTC enable ringing');
1122
- this.ringingEnabled = true;
1123
- }
1124
- disableRinging() {
1125
- logger.info('WebRTC disable ringing');
1126
- this.ringingEnabled = false;
1127
- }
1128
- getCurrentCallSession() {
1129
- if (!this.currentSipSession) {
1130
- return null;
1131
- }
1132
- return this._createCallSession(this.currentSipSession, this.currentCallSession);
1133
- }
1134
- hasIncomingCallSession() {
1135
- return this.incomingSessions.length > 0;
1136
- }
1137
- getIncomingCallSession() {
1138
- if (!this.hasIncomingCallSession()) {
1139
- return null;
1140
- }
1141
- const sessionId = this.incomingSessions[0];
1142
- const sipSession = this.client.getSipSession(sessionId);
1143
- if (!sipSession) {
1144
- return null;
1145
- }
1146
- return this._createCallSession(sipSession);
1147
- }
1148
- // eslint-disable-next-line @typescript-eslint/default-param-last
1149
- sendMessage(sipSession = null, body, contentType = 'text/plain') {
1150
- return this.client.sendMessage(sipSession, body, contentType);
1151
- }
1152
- getLocalStream(callSession) {
1153
- return callSession ? this.client.getLocalStream(callSession.sipCallId) : null;
1154
- }
1155
- getLocalVideoStream(callSession) {
1156
- return callSession ? this.client.getLocalVideoStream(callSession.sipCallId) : null;
1157
- }
1158
- // Deprecated
1159
- getLocalMediaStream(callSession) {
1160
- logger.warn('WebRTCPhone.getLocalMediaStream is deprecated, use WebRTCPhone.getLocalStream instead');
1161
- return this.getLocalStream(callSession);
1162
- }
1163
- hasLocalVideo(callSession) {
1164
- return callSession ? this.client.hasLocalVideo(callSession.sipCallId) : false;
1165
- }
1166
- hasALocalVideoTrack(callSession) {
1167
- return callSession ? this.client.hasALocalVideoTrack(callSession.sipCallId) : false;
1168
- }
1169
- getRemoteStream(callSession) {
1170
- return callSession ? this.client.getRemoteStream(callSession.sipCallId) : null;
1171
- }
1172
- getRemoteVideoStream(callSession) {
1173
- return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
1174
- }
1175
- getRemoteVideoStreamFromPc(callSession) {
1176
- return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
1177
- }
1178
- hasRemoteVideo(callSession) {
1179
- return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
1180
- }
1181
- setMediaConstraints(media) {
1182
- this.client.setMediaConstraints(media);
1183
- }
1184
- isVideoRemotelyHeld(callSession) {
1185
- return callSession ? this.client.isVideoRemotelyHeld(callSession.sipCallId) : false;
1186
- }
1187
- bindClientEvents() {
1188
- this.client.unbind();
1189
- this.client.on(this.client.INVITE, (sipSession, wantsToDoVideo) => {
1190
- const autoAnswer = sipSession.request.getHeader('Answer-Mode') === 'Auto';
1191
- const withVideo = this.allowVideo ? wantsToDoVideo : false;
1192
- logger.info('WebRTC invite received', {
1193
- sipId: this.getSipSessionId(sipSession),
1194
- withVideo,
1195
- autoAnswer,
1196
- });
1197
- const callSession = this._createIncomingCallSession(sipSession, withVideo, null, autoAnswer);
1198
- this.incomingSessions.push(callSession.getId());
1199
- this._bindEvents(sipSession);
1200
- this.client.storeSipSession(sipSession);
1201
- callSession.creationTime = new Date();
1202
- this._updateCallSession(callSession);
1203
- this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
1204
- if (!this.currentSipSession) {
1205
- if (this.ringingEnabled) {
1206
- this.eventEmitter.emit(ON_PLAY_RING_SOUND, this.audioRingDeviceId, this.audioRingVolume, callSession);
1207
- }
1208
- }
1209
- else {
1210
- this.eventEmitter.emit(ON_PLAY_INBOUND_CALL_SIGNAL_SOUND, this.audioOutputDeviceId, this.audioOutputVolume, callSession);
1211
- }
1212
- });
1213
- this.client.on(this.client.ON_REINVITE, (...args) => {
1214
- logger.info('WebRTC on reinvite', {
1215
- sessionId: args[0].id,
1216
- inviteId: args[1].id,
1217
- updatedCalleeName: args[2],
1218
- updatedNumber: args[3],
1219
- });
1220
- const sipSession = args[0];
1221
- // Give some time for the stream to be mounted.
1222
- // if `_createCallSession` is called too soon `hasVideo` will return false because the stream doesn't exists yet
1223
- setTimeout(() => {
1224
- // Update callSession
1225
- this._createCallSession(sipSession, this.callSessions[this.getSipSessionId(sipSession)]);
1226
- this.eventEmitter.emit.apply(this.eventEmitter, [this.client.ON_REINVITE, ...args]);
1227
- }, 2000);
1228
- });
1229
- this.client.on(this.client.ACCEPTED, async (sipSession) => {
1230
- const sessionId = this.getSipSessionId(sipSession);
1231
- const hasSession = (sessionId in this.callSessions);
1232
- logger.info('WebRTC call accepted', {
1233
- sipId: sessionId,
1234
- hasSession,
1235
- });
1236
- if (!hasSession) {
1237
- logger.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', {
1238
- sessionId,
1239
- });
1240
- return;
1241
- }
1242
- this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
1243
- if (this.audioOutputDeviceId) {
1244
- await this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
1245
- }
1246
- });
1247
- this.client.on('ended', () => { });
1248
- this.client.on(this.client.ON_ERROR, e => {
1249
- logger.error('WebRTC error', e);
1250
- this.eventEmitter.emit(ON_CALL_ERROR, e);
1251
- });
1252
- this.client.on(this.client.REJECTED, session => {
1253
- logger.info('WebRTC call rejected', { id: this.getSipSessionId(session) });
1254
- const callSession = this._createCallSession(session);
1255
- // `_createCallSession` add the CallSession in `this.callSessions`.
1256
- // so we have to remove it or `callCount` will always return 1 even if the call was rejected
1257
- delete this.callSessions[this.getSipSessionId(session)];
1258
- callSession.endTime = new Date();
1259
- this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
1260
- });
1261
- this.client.on(this.client.UNREGISTERED, () => {
1262
- logger.info('WebRTC unregistered');
1263
- this.eventEmitter.emit(ON_UNREGISTERED);
1264
- });
1265
- this.client.on(this.client.ON_DISCONNECTED, () => {
1266
- logger.info('WebRTC disconnected');
1267
- this.eventEmitter.emit(ON_DISCONNECTED);
1268
- });
1269
- this.client.on(this.client.ON_PROGRESS, session => {
1270
- logger.info('WebRTC progress (180)');
1271
- const callSession = this._createCallSession(session, null, {
1272
- incoming: false,
1273
- ringing: true,
1274
- callId: this.getSipSessionId(session),
1275
- });
1276
- this.eventEmitter.emit(ON_PROGRESS, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
1277
- });
1278
- this.client.on(this.client.ON_EARLY_MEDIA, session => {
1279
- logger.info('WebRTC early media');
1280
- const callSession = this._createCallSession(session, null, {
1281
- incoming: false,
1282
- ringing: true,
1283
- callId: this.getSipSessionId(session),
1284
- });
1285
- this.eventEmitter.emit(ON_EARLY_MEDIA, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
1286
- });
1287
- this.client.on(this.client.REGISTERED, () => {
1288
- logger.info('WebRTC registered', {
1289
- shouldSendReinvite: this.shouldSendReinvite,
1290
- state: this.currentSipSession ? this.currentSipSession.state : null,
1291
- currentSipSession: !!this.currentSipSession,
1292
- });
1293
- this.stopHeartbeat();
1294
- this.eventEmitter.emit(ON_REGISTERED);
1295
- // If the phone registered with a current callSession (eg: when switching network):
1296
- // send a reinvite to renegociate ICE with new IP
1297
- if (this.shouldSendReinvite && this.currentSipSession && this.currentSipSession.state === SessionState.Established) {
1298
- this.shouldSendReinvite = false;
1299
- const pc = this.currentSipSession?.sessionDescriptionHandler?.peerConnection;
1300
- const isConference = pc ? pc.sfu : false;
1301
- const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
1302
- try {
1303
- // Send reinvite with iceRestart
1304
- this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
1305
- }
1306
- catch (e) {
1307
- logger.error('WebRTC reinvite after register, error', {
1308
- message: e.message,
1309
- stack: e.stack,
1310
- });
1311
- }
1312
- }
1313
- });
1314
- this.client.on(this.client.CONNECTED, () => {
1315
- logger.info('WebRTC client connected');
1316
- this.stopHeartbeat();
1317
- });
1318
- this.client.on(this.client.DISCONNECTED, () => {
1319
- logger.info('WebRTC client disconnected');
1320
- this.eventEmitter.emit(ON_UNREGISTERED);
1321
- // Do not trigger heartbeat if already running
1322
- if (!this.client.hasHeartbeat()) {
1323
- this.startHeartbeat();
1324
- }
1325
- // Tell to send reinvite when reconnecting
1326
- this.shouldSendReinvite = true;
1327
- });
1328
- this.client.on(this.client.ON_TRACK, (session, event) => {
1329
- this.eventEmitter.emit(ON_TRACK, session, event);
1330
- });
1331
- this.client.on('onVideoInputChange', stream => {
1332
- this.eventEmitter.emit(ON_VIDEO_INPUT_CHANGE, stream);
1333
- });
1334
- this.client.on(this.client.MESSAGE, (message) => {
1335
- this._onMessage(message);
1336
- this.eventEmitter.emit(ON_MESSAGE, message);
1337
- });
1338
- this.client.on(this.client.ON_NETWORK_STATS, (session, stats, previousStats) => {
1339
- const callSession = this.getCallSession(this.getSipSessionId(session));
1340
- this.eventEmitter.emit(ON_NETWORK_STATS, callSession, stats, previousStats);
1341
- });
1342
- // Used when upgrading directly in screenshare mode
1343
- this.client.on(this.client.ON_SCREEN_SHARING_REINVITE, (sipSession, response, desktop) => {
1344
- const sipSessionId = this.getSipSessionId(sipSession);
1345
- const localStream = this.client.getLocalStream(sipSessionId);
1346
- const callSession = this.callSessions[sipSessionId];
1347
- logger.info('Updrading directly in screensharing mode', {
1348
- sipSessionId,
1349
- tracks: localStream?.getTracks() || null,
1350
- });
1351
- this._onScreenSharing(localStream, sipSession, callSession, false, desktop);
1352
- });
1353
- }
1354
- // Find a corresponding sipSession from a CallSession
1355
- findSipSession(callSession) {
1356
- const keys = this.client.getSipSessionIds();
1357
- const keyIndex = keys.findIndex(sessionId => callSession && callSession.isId(sessionId));
1358
- if (keyIndex === -1) {
1359
- const currentSipSessionId = this.currentSipSession ? this.getSipSessionId(this.currentSipSession) : this.client.getSipSessionIds()[0];
1360
- return currentSipSessionId ? this.client.getSipSession(currentSipSessionId) : null;
1361
- }
1362
- return this.client.getSipSession(keys[keyIndex]);
1363
- }
1364
- getCallSession(sipSessionId) {
1365
- return this.callSessions[sipSessionId];
1366
- }
1367
- getSipSessionId(sipSession) {
1368
- if (!sipSession) {
1369
- return '';
1370
- }
1371
- return this.client.getSipSessionId(sipSession);
1372
- }
1373
- getSipSessionIdFromCallSession(callSession) {
1374
- const sipSession = this.findSipSession(callSession);
1375
- return sipSession ? this.getSipSessionId(sipSession) : null;
1376
- }
1377
- _updateCallSession(callSession) {
1378
- const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
1379
- if (sipSessionId) {
1380
- this.callSessions[sipSessionId] = callSession;
1381
- }
1382
- }
1383
- _onMessage(message) {
1384
- if (!message || message.method !== 'MESSAGE') {
1385
- return;
1386
- }
1387
- let body;
1388
- try {
1389
- body = JSON.parse(message.body || '');
1390
- }
1391
- catch (e) {
1392
- return;
1393
- }
1394
- const { type, content, } = body;
1395
- switch (type) {
1396
- case MESSAGE_TYPE_CHAT:
1397
- this.eventEmitter.emit(ON_CHAT, content);
1398
- break;
1399
- case MESSAGE_TYPE_SIGNAL:
1400
- {
1401
- this.eventEmitter.emit(ON_SIGNAL, content);
1402
- break;
1403
- }
1404
- default:
1405
- }
1406
- }
1407
- _createIncomingCallSession(sipSession, cameraEnabled, fromSession, autoAnswer = false) {
1408
- return this._createCallSession(sipSession, fromSession, {
1409
- incoming: true,
1410
- ringing: true,
1411
- cameraEnabled,
1412
- autoAnswer,
1413
- });
1414
- }
1415
- _createOutgoingCallSession(sipSession, cameraEnabled, fromSession) {
1416
- return this._createCallSession(sipSession, fromSession, {
1417
- incoming: false,
1418
- ringing: true,
1419
- cameraEnabled,
1420
- });
1421
- }
1422
- _createAcceptedCallSession(sipSession, cameraEnabled, fromSession) {
1423
- return this._createCallSession(sipSession, fromSession, {
1424
- cameraEnabled: cameraEnabled !== undefined ? cameraEnabled : false,
1425
- });
1426
- }
1427
- _createMutedCallSession(sipSession, fromSession) {
1428
- return this._createCallSession(sipSession, fromSession, {
1429
- muted: true,
1430
- });
1431
- }
1432
- _createUnmutedCallSession(sipSession, fromSession) {
1433
- return this._createCallSession(sipSession, fromSession, {
1434
- muted: false,
1435
- });
1436
- }
1437
- _createCameraResumedCallSession(sipSession, fromSession) {
1438
- return this._createCallSession(sipSession, fromSession, {
1439
- videoMuted: false,
1440
- });
1441
- }
1442
- _createCameraDisabledCallSession(sipSession, fromSession) {
1443
- return this._createCallSession(sipSession, fromSession, {
1444
- videoMuted: true,
1445
- });
1446
- }
1447
- _createCallSession(sipSession, fromSession, extra = {}) {
1448
- // eslint-disable-next-line
1449
- const identity = sipSession ? sipSession.remoteIdentity || sipSession.assertedIdentity : null;
1450
- // @ts-ignore: private
1451
- const number = identity ? identity.uri._normal.user : null;
1452
- const { state, } = sipSession || {};
1453
- const sessionId = this.getSipSessionId(sipSession);
1454
- fromSession = fromSession || this.callSessions[sessionId];
1455
- const callSession = new CallSession({
1456
- callId: fromSession && fromSession.callId,
1457
- sipCallId: sessionId,
1458
- sipStatus: state,
1459
- displayName: identity ? identity.displayName || number : number,
1460
- // @ts-ignore: date / number
1461
- startTime: fromSession ? fromSession.startTime : new Date(),
1462
- creationTime: fromSession ? fromSession.creationTime : null,
1463
- answerTime: fromSession ? fromSession.answerTime : null,
1464
- endTime: fromSession ? fromSession.endTime : null,
1465
- answered: state === SessionState.Established,
1466
- paused: this.client.isCallHeld(sipSession),
1467
- isCaller: fromSession ? fromSession.isCaller : 'incoming' in extra ? !extra.incoming : false,
1468
- cameraEnabled: fromSession ? fromSession.isCameraEnabled() : this.client.hasVideo(sessionId),
1469
- number,
1470
- ringing: false,
1471
- muted: fromSession ? fromSession.isMuted() : this.client.isAudioMuted(sipSession),
1472
- videoMuted: fromSession ? fromSession.isVideoMuted() : false,
1473
- recording: fromSession ? fromSession.isRecording() : false,
1474
- recordingPaused: false,
1475
- sipSession,
1476
- conference: !!fromSession && fromSession.isConference(),
1477
- ...extra,
1478
- });
1479
- this.callSessions[sessionId] = callSession;
1480
- return callSession;
1481
- }
1482
- }