broadcast-operator.d.ts
4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import type { BroadcastFlags, Room, SocketId } from "socket.io-adapter";
import { Handshake } from "./socket";
import type { Adapter } from "socket.io-adapter";
import type { EventParams, EventNames, EventsMap, TypedEventBroadcaster } from "./typed-events";
export declare class BroadcastOperator<EmitEvents extends EventsMap> implements TypedEventBroadcaster<EmitEvents> {
private readonly adapter;
private readonly rooms;
private readonly exceptRooms;
private readonly flags;
constructor(adapter: Adapter, rooms?: Set<Room>, exceptRooms?: Set<Room>, flags?: BroadcastFlags);
/**
* Targets a room when emitting.
*
* @param room
* @return a new BroadcastOperator instance
* @public
*/
to(room: Room | Room[]): BroadcastOperator<EmitEvents>;
/**
* Targets a room when emitting.
*
* @param room
* @return a new BroadcastOperator instance
* @public
*/
in(room: Room | Room[]): BroadcastOperator<EmitEvents>;
/**
* Excludes a room when emitting.
*
* @param room
* @return a new BroadcastOperator instance
* @public
*/
except(room: Room | Room[]): BroadcastOperator<EmitEvents>;
/**
* Sets the compress flag.
*
* @param compress - if `true`, compresses the sending data
* @return a new BroadcastOperator instance
* @public
*/
compress(compress: boolean): BroadcastOperator<EmitEvents>;
/**
* 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 a new BroadcastOperator instance
* @public
*/
get volatile(): BroadcastOperator<EmitEvents>;
/**
* Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
*
* @return a new BroadcastOperator instance
* @public
*/
get local(): BroadcastOperator<EmitEvents>;
/**
* Emits to all clients.
*
* @return Always true
* @public
*/
emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean;
/**
* Gets a list of clients.
*
* @public
*/
allSockets(): Promise<Set<SocketId>>;
/**
* Returns the matching socket instances
*
* @public
*/
fetchSockets(): Promise<RemoteSocket<EmitEvents>[]>;
/**
* Makes the matching socket instances join the specified rooms
*
* @param room
* @public
*/
socketsJoin(room: Room | Room[]): void;
/**
* Makes the matching socket instances leave the specified rooms
*
* @param room
* @public
*/
socketsLeave(room: Room | Room[]): void;
/**
* Makes the matching socket instances disconnect
*
* @param close - whether to close the underlying connection
* @public
*/
disconnectSockets(close?: boolean): void;
}
/**
* Format of the data when the Socket instance exists on another Socket.IO server
*/
interface SocketDetails {
id: SocketId;
handshake: Handshake;
rooms: Room[];
data: any;
}
/**
* Expose of subset of the attributes and methods of the Socket class
*/
export declare class RemoteSocket<EmitEvents extends EventsMap> implements TypedEventBroadcaster<EmitEvents> {
readonly id: SocketId;
readonly handshake: Handshake;
readonly rooms: Set<Room>;
readonly data: any;
private readonly operator;
constructor(adapter: Adapter, details: SocketDetails);
emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean;
/**
* Joins a room.
*
* @param {String|Array} room - room or array of rooms
* @public
*/
join(room: Room | Room[]): void;
/**
* Leaves a room.
*
* @param {String} room
* @public
*/
leave(room: Room): void;
/**
* Disconnects this client.
*
* @param {Boolean} close - if `true`, closes the underlying connection
* @return {Socket} self
*
* @public
*/
disconnect(close?: boolean): this;
}
export {};