mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +09:00
Rename connected and dropped events
Rename the connector events connected and dropped to connect and drop respectively to be consistent with common Node.js names for events like close.
This commit is contained in:
1 parent
1629eaf225
commit
5c1214ad38
4 files changed
+14
-14
No files matched your search
@@ -199,7 +199,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
this._doConnect();
|
||||
|
||||
// Wait for the connection to be ready
|
||||
await events.once(this, "connected");
|
||||
await events.once(this, "connect");
|
||||
}
|
||||
|
||||
async _doConnect() {
|
||||
@@ -275,7 +275,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
} else {
|
||||
this._state = "handshake";
|
||||
this.reconnect();
|
||||
this.emit("dropped");
|
||||
this.emit("drop");
|
||||
}
|
||||
|
||||
this.stopHeartbeat();
|
||||
@@ -361,7 +361,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
this.startHeartbeat();
|
||||
this._startedReconnect = null;
|
||||
this._connected = true;
|
||||
this.emit("connected");
|
||||
this.emit("connect");
|
||||
|
||||
} else if (type === "continue") {
|
||||
console.log("SOCKET | resuming existing session");
|
||||
@@ -374,7 +374,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
}
|
||||
this._startedReconnect = null;
|
||||
this._connected = true;
|
||||
this.emit("connected");
|
||||
this.emit("connect");
|
||||
|
||||
} else if (type === "invalidate") {
|
||||
this._heartbeatInterval = null;
|
||||
|
||||
@@ -433,7 +433,7 @@ class ControlConnection extends BaseConnection {
|
||||
this.instanceOutputSubscriptions = new Set();
|
||||
|
||||
this.ws_dumper = null;
|
||||
this.connector.on("connected", () => {
|
||||
this.connector.on("connect", () => {
|
||||
this.connector._socket.clusterio_ignore_dump = !!this.ws_dumper;
|
||||
});
|
||||
this.connector.on("close", () => {
|
||||
@@ -701,7 +701,7 @@ class WebSocketServerConnector extends link.WebSocketBaseConnector {
|
||||
this._state = "connected";
|
||||
this._connected = true;
|
||||
this._attachSocketHandlers();
|
||||
this.emit("connected");
|
||||
this.emit("connect");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -736,7 +736,7 @@ class WebSocketServerConnector extends link.WebSocketBaseConnector {
|
||||
for (let message of this._sendBuffer) {
|
||||
this._socket.send(JSON.stringify(message));
|
||||
}
|
||||
this.emit("connected");
|
||||
this.emit("connect");
|
||||
}
|
||||
|
||||
setTimeout(timeout) {
|
||||
@@ -782,7 +782,7 @@ class WebSocketServerConnector extends link.WebSocketBaseConnector {
|
||||
|
||||
} else {
|
||||
this._state = "handshake";
|
||||
this.emit("dropped");
|
||||
this.emit("drop");
|
||||
this._timeoutId = setTimeout(() => { this._timedOut() }, this._timeout * 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,24 +45,24 @@ describe("Integration of lib/link", function() {
|
||||
|
||||
it("should reconnect on connection lost", async function() {
|
||||
controlConnector._socket.close(1008, "Test");
|
||||
await events.once(controlConnector, "connected");
|
||||
await events.once(controlConnector, "connect");
|
||||
});
|
||||
|
||||
it("should reconnect on connection terminated", async function() {
|
||||
controlConnector._socket.terminate();
|
||||
await events.once(controlConnector, "connected");
|
||||
await events.once(controlConnector, "connect");
|
||||
});
|
||||
|
||||
it("should reconnect on connection heartbeat timeout", async function() {
|
||||
controlConnector.stopHeartbeat();
|
||||
await events.once(controlConnector, "connected");
|
||||
await events.once(controlConnector, "connect");
|
||||
});
|
||||
|
||||
it("should invalidate on reconnection with bad session token", async function() {
|
||||
controlConnector._sessionToken = "blah";
|
||||
controlConnector.stopHeartbeat();
|
||||
await events.once(controlConnector, "invalidate");
|
||||
await events.once(controlConnector, "connected");
|
||||
await events.once(controlConnector, "connect");
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
|
||||
@@ -89,8 +89,8 @@ describe("lib/link/connectors", function() {
|
||||
testConnector._processHandshake({ seq: 1, type: 'hello', data: { version: "test", plugins: {} }});
|
||||
assert(called, "register was not called");
|
||||
});
|
||||
it("should emit connected on ready", async function() {
|
||||
let result = events.once(testConnector, 'connected');
|
||||
it("should emit connect on ready", async function() {
|
||||
let result = events.once(testConnector, "connect");
|
||||
testConnector._processHandshake(
|
||||
{ seq: 1, type: 'ready', data: { session_token: "x", heartbeat_interval: 10 }}
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user