diff --git a/lib/tunnelbroker/tunnelbroker-context.js b/lib/tunnelbroker/tunnelbroker-context.js index 32975d6b84..cccb0a3423 100644 --- a/lib/tunnelbroker/tunnelbroker-context.js +++ b/lib/tunnelbroker/tunnelbroker-context.js @@ -110,6 +110,9 @@ function TunnelbrokerProvider(props: Props): React.Node { 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 @@ function TunnelbrokerProvider(props: Props): React.Node { [secondaryTunnelbrokerConnection], ); + React.useEffect(() => { + if (!isAppActive) { + socket.current?.close(); + } + }, [isAppActive]); + const addListener = React.useCallback( (listener: TunnelbrokerSocketListener) => { listeners.current.add(listener);