@@ -160,6 +160,17 @@ public Task SendEventAsync(string text)
160160 return SendAsync ( ServerSentEventsHelper . GetEventBytes ( text ) , CancellationToken . None ) ;
161161 }
162162
163+ /// <summary>
164+ /// Sends event to all clients.
165+ /// </summary>
166+ /// <param name="text">The simple text event.</param>
167+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
168+ /// <returns>The task object representing the asynchronous operation.</returns>
169+ public Task SendEventAsync ( string text , Func < IServerSentEventsClient , bool > clientPredicate )
170+ {
171+ return SendAsync ( ServerSentEventsHelper . GetEventBytes ( text ) , clientPredicate , CancellationToken . None ) ;
172+ }
173+
163174 /// <summary>
164175 /// Sends event to clients in group.
165176 /// </summary>
@@ -171,6 +182,18 @@ public Task SendEventAsync(string groupName, string text)
171182 return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( text ) , CancellationToken . None ) ;
172183 }
173184
185+ /// <summary>
186+ /// Sends event to clients in group.
187+ /// </summary>
188+ /// <param name="groupName">The group name.</param>
189+ /// <param name="text">The simple text event.</param>
190+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
191+ /// <returns>The task object representing the asynchronous operation.</returns>
192+ public Task SendEventAsync ( string groupName , string text , Func < IServerSentEventsClient , bool > clientPredicate )
193+ {
194+ return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( text ) , clientPredicate , CancellationToken . None ) ;
195+ }
196+
174197 /// <summary>
175198 /// Sends event to all clients.
176199 /// </summary>
@@ -182,6 +205,18 @@ public Task SendEventAsync(string text, CancellationToken cancellationToken)
182205 return SendAsync ( ServerSentEventsHelper . GetEventBytes ( text ) , cancellationToken ) ;
183206 }
184207
208+ /// <summary>
209+ /// Sends event to all clients.
210+ /// </summary>
211+ /// <param name="text">The simple text event.</param>
212+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
213+ /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
214+ /// <returns>The task object representing the asynchronous operation.</returns>
215+ public Task SendEventAsync ( string text , Func < IServerSentEventsClient , bool > clientPredicate , CancellationToken cancellationToken )
216+ {
217+ return SendAsync ( ServerSentEventsHelper . GetEventBytes ( text ) , clientPredicate , cancellationToken ) ;
218+ }
219+
185220 /// <summary>
186221 /// Sends event to clients in group.
187222 /// </summary>
@@ -194,6 +229,19 @@ public Task SendEventAsync(string groupName, string text, CancellationToken canc
194229 return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( text ) , cancellationToken ) ;
195230 }
196231
232+ /// <summary>
233+ /// Sends event to clients in group.
234+ /// </summary>
235+ /// <param name="groupName">The group name.</param>
236+ /// <param name="text">The simple text event.</param>
237+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
238+ /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
239+ /// <returns>The task object representing the asynchronous operation.</returns>
240+ public Task SendEventAsync ( string groupName , string text , Func < IServerSentEventsClient , bool > clientPredicate , CancellationToken cancellationToken )
241+ {
242+ return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( text ) , clientPredicate , cancellationToken ) ;
243+ }
244+
197245 /// <summary>
198246 /// Sends event to all clients.
199247 /// </summary>
@@ -204,6 +252,17 @@ public Task SendEventAsync(ServerSentEvent serverSentEvent)
204252 return SendAsync ( ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , CancellationToken . None ) ;
205253 }
206254
255+ /// <summary>
256+ /// Sends event to all clients.
257+ /// </summary>
258+ /// <param name="serverSentEvent">The event.</param>
259+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
260+ /// <returns>The task object representing the asynchronous operation.</returns>
261+ public Task SendEventAsync ( ServerSentEvent serverSentEvent , Func < IServerSentEventsClient , bool > clientPredicate )
262+ {
263+ return SendAsync ( ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , clientPredicate , CancellationToken . None ) ;
264+ }
265+
207266 /// <summary>
208267 /// Sends event to clients in group.
209268 /// </summary>
@@ -215,6 +274,18 @@ public Task SendEventAsync(string groupName, ServerSentEvent serverSentEvent)
215274 return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , CancellationToken . None ) ;
216275 }
217276
277+ /// <summary>
278+ /// Sends event to clients in group.
279+ /// </summary>
280+ /// <param name="groupName">The group name.</param>
281+ /// <param name="serverSentEvent">The event.</param>
282+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
283+ /// <returns>The task object representing the asynchronous operation.</returns>
284+ public Task SendEventAsync ( string groupName , ServerSentEvent serverSentEvent , Func < IServerSentEventsClient , bool > clientPredicate )
285+ {
286+ return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , clientPredicate , CancellationToken . None ) ;
287+ }
288+
218289 /// <summary>
219290 /// Sends event to all clients.
220291 /// </summary>
@@ -226,6 +297,18 @@ public Task SendEventAsync(ServerSentEvent serverSentEvent, CancellationToken ca
226297 return SendAsync ( ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , cancellationToken ) ;
227298 }
228299
300+ /// <summary>
301+ /// Sends event to all clients.
302+ /// </summary>
303+ /// <param name="serverSentEvent">The event.</param>
304+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
305+ /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
306+ /// <returns>The task object representing the asynchronous operation.</returns>
307+ public Task SendEventAsync ( ServerSentEvent serverSentEvent , Func < IServerSentEventsClient , bool > clientPredicate , CancellationToken cancellationToken )
308+ {
309+ return SendAsync ( ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , clientPredicate , cancellationToken ) ;
310+ }
311+
229312 /// <summary>
230313 /// Sends event to clients in group.
231314 /// </summary>
@@ -238,6 +321,19 @@ public Task SendEventAsync(string groupName, ServerSentEvent serverSentEvent, Ca
238321 return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , cancellationToken ) ;
239322 }
240323
324+ /// <summary>
325+ /// Sends event to clients in group.
326+ /// </summary>
327+ /// <param name="groupName">The group name.</param>
328+ /// <param name="serverSentEvent">The event.</param>
329+ /// <param name="clientPredicate">The function to test each client for a condition.</param>
330+ /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
331+ /// <returns>The task object representing the asynchronous operation.</returns>
332+ public Task SendEventAsync ( string groupName , ServerSentEvent serverSentEvent , Func < IServerSentEventsClient , bool > clientPredicate , CancellationToken cancellationToken )
333+ {
334+ return SendAsync ( groupName , ServerSentEventsHelper . GetEventBytes ( serverSentEvent ) , clientPredicate , cancellationToken ) ;
335+ }
336+
241337 /// <summary>
242338 /// Method which is called when client is establishing the connection. The base implementation raises the <see cref="ClientConnected"/> event.
243339 /// </summary>
@@ -316,6 +412,11 @@ internal Task SendAsync(ServerSentEventBytes serverSentEventBytes, CancellationT
316412 return SendAsync ( _clients . Values , serverSentEventBytes , cancellationToken ) ;
317413 }
318414
415+ internal Task SendAsync ( ServerSentEventBytes serverSentEventBytes , Func < IServerSentEventsClient , bool > clientPredicate , CancellationToken cancellationToken )
416+ {
417+ return SendAsync ( _clients . Values . Where ( clientPredicate ) , serverSentEventBytes , cancellationToken ) ;
418+ }
419+
319420 internal Task SendAsync ( string groupName , ServerSentEventBytes serverSentEventBytes , CancellationToken cancellationToken )
320421 {
321422 if ( _groups . ContainsKey ( groupName ) )
@@ -326,7 +427,17 @@ internal Task SendAsync(string groupName, ServerSentEventBytes serverSentEventBy
326427 return Task . CompletedTask ;
327428 }
328429
329- internal Task SendAsync ( ICollection < IServerSentEventsClient > clients , ServerSentEventBytes serverSentEventBytes , CancellationToken cancellationToken )
430+ internal Task SendAsync ( string groupName , ServerSentEventBytes serverSentEventBytes , Func < IServerSentEventsClient , bool > clientPredicate , CancellationToken cancellationToken )
431+ {
432+ if ( _groups . ContainsKey ( groupName ) )
433+ {
434+ return SendAsync ( _groups [ groupName ] . Values . Where ( clientPredicate ) , serverSentEventBytes , cancellationToken ) ;
435+ }
436+
437+ return Task . CompletedTask ;
438+ }
439+
440+ internal Task SendAsync ( IEnumerable < IServerSentEventsClient > clients , ServerSentEventBytes serverSentEventBytes , CancellationToken cancellationToken )
330441 {
331442 List < Task > clientsTasks = null ;
332443
0 commit comments