mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
Add unsubscribe call on SharePage unload
This commit is contained in:
@@ -54,7 +54,15 @@ const SharePage = (props)=>{
|
||||
fetchThemeBundle(undefined, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
||||
|
||||
// listen for changes in the brew version
|
||||
const eventSource = new EventSource(`/stream/${props.brew.shareId}`);
|
||||
const eventSource = new EventSource(`/api/stream/${props.brew.shareId}`);
|
||||
|
||||
let subId = '';
|
||||
eventSource.addEventListener('subscribe', (evt)=>{
|
||||
const messageData = JSON.parse(evt.data);
|
||||
|
||||
subId = messageData.id;
|
||||
});
|
||||
|
||||
eventSource.addEventListener('brewUpdated', (evt)=>{
|
||||
const messageData = JSON.parse(evt.data);
|
||||
|
||||
@@ -64,7 +72,11 @@ const SharePage = (props)=>{
|
||||
}
|
||||
});
|
||||
|
||||
return ()=>{
|
||||
window.addEventListener('beforeunload', async ()=>{
|
||||
await request.get(`/api/stream/unsubscribe/${subId}`);
|
||||
});
|
||||
|
||||
return async ()=>{
|
||||
document.removeEventListener('keydown', handleControlKeys);
|
||||
eventSource.close();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user