@unwanted/matrix-sdk-mini 34.12.0-1

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