Skip to content

Commit 3f96ad1

Browse files
authored
Add presence REST API to web pubsub service client (Azure#49305)
1 parent 351f040 commit 3f96ad1

13 files changed

+367
-17
lines changed

sdk/webpubsub/Azure.Messaging.WebPubSub/CHANGELOG.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
# Release History
22

3-
## 1.6.0-beta.1 (Unreleased)
3+
## 1.6.0 (2025-05-07)
44

55
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
6+
- Added method `serviceClient.ListConnectionsInGroup` and `serviceClient.ListConnectionsInGroupAsync`.`
127

138
## 1.5.0 (2025-02-27)
149

sdk/webpubsub/Azure.Messaging.WebPubSub/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ var client = new WebPubSubServiceClient(connectionString, "some_hub");
161161
client.RemoveConnectionFromAllGroups("some_connection");
162162
```
163163

164+
#### List connections in group
165+
Synchronous version:
166+
```C# Snippet:WebPubSubListConnectionsInGroup
167+
foreach (WebPubSubGroupMember member in client.ListConnectionsInGroup("groupName"))
168+
{
169+
Console.WriteLine($"ConnectionId: {member.ConnectionId}, UserId: {member.UserId}");
170+
}
171+
```
172+
173+
Asynchronous version:
174+
```C# Snippet:WebPubSubListConnectionsInGroupAsync
175+
await foreach (WebPubSubGroupMember member in client.ListConnectionsInGroupAsync("groupName"))
176+
{
177+
Console.WriteLine($"ConnectionId: {member.ConnectionId}, UserId: {member.UserId}");
178+
}
179+
```
180+
164181
## Troubleshooting
165182

166183
### Setting up console logging

sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.net8.0.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public enum WebPubSubClientProtocol
1111
Mqtt = 1,
1212
SocketIO = 2,
1313
}
14+
public partial class WebPubSubGroupMember
15+
{
16+
public WebPubSubGroupMember(string connectionId) { }
17+
public string ConnectionId { get { throw null; } }
18+
public string? UserId { get { throw null; } set { } }
19+
}
1420
public enum WebPubSubPermission
1521
{
1622
SendToGroup = 1,
@@ -70,6 +76,8 @@ public WebPubSubServiceClient(System.Uri endpoint, string hub, Azure.Core.TokenC
7076
public virtual System.Threading.Tasks.Task<Azure.Response> GrantPermissionAsync(Azure.Messaging.WebPubSub.WebPubSubPermission permission, string connectionId, string targetName = null, Azure.RequestContext context = null) { throw null; }
7177
public virtual Azure.Response<bool> GroupExists(string group, Azure.RequestContext context = null) { throw null; }
7278
public virtual System.Threading.Tasks.Task<Azure.Response<bool>> GroupExistsAsync(string group, Azure.RequestContext context = null) { throw null; }
79+
public virtual Azure.Pageable<Azure.Messaging.WebPubSub.WebPubSubGroupMember> ListConnectionsInGroup(string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null) { throw null; }
80+
public virtual Azure.AsyncPageable<Azure.Messaging.WebPubSub.WebPubSubGroupMember> ListConnectionsInGroupAsync(string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null) { throw null; }
7381
public virtual Azure.Response RemoveConnectionFromAllGroups(string connectionId, Azure.RequestContext context = null) { throw null; }
7482
public virtual System.Threading.Tasks.Task<Azure.Response> RemoveConnectionFromAllGroupsAsync(string connectionId, Azure.RequestContext context = null) { throw null; }
7583
public virtual Azure.Response RemoveConnectionFromGroup(string group, string connectionId, Azure.RequestContext context = null) { throw null; }
@@ -109,12 +117,13 @@ public WebPubSubServiceClient(System.Uri endpoint, string hub, Azure.Core.TokenC
109117
}
110118
public partial class WebPubSubServiceClientOptions : Azure.Core.ClientOptions
111119
{
112-
public WebPubSubServiceClientOptions(Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion version = Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion.V2024_01_01) { }
120+
public WebPubSubServiceClientOptions(Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion version = Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion.V2024_12_01) { }
113121
public System.Uri ReverseProxyEndpoint { get { throw null; } set { } }
114122
public enum ServiceVersion
115123
{
116124
V2021_10_01 = 1,
117125
V2024_01_01 = 2,
126+
V2024_12_01 = 3,
118127
}
119128
}
120129
}

sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.netstandard2.0.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public enum WebPubSubClientProtocol
1111
Mqtt = 1,
1212
SocketIO = 2,
1313
}
14+
public partial class WebPubSubGroupMember
15+
{
16+
public WebPubSubGroupMember(string connectionId) { }
17+
public string ConnectionId { get { throw null; } }
18+
public string? UserId { get { throw null; } set { } }
19+
}
1420
public enum WebPubSubPermission
1521
{
1622
SendToGroup = 1,
@@ -70,6 +76,8 @@ public WebPubSubServiceClient(System.Uri endpoint, string hub, Azure.Core.TokenC
7076
public virtual System.Threading.Tasks.Task<Azure.Response> GrantPermissionAsync(Azure.Messaging.WebPubSub.WebPubSubPermission permission, string connectionId, string targetName = null, Azure.RequestContext context = null) { throw null; }
7177
public virtual Azure.Response<bool> GroupExists(string group, Azure.RequestContext context = null) { throw null; }
7278
public virtual System.Threading.Tasks.Task<Azure.Response<bool>> GroupExistsAsync(string group, Azure.RequestContext context = null) { throw null; }
79+
public virtual Azure.Pageable<Azure.Messaging.WebPubSub.WebPubSubGroupMember> ListConnectionsInGroup(string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null) { throw null; }
80+
public virtual Azure.AsyncPageable<Azure.Messaging.WebPubSub.WebPubSubGroupMember> ListConnectionsInGroupAsync(string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null) { throw null; }
7381
public virtual Azure.Response RemoveConnectionFromAllGroups(string connectionId, Azure.RequestContext context = null) { throw null; }
7482
public virtual System.Threading.Tasks.Task<Azure.Response> RemoveConnectionFromAllGroupsAsync(string connectionId, Azure.RequestContext context = null) { throw null; }
7583
public virtual Azure.Response RemoveConnectionFromGroup(string group, string connectionId, Azure.RequestContext context = null) { throw null; }
@@ -109,12 +117,13 @@ public WebPubSubServiceClient(System.Uri endpoint, string hub, Azure.Core.TokenC
109117
}
110118
public partial class WebPubSubServiceClientOptions : Azure.Core.ClientOptions
111119
{
112-
public WebPubSubServiceClientOptions(Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion version = Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion.V2024_01_01) { }
120+
public WebPubSubServiceClientOptions(Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion version = Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions.ServiceVersion.V2024_12_01) { }
113121
public System.Uri ReverseProxyEndpoint { get { throw null; } set { } }
114122
public enum ServiceVersion
115123
{
116124
V2021_10_01 = 1,
117125
V2024_01_01 = 2,
126+
V2024_12_01 = 3,
118127
}
119128
}
120129
}

sdk/webpubsub/Azure.Messaging.WebPubSub/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/webpubsub/Azure.Messaging.WebPubSub",
5-
"Tag": "net/webpubsub/Azure.Messaging.WebPubSub_7d6164a51f"
5+
"Tag": "net/webpubsub/Azure.Messaging.WebPubSub_61ea04e0f7"
66
}

