Gateway: add SB_SESSION_CLOSE and SB_SESSION_INVALIDATE events

This commit is contained in:
Rory&
2026-03-13 03:45:26 +01:00
parent bf778e5133
commit 3fdc6a54aa
3 changed files with 33 additions and 12 deletions

View File

@@ -17,25 +17,24 @@
*/
import {
getPermission,
Permissions,
RabbitMQ,
listenEvent,
Ban,
EVENTEnum,
EventOpts,
getPermission,
listenEvent,
ListenEventOpts,
Member,
EVENTEnum,
Relationship,
Message,
NewUrlUserSignatureData,
GuildMemberAddEvent,
Ban,
Permissions,
RabbitMQ,
Recipient,
Relationship,
} from "@spacebar/util";
import { OPCODES } from "../util/Constants";
import { CLOSECODES, OPCODES } from "../util/Constants";
import { Send } from "../util/Send";
import { WebSocket } from "@spacebar/gateway";
import { Channel as AMQChannel } from "amqplib";
import { Recipient } from "@spacebar/util";
import * as console from "node:console";
import { PublicMember, RelationshipType } from "@spacebar/schemas";
import { bgRedBright } from "picocolors";
@@ -208,6 +207,27 @@ async function consume(this: WebSocket, opts: EventOpts) {
opts.acknowledge?.();
// console.log("event", event);
// special codes
switch (event) {
case "SB_SESSION_CLOSE":
// TODO: what do we even send here?
await Send(this, {
op: OPCODES.Reconnect,
s: this.sequence++,
d: opts.reconnect_delay ?? opts.data ?? 1000,
});
this.close(1000); // not a discord close code, standard WS "Normal Closure"
return;
case "SB_SESSION_REMOVE":
// TODO: what do we even send here?
await Send(this, {
op: OPCODES.Invalid_Session,
s: this.sequence++,
});
this.close(CLOSECODES.Invalid_session); // TODO: this is deprecated?
return;
}
// subscription managment
switch (event) {
case "GUILD_MEMBER_REMOVE":

View File

@@ -42,7 +42,7 @@ export enum OPCODES {
Stream_Set_Paused = 22,
Request_Application_Commands = 24,
// We don't know the names for these:
ThirtySix = 36, // this is just a guild id?
Request_Channel_Statuses = 36, // this is just a guild id?
Guild_Subscriptions_Bulk = 37, // Already implemented it seems?
SetQoS = 40,
ClientInitSession = 41,

View File

@@ -60,6 +60,7 @@ export interface Event {
event: EVENT;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: any;
reconnect_delay?: number;
origin?: string;
}
@@ -848,4 +849,4 @@ export type EVENT =
| "THREAD_MEMBERS_UPDATE"
| CUSTOMEVENTS;
export type CUSTOMEVENTS = "INVALIDATED" | "RATELIMIT";
export type CUSTOMEVENTS = "INVALIDATED" | "RATELIMIT" | "SB_SESSION_REMOVE" | "SB_SESSION_CLOSE";