From fc2d5c710eddddc1811130b607e87997866feeae Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 13 Oct 2023 22:36:47 +0530 Subject: [PATCH 1/5] Added async version of channel status to channel interface --- src/IO.Ably.Shared/Rest/IRestChannel.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/IO.Ably.Shared/Rest/IRestChannel.cs b/src/IO.Ably.Shared/Rest/IRestChannel.cs index dfeed61c8..c557246c9 100644 --- a/src/IO.Ably.Shared/Rest/IRestChannel.cs +++ b/src/IO.Ably.Shared/Rest/IRestChannel.cs @@ -48,6 +48,12 @@ public interface IRestChannel /// of past Messages. Task> HistoryAsync(PaginatedRequestParams query); + /// + /// Returns the active status for the channel including the number of publishers, subscribers and presenceMembers etc. + /// + /// Channel Details. + Task StatusAsync(); + /// /// Name of the channel. /// @@ -103,7 +109,8 @@ public interface IRestChannel PaginatedResult History(PaginatedRequestParams query); /// - /// Returns the active status for the channel including the number of publishers, subscribers and presenceMembers etc. + /// Sync version of . + /// Prefer async version where possible. /// /// Channel Details. ChannelDetails Status(); From c710b3070a0e7a2783731e669249135cbff0515d Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 13 Oct 2023 22:39:18 +0530 Subject: [PATCH 2/5] Updated restchannel to implement async channel status method --- src/IO.Ably.Shared/Rest/RestChannel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IO.Ably.Shared/Rest/RestChannel.cs b/src/IO.Ably.Shared/Rest/RestChannel.cs index 794e9d615..fa4eac1dc 100644 --- a/src/IO.Ably.Shared/Rest/RestChannel.cs +++ b/src/IO.Ably.Shared/Rest/RestChannel.cs @@ -227,7 +227,8 @@ public PaginatedResult History(PaginatedRequestParams query) return AsyncHelper.RunSync(() => HistoryAsync(query)); } - private async Task StatusAsync() + /// + public async Task StatusAsync() { AblyRequest request = _ablyRest.CreateGetRequest("/channels/" + Name); return await _ablyRest.ExecuteRequest(request); From 6355ed5b5155e8139c6f75eb5f39a35c83d0a984 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 13 Oct 2023 23:23:17 +0530 Subject: [PATCH 3/5] Updated README to prefer statusAsync instead of blocking status --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ddd6c97c5..288d50f5b 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,7 @@ var presenceNextPage = await presenceHistory.NextAsync(); Getting the current status of a channel, including details of the current number of `Publishers`, `Subscribers` and `PresenceMembers` etc is simple ```csharp -ChannelDetails details = channel.Status(); +ChannelDetails details = await channel.StatusAsync(); ChannelMetrics metrics = details.Status.Occupancy.Metrics; // Do something with 'metrics.Publishers' etc ``` From d60c9dc07bbe4447b6ccc47b1fd5dbab669f1305 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 16 Oct 2023 23:20:31 +0530 Subject: [PATCH 4/5] Refactored channel status, moved from realtime to rest client --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 288d50f5b..06d9a069b 100644 --- a/README.md +++ b/README.md @@ -280,16 +280,6 @@ foreach (var presence in presenceHistory.Items) var presenceNextPage = await presenceHistory.NextAsync(); ``` -### Getting the channel status - -Getting the current status of a channel, including details of the current number of `Publishers`, `Subscribers` and `PresenceMembers` etc is simple - -```csharp -ChannelDetails details = await channel.StatusAsync(); -ChannelMetrics metrics = details.Status.Occupancy.Metrics; -// Do something with 'metrics.Publishers' etc -``` - ### Symmetric end-to-end encrypted payloads on a channel When a 128-bit or 256-bit key is provided to the library, all payloads are encrypted and decrypted automatically using that key on the channel. The secret key is never transmitted to Ably and thus it is the developer's responsibility to distribute a secret key to both publishers and subscribers. @@ -445,6 +435,16 @@ var nextStatsPage = await stats.NextAsync(); DateTimeOffset time = await client.TimeAsync(); ``` +### Getting the channel status + +Getting the current status of a channel, including details of the current number of `Publishers`, `Subscribers` and `PresenceMembers` etc is simple + +```csharp +ChannelDetails details = await channel.StatusAsync(); +ChannelMetrics metrics = details.Status.Occupancy.Metrics; +// Do something with 'metrics.Publishers' etc +``` + ### Making explicit HTTP requests to Ably Rest Endpoints / Batch publish - The `AblyRest->Request` method should be used to make explicit HTTP requests. - It automatically adds necessary auth headers based on the initial auth config and supports pagination. From 1cb02fef9571e411d6872edf0e89f302630205d8 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 16 Oct 2023 23:32:58 +0530 Subject: [PATCH 5/5] Updated channel sandboxspecs test for rest channel status --- src/IO.Ably.Tests.Shared/Rest/ChannelSandboxSpecs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IO.Ably.Tests.Shared/Rest/ChannelSandboxSpecs.cs b/src/IO.Ably.Tests.Shared/Rest/ChannelSandboxSpecs.cs index c7462eacc..2bb067a9e 100644 --- a/src/IO.Ably.Tests.Shared/Rest/ChannelSandboxSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Rest/ChannelSandboxSpecs.cs @@ -665,7 +665,7 @@ public async Task ChannelDetails_AreAvailable(Protocol protocol) AblyRest client = await GetRestClient(protocol); IRestChannel c = client.Channels.Get(Name); - ChannelDetails cd = c.Status(); + ChannelDetails cd = await c.StatusAsync(); cd.ChannelId.Should().Be(Name); cd.Status.IsActive.Should().BeTrue();