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();
});
});
12 changes: 10 additions & 2 deletions src/matrixrtc/LivekitTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Loading