123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /// <reference types="node" />
- import { Socket } from "./socket";
- import { Server } from "./index";
- import { Client } from "./client";
- import { EventEmitter } from "events";
- import { Adapter, Room, SocketId } from "socket.io-adapter";
- export interface ExtendedError extends Error {
- data?: any;
- }
- export declare class Namespace extends EventEmitter {
- readonly name: string;
- readonly sockets: Map<SocketId, Socket>;
- adapter: Adapter;
- /** @private */
- readonly server: Server;
- /** @private */
- _fns: Array<(socket: Socket, next: (err: ExtendedError) => void) => void>;
- /** @private */
- _rooms: Set<Room>;
- /** @private */
- _flags: any;
- /** @private */
- _ids: number;
- /**
- * Namespace constructor.
- *
- * @param {Server} server instance
- * @param {string} name
- */
- constructor(server: Server, name: string);
- /**
- * Initializes the `Adapter` for this nsp.
- * Run upon changing adapter by `Server#adapter`
- * in addition to the constructor.
- *
- * @private
- */
- _initAdapter(): void;
- /**
- * Sets up namespace middleware.
- *
- * @return {Namespace} self
- * @public
- */
- use(fn: (socket: Socket, next: (err?: ExtendedError) => void) => void): Namespace;
- /**
- * Executes the middleware for an incoming client.
- *
- * @param {Socket} socket - the socket that will get added
- * @param {Function} fn - last fn call in the middleware
- * @private
- */
- private run;
- /**
- * Targets a room when emitting.
- *
- * @param {String} name
- * @return {Namespace} self
- * @public
- */
- to(name: Room): Namespace;
- /**
- * Targets a room when emitting.
- *
- * @param {String} name
- * @return {Namespace} self
- * @public
- */
- in(name: Room): Namespace;
- /**
- * Adds a new client.
- *
- * @return {Socket}
- * @private
- */
- _add(client: Client, query: any, fn?: () => void): Socket;
- /**
- * Removes a client. Called by each `Socket`.
- *
- * @private
- */
- _remove(socket: Socket): void;
- /**
- * Emits to all clients.
- *
- * @return {Boolean} Always true
- * @public
- */
- emit(ev: string, ...args: any[]): boolean;
- /**
- * Sends a `message` event to all clients.
- *
- * @return {Namespace} self
- * @public
- */
- send(...args: any[]): Namespace;
- /**
- * Sends a `message` event to all clients.
- *
- * @return {Namespace} self
- * @public
- */
- write(...args: any[]): Namespace;
- /**
- * Gets a list of clients.
- *
- * @return {Namespace} self
- * @public
- */
- allSockets(): Promise<Set<SocketId>>;
- /**
- * Sets the compress flag.
- *
- * @param {Boolean} compress - if `true`, compresses the sending data
- * @return {Namespace} self
- * @public
- */
- compress(compress: boolean): Namespace;
- /**
- * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
- * receive messages (because of network slowness or other issues, or because they’re connected through long polling
- * and is in the middle of a request-response cycle).
- *
- * @return {Namespace} self
- * @public
- */
- get volatile(): Namespace;
- /**
- * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
- *
- * @return {Namespace} self
- * @public
- */
- get local(): Namespace;
- }
|