mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
Experimental gateway v5 support
This commit is contained in:
@@ -86,7 +86,7 @@ var _UtilTokenCacher = require("../Util/TokenCacher");
|
|||||||
|
|
||||||
var _UtilTokenCacher2 = _interopRequireDefault(_UtilTokenCacher);
|
var _UtilTokenCacher2 = _interopRequireDefault(_UtilTokenCacher);
|
||||||
|
|
||||||
var GATEWAY_VERSION = 4;
|
var GATEWAY_VERSION = 5;
|
||||||
var zlib;
|
var zlib;
|
||||||
var libVersion = require('../../package.json').version;
|
var libVersion = require('../../package.json').version;
|
||||||
|
|
||||||
@@ -1806,13 +1806,7 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
this.websocket = new _ws2["default"](url);
|
this.websocket = new _ws2["default"](url);
|
||||||
|
|
||||||
this.websocket.onopen = function () {
|
this.websocket.onopen = function () {};
|
||||||
if (_this36.sessionID) {
|
|
||||||
_this36.resume();
|
|
||||||
} else {
|
|
||||||
_this36.identify();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.websocket.onclose = function (event) {
|
this.websocket.onclose = function (event) {
|
||||||
_this36.websocket = null;
|
_this36.websocket = null;
|
||||||
@@ -1889,52 +1883,28 @@ var InternalClient = (function () {
|
|||||||
_this36.sequence = 0;
|
_this36.sequence = 0;
|
||||||
_this36.identify();
|
_this36.identify();
|
||||||
break;
|
break;
|
||||||
|
case 10:
|
||||||
|
console.log(packet);
|
||||||
|
if (_this36.sessionID) {
|
||||||
|
_this36.resume();
|
||||||
|
} else {
|
||||||
|
_this36.identify();
|
||||||
|
}
|
||||||
|
_this36.heartbeat();
|
||||||
|
_this36.intervals.kai = setInterval(function () {
|
||||||
|
return _this36.heartbeat();
|
||||||
|
}, packet.d.heartbeat_interval);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
_this36.heartbeatAcked = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_this36.client.emit("unknown", packet);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
InternalClient.prototype.resume = function resume() {
|
|
||||||
var data = {
|
|
||||||
op: 6,
|
|
||||||
d: {
|
|
||||||
token: this.token,
|
|
||||||
session_id: this.sessionID,
|
|
||||||
seq: this.sequence
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.sendWS(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
InternalClient.prototype.identify = function identify() {
|
|
||||||
var data = {
|
|
||||||
op: 2,
|
|
||||||
d: {
|
|
||||||
token: this.token,
|
|
||||||
v: GATEWAY_VERSION,
|
|
||||||
compress: this.client.options.compress,
|
|
||||||
large_threshold: this.client.options.largeThreshold,
|
|
||||||
properties: {
|
|
||||||
"$os": process.platform,
|
|
||||||
"$browser": "discord.js",
|
|
||||||
"$device": "discord.js",
|
|
||||||
"$referrer": "",
|
|
||||||
"$referring_domain": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.client.options.shard) {
|
|
||||||
data.d.shard = this.client.options.shard;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sendWS(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
InternalClient.prototype.heartbeat = function heartbeat() {
|
|
||||||
this.sendWS({ op: 1, d: Date.now() });
|
|
||||||
};
|
|
||||||
|
|
||||||
InternalClient.prototype.processPacket = function processPacket(packet) {
|
InternalClient.prototype.processPacket = function processPacket(packet) {
|
||||||
var _this37 = this;
|
var _this37 = this;
|
||||||
|
|
||||||
@@ -1943,9 +1913,8 @@ var InternalClient = (function () {
|
|||||||
switch (packet.t) {
|
switch (packet.t) {
|
||||||
case _Constants.PacketType.RESUME:
|
case _Constants.PacketType.RESUME:
|
||||||
case _Constants.PacketType.READY:
|
case _Constants.PacketType.READY:
|
||||||
this.intervals.kai = setInterval(function () {
|
this.autoReconnectInterval = 1000;
|
||||||
return _this37.heartbeat();
|
this.state = _ConnectionState2["default"].READY;
|
||||||
}, data.heartbeat_interval);
|
|
||||||
|
|
||||||
if (packet.t === _Constants.PacketType.RESUME) {
|
if (packet.t === _Constants.PacketType.RESUME) {
|
||||||
break;
|
break;
|
||||||
@@ -1959,7 +1928,6 @@ var InternalClient = (function () {
|
|||||||
this.forceFetchCount = {};
|
this.forceFetchCount = {};
|
||||||
this.forceFetchQueue = [];
|
this.forceFetchQueue = [];
|
||||||
this.forceFetchLength = 1;
|
this.forceFetchLength = 1;
|
||||||
this.autoReconnectInterval = 1000;
|
|
||||||
|
|
||||||
data.guilds.forEach(function (server) {
|
data.guilds.forEach(function (server) {
|
||||||
if (!server.unavailable) {
|
if (!server.unavailable) {
|
||||||
@@ -2016,8 +1984,6 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = _ConnectionState2["default"].READY;
|
|
||||||
|
|
||||||
client.emit("debug", "ready packet took " + (Date.now() - startTime) + "ms to process");
|
client.emit("debug", "ready packet took " + (Date.now() - startTime) + "ms to process");
|
||||||
client.emit("debug", "ready with " + this.servers.length + " servers, " + this.unavailableServers.length + " unavailable servers, " + this.channels.length + " channels and " + this.users.length + " users cached.");
|
client.emit("debug", "ready with " + this.servers.length + " servers, " + this.unavailableServers.length + " unavailable servers, " + this.channels.length + " channels and " + this.users.length + " users cached.");
|
||||||
|
|
||||||
@@ -2060,6 +2026,23 @@ var InternalClient = (function () {
|
|||||||
client.emit("warn", "message was deleted but channel is not cached");
|
client.emit("warn", "message was deleted but channel is not cached");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case _Constants.PacketType.MESSAGE_DELETE_BULK:
|
||||||
|
var channel = this.channels.get("id", data.channel_id) || this.private_channels.get("id", data.channel_id);
|
||||||
|
if (channel) {
|
||||||
|
data.ids.forEach(function (id) {
|
||||||
|
// potentially blank
|
||||||
|
var msg = channel.messages.get("id", id);
|
||||||
|
client.emit("messageDeleted", msg, channel);
|
||||||
|
if (msg) {
|
||||||
|
channel.messages.remove(msg);
|
||||||
|
} else {
|
||||||
|
client.emit("debug", "message was deleted but message is not cached");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
client.emit("warn", "message was deleted but channel is not cached");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case _Constants.PacketType.MESSAGE_UPDATE:
|
case _Constants.PacketType.MESSAGE_UPDATE:
|
||||||
// format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format
|
// format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format
|
||||||
var channel = this.channels.get("id", data.channel_id) || this.private_channels.get("id", data.channel_id);
|
var channel = this.channels.get("id", data.channel_id) || this.private_channels.get("id", data.channel_id);
|
||||||
@@ -2670,6 +2653,48 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
InternalClient.prototype.resume = function resume() {
|
||||||
|
var data = {
|
||||||
|
op: 6,
|
||||||
|
d: {
|
||||||
|
token: this.token,
|
||||||
|
session_id: this.sessionID,
|
||||||
|
seq: this.sequence
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sendWS(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
InternalClient.prototype.identify = function identify() {
|
||||||
|
var data = {
|
||||||
|
op: 2,
|
||||||
|
d: {
|
||||||
|
token: this.token,
|
||||||
|
v: GATEWAY_VERSION,
|
||||||
|
compress: this.client.options.compress,
|
||||||
|
large_threshold: this.client.options.largeThreshold,
|
||||||
|
properties: {
|
||||||
|
"$os": process.platform,
|
||||||
|
"$browser": "discord.js",
|
||||||
|
"$device": "discord.js",
|
||||||
|
"$referrer": "",
|
||||||
|
"$referring_domain": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.client.options.shard) {
|
||||||
|
data.d.shard = this.client.options.shard;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendWS(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
InternalClient.prototype.heartbeat = function heartbeat() {
|
||||||
|
this.sendWS({ op: 1, d: Date.now() });
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(InternalClient, [{
|
_createClass(InternalClient, [{
|
||||||
key: "uptime",
|
key: "uptime",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ Constants.PacketType = {
|
|||||||
CHANNEL_UPDATE: "CHANNEL_UPDATE",
|
CHANNEL_UPDATE: "CHANNEL_UPDATE",
|
||||||
MESSAGE_CREATE: "MESSAGE_CREATE",
|
MESSAGE_CREATE: "MESSAGE_CREATE",
|
||||||
MESSAGE_DELETE: "MESSAGE_DELETE",
|
MESSAGE_DELETE: "MESSAGE_DELETE",
|
||||||
|
MESSAGE_DELETE_BULK: "MESSAGE_DELETE_BULK",
|
||||||
MESSAGE_UPDATE: "MESSAGE_UPDATE",
|
MESSAGE_UPDATE: "MESSAGE_UPDATE",
|
||||||
PRESENCE_UPDATE: "PRESENCE_UPDATE",
|
PRESENCE_UPDATE: "PRESENCE_UPDATE",
|
||||||
READY: "READY",
|
READY: "READY",
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import Invite from "../Structures/Invite";
|
|||||||
import VoiceConnection from "../Voice/VoiceConnection";
|
import VoiceConnection from "../Voice/VoiceConnection";
|
||||||
import TokenCacher from "../Util/TokenCacher";
|
import TokenCacher from "../Util/TokenCacher";
|
||||||
|
|
||||||
var GATEWAY_VERSION = 4;
|
var GATEWAY_VERSION = 5;
|
||||||
var zlib;
|
var zlib;
|
||||||
var libVersion = require('../../package.json').version;
|
var libVersion = require('../../package.json').version;
|
||||||
|
|
||||||
@@ -1578,11 +1578,6 @@ export default class InternalClient {
|
|||||||
this.websocket = new WebSocket(url);
|
this.websocket = new WebSocket(url);
|
||||||
|
|
||||||
this.websocket.onopen = () => {
|
this.websocket.onopen = () => {
|
||||||
if(this.sessionID) {
|
|
||||||
this.resume();
|
|
||||||
} else {
|
|
||||||
this.identify();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onclose = (event) => {
|
this.websocket.onclose = (event) => {
|
||||||
@@ -1660,59 +1655,34 @@ export default class InternalClient {
|
|||||||
this.sequence = 0;
|
this.sequence = 0;
|
||||||
this.identify();
|
this.identify();
|
||||||
break;
|
break;
|
||||||
|
case 10:
|
||||||
|
console.log(packet);
|
||||||
|
if(this.sessionID) {
|
||||||
|
this.resume();
|
||||||
|
} else {
|
||||||
|
this.identify();
|
||||||
|
}
|
||||||
|
this.heartbeat();
|
||||||
|
this.intervals.kai = setInterval(() => this.heartbeat(), packet.d.heartbeat_interval);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
this.heartbeatAcked = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.client.emit("unknown", packet);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
resume() {
|
|
||||||
var data = {
|
|
||||||
op: 6,
|
|
||||||
d: {
|
|
||||||
token: this.token,
|
|
||||||
session_id: this.sessionID,
|
|
||||||
seq: this.sequence
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.sendWS(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
identify() {
|
|
||||||
var data = {
|
|
||||||
op: 2,
|
|
||||||
d: {
|
|
||||||
token: this.token,
|
|
||||||
v: GATEWAY_VERSION,
|
|
||||||
compress: this.client.options.compress,
|
|
||||||
large_threshold : this.client.options.largeThreshold,
|
|
||||||
properties: {
|
|
||||||
"$os": process.platform,
|
|
||||||
"$browser": "discord.js",
|
|
||||||
"$device": "discord.js",
|
|
||||||
"$referrer": "",
|
|
||||||
"$referring_domain": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.client.options.shard) {
|
|
||||||
data.d.shard = this.client.options.shard;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sendWS(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
heartbeat() {
|
|
||||||
this.sendWS({ op: 1, d: Date.now() });
|
|
||||||
}
|
|
||||||
|
|
||||||
processPacket(packet) {
|
processPacket(packet) {
|
||||||
var client = this.client;
|
var client = this.client;
|
||||||
var data = packet.d;
|
var data = packet.d;
|
||||||
switch (packet.t) {
|
switch (packet.t) {
|
||||||
case PacketType.RESUME:
|
case PacketType.RESUME:
|
||||||
case PacketType.READY:
|
case PacketType.READY:
|
||||||
this.intervals.kai = setInterval(() => this.heartbeat(), data.heartbeat_interval);
|
this.autoReconnectInterval = 1000;
|
||||||
|
this.state = ConnectionState.READY;
|
||||||
|
|
||||||
if(packet.t === PacketType.RESUME) {
|
if(packet.t === PacketType.RESUME) {
|
||||||
break;
|
break;
|
||||||
@@ -1726,7 +1696,6 @@ 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) {
|
||||||
@@ -1778,9 +1747,6 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.state = ConnectionState.READY;
|
|
||||||
|
|
||||||
client.emit("debug", `ready packet took ${Date.now() - startTime}ms to process`);
|
client.emit("debug", `ready packet took ${Date.now() - startTime}ms to process`);
|
||||||
client.emit("debug", `ready with ${this.servers.length} servers, ${this.unavailableServers.length} unavailable servers, ${this.channels.length} channels and ${this.users.length} users cached.`);
|
client.emit("debug", `ready with ${this.servers.length} servers, ${this.unavailableServers.length} unavailable servers, ${this.channels.length} channels and ${this.users.length} users cached.`);
|
||||||
|
|
||||||
@@ -1821,6 +1787,23 @@ export default class InternalClient {
|
|||||||
client.emit("warn", "message was deleted but channel is not cached");
|
client.emit("warn", "message was deleted but channel is not cached");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PacketType.MESSAGE_DELETE_BULK:
|
||||||
|
var channel = this.channels.get("id", data.channel_id) || this.private_channels.get("id", data.channel_id);
|
||||||
|
if (channel) {
|
||||||
|
data.ids.forEach((id) => {
|
||||||
|
// potentially blank
|
||||||
|
var msg = channel.messages.get("id", id);
|
||||||
|
client.emit("messageDeleted", msg, channel);
|
||||||
|
if (msg) {
|
||||||
|
channel.messages.remove(msg);
|
||||||
|
} else {
|
||||||
|
client.emit("debug", "message was deleted but message is not cached");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
client.emit("warn", "message was deleted but channel is not cached");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case PacketType.MESSAGE_UPDATE:
|
case PacketType.MESSAGE_UPDATE:
|
||||||
// format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format
|
// format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format
|
||||||
var channel = this.channels.get("id", data.channel_id) || this.private_channels.get("id", data.channel_id);
|
var channel = this.channels.get("id", data.channel_id) || this.private_channels.get("id", data.channel_id);
|
||||||
@@ -2391,4 +2374,46 @@ export default class InternalClient {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resume() {
|
||||||
|
var data = {
|
||||||
|
op: 6,
|
||||||
|
d: {
|
||||||
|
token: this.token,
|
||||||
|
session_id: this.sessionID,
|
||||||
|
seq: this.sequence
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sendWS(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
identify() {
|
||||||
|
var data = {
|
||||||
|
op: 2,
|
||||||
|
d: {
|
||||||
|
token: this.token,
|
||||||
|
v: GATEWAY_VERSION,
|
||||||
|
compress: this.client.options.compress,
|
||||||
|
large_threshold : this.client.options.largeThreshold,
|
||||||
|
properties: {
|
||||||
|
"$os": process.platform,
|
||||||
|
"$browser": "discord.js",
|
||||||
|
"$device": "discord.js",
|
||||||
|
"$referrer": "",
|
||||||
|
"$referring_domain": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.client.options.shard) {
|
||||||
|
data.d.shard = this.client.options.shard;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendWS(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
heartbeat() {
|
||||||
|
this.sendWS({ op: 1, d: Date.now() });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ Constants.PacketType = {
|
|||||||
CHANNEL_UPDATE : "CHANNEL_UPDATE",
|
CHANNEL_UPDATE : "CHANNEL_UPDATE",
|
||||||
MESSAGE_CREATE : "MESSAGE_CREATE",
|
MESSAGE_CREATE : "MESSAGE_CREATE",
|
||||||
MESSAGE_DELETE : "MESSAGE_DELETE",
|
MESSAGE_DELETE : "MESSAGE_DELETE",
|
||||||
|
MESSAGE_DELETE_BULK : "MESSAGE_DELETE_BULK",
|
||||||
MESSAGE_UPDATE : "MESSAGE_UPDATE",
|
MESSAGE_UPDATE : "MESSAGE_UPDATE",
|
||||||
PRESENCE_UPDATE : "PRESENCE_UPDATE",
|
PRESENCE_UPDATE : "PRESENCE_UPDATE",
|
||||||
READY : "READY",
|
READY : "READY",
|
||||||
|
|||||||
Reference in New Issue
Block a user