mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 07:04:53 +09:00
Fix issues with reconnect and logging out
Fix problems encountered logging out and in while the connection has dropped and is in the process of reconnecting.
This commit is contained in:
1 parent
6458810571
commit
d627c5e094
4 files changed
+17
-10
No files matched your search
@@ -178,7 +178,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
setTimeout(timeout) {
|
||||
this._timeout = timeout;
|
||||
|
||||
if (this._reconnectId && this.timeout < this._reconnectDelay / 2) {
|
||||
if (this._reconnectId && this._timeout < this._reconnectDelay / 2) {
|
||||
clearTimeout(this._reconnectId);
|
||||
this.reconnect();
|
||||
}
|
||||
@@ -280,6 +280,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
this._lastReceivedSeq = null;
|
||||
this._sessionToken = null;
|
||||
this._sendBuffer.length = 0;
|
||||
this._state = "new";
|
||||
this._connected = false;
|
||||
this.emit("close");
|
||||
return;
|
||||
|
||||
@@ -87,6 +87,7 @@ export default async function bootstrap() {
|
||||
wsUrl.protocol = wsUrl.protocol.replace("http", "ws");
|
||||
|
||||
let controlConnector = new ControlConnector(wsUrl, 10);
|
||||
controlConnector.setTimeout(15);
|
||||
let control = new Control(controlConnector, plugins);
|
||||
|
||||
ReactDOM.render(<App control={control} plugins={plugins}/>, document.getElementById("root"));
|
||||
|
||||
@@ -31,6 +31,7 @@ export default function App(props) {
|
||||
|
||||
function clearToken() {
|
||||
setToken(null);
|
||||
connector.token = null;
|
||||
localStorage.removeItem("master_token");
|
||||
}
|
||||
|
||||
@@ -54,6 +55,14 @@ export default function App(props) {
|
||||
connector.on("close", onClose);
|
||||
connector.on("error", onError);
|
||||
|
||||
return () => {
|
||||
connector.off("error", onError);
|
||||
connector.off("close", onClose);
|
||||
connector.off("connect", onConnect);
|
||||
};
|
||||
}, [props.control]);
|
||||
|
||||
useEffect(() => {
|
||||
if (token && !connected) {
|
||||
if (props.control.loggingOut) {
|
||||
clearToken();
|
||||
@@ -63,13 +72,7 @@ export default function App(props) {
|
||||
connector.connect();
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
connector.off("error", onError);
|
||||
connector.off("close", onClose);
|
||||
connector.off("connect", onConnect);
|
||||
};
|
||||
});
|
||||
}, [token, connected]);
|
||||
|
||||
let page;
|
||||
if (connected) {
|
||||
|
||||
@@ -122,6 +122,10 @@ export class Control extends libLink.Link {
|
||||
}
|
||||
|
||||
async updateLogSubscriptions() {
|
||||
if (!this.connector.connected) {
|
||||
return;
|
||||
}
|
||||
|
||||
await libLink.messages.setLogSubscriptions.send(this, {
|
||||
all: false,
|
||||
master: false,
|
||||
@@ -137,8 +141,6 @@ export class Control extends libLink.Link {
|
||||
}
|
||||
|
||||
async shutdown() {
|
||||
this.connector.setTimeout(5);
|
||||
|
||||
try {
|
||||
await libLink.messages.prepareDisconnect.send(this);
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user