Skip to content

Commit c8e70ba

Browse files
Mr-Yavartpeczek
authored andcommitted
Implement: Remove client from group
1 parent 4d0bd92 commit c8e70ba

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Lib.AspNetCore.ServerSentEvents/IServerSentEventsService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public interface IServerSentEventsService
5858
/// <param name="client">The client to add to a group.</param>
5959
/// <returns>The result of operation.</returns>
6060
ServerSentEventsAddToGroupResult AddToGroup(string groupName, IServerSentEventsClient client);
61+
62+
/// <summary>
63+
/// removes a client from the specified group.
64+
/// </summary>
65+
/// <param name="groupName">The group name.</param>
66+
/// <param name="client">The client to remove from a group.</param>
67+
/// <returns>The result of operation.</returns>
68+
ServerSentEventsRemoveFromGroupResult RemoveFromGroup(string groupName, IServerSentEventsClient client);
6169

6270
/// <summary>
6371
/// Changes the interval after which clients will attempt to reestablish failed connections.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Lib.AspNetCore.ServerSentEvents
2+
{
3+
/// <summary>
4+
/// The remove from group results.
5+
/// </summary>
6+
public enum ServerSentEventsRemoveFromGroupResult
7+
{
8+
/// <summary>
9+
/// The specified group could not be found.
10+
/// </summary>
11+
NotFoundGroup = 0,
12+
13+
/// <summary>
14+
/// The client has been removed from an existing group.
15+
/// </summary>
16+
RemovedFromExistingGroup = 1,
17+
18+
/// <summary>
19+
/// The client was not part of the group, so no removal occurred.
20+
/// </summary>
21+
NotInGroup = 2,
22+
}
23+
}

Lib.AspNetCore.ServerSentEvents/ServerSentEventsService.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ public ServerSentEventsAddToGroupResult AddToGroup(string groupName, IServerSent
129129
return result;
130130
}
131131

132+
/// <summary>
133+
/// removes a client from the specified group.
134+
/// </summary>
135+
/// <param name="groupName">The group name.</param>
136+
/// /// <param name="client">The client to remove from a group.</param>
137+
/// <returns>The task object representing the result of asynchronous operation</returns>
138+
public ServerSentEventsRemoveFromGroupResult RemoveFromGroup(string groupName, IServerSentEventsClient client)
139+
{
140+
ServerSentEventsRemoveFromGroupResult result = ServerSentEventsRemoveFromGroupResult.NotFoundGroup;
141+
142+
if (_groups.TryGetValue(groupName, out ConcurrentDictionary<Guid, IServerSentEventsClient> group))
143+
{
144+
result = ServerSentEventsRemoveFromGroupResult.NotInGroup;
145+
if (group.TryRemove(client.Id, out _))
146+
result = ServerSentEventsRemoveFromGroupResult.RemovedFromExistingGroup;
147+
}
148+
149+
return result;
150+
}
151+
132152
/// <summary>
133153
/// Changes the interval after which clients will attempt to reestablish failed connections.
134154
/// </summary>
@@ -138,7 +158,7 @@ public Task ChangeReconnectIntervalAsync(uint reconnectInterval)
138158
{
139159
return ChangeReconnectIntervalAsync(reconnectInterval, CancellationToken.None);
140160
}
141-
161+
142162
/// <summary>
143163
/// Changes the interval after which clients will attempt to reestablish failed connections.
144164
/// </summary>

0 commit comments

Comments
 (0)