Skip to content

Commit

Permalink
Merge pull request #384 from boostcampwm-2024/feat/#383/ticle-end
Browse files Browse the repository at this point in the history
[Feat] 티클 종료 status 변경 시점 변경
  • Loading branch information
simeunseo authored Dec 5, 2024
2 parents c24e15b + a8b9451 commit ffab126
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions apps/web/src/components/live/ControlBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,24 @@ const ControlBar = ({ isOwner, onTicleEnd }: ControlBarProps) => {
};

useEffect(() => {
const handleBeforeUnload = (e: Event) => {
if (isOwner) {
const blob = new Blob([], {
type: 'application/json',
});
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
e.preventDefault();
};

const handleUnload = () => {
if (isOwner) {
const blob = new Blob([], { type: 'application/json' });
navigator.sendBeacon(`${ENV.API_URL}/dashboard/${ticleId}/end`, blob);
}
e.preventDefault();
};

window.addEventListener('beforeunload', handleBeforeUnload);
return () => window.removeEventListener('beforeunload', handleBeforeUnload);
window.addEventListener('unload', handleUnload);

return () => {
window.removeEventListener('beforeunload', handleBeforeUnload);
window.removeEventListener('unload', handleUnload);
};
}, []);

return (
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/hooks/mediasoup/useMediasoup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ const useMediasoup = () => {
clearMediasoup();
};

window.addEventListener('beforeunload', clearAll);
window.addEventListener('unload', clearAll);

return () => {
clearAll();
window.removeEventListener('beforeunload', clearAll);
window.removeEventListener('unload', clearAll);
};
}, []);
};
Expand Down

0 comments on commit ffab126

Please sign in to comment.