sdk/webpubsub/Azure.Messaging.WebPubSub/src/Azure.Messaging.WebPubSub.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Description>Azure SDK client library for the WebPubSub service</Description>
44
<AssemblyTitle>Azure SDK for WebPubSub</AssemblyTitle>
5-
<Version>1.6.0-beta.1</Version>
5+
<Version>1.6.0</Version>
66
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
77
<ApiCompatVersion>1.5.0</ApiCompatVersion>
88
<PackageTags>Azure, WebPubSub, SignalR</PackageTags>

sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubServiceClient.cs

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Text.Json;
5+
6+
namespace Azure.Messaging.WebPubSub;
7+
8+
#nullable enable
9+
10+
/// <summary>
11+
/// Represents a connection in a group.
12+
/// </summary>
13+
/// <remarks>
14+
/// Creates a new instance of <see cref="WebPubSubGroupMember"/> with the specified connection id.
15+
/// </remarks>
16+
/// <param name="connectionId"></param>
17+
public class WebPubSubGroupMember(string connectionId)
18+
{
19+
/// <summary>
20+
/// The connection id.
21+
/// </summary>
22+
public string ConnectionId { get; } = connectionId;
23+
/// <summary>
24+
/// The user id.
25+
/// </summary>
26+
public string? UserId { get; set; }
27+
28+
internal static WebPubSubGroupMember ParseFromJson(JsonElement root)
29+
{
30+
var connectionId = root.GetProperty("connectionId").GetString() ??
31+
throw new JsonException("Required property 'connectionId' was null or not present");
32+
var userId = root.TryGetProperty("userId", out JsonElement userIdElement) ? userIdElement.GetString() : null;
33+
return new WebPubSubGroupMember(connectionId)
34+
{
35+
UserId = userId
36+
};
37+
}
38+
}

sdk/webpubsub/Azure.Messaging.WebPubSub/src/WebPubSubServiceClientOptions.ServiceVersion.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
56
using Azure.Core;
67

78
[assembly: CodeGenSuppressType("WebPubSubServiceClientOptions")]
@@ -30,13 +31,17 @@ public enum ServiceVersion
3031
/// The 2024_01_01_stable version of the Azure WebPubSub service.
3132
/// </summary>
3233
V2024_01_01 = 2,
34+
/// <summary>
35+
/// The 2024_12_01_stable version of the Azure WebPubSub service.
36+
/// </summary>
37+
V2024_12_01 = 3,
3338
#pragma warning restore CA1707 // Identifiers should not contain underscores
3439
}
3540

3641
/// <summary>
3742
/// The Latest <see cref="ServiceVersion"/> supported by this client library.
3843
/// </summary>
39-
private const ServiceVersion LatestVersion = ServiceVersion.V2024_01_01;
44+
private const ServiceVersion LatestVersion = ServiceVersion.V2024_12_01;
4045

4146
/// <summary>
4247
/// Gets the version of the service API used when making requests.
@@ -85,6 +90,7 @@ public static string ToVersionString(this WebPubSubServiceClientOptions.ServiceV
8590
{
8691
WebPubSubServiceClientOptions.ServiceVersion.V2021_10_01 => "2021-10-01",
8792
WebPubSubServiceClientOptions.ServiceVersion.V2024_01_01 => "2024-01-01",
93+
WebPubSubServiceClientOptions.ServiceVersion.V2024_12_01 => "2024-12-01",
8894
_ => throw CreateInvalidVersionException(version)
8995
};
9096

0 commit comments

Comments
 (0)