1 | /// <reference types="node" />
|
---|
2 | import { Socket } from "./socket";
|
---|
3 | import type { Server } from "./index";
|
---|
4 | import type { Client } from "./client";
|
---|
5 | import { EventEmitter } from "events";
|
---|
6 | import type { Adapter, Room, SocketId } from "socket.io-adapter";
|
---|
7 | export interface ExtendedError extends Error {
|
---|
8 | data?: any;
|
---|
9 | }
|
---|
10 | export declare class Namespace extends EventEmitter {
|
---|
11 | readonly name: string;
|
---|
12 | readonly sockets: Map<SocketId, Socket>;
|
---|
13 | adapter: Adapter;
|
---|
14 | /** @private */
|
---|
15 | readonly server: Server;
|
---|
16 | /** @private */
|
---|
17 | _fns: Array<(socket: Socket, next: (err?: ExtendedError) => void) => void>;
|
---|
18 | /** @private */
|
---|
19 | _rooms: Set<Room>;
|
---|
20 | /** @private */
|
---|
21 | _flags: any;
|
---|
22 | /** @private */
|
---|
23 | _ids: number;
|
---|
24 | /**
|
---|
25 | * Namespace constructor.
|
---|
26 | *
|
---|
27 | * @param server instance
|
---|
28 | * @param name
|
---|
29 | */
|
---|
30 | constructor(server: Server, name: string);
|
---|
31 | /**
|
---|
32 | * Initializes the `Adapter` for this nsp.
|
---|
33 | * Run upon changing adapter by `Server#adapter`
|
---|
34 | * in addition to the constructor.
|
---|
35 | *
|
---|
36 | * @private
|
---|
37 | */
|
---|
38 | _initAdapter(): void;
|
---|
39 | /**
|
---|
40 | * Sets up namespace middleware.
|
---|
41 | *
|
---|
42 | * @return self
|
---|
43 | * @public
|
---|
44 | */
|
---|
45 | use(fn: (socket: Socket, next: (err?: ExtendedError) => void) => void): this;
|
---|
46 | /**
|
---|
47 | * Executes the middleware for an incoming client.
|
---|
48 | *
|
---|
49 | * @param socket - the socket that will get added
|
---|
50 | * @param fn - last fn call in the middleware
|
---|
51 | * @private
|
---|
52 | */
|
---|
53 | private run;
|
---|
54 | /**
|
---|
55 | * Targets a room when emitting.
|
---|
56 | *
|
---|
57 | * @param name
|
---|
58 | * @return self
|
---|
59 | * @public
|
---|
60 | */
|
---|
61 | to(name: Room): this;
|
---|
62 | /**
|
---|
63 | * Targets a room when emitting.
|
---|
64 | *
|
---|
65 | * @param name
|
---|
66 | * @return self
|
---|
67 | * @public
|
---|
68 | */
|
---|
69 | in(name: Room): this;
|
---|
70 | /**
|
---|
71 | * Adds a new client.
|
---|
72 | *
|
---|
73 | * @return {Socket}
|
---|
74 | * @private
|
---|
75 | */
|
---|
76 | _add(client: Client, query: any, fn?: () => void): Socket;
|
---|
77 | /**
|
---|
78 | * Removes a client. Called by each `Socket`.
|
---|
79 | *
|
---|
80 | * @private
|
---|
81 | */
|
---|
82 | _remove(socket: Socket): void;
|
---|
83 | /**
|
---|
84 | * Emits to all clients.
|
---|
85 | *
|
---|
86 | * @return Always true
|
---|
87 | * @public
|
---|
88 | */
|
---|
89 | emit(ev: string | Symbol, ...args: any[]): true;
|
---|
90 | /**
|
---|
91 | * Sends a `message` event to all clients.
|
---|
92 | *
|
---|
93 | * @return self
|
---|
94 | * @public
|
---|
95 | */
|
---|
96 | send(...args: readonly any[]): this;
|
---|
97 | /**
|
---|
98 | * Sends a `message` event to all clients.
|
---|
99 | *
|
---|
100 | * @return self
|
---|
101 | * @public
|
---|
102 | */
|
---|
103 | write(...args: readonly any[]): this;
|
---|
104 | /**
|
---|
105 | * Gets a list of clients.
|
---|
106 | *
|
---|
107 | * @return self
|
---|
108 | * @public
|
---|
109 | */
|
---|
110 | allSockets(): Promise<Set<SocketId>>;
|
---|
111 | /**
|
---|
112 | * Sets the compress flag.
|
---|
113 | *
|
---|
114 | * @param compress - if `true`, compresses the sending data
|
---|
115 | * @return self
|
---|
116 | * @public
|
---|
117 | */
|
---|
118 | compress(compress: boolean): this;
|
---|
119 | /**
|
---|
120 | * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
|
---|
121 | * receive messages (because of network slowness or other issues, or because they’re connected through long polling
|
---|
122 | * and is in the middle of a request-response cycle).
|
---|
123 | *
|
---|
124 | * @return self
|
---|
125 | * @public
|
---|
126 | */
|
---|
127 | get volatile(): this;
|
---|
128 | /**
|
---|
129 | * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
|
---|
130 | *
|
---|
131 | * @return self
|
---|
132 | * @public
|
---|
133 | */
|
---|
134 | get local(): this;
|
---|
135 | }
|
---|