Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7e69f30

Browse files
committed
Yield a TURN server immediately
1 parent 3b02a45 commit 7e69f30

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,37 @@ export class StopGapWidgetDriver extends WidgetDriver {
185185

186186
public async sendToDevice(
187187
eventType: string,
188-
encrypt: boolean,
188+
encrypted: boolean,
189189
contentMap: { [userId: string]: { [deviceId: string]: unknown } },
190190
): Promise<void> {
191-
if (encrypt) {
192-
throw new Error("Encrypted to-device events not supported yet");
191+
const client = MatrixClientPeg.get();
192+
193+
if (encrypted) {
194+
const deviceInfoMap = await client.crypto.deviceList.downloadKeys(Object.keys(contentMap), false);
195+
196+
await Promise.all(
197+
Object.entries(contentMap).flatMap(([userId, userContentMap]) =>
198+
Object.entries(userContentMap).map(async ([deviceId, content]) => {
199+
if (deviceId === "*") {
200+
// Send the message to all devices we have keys for
201+
await client.encryptAndSendToDevices(
202+
Object.values(deviceInfoMap[userId]).map(deviceInfo => ({
203+
userId, deviceInfo,
204+
})),
205+
content,
206+
);
207+
} else {
208+
// Send the message to a specific device
209+
await client.encryptAndSendToDevices(
210+
[{ userId, deviceInfo: deviceInfoMap[userId][deviceId] }],
211+
content,
212+
);
213+
}
214+
}),
215+
),
216+
);
193217
} else {
194-
await MatrixClientPeg.get().sendToDevice(eventType, contentMap);
218+
await client.sendToDevice(eventType, contentMap);
195219
}
196220
}
197221

0 commit comments

Comments
 (0)