Skip to content

Commit

Permalink
chat should work now
Browse files Browse the repository at this point in the history
  • Loading branch information
lopatoj committed Sep 22, 2024
1 parent 2cc58ef commit c7d3ffd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client/src/pages/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement>(null);
const [messages, setMessages] = useState<Message[]>([]);
Expand All @@ -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();
Expand All @@ -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) => {
Expand Down Expand Up @@ -84,9 +91,7 @@ function Chat() {
))}
</div>
<input ref={input} />
<button
onClick={send_message}
>send</button>
<button onClick={send_message}>send</button>
</div>
);
}
Expand Down

0 comments on commit c7d3ffd

Please sign in to comment.