@@ -85,15 +85,15 @@ public override Task SendAllAsync(string methodName, object[] args, Cancellation
85
85
return SendToAllConnections ( methodName , args , null ) ;
86
86
}
87
87
88
- private Task SendToAllConnections ( string methodName , object [ ] args , Func < HubConnectionContext , bool > include )
88
+ private Task SendToAllConnections ( string methodName , object [ ] args , Func < HubConnectionContext , object , bool > include , object state = null )
89
89
{
90
90
List < Task > tasks = null ;
91
91
SerializedHubMessage message = null ;
92
92
93
93
// foreach over HubConnectionStore avoids allocating an enumerator
94
94
foreach ( var connection in _connections )
95
95
{
96
- if ( include != null && ! include ( connection ) )
96
+ if ( include != null && ! include ( connection , state ) )
97
97
{
98
98
continue ;
99
99
}
@@ -127,12 +127,12 @@ private Task SendToAllConnections(string methodName, object[] args, Func<HubConn
127
127
128
128
// Tasks and message are passed by ref so they can be lazily created inside the method post-filtering,
129
129
// while still being re-usable when sending to multiple groups
130
- private void SendToGroupConnections ( string methodName , object [ ] args , ConcurrentDictionary < string , HubConnectionContext > connections , Func < HubConnectionContext , bool > include , ref List < Task > tasks , ref SerializedHubMessage message )
130
+ private void SendToGroupConnections ( string methodName , object [ ] args , ConcurrentDictionary < string , HubConnectionContext > connections , Func < HubConnectionContext , object , bool > include , object state , ref List < Task > tasks , ref SerializedHubMessage message )
131
131
{
132
132
// foreach over ConcurrentDictionary avoids allocating an enumerator
133
133
foreach ( var connection in connections )
134
134
{
135
- if ( include != null && ! include ( connection . Value ) )
135
+ if ( include != null && ! include ( connection . Value , state ) )
136
136
{
137
137
continue ;
138
138
}
@@ -193,7 +193,7 @@ public override Task SendGroupAsync(string groupName, string methodName, object[
193
193
// group might be modified inbetween checking and sending
194
194
List < Task > tasks = null ;
195
195
SerializedHubMessage message = null ;
196
- SendToGroupConnections ( methodName , args , group , null , ref tasks , ref message ) ;
196
+ SendToGroupConnections ( methodName , args , group , null , null , ref tasks , ref message ) ;
197
197
198
198
if ( tasks != null )
199
199
{
@@ -221,7 +221,7 @@ public override Task SendGroupsAsync(IReadOnlyList<string> groupNames, string me
221
221
var group = _groups [ groupName ] ;
222
222
if ( group != null )
223
223
{
224
- SendToGroupConnections ( methodName , args , group , null , ref tasks , ref message ) ;
224
+ SendToGroupConnections ( methodName , args , group , null , null , ref tasks , ref message ) ;
225
225
}
226
226
}
227
227
@@ -247,7 +247,7 @@ public override Task SendGroupExceptAsync(string groupName, string methodName, o
247
247
List < Task > tasks = null ;
248
248
SerializedHubMessage message = null ;
249
249
250
- SendToGroupConnections ( methodName , args , group , connection => ! excludedConnectionIds . Contains ( connection . ConnectionId ) , ref tasks , ref message ) ;
250
+ SendToGroupConnections ( methodName , args , group , ( connection , state ) => ! ( ( IReadOnlyList < string > ) state ) . Contains ( connection . ConnectionId ) , excludedConnectionIds , ref tasks , ref message ) ;
251
251
252
252
if ( tasks != null )
253
253
{
@@ -271,7 +271,7 @@ private HubMessage CreateInvocationMessage(string methodName, object[] args)
271
271
/// <inheritdoc />
272
272
public override Task SendUserAsync ( string userId , string methodName , object [ ] args , CancellationToken cancellationToken = default )
273
273
{
274
- return SendToAllConnections ( methodName , args , connection => string . Equals ( connection . UserIdentifier , userId , StringComparison . Ordinal ) ) ;
274
+ return SendToAllConnections ( methodName , args , ( connection , state ) => string . Equals ( connection . UserIdentifier , ( string ) state , StringComparison . Ordinal ) , userId ) ;
275
275
}
276
276
277
277
/// <inheritdoc />
@@ -292,19 +292,19 @@ public override Task OnDisconnectedAsync(HubConnectionContext connection)
292
292
/// <inheritdoc />
293
293
public override Task SendAllExceptAsync ( string methodName , object [ ] args , IReadOnlyList < string > excludedConnectionIds , CancellationToken cancellationToken = default )
294
294
{
295
- return SendToAllConnections ( methodName , args , connection => ! excludedConnectionIds . Contains ( connection . ConnectionId ) ) ;
295
+ return SendToAllConnections ( methodName , args , ( connection , state ) => ! ( ( IReadOnlyList < string > ) state ) . Contains ( connection . ConnectionId ) , excludedConnectionIds ) ;
296
296
}
297
297
298
298
/// <inheritdoc />
299
299
public override Task SendConnectionsAsync ( IReadOnlyList < string > connectionIds , string methodName , object [ ] args , CancellationToken cancellationToken = default )
300
300
{
301
- return SendToAllConnections ( methodName , args , connection => connectionIds . Contains ( connection . ConnectionId ) ) ;
301
+ return SendToAllConnections ( methodName , args , ( connection , state ) => ( ( IReadOnlyList < string > ) state ) . Contains ( connection . ConnectionId ) , connectionIds ) ;
302
302
}
303
303
304
304
/// <inheritdoc />
305
305
public override Task SendUsersAsync ( IReadOnlyList < string > userIds , string methodName , object [ ] args , CancellationToken cancellationToken = default )
306
306
{
307
- return SendToAllConnections ( methodName , args , connection => userIds . Contains ( connection . UserIdentifier ) ) ;
307
+ return SendToAllConnections ( methodName , args , ( connection , state ) => ( ( IReadOnlyList < string > ) state ) . Contains ( connection . UserIdentifier ) , userIds ) ;
308
308
}
309
309
}
310
310
}
0 commit comments