From 4332277ce66969423113c63b467bb2fc8bb8614a Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 9 Oct 2023 20:45:08 +0100 Subject: [PATCH 1/2] Don't use event.sender in CallMembership I fell into another js-sdk trap: this is "only guaranteed to be set for events that appear in a timeline" and not state events. It does not say why. We only ever used it to get the sender user ID anyway, so just use getSender(). --- src/matrixrtc/CallMembership.ts | 8 ++++---- src/matrixrtc/MatrixRTCSession.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/matrixrtc/CallMembership.ts b/src/matrixrtc/CallMembership.ts index b73a937b986..d304c9df4d9 100644 --- a/src/matrixrtc/CallMembership.ts +++ b/src/matrixrtc/CallMembership.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { MatrixEvent, RoomMember } from "../matrix"; +import { MatrixEvent } from "../matrix"; import { deepCompare } from "../utils"; import { Focus } from "./focus"; @@ -42,11 +42,11 @@ export class CallMembership { if (typeof data.device_id !== "string") throw new Error("Malformed membership event: device_id must be string"); if (typeof data.call_id !== "string") throw new Error("Malformed membership event: call_id must be string"); if (typeof data.scope !== "string") throw new Error("Malformed membership event: scope must be string"); - if (!parentEvent.sender) throw new Error("Invalid parent event: sender is null"); + if (!parentEvent.getSender()) throw new Error("Invalid parent event: sender is null"); } - public get member(): RoomMember { - return this.parentEvent.sender!; + public get sender(): string | undefined { + return this.parentEvent.getSender(); } public get callId(): string { diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index fc3d63cc6c5..a1f0e99bb3b 100644 --- a/src/matrixrtc/MatrixRTCSession.ts +++ b/src/matrixrtc/MatrixRTCSession.ts @@ -120,7 +120,7 @@ export class MatrixRTCSession extends TypedEventEmitter a.createdTs() - b.createdTs()); logger.debug( "Call memberships, in order: ", - callMemberships.map((m) => [m.createdTs(), m.member.userId]), + callMemberships.map((m) => [m.createdTs(), m.sender]), ); return callMemberships; From f8735afc35d0865532ecbd020945624c3995eff4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 9 Oct 2023 20:53:30 +0100 Subject: [PATCH 2/2] Fix test --- spec/unit/matrixrtc/CallMembership.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/unit/matrixrtc/CallMembership.spec.ts b/spec/unit/matrixrtc/CallMembership.spec.ts index 6f7f8f5ca46..4bc5492e06d 100644 --- a/spec/unit/matrixrtc/CallMembership.spec.ts +++ b/spec/unit/matrixrtc/CallMembership.spec.ts @@ -29,9 +29,7 @@ const membershipTemplate: CallMembershipData = { function makeMockEvent(originTs = 0): MatrixEvent { return { getTs: jest.fn().mockReturnValue(originTs), - sender: { - userId: "@alice:example.org", - }, + getSender: jest.fn().mockReturnValue("@alice:example.org"), } as unknown as MatrixEvent; }