matrix-js-sdk 34.2.0 → 34.3.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/git-revision.txt +1 -1
  2. package/lib/@types/global.d.js.map +1 -1
  3. package/lib/@types/requests.d.ts +37 -0
  4. package/lib/@types/requests.d.ts.map +1 -1
  5. package/lib/@types/requests.js +28 -1
  6. package/lib/@types/requests.js.map +1 -1
  7. package/lib/client.d.ts +48 -4
  8. package/lib/client.d.ts.map +1 -1
  9. package/lib/client.js +412 -257
  10. package/lib/client.js.map +1 -1
  11. package/lib/crypto/algorithms/base.d.ts +0 -2
  12. package/lib/crypto/algorithms/base.d.ts.map +1 -1
  13. package/lib/crypto/algorithms/base.js +0 -4
  14. package/lib/crypto/algorithms/base.js.map +1 -1
  15. package/lib/digest.d.ts +10 -0
  16. package/lib/digest.d.ts.map +1 -0
  17. package/lib/digest.js +40 -0
  18. package/lib/digest.js.map +1 -0
  19. package/lib/embedded.d.ts +24 -1
  20. package/lib/embedded.d.ts.map +1 -1
  21. package/lib/embedded.js +84 -26
  22. package/lib/embedded.js.map +1 -1
  23. package/lib/matrixrtc/MatrixRTCSession.d.ts +2 -0
  24. package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
  25. package/lib/matrixrtc/MatrixRTCSession.js +44 -15
  26. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
  27. package/lib/matrixrtc/index.d.ts +7 -0
  28. package/lib/matrixrtc/index.d.ts.map +1 -0
  29. package/lib/matrixrtc/index.js +23 -0
  30. package/lib/matrixrtc/index.js.map +1 -0
  31. package/lib/models/event.js.map +1 -1
  32. package/lib/oidc/authorize.d.ts.map +1 -1
  33. package/lib/oidc/authorize.js +4 -3
  34. package/lib/oidc/authorize.js.map +1 -1
  35. package/lib/rust-crypto/RoomEncryptor.d.ts +1 -1
  36. package/lib/rust-crypto/RoomEncryptor.d.ts.map +1 -1
  37. package/lib/rust-crypto/RoomEncryptor.js +6 -2
  38. package/lib/rust-crypto/RoomEncryptor.js.map +1 -1
  39. package/lib/rust-crypto/index.js +1 -0
  40. package/lib/rust-crypto/index.js.map +1 -1
  41. package/lib/rust-crypto/rust-crypto.d.ts +9 -0
  42. package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
  43. package/lib/rust-crypto/rust-crypto.js +83 -58
  44. package/lib/rust-crypto/rust-crypto.js.map +1 -1
  45. package/lib/sync-accumulator.js.map +1 -1
  46. package/lib/sync.d.ts.map +1 -1
  47. package/lib/sync.js.map +1 -1
  48. package/package.json +6 -6
  49. package/src/@types/global.d.ts +0 -45
  50. package/src/@types/requests.ts +50 -0
  51. package/src/client.ts +237 -46
  52. package/src/crypto/algorithms/base.ts +0 -4
  53. package/src/digest.ts +34 -0
  54. package/src/embedded.ts +109 -5
  55. package/src/matrixrtc/MatrixRTCSession.ts +52 -20
  56. package/src/matrixrtc/index.ts +22 -0
  57. package/src/models/event.ts +1 -1
  58. package/src/oidc/authorize.ts +4 -7
  59. package/src/rust-crypto/RoomEncryptor.ts +10 -6
  60. package/src/rust-crypto/index.ts +3 -0
  61. package/src/rust-crypto/rust-crypto.ts +51 -24
  62. package/src/sync-accumulator.ts +1 -1
  63. package/src/sync.ts +3 -1
