mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
Allow switching servers via Favoriten while already connected
This commit is contained in:
1 parent
f523005972
commit
0b7d2b7346
1 file changed
+30
-1
+30
-1
@@ -1267,6 +1267,35 @@ function App() {
|
|||||||
const connectChannelPassword = overrides?.channelPassword ?? channelPassword;
|
const connectChannelPassword = overrides?.channelPassword ?? channelPassword;
|
||||||
const connectDefaultChannel = overrides?.defaultChannel ?? defaultChannel;
|
const connectDefaultChannel = overrides?.defaultChannel ?? defaultChannel;
|
||||||
|
|
||||||
|
// Switching servers while already connected (or mid-connect): tear down the
|
||||||
|
// old socket first and detach its handlers so its async close doesn't later
|
||||||
|
// clobber state that belongs to the new connection.
|
||||||
|
const previousSocket = socketRef.current;
|
||||||
|
if (previousSocket) {
|
||||||
|
previousSocket.onopen = null;
|
||||||
|
previousSocket.onmessage = null;
|
||||||
|
previousSocket.onerror = null;
|
||||||
|
previousSocket.onclose = null;
|
||||||
|
if (previousSocket.readyState === WebSocket.OPEN || previousSocket.readyState === WebSocket.CONNECTING) {
|
||||||
|
previousSocket.close();
|
||||||
|
}
|
||||||
|
stopMic();
|
||||||
|
audioPlayerRef.current?.dispose();
|
||||||
|
audioPlayerRef.current = null;
|
||||||
|
audioContextRef.current?.close();
|
||||||
|
audioContextRef.current = null;
|
||||||
|
setConnected(false);
|
||||||
|
setChannels([]);
|
||||||
|
setClients([]);
|
||||||
|
setSelected(null);
|
||||||
|
setChat([]);
|
||||||
|
setServerChat([]);
|
||||||
|
setPmThreads({});
|
||||||
|
setPokes([]);
|
||||||
|
setActiveTab("channel");
|
||||||
|
setTalkers(new Set());
|
||||||
|
}
|
||||||
|
|
||||||
hasConnectedRef.current = false;
|
hasConnectedRef.current = false;
|
||||||
setConnecting(true);
|
setConnecting(true);
|
||||||
setConnectError(null);
|
setConnectError(null);
|
||||||
@@ -1782,7 +1811,7 @@ function App() {
|
|||||||
<button
|
<button
|
||||||
key={f.id}
|
key={f.id}
|
||||||
className="ts-menu-item"
|
className="ts-menu-item"
|
||||||
disabled={connected || connecting}
|
disabled={connecting}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
connectToFavorite(f);
|
connectToFavorite(f);
|
||||||
setFavoritesMenuOpen(false);
|
setFavoritesMenuOpen(false);
|
||||||
|
|||||||
Reference in new issue
Block a user