-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate the latest embed element changes before merging into main.
- Loading branch information
1 parent
78f2c19
commit f9fffef
Showing
4 changed files
with
113 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { parseRoomUrlAndSubdomain } from "../roomUrl"; | ||
|
||
describe("roomUrl", () => { | ||
describe("parseRoomUrlAndSubdomain", () => { | ||
it.each` | ||
roomAttribute | subdomainAttribute | expectedRes | ||
${""} | ${undefined} | ${new Error("Missing room attribute")} | ||
${"https://abc.whereby.com/room"} | ${undefined} | ${{ roomUrl: new URL("https://abc.whereby.com/room"), subdomain: "abc" }} | ||
${"https://abc.whereby.com/room?roomKey=123"} | ${undefined} | ${{ roomUrl: new URL("https://abc.whereby.com/room?roomKey=123"), subdomain: "abc" }} | ||
${"https://abc-ip-127-0-0-1.hereby.dev:4443/room?roomKey=123"} | ${undefined} | ${{ roomUrl: new URL("https://abc-ip-127-0-0-1.hereby.dev:4443/room?roomKey=123"), subdomain: "abc" }} | ||
${"https://abc-ip-192-168-2-22.hereby.dev:4443/room?roomKey=123"} | ${undefined} | ${{ roomUrl: new URL("https://abc-ip-192-168-2-22.hereby.dev:4443/room?roomKey=123"), subdomain: "abc" }} | ||
${"https://whereby.com/room"} | ${undefined} | ${new Error("Missing subdomain attribute")} | ||
${"https://abc.whereby.com"} | ${"tt"} | ${new Error("Could not parse room URL")} | ||
`( | ||
"should return $expectedRes when roomAttribute:$roomAttribute, subdomainAttribute:$subdomainAttribute", | ||
({ roomAttribute, subdomainAttribute, expectedRes }) => { | ||
let res; | ||
|
||
try { | ||
res = parseRoomUrlAndSubdomain(roomAttribute, subdomainAttribute); | ||
} catch (error) { | ||
res = error; | ||
} | ||
|
||
expect(res).toEqual(expectedRes); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function parseRoomUrlAndSubdomain(roomAttribute?: string, subdomainAttribute?: string) { | ||
if (!roomAttribute) { | ||
throw new Error("Missing room attribute"); | ||
} | ||
|
||
// Get subdomain from room URL, or use it specified | ||
const m = /https:\/\/([^.]+)(\.whereby\.com|-ip-\d+-\d+-\d+-\d+.hereby.dev:4443)\/.+/.exec(roomAttribute); | ||
const subdomain = (m && m[1]) || subdomainAttribute; | ||
|
||
if (!subdomain) { | ||
throw new Error("Missing subdomain attribute"); | ||
} | ||
if (!m) { | ||
throw new Error("Could not parse room URL"); | ||
} | ||
|
||
const roomUrl = new URL(roomAttribute); | ||
|
||
return { | ||
subdomain, | ||
roomUrl, | ||
}; | ||
} |