mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
Sketchy autoreconnect
This commit is contained in:
@@ -199,6 +199,7 @@ var InternalClient = (function () {
|
|||||||
this.servers = new _UtilCache2["default"]();
|
this.servers = new _UtilCache2["default"]();
|
||||||
this.unavailableServers = new _UtilCache2["default"]();
|
this.unavailableServers = new _UtilCache2["default"]();
|
||||||
this.private_channels = new _UtilCache2["default"]();
|
this.private_channels = new _UtilCache2["default"]();
|
||||||
|
this.autoReconnectInterval = 1000;
|
||||||
|
|
||||||
this.intervals = {
|
this.intervals = {
|
||||||
typing: [],
|
typing: [],
|
||||||
@@ -240,7 +241,7 @@ var InternalClient = (function () {
|
|||||||
InternalClient.prototype.disconnected = function disconnected() {
|
InternalClient.prototype.disconnected = function disconnected() {
|
||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
var forced = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
|
var autoReconnect = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
|
||||||
|
|
||||||
this.cleanIntervals();
|
this.cleanIntervals();
|
||||||
|
|
||||||
@@ -248,15 +249,18 @@ var InternalClient = (function () {
|
|||||||
_this2.leaveVoiceChannel(vc);
|
_this2.leaveVoiceChannel(vc);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.client.options.revive && !forced) {
|
if (autoReconnect) {
|
||||||
this.setup();
|
this.autoReconnectInterval = Math.min(this.autoReconnectInterval * (Math.random() + 1), 60000);
|
||||||
|
setTimeout(function () {
|
||||||
|
_this2.setup();
|
||||||
|
|
||||||
// Check whether the email is set (if not, only a token has been used for login)
|
// Check whether the email is set (if not, only a token has been used for login)
|
||||||
if (this.email) {
|
if (_this2.email) {
|
||||||
this.login(this.email, this.password);
|
_this2.login(_this2.email, _this2.password);
|
||||||
} else {
|
} else {
|
||||||
this.loginWithToken(this.token);
|
_this2.loginWithToken(_this2.token);
|
||||||
}
|
}
|
||||||
|
}, this.autoReconnectInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client.emit("disconnected");
|
this.client.emit("disconnected");
|
||||||
@@ -669,6 +673,7 @@ var InternalClient = (function () {
|
|||||||
_this13.websocket = null;
|
_this13.websocket = null;
|
||||||
throw error;
|
throw error;
|
||||||
})["catch"](function (error) {
|
})["catch"](function (error) {
|
||||||
|
_this13.websocket = null;
|
||||||
_this13.state = _ConnectionState2["default"].DISCONNECTED;
|
_this13.state = _ConnectionState2["default"].DISCONNECTED;
|
||||||
client.emit("disconnected");
|
client.emit("disconnected");
|
||||||
throw error;
|
throw error;
|
||||||
@@ -1623,14 +1628,17 @@ var InternalClient = (function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onclose = function () {
|
this.websocket.onclose = function (code) {
|
||||||
self.websocket = null;
|
self.websocket = null;
|
||||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||||
self.disconnected();
|
self.disconnected(_this40.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onerror = function (e) {
|
this.websocket.onerror = function (e) {
|
||||||
client.emit("error", e);
|
client.emit("error", e);
|
||||||
|
self.websocket = null;
|
||||||
|
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||||
|
self.disconnected(_this40.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = function (e) {
|
this.websocket.onmessage = function (e) {
|
||||||
@@ -1662,6 +1670,7 @@ var InternalClient = (function () {
|
|||||||
_this40.forceFetchCount = {};
|
_this40.forceFetchCount = {};
|
||||||
_this40.forceFetchQueue = [];
|
_this40.forceFetchQueue = [];
|
||||||
_this40.forceFetchLength = 1;
|
_this40.forceFetchLength = 1;
|
||||||
|
_this40.autoReconnectInterval = 1000;
|
||||||
|
|
||||||
data.guilds.forEach(function (server) {
|
data.guilds.forEach(function (server) {
|
||||||
if (!server.unavailable) {
|
if (!server.unavailable) {
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ export default class InternalClient {
|
|||||||
this.servers = new Cache();
|
this.servers = new Cache();
|
||||||
this.unavailableServers = new Cache();
|
this.unavailableServers = new Cache();
|
||||||
this.private_channels = new Cache();
|
this.private_channels = new Cache();
|
||||||
|
this.autoReconnectInterval = 1000;
|
||||||
|
|
||||||
this.intervals = {
|
this.intervals = {
|
||||||
typing : [],
|
typing : [],
|
||||||
@@ -161,7 +162,7 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnected(forced = false) {
|
disconnected(autoReconnect = false) {
|
||||||
|
|
||||||
this.cleanIntervals();
|
this.cleanIntervals();
|
||||||
|
|
||||||
@@ -169,15 +170,18 @@ export default class InternalClient {
|
|||||||
this.leaveVoiceChannel(vc);
|
this.leaveVoiceChannel(vc);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.client.options.revive && !forced) {
|
if (autoReconnect) {
|
||||||
this.setup();
|
this.autoReconnectInterval = Math.min(this.autoReconnectInterval * (Math.random() + 1), 60000);
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setup();
|
||||||
|
|
||||||
// Check whether the email is set (if not, only a token has been used for login)
|
// Check whether the email is set (if not, only a token has been used for login)
|
||||||
if (this.email) {
|
if (this.email) {
|
||||||
this.login(this.email, this.password);
|
this.login(this.email, this.password);
|
||||||
} else {
|
} else {
|
||||||
this.loginWithToken(this.token);
|
this.loginWithToken(this.token);
|
||||||
}
|
}
|
||||||
|
}, this.autoReconnectInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client.emit("disconnected");
|
this.client.emit("disconnected");
|
||||||
@@ -544,6 +548,7 @@ export default class InternalClient {
|
|||||||
throw error;
|
throw error;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
this.websocket = null;
|
||||||
this.state = ConnectionState.DISCONNECTED;
|
this.state = ConnectionState.DISCONNECTED;
|
||||||
client.emit("disconnected");
|
client.emit("disconnected");
|
||||||
throw error;
|
throw error;
|
||||||
@@ -1381,14 +1386,17 @@ export default class InternalClient {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onclose = () => {
|
this.websocket.onclose = (code) => {
|
||||||
self.websocket = null;
|
self.websocket = null;
|
||||||
self.state = ConnectionState.DISCONNECTED;
|
self.state = ConnectionState.DISCONNECTED;
|
||||||
self.disconnected();
|
self.disconnected(this.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onerror = e => {
|
this.websocket.onerror = e => {
|
||||||
client.emit("error", e);
|
client.emit("error", e);
|
||||||
|
self.websocket = null;
|
||||||
|
self.state = ConnectionState.DISCONNECTED;
|
||||||
|
self.disconnected(this.client.options.autoReconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = e => {
|
this.websocket.onmessage = e => {
|
||||||
@@ -1418,6 +1426,7 @@ export default class InternalClient {
|
|||||||
this.forceFetchCount = {};
|
this.forceFetchCount = {};
|
||||||
this.forceFetchQueue = [];
|
this.forceFetchQueue = [];
|
||||||
this.forceFetchLength = 1;
|
this.forceFetchLength = 1;
|
||||||
|
this.autoReconnectInterval = 1000;
|
||||||
|
|
||||||
data.guilds.forEach(server => {
|
data.guilds.forEach(server => {
|
||||||
if (!server.unavailable) {
|
if (!server.unavailable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user