You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Merge pull request #1086 from matrix-org/dbkr/fix_calls_in_e2e_rooms
Fix calls in e2e rooms
This commit is contained in:
@@ -4644,8 +4644,11 @@ function setupCallEventHandler(client) {
|
|||||||
// This happens quite often, eg. replaying sync from storage, catchup sync
|
// This happens quite often, eg. replaying sync from storage, catchup sync
|
||||||
// after loading and after we've been offline for a bit.
|
// after loading and after we've been offline for a bit.
|
||||||
let callEventBuffer = [];
|
let callEventBuffer = [];
|
||||||
function onSync(state) {
|
function evaluateEventBuffer() {
|
||||||
if (state === "SYNCING") {
|
if (client.getSyncState() === "SYNCING") {
|
||||||
|
// don't process any events until they are all decrypted
|
||||||
|
if (callEventBuffer.some((e) => e.isBeingDecrypted())) return;
|
||||||
|
|
||||||
const ignoreCallIds = {}; // Set<String>
|
const ignoreCallIds = {}; // Set<String>
|
||||||
// inspect the buffer and mark all calls which have been answered
|
// inspect the buffer and mark all calls which have been answered
|
||||||
// or hung up before passing them to the call event handler.
|
// or hung up before passing them to the call event handler.
|
||||||
@@ -4670,21 +4673,32 @@ function setupCallEventHandler(client) {
|
|||||||
callEventBuffer = [];
|
callEventBuffer = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.on("sync", onSync);
|
client.on("sync", evaluateEventBuffer);
|
||||||
|
|
||||||
function onEvent(event) {
|
function onEvent(event) {
|
||||||
if (event.getType().indexOf("m.call.") !== 0) {
|
// any call events or ones that might be once they're decrypted
|
||||||
// not a call event
|
if (event.getType().indexOf("m.call.") === 0 || event.isBeingDecrypted()) {
|
||||||
if (event.isBeingDecrypted() || event.isDecryptionFailure()) {
|
|
||||||
// not *yet* a call event, but might become one...
|
|
||||||
event.once("Event.decrypted", onEvent);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// queue up for processing once all events from this sync have been
|
// queue up for processing once all events from this sync have been
|
||||||
// processed (see above).
|
// processed (see above).
|
||||||
callEventBuffer.push(event);
|
callEventBuffer.push(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.isBeingDecrypted() || event.isDecryptionFailure()) {
|
||||||
|
// add an event listener for once the event is decrypted.
|
||||||
|
event.once("Event.decrypted", () => {
|
||||||
|
if (event.getType().indexOf("m.call.") === -1) return;
|
||||||
|
|
||||||
|
if (callEventBuffer.includes(event)) {
|
||||||
|
// we were waiting for that event to decrypt, so recheck the buffer
|
||||||
|
evaluateEventBuffer();
|
||||||
|
} else {
|
||||||
|
// This one wasn't buffered so just run the event handler for it
|
||||||
|
// straight away
|
||||||
|
callEventHandler(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
client.on("event", onEvent);
|
client.on("event", onEvent);
|
||||||
|
|
||||||
function callEventHandler(event) {
|
function callEventHandler(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user