From c7d3ffd42cf1e4717a8c046ba5abe344c73946d4 Mon Sep 17 00:00:00 2001 From: Justin Lopato Date: Sun, 22 Sep 2024 01:28:49 -0500 Subject: [PATCH] chat should work now --- client/src/pages/Chat/Chat.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/src/pages/Chat/Chat.tsx b/client/src/pages/Chat/Chat.tsx index c531998..41edf62 100644 --- a/client/src/pages/Chat/Chat.tsx +++ b/client/src/pages/Chat/Chat.tsx @@ -6,6 +6,14 @@ import { useNavigate, useParams } from "react-router-dom"; import { getChat } from "../../modules/backend_functions"; import { auth } from "../../modules/firebase"; +function getWS() +{ + if (location.hostname === "localhost" || location.hostname === "127.0.0.1") + return "ws://localhost:8081" + else + return "ws://motivibe.live:8081" +} + function Chat() { const input = useRef(null); const [messages, setMessages] = useState([]); @@ -31,7 +39,7 @@ function Chat() { setMessages(chat.messages || []); const token = await user.getIdToken(); - const socket = io(`ws://localhost:8081`, { + const socket = io(getWS(), { auth: { token }, }); socket.connect(); @@ -41,7 +49,6 @@ function Chat() { socket.on("message", (message: Message) => { if (message.user == user.displayName) {return;} const new_messages = [...JSON.parse(JSON.stringify(messages)), message] - console.log("wdawtf", messages, new_messages) setMessages(new_messages); }); send.current = (message: Message) => { @@ -84,9 +91,7 @@ function Chat() { ))} - + ); }