MCPcopy
hub / github.com/socketio/socket.io / Emitter

Class Emitter

packages/socket.io-postgres-emitter/lib/index.ts:84–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84export class Emitter<
85 EmitEvents extends EventsMap = DefaultEventsMap,
86 ServerSideEvents extends EventsMap = DefaultEventsMap,
87> {
88 public readonly channel: string;
89 public readonly tableName: string;
90 public payloadThreshold: number;
91
92 constructor(
93 readonly pool: any,
94 readonly nsp: string = "/",
95 opts: Partial<PostgresEmitterOptions> = {},
96 ) {
97 const channelPrefix = opts.channelPrefix || "socket.io";
98 this.channel = `${channelPrefix}#${nsp}`;
99 this.tableName = opts.tableName || "socket_io_attachments";
100 this.payloadThreshold = opts.payloadThreshold || 8000;
101 }
102
103 /**
104 * Return a new emitter for the given namespace.
105 *
106 * @param nsp - namespace
107 * @public
108 */
109 public of(nsp: string): Emitter {
110 return new Emitter(this.pool, (nsp[0] !== "/" ? "/" : "") + nsp);
111 }
112
113 /**
114 * Emits to all clients.
115 *
116 * @return Always true
117 * @public
118 */
119 public emit<Ev extends EventNames<EmitEvents>>(
120 ev: Ev,
121 ...args: EventParams<EmitEvents, Ev>
122 ): true {
123 return new BroadcastOperator<EmitEvents, ServerSideEvents>(this).emit(
124 ev,
125 ...args,
126 );
127 }
128
129 /**
130 * Targets a room when emitting.
131 *
132 * @param room
133 * @return BroadcastOperator
134 * @public
135 */
136 public to(
137 room: string | string[],
138 ): BroadcastOperator<EmitEvents, ServerSideEvents> {
139 return new BroadcastOperator(this).to(room);
140 }
141

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…