mirror of
https://github.com/spacebarchat/server.git
synced 2026-03-30 13:55:39 +00:00
Gateway: allow addressing dispatch events to specific sessions
This commit is contained in:
@@ -106,6 +106,7 @@ export async function setupListener(this: WebSocket) {
|
||||
}
|
||||
|
||||
this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts);
|
||||
this.events[this.session_id] = await listenEvent(this.session_id, consumer, opts);
|
||||
|
||||
await Promise.all(
|
||||
relationships.map(async (relationship) => {
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
ReadyPrivateChannel,
|
||||
GuildOrUnavailable,
|
||||
Snowflake,
|
||||
ThreadMember,
|
||||
} from "@spacebar/util";
|
||||
import { JsonValue } from "@protobuf-ts/runtime";
|
||||
import {
|
||||
@@ -49,11 +50,11 @@ import {
|
||||
RelationshipType,
|
||||
UserPrivate,
|
||||
} from "@spacebar/schemas";
|
||||
import { ThreadMember } from "../entities/ThreadMember";
|
||||
|
||||
export interface Event {
|
||||
guild_id?: string;
|
||||
user_id?: string;
|
||||
session_id?: string;
|
||||
channel_id?: string;
|
||||
created_at?: Date;
|
||||
event: EVENT;
|
||||
|
||||
@@ -35,7 +35,7 @@ let unixSocketListener: UnixSocketListener | null = null;
|
||||
let unixSocketWriter: UnixSocketWriter | null = null;
|
||||
|
||||
export async function emitEvent(payload: Omit<Event, "created_at">) {
|
||||
const id = (payload.guild_id || payload.channel_id || payload.user_id) as string;
|
||||
const id = (payload.guild_id || payload.channel_id || payload.user_id || payload.session_id) as string;
|
||||
if (!id) return console.error("event doesn't contain any id", payload);
|
||||
|
||||
if (RabbitMQ.connection) {
|
||||
@@ -485,7 +485,7 @@ class UnixSocketWriter {
|
||||
await this.broadcastLock;
|
||||
return await (this.broadcastLock = new Promise((res) => {
|
||||
const tsw = Stopwatch.startNew();
|
||||
const payloadBuf = Buffer.from(JSON.stringify({ id: (event.guild_id || event.channel_id || event.user_id) as string, event }));
|
||||
const payloadBuf = Buffer.from(JSON.stringify({ id: (event.guild_id || event.channel_id || event.user_id || event.session_id) as string, event }));
|
||||
const lenBuf = Buffer.alloc(4);
|
||||
lenBuf.writeUInt32BE(payloadBuf.length, 0);
|
||||
const framed = Buffer.concat([lenBuf, payloadBuf]);
|
||||
|
||||
Reference in New Issue
Block a user