From f85246c8d6590c8d00af72ff2d28114d6cae2d2b Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 26 Nov 2024 13:48:32 +0530 Subject: [PATCH] Conv --- .../Collections/AlbumCastDialog.tsx | 15 +++++++--- web/packages/new/photos/services/cast.ts | 29 +++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx index a244fbd68c..ca4a0d272d 100644 --- a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx +++ b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx @@ -4,7 +4,7 @@ import { boxSeal } from "@/base/crypto"; import log from "@/base/log"; import type { Collection } from "@/media/collection"; import { photosDialogZIndex } from "@/new/photos/components/utils/z-index"; -import castGateway from "@/new/photos/services/cast"; +import castGateway, { revokeAllCastTokens } from "@/new/photos/services/cast"; import { loadCast } from "@/new/photos/utils/chromecast-sender"; import SingleInputForm, { type SingleInputFormProps, @@ -38,11 +38,18 @@ export const AlbumCastDialog: React.FC = ({ const [browserCanCast, setBrowserCanCast] = useState(false); - // Make API call to clear all previous sessions on component mount. useEffect(() => { - castGateway.revokeAllTokens(); + // Make API call to clear all previous sessions (if any) on component + // mount so that the user can start a new session. + // + // This is usually not going to have any effect, so we don't need to + // wait for it to finish (or do anything specific if it fails). + void revokeAllCastTokens(); - // Otherwise tsc complains about unknown property chrome. + // Determine if Chromecast is supported by the current browser + // (effectively, only Chrome). + // + // Override, otherwise tsc complains about unknown property `chrome`. // eslint-disable-next-line @typescript-eslint/dot-notation setBrowserCanCast(typeof window["chrome"] !== "undefined"); }, []); diff --git a/web/packages/new/photos/services/cast.ts b/web/packages/new/photos/services/cast.ts index 76b92dcb4f..e145c96c1e 100644 --- a/web/packages/new/photos/services/cast.ts +++ b/web/packages/new/photos/services/cast.ts @@ -1,27 +1,20 @@ +import { authenticatedRequestHeaders } from "@/base/http"; import log from "@/base/log"; import { apiURL } from "@/base/origins"; import { ApiError } from "@ente/shared/error"; -import { getToken } from "@ente/shared/storage/localStorage/helpers"; import HTTPService from "@ente/shared/network/HTTPService"; +import { getToken } from "@ente/shared/storage/localStorage/helpers"; + +/** + * Revoke all existing outstanding cast tokens for the current user on remote. + */ +export const revokeAllCastTokens = async () => + fetch(await apiURL("/cast/revoke-all-tokens"), { + method: "DELETE", + headers: await authenticatedRequestHeaders(), + }); class CastGateway { - public async revokeAllTokens() { - try { - const token = getToken(); - await HTTPService.delete( - await apiURL("/cast/revoke-all-tokens"), - undefined, - undefined, - { - "X-Auth-Token": token, - }, - ); - } catch (e) { - log.error("removeAllTokens failed", e); - // swallow error - } - } - public async getPublicKey(code: string): Promise { let resp; try {