Better addresses
This commit is contained in:
@@ -6,7 +6,7 @@ import AppSidebar from "@/components/Sidebar";
|
||||
import Message from "@/types/message";
|
||||
import useUser, { User } from "@/hooks/get-user";
|
||||
import { NumberMap } from "@/types/typeUtils";
|
||||
import auth from "@/lib/auth";
|
||||
import auth, { makeAddress } from "@/lib/auth";
|
||||
|
||||
// In this testing instance we are assuming that Alice's node is localhost
|
||||
// To make this functional we need to add a settings feature to the api
|
||||
@@ -22,7 +22,7 @@ export default function AppHome() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!ip || !user || loading) return;
|
||||
auth(ip, wsRef, () => {}, setMessages);
|
||||
auth(makeAddress(ip, 7090), wsRef, () => {}, setMessages);
|
||||
setUserList((prev) => {
|
||||
prev[user.id] = user;
|
||||
return prev;
|
||||
|
||||
@@ -8,7 +8,7 @@ import Message from "@/types/message";
|
||||
import useUser, { User } from "@/hooks/get-user";
|
||||
import { NumberMap } from "@/types/typeUtils";
|
||||
import ServerType from "@/types/server";
|
||||
import auth from "@/lib/auth";
|
||||
import auth, { makeAddress } from "@/lib/auth";
|
||||
|
||||
export default function Server() {
|
||||
const { id: ip } = useParams<{ id: string }>();
|
||||
@@ -20,7 +20,7 @@ export default function Server() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!ip || !user || loading) return;
|
||||
auth(ip, wsRef, setServer, setMessages);
|
||||
auth(makeAddress(ip), wsRef, setServer, setMessages);
|
||||
setUserList((prev) => {
|
||||
prev[user.id] = user;
|
||||
return prev;
|
||||
|
||||
+5
-1
@@ -3,6 +3,10 @@ import Server from "@/types/server";
|
||||
import axios from "axios";
|
||||
import { Dispatch, RefObject, SetStateAction } from "react";
|
||||
|
||||
export function makeAddress(ip: string, defaultPort = 7080) {
|
||||
return ip.includes(":") ? `${ip}` : `${ip}:${defaultPort}`;
|
||||
}
|
||||
|
||||
export default async function auth(
|
||||
ip: string,
|
||||
wsRef: RefObject<WebSocket | null>,
|
||||
@@ -14,7 +18,7 @@ export default async function auth(
|
||||
).token;
|
||||
|
||||
// Open the WebSocket connection
|
||||
const ws = new WebSocket(`ws://${ip}:7080`);
|
||||
const ws = new WebSocket(`ws://${ip}`);
|
||||
wsRef.current = ws;
|
||||
|
||||
ws.onopen = () => {
|
||||
|
||||
Reference in New Issue
Block a user