You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Change call event handlers to adapt to undecrypted events
This commit is contained in:
@@ -353,6 +353,10 @@ export function MatrixClient(opts) {
|
|||||||
if (call) {
|
if (call) {
|
||||||
this._callEventHandler = new CallEventHandler(this);
|
this._callEventHandler = new CallEventHandler(this);
|
||||||
this._supportsVoip = true;
|
this._supportsVoip = true;
|
||||||
|
// Start listening for calls after the initial sync is done
|
||||||
|
// We do not need to backfill the call event buffer
|
||||||
|
// with encrypted events that might never get decrypted
|
||||||
|
this.once("sync", () => this._callEventHandler.start());
|
||||||
} else {
|
} else {
|
||||||
this._callEventHandler = null;
|
this._callEventHandler = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ export class CallEventHandler {
|
|||||||
// after loading and after we've been offline for a bit.
|
// after loading and after we've been offline for a bit.
|
||||||
this.callEventBuffer = [];
|
this.callEventBuffer = [];
|
||||||
this.candidateEventsByCall = new Map<string, Array<MatrixEvent>>();
|
this.candidateEventsByCall = new Map<string, Array<MatrixEvent>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public start() {
|
||||||
this.client.on("sync", this.evaluateEventBuffer);
|
this.client.on("sync", this.evaluateEventBuffer);
|
||||||
this.client.on("event", this.onEvent);
|
this.client.on("event", this.onEvent);
|
||||||
}
|
}
|
||||||
@@ -85,37 +88,16 @@ export class CallEventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onEvent = (event: MatrixEvent) => {
|
private onEvent = async (event: MatrixEvent) => {
|
||||||
// any call events or ones that might be once they're decrypted
|
await this.client.decryptEventIfNeeded(event);
|
||||||
if (
|
if (
|
||||||
event.getType().indexOf("m.call.") === 0 ||
|
event.getType().indexOf("m.call.") === 0 ||
|
||||||
event.getType().indexOf("org.matrix.call.") === 0
|
event.getType().indexOf("org.matrix.call.") === 0
|
||||||
|| event.isBeingDecrypted()
|
|
||||||
) {
|
) {
|
||||||
// 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).
|
||||||
this.callEventBuffer.push(event);
|
this.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 (this.callEventBuffer.includes(event)) {
|
|
||||||
// we were waiting for that event to decrypt, so recheck the buffer
|
|
||||||
this.evaluateEventBuffer();
|
|
||||||
} else {
|
|
||||||
// This one wasn't buffered so just run the event handler for it
|
|
||||||
// straight away
|
|
||||||
try {
|
|
||||||
this.handleCallEvent(event);
|
|
||||||
} catch (e) {
|
|
||||||
logger.error("Caught exception handling call event", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCallEvent(event: MatrixEvent) {
|
private handleCallEvent(event: MatrixEvent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user