UNPKG

@socket.io/postgres-adapter

Version:

The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers

57 lines (56 loc) 1.87 kB
import { type Pool } from "pg"; import { ClusterAdapterWithHeartbeat } from "socket.io-adapter"; import type { ClusterAdapterOptions, ClusterMessage, ClusterResponse, Offset, ServerId } from "socket.io-adapter"; import { PubSubClient } from "./util"; export interface PostgresAdapterOptions { /** * The prefix of the notification channel * @default "socket.io" */ channelPrefix?: string; /** * The name of the table for payloads over the 8000 bytes limit or containing binary data * @default "socket_io_attachments" */ tableName?: string; /** * The threshold for the payload size in bytes (see https://www.postgresql.org/docs/current/sql-notify.html) * @default 8000 */ payloadThreshold?: number; /** * Number of ms between two cleanup queries * @default 30000 */ cleanupInterval?: number; /** * Handler for errors. If undefined, the errors will be simply logged. * * @default undefined */ errorHandler?: (err: Error) => void; } /** * Returns a function that will create a PostgresAdapter instance. * * @param pool - a pg.Pool instance * @param opts - additional options * * @public */ export declare function createAdapter(pool: Pool, opts?: PostgresAdapterOptions & ClusterAdapterOptions): (nsp: any) => PostgresAdapter; export declare class PostgresAdapter extends ClusterAdapterWithHeartbeat { private readonly client; /** * Adapter constructor. * * @param nsp - the namespace * @param opts - additional options * @param client * * @public */ constructor(nsp: any, opts: ClusterAdapterOptions, client: PubSubClient); protected doPublish(message: ClusterMessage): Promise<Offset>; protected doPublishResponse(_requesterUid: ServerId, response: ClusterResponse): Promise<void>; }