mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
ssr errors mitigation
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import "@whereby.com/browser-sdk/embed";
|
|
||||||
import { useCallback, useEffect, useRef, useState, useContext, RefObject } from "react";
|
import { useCallback, useEffect, useRef, useState, useContext, RefObject } from "react";
|
||||||
import { Box, Button, Text, VStack, HStack, Spinner, useToast } from "@chakra-ui/react";
|
import { Box, Button, Text, VStack, HStack, Spinner, useToast } from "@chakra-ui/react";
|
||||||
import useRoomMeeting from "./useRoomMeeting";
|
import useRoomMeeting from "./useRoomMeeting";
|
||||||
@@ -153,7 +152,21 @@ const recordingTypeRequiresConsent = (recordingType: NonNullable<Meeting['record
|
|||||||
return recordingType === 'cloud';
|
return recordingType === 'cloud';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// next throws even with "use client"
|
||||||
|
const useWhereby = () => {
|
||||||
|
const [wherebyLoaded, setWherebyLoaded] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
import("@whereby.com/browser-sdk/embed").then(() => {
|
||||||
|
setWherebyLoaded(true);
|
||||||
|
}).catch(console.error.bind(console));
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
return wherebyLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
export default function Room(details: RoomDetails) {
|
export default function Room(details: RoomDetails) {
|
||||||
|
const wherebyLoaded = useWhereby();
|
||||||
const wherebyRef = useRef<HTMLElement>(null);
|
const wherebyRef = useRef<HTMLElement>(null);
|
||||||
const roomName = details.params.roomName;
|
const roomName = details.params.roomName;
|
||||||
const meeting = useRoomMeeting(roomName);
|
const meeting = useRoomMeeting(roomName);
|
||||||
@@ -186,17 +199,10 @@ export default function Room(details: RoomDetails) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading || !isAuthenticated || !roomUrl) return;
|
if (isLoading || !isAuthenticated || !roomUrl) return;
|
||||||
|
|
||||||
// accessibility: whereby grabs focus after its interface is loaded => we lose "esc" and keyboard control over the consent popup
|
|
||||||
const handleReady = (event: any) => {
|
|
||||||
console.log("whereby-embed ready event:", event);
|
|
||||||
};
|
|
||||||
|
|
||||||
wherebyRef.current?.addEventListener("leave", handleLeave);
|
wherebyRef.current?.addEventListener("leave", handleLeave);
|
||||||
wherebyRef.current?.addEventListener("ready", handleReady);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
wherebyRef.current?.removeEventListener("leave", handleLeave);
|
wherebyRef.current?.removeEventListener("leave", handleLeave);
|
||||||
wherebyRef.current?.removeEventListener("ready", handleReady);
|
|
||||||
};
|
};
|
||||||
}, [handleLeave, roomUrl, isLoading, isAuthenticated]);
|
}, [handleLeave, roomUrl, isLoading, isAuthenticated]);
|
||||||
|
|
||||||
@@ -224,7 +230,7 @@ export default function Room(details: RoomDetails) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{roomUrl && meetingId && (
|
{roomUrl && meetingId && wherebyLoaded && (
|
||||||
<>
|
<>
|
||||||
<whereby-embed
|
<whereby-embed
|
||||||
ref={wherebyRef}
|
ref={wherebyRef}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ const useRoomMeeting = (
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
setResponse(result);
|
setResponse(result);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
console.debug("Meeting Loaded:", result);
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
const shouldShowHuman = shouldShowError(error);
|
const shouldShowHuman = shouldShowError(error);
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ export const RecordingConsentProvider: React.FC<RecordingConsentProviderProps> =
|
|||||||
|
|
||||||
const safeWriteToStorage = (meetingIds: string[]): void => {
|
const safeWriteToStorage = (meetingIds: string[]): void => {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(meetingIds));
|
if (typeof window !== 'undefined' && window.localStorage) {
|
||||||
|
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(meetingIds));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to save consent data to localStorage:", error);
|
console.error("Failed to save consent data to localStorage:", error);
|
||||||
}
|
}
|
||||||
@@ -69,6 +71,11 @@ export const RecordingConsentProvider: React.FC<RecordingConsentProviderProps> =
|
|||||||
// initialize on mount
|
// initialize on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
try {
|
||||||
|
if (typeof window === 'undefined' || !window.localStorage) {
|
||||||
|
setState({ ready: true, consentAnsweredForMeetings: new Set() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const stored = localStorage.getItem(LOCAL_STORAGE_KEY);
|
const stored = localStorage.getItem(LOCAL_STORAGE_KEY);
|
||||||
if (!stored) {
|
if (!stored) {
|
||||||
setState({ ready: true, consentAnsweredForMeetings: new Set() });
|
setState({ ready: true, consentAnsweredForMeetings: new Set() });
|
||||||
|
|||||||
Reference in New Issue
Block a user