@@ -41,8 +41,6 @@ const feedClientDefaults: Pick<FeedClientOptions, "archived" | "mode"> = {
4141 mode : "compact" ,
4242} ;
4343
44- const DEFAULT_DISCONNECT_DELAY = 2000 ;
45-
4644const CLIENT_REF_ID_PREFIX = "client_" ;
4745
4846class Feed {
@@ -53,10 +51,7 @@ class Feed {
5351 private userFeedId : string ;
5452 private broadcaster : EventEmitter ;
5553 private broadcastChannel ! : BroadcastChannel | null ;
56- private disconnectTimer : ReturnType < typeof setTimeout > | null = null ;
5754 private hasSubscribedToRealTimeUpdates : boolean = false ;
58- private visibilityChangeHandler : ( ) => void = ( ) => { } ;
59- private visibilityChangeListenerConnected : boolean = false ;
6055
6156 // The raw store instance, used for binding in React and other environments
6257 public store : FeedStore ;
@@ -117,13 +112,6 @@ class Feed {
117112
118113 this . socketManager ?. leave ( this ) ;
119114
120- this . tearDownVisibilityListeners ( ) ;
121-
122- if ( this . disconnectTimer ) {
123- clearTimeout ( this . disconnectTimer ) ;
124- this . disconnectTimer = null ;
125- }
126-
127115 if ( this . broadcastChannel ) {
128116 this . broadcastChannel . close ( ) ;
129117 }
@@ -553,8 +541,6 @@ class Feed {
553541 __loadingType : undefined ,
554542 __fetchSource : undefined ,
555543 __experimentalCrossBrowserUpdates : undefined ,
556- auto_manage_socket_connection : undefined ,
557- auto_manage_socket_connection_delay : undefined ,
558544 } ;
559545
560546 const result = await this . knock . client ( ) . makeRequest ( {
@@ -815,10 +801,6 @@ class Feed {
815801 // In server environments we might not have a socket connection
816802 if ( ! this . socketManager ) return ;
817803
818- if ( this . defaultOptions . auto_manage_socket_connection ) {
819- this . setUpVisibilityListeners ( ) ;
820- }
821-
822804 // If we're initializing but they have previously opted to listen to real-time updates
823805 // then we will automatically reconnect on their behalf
824806 if ( this . hasSubscribedToRealTimeUpdates && this . knock . isAuthenticated ( ) ) {
@@ -838,33 +820,6 @@ class Feed {
838820 }
839821 }
840822
841- /**
842- * Listen for changes to document visibility and automatically disconnect
843- * or reconnect the socket after a delay
844- */
845- private setUpVisibilityListeners ( ) {
846- if (
847- typeof document === "undefined" ||
848- this . visibilityChangeListenerConnected
849- ) {
850- return ;
851- }
852-
853- this . visibilityChangeHandler = this . handleVisibilityChange . bind ( this ) ;
854- this . visibilityChangeListenerConnected = true ;
855- document . addEventListener ( "visibilitychange" , this . visibilityChangeHandler ) ;
856- }
857-
858- private tearDownVisibilityListeners ( ) {
859- if ( typeof document === "undefined" ) return ;
860-
861- document . removeEventListener (
862- "visibilitychange" ,
863- this . visibilityChangeHandler ,
864- ) ;
865- this . visibilityChangeListenerConnected = false ;
866- }
867-
868823 private emitEvent (
869824 type :
870825 | MessageEngagementStatus
@@ -882,34 +837,6 @@ class Feed {
882837 // Internal events only need `items:`
883838 this . broadcastOverChannel ( `items:${ type } ` , { items } ) ;
884839 }
885-
886- private handleVisibilityChange ( ) {
887- const disconnectDelay =
888- this . defaultOptions . auto_manage_socket_connection_delay ??
889- DEFAULT_DISCONNECT_DELAY ;
890-
891- const client = this . knock . client ( ) ;
892-
893- if ( document . visibilityState === "hidden" ) {
894- // When the tab is hidden, clean up the socket connection after a delay
895- this . disconnectTimer = setTimeout ( ( ) => {
896- client . socket ?. disconnect ( ) ;
897- this . disconnectTimer = null ;
898- } , disconnectDelay ) ;
899- } else if ( document . visibilityState === "visible" ) {
900- // When the tab is visible, clear the disconnect timer if active to cancel disconnecting
901- // This handles cases where the tab is only briefly hidden to avoid unnecessary disconnects
902- if ( this . disconnectTimer ) {
903- clearTimeout ( this . disconnectTimer ) ;
904- this . disconnectTimer = null ;
905- }
906-
907- // If the socket is not connected, try to reconnect
908- if ( ! client . socket ?. isConnected ( ) ) {
909- client . socket ?. connect ( ) ;
910- }
911- }
912- }
913840}
914841
915842export default Feed ;
0 commit comments