1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Support party_id

Send party_id on events and check the party_id of incoming events matches

Includes a basic test to assert that it actually does: we should
build out a decent test suite for calls as there's a lot of edge-case
functionality that can break and slip through the cracks (eg. glare).
This is a start.

Fixes https://github.com/matrix-org/matrix-js-sdk/issues/1511
This commit is contained in:
David Baker
2020-10-16 12:53:08 +01:00
parent 7c3af91b42
commit 2df588f95a
4 changed files with 257 additions and 50 deletions

View File

@@ -28,7 +28,7 @@ export class CallEventHandler {
client: MatrixClient;
calls: Map<string, MatrixCall>;
callEventBuffer: MatrixEvent[];
candidatesByCall: Map<string, Array<RTCIceCandidate>>;
candidateEventsByCall: Map<string, Array<MatrixEvent>>;
constructor(client: MatrixClient) {
this.client = client;
@@ -42,7 +42,7 @@ export class CallEventHandler {
// This happens quite often, eg. replaying sync from storage, catchup sync
// after loading and after we've been offline for a bit.
this.callEventBuffer = [];
this.candidatesByCall = new Map<string, Array<RTCIceCandidate>>();
this.candidateEventsByCall = new Map<string, Array<MatrixEvent>>();
this.client.on("sync", this.evaluateEventBuffer);
this.client.on("event", this.onEvent);
}
@@ -157,9 +157,9 @@ export class CallEventHandler {
this.calls.set(call.callId, call);
// if we stashed candidate events for that call ID, play them back now
if (this.candidatesByCall.get(call.callId)) {
for (const cand of this.candidatesByCall.get(call.callId)) {
call.gotRemoteIceCandidate(cand);
if (this.candidateEventsByCall.get(call.callId)) {
for (const ev of this.candidateEventsByCall.get(call.callId)) {
call.onRemoteIceCandidatesReceived(ev);
}
}
@@ -221,16 +221,12 @@ export class CallEventHandler {
}
if (!call) {
// store the candidates; we may get a call eventually.
if (!this.candidatesByCall.has(content.call_id)) {
this.candidatesByCall.set(content.call_id, []);
if (!this.candidateEventsByCall.has(content.call_id)) {
this.candidateEventsByCall.set(content.call_id, []);
}
this.candidatesByCall.set(content.call_id, this.candidatesByCall.get(
content.call_id,
).concat(content.candidates));
this.candidateEventsByCall.get(content.call_id).push(event);
} else {
for (const cand of content.candidates) {
call.gotRemoteIceCandidate(cand);
}
call.onRemoteIceCandidatesReceived(event);
}
} else if ([EventType.CallHangup, EventType.CallReject].includes(event.getType())) {
// Note that we also observe our own hangups here so we can see