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(
(opts: ConnectionOptions) => {
// Don't reconnect, just send new desiredName
if (opts.desiredName === desiredName) {
setDesiredName(opts.desiredName);
webSocket.sendJsonMessage({
type: MessageType.DESIRED_NAME,
date: Date.now(),
desiredName: opts.desiredName,
} as DesiredNameMessage);
} else {
webSocket.getWebSocket()?.close();
console.debug(opts);
setConnectedUsers([]);
setMessageHistory([]);
setAuthorId("");
setDesiredName(opts.desiredName);
setSocketUrl(opts.url);
}
},
[webSocket]
[desiredName, webSocket]
);
const trySendMessage = useCallback(() => {