Don't reconnect for namechange
This commit is contained in:
parent
d1f386d00c
commit
58cd4b872b
1 changed files with 17 additions and 8 deletions
|
@ -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(() => {
|
||||||
|
|
Reference in a new issue