Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions spec/unit/matrixrtc/LivekitTransport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
17 changes: 13 additions & 4 deletions src/matrixrtc/LivekitTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ export interface LivekitTransportConfig extends Transport {
livekit_service_url: string;
}

export const isLivekitTransportConfig = (object: any): object is LivekitTransportConfig =>
object.type === "livekit" && "livekit_service_url" in object;
export const isLivekitTransportConfig = (object: unknown): object is LivekitTransportConfig =>
object !== null &&
typeof 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;
}

export const isLivekitTransport = (object: any): object is LivekitTransport =>
export const isLivekitTransport = (object: unknown): object is LivekitTransport =>
isLivekitTransportConfig(object) && "livekit_alias" in object;
Comment on lines +36 to 37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also needs to check for typeof object.livekit_alias === "string"


/**
Expand All @@ -43,4 +48,8 @@ export interface LivekitFocusSelection extends Transport {
* @deprecated see LivekitFocusSelection
*/
export const isLivekitFocusSelection = (object: any): object is LivekitFocusSelection =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toger5 this also needs to be unknown

object.type === "livekit" && "focus_selection" in object;
object &&
"type" in object &&
object.type === "livekit" &&
"focus_selection" in object &&
typeof object.focus_selection === "string";