@@ -44,7 +44,6 @@ export declare abstract class EncryptionAlgorithm {
44
44
  protected readonly crypto: Crypto;
45
45
  protected readonly olmDevice: OlmDevice;
46
46
  protected readonly baseApis: MatrixClient;
47
- protected readonly roomId?: string;
48
47
  /**
49
48
  * @param params - parameters
50
49
  */
@@ -86,7 +85,6 @@ export declare abstract class DecryptionAlgorithm {
86
85
  protected readonly crypto: Crypto;
87
86
  protected readonly olmDevice: OlmDevice;
88
87
  protected readonly baseApis: MatrixClient;
89
- protected readonly roomId?: string;
90
88
  constructor(params: DecryptionClassParams);
91
89
  /**
92
90
  * Decrypt an event
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/crypto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defineProperty(this, "crypto", void 0);
42
42
  _defineProperty(this, "olmDevice", void 0);
43
43
  _defineProperty(this, "baseApis", void 0);
44
- _defineProperty(this, "roomId", void 0);
45
44
  this.userId = params.userId;
46
45
  this.deviceId = params.deviceId;
47
46
  this.crypto = params.crypto;
48
47
  this.olmDevice = params.olmDevice;
49
48
  this.baseApis = params.baseApis;
50
- this.roomId = params.roomId;
51
49
  }
52
50
 
53
51
  /**
@@ -88,12 +86,10 @@ export class DecryptionAlgorithm {
88
86
  _defineProperty(this, "crypto", void 0);
89
87
  _defineProperty(this, "olmDevice", void 0);
90
88
  _defineProperty(this, "baseApis", void 0);
91
- _defineProperty(this, "roomId", void 0);
92
89
  this.userId = params.userId;
93
90
  this.crypto = params.crypto;
94
91
  this.olmDevice = params.olmDevice;
95
92
  this.baseApis = params.baseApis;
96
- this.roomId = params.roomId;
97
93
  }
98
94
 
99
95
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","names":["ENCRYPTION_CLASSES","Map","DECRYPTION_CLASSES","EncryptionAlgorithm","constructor","params","_defineProperty","userId","deviceId","crypto","olmDevice","baseApis","roomId","prepareToEncrypt","room","onRoomMembership","event","member","oldMembership","DecryptionAlgorithm","onRoomKeyEvent","_asyncToGenerator","importRoomKey","session","opts","hasKeysForKeyRequest","keyRequest","Promise","resolve","shareKeysWithDevice","Error","retryDecryptionFromSender","senderKey","UnknownDeviceError","msg","devices","name","registerAlgorithm","algorithm","encryptor","decryptor","set","DecryptionError"],"sources":["../../../src/crypto/algorithms/base.ts"],"sourcesContent":["/*\nCopyright 2016 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Internal module. Defines the base classes of the encryption implementations\n */\n\nimport type { IMegolmSessionData } from \"../../@types/crypto\";\nimport { MatrixClient } from \"../../client\";\nimport { Room } from \"../../models/room\";\nimport { OlmDevice } from \"../OlmDevice\";\nimport { IContent, MatrixEvent, RoomMember } from \"../../matrix\";\nimport { Crypto, IEncryptedContent, IEventDecryptionResult, IncomingRoomKeyRequest } from \"..\";\nimport { DeviceInfo } from \"../deviceinfo\";\nimport { IRoomEncryption } from \"../RoomList\";\nimport { DeviceInfoMap } from \"../DeviceList\";\n\n/**\n * Map of registered encryption algorithm classes. A map from string to {@link EncryptionAlgorithm} class\n */\nexport const ENCRYPTION_CLASSES = new Map<string, new (params: IParams) => EncryptionAlgorithm>();\n\nexport type DecryptionClassParams<P extends IParams = IParams> = Omit<P, \"deviceId\" | \"config\">;\n\n/**\n * map of registered encryption algorithm classes. Map from string to {@link DecryptionAlgorithm} class\n */\nexport const DECRYPTION_CLASSES = new Map<string, new (params: DecryptionClassParams) => DecryptionAlgorithm>();\n\nexport interface IParams {\n /** The UserID for the local user */\n userId: string;\n /** The identifier for this device. */\n deviceId: string;\n /** crypto core */\n crypto: Crypto;\n /** olm.js wrapper */\n olmDevice: OlmDevice;\n /** base matrix api interface */\n baseApis: MatrixClient;\n /** The ID of the room we will be sending to */\n roomId?: string;\n /** The body of the m.room.encryption event */\n config: IRoomEncryption & object;\n}\n\n/**\n * base type for encryption implementations\n */\nexport abstract class EncryptionAlgorithm {\n protected readonly userId: string;\n protected readonly deviceId: string;\n protected readonly crypto: Crypto;\n protected readonly olmDevice: OlmDevice;\n protected readonly baseApis: MatrixClient;\n protected readonly roomId?: string;\n\n /**\n * @param params - parameters\n */\n public constructor(params: IParams) {\n this.userId = params.userId;\n this.deviceId = params.deviceId;\n this.crypto = params.crypto;\n this.olmDevice = params.olmDevice;\n this.baseApis = params.baseApis;\n this.roomId = params.roomId;\n }\n\n /**\n * Perform any background tasks that can be done before a message is ready to\n * send, in order to speed up sending of the message.\n *\n * @param room - the room the event is in\n */\n public prepareToEncrypt(room: Room): void {}\n\n /**\n * Encrypt a message event\n *\n * @public\n *\n * @param content - event content\n *\n * @returns Promise which resolves to the new event body\n */\n public abstract encryptMessage(room: Room, eventType: string, content: IContent): Promise<IEncryptedContent>;\n\n /**\n * Called when the membership of a member of the room changes.\n *\n * @param event - event causing the change\n * @param member - user whose membership changed\n * @param oldMembership - previous membership\n * @public\n */\n public onRoomMembership(event: MatrixEvent, member: RoomMember, oldMembership?: string): void {}\n\n public reshareKeyWithDevice?(\n senderKey: string,\n sessionId: string,\n userId: string,\n device: DeviceInfo,\n ): Promise<void>;\n\n public forceDiscardSession?(): void;\n}\n\n/**\n * base type for decryption implementations\n */\nexport abstract class DecryptionAlgorithm {\n protected readonly userId: string;\n protected readonly crypto: Crypto;\n protected readonly olmDevice: OlmDevice;\n protected readonly baseApis: MatrixClient;\n protected readonly roomId?: string;\n\n public constructor(params: DecryptionClassParams) {\n this.userId = params.userId;\n this.crypto = params.crypto;\n this.olmDevice = params.olmDevice;\n this.baseApis = params.baseApis;\n this.roomId = params.roomId;\n }\n\n /**\n * Decrypt an event\n *\n * @param event - undecrypted event\n *\n * @returns promise which\n * resolves once we have finished decrypting. Rejects with an\n * `algorithms.DecryptionError` if there is a problem decrypting the event.\n */\n public abstract decryptEvent(event: MatrixEvent): Promise<IEventDecryptionResult>;\n\n /**\n * Handle a key event\n *\n * @param params - event key event\n */\n public async onRoomKeyEvent(params: MatrixEvent): Promise<void> {\n // ignore by default\n }\n\n /**\n * Import a room key\n *\n * @param opts - object\n */\n public async importRoomKey(session: IMegolmSessionData, opts: object): Promise<void> {\n // ignore by default\n }\n\n /**\n * Determine if we have the keys necessary to respond to a room key request\n *\n * @returns true if we have the keys and could (theoretically) share\n * them; else false.\n */\n public hasKeysForKeyRequest(keyRequest: IncomingRoomKeyRequest): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n /**\n * Send the response to a room key request\n *\n */\n public shareKeysWithDevice(keyRequest: IncomingRoomKeyRequest): void {\n throw new Error(\"shareKeysWithDevice not supported for this DecryptionAlgorithm\");\n }\n\n /**\n * Retry decrypting all the events from a sender that haven't been\n * decrypted yet.\n *\n * @param senderKey - the sender's key\n */\n public async retryDecryptionFromSender(senderKey: string): Promise<boolean> {\n // ignore by default\n return false;\n }\n\n public onRoomKeyWithheldEvent?(event: MatrixEvent): Promise<void>;\n public sendSharedHistoryInboundSessions?(devicesByUser: Map<string, DeviceInfo[]>): Promise<void>;\n}\n\nexport class UnknownDeviceError extends Error {\n /**\n * Exception thrown specifically when we want to warn the user to consider\n * the security of their conversation before continuing\n *\n * @param msg - message describing the problem\n * @param devices - set of unknown devices per user we're warning about\n */\n public constructor(\n msg: string,\n public readonly devices: DeviceInfoMap,\n public event?: MatrixEvent,\n ) {\n super(msg);\n this.name = \"UnknownDeviceError\";\n this.devices = devices;\n }\n}\n\n/**\n * Registers an encryption/decryption class for a particular algorithm\n *\n * @param algorithm - algorithm tag to register for\n *\n * @param encryptor - {@link EncryptionAlgorithm} implementation\n *\n * @param decryptor - {@link DecryptionAlgorithm} implementation\n */\nexport function registerAlgorithm<P extends IParams = IParams>(\n algorithm: string,\n encryptor: new (params: P) => EncryptionAlgorithm,\n decryptor: new (params: DecryptionClassParams<P>) => DecryptionAlgorithm,\n): void {\n ENCRYPTION_CLASSES.set(algorithm, encryptor as new (params: IParams) => EncryptionAlgorithm);\n DECRYPTION_CLASSES.set(algorithm, decryptor as new (params: DecryptionClassParams) => DecryptionAlgorithm);\n}\n\n/* Re-export for backwards compatibility. Deprecated: this is an internal class. */\nexport { DecryptionError } from \"../../common-crypto/CryptoBackend\";\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAYA;AACA;AACA;AACA,OAAO,IAAMA,kBAAkB,GAAG,IAAIC,GAAG,CAAuD,CAAC;AAIjG;AAC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eAAe,QAAQ,mCAAmC","ignoreList":[]}
1
+ {"version":3,"file":"base.js","names":["ENCRYPTION_CLASSES","Map","DECRYPTION_CLASSES","EncryptionAlgorithm","constructor","params","_defineProperty","userId","deviceId","crypto","olmDevice","baseApis","prepareToEncrypt","room","onRoomMembership","event","member","oldMembership","DecryptionAlgorithm","onRoomKeyEvent","_asyncToGenerator","importRoomKey","session","opts","hasKeysForKeyRequest","keyRequest","Promise","resolve","shareKeysWithDevice","Error","retryDecryptionFromSender","senderKey","UnknownDeviceError","msg","devices","name","registerAlgorithm","algorithm","encryptor","decryptor","set","DecryptionError"],"sources":["../../../src/crypto/algorithms/base.ts"],"sourcesContent":["/*\nCopyright 2016 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Internal module. Defines the base classes of the encryption implementations\n */\n\nimport type { IMegolmSessionData } from \"../../@types/crypto\";\nimport { MatrixClient } from \"../../client\";\nimport { Room } from \"../../models/room\";\nimport { OlmDevice } from \"../OlmDevice\";\nimport { IContent, MatrixEvent, RoomMember } from \"../../matrix\";\nimport { Crypto, IEncryptedContent, IEventDecryptionResult, IncomingRoomKeyRequest } from \"..\";\nimport { DeviceInfo } from \"../deviceinfo\";\nimport { IRoomEncryption } from \"../RoomList\";\nimport { DeviceInfoMap } from \"../DeviceList\";\n\n/**\n * Map of registered encryption algorithm classes. A map from string to {@link EncryptionAlgorithm} class\n */\nexport const ENCRYPTION_CLASSES = new Map<string, new (params: IParams) => EncryptionAlgorithm>();\n\nexport type DecryptionClassParams<P extends IParams = IParams> = Omit<P, \"deviceId\" | \"config\">;\n\n/**\n * map of registered encryption algorithm classes. Map from string to {@link DecryptionAlgorithm} class\n */\nexport const DECRYPTION_CLASSES = new Map<string, new (params: DecryptionClassParams) => DecryptionAlgorithm>();\n\nexport interface IParams {\n /** The UserID for the local user */\n userId: string;\n /** The identifier for this device. */\n deviceId: string;\n /** crypto core */\n crypto: Crypto;\n /** olm.js wrapper */\n olmDevice: OlmDevice;\n /** base matrix api interface */\n baseApis: MatrixClient;\n /** The ID of the room we will be sending to */\n roomId?: string;\n /** The body of the m.room.encryption event */\n config: IRoomEncryption & object;\n}\n\n/**\n * base type for encryption implementations\n */\nexport abstract class EncryptionAlgorithm {\n protected readonly userId: string;\n protected readonly deviceId: string;\n protected readonly crypto: Crypto;\n protected readonly olmDevice: OlmDevice;\n protected readonly baseApis: MatrixClient;\n\n /**\n * @param params - parameters\n */\n public constructor(params: IParams) {\n this.userId = params.userId;\n this.deviceId = params.deviceId;\n this.crypto = params.crypto;\n this.olmDevice = params.olmDevice;\n this.baseApis = params.baseApis;\n }\n\n /**\n * Perform any background tasks that can be done before a message is ready to\n * send, in order to speed up sending of the message.\n *\n * @param room - the room the event is in\n */\n public prepareToEncrypt(room: Room): void {}\n\n /**\n * Encrypt a message event\n *\n * @public\n *\n * @param content - event content\n *\n * @returns Promise which resolves to the new event body\n */\n public abstract encryptMessage(room: Room, eventType: string, content: IContent): Promise<IEncryptedContent>;\n\n /**\n * Called when the membership of a member of the room changes.\n *\n * @param event - event causing the change\n * @param member - user whose membership changed\n * @param oldMembership - previous membership\n * @public\n */\n public onRoomMembership(event: MatrixEvent, member: RoomMember, oldMembership?: string): void {}\n\n public reshareKeyWithDevice?(\n senderKey: string,\n sessionId: string,\n userId: string,\n device: DeviceInfo,\n ): Promise<void>;\n\n public forceDiscardSession?(): void;\n}\n\n/**\n * base type for decryption implementations\n */\nexport abstract class DecryptionAlgorithm {\n protected readonly userId: string;\n protected readonly crypto: Crypto;\n protected readonly olmDevice: OlmDevice;\n protected readonly baseApis: MatrixClient;\n\n public constructor(params: DecryptionClassParams) {\n this.userId = params.userId;\n this.crypto = params.crypto;\n this.olmDevice = params.olmDevice;\n this.baseApis = params.baseApis;\n }\n\n /**\n * Decrypt an event\n *\n * @param event - undecrypted event\n *\n * @returns promise which\n * resolves once we have finished decrypting. Rejects with an\n * `algorithms.DecryptionError` if there is a problem decrypting the event.\n */\n public abstract decryptEvent(event: MatrixEvent): Promise<IEventDecryptionResult>;\n\n /**\n * Handle a key event\n *\n * @param params - event key event\n */\n public async onRoomKeyEvent(params: MatrixEvent): Promise<void> {\n // ignore by default\n }\n\n /**\n * Import a room key\n *\n * @param opts - object\n */\n public async importRoomKey(session: IMegolmSessionData, opts: object): Promise<void> {\n // ignore by default\n }\n\n /**\n * Determine if we have the keys necessary to respond to a room key request\n *\n * @returns true if we have the keys and could (theoretically) share\n * them; else false.\n */\n public hasKeysForKeyRequest(keyRequest: IncomingRoomKeyRequest): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n /**\n * Send the response to a room key request\n *\n */\n public shareKeysWithDevice(keyRequest: IncomingRoomKeyRequest): void {\n throw new Error(\"shareKeysWithDevice not supported for this DecryptionAlgorithm\");\n }\n\n /**\n * Retry decrypting all the events from a sender that haven't been\n * decrypted yet.\n *\n * @param senderKey - the sender's key\n */\n public async retryDecryptionFromSender(senderKey: string): Promise<boolean> {\n // ignore by default\n return false;\n }\n\n public onRoomKeyWithheldEvent?(event: MatrixEvent): Promise<void>;\n public sendSharedHistoryInboundSessions?(devicesByUser: Map<string, DeviceInfo[]>): Promise<void>;\n}\n\nexport class UnknownDeviceError extends Error {\n /**\n * Exception thrown specifically when we want to warn the user to consider\n * the security of their conversation before continuing\n *\n * @param msg - message describing the problem\n * @param devices - set of unknown devices per user we're warning about\n */\n public constructor(\n msg: string,\n public readonly devices: DeviceInfoMap,\n public event?: MatrixEvent,\n ) {\n super(msg);\n this.name = \"UnknownDeviceError\";\n this.devices = devices;\n }\n}\n\n/**\n * Registers an encryption/decryption class for a particular algorithm\n *\n * @param algorithm - algorithm tag to register for\n *\n * @param encryptor - {@link EncryptionAlgorithm} implementation\n *\n * @param decryptor - {@link DecryptionAlgorithm} implementation\n */\nexport function registerAlgorithm<P extends IParams = IParams>(\n algorithm: string,\n encryptor: new (params: P) => EncryptionAlgorithm,\n decryptor: new (params: DecryptionClassParams<P>) => DecryptionAlgorithm,\n): void {\n ENCRYPTION_CLASSES.set(algorithm, encryptor as new (params: IParams) => EncryptionAlgorithm);\n DECRYPTION_CLASSES.set(algorithm, decryptor as new (params: DecryptionClassParams) => DecryptionAlgorithm);\n}\n\n/* Re-export for backwards compatibility. Deprecated: this is an internal class. */\nexport { DecryptionError } from \"../../common-crypto/CryptoBackend\";\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAYA;AACA;AACA;AACA,OAAO,IAAMA,kBAAkB,GAAG,IAAIC,GAAG,CAAuD,CAAC;AAIjG;AACA;AACA;AACA,OAAO,IAAMC,kBAAkB,GAAG,IAAID,GAAG,CAAqE,CAAC;AAmB/G;AACA;AACA;AACA,OAAO,MAAeE,mBAAmB,CAAC;EAOtC;AACJ;AACA;EACWC,WAAWA,CAACC,MAAe,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAChC,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,MAAM;IAC3B,IAAI,CAACC,QAAQ,GAAGH,MAAM,CAACG,QAAQ;IAC/B,IAAI,CAACC,MAAM,GAAGJ,MAAM,CAACI,MAAM;IAC3B,IAAI,CAACC,SAAS,GAAGL,MAAM,CAACK,SAAS;IACjC,IAAI,CAACC,QAAQ,GAAGN,MAAM,CAACM,QAAQ;EACnC;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACWC,gBAAgBA,CAACC,IAAU,EAAQ,CAAC;;EAE3C;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;A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/BnB,KAAmB,EAC5B;IACE,KAAK,CAACkB,GAAG,CAAC;IAAC,KAHKC,OAAsB,GAAtBA,OAAsB;IAAA,KAC/BnB,KAAmB,GAAnBA,KAAmB;IAG1B,IAAI,CAACoB,IAAI,GAAG,oBAAoB;IAChC,IAAI,CAACD,OAAO,GAAGA,OAAO;EAC1B;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAC7BC,SAAiB,EACjBC,SAAiD,EACjDC,SAAwE,EACpE;EACJvC,kBAAkB,CAACwC,GAAG,CAACH,SAAS,EAAEC,SAAyD,CAAC;EAC5FpC,kBAAkB,CAACsC,GAAG,CAACH,SAAS,EAAEE,SAAuE,CAAC;AAC9G;;AAEA;AACA,SAASE,eAAe,QAAQ,mCAAmC","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Computes a SHA-256 hash of a string (after utf-8 encoding) and returns it as an ArrayBuffer.
3
+ *
4
+ * @param plaintext The string to hash
5
+ * @returns An ArrayBuffer containing the SHA-256 hash of the input string
6
+ * @throws If the subtle crypto API is not available, for example if the code is running
7
+ * in a web page with an insecure context (eg. served over plain HTTP).
8
+ */
9
+ export declare function sha256(plaintext: string): Promise<ArrayBuffer>;
10
+ //# sourceMappingURL=digest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CASpE"}
package/lib/digest.js ADDED
@@ -0,0 +1,40 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ /*
3
+ Copyright 2024 The Matrix.org Foundation C.I.C.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ /**
19
+ * Computes a SHA-256 hash of a string (after utf-8 encoding) and returns it as an ArrayBuffer.
20
+ *
21
+ * @param plaintext The string to hash
22
+ * @returns An ArrayBuffer containing the SHA-256 hash of the input string
23
+ * @throws If the subtle crypto API is not available, for example if the code is running
24
+ * in a web page with an insecure context (eg. served over plain HTTP).
25
+ */
26
+ export function sha256(_x) {
27
+ return _sha.apply(this, arguments);
28
+ }
29
+ function _sha() {
30
+ _sha = _asyncToGenerator(function* (plaintext) {
31
+ if (!globalThis.crypto.subtle) {
32
+ throw new Error("Crypto.subtle is not available: insecure context?");
33
+ }
34
+ var utf8 = new TextEncoder().encode(plaintext);
35
+ var digest = yield globalThis.crypto.subtle.digest("SHA-256", utf8);
36
+ return digest;
37
+ });
38
+ return _sha.apply(this, arguments);
39
+ }
40
+ //# sourceMappingURL=digest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.js","names":["sha256","_x","_sha","apply","arguments","_asyncToGenerator","plaintext","globalThis","crypto","subtle","Error","utf8","TextEncoder","encode","digest"],"sources":["../src/digest.ts"],"sourcesContent":["/*\nCopyright 2024 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Computes a SHA-256 hash of a string (after utf-8 encoding) and returns it as an ArrayBuffer.\n *\n * @param plaintext The string to hash\n * @returns An ArrayBuffer containing the SHA-256 hash of the input string\n * @throws If the subtle crypto API is not available, for example if the code is running\n * in a web page with an insecure context (eg. served over plain HTTP).\n */\nexport async function sha256(plaintext: string): Promise<ArrayBuffer> {\n if (!globalThis.crypto.subtle) {\n throw new Error(\"Crypto.subtle is not available: insecure context?\");\n }\n const utf8 = new TextEncoder().encode(plaintext);\n\n const digest = await globalThis.crypto.subtle.digest(\"SHA-256\", utf8);\n\n return digest;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAsBA,MAAMA,CAAAC,EAAA;EAAA,OAAAC,IAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAS3B,SAAAF,KAAA;EAAAA,IAAA,GAAAG,iBAAA,CATM,WAAsBC,SAAiB,EAAwB;IAClE,IAAI,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,EAAE;MAC3B,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;IACxE;IACA,IAAMC,IAAI,GAAG,IAAIC,WAAW,CAAC,CAAC,CAACC,MAAM,CAACP,SAAS,CAAC;IAEhD,IAAMQ,MAAM,SAASP,UAAU,CAACC,MAAM,CAACC,MAAM,CAACK,MAAM,CAAC,SAAS,EAAEH,IAAI,CAAC;IAErE,OAAOG,MAAM;EACjB,CAAC;EAAA,OAAAZ,IAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA","ignoreList":[]}
package/lib/embedded.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { WidgetApi } from "matrix-widget-api";
2
2
  import { MatrixEvent } from "./models/event";
3
- import { ISendEventResponse } from "./@types/requests";
3
+ import { ISendEventResponse, SendDelayedEventRequestOpts, SendDelayedEventResponse, UpdateDelayedEventAction } from "./@types/requests";
4
+ import { StateEvents } from "./@types/event";
4
5
  import { MatrixClient, IMatrixClientCreateOpts, IStartClientOpts, SendToDeviceContentMap, IOpenIDToken } from "./client";
5
6
  import { SyncState } from "./sync";
6
7
  import { Room } from "./models/room";
@@ -51,6 +52,18 @@ export interface ICapabilities {
51
52
  * @defaultValue false
52
53
  */
53
54
  turnServers?: boolean;
55
+ /**
56
+ * Whether this client needs to be able to send delayed events.
57
+ * @experimental Part of MSC4140 & MSC4157
58
+ * @defaultValue false
59
+ */
60
+ sendDelayedEvents?: boolean;
61
+ /**
62
+ * Whether this client needs to be able to update delayed events.
63
+ * @experimental Part of MSC4140 & MSC4157
64
+ * @defaultValue false
65
+ */
66
+ updateDelayedEvents?: boolean;
54
67
  }
55
68
  /**
56
69
  * A MatrixClient that routes its requests through the widget API instead of the
@@ -80,7 +93,17 @@ export declare class RoomWidgetClient extends MatrixClient {
80
93
  stopClient(): void;
81
94
  joinRoom(roomIdOrAlias: string): Promise<Room>;
82
95
  protected encryptAndSendEvent(room: Room, event: MatrixEvent): Promise<ISendEventResponse>;
96
+ protected encryptAndSendEvent(room: Room, event: MatrixEvent, delayOpts: SendDelayedEventRequestOpts): Promise<SendDelayedEventResponse>;
83
97
  sendStateEvent(roomId: string, eventType: string, content: any, stateKey?: string): Promise<ISendEventResponse>;
98
+ /**
99
+ * @experimental This currently relies on an unstable MSC (MSC4140).
100
+ */
101
+ _unstable_sendDelayedStateEvent<K extends keyof StateEvents>(roomId: string, delayOpts: SendDelayedEventRequestOpts, eventType: K, content: StateEvents[K], stateKey?: string): Promise<SendDelayedEventResponse>;
102
+ private validateSendDelayedEventResponse;
103
+ /**
104
+ * @experimental This currently relies on an unstable MSC (MSC4140).
105
+ */
106
+ _unstable_updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<{}>;
84
107
  sendToDevice(eventType: string, contentMap: SendToDeviceContentMap): Promise<{}>;
85
108
  getOpenIdToken(): Promise<IOpenIDToken>;
86
109
  queueToDevice({ eventType, batch }: ToDeviceBatch): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"embedded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Ac,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,GAAG,EACZ,QAAQ,SAAK,GACd,OAAO,CAAC,kBAAkB,CAAC;IAQ9B;;OAEG;IAEU,+BAA+B,CAAC,CAAC,SAAS,MAAM,WAAW,EACpE,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,2BAA2B,EACtC,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,QAAQ,SAAK,GACd,OAAO,CAAC,wBAAwB,CAAC;IAgBpC,OAAO,CAAC,gCAAgC;IAOxC;;OAEG;IAEU,4BAA4B,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,EAAE,CAAC;IAQ5F,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,sBAAsB,GAAG,OAAO,CAAC,EAAE,CAAC;IAKhF,cAAc,IAAI,OAAO,CAAC,YAAY,CAAC;IAYvC,aAAa,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjE,uBAAuB,CAAC,iBAAiB,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAepG,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAK1C,YAAY,IAAI,SAAS,GAAG,IAAI;IAIvC,OAAO,CAAC,YAAY;YAMN,GAAG;IAIjB,OAAO,CAAC,OAAO,CAiBb;IAEF,OAAO,CAAC,UAAU,CAchB;YAEY,gBAAgB;CAyBjC"}
package/lib/embedded.js CHANGED
@@ -22,7 +22,7 @@ import { WidgetApiToWidgetAction, MatrixCapabilities } from "matrix-widget-api";
22
22
  import { MatrixEvent, EventStatus } from "./models/event";
23
23
  import { EventType } from "./@types/event";
24
24
  import { logger } from "./logger";
25
- import { MatrixClient, ClientEvent } from "./client";
25
+ import { MatrixClient, ClientEvent, UNSTABLE_MSC4140_DELAYED_EVENTS } from "./client";
26
26
  import { SyncApi, SyncState } from "./sync";
27
27
  import { SlidingSyncSdk } from "./sliding-sync-sdk";
28
28
  import { User } from "./models/user";
@@ -44,7 +44,7 @@ export class RoomWidgetClient extends MatrixClient {
44
44
  * or if the the widget wants to send the `ContentLoaded` action at a later point in time after the initial setup.
45
45
  */
46
46
  constructor(widgetApi, capabilities, roomId, opts, sendContentLoaded) {
47
- var _this, _capabilities$sendEve, _capabilities$receive, _capabilities$sendSta, _capabilities$receive2, _capabilities$sendEve2, _capabilities$receive3, _capabilities$sendSta2, _capabilities$receive4, _capabilities$sendToD, _capabilities$receive5;
47
+ var _this, _capabilities$sendEve, _capabilities$receive, _capabilities$sendSta, _capabilities$receive2, _capabilities$sendEve2, _capabilities$receive3, _capabilities$sendSta2, _capabilities$receive4, _capabilities$sendToD, _capabilities$receive5, _capabilities$sendEve3, _capabilities$sendSta3;
48
48
  super(opts);
49
49
  _this = this;
50
50
  this.widgetApi = widgetApi;
@@ -61,11 +61,11 @@ export class RoomWidgetClient extends MatrixClient {
61
61
  // Verify the room ID matches, since it's possible for the client to
62
62
  // send us events from other rooms if this widget is always on screen
63
63
  if (ev.detail.data.room_id === _this.roomId) {
64
- var event = new MatrixEvent(ev.detail.data);
65
- yield _this.syncApi.injectRoomEvents(_this.room, [], [event]);
66
- _this.emit(ClientEvent.Event, event);
64
+ var _event = new MatrixEvent(ev.detail.data);
65
+ yield _this.syncApi.injectRoomEvents(_this.room, [], [_event]);
66
+ _this.emit(ClientEvent.Event, _event);
67
67
  _this.setSyncState(SyncState.Syncing);
68
- logger.info("Received event ".concat(event.getId(), " ").concat(event.getType(), " ").concat(event.getStateKey()));
68
+ logger.info("Received event ".concat(_event.getId(), " ").concat(_event.getType(), " ").concat(_event.getStateKey()));
69
69
  } else {
70
70
  var {
71
71
  event_id: eventId,
@@ -131,6 +131,12 @@ export class RoomWidgetClient extends MatrixClient {
131
131
  });
132
132
  (_capabilities$sendToD = capabilities.sendToDevice) === null || _capabilities$sendToD === void 0 || _capabilities$sendToD.forEach(eventType => widgetApi.requestCapabilityToSendToDevice(eventType));
133
133
  (_capabilities$receive5 = capabilities.receiveToDevice) === null || _capabilities$receive5 === void 0 || _capabilities$receive5.forEach(eventType => widgetApi.requestCapabilityToReceiveToDevice(eventType));
134
+ if (capabilities.sendDelayedEvents && ((_capabilities$sendEve3 = capabilities.sendEvent) !== null && _capabilities$sendEve3 !== void 0 && _capabilities$sendEve3.length || capabilities.sendMessage === true || Array.isArray(capabilities.sendMessage) && capabilities.sendMessage.length || (_capabilities$sendSta3 = capabilities.sendState) !== null && _capabilities$sendSta3 !== void 0 && _capabilities$sendSta3.length)) {
135
+ widgetApi.requestCapability(MatrixCapabilities.MSC4157SendDelayedEvent);
136
+ }
137
+ if (capabilities.updateDelayedEvents) {
138
+ widgetApi.requestCapability(MatrixCapabilities.MSC4157UpdateDelayedEvent);
139
+ }
134
140
  if (capabilities.turnServers) {
135
141
  widgetApi.requestCapability(MatrixCapabilities.MSC3846TurnServers);
136
142
  }
@@ -221,9 +227,14 @@ export class RoomWidgetClient extends MatrixClient {
221
227
  throw new Error("Unknown room: ".concat(roomIdOrAlias));
222
228
  })();
223
229
  }
224
- encryptAndSendEvent(room, event) {
230
+ encryptAndSendEvent(room, event, delayOpts) {
225
231
  var _this4 = this;
226
232
  return _asyncToGenerator(function* () {
233
+ if (delayOpts) {
234
+ // TODO: updatePendingEvent for delayed events?
235
+ var _response = yield _this4.widgetApi.sendRoomEvent(event.getType(), event.getContent(), room.roomId, "delay" in delayOpts ? delayOpts.delay : undefined, "parent_delay_id" in delayOpts ? delayOpts.parent_delay_id : undefined);
236
+ return _this4.validateSendDelayedEventResponse(_response);
237
+ }
227
238
  var response;
228
239
  try {
229
240
  response = yield _this4.widgetApi.sendRoomEvent(event.getType(), event.getContent(), room.roomId);
@@ -231,6 +242,8 @@ export class RoomWidgetClient extends MatrixClient {
231
242
  _this4.updatePendingEventStatus(room, event, EventStatus.NOT_SENT);
232
243
  throw e;
233
244
  }
245
+
246
+ // This also checks for an event id on the response
234
247
  room.updatePendingEvent(event, EventStatus.SENT, response.event_id);
235
248
  return {
236
249
  event_id: response.event_id
@@ -242,20 +255,65 @@ export class RoomWidgetClient extends MatrixClient {
242
255
  _this5 = this;
243
256
  return _asyncToGenerator(function* () {
244
257
  var stateKey = _arguments2.length > 3 && _arguments2[3] !== undefined ? _arguments2[3] : "";
245
- return yield _this5.widgetApi.sendStateEvent(eventType, stateKey, content, roomId);
258
+ var response = yield _this5.widgetApi.sendStateEvent(eventType, stateKey, content, roomId);
259
+ if (response.event_id === undefined) {
260
+ throw new Error("'event_id' absent from response to an event request");
261
+ }
262
+ return {
263
+ event_id: response.event_id
264
+ };
265
+ })();
266
+ }
267
+
268
+ /**
269
+ * @experimental This currently relies on an unstable MSC (MSC4140).
270
+ */
271
+ // eslint-disable-next-line
272
+ _unstable_sendDelayedStateEvent(roomId, delayOpts, eventType, content) {
273
+ var _arguments3 = arguments,
274
+ _this6 = this;
275
+ return _asyncToGenerator(function* () {
276
+ var stateKey = _arguments3.length > 4 && _arguments3[4] !== undefined ? _arguments3[4] : "";
277
+ if (!(yield _this6.doesServerSupportUnstableFeature(UNSTABLE_MSC4140_DELAYED_EVENTS))) {
278
+ throw Error("Server does not support the delayed events API");
279
+ }
280
+ var response = yield _this6.widgetApi.sendStateEvent(eventType, stateKey, content, roomId, "delay" in delayOpts ? delayOpts.delay : undefined, "parent_delay_id" in delayOpts ? delayOpts.parent_delay_id : undefined);
281
+ return _this6.validateSendDelayedEventResponse(response);
282
+ })();
283
+ }
284
+ validateSendDelayedEventResponse(response) {
285
+ if (response.delay_id === undefined) {
286
+ throw new Error("'delay_id' absent from response to a delayed event request");
287
+ }
288
+ return {
289
+ delay_id: response.delay_id
290
+ };
291
+ }
292
+
293
+ /**
294
+ * @experimental This currently relies on an unstable MSC (MSC4140).
295
+ */
296
+ // eslint-disable-next-line
297
+ _unstable_updateDelayedEvent(delayId, action) {
298
+ var _this7 = this;
299
+ return _asyncToGenerator(function* () {
300
+ if (!(yield _this7.doesServerSupportUnstableFeature(UNSTABLE_MSC4140_DELAYED_EVENTS))) {
301
+ throw Error("Server does not support the delayed events API");
302
+ }
303
+ return yield _this7.widgetApi.updateDelayedEvent(delayId, action);
246
304
  })();
247
305
  }
248
306
  sendToDevice(eventType, contentMap) {
249
- var _this6 = this;
307
+ var _this8 = this;
250
308
  return _asyncToGenerator(function* () {
251
- yield _this6.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap));
309
+ yield _this8.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap));
252
310
  return {};
253
311
  })();
254
312
  }
255
313
  getOpenIdToken() {
256
- var _this7 = this;
314
+ var _this9 = this;
257
315
  return _asyncToGenerator(function* () {
258
- var token = yield _this7.widgetApi.requestOpenIDConnectToken();
316
+ var token = yield _this9.widgetApi.requestOpenIDConnectToken();
259
317
  // the IOpenIDCredentials from the widget-api and IOpenIDToken form the matrix-js-sdk are compatible.
260
318
  // we still recreate the token to make this transparent and catch'able by the linter in case the types change in the future.
261
319
  return {
@@ -267,7 +325,7 @@ export class RoomWidgetClient extends MatrixClient {
267
325
  })();
268
326
  }
269
327
  queueToDevice(_ref7) {
270
- var _this8 = this;
328
+ var _this10 = this;
271
329
  return _asyncToGenerator(function* () {
272
330
  var {
273
331
  eventType,
@@ -282,11 +340,11 @@ export class RoomWidgetClient extends MatrixClient {
282
340
  } of batch) {
283
341
  contentMap.getOrCreate(userId).set(deviceId, payload);
284
342
  }
285
- yield _this8.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap));
343
+ yield _this10.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap));
286
344
  })();
287
345
  }
288
346
  encryptAndSendToDevices(userDeviceInfoArr, payload) {
289
- var _this9 = this;
347
+ var _this11 = this;
290
348
  return _asyncToGenerator(function* () {
291
349
  // map: user Id → device Id → payload
292
350
  var contentMap = new MapWithDefault(() => new Map());
@@ -298,16 +356,16 @@ export class RoomWidgetClient extends MatrixClient {
298
356
  } of userDeviceInfoArr) {
299
357
  contentMap.getOrCreate(userId).set(deviceId, payload);
300
358
  }
301
- yield _this9.widgetApi.sendToDevice(payload.type, true, recursiveMapToObject(contentMap));
359
+ yield _this11.widgetApi.sendToDevice(payload.type, true, recursiveMapToObject(contentMap));
302
360
  })();
303
361
  }
304
362
 
305
363
  // Overridden since we get TURN servers automatically over the widget API,
306
364
  // and this method would otherwise complain about missing an access token
307
365
  checkTurnServers() {
308
- var _this10 = this;
366
+ var _this12 = this;
309
367
  return _asyncToGenerator(function* () {
310
- return _this10.turnServers.length > 0;
368
+ return _this12.turnServers.length > 0;
311
369
  })();
312
370
  }
313
371
 
@@ -321,19 +379,19 @@ export class RoomWidgetClient extends MatrixClient {
321
379
  this.emit(ClientEvent.Sync, state, oldState);
322
380
  }
323
381
  ack(ev) {
324
- var _this11 = this;
382
+ var _this13 = this;
325
383
  return _asyncToGenerator(function* () {
326
- yield _this11.widgetApi.transport.reply(ev.detail, {});
384
+ yield _this13.widgetApi.transport.reply(ev.detail, {});
327
385
  })();
328
386
  }
329
387
  watchTurnServers() {
330
- var _this12 = this;
388
+ var _this14 = this;
331
389
  return _asyncToGenerator(function* () {
332
- var servers = _this12.widgetApi.getTurnServers();
390
+ var servers = _this14.widgetApi.getTurnServers();
333
391
  var onClientStopped = () => {
334
392
  servers.return(undefined);
335
393
  };
336
- _this12.lifecycle.signal.addEventListener("abort", onClientStopped);
394
+ _this14.lifecycle.signal.addEventListener("abort", onClientStopped);
337
395
  try {
338
396
  var _iteratorAbruptCompletion = false;
339
397
  var _didIteratorError = false;
@@ -342,12 +400,12 @@ export class RoomWidgetClient extends MatrixClient {
342
400
  for (var _iterator = _asyncIterator(servers), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) {
343
401
  var server = _step.value;
344
402
  {
345
- _this12.turnServers = [{
403
+ _this14.turnServers = [{
346
404
  urls: server.uris,
347
405
  username: server.username,
348
406
  credential: server.password
349
407
  }];
350
- _this12.emit(ClientEvent.TurnServers, _this12.turnServers);
408
+ _this14.emit(ClientEvent.TurnServers, _this14.turnServers);
351
409
  logger.log("Received TURN server: ".concat(server.uris));
352
410
  }
353
411
  }
@@ -368,7 +426,7 @@ export class RoomWidgetClient extends MatrixClient {
368
426
  } catch (e) {
369
427
  logger.warn("Error watching TURN servers", e);
370
428
  } finally {
371
- _this12.lifecycle.signal.removeEventListener("abort", onClientStopped);
429
+ _this14.lifecycle.signal.removeEventListener("abort", onClientStopped);
372
430
  }
373
431
  })();
374
432
  }