Skip to content

Commit

Permalink
Use call link as join link (#49)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Marcell Guilherme Costa da Silva <[email protected]>
Co-authored-by: mazuh <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2023
1 parent f12aa58 commit aee5978
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/participants/ParticipantsModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("ParticipantsModal", () => {
preloadedState: { call },
});
expect(
screen.getByText(window.location.href + "join?callUid=" + call.uid)
screen.getByText(`${window.location.origin}${window.location.pathname}`)
).toBeVisible();
});

Expand All @@ -51,7 +51,7 @@ describe("ParticipantsModal", () => {
await act(() => fireEvent.click(copyButton));

expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
window.location.href + "join?callUid=" + call.uid
`${window.location.origin}${window.location.pathname}`
);

const successSnackbar = await waitFor(() => screen.getByRole("alert"));
Expand Down
5 changes: 2 additions & 3 deletions src/components/participants/ParticipantsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
selectPendingUsers,
} from "../../state/call";
import DialogModal from "../basic/DialogModal";
import { selectCallHostId, selectCallUid } from "../../state/call";
import { selectCallHostId } from "../../state/call";
import { selectUserUid } from "../../state/user";

export interface ParticipantsModalProps {
Expand Down Expand Up @@ -103,8 +103,7 @@ export default function ParticipantsModal({
}

function CallLink() {
const callUid = useAppSelector(selectCallUid);
const link = `${window.location.origin}/join?callUid=${callUid}`;
const link = `${window.location.origin}${window.location.pathname}`;

const handleCopyClick = async () => {
await navigator.clipboard.writeText(link);
Expand Down
10 changes: 9 additions & 1 deletion src/hooks/useRedirectionRule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,20 @@ describe("getRedirectionRule: /p2p-call", () => {
expect(result).toBe("/create");
});

it("when not authenticated, be forced to reset flow", () => {
it("when not authenticated and the url has call uuid, then go to join page", () => {
// TODO: retrieve attempt call uid and convert into "/?joining=" flow
const result = getRedirectionRule(
{ path: "/p2p-call/123-321", hasAuth: false, isSessionBlocked: false },
{}
);
expect(result).toBe("/join?callUid=123-321");
});

it("when not authenticated and the url has not call uuid, be forced to reset flow", () => {
const result = getRedirectionRule(
{ path: "/p2p-call/", hasAuth: false },
{}
);
expect(result).toBe("/");
});

Expand Down
8 changes: 7 additions & 1 deletion src/hooks/useRedirectionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function useRedirectionRule(): string {
export interface RedirectionContext {
path: string;
hasAuth: boolean;
isSessionBlocked: boolean;
isSessionBlocked?: boolean;
pendingCall?: string;
ongoingCall?: string;
}
Expand Down Expand Up @@ -127,6 +127,8 @@ export function getRedirectionRule(
}

if (path.startsWith("/p2p-call")) {
const callUuid = path.replace("/p2p-call/", "");

if (isSessionBlocked) {
return "/blocked-session";
}
Expand All @@ -136,6 +138,10 @@ export function getRedirectionRule(
// return "/left";
}

if (!hasAuth && callUuid) {
return `/join?callUid=${callUuid}`;
}

if (!hasAuth) {
return "/";
}
Expand Down

0 comments on commit aee5978

Please sign in to comment.