mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 16:00:07 +00:00
update sequence number and keep gateway alive
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
// import { BufReader } from "https://deno.land/std/io/bufio.ts"
|
||||
// import { TextProtoReader } from "https://deno.land/std/textproto/mod.ts"
|
||||
import { blue, green, red, yellow } from "https://deno.land/std/fmt/colors.ts"
|
||||
import { keepDiscordWebsocketAlive } from "./websocket.ts";
|
||||
import { keepDiscordWebsocketAlive, updatePreviousSequenceNumber } from "./websocket.ts";
|
||||
|
||||
class Client {
|
||||
/** The bot's token. This should never be used by end users. It is meant to be used internally to make requests to the Discord API. */
|
||||
@@ -65,6 +65,10 @@ class Client {
|
||||
switch (data.op) {
|
||||
case 10: // Initial Heartbeat
|
||||
keepDiscordWebsocketAlive(socket, (data.d as DiscordHeartbeatPayload).heartbeat_interval, data.s)
|
||||
break
|
||||
case 11:
|
||||
updatePreviousSequenceNumber(data.s)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { WebSocket } from "https://deno.land/std/ws/mod.ts";
|
||||
|
||||
export const keepDiscordWebsocketAlive = (socket: WebSocket, millesecondsInterval: number, payload: number | null = null) => {
|
||||
let previousSequenceNumber = payload
|
||||
let previousSequenceNumber: number | null = null
|
||||
|
||||
export const keepDiscordWebsocketAlive = (socket: WebSocket, millesecondsInterval: number, payload: number | null = null) => {
|
||||
setInterval(() => {
|
||||
const response = await socket.send(JSON.stringify({
|
||||
socket.send(JSON.stringify({
|
||||
op: 1,
|
||||
d: previousSequenceNumber
|
||||
}))
|
||||
|
||||
console.log(response)
|
||||
|
||||
}, millesecondsInterval)
|
||||
}
|
||||
|
||||
export const updatePreviousSequenceNumber = (sequence: number | null = null) => {
|
||||
previousSequenceNumber = sequence
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user