diff --git a/lib/tunnelbroker/peer-to-peer-message-handler.js b/lib/tunnelbroker/peer-to-peer-message-handler.js --- a/lib/tunnelbroker/peer-to-peer-message-handler.js +++ b/lib/tunnelbroker/peer-to-peer-message-handler.js @@ -31,7 +31,7 @@ function PeerToPeerMessageHandler(props: Props): React.Node { const { socketSend, getSessionCounter, doesSocketExist } = props; - const { addListener, removeListener } = useTunnelbroker(); + const { addListener, removeListener, socketState } = useTunnelbroker(); const peerToPeerMessageHandler = usePeerToPeerMessageHandler(); const handleOlmMessageToDevice = useHandleOlmMessageToDevice(); @@ -180,12 +180,16 @@ const processingInputMessagesStarted = React.useRef(false); React.useEffect(() => { - if (!viewerID || processingInputMessagesStarted.current) { + if ( + !viewerID || + processingInputMessagesStarted.current || + !socketState.isAuthorized + ) { return; } processingInputMessagesStarted.current = true; void processPersistedInboundMessages(); - }, [processPersistedInboundMessages, viewerID]); + }, [processPersistedInboundMessages, viewerID, socketState]); } export { PeerToPeerMessageHandler };