This commit is contained in:
niki-on-github 2025-02-07 15:38:49 +08:00 committed by GitHub
commit 11d539c805
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -393,11 +393,16 @@ const ChatWindow = ({ id }: { id?: string }) => {
const [isReady, setIsReady] = useState(false); const [isReady, setIsReady] = useState(false);
const [isWSReady, setIsWSReady] = useState(false); const [isWSReady, setIsWSReady] = useState(false);
const ws = useSocket(
process.env.NEXT_PUBLIC_WS_URL!, let websocketUrl = process.env.NEXT_PUBLIC_WS_URL!;
setIsWSReady, if (websocketUrl.startsWith('/')) {
setHasError, const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
); const host = window.location.host;
const path = websocketUrl;
websocketUrl = `${protocol}${host}${path}`;
}
const ws = useSocket(websocketUrl, setIsWSReady, setHasError);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [messageAppeared, setMessageAppeared] = useState(false); const [messageAppeared, setMessageAppeared] = useState(false);