chore(code):Add cache room ID feature, no need to manually input room ID

This commit is contained in:
david_bai
2025-10-23 20:47:49 +08:00
parent 0d308515a7
commit 5ca89d71ad
12 changed files with 213 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
// Utilities to cache a single room ID in browser localStorage
// Works on client only; no-ops on server.
const CACHED_KEY = "pd_cached_room_id_v1";
function isClient() {
return typeof window !== "undefined";
}
export function getCachedId(): string | null {
if (!isClient()) return null;
try {
const v = window.localStorage.getItem(CACHED_KEY);
return v && v.trim() ? v : null;
} catch (_) {
return null;
}
}
export function setCachedId(id: string): void {
if (!isClient()) return;
try {
window.localStorage.setItem(CACHED_KEY, id);
} catch (_) {
// ignore
}
}
export function clearCachedId(): void {
if (!isClient()) return;
try {
window.localStorage.removeItem(CACHED_KEY);
} catch (_) {
// ignore
}
}