This commit is contained in:
Atridad Lahiji 2023-08-08 12:39:06 -06:00 committed by atridadl
parent b34e6243c8
commit a4956e9926
No known key found for this signature in database

View file

@ -91,7 +91,7 @@ const RoomBody: React.FC = ({}) => {
},
});
useChannel(
const [channel] = useChannel(
{
channelName: `${env.NEXT_PUBLIC_APP_ENV}-${roomId}`,
},
@ -116,6 +116,17 @@ const RoomBody: React.FC = ({}) => {
}
);
// Subscribe on mount and unsubscribe on unmount
useEffect(() => {
window.addEventListener("beforeunload", () => channel.presence.leave());
return () => {
window.removeEventListener("beforeunload", () =>
channel.presence.leave()
);
channel.presence.leave();
};
}, [channel.presence, roomId]);
// Init story name
useEffect(() => {
if (sessionData && roomFromDb) {