From 82d2db191de629fbc43ec003228a961b403981f1 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Sat, 25 Nov 2023 11:41:25 +0100 Subject: [PATCH] handle closing of sse's better --- backend/app.js | 3 +++ frontend/src/app.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/backend/app.js b/backend/app.js index d7ca71b..05304fe 100644 --- a/backend/app.js +++ b/backend/app.js @@ -150,6 +150,9 @@ app.get( '/clientDisplayNotifier', ( req, res ) => { let det = { 'type': 'basics', 'data': currentDetails }; res.write( `data: ${ JSON.stringify( det ) }\n\n` ); connectedClients[ req.session.id ] = res; + req.on( 'close', () => { + connectedClients.splice( Object.keys( connectedClients ).indexOf( req.session.id ), 1 ); + } ); } ); const sendUpdate = ( update ) => { diff --git a/frontend/src/app.js b/frontend/src/app.js index a9b167d..602d008 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -185,6 +185,9 @@ app.get( '/clientDisplayNotifier', ( req, res ) => { let det = { 'type': 'basics', 'data': currentDetails }; res.write( `data: ${ JSON.stringify( det ) }\n\n` ); connectedClients[ req.session.id ] = res; + req.on( 'close', () => { + connectedClients.splice( Object.keys( connectedClients ).indexOf( req.session.id ), 1 ); + } ); } ); app.get( '/mainNotifier', ( req, res ) => {