@@ -9,6 +9,7 @@ export interface BroadcastFlags {
9
9
local ?: boolean ;
10
10
broadcast ?: boolean ;
11
11
binary ?: boolean ;
12
+ timeout ?: number ;
12
13
}
13
14
14
15
export interface BroadcastOptions {
@@ -42,6 +43,15 @@ export class Adapter extends EventEmitter {
42
43
*/
43
44
public close ( ) : Promise < void > | void { }
44
45
46
+ /**
47
+ * Returns the number of Socket.IO servers in the cluster
48
+ *
49
+ * @public
50
+ */
51
+ public serverCount ( ) : Promise < number > {
52
+ return Promise . resolve ( 1 ) ;
53
+ }
54
+
45
55
/**
46
56
* Adds a socket to a list of room.
47
57
*
@@ -140,6 +150,54 @@ export class Adapter extends EventEmitter {
140
150
} ) ;
141
151
}
142
152
153
+ /**
154
+ * Broadcasts a packet and expects multiple acknowledgements.
155
+ *
156
+ * Options:
157
+ * - `flags` {Object} flags for this packet
158
+ * - `except` {Array} sids that should be excluded
159
+ * - `rooms` {Array} list of rooms to broadcast to
160
+ *
161
+ * @param {Object } packet the packet object
162
+ * @param {Object } opts the options
163
+ * @param clientCountCallback - the number of clients that received the packet
164
+ * @param ack - the callback that will be called for each client response
165
+ *
166
+ * @public
167
+ */
168
+ public broadcastWithAck (
169
+ packet : any ,
170
+ opts : BroadcastOptions ,
171
+ clientCountCallback : ( clientCount : number ) => void ,
172
+ ack : ( ...args : any [ ] ) => void
173
+ ) {
174
+ const flags = opts . flags || { } ;
175
+ const packetOpts = {
176
+ preEncoded : true ,
177
+ volatile : flags . volatile ,
178
+ compress : flags . compress
179
+ } ;
180
+
181
+ packet . nsp = this . nsp . name ;
182
+ // we can use the same id for each packet, since the _ids counter is common (no duplicate)
183
+ packet . id = this . nsp . _ids ++ ;
184
+
185
+ const encodedPackets = this . encoder . encode ( packet ) ;
186
+
187
+ let clientCount = 0 ;
188
+
189
+ this . apply ( opts , socket => {
190
+ // track the total number of acknowledgements that are expected
191
+ clientCount ++ ;
192
+ // call the ack callback for each client response
193
+ socket . acks . set ( packet . id , ack ) ;
194
+
195
+ socket . client . writeToEngine ( encodedPackets , packetOpts ) ;
196
+ } ) ;
197
+
198
+ clientCountCallback ( clientCount ) ;
199
+ }
200
+
143
201
/**
144
202
* Gets a list of sockets by sid.
145
203
*
0 commit comments