From 14cc1bb37ff81621d72cd086457595273f59d8dd Mon Sep 17 00:00:00 2001 From: Timo K Date: Fri, 10 Oct 2025 10:55:17 +0200 Subject: [PATCH 1/2] Improve is livekit checks to check for field availability and first. Signed-off-by: Timo K --- src/matrixrtc/LivekitTransport.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/matrixrtc/LivekitTransport.ts b/src/matrixrtc/LivekitTransport.ts index eda11f554e..006056007b 100644 --- a/src/matrixrtc/LivekitTransport.ts +++ b/src/matrixrtc/LivekitTransport.ts @@ -22,7 +22,10 @@ export interface LivekitTransportConfig extends Transport { } export const isLivekitTransportConfig = (object: any): object is LivekitTransportConfig => - object.type === "livekit" && "livekit_service_url" in object; + "type" in object && + object.type === "livekit" && + "livekit_service_url" in object && + typeof object.livekit_service_url === "string"; export interface LivekitTransport extends LivekitTransportConfig { livekit_alias: string; @@ -43,4 +46,7 @@ export interface LivekitFocusSelection extends Transport { * @deprecated see LivekitFocusSelection */ export const isLivekitFocusSelection = (object: any): object is LivekitFocusSelection => - object.type === "livekit" && "focus_selection" in object; + "type" in object && + object.type === "livekit" && + "focus_selection" in object && + typeof object.focus_selection === "string"; From 3e24e15d130585284d36a822f2a306889e52be24 Mon Sep 17 00:00:00 2001 From: Timo K Date: Fri, 10 Oct 2025 10:59:56 +0200 Subject: [PATCH 2/2] add test Signed-off-by: Timo K --- spec/unit/matrixrtc/LivekitTransport.spec.ts | 11 +++++++++++ src/matrixrtc/LivekitTransport.ts | 2 ++ 2 files changed, 13 insertions(+) diff --git a/spec/unit/matrixrtc/LivekitTransport.spec.ts b/spec/unit/matrixrtc/LivekitTransport.spec.ts index 04f04a1357..f10449d1f6 100644 --- a/spec/unit/matrixrtc/LivekitTransport.spec.ts +++ b/spec/unit/matrixrtc/LivekitTransport.spec.ts @@ -61,4 +61,15 @@ describe("LivekitFocus", () => { expect(isLivekitTransportConfig({ type: "not-livekit", livekit_service_url: "http://test.com" })).toBeFalsy(); expect(isLivekitTransportConfig({ type: "livekit", other_service_url: "oldest_membership" })).toBeFalsy(); }); + it("does not throw with missing fields", () => { + expect(() => isLivekitTransport({})).not.toThrow(); + expect(() => isLivekitTransportConfig({})).not.toThrow(); + expect(() => isLivekitFocusSelection({})).not.toThrow(); + expect(() => isLivekitTransport({ wrong: "field" })).not.toThrow(); + expect(() => isLivekitTransportConfig({ wrong: "field" })).not.toThrow(); + expect(() => isLivekitFocusSelection({ wrong: "field" })).not.toThrow(); + expect(() => isLivekitTransport(undefined)).not.toThrow(); + expect(() => isLivekitTransportConfig(undefined)).not.toThrow(); + expect(() => isLivekitFocusSelection(undefined)).not.toThrow(); + }); }); diff --git a/src/matrixrtc/LivekitTransport.ts b/src/matrixrtc/LivekitTransport.ts index 006056007b..cbbd740ad4 100644 --- a/src/matrixrtc/LivekitTransport.ts +++ b/src/matrixrtc/LivekitTransport.ts @@ -22,6 +22,7 @@ export interface LivekitTransportConfig extends Transport { } export const isLivekitTransportConfig = (object: any): object is LivekitTransportConfig => + object && "type" in object && object.type === "livekit" && "livekit_service_url" in object && @@ -46,6 +47,7 @@ export interface LivekitFocusSelection extends Transport { * @deprecated see LivekitFocusSelection */ export const isLivekitFocusSelection = (object: any): object is LivekitFocusSelection => + object && "type" in object && object.type === "livekit" && "focus_selection" in object &&