UNPKG

3.5 kBTypeScriptView Raw
1import { Adapter, BroadcastOptions, Room, SocketId } from "socket.io-adapter";
2export interface RedisAdapterOptions {
3 /**
4 * the name of the key to pub/sub events on as prefix
5 * @default socket.io
6 */
7 key: string;
8 /**
9 * the redis client to publish events on
10 */
11 pubClient: any;
12 /**
13 * the redis client to subscribe to events on
14 */
15 subClient: any;
16 /**
17 * after this timeout the adapter will stop waiting from responses to request
18 * @default 5000
19 */
20 requestsTimeout: number;
21}
22/**
23 * Returns a redis Adapter class.
24 *
25 * @param {String} uri - optional, redis uri
26 * @param {String} opts - redis connection options
27 * @return {RedisAdapter} adapter
28 *
29 * @public
30 */
31export declare function createAdapter(uri: string, opts?: Partial<RedisAdapterOptions>): any;
32export declare function createAdapter(opts: Partial<RedisAdapterOptions>): any;
33export declare class RedisAdapter extends Adapter {
34 readonly uid: any;
35 readonly pubClient: any;
36 readonly subClient: any;
37 readonly requestsTimeout: number;
38 private readonly channel;
39 private readonly requestChannel;
40 private readonly responseChannel;
41 private requests;
42 /**
43 * Adapter constructor.
44 *
45 * @param nsp - the namespace
46 * @param uri - the url of the Redis server
47 * @param opts - the options for both the Redis adapter and the Redis client
48 *
49 * @public
50 */
51 constructor(nsp: any, uri: string, opts?: Partial<RedisAdapterOptions>);
52 /**
53 * Called with a subscription message
54 *
55 * @private
56 */
57 private onmessage;
58 /**
59 * Called on request from another node
60 *
61 * @private
62 */
63 private onrequest;
64 /**
65 * Called on response from another node
66 *
67 * @private
68 */
69 private onresponse;
70 /**
71 * Broadcasts a packet.
72 *
73 * @param {Object} packet - packet to emit
74 * @param {Object} opts - options
75 *
76 * @public
77 */
78 broadcast(packet: any, opts: BroadcastOptions): void;
79 /**
80 * Gets a list of sockets by sid.
81 *
82 * @param {Set<Room>} rooms the explicit set of rooms to check.
83 */
84 sockets(rooms: Set<Room>): Promise<Set<SocketId>>;
85 /**
86 * Gets the list of all rooms (across every node)
87 *
88 * @public
89 */
90 allRooms(): Promise<Set<Room>>;
91 /**
92 * Makes the socket with the given id join the room
93 *
94 * @param {String} id - socket id
95 * @param {String} room - room name
96 * @public
97 */
98 remoteJoin(id: SocketId, room: Room): Promise<void>;
99 /**
100 * Makes the socket with the given id leave the room
101 *
102 * @param {String} id - socket id
103 * @param {String} room - room name
104 * @public
105 */
106 remoteLeave(id: SocketId, room: Room): Promise<void>;
107 /**
108 * Makes the socket with the given id to be forcefully disconnected
109 * @param {String} id - socket id
110 * @param {Boolean} close - if `true`, closes the underlying connection
111 *
112 * @public
113 */
114 remoteDisconnect(id: SocketId, close?: boolean): Promise<void>;
115 fetchSockets(opts: BroadcastOptions): Promise<any[]>;
116 addSockets(opts: BroadcastOptions, rooms: Room[]): void;
117 delSockets(opts: BroadcastOptions, rooms: Room[]): void;
118 disconnectSockets(opts: BroadcastOptions, close: boolean): void;
119 /**
120 * Get the number of subscribers of the request channel
121 *
122 * @private
123 */
124 private getNumSub;
125}