From 23bbd91a76da9252b9ca1e08ac69e719a2dde755 Mon Sep 17 00:00:00 2001 From: Om Swami Date: Wed, 5 Mar 2025 16:13:10 +0530 Subject: [PATCH] Fix chat delays in active order Fixes #1293 Draft --- .../EncryptedSocketChat/index.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx index 00225d8a..ddf11cd4 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx @@ -3,7 +3,6 @@ import { useTranslation } from 'react-i18next'; import { Button, TextField, Grid, Paper, Typography } from '@mui/material'; import { encryptMessage, decryptMessage } from '../../../../pgp'; import { AuditPGPDialog } from '../../../Dialogs'; -import { websocketClient, type WebsocketConnection } from '../../../../services/Websocket'; import { GarageContext, type UseGarageStoreType } from '../../../../contexts/GarageContext'; // Icons @@ -21,6 +20,7 @@ import { FederationContext, } from '../../../../contexts/FederationContext'; import { type UseAppStoreType, AppContext } from '../../../../contexts/AppContext'; +import TorModule from '../../../../native/TorModule'; const audioPath = window.NativeRobosats === undefined @@ -64,7 +64,7 @@ const EncryptedSocketChat: React.FC = ({ const [peerPubKey, setPeerPubKey] = useState(); const [serverMessages, setServerMessages] = useState([]); const [value, setValue] = useState(''); - const [connection, setConnection] = useState(); + const [connection, setConnection] = useState(null); const [audit, setAudit] = useState(false); const [waitingEcho, setWaitingEcho] = useState(false); const [lastSent, setLastSent] = useState('---BLANK---'); @@ -82,7 +82,7 @@ const EncryptedSocketChat: React.FC = ({ useEffect(() => { if (![9, 10].includes(status)) { connection?.close(); - setConnection(undefined); + setConnection(null); } }, [status]); @@ -90,7 +90,7 @@ const EncryptedSocketChat: React.FC = ({ // On component unmount close reconnecting-websockets return () => { connection?.close(); - setConnection(undefined); + setConnection(null); }; }, []); @@ -117,12 +117,11 @@ const EncryptedSocketChat: React.FC = ({ .getCoordinator(order.shortAlias) .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); - websocketClient - .open( - `${url.replace(/^https?:\/\//, 'ws://') + basePath}/ws/chat/${ - order.id - }/?token_sha256_hex=${sha256(slot?.token)}`, - ) + TorModule.sendWsOpen( + `${url.replace(/^https?:\/\//, 'ws://') + basePath}/ws/chat/${ + order.id + }/?token_sha256_hex=${sha256(slot?.token)}`, + ) .then((connection) => { setConnection(connection); setConnected(true);