@textrp/briij-js-sdk 41.0.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 (1104) hide show
  1. package/CHANGELOG.md +6464 -0
  2. package/LICENSE +177 -0
  3. package/README.md +477 -0
  4. package/lib/@types/AESEncryptedSecretStoragePayload.d.ts +14 -0
  5. package/lib/@types/AESEncryptedSecretStoragePayload.d.ts.map +1 -0
  6. package/lib/@types/AESEncryptedSecretStoragePayload.js +1 -0
  7. package/lib/@types/AESEncryptedSecretStoragePayload.js.map +1 -0
  8. package/lib/@types/IIdentityServerProvider.d.ts +9 -0
  9. package/lib/@types/IIdentityServerProvider.d.ts.map +1 -0
  10. package/lib/@types/IIdentityServerProvider.js +1 -0
  11. package/lib/@types/IIdentityServerProvider.js.map +1 -0
  12. package/lib/@types/PushRules.d.ts +140 -0
  13. package/lib/@types/PushRules.d.ts.map +1 -0
  14. package/lib/@types/PushRules.js +94 -0
  15. package/lib/@types/PushRules.js.map +1 -0
  16. package/lib/@types/another-json.d.js +0 -0
  17. package/lib/@types/another-json.d.js.map +1 -0
  18. package/lib/@types/auth.d.ts +213 -0
  19. package/lib/@types/auth.d.ts.map +1 -0
  20. package/lib/@types/auth.js +107 -0
  21. package/lib/@types/auth.js.map +1 -0
  22. package/lib/@types/beacon.d.ts +106 -0
  23. package/lib/@types/beacon.d.ts.map +1 -0
  24. package/lib/@types/beacon.js +119 -0
  25. package/lib/@types/beacon.js.map +1 -0
  26. package/lib/@types/common.d.ts +10 -0
  27. package/lib/@types/common.d.ts.map +1 -0
  28. package/lib/@types/common.js +1 -0
  29. package/lib/@types/common.js.map +1 -0
  30. package/lib/@types/crypto.d.ts +46 -0
  31. package/lib/@types/crypto.d.ts.map +1 -0
  32. package/lib/@types/crypto.js +1 -0
  33. package/lib/@types/crypto.js.map +1 -0
  34. package/lib/@types/event.d.ts +356 -0
  35. package/lib/@types/event.d.ts.map +1 -0
  36. package/lib/@types/event.js +280 -0
  37. package/lib/@types/event.js.map +1 -0
  38. package/lib/@types/events.d.ts +92 -0
  39. package/lib/@types/events.d.ts.map +1 -0
  40. package/lib/@types/events.js +1 -0
  41. package/lib/@types/events.js.map +1 -0
  42. package/lib/@types/extensible_events.d.ts +98 -0
  43. package/lib/@types/extensible_events.d.ts.map +1 -0
  44. package/lib/@types/extensible_events.js +116 -0
  45. package/lib/@types/extensible_events.js.map +1 -0
  46. package/lib/@types/global.d.js +18 -0
  47. package/lib/@types/global.d.js.map +1 -0
  48. package/lib/@types/local_notifications.d.ts +4 -0
  49. package/lib/@types/local_notifications.d.ts.map +1 -0
  50. package/lib/@types/local_notifications.js +1 -0
  51. package/lib/@types/local_notifications.js.map +1 -0
  52. package/lib/@types/location.d.ts +60 -0
  53. package/lib/@types/location.d.ts.map +1 -0
  54. package/lib/@types/location.js +66 -0
  55. package/lib/@types/location.js.map +1 -0
  56. package/lib/@types/matrix-sdk-crypto-wasm.d.js +1 -0
  57. package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -0
  58. package/lib/@types/media.d.ts +220 -0
  59. package/lib/@types/media.d.ts.map +1 -0
  60. package/lib/@types/media.js +1 -0
  61. package/lib/@types/media.js.map +1 -0
  62. package/lib/@types/membership.d.ts +41 -0
  63. package/lib/@types/membership.d.ts.map +1 -0
  64. package/lib/@types/membership.js +58 -0
  65. package/lib/@types/membership.js.map +1 -0
  66. package/lib/@types/partials.d.ts +72 -0
  67. package/lib/@types/partials.d.ts.map +1 -0
  68. package/lib/@types/partials.js +71 -0
  69. package/lib/@types/partials.js.map +1 -0
  70. package/lib/@types/polls.d.ts +89 -0
  71. package/lib/@types/polls.d.ts.map +1 -0
  72. package/lib/@types/polls.js +86 -0
  73. package/lib/@types/polls.js.map +1 -0
  74. package/lib/@types/read_receipts.d.ts +36 -0
  75. package/lib/@types/read_receipts.d.ts.map +1 -0
  76. package/lib/@types/read_receipts.js +27 -0
  77. package/lib/@types/read_receipts.js.map +1 -0
  78. package/lib/@types/registration.d.ts +85 -0
  79. package/lib/@types/registration.d.ts.map +1 -0
  80. package/lib/@types/registration.js +1 -0
  81. package/lib/@types/registration.js.map +1 -0
  82. package/lib/@types/requests.d.ts +267 -0
  83. package/lib/@types/requests.d.ts.map +1 -0
  84. package/lib/@types/requests.js +42 -0
  85. package/lib/@types/requests.js.map +1 -0
  86. package/lib/@types/search.d.ts +90 -0
  87. package/lib/@types/search.d.ts.map +1 -0
  88. package/lib/@types/search.js +30 -0
  89. package/lib/@types/search.js.map +1 -0
  90. package/lib/@types/signed.d.ts +9 -0
  91. package/lib/@types/signed.d.ts.map +1 -0
  92. package/lib/@types/signed.js +1 -0
  93. package/lib/@types/signed.js.map +1 -0
  94. package/lib/@types/spaces.d.ts +16 -0
  95. package/lib/@types/spaces.d.ts.map +1 -0
  96. package/lib/@types/spaces.js +1 -0
  97. package/lib/@types/spaces.js.map +1 -0
  98. package/lib/@types/state_events.d.ts +121 -0
  99. package/lib/@types/state_events.d.ts.map +1 -0
  100. package/lib/@types/state_events.js +1 -0
  101. package/lib/@types/state_events.js.map +1 -0
  102. package/lib/@types/synapse.d.ts +19 -0
  103. package/lib/@types/synapse.d.ts.map +1 -0
  104. package/lib/@types/synapse.js +1 -0
  105. package/lib/@types/synapse.js.map +1 -0
  106. package/lib/@types/sync.d.ts +8 -0
  107. package/lib/@types/sync.d.ts.map +1 -0
  108. package/lib/@types/sync.js +25 -0
  109. package/lib/@types/sync.js.map +1 -0
  110. package/lib/@types/threepids.d.ts +12 -0
  111. package/lib/@types/threepids.d.ts.map +1 -0
  112. package/lib/@types/threepids.js +24 -0
  113. package/lib/@types/threepids.js.map +1 -0
  114. package/lib/@types/topic.d.ts +55 -0
  115. package/lib/@types/topic.d.ts.map +1 -0
  116. package/lib/@types/topic.js +62 -0
  117. package/lib/@types/topic.js.map +1 -0
  118. package/lib/@types/uia.d.ts +8 -0
  119. package/lib/@types/uia.d.ts.map +1 -0
  120. package/lib/@types/uia.js +1 -0
  121. package/lib/@types/uia.js.map +1 -0
  122. package/lib/NamespacedValue.d.ts +32 -0
  123. package/lib/NamespacedValue.d.ts.map +1 -0
  124. package/lib/NamespacedValue.js +113 -0
  125. package/lib/NamespacedValue.js.map +1 -0
  126. package/lib/ReEmitter.d.ts +15 -0
  127. package/lib/ReEmitter.d.ts.map +1 -0
  128. package/lib/ReEmitter.js +87 -0
  129. package/lib/ReEmitter.js.map +1 -0
  130. package/lib/ToDeviceMessageQueue.d.ts +30 -0
  131. package/lib/ToDeviceMessageQueue.d.ts.map +1 -0
  132. package/lib/ToDeviceMessageQueue.js +135 -0
  133. package/lib/ToDeviceMessageQueue.js.map +1 -0
  134. package/lib/autodiscovery.d.ts +136 -0
  135. package/lib/autodiscovery.d.ts.map +1 -0
  136. package/lib/autodiscovery.js +464 -0
  137. package/lib/autodiscovery.js.map +1 -0
  138. package/lib/base64.d.ts +25 -0
  139. package/lib/base64.d.ts.map +1 -0
  140. package/lib/base64.js +95 -0
  141. package/lib/base64.js.map +1 -0
  142. package/lib/briij.d.ts +116 -0
  143. package/lib/briij.d.ts.map +1 -0
  144. package/lib/briij.js +145 -0
  145. package/lib/briij.js.map +1 -0
  146. package/lib/browser-index.d.ts +8 -0
  147. package/lib/browser-index.d.ts.map +1 -0
  148. package/lib/browser-index.js +35 -0
  149. package/lib/browser-index.js.map +1 -0
  150. package/lib/client.d.ts +3493 -0
  151. package/lib/client.d.ts.map +1 -0
  152. package/lib/client.js +7482 -0
  153. package/lib/client.js.map +1 -0
  154. package/lib/common-crypto/CryptoBackend.d.ts +234 -0
  155. package/lib/common-crypto/CryptoBackend.d.ts.map +1 -0
  156. package/lib/common-crypto/CryptoBackend.js +69 -0
  157. package/lib/common-crypto/CryptoBackend.js.map +1 -0
  158. package/lib/common-crypto/key-passphrase.d.ts +14 -0
  159. package/lib/common-crypto/key-passphrase.d.ts.map +1 -0
  160. package/lib/common-crypto/key-passphrase.js +33 -0
  161. package/lib/common-crypto/key-passphrase.js.map +1 -0
  162. package/lib/content-helpers.d.ts +90 -0
  163. package/lib/content-helpers.d.ts.map +1 -0
  164. package/lib/content-helpers.js +262 -0
  165. package/lib/content-helpers.js.map +1 -0
  166. package/lib/content-repo.d.ts +25 -0
  167. package/lib/content-repo.d.ts.map +1 -0
  168. package/lib/content-repo.js +109 -0
  169. package/lib/content-repo.js.map +1 -0
  170. package/lib/crypto/store/base.d.ts +301 -0
  171. package/lib/crypto/store/base.d.ts.map +1 -0
  172. package/lib/crypto/store/base.js +145 -0
  173. package/lib/crypto/store/base.js.map +1 -0
  174. package/lib/crypto/store/indexeddb-crypto-store-backend.d.ts +94 -0
  175. package/lib/crypto/store/indexeddb-crypto-store-backend.d.ts.map +1 -0
  176. package/lib/crypto/store/indexeddb-crypto-store-backend.js +604 -0
  177. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -0
  178. package/lib/crypto/store/indexeddb-crypto-store.d.ts +251 -0
  179. package/lib/crypto/store/indexeddb-crypto-store.d.ts.map +1 -0
  180. package/lib/crypto/store/indexeddb-crypto-store.js +477 -0
  181. package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -0
  182. package/lib/crypto/store/localStorage-crypto-store.d.ts +102 -0
  183. package/lib/crypto/store/localStorage-crypto-store.d.ts.map +1 -0
  184. package/lib/crypto/store/localStorage-crypto-store.js +374 -0
  185. package/lib/crypto/store/localStorage-crypto-store.js.map +1 -0
  186. package/lib/crypto/store/memory-crypto-store.d.ts +117 -0
  187. package/lib/crypto/store/memory-crypto-store.d.ts.map +1 -0
  188. package/lib/crypto/store/memory-crypto-store.js +311 -0
  189. package/lib/crypto/store/memory-crypto-store.js.map +1 -0
  190. package/lib/crypto-api/CryptoEvent.d.ts +120 -0
  191. package/lib/crypto-api/CryptoEvent.d.ts.map +1 -0
  192. package/lib/crypto-api/CryptoEvent.js +137 -0
  193. package/lib/crypto-api/CryptoEvent.js.map +1 -0
  194. package/lib/crypto-api/CryptoEventHandlerMap.d.ts +26 -0
  195. package/lib/crypto-api/CryptoEventHandlerMap.d.ts.map +1 -0
  196. package/lib/crypto-api/CryptoEventHandlerMap.js +1 -0
  197. package/lib/crypto-api/CryptoEventHandlerMap.js.map +1 -0
  198. package/lib/crypto-api/index.d.ts +1160 -0
  199. package/lib/crypto-api/index.d.ts.map +1 -0
  200. package/lib/crypto-api/index.js +410 -0
  201. package/lib/crypto-api/index.js.map +1 -0
  202. package/lib/crypto-api/key-passphrase.d.ts +11 -0
  203. package/lib/crypto-api/key-passphrase.d.ts.map +1 -0
  204. package/lib/crypto-api/key-passphrase.js +51 -0
  205. package/lib/crypto-api/key-passphrase.js.map +1 -0
  206. package/lib/crypto-api/keybackup.d.ts +87 -0
  207. package/lib/crypto-api/keybackup.d.ts.map +1 -0
  208. package/lib/crypto-api/keybackup.js +1 -0
  209. package/lib/crypto-api/keybackup.js.map +1 -0
  210. package/lib/crypto-api/recovery-key.d.ts +11 -0
  211. package/lib/crypto-api/recovery-key.d.ts.map +1 -0
  212. package/lib/crypto-api/recovery-key.js +65 -0
  213. package/lib/crypto-api/recovery-key.js.map +1 -0
  214. package/lib/crypto-api/verification.d.ts +315 -0
  215. package/lib/crypto-api/verification.d.ts.map +1 -0
  216. package/lib/crypto-api/verification.js +130 -0
  217. package/lib/crypto-api/verification.js.map +1 -0
  218. package/lib/digest.d.ts +10 -0
  219. package/lib/digest.d.ts.map +1 -0
  220. package/lib/digest.js +40 -0
  221. package/lib/digest.js.map +1 -0
  222. package/lib/embedded.d.ts +182 -0
  223. package/lib/embedded.d.ts.map +1 -0
  224. package/lib/embedded.js +746 -0
  225. package/lib/embedded.js.map +1 -0
  226. package/lib/errors.d.ts +38 -0
  227. package/lib/errors.d.ts.map +1 -0
  228. package/lib/errors.js +73 -0
  229. package/lib/errors.js.map +1 -0
  230. package/lib/event-mapper.d.ts +9 -0
  231. package/lib/event-mapper.d.ts.map +1 -0
  232. package/lib/event-mapper.js +74 -0
  233. package/lib/event-mapper.js.map +1 -0
  234. package/lib/extensible_events_v1/ExtensibleEvent.d.ts +38 -0
  235. package/lib/extensible_events_v1/ExtensibleEvent.d.ts.map +1 -0
  236. package/lib/extensible_events_v1/ExtensibleEvent.js +57 -0
  237. package/lib/extensible_events_v1/ExtensibleEvent.js.map +1 -0
  238. package/lib/extensible_events_v1/InvalidEventError.d.ts +7 -0
  239. package/lib/extensible_events_v1/InvalidEventError.d.ts.map +1 -0
  240. package/lib/extensible_events_v1/InvalidEventError.js +25 -0
  241. package/lib/extensible_events_v1/InvalidEventError.js.map +1 -0
  242. package/lib/extensible_events_v1/MessageEvent.d.ts +44 -0
  243. package/lib/extensible_events_v1/MessageEvent.d.ts.map +1 -0
  244. package/lib/extensible_events_v1/MessageEvent.js +134 -0
  245. package/lib/extensible_events_v1/MessageEvent.js.map +1 -0
  246. package/lib/extensible_events_v1/PollEndEvent.d.ts +33 -0
  247. package/lib/extensible_events_v1/PollEndEvent.d.ts.map +1 -0
  248. package/lib/extensible_events_v1/PollEndEvent.js +88 -0
  249. package/lib/extensible_events_v1/PollEndEvent.js.map +1 -0
  250. package/lib/extensible_events_v1/PollResponseEvent.d.ts +49 -0
  251. package/lib/extensible_events_v1/PollResponseEvent.d.ts.map +1 -0
  252. package/lib/extensible_events_v1/PollResponseEvent.js +135 -0
  253. package/lib/extensible_events_v1/PollResponseEvent.js.map +1 -0
  254. package/lib/extensible_events_v1/PollStartEvent.d.ts +71 -0
  255. package/lib/extensible_events_v1/PollStartEvent.d.ts.map +1 -0
  256. package/lib/extensible_events_v1/PollStartEvent.js +185 -0
  257. package/lib/extensible_events_v1/PollStartEvent.js.map +1 -0
  258. package/lib/extensible_events_v1/utilities.d.ts +14 -0
  259. package/lib/extensible_events_v1/utilities.d.ts.map +1 -0
  260. package/lib/extensible_events_v1/utilities.js +34 -0
  261. package/lib/extensible_events_v1/utilities.js.map +1 -0
  262. package/lib/feature.d.ts +20 -0
  263. package/lib/feature.d.ts.map +1 -0
  264. package/lib/feature.js +89 -0
  265. package/lib/feature.js.map +1 -0
  266. package/lib/filter-component.d.ts +64 -0
  267. package/lib/filter-component.d.ts.map +1 -0
  268. package/lib/filter-component.js +170 -0
  269. package/lib/filter-component.js.map +1 -0
  270. package/lib/filter.d.ts +97 -0
  271. package/lib/filter.d.ts.map +1 -0
  272. package/lib/filter.js +207 -0
  273. package/lib/filter.js.map +1 -0
  274. package/lib/http-api/errors.d.ts +117 -0
  275. package/lib/http-api/errors.d.ts.map +1 -0
  276. package/lib/http-api/errors.js +245 -0
  277. package/lib/http-api/errors.js.map +1 -0
  278. package/lib/http-api/fetch.d.ts +80 -0
  279. package/lib/http-api/fetch.d.ts.map +1 -0
  280. package/lib/http-api/fetch.js +332 -0
  281. package/lib/http-api/fetch.js.map +1 -0
  282. package/lib/http-api/index.d.ts +33 -0
  283. package/lib/http-api/index.d.ts.map +1 -0
  284. package/lib/http-api/index.js +178 -0
  285. package/lib/http-api/index.js.map +1 -0
  286. package/lib/http-api/interface.d.ts +186 -0
  287. package/lib/http-api/interface.d.ts.map +1 -0
  288. package/lib/http-api/interface.js +39 -0
  289. package/lib/http-api/interface.js.map +1 -0
  290. package/lib/http-api/method.d.ts +10 -0
  291. package/lib/http-api/method.d.ts.map +1 -0
  292. package/lib/http-api/method.js +27 -0
  293. package/lib/http-api/method.js.map +1 -0
  294. package/lib/http-api/prefix.d.ts +31 -0
  295. package/lib/http-api/prefix.d.ts.map +1 -0
  296. package/lib/http-api/prefix.js +50 -0
  297. package/lib/http-api/prefix.js.map +1 -0
  298. package/lib/http-api/refresh.d.ts +53 -0
  299. package/lib/http-api/refresh.d.ts.map +1 -0
  300. package/lib/http-api/refresh.js +174 -0
  301. package/lib/http-api/refresh.js.map +1 -0
  302. package/lib/http-api/utils.d.ts +37 -0
  303. package/lib/http-api/utils.d.ts.map +1 -0
  304. package/lib/http-api/utils.js +182 -0
  305. package/lib/http-api/utils.js.map +1 -0
  306. package/lib/index.d.ts +4 -0
  307. package/lib/index.d.ts.map +1 -0
  308. package/lib/index.js +24 -0
  309. package/lib/index.js.map +1 -0
  310. package/lib/indexeddb-helpers.d.ts +10 -0
  311. package/lib/indexeddb-helpers.d.ts.map +1 -0
  312. package/lib/indexeddb-helpers.js +51 -0
  313. package/lib/indexeddb-helpers.js.map +1 -0
  314. package/lib/indexeddb-worker.d.ts +7 -0
  315. package/lib/indexeddb-worker.d.ts.map +1 -0
  316. package/lib/indexeddb-worker.js +25 -0
  317. package/lib/indexeddb-worker.js.map +1 -0
  318. package/lib/interactive-auth.d.ts +341 -0
  319. package/lib/interactive-auth.d.ts.map +1 -0
  320. package/lib/interactive-auth.js +563 -0
  321. package/lib/interactive-auth.js.map +1 -0
  322. package/lib/logger.d.ts +124 -0
  323. package/lib/logger.d.ts.map +1 -0
  324. package/lib/logger.js +230 -0
  325. package/lib/logger.js.map +1 -0
  326. package/lib/matrixrtc/CallMembership.d.ts +154 -0
  327. package/lib/matrixrtc/CallMembership.d.ts.map +1 -0
  328. package/lib/matrixrtc/CallMembership.js +469 -0
  329. package/lib/matrixrtc/CallMembership.js.map +1 -0
  330. package/lib/matrixrtc/EncryptionManager.d.ts +44 -0
  331. package/lib/matrixrtc/EncryptionManager.d.ts.map +1 -0
  332. package/lib/matrixrtc/EncryptionManager.js +13 -0
  333. package/lib/matrixrtc/EncryptionManager.js.map +1 -0
  334. package/lib/matrixrtc/IKeyTransport.d.ts +37 -0
  335. package/lib/matrixrtc/IKeyTransport.d.ts.map +1 -0
  336. package/lib/matrixrtc/IKeyTransport.js +27 -0
  337. package/lib/matrixrtc/IKeyTransport.js.map +1 -0
  338. package/lib/matrixrtc/IMembershipManager.d.ts +94 -0
  339. package/lib/matrixrtc/IMembershipManager.d.ts.map +1 -0
  340. package/lib/matrixrtc/IMembershipManager.js +40 -0
  341. package/lib/matrixrtc/IMembershipManager.js.map +1 -0
  342. package/lib/matrixrtc/LivekitTransport.d.ts +23 -0
  343. package/lib/matrixrtc/LivekitTransport.d.ts.map +1 -0
  344. package/lib/matrixrtc/LivekitTransport.js +29 -0
  345. package/lib/matrixrtc/LivekitTransport.js.map +1 -0
  346. package/lib/matrixrtc/MatrixRTCSession.d.ts +343 -0
  347. package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -0
  348. package/lib/matrixrtc/MatrixRTCSession.js +623 -0
  349. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -0
  350. package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +46 -0
  351. package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +1 -0
  352. package/lib/matrixrtc/MatrixRTCSessionManager.js +149 -0
  353. package/lib/matrixrtc/MatrixRTCSessionManager.js.map +1 -0
  354. package/lib/matrixrtc/MembershipManager.d.ts +210 -0
  355. package/lib/matrixrtc/MembershipManager.d.ts.map +1 -0
  356. package/lib/matrixrtc/MembershipManager.js +977 -0
  357. package/lib/matrixrtc/MembershipManager.js.map +1 -0
  358. package/lib/matrixrtc/MembershipManagerActionScheduler.d.ts +59 -0
  359. package/lib/matrixrtc/MembershipManagerActionScheduler.d.ts.map +1 -0
  360. package/lib/matrixrtc/MembershipManagerActionScheduler.js +125 -0
  361. package/lib/matrixrtc/MembershipManagerActionScheduler.js.map +1 -0
  362. package/lib/matrixrtc/RTCEncryptionManager.d.ts +110 -0
  363. package/lib/matrixrtc/RTCEncryptionManager.d.ts.map +1 -0
  364. package/lib/matrixrtc/RTCEncryptionManager.js +376 -0
  365. package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -0
  366. package/lib/matrixrtc/ToDeviceKeyTransport.d.ts +30 -0
  367. package/lib/matrixrtc/ToDeviceKeyTransport.d.ts.map +1 -0
  368. package/lib/matrixrtc/ToDeviceKeyTransport.js +164 -0
  369. package/lib/matrixrtc/ToDeviceKeyTransport.js.map +1 -0
  370. package/lib/matrixrtc/index.d.ts +9 -0
  371. package/lib/matrixrtc/index.d.ts.map +1 -0
  372. package/lib/matrixrtc/index.js +23 -0
  373. package/lib/matrixrtc/index.js.map +1 -0
  374. package/lib/matrixrtc/membershipData/common.d.ts +8 -0
  375. package/lib/matrixrtc/membershipData/common.d.ts.map +1 -0
  376. package/lib/matrixrtc/membershipData/common.js +26 -0
  377. package/lib/matrixrtc/membershipData/common.js.map +1 -0
  378. package/lib/matrixrtc/membershipData/index.d.ts +4 -0
  379. package/lib/matrixrtc/membershipData/index.d.ts.map +1 -0
  380. package/lib/matrixrtc/membershipData/index.js +20 -0
  381. package/lib/matrixrtc/membershipData/index.js.map +1 -0
  382. package/lib/matrixrtc/membershipData/rtc.d.ts +33 -0
  383. package/lib/matrixrtc/membershipData/rtc.d.ts.map +1 -0
  384. package/lib/matrixrtc/membershipData/rtc.js +137 -0
  385. package/lib/matrixrtc/membershipData/rtc.js.map +1 -0
  386. package/lib/matrixrtc/membershipData/session.d.ts +77 -0
  387. package/lib/matrixrtc/membershipData/session.d.ts.map +1 -0
  388. package/lib/matrixrtc/membershipData/session.js +62 -0
  389. package/lib/matrixrtc/membershipData/session.js.map +1 -0
  390. package/lib/matrixrtc/types.d.ts +169 -0
  391. package/lib/matrixrtc/types.d.ts.map +1 -0
  392. package/lib/matrixrtc/types.js +117 -0
  393. package/lib/matrixrtc/types.js.map +1 -0
  394. package/lib/matrixrtc/utils.d.ts +27 -0
  395. package/lib/matrixrtc/utils.d.ts.map +1 -0
  396. package/lib/matrixrtc/utils.js +72 -0
  397. package/lib/matrixrtc/utils.js.map +1 -0
  398. package/lib/models/MSC3089Branch.d.ts +98 -0
  399. package/lib/models/MSC3089Branch.d.ts.map +1 -0
  400. package/lib/models/MSC3089Branch.js +240 -0
  401. package/lib/models/MSC3089Branch.js.map +1 -0
  402. package/lib/models/MSC3089TreeSpace.d.ts +166 -0
  403. package/lib/models/MSC3089TreeSpace.d.ts.map +1 -0
  404. package/lib/models/MSC3089TreeSpace.js +521 -0
  405. package/lib/models/MSC3089TreeSpace.js.map +1 -0
  406. package/lib/models/ToDeviceMessage.d.ts +17 -0
  407. package/lib/models/ToDeviceMessage.d.ts.map +1 -0
  408. package/lib/models/ToDeviceMessage.js +1 -0
  409. package/lib/models/ToDeviceMessage.js.map +1 -0
  410. package/lib/models/beacon.d.ts +52 -0
  411. package/lib/models/beacon.d.ts.map +1 -0
  412. package/lib/models/beacon.js +174 -0
  413. package/lib/models/beacon.js.map +1 -0
  414. package/lib/models/compare-event-ordering.d.ts +24 -0
  415. package/lib/models/compare-event-ordering.d.ts.map +1 -0
  416. package/lib/models/compare-event-ordering.js +120 -0
  417. package/lib/models/compare-event-ordering.js.map +1 -0
  418. package/lib/models/device.d.ts +45 -0
  419. package/lib/models/device.d.ts.map +1 -0
  420. package/lib/models/device.js +77 -0
  421. package/lib/models/device.js.map +1 -0
  422. package/lib/models/event-context.d.ts +62 -0
  423. package/lib/models/event-context.d.ts.map +1 -0
  424. package/lib/models/event-context.js +113 -0
  425. package/lib/models/event-context.js.map +1 -0
  426. package/lib/models/event-status.d.ts +19 -0
  427. package/lib/models/event-status.d.ts.map +1 -0
  428. package/lib/models/event-status.js +36 -0
  429. package/lib/models/event-status.js.map +1 -0
  430. package/lib/models/event-timeline-set.d.ts +308 -0
  431. package/lib/models/event-timeline-set.d.ts.map +1 -0
  432. package/lib/models/event-timeline-set.js +805 -0
  433. package/lib/models/event-timeline-set.js.map +1 -0
  434. package/lib/models/event-timeline.d.ts +224 -0
  435. package/lib/models/event-timeline.d.ts.map +1 -0
  436. package/lib/models/event-timeline.js +434 -0
  437. package/lib/models/event-timeline.js.map +1 -0
  438. package/lib/models/event.d.ts +844 -0
  439. package/lib/models/event.d.ts.map +1 -0
  440. package/lib/models/event.js +1600 -0
  441. package/lib/models/event.js.map +1 -0
  442. package/lib/models/invites-ignorer-types.d.ts +27 -0
  443. package/lib/models/invites-ignorer-types.d.ts.map +1 -0
  444. package/lib/models/invites-ignorer-types.js +56 -0
  445. package/lib/models/invites-ignorer-types.js.map +1 -0
  446. package/lib/models/invites-ignorer.d.ts +112 -0
  447. package/lib/models/invites-ignorer.d.ts.map +1 -0
  448. package/lib/models/invites-ignorer.js +357 -0
  449. package/lib/models/invites-ignorer.js.map +1 -0
  450. package/lib/models/poll.d.ts +67 -0
  451. package/lib/models/poll.d.ts.map +1 -0
  452. package/lib/models/poll.js +241 -0
  453. package/lib/models/poll.js.map +1 -0
  454. package/lib/models/profile-keys.d.ts +17 -0
  455. package/lib/models/profile-keys.d.ts.map +1 -0
  456. package/lib/models/profile-keys.js +34 -0
  457. package/lib/models/profile-keys.js.map +1 -0
  458. package/lib/models/read-receipt.d.ts +115 -0
  459. package/lib/models/read-receipt.d.ts.map +1 -0
  460. package/lib/models/read-receipt.js +366 -0
  461. package/lib/models/read-receipt.js.map +1 -0
  462. package/lib/models/related-relations.d.ts +11 -0
  463. package/lib/models/related-relations.d.ts.map +1 -0
  464. package/lib/models/related-relations.js +33 -0
  465. package/lib/models/related-relations.js.map +1 -0
  466. package/lib/models/relations-container.d.ts +44 -0
  467. package/lib/models/relations-container.d.ts.map +1 -0
  468. package/lib/models/relations-container.js +132 -0
  469. package/lib/models/relations-container.js.map +1 -0
  470. package/lib/models/relations.d.ts +123 -0
  471. package/lib/models/relations.d.ts.map +1 -0
  472. package/lib/models/relations.js +378 -0
  473. package/lib/models/relations.js.map +1 -0
  474. package/lib/models/room-member.d.ts +221 -0
  475. package/lib/models/room-member.d.ts.map +1 -0
  476. package/lib/models/room-member.js +376 -0
  477. package/lib/models/room-member.js.map +1 -0
  478. package/lib/models/room-receipts.d.ts +39 -0
  479. package/lib/models/room-receipts.d.ts.map +1 -0
  480. package/lib/models/room-receipts.js +392 -0
  481. package/lib/models/room-receipts.js.map +1 -0
  482. package/lib/models/room-state.d.ts +463 -0
  483. package/lib/models/room-state.d.ts.map +1 -0
  484. package/lib/models/room-state.js +1066 -0
  485. package/lib/models/room-state.js.map +1 -0
  486. package/lib/models/room-sticky-events.d.ts +110 -0
  487. package/lib/models/room-sticky-events.d.ts.map +1 -0
  488. package/lib/models/room-sticky-events.js +353 -0
  489. package/lib/models/room-sticky-events.js.map +1 -0
  490. package/lib/models/room-summary.d.ts +59 -0
  491. package/lib/models/room-summary.d.ts.map +1 -0
  492. package/lib/models/room-summary.js +39 -0
  493. package/lib/models/room-summary.js.map +1 -0
  494. package/lib/models/room.d.ts +1285 -0
  495. package/lib/models/room.d.ts.map +1 -0
  496. package/lib/models/room.js +3548 -0
  497. package/lib/models/room.js.map +1 -0
  498. package/lib/models/search-result.d.ts +20 -0
  499. package/lib/models/search-result.d.ts.map +1 -0
  500. package/lib/models/search-result.js +52 -0
  501. package/lib/models/search-result.js.map +1 -0
  502. package/lib/models/thread.d.ts +245 -0
  503. package/lib/models/thread.d.ts.map +1 -0
  504. package/lib/models/thread.js +866 -0
  505. package/lib/models/thread.js.map +1 -0
  506. package/lib/models/typed-event-emitter.d.ts +157 -0
  507. package/lib/models/typed-event-emitter.d.ts.map +1 -0
  508. package/lib/models/typed-event-emitter.js +227 -0
  509. package/lib/models/typed-event-emitter.js.map +1 -0
  510. package/lib/models/user.d.ts +195 -0
  511. package/lib/models/user.d.ts.map +1 -0
  512. package/lib/models/user.js +218 -0
  513. package/lib/models/user.js.map +1 -0
  514. package/lib/oidc/authorize.d.ts +93 -0
  515. package/lib/oidc/authorize.d.ts.map +1 -0
  516. package/lib/oidc/authorize.js +282 -0
  517. package/lib/oidc/authorize.js.map +1 -0
  518. package/lib/oidc/discovery.d.ts +22 -0
  519. package/lib/oidc/discovery.d.ts.map +1 -0
  520. package/lib/oidc/discovery.js +78 -0
  521. package/lib/oidc/discovery.js.map +1 -0
  522. package/lib/oidc/error.d.ts +18 -0
  523. package/lib/oidc/error.d.ts.map +1 -0
  524. package/lib/oidc/error.js +35 -0
  525. package/lib/oidc/error.js.map +1 -0
  526. package/lib/oidc/index.d.ts +16 -0
  527. package/lib/oidc/index.d.ts.map +1 -0
  528. package/lib/oidc/index.js +29 -0
  529. package/lib/oidc/index.js.map +1 -0
  530. package/lib/oidc/register.d.ts +70 -0
  531. package/lib/oidc/register.d.ts.map +1 -0
  532. package/lib/oidc/register.js +135 -0
  533. package/lib/oidc/register.js.map +1 -0
  534. package/lib/oidc/tokenRefresher.d.ts +91 -0
  535. package/lib/oidc/tokenRefresher.d.ts.map +1 -0
  536. package/lib/oidc/tokenRefresher.js +187 -0
  537. package/lib/oidc/tokenRefresher.js.map +1 -0
  538. package/lib/oidc/validate.d.ts +78 -0
  539. package/lib/oidc/validate.d.ts.map +1 -0
  540. package/lib/oidc/validate.js +181 -0
  541. package/lib/oidc/validate.js.map +1 -0
  542. package/lib/pushprocessor.d.ts +140 -0
  543. package/lib/pushprocessor.d.ts.map +1 -0
  544. package/lib/pushprocessor.js +702 -0
  545. package/lib/pushprocessor.js.map +1 -0
  546. package/lib/randomstring.d.ts +32 -0
  547. package/lib/randomstring.d.ts.map +1 -0
  548. package/lib/randomstring.js +97 -0
  549. package/lib/randomstring.js.map +1 -0
  550. package/lib/realtime-callbacks.d.ts +18 -0
  551. package/lib/realtime-callbacks.d.ts.map +1 -0
  552. package/lib/realtime-callbacks.js +177 -0
  553. package/lib/realtime-callbacks.js.map +1 -0
  554. package/lib/receipt-accumulator.d.ts +51 -0
  555. package/lib/receipt-accumulator.d.ts.map +1 -0
  556. package/lib/receipt-accumulator.js +164 -0
  557. package/lib/receipt-accumulator.js.map +1 -0
  558. package/lib/rendezvous/MSC4108SignInWithQR.d.ts +112 -0
  559. package/lib/rendezvous/MSC4108SignInWithQR.d.ts.map +1 -0
  560. package/lib/rendezvous/MSC4108SignInWithQR.js +389 -0
  561. package/lib/rendezvous/MSC4108SignInWithQR.js.map +1 -0
  562. package/lib/rendezvous/RendezvousChannel.d.ts +27 -0
  563. package/lib/rendezvous/RendezvousChannel.d.ts.map +1 -0
  564. package/lib/rendezvous/RendezvousChannel.js +1 -0
  565. package/lib/rendezvous/RendezvousChannel.js.map +1 -0
  566. package/lib/rendezvous/RendezvousCode.d.ts +9 -0
  567. package/lib/rendezvous/RendezvousCode.d.ts.map +1 -0
  568. package/lib/rendezvous/RendezvousCode.js +1 -0
  569. package/lib/rendezvous/RendezvousCode.js.map +1 -0
  570. package/lib/rendezvous/RendezvousError.d.ts +6 -0
  571. package/lib/rendezvous/RendezvousError.d.ts.map +1 -0
  572. package/lib/rendezvous/RendezvousError.js +23 -0
  573. package/lib/rendezvous/RendezvousError.js.map +1 -0
  574. package/lib/rendezvous/RendezvousFailureReason.d.ts +31 -0
  575. package/lib/rendezvous/RendezvousFailureReason.d.ts.map +1 -0
  576. package/lib/rendezvous/RendezvousFailureReason.js +47 -0
  577. package/lib/rendezvous/RendezvousFailureReason.js.map +1 -0
  578. package/lib/rendezvous/RendezvousIntent.d.ts +5 -0
  579. package/lib/rendezvous/RendezvousIntent.d.ts.map +1 -0
  580. package/lib/rendezvous/RendezvousIntent.js +22 -0
  581. package/lib/rendezvous/RendezvousIntent.js.map +1 -0
  582. package/lib/rendezvous/RendezvousTransport.d.ts +36 -0
  583. package/lib/rendezvous/RendezvousTransport.d.ts.map +1 -0
  584. package/lib/rendezvous/RendezvousTransport.js +1 -0
  585. package/lib/rendezvous/RendezvousTransport.js.map +1 -0
  586. package/lib/rendezvous/channels/MSC4108SecureChannel.d.ts +58 -0
  587. package/lib/rendezvous/channels/MSC4108SecureChannel.d.ts.map +1 -0
  588. package/lib/rendezvous/channels/MSC4108SecureChannel.js +246 -0
  589. package/lib/rendezvous/channels/MSC4108SecureChannel.js.map +1 -0
  590. package/lib/rendezvous/channels/index.d.ts +2 -0
  591. package/lib/rendezvous/channels/index.d.ts.map +1 -0
  592. package/lib/rendezvous/channels/index.js +18 -0
  593. package/lib/rendezvous/channels/index.js.map +1 -0
  594. package/lib/rendezvous/index.d.ts +10 -0
  595. package/lib/rendezvous/index.d.ts.map +1 -0
  596. package/lib/rendezvous/index.js +23 -0
  597. package/lib/rendezvous/index.js.map +1 -0
  598. package/lib/rendezvous/transports/MSC4108RendezvousSession.d.ts +61 -0
  599. package/lib/rendezvous/transports/MSC4108RendezvousSession.d.ts.map +1 -0
  600. package/lib/rendezvous/transports/MSC4108RendezvousSession.js +254 -0
  601. package/lib/rendezvous/transports/MSC4108RendezvousSession.js.map +1 -0
  602. package/lib/rendezvous/transports/index.d.ts +2 -0
  603. package/lib/rendezvous/transports/index.d.ts.map +1 -0
  604. package/lib/rendezvous/transports/index.js +18 -0
  605. package/lib/rendezvous/transports/index.js.map +1 -0
  606. package/lib/room-hierarchy.d.ts +35 -0
  607. package/lib/room-hierarchy.d.ts.map +1 -0
  608. package/lib/room-hierarchy.js +136 -0
  609. package/lib/room-hierarchy.js.map +1 -0
  610. package/lib/rust-crypto/CrossSigningIdentity.d.ts +35 -0
  611. package/lib/rust-crypto/CrossSigningIdentity.d.ts.map +1 -0
  612. package/lib/rust-crypto/CrossSigningIdentity.js +163 -0
  613. package/lib/rust-crypto/CrossSigningIdentity.js.map +1 -0
  614. package/lib/rust-crypto/DehydratedDeviceManager.d.ts +118 -0
  615. package/lib/rust-crypto/DehydratedDeviceManager.d.ts.map +1 -0
  616. package/lib/rust-crypto/DehydratedDeviceManager.js +361 -0
  617. package/lib/rust-crypto/DehydratedDeviceManager.js.map +1 -0
  618. package/lib/rust-crypto/KeyClaimManager.d.ts +33 -0
  619. package/lib/rust-crypto/KeyClaimManager.d.ts.map +1 -0
  620. package/lib/rust-crypto/KeyClaimManager.js +82 -0
  621. package/lib/rust-crypto/KeyClaimManager.js.map +1 -0
  622. package/lib/rust-crypto/OutgoingRequestProcessor.d.ts +36 -0
  623. package/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map +1 -0
  624. package/lib/rust-crypto/OutgoingRequestProcessor.js +194 -0
  625. package/lib/rust-crypto/OutgoingRequestProcessor.js.map +1 -0
  626. package/lib/rust-crypto/OutgoingRequestsManager.d.ts +47 -0
  627. package/lib/rust-crypto/OutgoingRequestsManager.d.ts.map +1 -0
  628. package/lib/rust-crypto/OutgoingRequestsManager.js +175 -0
  629. package/lib/rust-crypto/OutgoingRequestsManager.js.map +1 -0
  630. package/lib/rust-crypto/PerSessionKeyBackupDownloader.d.ts +120 -0
  631. package/lib/rust-crypto/PerSessionKeyBackupDownloader.d.ts.map +1 -0
  632. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js +469 -0
  633. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js.map +1 -0
  634. package/lib/rust-crypto/RoomEncryptor.d.ts +100 -0
  635. package/lib/rust-crypto/RoomEncryptor.d.ts.map +1 -0
  636. package/lib/rust-crypto/RoomEncryptor.js +308 -0
  637. package/lib/rust-crypto/RoomEncryptor.js.map +1 -0
  638. package/lib/rust-crypto/backup.d.ts +278 -0
  639. package/lib/rust-crypto/backup.d.ts.map +1 -0
  640. package/lib/rust-crypto/backup.js +898 -0
  641. package/lib/rust-crypto/backup.js.map +1 -0
  642. package/lib/rust-crypto/constants.d.ts +3 -0
  643. package/lib/rust-crypto/constants.d.ts.map +1 -0
  644. package/lib/rust-crypto/constants.js +19 -0
  645. package/lib/rust-crypto/constants.js.map +1 -0
  646. package/lib/rust-crypto/device-converter.d.ts +28 -0
  647. package/lib/rust-crypto/device-converter.d.ts.map +1 -0
  648. package/lib/rust-crypto/device-converter.js +123 -0
  649. package/lib/rust-crypto/device-converter.js.map +1 -0
  650. package/lib/rust-crypto/index.d.ts +65 -0
  651. package/lib/rust-crypto/index.d.ts.map +1 -0
  652. package/lib/rust-crypto/index.js +149 -0
  653. package/lib/rust-crypto/index.js.map +1 -0
  654. package/lib/rust-crypto/libolm_migration.d.ts +81 -0
  655. package/lib/rust-crypto/libolm_migration.d.ts.map +1 -0
  656. package/lib/rust-crypto/libolm_migration.js +456 -0
  657. package/lib/rust-crypto/libolm_migration.js.map +1 -0
  658. package/lib/rust-crypto/rust-crypto.d.ts +576 -0
  659. package/lib/rust-crypto/rust-crypto.d.ts.map +1 -0
  660. package/lib/rust-crypto/rust-crypto.js +2324 -0
  661. package/lib/rust-crypto/rust-crypto.js.map +1 -0
  662. package/lib/rust-crypto/secret-storage.d.ts +22 -0
  663. package/lib/rust-crypto/secret-storage.d.ts.map +1 -0
  664. package/lib/rust-crypto/secret-storage.js +63 -0
  665. package/lib/rust-crypto/secret-storage.js.map +1 -0
  666. package/lib/rust-crypto/verification.d.ts +321 -0
  667. package/lib/rust-crypto/verification.d.ts.map +1 -0
  668. package/lib/rust-crypto/verification.js +817 -0
  669. package/lib/rust-crypto/verification.js.map +1 -0
  670. package/lib/scheduler.d.ts +132 -0
  671. package/lib/scheduler.d.ts.map +1 -0
  672. package/lib/scheduler.js +259 -0
  673. package/lib/scheduler.js.map +1 -0
  674. package/lib/secret-storage.d.ts +383 -0
  675. package/lib/secret-storage.d.ts.map +1 -0
  676. package/lib/secret-storage.js +487 -0
  677. package/lib/secret-storage.js.map +1 -0
  678. package/lib/serverCapabilities.d.ts +78 -0
  679. package/lib/serverCapabilities.d.ts.map +1 -0
  680. package/lib/serverCapabilities.js +104 -0
  681. package/lib/serverCapabilities.js.map +1 -0
  682. package/lib/service-types.d.ts +5 -0
  683. package/lib/service-types.d.ts.map +1 -0
  684. package/lib/service-types.js +23 -0
  685. package/lib/service-types.js.map +1 -0
  686. package/lib/sliding-sync-sdk.d.ts +107 -0
  687. package/lib/sliding-sync-sdk.d.ts.map +1 -0
  688. package/lib/sliding-sync-sdk.js +892 -0
  689. package/lib/sliding-sync-sdk.js.map +1 -0
  690. package/lib/sliding-sync.d.ts +306 -0
  691. package/lib/sliding-sync.d.ts.map +1 -0
  692. package/lib/sliding-sync.js +585 -0
  693. package/lib/sliding-sync.js.map +1 -0
  694. package/lib/store/index.d.ts +201 -0
  695. package/lib/store/index.d.ts.map +1 -0
  696. package/lib/store/index.js +1 -0
  697. package/lib/store/index.js.map +1 -0
  698. package/lib/store/indexeddb-backend.d.ts +24 -0
  699. package/lib/store/indexeddb-backend.d.ts.map +1 -0
  700. package/lib/store/indexeddb-backend.js +1 -0
  701. package/lib/store/indexeddb-backend.js.map +1 -0
  702. package/lib/store/indexeddb-local-backend.d.ts +129 -0
  703. package/lib/store/indexeddb-local-backend.d.ts.map +1 -0
  704. package/lib/store/indexeddb-local-backend.js +599 -0
  705. package/lib/store/indexeddb-local-backend.js.map +1 -0
  706. package/lib/store/indexeddb-remote-backend.d.ts +79 -0
  707. package/lib/store/indexeddb-remote-backend.d.ts.map +1 -0
  708. package/lib/store/indexeddb-remote-backend.js +209 -0
  709. package/lib/store/indexeddb-remote-backend.js.map +1 -0
  710. package/lib/store/indexeddb-store-worker.d.ts +35 -0
  711. package/lib/store/indexeddb-store-worker.d.ts.map +1 -0
  712. package/lib/store/indexeddb-store-worker.js +146 -0
  713. package/lib/store/indexeddb-store-worker.js.map +1 -0
  714. package/lib/store/indexeddb.d.ts +142 -0
  715. package/lib/store/indexeddb.d.ts.map +1 -0
  716. package/lib/store/indexeddb.js +347 -0
  717. package/lib/store/indexeddb.js.map +1 -0
  718. package/lib/store/local-storage-events-emitter.d.ts +30 -0
  719. package/lib/store/local-storage-events-emitter.d.ts.map +1 -0
  720. package/lib/store/local-storage-events-emitter.js +37 -0
  721. package/lib/store/local-storage-events-emitter.js.map +1 -0
  722. package/lib/store/memory.d.ts +209 -0
  723. package/lib/store/memory.d.ts.map +1 -0
  724. package/lib/store/memory.js +432 -0
  725. package/lib/store/memory.js.map +1 -0
  726. package/lib/store/stub.d.ts +161 -0
  727. package/lib/store/stub.d.ts.map +1 -0
  728. package/lib/store/stub.js +268 -0
  729. package/lib/store/stub.js.map +1 -0
  730. package/lib/sync-accumulator.d.ts +207 -0
  731. package/lib/sync-accumulator.d.ts.map +1 -0
  732. package/lib/sync-accumulator.js +588 -0
  733. package/lib/sync-accumulator.js.map +1 -0
  734. package/lib/sync.d.ts +273 -0
  735. package/lib/sync.d.ts.map +1 -0
  736. package/lib/sync.js +1764 -0
  737. package/lib/sync.js.map +1 -0
  738. package/lib/testing.d.ts +98 -0
  739. package/lib/testing.d.ts.map +1 -0
  740. package/lib/testing.js +205 -0
  741. package/lib/testing.js.map +1 -0
  742. package/lib/thread-utils.d.ts +10 -0
  743. package/lib/thread-utils.d.ts.map +1 -0
  744. package/lib/thread-utils.js +31 -0
  745. package/lib/thread-utils.js.map +1 -0
  746. package/lib/timeline-window.d.ts +168 -0
  747. package/lib/timeline-window.d.ts.map +1 -0
  748. package/lib/timeline-window.js +494 -0
  749. package/lib/timeline-window.js.map +1 -0
  750. package/lib/types.d.ts +33 -0
  751. package/lib/types.d.ts.map +1 -0
  752. package/lib/types.js +52 -0
  753. package/lib/types.js.map +1 -0
  754. package/lib/utils/decryptAESSecretStorageItem.d.ts +12 -0
  755. package/lib/utils/decryptAESSecretStorageItem.d.ts.map +1 -0
  756. package/lib/utils/decryptAESSecretStorageItem.js +50 -0
  757. package/lib/utils/decryptAESSecretStorageItem.js.map +1 -0
  758. package/lib/utils/encryptAESSecretStorageItem.d.ts +16 -0
  759. package/lib/utils/encryptAESSecretStorageItem.d.ts.map +1 -0
  760. package/lib/utils/encryptAESSecretStorageItem.js +68 -0
  761. package/lib/utils/encryptAESSecretStorageItem.js.map +1 -0
  762. package/lib/utils/internal/deriveKeys.d.ts +10 -0
  763. package/lib/utils/internal/deriveKeys.d.ts.map +1 -0
  764. package/lib/utils/internal/deriveKeys.js +60 -0
  765. package/lib/utils/internal/deriveKeys.js.map +1 -0
  766. package/lib/utils/roomVersion.d.ts +13 -0
  767. package/lib/utils/roomVersion.d.ts.map +1 -0
  768. package/lib/utils/roomVersion.js +36 -0
  769. package/lib/utils/roomVersion.js.map +1 -0
  770. package/lib/utils.d.ts +270 -0
  771. package/lib/utils.d.ts.map +1 -0
  772. package/lib/utils.js +764 -0
  773. package/lib/utils.js.map +1 -0
  774. package/lib/version-support.d.ts +19 -0
  775. package/lib/version-support.d.ts.map +1 -0
  776. package/lib/version-support.js +37 -0
  777. package/lib/version-support.js.map +1 -0
  778. package/lib/webrtc/audioContext.d.ts +15 -0
  779. package/lib/webrtc/audioContext.d.ts.map +1 -0
  780. package/lib/webrtc/audioContext.js +46 -0
  781. package/lib/webrtc/audioContext.js.map +1 -0
  782. package/lib/webrtc/call.d.ts +560 -0
  783. package/lib/webrtc/call.d.ts.map +1 -0
  784. package/lib/webrtc/call.js +2596 -0
  785. package/lib/webrtc/call.js.map +1 -0
  786. package/lib/webrtc/callEventHandler.d.ts +37 -0
  787. package/lib/webrtc/callEventHandler.d.ts.map +1 -0
  788. package/lib/webrtc/callEventHandler.js +344 -0
  789. package/lib/webrtc/callEventHandler.js.map +1 -0
  790. package/lib/webrtc/callEventTypes.d.ts +79 -0
  791. package/lib/webrtc/callEventTypes.d.ts.map +1 -0
  792. package/lib/webrtc/callEventTypes.js +13 -0
  793. package/lib/webrtc/callEventTypes.js.map +1 -0
  794. package/lib/webrtc/callFeed.d.ts +128 -0
  795. package/lib/webrtc/callFeed.d.ts.map +1 -0
  796. package/lib/webrtc/callFeed.js +289 -0
  797. package/lib/webrtc/callFeed.js.map +1 -0
  798. package/lib/webrtc/groupCall.d.ts +319 -0
  799. package/lib/webrtc/groupCall.d.ts.map +1 -0
  800. package/lib/webrtc/groupCall.js +1334 -0
  801. package/lib/webrtc/groupCall.js.map +1 -0
  802. package/lib/webrtc/groupCallEventHandler.d.ts +31 -0
  803. package/lib/webrtc/groupCallEventHandler.d.ts.map +1 -0
  804. package/lib/webrtc/groupCallEventHandler.js +178 -0
  805. package/lib/webrtc/groupCallEventHandler.js.map +1 -0
  806. package/lib/webrtc/mediaHandler.d.ts +89 -0
  807. package/lib/webrtc/mediaHandler.d.ts.map +1 -0
  808. package/lib/webrtc/mediaHandler.js +454 -0
  809. package/lib/webrtc/mediaHandler.js.map +1 -0
  810. package/lib/webrtc/stats/callFeedStatsReporter.d.ts +8 -0
  811. package/lib/webrtc/stats/callFeedStatsReporter.d.ts.map +1 -0
  812. package/lib/webrtc/stats/callFeedStatsReporter.js +79 -0
  813. package/lib/webrtc/stats/callFeedStatsReporter.js.map +1 -0
  814. package/lib/webrtc/stats/callStatsReportGatherer.d.ts +25 -0
  815. package/lib/webrtc/stats/callStatsReportGatherer.d.ts.map +1 -0
  816. package/lib/webrtc/stats/callStatsReportGatherer.js +199 -0
  817. package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -0
  818. package/lib/webrtc/stats/callStatsReportSummary.d.ts +17 -0
  819. package/lib/webrtc/stats/callStatsReportSummary.d.ts.map +1 -0
  820. package/lib/webrtc/stats/callStatsReportSummary.js +1 -0
  821. package/lib/webrtc/stats/callStatsReportSummary.js.map +1 -0
  822. package/lib/webrtc/stats/connectionStats.d.ts +28 -0
  823. package/lib/webrtc/stats/connectionStats.d.ts.map +1 -0
  824. package/lib/webrtc/stats/connectionStats.js +26 -0
  825. package/lib/webrtc/stats/connectionStats.js.map +1 -0
  826. package/lib/webrtc/stats/connectionStatsBuilder.d.ts +5 -0
  827. package/lib/webrtc/stats/connectionStatsBuilder.d.ts.map +1 -0
  828. package/lib/webrtc/stats/connectionStatsBuilder.js +27 -0
  829. package/lib/webrtc/stats/connectionStatsBuilder.js.map +1 -0
  830. package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts +7 -0
  831. package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts.map +1 -0
  832. package/lib/webrtc/stats/connectionStatsReportBuilder.js +121 -0
  833. package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +1 -0
  834. package/lib/webrtc/stats/groupCallStats.d.ts +22 -0
  835. package/lib/webrtc/stats/groupCallStats.d.ts.map +1 -0
  836. package/lib/webrtc/stats/groupCallStats.js +78 -0
  837. package/lib/webrtc/stats/groupCallStats.js.map +1 -0
  838. package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts +10 -0
  839. package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts.map +1 -0
  840. package/lib/webrtc/stats/media/mediaSsrcHandler.js +57 -0
  841. package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +1 -0
  842. package/lib/webrtc/stats/media/mediaTrackHandler.d.ts +12 -0
  843. package/lib/webrtc/stats/media/mediaTrackHandler.d.ts.map +1 -0
  844. package/lib/webrtc/stats/media/mediaTrackHandler.js +58 -0
  845. package/lib/webrtc/stats/media/mediaTrackHandler.js.map +1 -0
  846. package/lib/webrtc/stats/media/mediaTrackStats.d.ts +86 -0
  847. package/lib/webrtc/stats/media/mediaTrackStats.d.ts.map +1 -0
  848. package/lib/webrtc/stats/media/mediaTrackStats.js +142 -0
  849. package/lib/webrtc/stats/media/mediaTrackStats.js.map +1 -0
  850. package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts +22 -0
  851. package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts.map +1 -0
  852. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +76 -0
  853. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +1 -0
  854. package/lib/webrtc/stats/statsReport.d.ts +99 -0
  855. package/lib/webrtc/stats/statsReport.d.ts.map +1 -0
  856. package/lib/webrtc/stats/statsReport.js +32 -0
  857. package/lib/webrtc/stats/statsReport.js.map +1 -0
  858. package/lib/webrtc/stats/statsReportEmitter.d.ts +15 -0
  859. package/lib/webrtc/stats/statsReportEmitter.d.ts.map +1 -0
  860. package/lib/webrtc/stats/statsReportEmitter.js +33 -0
  861. package/lib/webrtc/stats/statsReportEmitter.js.map +1 -0
  862. package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts +16 -0
  863. package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts.map +1 -0
  864. package/lib/webrtc/stats/summaryStatsReportGatherer.js +116 -0
  865. package/lib/webrtc/stats/summaryStatsReportGatherer.js.map +1 -0
  866. package/lib/webrtc/stats/trackStatsBuilder.d.ts +19 -0
  867. package/lib/webrtc/stats/trackStatsBuilder.d.ts.map +1 -0
  868. package/lib/webrtc/stats/trackStatsBuilder.js +168 -0
  869. package/lib/webrtc/stats/trackStatsBuilder.js.map +1 -0
  870. package/lib/webrtc/stats/transportStats.d.ts +11 -0
  871. package/lib/webrtc/stats/transportStats.d.ts.map +1 -0
  872. package/lib/webrtc/stats/transportStats.js +1 -0
  873. package/lib/webrtc/stats/transportStats.js.map +1 -0
  874. package/lib/webrtc/stats/transportStatsBuilder.d.ts +5 -0
  875. package/lib/webrtc/stats/transportStatsBuilder.d.ts.map +1 -0
  876. package/lib/webrtc/stats/transportStatsBuilder.js +34 -0
  877. package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -0
  878. package/lib/webrtc/stats/valueFormatter.d.ts +4 -0
  879. package/lib/webrtc/stats/valueFormatter.d.ts.map +1 -0
  880. package/lib/webrtc/stats/valueFormatter.js +25 -0
  881. package/lib/webrtc/stats/valueFormatter.js.map +1 -0
  882. package/package.json +129 -0
  883. package/src/@types/AESEncryptedSecretStoragePayload.ts +29 -0
  884. package/src/@types/IIdentityServerProvider.ts +24 -0
  885. package/src/@types/PushRules.ts +208 -0
  886. package/src/@types/another-json.d.ts +19 -0
  887. package/src/@types/auth.ts +258 -0
  888. package/src/@types/beacon.ts +140 -0
  889. package/src/@types/common.ts +24 -0
  890. package/src/@types/crypto.ts +71 -0
  891. package/src/@types/event.ts +449 -0
  892. package/src/@types/events.ts +119 -0
  893. package/src/@types/extensible_events.ts +147 -0
  894. package/src/@types/global.d.ts +67 -0
  895. package/src/@types/local_notifications.ts +19 -0
  896. package/src/@types/location.ts +92 -0
  897. package/src/@types/matrix-sdk-crypto-wasm.d.ts +39 -0
  898. package/src/@types/media.ts +245 -0
  899. package/src/@types/membership.ts +57 -0
  900. package/src/@types/partials.ts +103 -0
  901. package/src/@types/polls.ts +120 -0
  902. package/src/@types/read_receipts.ts +61 -0
  903. package/src/@types/registration.ts +102 -0
  904. package/src/@types/requests.ts +346 -0
  905. package/src/@types/search.ts +119 -0
  906. package/src/@types/signed.ts +25 -0
  907. package/src/@types/spaces.ts +37 -0
  908. package/src/@types/state_events.ts +153 -0
  909. package/src/@types/synapse.ts +40 -0
  910. package/src/@types/sync.ts +27 -0
  911. package/src/@types/threepids.ts +29 -0
  912. package/src/@types/topic.ts +69 -0
  913. package/src/@types/uia.ts +24 -0
  914. package/src/NamespacedValue.ts +121 -0
  915. package/src/ReEmitter.ts +93 -0
  916. package/src/ToDeviceMessageQueue.ts +156 -0
  917. package/src/autodiscovery.ts +505 -0
  918. package/src/base64.ts +86 -0
  919. package/src/briij.ts +173 -0
  920. package/src/browser-index.ts +44 -0
  921. package/src/client.ts +9031 -0
  922. package/src/common-crypto/CryptoBackend.ts +295 -0
  923. package/src/common-crypto/README.md +4 -0
  924. package/src/common-crypto/key-passphrase.ts +43 -0
  925. package/src/content-helpers.ts +298 -0
  926. package/src/content-repo.ts +122 -0
  927. package/src/crypto/store/base.ts +388 -0
  928. package/src/crypto/store/indexeddb-crypto-store-backend.ts +655 -0
  929. package/src/crypto/store/indexeddb-crypto-store.ts +555 -0
  930. package/src/crypto/store/localStorage-crypto-store.ts +409 -0
  931. package/src/crypto/store/memory-crypto-store.ts +326 -0
  932. package/src/crypto-api/CryptoEvent.ts +152 -0
  933. package/src/crypto-api/CryptoEventHandlerMap.ts +42 -0
  934. package/src/crypto-api/index.ts +1362 -0
  935. package/src/crypto-api/key-passphrase.ts +58 -0
  936. package/src/crypto-api/keybackup.ts +114 -0
  937. package/src/crypto-api/recovery-key.ts +69 -0
  938. package/src/crypto-api/verification.ts +382 -0
  939. package/src/digest.ts +34 -0
  940. package/src/embedded.ts +865 -0
  941. package/src/errors.ts +87 -0
  942. package/src/event-mapper.ts +88 -0
  943. package/src/extensible_events_v1/ExtensibleEvent.ts +58 -0
  944. package/src/extensible_events_v1/InvalidEventError.ts +24 -0
  945. package/src/extensible_events_v1/MessageEvent.ts +143 -0
  946. package/src/extensible_events_v1/PollEndEvent.ts +97 -0
  947. package/src/extensible_events_v1/PollResponseEvent.ts +148 -0
  948. package/src/extensible_events_v1/PollStartEvent.ts +207 -0
  949. package/src/extensible_events_v1/utilities.ts +35 -0
  950. package/src/feature.ts +88 -0
  951. package/src/filter-component.ts +209 -0
  952. package/src/filter.ts +245 -0
  953. package/src/http-api/errors.ts +261 -0
  954. package/src/http-api/fetch.ts +377 -0
  955. package/src/http-api/index.ts +194 -0
  956. package/src/http-api/interface.ts +229 -0
  957. package/src/http-api/method.ts +25 -0
  958. package/src/http-api/prefix.ts +48 -0
  959. package/src/http-api/refresh.ts +167 -0
  960. package/src/http-api/utils.ts +217 -0
  961. package/src/index.ts +25 -0
  962. package/src/indexeddb-helpers.ts +50 -0
  963. package/src/indexeddb-worker.ts +24 -0
  964. package/src/interactive-auth.ts +700 -0
  965. package/src/logger.ts +279 -0
  966. package/src/matrixrtc/CallMembership.ts +438 -0
  967. package/src/matrixrtc/EncryptionManager.ts +54 -0
  968. package/src/matrixrtc/IKeyTransport.ts +63 -0
  969. package/src/matrixrtc/IMembershipManager.ts +120 -0
  970. package/src/matrixrtc/LivekitTransport.ts +46 -0
  971. package/src/matrixrtc/MatrixRTCSession.ts +934 -0
  972. package/src/matrixrtc/MatrixRTCSessionManager.ts +170 -0
  973. package/src/matrixrtc/MembershipManager.ts +1122 -0
  974. package/src/matrixrtc/MembershipManagerActionScheduler.ts +135 -0
  975. package/src/matrixrtc/RTCEncryptionManager.ts +459 -0
  976. package/src/matrixrtc/ToDeviceKeyTransport.ts +197 -0
  977. package/src/matrixrtc/index.ts +24 -0
  978. package/src/matrixrtc/membershipData/common.ts +27 -0
  979. package/src/matrixrtc/membershipData/index.ts +19 -0
  980. package/src/matrixrtc/membershipData/rtc.ts +156 -0
  981. package/src/matrixrtc/membershipData/session.ts +146 -0
  982. package/src/matrixrtc/types.ts +227 -0
  983. package/src/matrixrtc/utils.ts +71 -0
  984. package/src/models/MSC3089Branch.ts +272 -0
  985. package/src/models/MSC3089TreeSpace.ts +565 -0
  986. package/src/models/ToDeviceMessage.ts +38 -0
  987. package/src/models/beacon.ts +213 -0
  988. package/src/models/compare-event-ordering.ts +139 -0
  989. package/src/models/device.ts +85 -0
  990. package/src/models/event-context.ts +110 -0
  991. package/src/models/event-status.ts +39 -0
  992. package/src/models/event-timeline-set.ts +962 -0
  993. package/src/models/event-timeline.ts +461 -0
  994. package/src/models/event.ts +1819 -0
  995. package/src/models/invites-ignorer-types.ts +58 -0
  996. package/src/models/invites-ignorer.ts +341 -0
  997. package/src/models/poll.ts +285 -0
  998. package/src/models/profile-keys.ts +33 -0
  999. package/src/models/read-receipt.ts +422 -0
  1000. package/src/models/related-relations.ts +39 -0
  1001. package/src/models/relations-container.ts +149 -0
  1002. package/src/models/relations.ts +392 -0
  1003. package/src/models/room-member.ts +486 -0
  1004. package/src/models/room-receipts.ts +439 -0
  1005. package/src/models/room-state.ts +1230 -0
  1006. package/src/models/room-sticky-events.ts +383 -0
  1007. package/src/models/room-summary.ts +78 -0
  1008. package/src/models/room.ts +4067 -0
  1009. package/src/models/search-result.ts +57 -0
  1010. package/src/models/thread.ts +928 -0
  1011. package/src/models/typed-event-emitter.ts +246 -0
  1012. package/src/models/user.ts +302 -0
  1013. package/src/oidc/authorize.ts +279 -0
  1014. package/src/oidc/discovery.ts +67 -0
  1015. package/src/oidc/error.ts +33 -0
  1016. package/src/oidc/index.ts +33 -0
  1017. package/src/oidc/register.ts +163 -0
  1018. package/src/oidc/tokenRefresher.ts +184 -0
  1019. package/src/oidc/validate.ts +265 -0
  1020. package/src/pushprocessor.ts +856 -0
  1021. package/src/randomstring.ts +103 -0
  1022. package/src/realtime-callbacks.ts +191 -0
  1023. package/src/receipt-accumulator.ts +189 -0
  1024. package/src/rendezvous/MSC4108SignInWithQR.ts +443 -0
  1025. package/src/rendezvous/RendezvousChannel.ts +48 -0
  1026. package/src/rendezvous/RendezvousCode.ts +25 -0
  1027. package/src/rendezvous/RendezvousError.ts +26 -0
  1028. package/src/rendezvous/RendezvousFailureReason.ts +49 -0
  1029. package/src/rendezvous/RendezvousIntent.ts +20 -0
  1030. package/src/rendezvous/RendezvousTransport.ts +58 -0
  1031. package/src/rendezvous/channels/MSC4108SecureChannel.ts +270 -0
  1032. package/src/rendezvous/channels/index.ts +17 -0
  1033. package/src/rendezvous/index.ts +25 -0
  1034. package/src/rendezvous/transports/MSC4108RendezvousSession.ts +272 -0
  1035. package/src/rendezvous/transports/index.ts +17 -0
  1036. package/src/room-hierarchy.ts +152 -0
  1037. package/src/rust-crypto/CrossSigningIdentity.ts +195 -0
  1038. package/src/rust-crypto/DehydratedDeviceManager.ts +392 -0
  1039. package/src/rust-crypto/KeyClaimManager.ts +86 -0
  1040. package/src/rust-crypto/OutgoingRequestProcessor.ts +233 -0
  1041. package/src/rust-crypto/OutgoingRequestsManager.ts +170 -0
  1042. package/src/rust-crypto/PerSessionKeyBackupDownloader.ts +501 -0
  1043. package/src/rust-crypto/RoomEncryptor.ts +362 -0
  1044. package/src/rust-crypto/backup.ts +942 -0
  1045. package/src/rust-crypto/constants.ts +18 -0
  1046. package/src/rust-crypto/device-converter.ts +128 -0
  1047. package/src/rust-crypto/index.ts +251 -0
  1048. package/src/rust-crypto/libolm_migration.ts +532 -0
  1049. package/src/rust-crypto/rust-crypto.ts +2542 -0
  1050. package/src/rust-crypto/secret-storage.ts +60 -0
  1051. package/src/rust-crypto/verification.ts +833 -0
  1052. package/src/scheduler.ts +309 -0
  1053. package/src/secret-storage.ts +714 -0
  1054. package/src/serverCapabilities.ts +146 -0
  1055. package/src/service-types.ts +20 -0
  1056. package/src/sliding-sync-sdk.ts +1005 -0
  1057. package/src/sliding-sync.ts +674 -0
  1058. package/src/store/index.ts +261 -0
  1059. package/src/store/indexeddb-backend.ts +41 -0
  1060. package/src/store/indexeddb-local-backend.ts +610 -0
  1061. package/src/store/indexeddb-remote-backend.ts +212 -0
  1062. package/src/store/indexeddb-store-worker.ts +157 -0
  1063. package/src/store/indexeddb.ts +397 -0
  1064. package/src/store/local-storage-events-emitter.ts +46 -0
  1065. package/src/store/memory.ts +448 -0
  1066. package/src/store/stub.ts +280 -0
  1067. package/src/sync-accumulator.ts +779 -0
  1068. package/src/sync.ts +2020 -0
  1069. package/src/testing.ts +231 -0
  1070. package/src/thread-utils.ts +31 -0
  1071. package/src/timeline-window.ts +534 -0
  1072. package/src/types.ts +59 -0
  1073. package/src/utils/decryptAESSecretStorageItem.ts +54 -0
  1074. package/src/utils/encryptAESSecretStorageItem.ts +73 -0
  1075. package/src/utils/internal/deriveKeys.ts +63 -0
  1076. package/src/utils/roomVersion.ts +35 -0
  1077. package/src/utils.ts +775 -0
  1078. package/src/version-support.ts +50 -0
  1079. package/src/webrtc/audioContext.ts +44 -0
  1080. package/src/webrtc/call.ts +3061 -0
  1081. package/src/webrtc/callEventHandler.ts +425 -0
  1082. package/src/webrtc/callEventTypes.ts +101 -0
  1083. package/src/webrtc/callFeed.ts +364 -0
  1084. package/src/webrtc/groupCall.ts +1729 -0
  1085. package/src/webrtc/groupCallEventHandler.ts +234 -0
  1086. package/src/webrtc/mediaHandler.ts +501 -0
  1087. package/src/webrtc/stats/callFeedStatsReporter.ts +91 -0
  1088. package/src/webrtc/stats/callStatsReportGatherer.ts +219 -0
  1089. package/src/webrtc/stats/callStatsReportSummary.ts +30 -0
  1090. package/src/webrtc/stats/connectionStats.ts +47 -0
  1091. package/src/webrtc/stats/connectionStatsBuilder.ts +28 -0
  1092. package/src/webrtc/stats/connectionStatsReportBuilder.ts +140 -0
  1093. package/src/webrtc/stats/groupCallStats.ts +93 -0
  1094. package/src/webrtc/stats/media/mediaSsrcHandler.ts +57 -0
  1095. package/src/webrtc/stats/media/mediaTrackHandler.ts +70 -0
  1096. package/src/webrtc/stats/media/mediaTrackStats.ts +176 -0
  1097. package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +90 -0
  1098. package/src/webrtc/stats/statsReport.ts +133 -0
  1099. package/src/webrtc/stats/statsReportEmitter.ts +49 -0
  1100. package/src/webrtc/stats/summaryStatsReportGatherer.ts +148 -0
  1101. package/src/webrtc/stats/trackStatsBuilder.ts +207 -0
  1102. package/src/webrtc/stats/transportStats.ts +26 -0
  1103. package/src/webrtc/stats/transportStatsBuilder.ts +48 -0
  1104. package/src/webrtc/stats/valueFormatter.ts +27 -0
