This commit is contained in:
Atridad Lahiji 2023-08-08 12:39:06 -06:00
parent fc8a90ffc4
commit aa5485d8fd
No known key found for this signature in database
GPG key ID: 7CB8245F56BC3880

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) {