@@ -710,17 +710,32 @@ app.ws("/websocket", async function (ws, req) {
710
710
) ,
711
711
) ;
712
712
} ;
713
+ const keepWsAliveListener = ( ) => {
714
+ // TODO: How to send an empty message that doesn't conflict with HTMX?
715
+ ws . send ( "<div data-reason='empty-message-to-keepalive-websocket'></div>" ) ;
716
+ } ;
713
717
714
718
emitter . on ( "room-change" , roomListener ) ;
715
719
emitter . on ( "in-the-hub-change" , inTheHubListener ) ;
720
+ emitter . on ( "keep-ws-alive" , keepWsAliveListener ) ;
716
721
717
722
// If client closes connection, stop sending events
718
723
ws . on ( "close" , ( ) => {
719
724
emitter . off ( "room-change" , roomListener ) ;
720
725
emitter . off ( "in-the-hub-change" , inTheHubListener ) ;
726
+ emitter . off ( "keep-ws-alive" , keepWsAliveListener ) ;
721
727
} ) ;
722
728
} ) ;
723
729
730
+ // After seeing reference to another service with a 60 second idle timeout for
731
+ // websocket connections (https://stackoverflow.com/a/48764819), I thought I
732
+ // might try the same solution and see if that fixed the issue despite this
733
+ // being on a different stack.
734
+ // TODO: Test and see if the websocket still closes after 55 seconds
735
+ setInterval ( ( ) => {
736
+ emitter . emit ( "keep-ws-alive" ) ;
737
+ } , 1000 * 30 ) ;
738
+
724
739
const roomNameToNote = { } ;
725
740
app . post (
726
741
"/note" ,
@@ -799,7 +814,7 @@ app.post(
799
814
} ) ;
800
815
801
816
const botCreated = await apiResult . json ( ) ;
802
- console . log ( "Bot created with ID #" + botCreated . id ) ;
817
+ // console.log("Bot created with ID #" + botCreated.id);
803
818
if ( ! botCreated . id ) {
804
819
console . log ( "Bot creation failed somehow" ) ;
805
820
console . log ( apiResult . status ) ;
0 commit comments