@@ -0,0 +1,2596 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ /*
6
+ Copyright 2015, 2016 OpenMarket Ltd
7
+ Copyright 2017 New Vector Ltd
8
+ Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
9
+ Copyright 2021 - 2022 Šimon Brandner <simon.bra.ag@gmail.com>
10
+
11
+ Licensed under the Apache License, Version 2.0 (the "License");
12
+ you may not use this file except in compliance with the License.
13
+ You may obtain a copy of the License at
14
+
15
+ http://www.apache.org/licenses/LICENSE-2.0
16
+
17
+ Unless required by applicable law or agreed to in writing, software
18
+ distributed under the License is distributed on an "AS IS" BASIS,
19
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ See the License for the specific language governing permissions and
21
+ limitations under the License.
22
+ */
23
+
24
+ /**
25
+ * This is an internal module. See {@link createNewBriijCall} for the public API.
26
+ */
27
+
28
+ import { v4 as uuidv4 } from "uuid";
29
+ import { parse as parseSdp, write as writeSdp } from "sdp-transform";
30
+ import { logger } from "../logger.js";
31
+ import { checkObjectHasKeys, isNullOrUndefined, recursivelyAssign } from "../utils.js";
32
+ import { EventType, ToDeviceMessageId } from "../@types/event.js";
33
+ import { secureRandomString } from "../randomstring.js";
34
+ import { SDPStreamMetadataPurpose, SDPStreamMetadataKey } from "./callEventTypes.js";
35
+ import { CallFeed } from "./callFeed.js";
36
+ import { EventEmitterEvents, TypedEventEmitter } from "../models/typed-event-emitter.js";
37
+ import { GroupCallUnknownDeviceError } from "./groupCall.js";
38
+ import { BriijError } from "../http-api/index.js";
39
+ var MediaType = /*#__PURE__*/function (MediaType) {
40
+ MediaType["AUDIO"] = "audio";
41
+ MediaType["VIDEO"] = "video";
42
+ return MediaType;
43
+ }(MediaType || {});
44
+ var CodecName = /*#__PURE__*/function (CodecName) {
45
+ CodecName["OPUS"] = "opus"; // add more as needed
46
+ return CodecName;
47
+ }(CodecName || {}); // Used internally to specify modifications to codec parameters in SDP
48
+ export var CallState = /*#__PURE__*/function (CallState) {
49
+ CallState["Fledgling"] = "fledgling";
50
+ CallState["InviteSent"] = "invite_sent";
51
+ CallState["WaitLocalMedia"] = "wait_local_media";
52
+ CallState["CreateOffer"] = "create_offer";
53
+ CallState["CreateAnswer"] = "create_answer";
54
+ CallState["Connecting"] = "connecting";
55
+ CallState["Connected"] = "connected";
56
+ CallState["Ringing"] = "ringing";
57
+ CallState["Ended"] = "ended";
58
+ return CallState;
59
+ }({});
60
+ export var CallType = /*#__PURE__*/function (CallType) {
61
+ CallType["Voice"] = "voice";
62
+ CallType["Video"] = "video";
63
+ return CallType;
64
+ }({});
65
+ export var CallDirection = /*#__PURE__*/function (CallDirection) {
66
+ CallDirection["Inbound"] = "inbound";
67
+ CallDirection["Outbound"] = "outbound";
68
+ return CallDirection;
69
+ }({});
70
+ export var CallParty = /*#__PURE__*/function (CallParty) {
71
+ CallParty["Local"] = "local";
72
+ CallParty["Remote"] = "remote";
73
+ return CallParty;
74
+ }({});
75
+ export var CallEvent = /*#__PURE__*/function (CallEvent) {
76
+ CallEvent["Hangup"] = "hangup";
77
+ CallEvent["State"] = "state";
78
+ CallEvent["Error"] = "error";
79
+ CallEvent["Replaced"] = "replaced";
80
+ // The value of isLocalOnHold() has changed
81
+ CallEvent["LocalHoldUnhold"] = "local_hold_unhold";
82
+ // The value of isRemoteOnHold() has changed
83
+ CallEvent["RemoteHoldUnhold"] = "remote_hold_unhold";
84
+ // backwards compat alias for LocalHoldUnhold: remove in a major version bump
85
+ CallEvent["HoldUnhold"] = "hold_unhold";
86
+ // Feeds have changed
87
+ CallEvent["FeedsChanged"] = "feeds_changed";
88
+ CallEvent["AssertedIdentityChanged"] = "asserted_identity_changed";
89
+ CallEvent["LengthChanged"] = "length_changed";
90
+ CallEvent["DataChannel"] = "datachannel";
91
+ CallEvent["SendVoipEvent"] = "send_voip_event";
92
+ // When the call instantiates its peer connection
93
+ // For apps that want to access the underlying peer connection, eg for debugging
94
+ CallEvent["PeerConnectionCreated"] = "peer_connection_created";
95
+ return CallEvent;
96
+ }({});
97
+ export var CallErrorCode = /*#__PURE__*/function (CallErrorCode) {
98
+ /** The user chose to end the call */
99
+ CallErrorCode["UserHangup"] = "user_hangup";
100
+ /** An error code when the local client failed to create an offer. */
101
+ CallErrorCode["LocalOfferFailed"] = "local_offer_failed";
102
+ /**
103
+ * An error code when there is no local mic/camera to use. This may be because
104
+ * the hardware isn't plugged in, or the user has explicitly denied access.
105
+ */
106
+ CallErrorCode["NoUserMedia"] = "no_user_media";
107
+ /**
108
+ * Error code used when a call event failed to send
109
+ * because unknown devices were present in the room
110
+ */
111
+ CallErrorCode["UnknownDevices"] = "unknown_devices";
112
+ /**
113
+ * Error code used when we fail to send the invite
114
+ * for some reason other than there being unknown devices
115
+ */
116
+ CallErrorCode["SendInvite"] = "send_invite";
117
+ /**
118
+ * An answer could not be created
119
+ */
120
+ CallErrorCode["CreateAnswer"] = "create_answer";
121
+ /**
122
+ * An offer could not be created
123
+ */
124
+ CallErrorCode["CreateOffer"] = "create_offer";
125
+ /**
126
+ * Error code used when we fail to send the answer
127
+ * for some reason other than there being unknown devices
128
+ */
129
+ CallErrorCode["SendAnswer"] = "send_answer";
130
+ /**
131
+ * The session description from the other side could not be set
132
+ */
133
+ CallErrorCode["SetRemoteDescription"] = "set_remote_description";
134
+ /**
135
+ * The session description from this side could not be set
136
+ */
137
+ CallErrorCode["SetLocalDescription"] = "set_local_description";
138
+ /**
139
+ * A different device answered the call
140
+ */
141
+ CallErrorCode["AnsweredElsewhere"] = "answered_elsewhere";
142
+ /**
143
+ * No media connection could be established to the other party
144
+ */
145
+ CallErrorCode["IceFailed"] = "ice_failed";
146
+ /**
147
+ * The invite timed out whilst waiting for an answer
148
+ */
149
+ CallErrorCode["InviteTimeout"] = "invite_timeout";
150
+ /**
151
+ * The call was replaced by another call
152
+ */
153
+ CallErrorCode["Replaced"] = "replaced";
154
+ /**
155
+ * Signalling for the call could not be sent (other than the initial invite)
156
+ */
157
+ CallErrorCode["SignallingFailed"] = "signalling_timeout";
158
+ /**
159
+ * The remote party is busy
160
+ */
161
+ CallErrorCode["UserBusy"] = "user_busy";
162
+ /**
163
+ * We transferred the call off to somewhere else
164
+ */
165
+ CallErrorCode["Transferred"] = "transferred";
166
+ /**
167
+ * A call from the same user was found with a new session id
168
+ */
169
+ CallErrorCode["NewSession"] = "new_session";
170
+ return CallErrorCode;
171
+ }({});
172
+
173
+ /**
174
+ * The version field that we set in m.call.* events
175
+ */
176
+ var VOIP_PROTO_VERSION = "1";
177
+
178
+ /** The fallback ICE server to use for STUN or TURN protocols. */
179
+ export var FALLBACK_ICE_SERVER = "stun:turn.matrix.org";
180
+
181
+ /** The length of time a call can be ringing for. */
182
+ var CALL_TIMEOUT_MS = 60 * 1000; // ms
183
+ /** The time after which we increment callLength */
184
+ var CALL_LENGTH_INTERVAL = 1000; // ms
185
+ /** The time after which we end the call, if ICE got disconnected */
186
+ var ICE_DISCONNECTED_TIMEOUT = 30 * 1000; // ms
187
+ /** The time after which we try a ICE restart, if ICE got disconnected */
188
+ var ICE_RECONNECTING_TIMEOUT = 2 * 1000; // ms
189
+ export class CallError extends Error {
190
+ constructor(code, msg, err) {
191
+ // Still don't think there's any way to have proper nested errors
192
+ super(msg + ": " + err);
193
+ _defineProperty(this, "code", void 0);
194
+ this.code = code;
195
+ }
196
+ }
197
+ export function genCallID() {
198
+ return Date.now().toString() + secureRandomString(16);
199
+ }
200
+ function getCodecParamMods(isPtt) {
201
+ var mods = [{
202
+ mediaType: "audio",
203
+ codec: "opus",
204
+ enableDtx: true,
205
+ maxAverageBitrate: isPtt ? 12000 : undefined
206
+ }];
207
+ return mods;
208
+ }
209
+
210
+ /**
211
+ * These now all have the call object as an argument. Why? Well, to know which call a given event is
212
+ * about you have three options:
213
+ * 1. Use a closure as the callback that remembers what call it's listening to. This can be
214
+ * a pain because you need to pass the listener function again when you remove the listener,
215
+ * which might be somewhere else.
216
+ * 2. Use not-very-well-known fact that EventEmitter sets 'this' to the emitter object in the
217
+ * callback. This doesn't really play well with modern Typescript and eslint and doesn't work
218
+ * with our pattern of re-emitting events.
219
+ * 3. Pass the object in question as an argument to the callback.
220
+ *
221
+ * Now that we have group calls which have to deal with multiple call objects, this will
222
+ * become more important, and I think methods 1 and 2 are just going to cause issues.
223
+ */
224
+
225
+ // The key of the transceiver map (purpose + media type, separated by ':')
226
+
227
+ // generates keys for the map of transceivers
228
+ // kind is unfortunately a string rather than MediaType as this is the type of
229
+ // track.kind
230
+ function getTransceiverKey(purpose, kind) {
231
+ return purpose + ":" + kind;
232
+ }
233
+ export class BriijCall extends TypedEventEmitter {
234
+ /**
235
+ * Construct a new Matrix Call.
236
+ * @param opts - Config options.
237
+ */
238
+ constructor(opts) {
239
+ var _this, _opts$forceTURN;
240
+ super();
241
+ _this = this;
242
+ _defineProperty(this, "roomId", void 0);
243
+ _defineProperty(this, "callId", void 0);
244
+ _defineProperty(this, "invitee", void 0);
245
+ _defineProperty(this, "hangupParty", void 0);
246
+ _defineProperty(this, "hangupReason", void 0);
247
+ _defineProperty(this, "direction", void 0);
248
+ _defineProperty(this, "ourPartyId", void 0);
249
+ _defineProperty(this, "peerConn", void 0);
250
+ _defineProperty(this, "toDeviceSeq", 0);
251
+ // whether this call should have push-to-talk semantics
252
+ // This should be set by the consumer on incoming & outgoing calls.
253
+ _defineProperty(this, "isPtt", false);
254
+ _defineProperty(this, "_state", CallState.Fledgling);
255
+ _defineProperty(this, "client", void 0);
256
+ _defineProperty(this, "forceTURN", void 0);
257
+ _defineProperty(this, "turnServers", void 0);
258
+ // A queue for candidates waiting to go out.
259
+ // We try to amalgamate candidates into a single candidate message where
260
+ // possible
261
+ _defineProperty(this, "candidateSendQueue", []);
262
+ _defineProperty(this, "candidateSendTries", 0);
263
+ _defineProperty(this, "candidatesEnded", false);
264
+ _defineProperty(this, "feeds", []);
265
+ // our transceivers for each purpose and type of media
266
+ _defineProperty(this, "transceivers", new Map());
267
+ _defineProperty(this, "inviteOrAnswerSent", false);
268
+ _defineProperty(this, "waitForLocalAVStream", false);
269
+ _defineProperty(this, "successor", void 0);
270
+ _defineProperty(this, "opponentMember", void 0);
271
+ _defineProperty(this, "opponentVersion", void 0);
272
+ // The party ID of the other side: undefined if we haven't chosen a partner
273
+ // yet, null if we have but they didn't send a party ID.
274
+ _defineProperty(this, "opponentPartyId", void 0);
275
+ _defineProperty(this, "opponentCaps", void 0);
276
+ _defineProperty(this, "iceDisconnectedTimeout", void 0);
277
+ _defineProperty(this, "iceReconnectionTimeOut", void 0);
278
+ _defineProperty(this, "inviteTimeout", void 0);
279
+ _defineProperty(this, "removeTrackListeners", new Map());
280
+ // The logic of when & if a call is on hold is nontrivial and explained in is*OnHold
281
+ // This flag represents whether we want the other party to be on hold
282
+ _defineProperty(this, "remoteOnHold", false);
283
+ // the stats for the call at the point it ended. We can't get these after we
284
+ // tear the call down, so we just grab a snapshot before we stop the call.
285
+ // The typescript definitions have this type as 'any' :(
286
+ _defineProperty(this, "callStatsAtEnd", void 0);
287
+ // Perfect negotiation state: https://www.w3.org/TR/webrtc/#perfect-negotiation-example
288
+ _defineProperty(this, "makingOffer", false);
289
+ _defineProperty(this, "ignoreOffer", false);
290
+ _defineProperty(this, "isSettingRemoteAnswerPending", false);
291
+ _defineProperty(this, "responsePromiseChain", void 0);
292
+ // If candidates arrive before we've picked an opponent (which, in particular,
293
+ // will happen if the opponent sends candidates eagerly before the user answers
294
+ // the call) we buffer them up here so we can then add the ones from the party we pick
295
+ _defineProperty(this, "remoteCandidateBuffer", new Map());
296
+ _defineProperty(this, "remoteAssertedIdentity", void 0);
297
+ _defineProperty(this, "remoteSDPStreamMetadata", void 0);
298
+ _defineProperty(this, "callLengthInterval", void 0);
299
+ _defineProperty(this, "callStartTime", void 0);
300
+ _defineProperty(this, "opponentDeviceId", void 0);
301
+ _defineProperty(this, "hasOpponentDeviceInfo", void 0);
302
+ _defineProperty(this, "opponentSessionId", void 0);
303
+ _defineProperty(this, "groupCallId", void 0);
304
+ // Used to keep the timer for the delay before actually stopping our
305
+ // video track after muting (see setLocalVideoMuted)
306
+ _defineProperty(this, "stopVideoTrackTimer", void 0);
307
+ // Used to allow connection without Video and Audio. To establish a webrtc connection without media a Data channel is
308
+ // needed At the moment this property is true if we allow BriijClient with isVoipWithNoMediaAllowed = true
309
+ _defineProperty(this, "isOnlyDataChannelAllowed", void 0);
310
+ _defineProperty(this, "stats", void 0);
311
+ /**
312
+ * Internal
313
+ */
314
+ _defineProperty(this, "gotLocalIceCandidate", event => {
315
+ if (event.candidate) {
316
+ if (this.candidatesEnded) {
317
+ logger.warn("Call ".concat(this.callId, " gotLocalIceCandidate() got candidate after candidates have ended!"));
318
+ }
319
+ logger.debug("Call ".concat(this.callId, " got local ICE ").concat(event.candidate.sdpMid, " ").concat(event.candidate.candidate));
320
+ if (this.callHasEnded()) return;
321
+
322
+ // As with the offer, note we need to make a copy of this object, not
323
+ // pass the original: that broke in Chrome ~m43.
324
+ if (event.candidate.candidate === "") {
325
+ this.queueCandidate(null);
326
+ } else {
327
+ this.queueCandidate(event.candidate);
328
+ }
329
+ }
330
+ });
331
+ _defineProperty(this, "onIceGatheringStateChange", event => {
332
+ var _this$peerConn;
333
+ logger.debug("Call ".concat(this.callId, " onIceGatheringStateChange() ice gathering state changed to ").concat(this.peerConn.iceGatheringState));
334
+ if (((_this$peerConn = this.peerConn) === null || _this$peerConn === void 0 ? void 0 : _this$peerConn.iceGatheringState) === "complete") {
335
+ this.queueCandidate(null); // We should leave it to WebRTC to announce the end
336
+ logger.debug("Call ".concat(this.callId, " onIceGatheringStateChange() ice gathering state complete, set candidates have ended"));
337
+ }
338
+ });
339
+ _defineProperty(this, "getLocalOfferFailed", err => {
340
+ logger.error("Call ".concat(this.callId, " getLocalOfferFailed() running"), err);
341
+ this.emit(CallEvent.Error, new CallError(CallErrorCode.LocalOfferFailed, "Failed to get local offer!", err), this);
342
+ this.terminate(CallParty.Local, CallErrorCode.LocalOfferFailed, false);
343
+ });
344
+ _defineProperty(this, "getUserMediaFailed", err => {
345
+ if (this.successor) {
346
+ this.successor.getUserMediaFailed(err);
347
+ return;
348
+ }
349
+ logger.warn("Call ".concat(this.callId, " getUserMediaFailed() failed to get user media - ending call"), err);
350
+ this.emit(CallEvent.Error, new CallError(CallErrorCode.NoUserMedia, "Couldn't start capturing media! Is your microphone set up and does this app have permission?", err), this);
351
+ this.terminate(CallParty.Local, CallErrorCode.NoUserMedia, false);
352
+ });
353
+ _defineProperty(this, "placeCallFailed", err => {
354
+ if (this.successor) {
355
+ this.successor.placeCallFailed(err);
356
+ return;
357
+ }
358
+ logger.warn("Call ".concat(this.callId, " placeCallWithCallFeeds() failed - ending call"), err);
359
+ this.emit(CallEvent.Error, new CallError(CallErrorCode.IceFailed, "Couldn't start call! Invalid ICE server configuration.", err), this);
360
+ this.terminate(CallParty.Local, CallErrorCode.IceFailed, false);
361
+ });
362
+ _defineProperty(this, "onIceConnectionStateChanged", () => {
363
+ var _this$peerConn2, _this$peerConn3, _this$peerConn$iceCon, _this$peerConn4, _this$peerConn5, _this$peerConn8;
364
+ if (this.callHasEnded()) {
365
+ return; // because ICE can still complete as we're ending the call
366
+ }
367
+ logger.debug("Call ".concat(this.callId, " onIceConnectionStateChanged() running (state=").concat((_this$peerConn2 = this.peerConn) === null || _this$peerConn2 === void 0 ? void 0 : _this$peerConn2.iceConnectionState, ", conn=").concat((_this$peerConn3 = this.peerConn) === null || _this$peerConn3 === void 0 ? void 0 : _this$peerConn3.connectionState, ")"));
368
+
369
+ // ideally we'd consider the call to be connected when we get media but
370
+ // chrome doesn't implement any of the 'onstarted' events yet
371
+ if (["connected", "completed"].includes((_this$peerConn$iceCon = (_this$peerConn4 = this.peerConn) === null || _this$peerConn4 === void 0 ? void 0 : _this$peerConn4.iceConnectionState) !== null && _this$peerConn$iceCon !== void 0 ? _this$peerConn$iceCon : "")) {
372
+ clearTimeout(this.iceDisconnectedTimeout);
373
+ this.iceDisconnectedTimeout = undefined;
374
+ if (this.iceReconnectionTimeOut) {
375
+ clearTimeout(this.iceReconnectionTimeOut);
376
+ }
377
+ this.state = CallState.Connected;
378
+ if (!this.callLengthInterval && !this.callStartTime) {
379
+ this.callStartTime = Date.now();
380
+ this.callLengthInterval = setInterval(() => {
381
+ this.emit(CallEvent.LengthChanged, Math.round((Date.now() - this.callStartTime) / 1000), this);
382
+ }, CALL_LENGTH_INTERVAL);
383
+ }
384
+ } else if (((_this$peerConn5 = this.peerConn) === null || _this$peerConn5 === void 0 ? void 0 : _this$peerConn5.iceConnectionState) == "failed") {
385
+ var _this$peerConn6;
386
+ this.candidatesEnded = false;
387
+ // Firefox for Android does not yet have support for restartIce()
388
+ // (the types say it's always defined though, so we have to cast
389
+ // to prevent typescript from warning).
390
+ if ((_this$peerConn6 = this.peerConn) !== null && _this$peerConn6 !== void 0 && _this$peerConn6.restartIce) {
391
+ var _this$peerConn7;
392
+ this.candidatesEnded = false;
393
+ logger.debug("Call ".concat(this.callId, " onIceConnectionStateChanged() ice restart (state=").concat((_this$peerConn7 = this.peerConn) === null || _this$peerConn7 === void 0 ? void 0 : _this$peerConn7.iceConnectionState, ")"));
394
+ this.peerConn.restartIce();
395
+ } else {
396
+ logger.info("Call ".concat(this.callId, " onIceConnectionStateChanged() hanging up call (ICE failed and no ICE restart method)"));
397
+ this.hangup(CallErrorCode.IceFailed, false);
398
+ }
399
+ } else if (((_this$peerConn8 = this.peerConn) === null || _this$peerConn8 === void 0 ? void 0 : _this$peerConn8.iceConnectionState) == "disconnected") {
400
+ this.candidatesEnded = false;
401
+ this.iceReconnectionTimeOut = setTimeout(() => {
402
+ var _this$peerConn9, _this$peerConn0, _this$peerConn1;
403
+ logger.info("Call ".concat(this.callId, " onIceConnectionStateChanged() ICE restarting because of ICE disconnected, (state=").concat((_this$peerConn9 = this.peerConn) === null || _this$peerConn9 === void 0 ? void 0 : _this$peerConn9.iceConnectionState, ", conn=").concat((_this$peerConn0 = this.peerConn) === null || _this$peerConn0 === void 0 ? void 0 : _this$peerConn0.connectionState, ")"));
404
+ if ((_this$peerConn1 = this.peerConn) !== null && _this$peerConn1 !== void 0 && _this$peerConn1.restartIce) {
405
+ this.candidatesEnded = false;
406
+ this.peerConn.restartIce();
407
+ }
408
+ this.iceReconnectionTimeOut = undefined;
409
+ }, ICE_RECONNECTING_TIMEOUT);
410
+ this.iceDisconnectedTimeout = setTimeout(() => {
411
+ logger.info("Call ".concat(this.callId, " onIceConnectionStateChanged() hanging up call (ICE disconnected for too long)"));
412
+ this.hangup(CallErrorCode.IceFailed, false);
413
+ }, ICE_DISCONNECTED_TIMEOUT);
414
+ this.state = CallState.Connecting;
415
+ }
416
+
417
+ // In PTT mode, override feed status to muted when we lose connection to
418
+ // the peer, since we don't want to block the line if they're not saying anything.
419
+ // Experimenting in Chrome, this happens after 5 or 6 seconds, which is probably
420
+ // fast enough.
421
+ if (this.isPtt && ["failed", "disconnected"].includes(this.peerConn.iceConnectionState)) {
422
+ for (var feed of this.getRemoteFeeds()) {
423
+ feed.setAudioVideoMuted(true, true);
424
+ }
425
+ }
426
+ });
427
+ _defineProperty(this, "onSignallingStateChanged", () => {
428
+ var _this$peerConn10;
429
+ logger.debug("Call ".concat(this.callId, " onSignallingStateChanged() running (state=").concat((_this$peerConn10 = this.peerConn) === null || _this$peerConn10 === void 0 ? void 0 : _this$peerConn10.signalingState, ")"));
430
+ });
431
+ _defineProperty(this, "onTrack", ev => {
432
+ if (ev.streams.length === 0) {
433
+ logger.warn("Call ".concat(this.callId, " onTrack() called with streamless track streamless (kind=").concat(ev.track.kind, ")"));
434
+ return;
435
+ }
436
+ var stream = ev.streams[0];
437
+ this.pushRemoteFeed(stream);
438
+ if (!this.removeTrackListeners.has(stream)) {
439
+ var onRemoveTrack = () => {
440
+ if (stream.getTracks().length === 0) {
441
+ logger.info("Call ".concat(this.callId, " onTrack() removing track (streamId=").concat(stream.id, ")"));
442
+ this.deleteFeedByStream(stream);
443
+ stream.removeEventListener("removetrack", onRemoveTrack);
444
+ this.removeTrackListeners.delete(stream);
445
+ }
446
+ };
447
+ stream.addEventListener("removetrack", onRemoveTrack);
448
+ this.removeTrackListeners.set(stream, onRemoveTrack);
449
+ }
450
+ });
451
+ _defineProperty(this, "onDataChannel", ev => {
452
+ this.emit(CallEvent.DataChannel, ev.channel, this);
453
+ });
454
+ _defineProperty(this, "onNegotiationNeeded", /*#__PURE__*/_asyncToGenerator(function* () {
455
+ logger.info("Call ".concat(_this.callId, " onNegotiationNeeded() negotiation is needed!"));
456
+ if (_this.state !== CallState.CreateOffer && _this.opponentVersion === 0) {
457
+ logger.info("Call ".concat(_this.callId, " onNegotiationNeeded() opponent does not support renegotiation: ignoring negotiationneeded event"));
458
+ return;
459
+ }
460
+ _this.queueGotLocalOffer();
461
+ }));
462
+ _defineProperty(this, "onHangupReceived", msg => {
463
+ logger.debug("Call ".concat(this.callId, " onHangupReceived() running"));
464
+
465
+ // party ID must match (our chosen partner hanging up the call) or be undefined (we haven't chosen
466
+ // a partner yet but we're treating the hangup as a reject as per VoIP v0)
467
+ if (this.partyIdMatches(msg) || this.state === CallState.Ringing) {
468
+ // default reason is user_hangup
469
+ this.terminate(CallParty.Remote, msg.reason || CallErrorCode.UserHangup, true);
470
+ } else {
471
+ logger.info("Call ".concat(this.callId, " onHangupReceived() ignoring message from party ID ").concat(msg.party_id, ": our partner is ").concat(this.opponentPartyId));
472
+ }
473
+ });
474
+ _defineProperty(this, "onRejectReceived", msg => {
475
+ logger.debug("Call ".concat(this.callId, " onRejectReceived() running"));
476
+
477
+ // No need to check party_id for reject because if we'd received either
478
+ // an answer or reject, we wouldn't be in state InviteSent
479
+
480
+ var shouldTerminate =
481
+ // reject events also end the call if it's ringing: it's another of
482
+ // our devices rejecting the call.
483
+ [CallState.InviteSent, CallState.Ringing].includes(this.state) ||
484
+ // also if we're in the init state and it's an inbound call, since
485
+ // this means we just haven't entered the ringing state yet
486
+ this.state === CallState.Fledgling && this.direction === CallDirection.Inbound;
487
+ if (shouldTerminate) {
488
+ this.terminate(CallParty.Remote, msg.reason || CallErrorCode.UserHangup, true);
489
+ } else {
490
+ logger.debug("Call ".concat(this.callId, " onRejectReceived() called in wrong state (state=").concat(this.state, ")"));
491
+ }
492
+ });
493
+ _defineProperty(this, "onAnsweredElsewhere", msg => {
494
+ logger.debug("Call ".concat(this.callId, " onAnsweredElsewhere() running"));
495
+ this.terminate(CallParty.Remote, CallErrorCode.AnsweredElsewhere, true);
496
+ });
497
+ this.roomId = opts.roomId;
498
+ this.invitee = opts.invitee;
499
+ this.client = opts.client;
500
+ if (!this.client.deviceId) throw new Error("Client must have a device ID to start calls");
501
+ this.forceTURN = (_opts$forceTURN = opts.forceTURN) !== null && _opts$forceTURN !== void 0 ? _opts$forceTURN : false;
502
+ this.ourPartyId = this.client.deviceId;
503
+ this.opponentDeviceId = opts.opponentDeviceId;
504
+ this.opponentSessionId = opts.opponentSessionId;
505
+ this.groupCallId = opts.groupCallId;
506
+ // Array of Objects with urls, username, credential keys
507
+ this.turnServers = opts.turnServers || [];
508
+ if (this.turnServers.length === 0 && this.client.isFallbackICEServerAllowed()) {
509
+ this.turnServers.push({
510
+ urls: [FALLBACK_ICE_SERVER]
511
+ });
512
+ }
513
+ for (var server of this.turnServers) {
514
+ checkObjectHasKeys(server, ["urls"]);
515
+ }
516
+ this.callId = genCallID();
517
+ // If the Client provides calls without audio and video we need a datachannel for a webrtc connection
518
+ this.isOnlyDataChannelAllowed = this.client.isVoipWithNoMediaAllowed;
519
+ }
520
+
521
+ /**
522
+ * Place a voice call to this room.
523
+ * @throws If you have not specified a listener for 'error' events.
524
+ */
525
+ placeVoiceCall() {
526
+ var _this2 = this;
527
+ return _asyncToGenerator(function* () {
528
+ yield _this2.placeCall(true, false);
529
+ })();
530
+ }
531
+
532
+ /**
533
+ * Place a video call to this room.
534
+ * @throws If you have not specified a listener for 'error' events.
535
+ */
536
+ placeVideoCall() {
537
+ var _this3 = this;
538
+ return _asyncToGenerator(function* () {
539
+ yield _this3.placeCall(true, true);
540
+ })();
541
+ }
542
+
543
+ /**
544
+ * Create a datachannel using this call's peer connection.
545
+ * @param label - A human readable label for this datachannel
546
+ * @param options - An object providing configuration options for the data channel.
547
+ */
548
+ createDataChannel(label, options) {
549
+ var dataChannel = this.peerConn.createDataChannel(label, options);
550
+ this.emit(CallEvent.DataChannel, dataChannel, this);
551
+ return dataChannel;
552
+ }
553
+ getOpponentMember() {
554
+ return this.opponentMember;
555
+ }
556
+ getOpponentDeviceId() {
557
+ return this.opponentDeviceId;
558
+ }
559
+ getOpponentSessionId() {
560
+ return this.opponentSessionId;
561
+ }
562
+ opponentCanBeTransferred() {
563
+ return Boolean(this.opponentCaps && this.opponentCaps["m.call.transferee"]);
564
+ }
565
+ opponentSupportsDTMF() {
566
+ return Boolean(this.opponentCaps && this.opponentCaps["m.call.dtmf"]);
567
+ }
568
+ getRemoteAssertedIdentity() {
569
+ return this.remoteAssertedIdentity;
570
+ }
571
+ get state() {
572
+ return this._state;
573
+ }
574
+ set state(state) {
575
+ var oldState = this._state;
576
+ this._state = state;
577
+ this.emit(CallEvent.State, state, oldState, this);
578
+ }
579
+ get type() {
580
+ // we may want to look for a video receiver here rather than a track to match the
581
+ // sender behaviour, although in practice they should be the same thing
582
+ return this.hasUserMediaVideoSender || this.hasRemoteUserMediaVideoTrack ? CallType.Video : CallType.Voice;
583
+ }
584
+ get hasLocalUserMediaVideoTrack() {
585
+ var _this$localUsermediaS;
586
+ return !!((_this$localUsermediaS = this.localUsermediaStream) !== null && _this$localUsermediaS !== void 0 && _this$localUsermediaS.getVideoTracks().length);
587
+ }
588
+ get hasRemoteUserMediaVideoTrack() {
589
+ return this.getRemoteFeeds().some(feed => {
590
+ var _feed$stream;
591
+ return feed.purpose === SDPStreamMetadataPurpose.Usermedia && ((_feed$stream = feed.stream) === null || _feed$stream === void 0 ? void 0 : _feed$stream.getVideoTracks().length);
592
+ });
593
+ }
594
+ get hasLocalUserMediaAudioTrack() {
595
+ var _this$localUsermediaS2;
596
+ return !!((_this$localUsermediaS2 = this.localUsermediaStream) !== null && _this$localUsermediaS2 !== void 0 && _this$localUsermediaS2.getAudioTracks().length);
597
+ }
598
+ get hasRemoteUserMediaAudioTrack() {
599
+ return this.getRemoteFeeds().some(feed => {
600
+ var _feed$stream2;
601
+ return feed.purpose === SDPStreamMetadataPurpose.Usermedia && !!((_feed$stream2 = feed.stream) !== null && _feed$stream2 !== void 0 && _feed$stream2.getAudioTracks().length);
602
+ });
603
+ }
604
+ get hasUserMediaAudioSender() {
605
+ var _this$transceivers$ge;
606
+ return Boolean((_this$transceivers$ge = this.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "audio"))) === null || _this$transceivers$ge === void 0 ? void 0 : _this$transceivers$ge.sender);
607
+ }
608
+ get hasUserMediaVideoSender() {
609
+ var _this$transceivers$ge2;
610
+ return Boolean((_this$transceivers$ge2 = this.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "video"))) === null || _this$transceivers$ge2 === void 0 ? void 0 : _this$transceivers$ge2.sender);
611
+ }
612
+ get localUsermediaFeed() {
613
+ return this.getLocalFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
614
+ }
615
+ get localScreensharingFeed() {
616
+ return this.getLocalFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Screenshare);
617
+ }
618
+ get localUsermediaStream() {
619
+ var _this$localUsermediaF;
620
+ return (_this$localUsermediaF = this.localUsermediaFeed) === null || _this$localUsermediaF === void 0 ? void 0 : _this$localUsermediaF.stream;
621
+ }
622
+ get localScreensharingStream() {
623
+ var _this$localScreenshar;
624
+ return (_this$localScreenshar = this.localScreensharingFeed) === null || _this$localScreenshar === void 0 ? void 0 : _this$localScreenshar.stream;
625
+ }
626
+ get remoteUsermediaFeed() {
627
+ return this.getRemoteFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
628
+ }
629
+ get remoteScreensharingFeed() {
630
+ return this.getRemoteFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Screenshare);
631
+ }
632
+ get remoteUsermediaStream() {
633
+ var _this$remoteUsermedia;
634
+ return (_this$remoteUsermedia = this.remoteUsermediaFeed) === null || _this$remoteUsermedia === void 0 ? void 0 : _this$remoteUsermedia.stream;
635
+ }
636
+ get remoteScreensharingStream() {
637
+ var _this$remoteScreensha;
638
+ return (_this$remoteScreensha = this.remoteScreensharingFeed) === null || _this$remoteScreensha === void 0 ? void 0 : _this$remoteScreensha.stream;
639
+ }
640
+ getFeedByStreamId(streamId) {
641
+ return this.getFeeds().find(feed => feed.stream.id === streamId);
642
+ }
643
+
644
+ /**
645
+ * Returns an array of all CallFeeds
646
+ * @returns CallFeeds
647
+ */
648
+ getFeeds() {
649
+ return this.feeds;
650
+ }
651
+
652
+ /**
653
+ * Returns an array of all local CallFeeds
654
+ * @returns local CallFeeds
655
+ */
656
+ getLocalFeeds() {
657
+ return this.feeds.filter(feed => feed.isLocal());
658
+ }
659
+
660
+ /**
661
+ * Returns an array of all remote CallFeeds
662
+ * @returns remote CallFeeds
663
+ */
664
+ getRemoteFeeds() {
665
+ return this.feeds.filter(feed => !feed.isLocal());
666
+ }
667
+ initOpponentCrypto() {
668
+ var _this4 = this;
669
+ return _asyncToGenerator(function* () {
670
+ var _this4$getOpponentMem;
671
+ if (!_this4.opponentDeviceId) return;
672
+ if (!_this4.client.getUseE2eForGroupCall()) return;
673
+ // It's possible to want E2EE and yet not have the means to manage E2EE
674
+ // ourselves (for example if the client is a RoomWidgetClient)
675
+ if (!_this4.client.getCrypto()) {
676
+ // All we know is the device ID
677
+ _this4.hasOpponentDeviceInfo = true;
678
+ return;
679
+ }
680
+ var userId = _this4.invitee || ((_this4$getOpponentMem = _this4.getOpponentMember()) === null || _this4$getOpponentMem === void 0 ? void 0 : _this4$getOpponentMem.userId);
681
+ if (!userId) throw new Error("Couldn't find opponent user ID to init crypto");
682
+
683
+ // Here we were calling `BriijClient.crypto.deviceList.downloadKeys` which is not supported by the rust cryptography.
684
+ _this4.hasOpponentDeviceInfo = false;
685
+ throw new GroupCallUnknownDeviceError(userId);
686
+ })();
687
+ }
688
+
689
+ /**
690
+ * Generates and returns localSDPStreamMetadata
691
+ * @returns localSDPStreamMetadata
692
+ */
693
+ getLocalSDPStreamMetadata() {
694
+ var updateStreamIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
695
+ var metadata = {};
696
+ for (var localFeed of this.getLocalFeeds()) {
697
+ if (updateStreamIds) {
698
+ localFeed.sdpMetadataStreamId = localFeed.stream.id;
699
+ }
700
+ metadata[localFeed.sdpMetadataStreamId] = {
701
+ purpose: localFeed.purpose,
702
+ audio_muted: localFeed.isAudioMuted(),
703
+ video_muted: localFeed.isVideoMuted()
704
+ };
705
+ }
706
+ return metadata;
707
+ }
708
+
709
+ /**
710
+ * Returns true if there are no incoming feeds,
711
+ * otherwise returns false
712
+ * @returns no incoming feeds
713
+ */
714
+ noIncomingFeeds() {
715
+ return !this.feeds.some(feed => !feed.isLocal());
716
+ }
717
+ pushRemoteFeed(stream) {
718
+ // Fallback to old behavior if the other side doesn't support SDPStreamMetadata
719
+ if (!this.opponentSupportsSDPStreamMetadata()) {
720
+ this.pushRemoteFeedWithoutMetadata(stream);
721
+ return;
722
+ }
723
+ var userId = this.getOpponentMember().userId;
724
+ var purpose = this.remoteSDPStreamMetadata[stream.id].purpose;
725
+ var audioMuted = this.remoteSDPStreamMetadata[stream.id].audio_muted;
726
+ var videoMuted = this.remoteSDPStreamMetadata[stream.id].video_muted;
727
+ if (!purpose) {
728
+ logger.warn("Call ".concat(this.callId, " pushRemoteFeed() ignoring stream because we didn't get any metadata about it (streamId=").concat(stream.id, ")"));
729
+ return;
730
+ }
731
+ if (this.getFeedByStreamId(stream.id)) {
732
+ logger.warn("Call ".concat(this.callId, " pushRemoteFeed() ignoring stream because we already have a feed for it (streamId=").concat(stream.id, ")"));
733
+ return;
734
+ }
735
+ this.feeds.push(new CallFeed({
736
+ client: this.client,
737
+ call: this,
738
+ roomId: this.roomId,
739
+ userId,
740
+ deviceId: this.getOpponentDeviceId(),
741
+ stream,
742
+ purpose,
743
+ audioMuted,
744
+ videoMuted
745
+ }));
746
+ this.emit(CallEvent.FeedsChanged, this.feeds, this);
747
+ logger.info("Call ".concat(this.callId, " pushRemoteFeed() pushed stream (streamId=").concat(stream.id, ", active=").concat(stream.active, ", purpose=").concat(purpose, ")"));
748
+ }
749
+
750
+ /**
751
+ * This method is used ONLY if the other client doesn't support sending SDPStreamMetadata
752
+ */
753
+ pushRemoteFeedWithoutMetadata(stream) {
754
+ var _this$feeds$find;
755
+ var userId = this.getOpponentMember().userId;
756
+ // We can guess the purpose here since the other client can only send one stream
757
+ var purpose = SDPStreamMetadataPurpose.Usermedia;
758
+ var oldRemoteStream = (_this$feeds$find = this.feeds.find(feed => !feed.isLocal())) === null || _this$feeds$find === void 0 ? void 0 : _this$feeds$find.stream;
759
+
760
+ // Note that we check by ID and always set the remote stream: Chrome appears
761
+ // to make new stream objects when transceiver directionality is changed and the 'active'
762
+ // status of streams change - Dave
763
+ // If we already have a stream, check this stream has the same id
764
+ if (oldRemoteStream && stream.id !== oldRemoteStream.id) {
765
+ logger.warn("Call ".concat(this.callId, " pushRemoteFeedWithoutMetadata() ignoring new stream because we already have stream (streamId=").concat(stream.id, ")"));
766
+ return;
767
+ }
768
+ if (this.getFeedByStreamId(stream.id)) {
769
+ logger.warn("Call ".concat(this.callId, " pushRemoteFeedWithoutMetadata() ignoring stream because we already have a feed for it (streamId=").concat(stream.id, ")"));
770
+ return;
771
+ }
772
+ this.feeds.push(new CallFeed({
773
+ client: this.client,
774
+ call: this,
775
+ roomId: this.roomId,
776
+ audioMuted: false,
777
+ videoMuted: false,
778
+ userId,
779
+ deviceId: this.getOpponentDeviceId(),
780
+ stream,
781
+ purpose
782
+ }));
783
+ this.emit(CallEvent.FeedsChanged, this.feeds, this);
784
+ logger.info("Call ".concat(this.callId, " pushRemoteFeedWithoutMetadata() pushed stream (streamId=").concat(stream.id, ", active=").concat(stream.active, ")"));
785
+ }
786
+ pushNewLocalFeed(stream, purpose) {
787
+ var addToPeerConnection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
788
+ var userId = this.client.getUserId();
789
+
790
+ // Tracks don't always start off enabled, eg. chrome will give a disabled
791
+ // audio track if you ask for user media audio and already had one that
792
+ // you'd set to disabled (presumably because it clones them internally).
793
+ setTracksEnabled(stream.getAudioTracks(), true);
794
+ setTracksEnabled(stream.getVideoTracks(), true);
795
+ if (this.getFeedByStreamId(stream.id)) {
796
+ logger.warn("Call ".concat(this.callId, " pushNewLocalFeed() ignoring stream because we already have a feed for it (streamId=").concat(stream.id, ")"));
797
+ return;
798
+ }
799
+ this.pushLocalFeed(new CallFeed({
800
+ client: this.client,
801
+ roomId: this.roomId,
802
+ audioMuted: false,
803
+ videoMuted: false,
804
+ userId,
805
+ deviceId: this.getOpponentDeviceId(),
806
+ stream,
807
+ purpose
808
+ }), addToPeerConnection);
809
+ }
810
+
811
+ /**
812
+ * Pushes supplied feed to the call
813
+ * @param callFeed - to push
814
+ * @param addToPeerConnection - whether to add the tracks to the peer connection
815
+ */
816
+ pushLocalFeed(callFeed) {
817
+ var _this5 = this;
818
+ var addToPeerConnection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
819
+ if (this.feeds.some(feed => callFeed.stream.id === feed.stream.id)) {
820
+ logger.info("Call ".concat(this.callId, " pushLocalFeed() ignoring duplicate local stream (streamId=").concat(callFeed.stream.id, ")"));
821
+ return;
822
+ }
823
+ this.feeds.push(callFeed);
824
+ if (addToPeerConnection) {
825
+ var _loop = function _loop() {
826
+ logger.info("Call ".concat(_this5.callId, " pushLocalFeed() adding track to peer connection (id=").concat(track.id, ", kind=").concat(track.kind, ", streamId=").concat(callFeed.stream.id, ", streamPurpose=").concat(callFeed.purpose, ", enabled=").concat(track.enabled, ")"));
827
+ var tKey = getTransceiverKey(callFeed.purpose, track.kind);
828
+ if (_this5.transceivers.has(tKey)) {
829
+ // we already have a sender, so we re-use it. We try to re-use transceivers as much
830
+ // as possible because they can't be removed once added, so otherwise they just
831
+ // accumulate which makes the SDP very large very quickly: in fact it only takes
832
+ // about 6 video tracks to exceed the maximum size of an Olm-encrypted
833
+ // Matrix event.
834
+ var transceiver = _this5.transceivers.get(tKey);
835
+ transceiver.sender.replaceTrack(track);
836
+ // set the direction to indicate we're going to start sending again
837
+ // (this will trigger the re-negotiation)
838
+ transceiver.direction = transceiver.direction === "inactive" ? "sendonly" : "sendrecv";
839
+ } else {
840
+ // create a new one. We need to use addTrack rather addTransceiver for this because firefox
841
+ // doesn't yet implement RTCRTPSender.setStreams()
842
+ // (https://bugzilla.mozilla.org/show_bug.cgi?id=1510802) so we'd have no way to group the
843
+ // two tracks together into a stream.
844
+ var newSender = _this5.peerConn.addTrack(track, callFeed.stream);
845
+
846
+ // now go & fish for the new transceiver
847
+ var newTransceiver = _this5.peerConn.getTransceivers().find(t => t.sender === newSender);
848
+ if (newTransceiver) {
849
+ _this5.transceivers.set(tKey, newTransceiver);
850
+ } else {
851
+ logger.warn("Call ".concat(_this5.callId, " pushLocalFeed() didn't find a matching transceiver after adding track!"));
852
+ }
853
+ }
854
+ };
855
+ for (var track of callFeed.stream.getTracks()) {
856
+ _loop();
857
+ }
858
+ }
859
+ logger.info("Call ".concat(this.callId, " pushLocalFeed() pushed stream (id=").concat(callFeed.stream.id, ", active=").concat(callFeed.stream.active, ", purpose=").concat(callFeed.purpose, ")"));
860
+ this.emit(CallEvent.FeedsChanged, this.feeds, this);
861
+ }
862
+
863
+ /**
864
+ * Removes local call feed from the call and its tracks from the peer
865
+ * connection
866
+ * @param callFeed - to remove
867
+ */
868
+ removeLocalFeed(callFeed) {
869
+ var audioTransceiverKey = getTransceiverKey(callFeed.purpose, "audio");
870
+ var videoTransceiverKey = getTransceiverKey(callFeed.purpose, "video");
871
+ for (var transceiverKey of [audioTransceiverKey, videoTransceiverKey]) {
872
+ // this is slightly mixing the track and transceiver API but is basically just shorthand.
873
+ // There is no way to actually remove a transceiver, so this just sets it to inactive
874
+ // (or recvonly) and replaces the source with nothing.
875
+ if (this.transceivers.has(transceiverKey)) {
876
+ var transceiver = this.transceivers.get(transceiverKey);
877
+ if (transceiver.sender) this.peerConn.removeTrack(transceiver.sender);
878
+ }
879
+ }
880
+ if (callFeed.purpose === SDPStreamMetadataPurpose.Screenshare) {
881
+ this.client.getMediaHandler().stopScreensharingStream(callFeed.stream);
882
+ }
883
+ this.deleteFeed(callFeed);
884
+ }
885
+ deleteAllFeeds() {
886
+ for (var feed of this.feeds) {
887
+ if (!feed.isLocal() || !this.groupCallId) {
888
+ feed.dispose();
889
+ }
890
+ }
891
+ this.feeds = [];
892
+ this.emit(CallEvent.FeedsChanged, this.feeds, this);
893
+ }
894
+ deleteFeedByStream(stream) {
895
+ var feed = this.getFeedByStreamId(stream.id);
896
+ if (!feed) {
897
+ logger.warn("Call ".concat(this.callId, " deleteFeedByStream() didn't find the feed to delete (streamId=").concat(stream.id, ")"));
898
+ return;
899
+ }
900
+ this.deleteFeed(feed);
901
+ }
902
+ deleteFeed(feed) {
903
+ feed.dispose();
904
+ this.feeds.splice(this.feeds.indexOf(feed), 1);
905
+ this.emit(CallEvent.FeedsChanged, this.feeds, this);
906
+ }
907
+
908
+ // The typescript definitions have this type as 'any' :(
909
+ getCurrentCallStats() {
910
+ var _this6 = this;
911
+ return _asyncToGenerator(function* () {
912
+ if (_this6.callHasEnded()) {
913
+ return _this6.callStatsAtEnd;
914
+ }
915
+ return _this6.collectCallStats();
916
+ })();
917
+ }
918
+ collectCallStats() {
919
+ var _this7 = this;
920
+ return _asyncToGenerator(function* () {
921
+ // This happens when the call fails before it starts.
922
+ // For example when we fail to get capture sources
923
+ if (!_this7.peerConn) return;
924
+ var statsReport = yield _this7.peerConn.getStats();
925
+ var stats = [];
926
+ statsReport.forEach(item => {
927
+ stats.push(item);
928
+ });
929
+ return stats;
930
+ })();
931
+ }
932
+
933
+ /**
934
+ * Configure this call from an invite event. Used by BriijClient.
935
+ * @param event - The m.call.invite event
936
+ */
937
+ initWithInvite(event) {
938
+ var _this8 = this;
939
+ return _asyncToGenerator(function* () {
940
+ var _this8$feeds$find;
941
+ var invite = event.getContent();
942
+ _this8.direction = CallDirection.Inbound;
943
+
944
+ // make sure we have valid turn creds. Unless something's gone wrong, it should
945
+ // poll and keep the credentials valid so this should be instant.
946
+ var haveTurnCreds = yield _this8.client.checkTurnServers();
947
+ if (!haveTurnCreds) {
948
+ logger.warn("Call ".concat(_this8.callId, " initWithInvite() failed to get TURN credentials! Proceeding with call anyway..."));
949
+ }
950
+ var sdpStreamMetadata = SDPStreamMetadataKey.findIn(invite);
951
+ if (sdpStreamMetadata) {
952
+ _this8.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
953
+ } else {
954
+ logger.debug("Call ".concat(_this8.callId, " initWithInvite() did not get any SDPStreamMetadata! Can not send/receive multiple streams"));
955
+ }
956
+ _this8.peerConn = _this8.createPeerConnection();
957
+ _this8.emit(CallEvent.PeerConnectionCreated, _this8.peerConn, _this8);
958
+ // we must set the party ID before await-ing on anything: the call event
959
+ // handler will start giving us more call events (eg. candidates) so if
960
+ // we haven't set the party ID, we'll ignore them.
961
+ _this8.chooseOpponent(event);
962
+ yield _this8.initOpponentCrypto();
963
+ try {
964
+ yield _this8.peerConn.setRemoteDescription(invite.offer);
965
+ logger.debug("Call ".concat(_this8.callId, " initWithInvite() set remote description: ").concat(invite.offer.type));
966
+ yield _this8.addBufferedIceCandidates();
967
+ } catch (e) {
968
+ logger.debug("Call ".concat(_this8.callId, " initWithInvite() failed to set remote description"), e);
969
+ _this8.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
970
+ return;
971
+ }
972
+ var remoteStream = (_this8$feeds$find = _this8.feeds.find(feed => !feed.isLocal())) === null || _this8$feeds$find === void 0 ? void 0 : _this8$feeds$find.stream;
973
+
974
+ // According to previous comments in this file, firefox at some point did not
975
+ // add streams until media started arriving on them. Testing latest firefox
976
+ // (81 at time of writing), this is no longer a problem, so let's do it the correct way.
977
+ //
978
+ // For example in case of no media webrtc connections like screen share only call we have to allow webrtc
979
+ // connections without remote media. In this case we always use a data channel. At the moment we allow as well
980
+ // only data channel as media in the WebRTC connection with this setup here.
981
+ if (!_this8.isOnlyDataChannelAllowed && (!remoteStream || remoteStream.getTracks().length === 0)) {
982
+ logger.error("Call ".concat(_this8.callId, " initWithInvite() no remote stream or no tracks after setting remote description!"));
983
+ _this8.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
984
+ return;
985
+ }
986
+ _this8.state = CallState.Ringing;
987
+ if (event.getLocalAge()) {
988
+ // Time out the call if it's ringing for too long
989
+ var ringingTimer = setTimeout(() => {
990
+ if (_this8.state == CallState.Ringing) {
991
+ var _this8$stats;
992
+ logger.debug("Call ".concat(_this8.callId, " initWithInvite() invite has expired. Hanging up."));
993
+ _this8.hangupParty = CallParty.Remote; // effectively
994
+ _this8.state = CallState.Ended;
995
+ _this8.stopAllMedia();
996
+ if (_this8.peerConn.signalingState != "closed") {
997
+ _this8.peerConn.close();
998
+ }
999
+ (_this8$stats = _this8.stats) === null || _this8$stats === void 0 || _this8$stats.removeStatsReportGatherer(_this8.callId);
1000
+ _this8.emit(CallEvent.Hangup, _this8);
1001
+ }
1002
+ }, invite.lifetime - event.getLocalAge());
1003
+ var onState = state => {
1004
+ if (state !== CallState.Ringing) {
1005
+ clearTimeout(ringingTimer);
1006
+ _this8.off(CallEvent.State, onState);
1007
+ }
1008
+ };
1009
+ _this8.on(CallEvent.State, onState);
1010
+ }
1011
+ })();
1012
+ }
1013
+
1014
+ /**
1015
+ * Configure this call from a hangup or reject event. Used by BriijClient.
1016
+ * @param event - The m.call.hangup event
1017
+ */
1018
+ initWithHangup(event) {
1019
+ // perverse as it may seem, sometimes we want to instantiate a call with a
1020
+ // hangup message (because when getting the state of the room on load, events
1021
+ // come in reverse order and we want to remember that a call has been hung up)
1022
+ this.state = CallState.Ended;
1023
+ }
1024
+ shouldAnswerWithMediaType(wantedValue, valueOfTheOtherSide, type) {
1025
+ if (wantedValue && !valueOfTheOtherSide) {
1026
+ // TODO: Figure out how to do this
1027
+ logger.warn("Call ".concat(this.callId, " shouldAnswerWithMediaType() unable to answer with ").concat(type, " because the other side isn't sending it either."));
1028
+ return false;
1029
+ } else if (!isNullOrUndefined(wantedValue) && wantedValue !== valueOfTheOtherSide && !this.opponentSupportsSDPStreamMetadata()) {
1030
+ logger.warn("Call ".concat(this.callId, " shouldAnswerWithMediaType() unable to answer with ").concat(type, "=").concat(wantedValue, " because the other side doesn't support it. Answering with ").concat(type, "=").concat(valueOfTheOtherSide, "."));
1031
+ return valueOfTheOtherSide;
1032
+ }
1033
+ return wantedValue !== null && wantedValue !== void 0 ? wantedValue : valueOfTheOtherSide;
1034
+ }
1035
+
1036
+ /**
1037
+ * Answer a call.
1038
+ */
1039
+ answer(audio, video) {
1040
+ var _this9 = this;
1041
+ return _asyncToGenerator(function* () {
1042
+ if (_this9.inviteOrAnswerSent) return;
1043
+ // TODO: Figure out how to do this
1044
+ if (audio === false && video === false) throw new Error("You CANNOT answer a call without media");
1045
+ if (!_this9.localUsermediaStream && !_this9.waitForLocalAVStream) {
1046
+ var prevState = _this9.state;
1047
+ var answerWithAudio = _this9.shouldAnswerWithMediaType(audio, _this9.hasRemoteUserMediaAudioTrack, "audio");
1048
+ var answerWithVideo = _this9.shouldAnswerWithMediaType(video, _this9.hasRemoteUserMediaVideoTrack, "video");
1049
+ _this9.state = CallState.WaitLocalMedia;
1050
+ _this9.waitForLocalAVStream = true;
1051
+ try {
1052
+ var _this9$client$getDevi;
1053
+ var stream = yield _this9.client.getMediaHandler().getUserMediaStream(answerWithAudio, answerWithVideo);
1054
+ _this9.waitForLocalAVStream = false;
1055
+ var usermediaFeed = new CallFeed({
1056
+ client: _this9.client,
1057
+ roomId: _this9.roomId,
1058
+ userId: _this9.client.getUserId(),
1059
+ deviceId: (_this9$client$getDevi = _this9.client.getDeviceId()) !== null && _this9$client$getDevi !== void 0 ? _this9$client$getDevi : undefined,
1060
+ stream,
1061
+ purpose: SDPStreamMetadataPurpose.Usermedia,
1062
+ audioMuted: false,
1063
+ videoMuted: false
1064
+ });
1065
+ var feeds = [usermediaFeed];
1066
+ if (_this9.localScreensharingFeed) {
1067
+ feeds.push(_this9.localScreensharingFeed);
1068
+ }
1069
+ _this9.answerWithCallFeeds(feeds);
1070
+ } catch (e) {
1071
+ if (answerWithVideo) {
1072
+ // Try to answer without video
1073
+ logger.warn("Call ".concat(_this9.callId, " answer() failed to getUserMedia(), trying to getUserMedia() without video"));
1074
+ _this9.state = prevState;
1075
+ _this9.waitForLocalAVStream = false;
1076
+ yield _this9.answer(answerWithAudio, false);
1077
+ } else {
1078
+ _this9.getUserMediaFailed(e);
1079
+ return;
1080
+ }
1081
+ }
1082
+ } else if (_this9.waitForLocalAVStream) {
1083
+ _this9.state = CallState.WaitLocalMedia;
1084
+ }
1085
+ })();
1086
+ }
1087
+ answerWithCallFeeds(callFeeds) {
1088
+ if (this.inviteOrAnswerSent) return;
1089
+ this.queueGotCallFeedsForAnswer(callFeeds);
1090
+ }
1091
+
1092
+ /**
1093
+ * Replace this call with a new call, e.g. for glare resolution. Used by
1094
+ * BriijClient.
1095
+ * @param newCall - The new call.
1096
+ */
1097
+ replacedBy(newCall) {
1098
+ logger.debug("Call ".concat(this.callId, " replacedBy() running (newCallId=").concat(newCall.callId, ")"));
1099
+ if (this.state === CallState.WaitLocalMedia) {
1100
+ logger.debug("Call ".concat(this.callId, " replacedBy() telling new call to wait for local media (newCallId=").concat(newCall.callId, ")"));
1101
+ newCall.waitForLocalAVStream = true;
1102
+ } else if ([CallState.CreateOffer, CallState.InviteSent].includes(this.state)) {
1103
+ if (newCall.direction === CallDirection.Outbound) {
1104
+ newCall.queueGotCallFeedsForAnswer([]);
1105
+ } else {
1106
+ logger.debug("Call ".concat(this.callId, " replacedBy() handing local stream to new call(newCallId=").concat(newCall.callId, ")"));
1107
+ newCall.queueGotCallFeedsForAnswer(this.getLocalFeeds().map(feed => feed.clone()));
1108
+ }
1109
+ }
1110
+ this.successor = newCall;
1111
+ this.emit(CallEvent.Replaced, newCall, this);
1112
+ this.hangup(CallErrorCode.Replaced, true);
1113
+ }
1114
+
1115
+ /**
1116
+ * Hangup a call.
1117
+ * @param reason - The reason why the call is being hung up.
1118
+ * @param suppressEvent - True to suppress emitting an event.
1119
+ */
1120
+ hangup(reason, suppressEvent) {
1121
+ if (this.callHasEnded()) return;
1122
+ logger.debug("Call ".concat(this.callId, " hangup() ending call (reason=").concat(reason, ")"));
1123
+ this.terminate(CallParty.Local, reason, !suppressEvent);
1124
+ // We don't want to send hangup here if we didn't even get to sending an invite
1125
+ if ([CallState.Fledgling, CallState.WaitLocalMedia].includes(this.state)) return;
1126
+ var content = {};
1127
+ // Don't send UserHangup reason to older clients
1128
+ if (this.opponentVersion && this.opponentVersion !== 0 || reason !== CallErrorCode.UserHangup) {
1129
+ content["reason"] = reason;
1130
+ }
1131
+ this.sendVoipEvent(EventType.CallHangup, content);
1132
+ }
1133
+
1134
+ /**
1135
+ * Reject a call
1136
+ * This used to be done by calling hangup, but is a separate method and protocol
1137
+ * event as of MSC2746.
1138
+ */
1139
+ reject() {
1140
+ if (this.state !== CallState.Ringing) {
1141
+ throw Error("Call must be in 'ringing' state to reject!");
1142
+ }
1143
+ if (this.opponentVersion === 0) {
1144
+ logger.info("Call ".concat(this.callId, " reject() opponent version is less than 1: sending hangup instead of reject (opponentVersion=").concat(this.opponentVersion, ")"));
1145
+ this.hangup(CallErrorCode.UserHangup, true);
1146
+ return;
1147
+ }
1148
+ logger.debug("Rejecting call: " + this.callId);
1149
+ this.terminate(CallParty.Local, CallErrorCode.UserHangup, true);
1150
+ this.sendVoipEvent(EventType.CallReject, {});
1151
+ }
1152
+
1153
+ /**
1154
+ * Adds an audio and/or video track - upgrades the call
1155
+ * @param audio - should add an audio track
1156
+ * @param video - should add an video track
1157
+ */
1158
+ upgradeCall(audio, video) {
1159
+ var _this0 = this;
1160
+ return _asyncToGenerator(function* () {
1161
+ // We don't do call downgrades
1162
+ if (!audio && !video) return;
1163
+ if (!_this0.opponentSupportsSDPStreamMetadata()) return;
1164
+ try {
1165
+ logger.debug("Call ".concat(_this0.callId, " upgradeCall() upgrading call (audio=").concat(audio, ", video=").concat(video, ")"));
1166
+ var getAudio = audio || _this0.hasLocalUserMediaAudioTrack;
1167
+ var getVideo = video || _this0.hasLocalUserMediaVideoTrack;
1168
+
1169
+ // updateLocalUsermediaStream() will take the tracks, use them as
1170
+ // replacement and throw the stream away, so it isn't reusable
1171
+ var stream = yield _this0.client.getMediaHandler().getUserMediaStream(getAudio, getVideo, false);
1172
+ yield _this0.updateLocalUsermediaStream(stream, audio, video);
1173
+ } catch (error) {
1174
+ logger.error("Call ".concat(_this0.callId, " upgradeCall() failed to upgrade the call"), error);
1175
+ _this0.emit(CallEvent.Error, new CallError(CallErrorCode.NoUserMedia, "Failed to get camera access: ", error), _this0);
1176
+ }
1177
+ })();
1178
+ }
1179
+
1180
+ /**
1181
+ * Returns true if this.remoteSDPStreamMetadata is defined, otherwise returns false
1182
+ * @returns can screenshare
1183
+ */
1184
+ opponentSupportsSDPStreamMetadata() {
1185
+ return Boolean(this.remoteSDPStreamMetadata);
1186
+ }
1187
+
1188
+ /**
1189
+ * If there is a screensharing stream returns true, otherwise returns false
1190
+ * @returns is screensharing
1191
+ */
1192
+ isScreensharing() {
1193
+ return Boolean(this.localScreensharingStream);
1194
+ }
1195
+
1196
+ /**
1197
+ * Starts/stops screensharing
1198
+ * @param enabled - the desired screensharing state
1199
+ * @param opts - screen sharing options
1200
+ * @returns new screensharing state
1201
+ */
1202
+ setScreensharingEnabled(enabled, opts) {
1203
+ var _this1 = this;
1204
+ return _asyncToGenerator(function* () {
1205
+ // Skip if there is nothing to do
1206
+ if (enabled && _this1.isScreensharing()) {
1207
+ logger.warn("Call ".concat(_this1.callId, " setScreensharingEnabled() there is already a screensharing stream - there is nothing to do!"));
1208
+ return true;
1209
+ } else if (!enabled && !_this1.isScreensharing()) {
1210
+ logger.warn("Call ".concat(_this1.callId, " setScreensharingEnabled() there already isn't a screensharing stream - there is nothing to do!"));
1211
+ return false;
1212
+ }
1213
+
1214
+ // Fallback to replaceTrack()
1215
+ if (!_this1.opponentSupportsSDPStreamMetadata()) {
1216
+ return _this1.setScreensharingEnabledWithoutMetadataSupport(enabled, opts);
1217
+ }
1218
+ logger.debug("Call ".concat(_this1.callId, " setScreensharingEnabled() running (enabled=").concat(enabled, ")"));
1219
+ if (enabled) {
1220
+ try {
1221
+ var stream = yield _this1.client.getMediaHandler().getScreensharingStream(opts);
1222
+ if (!stream) return false;
1223
+ _this1.pushNewLocalFeed(stream, SDPStreamMetadataPurpose.Screenshare);
1224
+ return true;
1225
+ } catch (err) {
1226
+ logger.error("Call ".concat(_this1.callId, " setScreensharingEnabled() failed to get screen-sharing stream:"), err);
1227
+ return false;
1228
+ }
1229
+ } else {
1230
+ var audioTransceiver = _this1.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "audio"));
1231
+ var videoTransceiver = _this1.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"));
1232
+ for (var transceiver of [audioTransceiver, videoTransceiver]) {
1233
+ // this is slightly mixing the track and transceiver API but is basically just shorthand
1234
+ // for removing the sender.
1235
+ if (transceiver && transceiver.sender) _this1.peerConn.removeTrack(transceiver.sender);
1236
+ }
1237
+ _this1.client.getMediaHandler().stopScreensharingStream(_this1.localScreensharingStream);
1238
+ _this1.deleteFeedByStream(_this1.localScreensharingStream);
1239
+ return false;
1240
+ }
1241
+ })();
1242
+ }
1243
+
1244
+ /**
1245
+ * Starts/stops screensharing
1246
+ * Should be used ONLY if the opponent doesn't support SDPStreamMetadata
1247
+ * @param enabled - the desired screensharing state
1248
+ * @param opts - screen sharing options
1249
+ * @returns new screensharing state
1250
+ */
1251
+ setScreensharingEnabledWithoutMetadataSupport(enabled, opts) {
1252
+ var _this10 = this;
1253
+ return _asyncToGenerator(function* () {
1254
+ logger.debug("Call ".concat(_this10.callId, " setScreensharingEnabledWithoutMetadataSupport() running (enabled=").concat(enabled, ")"));
1255
+ if (enabled) {
1256
+ try {
1257
+ var _this10$transceivers$;
1258
+ var stream = yield _this10.client.getMediaHandler().getScreensharingStream(opts);
1259
+ if (!stream) return false;
1260
+ var track = stream.getTracks().find(track => track.kind === "video");
1261
+ var sender = (_this10$transceivers$ = _this10.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "video"))) === null || _this10$transceivers$ === void 0 ? void 0 : _this10$transceivers$.sender;
1262
+ sender === null || sender === void 0 || sender.replaceTrack(track !== null && track !== void 0 ? track : null);
1263
+ _this10.pushNewLocalFeed(stream, SDPStreamMetadataPurpose.Screenshare, false);
1264
+ return true;
1265
+ } catch (err) {
1266
+ logger.error("Call ".concat(_this10.callId, " setScreensharingEnabledWithoutMetadataSupport() failed to get screen-sharing stream:"), err);
1267
+ return false;
1268
+ }
1269
+ } else {
1270
+ var _this10$localUsermedi, _this10$transceivers$2;
1271
+ var _track = (_this10$localUsermedi = _this10.localUsermediaStream) === null || _this10$localUsermedi === void 0 ? void 0 : _this10$localUsermedi.getTracks().find(track => track.kind === "video");
1272
+ var _sender = (_this10$transceivers$2 = _this10.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "video"))) === null || _this10$transceivers$2 === void 0 ? void 0 : _this10$transceivers$2.sender;
1273
+ _sender === null || _sender === void 0 || _sender.replaceTrack(_track !== null && _track !== void 0 ? _track : null);
1274
+ _this10.client.getMediaHandler().stopScreensharingStream(_this10.localScreensharingStream);
1275
+ _this10.deleteFeedByStream(_this10.localScreensharingStream);
1276
+ return false;
1277
+ }
1278
+ })();
1279
+ }
1280
+
1281
+ /**
1282
+ * Replaces/adds the tracks from the passed stream to the localUsermediaStream
1283
+ * @param stream - to use a replacement for the local usermedia stream
1284
+ */
1285
+ updateLocalUsermediaStream(stream) {
1286
+ var _arguments = arguments,
1287
+ _this11 = this;
1288
+ return _asyncToGenerator(function* () {
1289
+ var forceAudio = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : false;
1290
+ var forceVideo = _arguments.length > 2 && _arguments[2] !== undefined ? _arguments[2] : false;
1291
+ var callFeed = _this11.localUsermediaFeed;
1292
+ var audioEnabled = forceAudio || !callFeed.isAudioMuted() && !_this11.remoteOnHold;
1293
+ var videoEnabled = forceVideo || !callFeed.isVideoMuted() && !_this11.remoteOnHold;
1294
+ logger.log("Call ".concat(_this11.callId, " updateLocalUsermediaStream() running (streamId=").concat(stream.id, ", audio=").concat(audioEnabled, ", video=").concat(videoEnabled, ")"));
1295
+ setTracksEnabled(stream.getAudioTracks(), audioEnabled);
1296
+ setTracksEnabled(stream.getVideoTracks(), videoEnabled);
1297
+
1298
+ // We want to keep the same stream id, so we replace the tracks rather
1299
+ // than the whole stream.
1300
+
1301
+ // Firstly, we replace the tracks in our localUsermediaStream.
1302
+ for (var track of _this11.localUsermediaStream.getTracks()) {
1303
+ _this11.localUsermediaStream.removeTrack(track);
1304
+ track.stop();
1305
+ }
1306
+ for (var _track2 of stream.getTracks()) {
1307
+ _this11.localUsermediaStream.addTrack(_track2);
1308
+ }
1309
+
1310
+ // Then replace the old tracks, if possible.
1311
+ var _loop2 = function* _loop2() {
1312
+ var tKey = getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, _track3.kind);
1313
+ var transceiver = _this11.transceivers.get(tKey);
1314
+ var oldSender = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender;
1315
+ var added = false;
1316
+ if (oldSender) {
1317
+ try {
1318
+ logger.info("Call ".concat(_this11.callId, " updateLocalUsermediaStream() replacing track (id=").concat(_track3.id, ", kind=").concat(_track3.kind, ", streamId=").concat(stream.id, ", streamPurpose=").concat(callFeed.purpose, ")"));
1319
+ yield oldSender.replaceTrack(_track3);
1320
+ // Set the direction to indicate we're going to be sending.
1321
+ // This is only necessary in the cases where we're upgrading
1322
+ // the call to video after downgrading it.
1323
+ transceiver.direction = transceiver.direction === "inactive" ? "sendonly" : "sendrecv";
1324
+ added = true;
1325
+ } catch (error) {
1326
+ logger.warn("Call ".concat(_this11.callId, " updateLocalUsermediaStream() replaceTrack failed: adding new transceiver instead"), error);
1327
+ }
1328
+ }
1329
+ if (!added) {
1330
+ logger.info("Call ".concat(_this11.callId, " updateLocalUsermediaStream() adding track to peer connection (id=").concat(_track3.id, ", kind=").concat(_track3.kind, ", streamId=").concat(stream.id, ", streamPurpose=").concat(callFeed.purpose, ")"));
1331
+ var newSender = _this11.peerConn.addTrack(_track3, _this11.localUsermediaStream);
1332
+ var newTransceiver = _this11.peerConn.getTransceivers().find(t => t.sender === newSender);
1333
+ if (newTransceiver) {
1334
+ _this11.transceivers.set(tKey, newTransceiver);
1335
+ } else {
1336
+ logger.warn("Call ".concat(_this11.callId, " updateLocalUsermediaStream() couldn't find matching transceiver for newly added track!"));
1337
+ }
1338
+ }
1339
+ };
1340
+ for (var _track3 of stream.getTracks()) {
1341
+ yield* _loop2();
1342
+ }
1343
+ })();
1344
+ }
1345
+
1346
+ /**
1347
+ * Set whether our outbound video should be muted or not.
1348
+ * @param muted - True to mute the outbound video.
1349
+ * @returns the new mute state
1350
+ */
1351
+ setLocalVideoMuted(muted) {
1352
+ var _this12 = this;
1353
+ return _asyncToGenerator(function* () {
1354
+ var _this12$localUsermedi2;
1355
+ logger.log("Call ".concat(_this12.callId, " setLocalVideoMuted() running ").concat(muted));
1356
+
1357
+ // if we were still thinking about stopping and removing the video
1358
+ // track: don't, because we want it back.
1359
+ if (!muted && _this12.stopVideoTrackTimer !== undefined) {
1360
+ clearTimeout(_this12.stopVideoTrackTimer);
1361
+ _this12.stopVideoTrackTimer = undefined;
1362
+ }
1363
+ if (!(yield _this12.client.getMediaHandler().hasVideoDevice())) {
1364
+ return _this12.isLocalVideoMuted();
1365
+ }
1366
+ if (!_this12.hasUserMediaVideoSender && !muted) {
1367
+ var _this12$localUsermedi;
1368
+ (_this12$localUsermedi = _this12.localUsermediaFeed) === null || _this12$localUsermedi === void 0 || _this12$localUsermedi.setAudioVideoMuted(null, muted);
1369
+ yield _this12.upgradeCall(false, true);
1370
+ return _this12.isLocalVideoMuted();
1371
+ }
1372
+
1373
+ // we may not have a video track - if not, re-request usermedia
1374
+ if (!muted && _this12.localUsermediaStream.getVideoTracks().length === 0) {
1375
+ var stream = yield _this12.client.getMediaHandler().getUserMediaStream(true, true);
1376
+ yield _this12.updateLocalUsermediaStream(stream);
1377
+ }
1378
+ (_this12$localUsermedi2 = _this12.localUsermediaFeed) === null || _this12$localUsermedi2 === void 0 || _this12$localUsermedi2.setAudioVideoMuted(null, muted);
1379
+ _this12.updateMuteStatus();
1380
+ yield _this12.sendMetadataUpdate();
1381
+
1382
+ // if we're muting video, set a timeout to stop & remove the video track so we release
1383
+ // the camera. We wait a short time to do this because when we disable a track, WebRTC
1384
+ // will send black video for it. If we just stop and remove it straight away, the video
1385
+ // will just freeze which means that when we unmute video, the other side will briefly
1386
+ // get a static frame of us from before we muted. This way, the still frame is just black.
1387
+ // A very small delay is not always enough so the theory here is that it needs to be long
1388
+ // enough for WebRTC to encode a frame: 120ms should be long enough even if we're only
1389
+ // doing 10fps.
1390
+ if (muted) {
1391
+ _this12.stopVideoTrackTimer = setTimeout(() => {
1392
+ for (var t of _this12.localUsermediaStream.getVideoTracks()) {
1393
+ t.stop();
1394
+ _this12.localUsermediaStream.removeTrack(t);
1395
+ }
1396
+ }, 120);
1397
+ }
1398
+ return _this12.isLocalVideoMuted();
1399
+ })();
1400
+ }
1401
+
1402
+ /**
1403
+ * Check if local video is muted.
1404
+ *
1405
+ * If there are multiple video tracks, <i>all</i> of the tracks need to be muted
1406
+ * for this to return true. This means if there are no video tracks, this will
1407
+ * return true.
1408
+ * @returns True if the local preview video is muted, else false
1409
+ * (including if the call is not set up yet).
1410
+ */
1411
+ isLocalVideoMuted() {
1412
+ var _this$localUsermediaF2, _this$localUsermediaF3;
1413
+ return (_this$localUsermediaF2 = (_this$localUsermediaF3 = this.localUsermediaFeed) === null || _this$localUsermediaF3 === void 0 ? void 0 : _this$localUsermediaF3.isVideoMuted()) !== null && _this$localUsermediaF2 !== void 0 ? _this$localUsermediaF2 : false;
1414
+ }
1415
+
1416
+ /**
1417
+ * Set whether the microphone should be muted or not.
1418
+ * @param muted - True to mute the mic.
1419
+ * @returns the new mute state
1420
+ */
1421
+ setMicrophoneMuted(muted) {
1422
+ var _this13 = this;
1423
+ return _asyncToGenerator(function* () {
1424
+ var _this13$localUsermedi;
1425
+ logger.log("Call ".concat(_this13.callId, " setMicrophoneMuted() running ").concat(muted));
1426
+ if (!(yield _this13.client.getMediaHandler().hasAudioDevice())) {
1427
+ return _this13.isMicrophoneMuted();
1428
+ }
1429
+ if (!muted && (!_this13.hasUserMediaAudioSender || !_this13.hasLocalUserMediaAudioTrack)) {
1430
+ yield _this13.upgradeCall(true, false);
1431
+ return _this13.isMicrophoneMuted();
1432
+ }
1433
+ (_this13$localUsermedi = _this13.localUsermediaFeed) === null || _this13$localUsermedi === void 0 || _this13$localUsermedi.setAudioVideoMuted(muted, null);
1434
+ _this13.updateMuteStatus();
1435
+ yield _this13.sendMetadataUpdate();
1436
+ return _this13.isMicrophoneMuted();
1437
+ })();
1438
+ }
1439
+
1440
+ /**
1441
+ * Check if the microphone is muted.
1442
+ *
1443
+ * If there are multiple audio tracks, <i>all</i> of the tracks need to be muted
1444
+ * for this to return true. This means if there are no audio tracks, this will
1445
+ * return true.
1446
+ * @returns True if the mic is muted, else false (including if the call
1447
+ * is not set up yet).
1448
+ */
1449
+ isMicrophoneMuted() {
1450
+ var _this$localUsermediaF4, _this$localUsermediaF5;
1451
+ return (_this$localUsermediaF4 = (_this$localUsermediaF5 = this.localUsermediaFeed) === null || _this$localUsermediaF5 === void 0 ? void 0 : _this$localUsermediaF5.isAudioMuted()) !== null && _this$localUsermediaF4 !== void 0 ? _this$localUsermediaF4 : false;
1452
+ }
1453
+
1454
+ /**
1455
+ * @returns true if we have put the party on the other side of the call on hold
1456
+ * (that is, we are signalling to them that we are not listening)
1457
+ */
1458
+ isRemoteOnHold() {
1459
+ return this.remoteOnHold;
1460
+ }
1461
+ setRemoteOnHold(onHold) {
1462
+ if (this.isRemoteOnHold() === onHold) return;
1463
+ this.remoteOnHold = onHold;
1464
+ for (var transceiver of this.peerConn.getTransceivers()) {
1465
+ // We don't send hold music or anything so we're not actually
1466
+ // sending anything, but sendrecv is fairly standard for hold and
1467
+ // it makes it a lot easier to figure out who's put who on hold.
1468
+ transceiver.direction = onHold ? "sendonly" : "sendrecv";
1469
+ }
1470
+ this.updateMuteStatus();
1471
+ this.sendMetadataUpdate();
1472
+ this.emit(CallEvent.RemoteHoldUnhold, this.remoteOnHold, this);
1473
+ }
1474
+
1475
+ /**
1476
+ * Indicates whether we are 'on hold' to the remote party (ie. if true,
1477
+ * they cannot hear us).
1478
+ * @returns true if the other party has put us on hold
1479
+ */
1480
+ isLocalOnHold() {
1481
+ if (this.state !== CallState.Connected) return false;
1482
+ var callOnHold = true;
1483
+
1484
+ // We consider a call to be on hold only if *all* the tracks are on hold
1485
+ // (is this the right thing to do?)
1486
+ for (var transceiver of this.peerConn.getTransceivers()) {
1487
+ var trackOnHold = ["inactive", "recvonly"].includes(transceiver.currentDirection);
1488
+ if (!trackOnHold) callOnHold = false;
1489
+ }
1490
+ return callOnHold;
1491
+ }
1492
+
1493
+ /**
1494
+ * Sends a DTMF digit to the other party
1495
+ * @param digit - The digit (nb. string - '#' and '*' are dtmf too)
1496
+ */
1497
+ sendDtmfDigit(digit) {
1498
+ for (var sender of this.peerConn.getSenders()) {
1499
+ var _sender$track;
1500
+ if (((_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.kind) === "audio" && sender.dtmf) {
1501
+ sender.dtmf.insertDTMF(digit);
1502
+ return;
1503
+ }
1504
+ }
1505
+ throw new Error("Unable to find a track to send DTMF on");
1506
+ }
1507
+ updateMuteStatus() {
1508
+ var micShouldBeMuted = this.isMicrophoneMuted() || this.remoteOnHold;
1509
+ var vidShouldBeMuted = this.isLocalVideoMuted() || this.remoteOnHold;
1510
+ logger.log("Call ".concat(this.callId, " updateMuteStatus stream ").concat(this.localUsermediaStream.id, " micShouldBeMuted ").concat(micShouldBeMuted, " vidShouldBeMuted ").concat(vidShouldBeMuted));
1511
+ setTracksEnabled(this.localUsermediaStream.getAudioTracks(), !micShouldBeMuted);
1512
+ setTracksEnabled(this.localUsermediaStream.getVideoTracks(), !vidShouldBeMuted);
1513
+ }
1514
+ sendMetadataUpdate() {
1515
+ var _this14 = this;
1516
+ return _asyncToGenerator(function* () {
1517
+ yield _this14.sendVoipEvent(EventType.CallSDPStreamMetadataChanged, {
1518
+ [SDPStreamMetadataKey.name]: _this14.getLocalSDPStreamMetadata()
1519
+ });
1520
+ })();
1521
+ }
1522
+ gotCallFeedsForInvite(callFeeds) {
1523
+ var requestScreenshareFeed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1524
+ if (this.successor) {
1525
+ this.successor.queueGotCallFeedsForAnswer(callFeeds);
1526
+ return;
1527
+ }
1528
+ if (this.callHasEnded()) {
1529
+ this.stopAllMedia();
1530
+ return;
1531
+ }
1532
+ for (var feed of callFeeds) {
1533
+ this.pushLocalFeed(feed);
1534
+ }
1535
+ if (requestScreenshareFeed) {
1536
+ this.peerConn.addTransceiver("video", {
1537
+ direction: "recvonly"
1538
+ });
1539
+ }
1540
+ this.state = CallState.CreateOffer;
1541
+ logger.debug("Call ".concat(this.callId, " gotUserMediaForInvite() run"));
1542
+ // Now we wait for the negotiationneeded event
1543
+ }
1544
+ sendAnswer() {
1545
+ var _this15 = this;
1546
+ return _asyncToGenerator(function* () {
1547
+ var answerContent = {
1548
+ answer: {
1549
+ sdp: _this15.peerConn.localDescription.sdp,
1550
+ // type is now deprecated as of Matrix VoIP v1, but
1551
+ // required to still be sent for backwards compat
1552
+ type: _this15.peerConn.localDescription.type
1553
+ },
1554
+ [SDPStreamMetadataKey.name]: _this15.getLocalSDPStreamMetadata(true)
1555
+ };
1556
+ answerContent.capabilities = {
1557
+ "m.call.transferee": _this15.client.supportsCallTransfer,
1558
+ "m.call.dtmf": false
1559
+ };
1560
+
1561
+ // We have just taken the local description from the peerConn which will
1562
+ // contain all the local candidates added so far, so we can discard any candidates
1563
+ // we had queued up because they'll be in the answer.
1564
+ var discardCount = _this15.discardDuplicateCandidates();
1565
+ logger.info("Call ".concat(_this15.callId, " sendAnswer() discarding ").concat(discardCount, " candidates that will be sent in answer"));
1566
+ try {
1567
+ yield _this15.sendVoipEvent(EventType.CallAnswer, answerContent);
1568
+ // If this isn't the first time we've tried to send the answer,
1569
+ // we may have candidates queued up, so send them now.
1570
+ _this15.inviteOrAnswerSent = true;
1571
+ } catch (error) {
1572
+ // We've failed to answer: back to the ringing state
1573
+ _this15.state = CallState.Ringing;
1574
+ if (error instanceof BriijError && error.event) _this15.client.cancelPendingEvent(error.event);
1575
+ var code = CallErrorCode.SendAnswer;
1576
+ var message = "Failed to send answer";
1577
+ if (error.name == "UnknownDeviceError") {
1578
+ code = CallErrorCode.UnknownDevices;
1579
+ message = "Unknown devices present in the room";
1580
+ }
1581
+ _this15.emit(CallEvent.Error, new CallError(code, message, error), _this15);
1582
+ throw error;
1583
+ }
1584
+
1585
+ // error handler re-throws so this won't happen on error, but
1586
+ // we don't want the same error handling on the candidate queue
1587
+ _this15.sendCandidateQueue();
1588
+ })();
1589
+ }
1590
+ queueGotCallFeedsForAnswer(callFeeds) {
1591
+ // Ensure only one negotiate/answer event is being processed at a time.
1592
+ if (this.responsePromiseChain) {
1593
+ this.responsePromiseChain = this.responsePromiseChain.then(() => this.gotCallFeedsForAnswer(callFeeds));
1594
+ } else {
1595
+ this.responsePromiseChain = this.gotCallFeedsForAnswer(callFeeds);
1596
+ }
1597
+ }
1598
+
1599
+ // Enables DTX (discontinuous transmission) on the given session to reduce
1600
+ // bandwidth when transmitting silence
1601
+ mungeSdp(description, mods) {
1602
+ // The only way to enable DTX at this time is through SDP munging
1603
+ var sdp = parseSdp(description.sdp);
1604
+ sdp.media.forEach(media => {
1605
+ var payloadTypeToCodecMap = new Map();
1606
+ var codecToPayloadTypeMap = new Map();
1607
+ for (var rtp of media.rtp) {
1608
+ payloadTypeToCodecMap.set(rtp.payload, rtp.codec);
1609
+ codecToPayloadTypeMap.set(rtp.codec, rtp.payload);
1610
+ }
1611
+ for (var mod of mods) {
1612
+ if (mod.mediaType !== media.type) continue;
1613
+ if (!codecToPayloadTypeMap.has(mod.codec)) {
1614
+ logger.info("Call ".concat(this.callId, " mungeSdp() ignoring SDP modifications for ").concat(mod.codec, " as it's not present."));
1615
+ continue;
1616
+ }
1617
+ var extraConfig = [];
1618
+ if (mod.enableDtx !== undefined) {
1619
+ extraConfig.push("usedtx=".concat(mod.enableDtx ? "1" : "0"));
1620
+ }
1621
+ if (mod.maxAverageBitrate !== undefined) {
1622
+ extraConfig.push("maxaveragebitrate=".concat(mod.maxAverageBitrate));
1623
+ }
1624
+ var found = false;
1625
+ for (var fmtp of media.fmtp) {
1626
+ if (payloadTypeToCodecMap.get(fmtp.payload) === mod.codec) {
1627
+ found = true;
1628
+ fmtp.config += ";" + extraConfig.join(";");
1629
+ }
1630
+ }
1631
+ if (!found) {
1632
+ media.fmtp.push({
1633
+ payload: codecToPayloadTypeMap.get(mod.codec),
1634
+ config: extraConfig.join(";")
1635
+ });
1636
+ }
1637
+ }
1638
+ });
1639
+ description.sdp = writeSdp(sdp);
1640
+ }
1641
+ createOffer() {
1642
+ var _this16 = this;
1643
+ return _asyncToGenerator(function* () {
1644
+ var offer = yield _this16.peerConn.createOffer();
1645
+ _this16.mungeSdp(offer, getCodecParamMods(_this16.isPtt));
1646
+ return offer;
1647
+ })();
1648
+ }
1649
+ createAnswer() {
1650
+ var _this17 = this;
1651
+ return _asyncToGenerator(function* () {
1652
+ var answer = yield _this17.peerConn.createAnswer();
1653
+ _this17.mungeSdp(answer, getCodecParamMods(_this17.isPtt));
1654
+ return answer;
1655
+ })();
1656
+ }
1657
+ gotCallFeedsForAnswer(callFeeds) {
1658
+ var _this18 = this;
1659
+ return _asyncToGenerator(function* () {
1660
+ if (_this18.callHasEnded()) return;
1661
+ _this18.waitForLocalAVStream = false;
1662
+ for (var feed of callFeeds) {
1663
+ _this18.pushLocalFeed(feed);
1664
+ }
1665
+ _this18.state = CallState.CreateAnswer;
1666
+ var answer;
1667
+ try {
1668
+ _this18.getRidOfRTXCodecs();
1669
+ answer = yield _this18.createAnswer();
1670
+ } catch (err) {
1671
+ logger.debug("Call ".concat(_this18.callId, " gotCallFeedsForAnswer() failed to create answer: "), err);
1672
+ _this18.terminate(CallParty.Local, CallErrorCode.CreateAnswer, true);
1673
+ return;
1674
+ }
1675
+ try {
1676
+ yield _this18.peerConn.setLocalDescription(answer);
1677
+
1678
+ // make sure we're still going
1679
+ if (_this18.callHasEnded()) return;
1680
+ _this18.state = CallState.Connecting;
1681
+
1682
+ // Allow a short time for initial candidates to be gathered
1683
+ yield new Promise(resolve => {
1684
+ setTimeout(resolve, 200);
1685
+ });
1686
+
1687
+ // make sure the call hasn't ended before we continue
1688
+ if (_this18.callHasEnded()) return;
1689
+ _this18.sendAnswer();
1690
+ } catch (err) {
1691
+ logger.debug("Call ".concat(_this18.callId, " gotCallFeedsForAnswer() error setting local description!"), err);
1692
+ _this18.terminate(CallParty.Local, CallErrorCode.SetLocalDescription, true);
1693
+ return;
1694
+ }
1695
+ })();
1696
+ }
1697
+ onRemoteIceCandidatesReceived(ev) {
1698
+ var _this19 = this;
1699
+ return _asyncToGenerator(function* () {
1700
+ if (_this19.callHasEnded()) {
1701
+ //debuglog("Ignoring remote ICE candidate because call has ended");
1702
+ return;
1703
+ }
1704
+ var content = ev.getContent();
1705
+ var candidates = content.candidates;
1706
+ if (!candidates) {
1707
+ logger.info("Call ".concat(_this19.callId, " onRemoteIceCandidatesReceived() ignoring candidates event with no candidates!"));
1708
+ return;
1709
+ }
1710
+ var fromPartyId = content.version === 0 ? null : content.party_id || null;
1711
+ if (_this19.opponentPartyId === undefined) {
1712
+ // we haven't picked an opponent yet so save the candidates
1713
+ if (fromPartyId) {
1714
+ logger.info("Call ".concat(_this19.callId, " onRemoteIceCandidatesReceived() buffering ").concat(candidates.length, " candidates until we pick an opponent"));
1715
+ var bufferedCandidates = _this19.remoteCandidateBuffer.get(fromPartyId) || [];
1716
+ bufferedCandidates.push(...candidates);
1717
+ _this19.remoteCandidateBuffer.set(fromPartyId, bufferedCandidates);
1718
+ }
1719
+ return;
1720
+ }
1721
+ if (!_this19.partyIdMatches(content)) {
1722
+ logger.info("Call ".concat(_this19.callId, " onRemoteIceCandidatesReceived() ignoring candidates from party ID ").concat(content.party_id, ": we have chosen party ID ").concat(_this19.opponentPartyId));
1723
+ return;
1724
+ }
1725
+ yield _this19.addIceCandidates(candidates);
1726
+ })();
1727
+ }
1728
+
1729
+ /**
1730
+ * Used by BriijClient.
1731
+ */
1732
+ onAnswerReceived(event) {
1733
+ var _this20 = this;
1734
+ return _asyncToGenerator(function* () {
1735
+ var content = event.getContent();
1736
+ logger.debug("Call ".concat(_this20.callId, " onAnswerReceived() running (hangupParty=").concat(content.party_id, ")"));
1737
+ if (_this20.callHasEnded()) {
1738
+ logger.debug("Call ".concat(_this20.callId, " onAnswerReceived() ignoring answer because call has ended"));
1739
+ return;
1740
+ }
1741
+ if (_this20.opponentPartyId !== undefined) {
1742
+ logger.info("Call ".concat(_this20.callId, " onAnswerReceived() ignoring answer from party ID ").concat(content.party_id, ": we already have an answer/reject from ").concat(_this20.opponentPartyId));
1743
+ return;
1744
+ }
1745
+ _this20.chooseOpponent(event);
1746
+ yield _this20.addBufferedIceCandidates();
1747
+ _this20.state = CallState.Connecting;
1748
+ var sdpStreamMetadata = SDPStreamMetadataKey.findIn(content);
1749
+ if (sdpStreamMetadata) {
1750
+ _this20.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
1751
+ } else {
1752
+ logger.warn("Call ".concat(_this20.callId, " onAnswerReceived() did not get any SDPStreamMetadata! Can not send/receive multiple streams"));
1753
+ }
1754
+ try {
1755
+ _this20.isSettingRemoteAnswerPending = true;
1756
+ yield _this20.peerConn.setRemoteDescription(content.answer);
1757
+ _this20.isSettingRemoteAnswerPending = false;
1758
+ logger.debug("Call ".concat(_this20.callId, " onAnswerReceived() set remote description: ").concat(content.answer.type));
1759
+ } catch (e) {
1760
+ _this20.isSettingRemoteAnswerPending = false;
1761
+ logger.debug("Call ".concat(_this20.callId, " onAnswerReceived() failed to set remote description"), e);
1762
+ _this20.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
1763
+ return;
1764
+ }
1765
+
1766
+ // If the answer we selected has a party_id, send a select_answer event
1767
+ // We do this after setting the remote description since otherwise we'd block
1768
+ // call setup on it
1769
+ if (_this20.opponentPartyId !== null) {
1770
+ try {
1771
+ yield _this20.sendVoipEvent(EventType.CallSelectAnswer, {
1772
+ selected_party_id: _this20.opponentPartyId
1773
+ });
1774
+ } catch (err) {
1775
+ // This isn't fatal, and will just mean that if another party has raced to answer
1776
+ // the call, they won't know they got rejected, so we carry on & don't retry.
1777
+ logger.warn("Call ".concat(_this20.callId, " onAnswerReceived() failed to send select_answer event"), err);
1778
+ }
1779
+ }
1780
+ })();
1781
+ }
1782
+ onSelectAnswerReceived(event) {
1783
+ var _this21 = this;
1784
+ return _asyncToGenerator(function* () {
1785
+ if (_this21.direction !== CallDirection.Inbound) {
1786
+ logger.warn("Call ".concat(_this21.callId, " onSelectAnswerReceived() got select_answer for an outbound call: ignoring"));
1787
+ return;
1788
+ }
1789
+ var selectedPartyId = event.getContent().selected_party_id;
1790
+ if (selectedPartyId === undefined || selectedPartyId === null) {
1791
+ logger.warn("Call ".concat(_this21.callId, " onSelectAnswerReceived() got nonsensical select_answer with null/undefined selected_party_id: ignoring"));
1792
+ return;
1793
+ }
1794
+ if (selectedPartyId !== _this21.ourPartyId) {
1795
+ logger.info("Call ".concat(_this21.callId, " onSelectAnswerReceived() got select_answer for party ID ").concat(selectedPartyId, ": we are party ID ").concat(_this21.ourPartyId, "."));
1796
+ // The other party has picked somebody else's answer
1797
+ yield _this21.terminate(CallParty.Remote, CallErrorCode.AnsweredElsewhere, true);
1798
+ }
1799
+ })();
1800
+ }
1801
+ onNegotiateReceived(event) {
1802
+ var _this22 = this;
1803
+ return _asyncToGenerator(function* () {
1804
+ var content = event.getContent();
1805
+ var description = content.description;
1806
+ if (!description || !description.sdp || !description.type) {
1807
+ logger.info("Call ".concat(_this22.callId, " onNegotiateReceived() ignoring invalid m.call.negotiate event"));
1808
+ return;
1809
+ }
1810
+ // Politeness always follows the direction of the call: in a glare situation,
1811
+ // we pick either the inbound or outbound call, so one side will always be
1812
+ // inbound and one outbound
1813
+ var polite = _this22.direction === CallDirection.Inbound;
1814
+
1815
+ // Here we follow the perfect negotiation logic from
1816
+ // https://w3c.github.io/webrtc-pc/#perfect-negotiation-example
1817
+ var readyForOffer = !_this22.makingOffer && (_this22.peerConn.signalingState === "stable" || _this22.isSettingRemoteAnswerPending);
1818
+ var offerCollision = description.type === "offer" && !readyForOffer;
1819
+ _this22.ignoreOffer = !polite && offerCollision;
1820
+ if (_this22.ignoreOffer) {
1821
+ logger.info("Call ".concat(_this22.callId, " onNegotiateReceived() ignoring colliding negotiate event because we're impolite"));
1822
+ return;
1823
+ }
1824
+ var prevLocalOnHold = _this22.isLocalOnHold();
1825
+ var sdpStreamMetadata = SDPStreamMetadataKey.findIn(content);
1826
+ if (sdpStreamMetadata) {
1827
+ _this22.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
1828
+ } else {
1829
+ logger.warn("Call ".concat(_this22.callId, " onNegotiateReceived() received negotiation event without SDPStreamMetadata!"));
1830
+ }
1831
+ try {
1832
+ _this22.isSettingRemoteAnswerPending = description.type == "answer";
1833
+ yield _this22.peerConn.setRemoteDescription(description); // SRD rolls back as needed
1834
+ _this22.isSettingRemoteAnswerPending = false;
1835
+ logger.debug("Call ".concat(_this22.callId, " onNegotiateReceived() set remote description: ").concat(description.type));
1836
+ if (description.type === "offer") {
1837
+ var _localDescription;
1838
+ var answer;
1839
+ try {
1840
+ _this22.getRidOfRTXCodecs();
1841
+ answer = yield _this22.createAnswer();
1842
+ } catch (err) {
1843
+ logger.debug("Call ".concat(_this22.callId, " onNegotiateReceived() failed to create answer: "), err);
1844
+ _this22.terminate(CallParty.Local, CallErrorCode.CreateAnswer, true);
1845
+ return;
1846
+ }
1847
+ yield _this22.peerConn.setLocalDescription(answer);
1848
+ logger.debug("Call ".concat(_this22.callId, " onNegotiateReceived() create an answer"));
1849
+ _this22.sendVoipEvent(EventType.CallNegotiate, {
1850
+ lifetime: CALL_TIMEOUT_MS,
1851
+ description: (_localDescription = _this22.peerConn.localDescription) === null || _localDescription === void 0 ? void 0 : _localDescription.toJSON(),
1852
+ [SDPStreamMetadataKey.name]: _this22.getLocalSDPStreamMetadata(true)
1853
+ });
1854
+ }
1855
+ } catch (err) {
1856
+ _this22.isSettingRemoteAnswerPending = false;
1857
+ logger.warn("Call ".concat(_this22.callId, " onNegotiateReceived() failed to complete negotiation"), err);
1858
+ }
1859
+ var newLocalOnHold = _this22.isLocalOnHold();
1860
+ if (prevLocalOnHold !== newLocalOnHold) {
1861
+ _this22.emit(CallEvent.LocalHoldUnhold, newLocalOnHold, _this22);
1862
+ // also this one for backwards compat
1863
+ _this22.emit(CallEvent.HoldUnhold, newLocalOnHold);
1864
+ }
1865
+ })();
1866
+ }
1867
+ updateRemoteSDPStreamMetadata(metadata) {
1868
+ this.remoteSDPStreamMetadata = recursivelyAssign(this.remoteSDPStreamMetadata || {}, metadata, true);
1869
+ for (var feed of this.getRemoteFeeds()) {
1870
+ var _streamId;
1871
+ var streamId = feed.stream.id;
1872
+ var _metadata = this.remoteSDPStreamMetadata[streamId];
1873
+ feed.setAudioVideoMuted(_metadata === null || _metadata === void 0 ? void 0 : _metadata.audio_muted, _metadata === null || _metadata === void 0 ? void 0 : _metadata.video_muted);
1874
+ feed.purpose = (_streamId = this.remoteSDPStreamMetadata[streamId]) === null || _streamId === void 0 ? void 0 : _streamId.purpose;
1875
+ }
1876
+ }
1877
+ onSDPStreamMetadataChangedReceived(event) {
1878
+ var content = event.getContent();
1879
+ var metadata = SDPStreamMetadataKey.findIn(content);
1880
+ if (metadata) {
1881
+ this.updateRemoteSDPStreamMetadata(metadata);
1882
+ }
1883
+ }
1884
+ onAssertedIdentityReceived(event) {
1885
+ var _this23 = this;
1886
+ return _asyncToGenerator(function* () {
1887
+ var content = event.getContent();
1888
+ if (!content.asserted_identity) return;
1889
+ _this23.remoteAssertedIdentity = {
1890
+ id: content.asserted_identity.id,
1891
+ displayName: content.asserted_identity.display_name
1892
+ };
1893
+ _this23.emit(CallEvent.AssertedIdentityChanged, _this23);
1894
+ })();
1895
+ }
1896
+ callHasEnded() {
1897
+ // This exists as workaround to typescript trying to be clever and erroring
1898
+ // when putting if (this.state === CallState.Ended) return; twice in the same
1899
+ // function, even though that function is async.
1900
+ return this.state === CallState.Ended;
1901
+ }
1902
+ queueGotLocalOffer() {
1903
+ // Ensure only one negotiate/answer event is being processed at a time.
1904
+ if (this.responsePromiseChain) {
1905
+ this.responsePromiseChain = this.responsePromiseChain.then(() => this.wrappedGotLocalOffer());
1906
+ } else {
1907
+ this.responsePromiseChain = this.wrappedGotLocalOffer();
1908
+ }
1909
+ }
1910
+ wrappedGotLocalOffer() {
1911
+ var _this24 = this;
1912
+ return _asyncToGenerator(function* () {
1913
+ _this24.makingOffer = true;
1914
+ try {
1915
+ // XXX: in what situations do we believe gotLocalOffer actually throws? It appears
1916
+ // to handle most of its exceptions itself and terminate the call. I'm not entirely
1917
+ // sure it would ever throw, so I can't add a test for these lines.
1918
+ // Also the tense is different between "gotLocalOffer" and "getLocalOfferFailed" so
1919
+ // it's not entirely clear whether getLocalOfferFailed is just misnamed or whether
1920
+ // they've been cross-polinated somehow at some point.
1921
+ yield _this24.gotLocalOffer();
1922
+ } catch (e) {
1923
+ _this24.getLocalOfferFailed(e);
1924
+ return;
1925
+ } finally {
1926
+ _this24.makingOffer = false;
1927
+ }
1928
+ })();
1929
+ }
1930
+ gotLocalOffer() {
1931
+ var _this25 = this;
1932
+ return _asyncToGenerator(function* () {
1933
+ logger.debug("Call ".concat(_this25.callId, " gotLocalOffer() running"));
1934
+ if (_this25.callHasEnded()) {
1935
+ logger.debug("Call ".concat(_this25.callId, " gotLocalOffer() ignoring newly created offer because the call has ended\""));
1936
+ return;
1937
+ }
1938
+ var offer;
1939
+ try {
1940
+ _this25.getRidOfRTXCodecs();
1941
+ offer = yield _this25.createOffer();
1942
+ } catch (err) {
1943
+ logger.debug("Call ".concat(_this25.callId, " gotLocalOffer() failed to create offer: "), err);
1944
+ _this25.terminate(CallParty.Local, CallErrorCode.CreateOffer, true);
1945
+ return;
1946
+ }
1947
+ try {
1948
+ yield _this25.peerConn.setLocalDescription(offer);
1949
+ } catch (err) {
1950
+ logger.debug("Call ".concat(_this25.callId, " gotLocalOffer() error setting local description!"), err);
1951
+ _this25.terminate(CallParty.Local, CallErrorCode.SetLocalDescription, true);
1952
+ return;
1953
+ }
1954
+ if (_this25.peerConn.iceGatheringState === "gathering") {
1955
+ // Allow a short time for initial candidates to be gathered
1956
+ yield new Promise(resolve => {
1957
+ setTimeout(resolve, 200);
1958
+ });
1959
+ }
1960
+ if (_this25.callHasEnded()) return;
1961
+ var eventType = _this25.state === CallState.CreateOffer ? EventType.CallInvite : EventType.CallNegotiate;
1962
+ var content = {
1963
+ lifetime: CALL_TIMEOUT_MS
1964
+ };
1965
+ if (eventType === EventType.CallInvite && _this25.invitee) {
1966
+ content.invitee = _this25.invitee;
1967
+ }
1968
+
1969
+ // clunky because TypeScript can't follow the types through if we use an expression as the key
1970
+ if (_this25.state === CallState.CreateOffer) {
1971
+ var _localDescription2;
1972
+ content.offer = (_localDescription2 = _this25.peerConn.localDescription) === null || _localDescription2 === void 0 ? void 0 : _localDescription2.toJSON();
1973
+ } else {
1974
+ var _localDescription3;
1975
+ content.description = (_localDescription3 = _this25.peerConn.localDescription) === null || _localDescription3 === void 0 ? void 0 : _localDescription3.toJSON();
1976
+ }
1977
+ content.capabilities = {
1978
+ "m.call.transferee": _this25.client.supportsCallTransfer,
1979
+ "m.call.dtmf": false
1980
+ };
1981
+ content[SDPStreamMetadataKey.name] = _this25.getLocalSDPStreamMetadata(true);
1982
+
1983
+ // Get rid of any candidates waiting to be sent: they'll be included in the local
1984
+ // description we just got and will send in the offer.
1985
+ var discardCount = _this25.discardDuplicateCandidates();
1986
+ logger.info("Call ".concat(_this25.callId, " gotLocalOffer() discarding ").concat(discardCount, " candidates that will be sent in offer"));
1987
+ try {
1988
+ yield _this25.sendVoipEvent(eventType, content);
1989
+ } catch (error) {
1990
+ logger.error("Call ".concat(_this25.callId, " gotLocalOffer() failed to send invite"), error);
1991
+ if (error instanceof BriijError && error.event) _this25.client.cancelPendingEvent(error.event);
1992
+ var code = CallErrorCode.SignallingFailed;
1993
+ var message = "Signalling failed";
1994
+ if (_this25.state === CallState.CreateOffer) {
1995
+ code = CallErrorCode.SendInvite;
1996
+ message = "Failed to send invite";
1997
+ }
1998
+ if (error.name == "UnknownDeviceError") {
1999
+ code = CallErrorCode.UnknownDevices;
2000
+ message = "Unknown devices present in the room";
2001
+ }
2002
+ _this25.emit(CallEvent.Error, new CallError(code, message, error), _this25);
2003
+ _this25.terminate(CallParty.Local, code, false);
2004
+
2005
+ // no need to carry on & send the candidate queue, but we also
2006
+ // don't want to rethrow the error
2007
+ return;
2008
+ }
2009
+ _this25.sendCandidateQueue();
2010
+ if (_this25.state === CallState.CreateOffer) {
2011
+ _this25.inviteOrAnswerSent = true;
2012
+ _this25.state = CallState.InviteSent;
2013
+ _this25.inviteTimeout = setTimeout(() => {
2014
+ _this25.inviteTimeout = undefined;
2015
+ if (_this25.state === CallState.InviteSent) {
2016
+ _this25.hangup(CallErrorCode.InviteTimeout, false);
2017
+ }
2018
+ }, CALL_TIMEOUT_MS);
2019
+ }
2020
+ })();
2021
+ }
2022
+ /**
2023
+ * This method removes all video/rtx codecs from screensharing video
2024
+ * transceivers. This is necessary since they can cause problems. Without
2025
+ * this the following steps should produce an error:
2026
+ * Chromium calls Firefox
2027
+ * Firefox answers
2028
+ * Firefox starts screen-sharing
2029
+ * Chromium starts screen-sharing
2030
+ * Call crashes for Chromium with:
2031
+ * [96685:23:0518/162603.933321:ERROR:webrtc_video_engine.cc(3296)] RTX codec (PT=97) mapped to PT=96 which is not in the codec list.
2032
+ * [96685:23:0518/162603.933377:ERROR:webrtc_video_engine.cc(1171)] GetChangedRecvParameters called without any video codecs.
2033
+ * [96685:23:0518/162603.933430:ERROR:sdp_offer_answer.cc(4302)] Failed to set local video description recv parameters for m-section with mid='2'. (INVALID_PARAMETER)
2034
+ */
2035
+ getRidOfRTXCodecs() {
2036
+ // RTCRtpReceiver.getCapabilities and RTCRtpSender.getCapabilities don't seem to be supported on FF before v113
2037
+ if (!RTCRtpReceiver.getCapabilities || !RTCRtpSender.getCapabilities) return;
2038
+ var screenshareVideoTransceiver = this.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"));
2039
+
2040
+ // setCodecPreferences isn't supported on FF (as of v113)
2041
+ if (!screenshareVideoTransceiver || !screenshareVideoTransceiver.setCodecPreferences) return;
2042
+ var recvCodecs = RTCRtpReceiver.getCapabilities("video").codecs;
2043
+ var sendCodecs = RTCRtpSender.getCapabilities("video").codecs;
2044
+ var codecs = [];
2045
+ for (var codec of [...recvCodecs, ...sendCodecs]) {
2046
+ if (codec.mimeType !== "video/rtx") {
2047
+ codecs.push(codec);
2048
+ try {
2049
+ screenshareVideoTransceiver.setCodecPreferences(codecs);
2050
+ } catch (e) {
2051
+ // Specifically, Chrome around version 125 and Electron 30 (which is Chromium 124) return an H.264 codec in
2052
+ // the sender's capabilities but throw when you try to set it. Hence... this mess.
2053
+ // Specifically, that codec is:
2054
+ // {
2055
+ // clockRate: 90000,
2056
+ // mimeType: "video/H264",
2057
+ // sdpFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640034",
2058
+ // }
2059
+ logger.info("Working around buggy WebRTC impl: claimed to support codec but threw when setting codec preferences", codec, e);
2060
+ codecs.pop();
2061
+ }
2062
+ }
2063
+ }
2064
+ }
2065
+ /**
2066
+ * @internal
2067
+ */
2068
+ sendVoipEvent(eventType, content) {
2069
+ var _this26 = this;
2070
+ return _asyncToGenerator(function* () {
2071
+ var realContent = _objectSpread(_objectSpread({}, content), {}, {
2072
+ version: VOIP_PROTO_VERSION,
2073
+ call_id: _this26.callId,
2074
+ party_id: _this26.ourPartyId,
2075
+ conf_id: _this26.groupCallId
2076
+ });
2077
+ if (_this26.opponentDeviceId) {
2078
+ var _this26$getOpponentMe;
2079
+ var toDeviceSeq = _this26.toDeviceSeq++;
2080
+ var _content = _objectSpread(_objectSpread({}, realContent), {}, {
2081
+ device_id: _this26.client.deviceId,
2082
+ sender_session_id: _this26.client.getSessionId(),
2083
+ dest_session_id: _this26.opponentSessionId,
2084
+ seq: toDeviceSeq,
2085
+ [ToDeviceMessageId]: uuidv4()
2086
+ });
2087
+ _this26.emit(CallEvent.SendVoipEvent, {
2088
+ type: "toDevice",
2089
+ eventType,
2090
+ userId: _this26.invitee || ((_this26$getOpponentMe = _this26.getOpponentMember()) === null || _this26$getOpponentMe === void 0 ? void 0 : _this26$getOpponentMe.userId),
2091
+ opponentDeviceId: _this26.opponentDeviceId,
2092
+ content: _content
2093
+ }, _this26);
2094
+ var userId = _this26.invitee || _this26.getOpponentMember().userId;
2095
+ if (_this26.client.getUseE2eForGroupCall()) {
2096
+ if (!_this26.hasOpponentDeviceInfo) {
2097
+ logger.warn("Call ".concat(_this26.callId, " sendVoipEvent() failed: we do not have opponentDeviceInfo"));
2098
+ return;
2099
+ }
2100
+
2101
+ // TODO: Here we were sending the event to the opponent's device as a to-device message with BriijClient.encryptAndSendToDevice.
2102
+ // However due to the switch to Rust cryptography we need to migrate to the new encryptToDeviceMessages API.
2103
+ throw new Error("Unimplemented");
2104
+ } else {
2105
+ yield _this26.client.sendToDevice(eventType, new Map([[userId, new Map([[_this26.opponentDeviceId, _content]])]]));
2106
+ }
2107
+ } else {
2108
+ var _this26$getOpponentMe2;
2109
+ _this26.emit(CallEvent.SendVoipEvent, {
2110
+ type: "sendEvent",
2111
+ eventType,
2112
+ roomId: _this26.roomId,
2113
+ content: realContent,
2114
+ userId: _this26.invitee || ((_this26$getOpponentMe2 = _this26.getOpponentMember()) === null || _this26$getOpponentMe2 === void 0 ? void 0 : _this26$getOpponentMe2.userId)
2115
+ }, _this26);
2116
+ yield _this26.client.sendEvent(_this26.roomId, eventType, realContent);
2117
+ }
2118
+ })();
2119
+ }
2120
+
2121
+ /**
2122
+ * Queue a candidate to be sent
2123
+ * @param content - The candidate to queue up, or null if candidates have finished being generated
2124
+ * and end-of-candidates should be signalled
2125
+ */
2126
+ queueCandidate(content) {
2127
+ // We partially de-trickle candidates by waiting for `delay` before sending them
2128
+ // amalgamated, in order to avoid sending too many m.call.candidates events and hitting
2129
+ // rate limits in Matrix.
2130
+ // In practice, it'd be better to remove rate limits for m.call.*
2131
+
2132
+ // N.B. this deliberately lets you queue and send blank candidates, which MSC2746
2133
+ // currently proposes as the way to indicate that candidate gathering is complete.
2134
+ // This will hopefully be changed to an explicit rather than implicit notification
2135
+ // shortly.
2136
+ if (content) {
2137
+ this.candidateSendQueue.push(content);
2138
+ } else {
2139
+ this.candidatesEnded = true;
2140
+ }
2141
+
2142
+ // Don't send the ICE candidates yet if the call is in the ringing state: this
2143
+ // means we tried to pick (ie. started generating candidates) and then failed to
2144
+ // send the answer and went back to the ringing state. Queue up the candidates
2145
+ // to send if we successfully send the answer.
2146
+ // Equally don't send if we haven't yet sent the answer because we can send the
2147
+ // first batch of candidates along with the answer
2148
+ if (this.state === CallState.Ringing || !this.inviteOrAnswerSent) return;
2149
+
2150
+ // MSC2746 recommends these values (can be quite long when calling because the
2151
+ // callee will need a while to answer the call)
2152
+ var delay = this.direction === CallDirection.Inbound ? 500 : 2000;
2153
+ if (this.candidateSendTries === 0) {
2154
+ setTimeout(() => {
2155
+ this.sendCandidateQueue();
2156
+ }, delay);
2157
+ }
2158
+ }
2159
+
2160
+ // Discard all non-end-of-candidates messages
2161
+ // Return the number of candidate messages that were discarded.
2162
+ // Call this method before sending an invite or answer message
2163
+ discardDuplicateCandidates() {
2164
+ var discardCount = 0;
2165
+ var newQueue = [];
2166
+ for (var i = 0; i < this.candidateSendQueue.length; i++) {
2167
+ var candidate = this.candidateSendQueue[i];
2168
+ if (candidate.candidate === "") {
2169
+ newQueue.push(candidate);
2170
+ } else {
2171
+ discardCount++;
2172
+ }
2173
+ }
2174
+ this.candidateSendQueue = newQueue;
2175
+ return discardCount;
2176
+ }
2177
+
2178
+ /*
2179
+ * Transfers this call to another user
2180
+ */
2181
+ transfer(targetUserId) {
2182
+ var _this27 = this;
2183
+ return _asyncToGenerator(function* () {
2184
+ // Fetch the target user's global profile info: their room avatar / displayname
2185
+ // could be different in whatever room we share with them.
2186
+ var profileInfo = yield _this27.client.getProfileInfo(targetUserId);
2187
+ var replacementId = genCallID();
2188
+ var body = {
2189
+ replacement_id: genCallID(),
2190
+ target_user: {
2191
+ id: targetUserId,
2192
+ display_name: profileInfo.displayname,
2193
+ avatar_url: profileInfo.avatar_url
2194
+ },
2195
+ create_call: replacementId
2196
+ };
2197
+ yield _this27.sendVoipEvent(EventType.CallReplaces, body);
2198
+ yield _this27.terminate(CallParty.Local, CallErrorCode.Transferred, true);
2199
+ })();
2200
+ }
2201
+
2202
+ /*
2203
+ * Transfers this call to the target call, effectively 'joining' the
2204
+ * two calls (so the remote parties on each call are connected together).
2205
+ */
2206
+ transferToCall(transferTargetCall) {
2207
+ var _this28 = this;
2208
+ return _asyncToGenerator(function* () {
2209
+ var _transferTargetCall$g, _this28$getOpponentMe;
2210
+ var targetUserId = (_transferTargetCall$g = transferTargetCall.getOpponentMember()) === null || _transferTargetCall$g === void 0 ? void 0 : _transferTargetCall$g.userId;
2211
+ var targetProfileInfo = targetUserId ? yield _this28.client.getProfileInfo(targetUserId) : undefined;
2212
+ var opponentUserId = (_this28$getOpponentMe = _this28.getOpponentMember()) === null || _this28$getOpponentMe === void 0 ? void 0 : _this28$getOpponentMe.userId;
2213
+ var transfereeProfileInfo = opponentUserId ? yield _this28.client.getProfileInfo(opponentUserId) : undefined;
2214
+ var newCallId = genCallID();
2215
+ var bodyToTransferTarget = {
2216
+ // the replacements on each side have their own ID, and it's distinct from the
2217
+ // ID of the new call (but we can use the same function to generate it)
2218
+ replacement_id: genCallID(),
2219
+ target_user: {
2220
+ id: opponentUserId,
2221
+ display_name: transfereeProfileInfo === null || transfereeProfileInfo === void 0 ? void 0 : transfereeProfileInfo.displayname,
2222
+ avatar_url: transfereeProfileInfo === null || transfereeProfileInfo === void 0 ? void 0 : transfereeProfileInfo.avatar_url
2223
+ },
2224
+ await_call: newCallId
2225
+ };
2226
+ yield transferTargetCall.sendVoipEvent(EventType.CallReplaces, bodyToTransferTarget);
2227
+ var bodyToTransferee = {
2228
+ replacement_id: genCallID(),
2229
+ target_user: {
2230
+ id: targetUserId,
2231
+ display_name: targetProfileInfo === null || targetProfileInfo === void 0 ? void 0 : targetProfileInfo.displayname,
2232
+ avatar_url: targetProfileInfo === null || targetProfileInfo === void 0 ? void 0 : targetProfileInfo.avatar_url
2233
+ },
2234
+ create_call: newCallId
2235
+ };
2236
+ yield _this28.sendVoipEvent(EventType.CallReplaces, bodyToTransferee);
2237
+ yield _this28.terminate(CallParty.Local, CallErrorCode.Transferred, true);
2238
+ yield transferTargetCall.terminate(CallParty.Local, CallErrorCode.Transferred, true);
2239
+ })();
2240
+ }
2241
+ terminate(hangupParty, hangupReason, shouldEmit) {
2242
+ var _this29 = this;
2243
+ return _asyncToGenerator(function* () {
2244
+ var _this29$stats;
2245
+ if (_this29.callHasEnded()) return;
2246
+ _this29.hangupParty = hangupParty;
2247
+ _this29.hangupReason = hangupReason;
2248
+ _this29.state = CallState.Ended;
2249
+ if (_this29.inviteTimeout) {
2250
+ clearTimeout(_this29.inviteTimeout);
2251
+ _this29.inviteTimeout = undefined;
2252
+ }
2253
+ if (_this29.iceDisconnectedTimeout !== undefined) {
2254
+ clearTimeout(_this29.iceDisconnectedTimeout);
2255
+ _this29.iceDisconnectedTimeout = undefined;
2256
+ }
2257
+ if (_this29.callLengthInterval) {
2258
+ clearInterval(_this29.callLengthInterval);
2259
+ _this29.callLengthInterval = undefined;
2260
+ }
2261
+ if (_this29.stopVideoTrackTimer !== undefined) {
2262
+ clearTimeout(_this29.stopVideoTrackTimer);
2263
+ _this29.stopVideoTrackTimer = undefined;
2264
+ }
2265
+ for (var [stream, listener] of _this29.removeTrackListeners) {
2266
+ stream.removeEventListener("removetrack", listener);
2267
+ }
2268
+ _this29.removeTrackListeners.clear();
2269
+ _this29.callStatsAtEnd = yield _this29.collectCallStats();
2270
+
2271
+ // Order is important here: first we stopAllMedia() and only then we can deleteAllFeeds()
2272
+ _this29.stopAllMedia();
2273
+ _this29.deleteAllFeeds();
2274
+ if (_this29.peerConn && _this29.peerConn.signalingState !== "closed") {
2275
+ _this29.peerConn.close();
2276
+ }
2277
+ (_this29$stats = _this29.stats) === null || _this29$stats === void 0 || _this29$stats.removeStatsReportGatherer(_this29.callId);
2278
+ if (shouldEmit) {
2279
+ _this29.emit(CallEvent.Hangup, _this29);
2280
+ }
2281
+ _this29.client.callEventHandler.calls.delete(_this29.callId);
2282
+ })();
2283
+ }
2284
+ stopAllMedia() {
2285
+ logger.debug("Call ".concat(this.callId, " stopAllMedia() running"));
2286
+ for (var feed of this.feeds) {
2287
+ // Slightly awkward as local feed need to go via the correct method on
2288
+ // the MediaHandler so they get removed from MediaHandler (remote tracks
2289
+ // don't)
2290
+ // NB. We clone local streams when passing them to individual calls in a group
2291
+ // call, so we can (and should) stop the clones once we no longer need them:
2292
+ // the other clones will continue fine.
2293
+ if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Usermedia) {
2294
+ this.client.getMediaHandler().stopUserMediaStream(feed.stream);
2295
+ } else if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Screenshare) {
2296
+ this.client.getMediaHandler().stopScreensharingStream(feed.stream);
2297
+ } else if (!feed.isLocal()) {
2298
+ logger.debug("Call ".concat(this.callId, " stopAllMedia() stopping stream (streamId=").concat(feed.stream.id, ")"));
2299
+ for (var track of feed.stream.getTracks()) {
2300
+ track.stop();
2301
+ }
2302
+ }
2303
+ }
2304
+ }
2305
+ checkForErrorListener() {
2306
+ if (this.listeners(EventEmitterEvents.Error).length === 0) {
2307
+ throw new Error("You MUST attach an error listener using call.on('error', function() {})");
2308
+ }
2309
+ }
2310
+ sendCandidateQueue() {
2311
+ var _this30 = this;
2312
+ return _asyncToGenerator(function* () {
2313
+ if (_this30.candidateSendQueue.length === 0 || _this30.callHasEnded()) {
2314
+ return;
2315
+ }
2316
+ var candidates = _this30.candidateSendQueue;
2317
+ _this30.candidateSendQueue = [];
2318
+ ++_this30.candidateSendTries;
2319
+ var content = {
2320
+ candidates: candidates.map(candidate => candidate.toJSON())
2321
+ };
2322
+ if (_this30.candidatesEnded) {
2323
+ // If there are no more candidates, signal this by adding an empty string candidate
2324
+ content.candidates.push({
2325
+ candidate: ""
2326
+ });
2327
+ }
2328
+ logger.debug("Call ".concat(_this30.callId, " sendCandidateQueue() attempting to send ").concat(candidates.length, " candidates"));
2329
+ try {
2330
+ yield _this30.sendVoipEvent(EventType.CallCandidates, content);
2331
+ // reset our retry count if we have successfully sent our candidates
2332
+ // otherwise queueCandidate() will refuse to try to flush the queue
2333
+ _this30.candidateSendTries = 0;
2334
+
2335
+ // Try to send candidates again just in case we received more candidates while sending.
2336
+ _this30.sendCandidateQueue();
2337
+ } catch (error) {
2338
+ // don't retry this event: we'll send another one later as we might
2339
+ // have more candidates by then.
2340
+ if (error instanceof BriijError && error.event) _this30.client.cancelPendingEvent(error.event);
2341
+
2342
+ // put all the candidates we failed to send back in the queue
2343
+ _this30.candidateSendQueue.push(...candidates);
2344
+ if (_this30.candidateSendTries > 5) {
2345
+ logger.debug("Call ".concat(_this30.callId, " sendCandidateQueue() failed to send candidates on attempt ").concat(_this30.candidateSendTries, ". Giving up on this call."), error);
2346
+ var code = CallErrorCode.SignallingFailed;
2347
+ var message = "Signalling failed";
2348
+ _this30.emit(CallEvent.Error, new CallError(code, message, error), _this30);
2349
+ _this30.hangup(code, false);
2350
+ return;
2351
+ }
2352
+ var delayMs = 500 * Math.pow(2, _this30.candidateSendTries);
2353
+ ++_this30.candidateSendTries;
2354
+ logger.debug("Call ".concat(_this30.callId, " sendCandidateQueue() failed to send candidates. Retrying in ").concat(delayMs, "ms"), error);
2355
+ setTimeout(() => {
2356
+ _this30.sendCandidateQueue();
2357
+ }, delayMs);
2358
+ }
2359
+ })();
2360
+ }
2361
+
2362
+ /**
2363
+ * Place a call to this room.
2364
+ * @throws if you have not specified a listener for 'error' events.
2365
+ * @throws if have passed audio=false.
2366
+ */
2367
+ placeCall(audio, video) {
2368
+ var _this31 = this;
2369
+ return _asyncToGenerator(function* () {
2370
+ if (!audio) {
2371
+ throw new Error("You CANNOT start a call without audio");
2372
+ }
2373
+ _this31.state = CallState.WaitLocalMedia;
2374
+ var callFeed;
2375
+ try {
2376
+ var _this31$client$getDev;
2377
+ var stream = yield _this31.client.getMediaHandler().getUserMediaStream(audio, video);
2378
+
2379
+ // make sure all the tracks are enabled (same as pushNewLocalFeed -
2380
+ // we probably ought to just have one code path for adding streams)
2381
+ setTracksEnabled(stream.getAudioTracks(), true);
2382
+ setTracksEnabled(stream.getVideoTracks(), true);
2383
+ callFeed = new CallFeed({
2384
+ client: _this31.client,
2385
+ roomId: _this31.roomId,
2386
+ userId: _this31.client.getUserId(),
2387
+ deviceId: (_this31$client$getDev = _this31.client.getDeviceId()) !== null && _this31$client$getDev !== void 0 ? _this31$client$getDev : undefined,
2388
+ stream,
2389
+ purpose: SDPStreamMetadataPurpose.Usermedia,
2390
+ audioMuted: false,
2391
+ videoMuted: false
2392
+ });
2393
+ } catch (e) {
2394
+ _this31.getUserMediaFailed(e);
2395
+ return;
2396
+ }
2397
+ try {
2398
+ yield _this31.placeCallWithCallFeeds([callFeed]);
2399
+ } catch (e) {
2400
+ _this31.placeCallFailed(e);
2401
+ return;
2402
+ }
2403
+ })();
2404
+ }
2405
+
2406
+ /**
2407
+ * Place a call to this room with call feed.
2408
+ * @param callFeeds - to use
2409
+ * @throws if you have not specified a listener for 'error' events.
2410
+ * @throws if have passed audio=false.
2411
+ */
2412
+ placeCallWithCallFeeds(callFeeds) {
2413
+ var _arguments2 = arguments,
2414
+ _this32 = this;
2415
+ return _asyncToGenerator(function* () {
2416
+ var requestScreenshareFeed = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : false;
2417
+ _this32.checkForErrorListener();
2418
+ _this32.direction = CallDirection.Outbound;
2419
+ yield _this32.initOpponentCrypto();
2420
+
2421
+ // XXX Find a better way to do this
2422
+ _this32.client.callEventHandler.calls.set(_this32.callId, _this32);
2423
+
2424
+ // make sure we have valid turn creds. Unless something's gone wrong, it should
2425
+ // poll and keep the credentials valid so this should be instant.
2426
+ var haveTurnCreds = yield _this32.client.checkTurnServers();
2427
+ if (!haveTurnCreds) {
2428
+ logger.warn("Call ".concat(_this32.callId, " placeCallWithCallFeeds() failed to get TURN credentials! Proceeding with call anyway..."));
2429
+ }
2430
+
2431
+ // create the peer connection now so it can be gathering candidates while we get user
2432
+ // media (assuming a candidate pool size is configured)
2433
+ _this32.peerConn = _this32.createPeerConnection();
2434
+ _this32.emit(CallEvent.PeerConnectionCreated, _this32.peerConn, _this32);
2435
+ _this32.gotCallFeedsForInvite(callFeeds, requestScreenshareFeed);
2436
+ })();
2437
+ }
2438
+ createPeerConnection() {
2439
+ var _this$stats;
2440
+ var pc = new window.RTCPeerConnection({
2441
+ iceTransportPolicy: this.forceTURN ? "relay" : undefined,
2442
+ iceServers: this.turnServers.length ? this.turnServers : undefined,
2443
+ iceCandidatePoolSize: this.client.iceCandidatePoolSize,
2444
+ bundlePolicy: "max-bundle"
2445
+ });
2446
+
2447
+ // 'connectionstatechange' would be better, but firefox doesn't implement that.
2448
+ pc.addEventListener("iceconnectionstatechange", this.onIceConnectionStateChanged);
2449
+ pc.addEventListener("signalingstatechange", this.onSignallingStateChanged);
2450
+ pc.addEventListener("icecandidate", this.gotLocalIceCandidate);
2451
+ pc.addEventListener("icegatheringstatechange", this.onIceGatheringStateChange);
2452
+ pc.addEventListener("track", this.onTrack);
2453
+ pc.addEventListener("negotiationneeded", this.onNegotiationNeeded);
2454
+ pc.addEventListener("datachannel", this.onDataChannel);
2455
+ var opponentMember = this.getOpponentMember();
2456
+ var opponentMemberId = opponentMember ? opponentMember.userId : "unknown";
2457
+ (_this$stats = this.stats) === null || _this$stats === void 0 || _this$stats.addStatsReportGatherer(this.callId, opponentMemberId, pc);
2458
+ return pc;
2459
+ }
2460
+ partyIdMatches(msg) {
2461
+ // They must either match or both be absent (in which case opponentPartyId will be null)
2462
+ // Also we ignore party IDs on the invite/offer if the version is 0, so we must do the same
2463
+ // here and use null if the version is 0 (woe betide any opponent sending messages in the
2464
+ // same call with different versions)
2465
+ var msgPartyId = msg.version === 0 ? null : msg.party_id || null;
2466
+ return msgPartyId === this.opponentPartyId;
2467
+ }
2468
+
2469
+ // Commits to an opponent for the call
2470
+ // ev: An invite or answer event
2471
+ chooseOpponent(ev) {
2472
+ var _getMember;
2473
+ // I choo-choo-choose you
2474
+ var msg = ev.getContent();
2475
+ logger.debug("Call ".concat(this.callId, " chooseOpponent() running (partyId=").concat(msg.party_id, ")"));
2476
+ this.opponentVersion = msg.version;
2477
+ if (this.opponentVersion === 0) {
2478
+ // set to null to indicate that we've chosen an opponent, but because
2479
+ // they're v0 they have no party ID (even if they sent one, we're ignoring it)
2480
+ this.opponentPartyId = null;
2481
+ } else {
2482
+ // set to their party ID, or if they're naughty and didn't send one despite
2483
+ // not being v0, set it to null to indicate we picked an opponent with no
2484
+ // party ID
2485
+ this.opponentPartyId = msg.party_id || null;
2486
+ }
2487
+ this.opponentCaps = msg.capabilities || {};
2488
+ this.opponentMember = (_getMember = this.client.getRoom(this.roomId).getMember(ev.getSender())) !== null && _getMember !== void 0 ? _getMember : undefined;
2489
+ if (this.opponentMember) {
2490
+ var _this$stats2;
2491
+ (_this$stats2 = this.stats) === null || _this$stats2 === void 0 || _this$stats2.updateOpponentMember(this.callId, this.opponentMember.userId);
2492
+ }
2493
+ }
2494
+ addBufferedIceCandidates() {
2495
+ var _this33 = this;
2496
+ return _asyncToGenerator(function* () {
2497
+ var bufferedCandidates = _this33.remoteCandidateBuffer.get(_this33.opponentPartyId);
2498
+ if (bufferedCandidates) {
2499
+ logger.info("Call ".concat(_this33.callId, " addBufferedIceCandidates() adding ").concat(bufferedCandidates.length, " buffered candidates for opponent ").concat(_this33.opponentPartyId));
2500
+ yield _this33.addIceCandidates(bufferedCandidates);
2501
+ }
2502
+ _this33.remoteCandidateBuffer.clear();
2503
+ })();
2504
+ }
2505
+ addIceCandidates(candidates) {
2506
+ var _this34 = this;
2507
+ return _asyncToGenerator(function* () {
2508
+ for (var candidate of candidates) {
2509
+ if ((candidate.sdpMid === null || candidate.sdpMid === undefined) && (candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined)) {
2510
+ logger.debug("Call ".concat(_this34.callId, " addIceCandidates() got remote ICE end-of-candidates"));
2511
+ } else {
2512
+ logger.debug("Call ".concat(_this34.callId, " addIceCandidates() got remote ICE candidate (sdpMid=").concat(candidate.sdpMid, ", candidate=").concat(candidate.candidate, ")"));
2513
+ }
2514
+ try {
2515
+ yield _this34.peerConn.addIceCandidate(candidate);
2516
+ } catch (err) {
2517
+ if (!_this34.ignoreOffer) {
2518
+ logger.info("Call ".concat(_this34.callId, " addIceCandidates() failed to add remote ICE candidate"), err);
2519
+ } else {
2520
+ logger.debug("Call ".concat(_this34.callId, " addIceCandidates() failed to add remote ICE candidate because ignoring offer"), err);
2521
+ }
2522
+ }
2523
+ }
2524
+ })();
2525
+ }
2526
+ get hasPeerConnection() {
2527
+ return Boolean(this.peerConn);
2528
+ }
2529
+ initStats(stats) {
2530
+ var peerId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unknown";
2531
+ this.stats = stats;
2532
+ this.stats.start();
2533
+ }
2534
+ }
2535
+ export function setTracksEnabled(tracks, enabled) {
2536
+ for (var track of tracks) {
2537
+ track.enabled = enabled;
2538
+ }
2539
+ }
2540
+ export function supportsBriijCall() {
2541
+ // typeof prevents Node from erroring on an undefined reference
2542
+ if (typeof window === "undefined" || typeof document === "undefined") {
2543
+ // NB. We don't log here as apps try to create a call object as a test for
2544
+ // whether calls are supported, so we shouldn't fill the logs up.
2545
+ return false;
2546
+ }
2547
+
2548
+ // Firefox throws on so little as accessing the RTCPeerConnection when operating in a secure mode.
2549
+ // There's some information at https://bugzilla.mozilla.org/show_bug.cgi?id=1542616 though the concern
2550
+ // is that the browser throwing a SecurityError will brick the client creation process.
2551
+ try {
2552
+ var _ref2, _ref3, _window$RTCPeerConnec;
2553
+ var supported = Boolean((_ref2 = (_ref3 = (_window$RTCPeerConnec = window.RTCPeerConnection) !== null && _window$RTCPeerConnec !== void 0 ? _window$RTCPeerConnec : window.RTCSessionDescription) !== null && _ref3 !== void 0 ? _ref3 : window.RTCIceCandidate) !== null && _ref2 !== void 0 ? _ref2 : navigator.mediaDevices);
2554
+ if (!supported) {
2555
+ /* istanbul ignore if */ // Adds a lot of noise to test runs, so disable logging there.
2556
+ if (process.env.NODE_ENV !== "test") {
2557
+ logger.error("WebRTC is not supported in this browser / environment");
2558
+ }
2559
+ return false;
2560
+ }
2561
+ } catch (e) {
2562
+ logger.error("Exception thrown when trying to access WebRTC", e);
2563
+ return false;
2564
+ }
2565
+ return true;
2566
+ }
2567
+
2568
+ /**
2569
+ * DEPRECATED
2570
+ * Use client.createCall()
2571
+ *
2572
+ * Create a new Matrix call for the browser.
2573
+ * @param client - The client instance to use.
2574
+ * @param roomId - The room the call is in.
2575
+ * @param options - DEPRECATED optional options map.
2576
+ * @returns the call or null if the browser doesn't support calling.
2577
+ */
2578
+ export function createNewBriijCall(client, roomId, options) {
2579
+ if (!supportsBriijCall()) return null;
2580
+ var optionsForceTURN = options ? options.forceTURN : false;
2581
+ var opts = {
2582
+ client: client,
2583
+ roomId: roomId,
2584
+ invitee: options === null || options === void 0 ? void 0 : options.invitee,
2585
+ turnServers: client.getTurnServers(),
2586
+ // call level options
2587
+ forceTURN: client.forceTURN || optionsForceTURN,
2588
+ opponentDeviceId: options === null || options === void 0 ? void 0 : options.opponentDeviceId,
2589
+ opponentSessionId: options === null || options === void 0 ? void 0 : options.opponentSessionId,
2590
+ groupCallId: options === null || options === void 0 ? void 0 : options.groupCallId
2591
+ };
2592
+ var call = new BriijCall(opts);
2593
+ client.reEmitter.reEmit(call, Object.values(CallEvent));
2594
+ return call;
2595
+ }
2596
+ //# sourceMappingURL=call.js.map