:|
This commit is contained in:
parent
fc8a90ffc4
commit
aa5485d8fd
1 changed files with 12 additions and 1 deletions
|
@ -91,7 +91,7 @@ const RoomBody: React.FC = ({}) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useChannel(
|
const [channel] = useChannel(
|
||||||
{
|
{
|
||||||
channelName: `${env.NEXT_PUBLIC_APP_ENV}-${roomId}`,
|
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
|
// Init story name
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sessionData && roomFromDb) {
|
if (sessionData && roomFromDb) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue