Skip to content

Commit

Permalink
Update Streaming APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienLavocat committed Aug 2, 2024
1 parent a64fba6 commit 6e03d31
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 63 deletions.
53 changes: 53 additions & 0 deletions DolbyIO.Rest/Streaming/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using DolbyIO.Rest.Streaming.Models;
using Newtonsoft.Json;

namespace DolbyIO.Rest.Streaming;

public sealed class Account
{
private readonly HttpClient _httpClient;

internal Account(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<GeoCascade> ReadGeoCascadeAsync(string apiSecret)
{
const string url = Urls.STREAMING_BASE_URL + "/api/account/geo_cascade";
using HttpRequestMessage request = Extensions.BuildHttpRequestMessageBase(HttpMethod.Get, url, apiSecret);
return await _httpClient.GetResponseAsync<GeoCascade>(request);
}

public async Task<GeoCascade> UpdateGeoCascadeAsync(string apiSecret, UpdateGeoCascade rules)
{
const string url = Urls.STREAMING_BASE_URL + "/api/account/geo_cascade";
string content = JsonConvert.SerializeObject(rules);
using HttpRequestMessage request = Extensions.BuildHttpRequestMessage(HttpMethod.Put, url, apiSecret, content);
return await _httpClient.GetResponseAsync<GeoCascade>(request);
}

public async Task<GeoRestrictions> ReadGeoRestrictionsAsync(string apiSecret)
{
const string url = Urls.STREAMING_BASE_URL + "/api/geo/account";
using HttpRequestMessage request = Extensions.BuildHttpRequestMessageBase(HttpMethod.Get, url, apiSecret);
return await _httpClient.GetResponseAsync<GeoRestrictions>(request);
}

public async Task<GeoRestrictions> UpdateGeoRestrictionsAsync(string apiSecret, IEnumerable<string> allowedCountries, IEnumerable<string> deniedCountries)
{
const string url = Urls.STREAMING_BASE_URL + "/api/geo/account";
var body = new UpdateGeoRestrictions
{
UpdateAllowedCountries = allowedCountries,
UpdateDeniedCountries = deniedCountries
};

string content = JsonConvert.SerializeObject(body);
using HttpRequestMessage request = Extensions.BuildHttpRequestMessage(HttpMethod.Post, url, apiSecret, content);
return await _httpClient.GetResponseAsync<GeoRestrictions>(request);
}
}
6 changes: 3 additions & 3 deletions DolbyIO.Rest/Streaming/Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal Cluster(HttpClient httpClient)

public async Task<ClusterResponse> ReadAsync(string apiSecret)
{
const string url = Urls.SAPI_BASE_URL + "/api/cluster";
const string url = Urls.STREAMING_BASE_URL + "/api/cluster";

using var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiSecret);
Expand All @@ -29,11 +29,11 @@ public async Task<ClusterResponse> ReadAsync(string apiSecret)

public async Task<ClusterResponse> UpdateAsync(string apiSecret, string defaultCluster)
{
const string url = Urls.SAPI_BASE_URL + "/api/cluster";
const string url = Urls.STREAMING_BASE_URL + "/api/cluster";

var body = new
{
defaultCluster = defaultCluster
defaultCluster
};

string content = JsonConvert.SerializeObject(body);
Expand Down
4 changes: 2 additions & 2 deletions DolbyIO.Rest/Streaming/Director.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal Director(HttpClient httpClient)
/// <returns>The <xref href="System.Threading.Tasks.Task`1.Result"/> property returns the <see cref="PublishResponse" /> object.</returns>
public async Task<PublishResponse> PublishAsync(string publishingToken, string streamName)
{
const string url = Urls.SAPI_DIRECTOR_BASE_URL + "/api/director/publish";
const string url = Urls.STREAMING_DIRECTOR_BASE_URL + "/api/director/publish";

var body = new
{
Expand All @@ -43,7 +43,7 @@ public async Task<PublishResponse> PublishAsync(string publishingToken, string s
/// <returns>The <xref href="System.Threading.Tasks.Task`1.Result"/> property returns the <see cref="SubscribeResponse" /> object.</returns>
public async Task<SubscribeResponse> SubscribeAsync(string streamName, string streamAccountId = null, string subscribeToken = null)
{
const string url = Urls.SAPI_DIRECTOR_BASE_URL + "/api/director/subscribe";
const string url = Urls.STREAMING_DIRECTOR_BASE_URL + "/api/director/subscribe";

var body = new
{
Expand Down
38 changes: 0 additions & 38 deletions DolbyIO.Rest/Streaming/Geo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,38 @@

namespace DolbyIO.Rest.Streaming.Models;

public sealed class GeoUpdate
public sealed class GeoCascade
{
[JsonProperty("updateAllowedCountries", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<string> UpdateAllowedCountries { get; set; }
[JsonProperty("isEnabled")]
public bool IsEnabled { get; internal set; }

[JsonProperty("updateDeniedCountries", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<string> UpdateDeniedCountries { get; set; }
[JsonProperty("clusters")]
public IEnumerable<string> Clusters { get; internal set; }
}

public sealed class UpdateGeoCascade
{
[JsonProperty("isEnabled", NullValueHandling = NullValueHandling.Ignore)]
public bool? IsEnabled { get; set; }

[JsonProperty("clusters", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<string> Clusters { get; set; }
}

public sealed class GeoResponse
public sealed class GeoRestrictions
{
[JsonProperty("allowedCountries")]
public IEnumerable<string> AllowedCountries { get; internal set; }

[JsonProperty("deniedCountries")]
public IEnumerable<string> DeniedCountries { get; internal set; }
}

public sealed class UpdateGeoRestrictions
{
[JsonProperty("updateAllowedCountries", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<string> UpdateAllowedCountries { get; set; }

[JsonProperty("updateDeniedCountries", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<string> UpdateDeniedCountries { get; set; }
}
8 changes: 4 additions & 4 deletions DolbyIO.Rest/Streaming/PublishTokens.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -10,7 +10,7 @@ namespace DolbyIO.Rest.Streaming;

public sealed class PublishTokens
{
private const string URL_BASE = Urls.SAPI_BASE_URL + "/api/publish_token";
private const string URL_BASE = Urls.STREAMING_BASE_URL + "/api/publish_token";

private readonly HttpClient _httpClient;

Expand Down Expand Up @@ -50,7 +50,7 @@ public enum ListSortBy

public async Task<IEnumerable<PublishToken>> ListAsync(string apiSecret, int page, int itemsOnPage, ListSortBy sortBy = ListSortBy.None, bool isDescending = false)
{
var uriBuilder = new UriBuilder(Urls.SAPI_BASE_URL);
var uriBuilder = new UriBuilder(Urls.STREAMING_BASE_URL);
uriBuilder.Path = "/api/publish_token/list";

var nvc = new NameValueCollection();
Expand Down
7 changes: 3 additions & 4 deletions DolbyIO.Rest/Streaming/Sapi.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Net.Http;
using DolbyIO.Rest.Streaming.Models;

namespace DolbyIO.Rest.Streaming;

public sealed class Sapi
{
public Cluster Cluster { get; }
public Account Account { get; }

public Geo Geo { get; }
public Cluster Cluster { get; }

public PublishTokens PublishToken { get; }

Expand All @@ -23,8 +22,8 @@ public sealed class Sapi

internal Sapi(HttpClient httpClient)
{
Account = new Account(httpClient);
Cluster = new Cluster(httpClient);
Geo = new Geo(httpClient);
PublishToken = new PublishTokens(httpClient);
Stream = new Stream(httpClient);
SubscribeToken = new SubscribeTokens(httpClient);
Expand Down
4 changes: 2 additions & 2 deletions DolbyIO.Rest/Streaming/Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal Stream(HttpClient httpClient)
/// <remarks>Prior to stopping all streams, you must call the <xref href="DolbyIO.Rest.Streaming.PublishToken.DisableAsync"/> function.</remarks>
public async Task StopAsync(string apiSecret, string streamId)
{
const string url = Urls.SAPI_BASE_URL + "/api/stream/stop";
const string url = Urls.STREAMING_BASE_URL + "/api/stream/stop";

var body = new
{
Expand All @@ -42,7 +42,7 @@ public async Task StopAsync(string apiSecret, string streamId)
/// <remarks>Prior to stopping all streams, you must call the <xref href="DolbyIO.Rest.Streaming.PublishToken.DisableAsync"/> function.</remarks>
public async Task StopAllAsync(string apiSecret)
{
const string url = Urls.SAPI_BASE_URL + "/api/stream/stop/all";
const string url = Urls.STREAMING_BASE_URL + "/api/stream/stop/all";
using HttpRequestMessage request = Extensions.BuildHttpRequestMessageBase(HttpMethod.Post, url, apiSecret);
await _httpClient.SendRequestAsync(request);
}
Expand Down
4 changes: 2 additions & 2 deletions DolbyIO.Rest/Streaming/SubscribeTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DolbyIO.Rest.Streaming;

public sealed class SubscribeTokens
{
private const string URL_BASE = Urls.SAPI_BASE_URL + "/api/subscribe_token";
private const string URL_BASE = Urls.STREAMING_BASE_URL + "/api/subscribe_token";

private readonly HttpClient _httpClient;

Expand Down Expand Up @@ -50,7 +50,7 @@ public enum ListSortBy

public async Task<IEnumerable<SubscribeToken>> ListAsync(string apiSecret, int page, int itemsOnPage, ListSortBy sortBy = ListSortBy.None, bool isDescending = false)
{
var uriBuilder = new UriBuilder(Urls.SAPI_BASE_URL);
var uriBuilder = new UriBuilder(Urls.STREAMING_BASE_URL);
uriBuilder.Path = "/api/subscribe_token/list";

var nvc = new NameValueCollection();
Expand Down
2 changes: 1 addition & 1 deletion DolbyIO.Rest/Streaming/Whep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal Whep(HttpClient httpClient)
/// <remarks>This specification is based on the https://www.ietf.org/archive/id/draft-murillo-whep-00.html draft and will be updated to upcoming versions as soon as they are available.</remarks>
public async Task<string> WhepAsync(string publishingToken, string streamAccountId, string streamName, string sourceId, string sdpOffer)
{
var uriBuilder = new UriBuilder(Urls.SAPI_DIRECTOR_BASE_URL)
var uriBuilder = new UriBuilder(Urls.STREAMING_DIRECTOR_BASE_URL)
{
Path = $"/api/whep/{streamAccountId}/{streamName}"
};
Expand Down
2 changes: 1 addition & 1 deletion DolbyIO.Rest/Streaming/Whip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal Whip(HttpClient httpClient)
/// <returns>The <xref href="System.Threading.Tasks.Task`1.Result"/> property returns the SDP answer.</returns>
public async Task<string> WhipAsync(string publishingToken, string streamName, string codec, string sourceId, string sdpOffer)
{
var uriBuilder = new UriBuilder(Urls.SAPI_DIRECTOR_BASE_URL)
var uriBuilder = new UriBuilder(Urls.STREAMING_DIRECTOR_BASE_URL)
{
Path = $"/api/whip/{streamName}"
};
Expand Down

0 comments on commit 6e03d31

Please sign in to comment.