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(
|
||||
(opts: ConnectionOptions) => {
|
||||
webSocket.getWebSocket()?.close();
|
||||
console.debug(opts);
|
||||
setConnectedUsers([]);
|
||||
setMessageHistory([]);
|
||||
setAuthorId("");
|
||||
// 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();
|
||||
setConnectedUsers([]);
|
||||
setMessageHistory([]);
|
||||
setAuthorId("");
|
||||
|
||||
setDesiredName(opts.desiredName);
|
||||
setSocketUrl(opts.url);
|
||||
setDesiredName(opts.desiredName);
|
||||
setSocketUrl(opts.url);
|
||||
}
|
||||
},
|
||||
[webSocket]
|
||||
[desiredName, webSocket]
|
||||
);
|
||||
|
||||
const trySendMessage = useCallback(() => {
|
||||
|
|
Reference in a new issue