1
Fork 0

Don't reconnect for namechange

This commit is contained in:
Tobias Berger 2022-01-28 10:46:05 +00:00 committed by GitHub
parent d1f386d00c
commit 58cd4b872b

View file

@ -103,16 +103,25 @@ export default function Index(): JSX.Element {
const tryConnect = useCallback( const tryConnect = useCallback(
(opts: ConnectionOptions) => { (opts: ConnectionOptions) => {
webSocket.getWebSocket()?.close(); // Don't reconnect, just send new desiredName
console.debug(opts); if (opts.desiredName === desiredName) {
setConnectedUsers([]); setDesiredName(opts.desiredName);
setMessageHistory([]); webSocket.sendJsonMessage({
setAuthorId(""); type: MessageType.DESIRED_NAME,
date: Date.now(),
desiredName: opts.desiredName,
} as DesiredNameMessage);
} else {
webSocket.getWebSocket()?.close();
setConnectedUsers([]);
setMessageHistory([]);
setAuthorId("");
setDesiredName(opts.desiredName); setDesiredName(opts.desiredName);
setSocketUrl(opts.url); setSocketUrl(opts.url);
}
}, },
[webSocket] [desiredName, webSocket]
); );
const trySendMessage = useCallback(() => { const trySendMessage = useCallback(() => {