diff --git a/lib/tunnelbroker/tunnelbroker-context.js b/lib/tunnelbroker/tunnelbroker-context.js --- a/lib/tunnelbroker/tunnelbroker-context.js +++ b/lib/tunnelbroker/tunnelbroker-context.js @@ -110,6 +110,9 @@ const accessToken = useSelector(state => state.commServicesAccessToken); const userID = useSelector(state => state.currentUserInfo?.id); + const isAppActive = useSelector( + state => state.lifecycleState !== 'background', + ); const [unauthorizedDeviceID, setUnauthorizedDeviceID] = React.useState(null); @@ -440,6 +443,12 @@ [secondaryTunnelbrokerConnection], ); + React.useEffect(() => { + if (!isAppActive) { + socket.current?.close(); + } + }, [isAppActive]); + const addListener = React.useCallback( (listener: TunnelbrokerSocketListener) => { listeners.current.add(listener);