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 eda11f554e..cbbd740ad4 100644 --- a/src/matrixrtc/LivekitTransport.ts +++ b/src/matrixrtc/LivekitTransport.ts @@ -22,7 +22,11 @@ export interface LivekitTransportConfig extends Transport { } export const isLivekitTransportConfig = (object: any): object is LivekitTransportConfig => - object.type === "livekit" && "livekit_service_url" in object; + 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 +47,8 @@ export interface LivekitFocusSelection extends Transport { * @deprecated see LivekitFocusSelection */ export const isLivekitFocusSelection = (object: any): object is LivekitFocusSelection => - object.type === "livekit" && "focus_selection" in object; + object && + "type" in object && + object.type === "livekit" && + "focus_selection" in object && + typeof object.focus_selection === "string";