Skip to content

Commit

Permalink
feat: add MaxBitrate for Archives
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Dec 6, 2024
1 parent 149d435 commit 7364c5c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
18 changes: 15 additions & 3 deletions OpenTok/OpenTok.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,11 @@ public string GenerateT1Token(string sessionId, Role role = Role.PUBLISHER, doub
/// only record one archive at a time for a given session. See
/// <a href="https://tokbox.com/developer/guides/archiving/#simultaneous-archives">Simultaneous archives</a>.
/// </param>
/// <param name="maxBitrate">The maximum video bitrate for the archive, in bits per second. This option is only valid for composed archives. Set the maximum video bitrate to control the size of the composed archive. This maximum bitrate applies to the video bitrate only. If the output archive has audio, those bits will be excluded from the limit.</param>
/// <returns>
/// The Archive object. This object includes properties defining the archive, including the archive ID.
/// </returns>
public Archive StartArchive(string sessionId, string name = "", bool hasVideo = true, bool hasAudio = true, OutputMode outputMode = OutputMode.COMPOSED, string resolution = null, ArchiveLayout layout = null, StreamMode? streamMode = null, string multiArchiveTag = null)
public Archive StartArchive(string sessionId, string name = "", bool hasVideo = true, bool hasAudio = true, OutputMode outputMode = OutputMode.COMPOSED, string resolution = null, ArchiveLayout layout = null, StreamMode? streamMode = null, string multiArchiveTag = null, int? maxBitrate = null)
{
if (string.IsNullOrEmpty(sessionId))
{
Expand Down Expand Up @@ -588,6 +589,11 @@ public Archive StartArchive(string sessionId, string name = "", bool hasVideo =
{
data.Add("streamMode", streamMode.Value.ToString().ToLower());
}

if (maxBitrate.HasValue)
{
data.Add("maxBitrate", maxBitrate.Value);
}

string response = Client.Post(url, headers, data);
return OpenTokUtils.GenerateArchive(response, ApiKey, ApiSecret, OpenTokServer);
Expand All @@ -598,7 +604,7 @@ public Archive StartArchive(string sessionId, string name = "", bool hasVideo =
/// </summary>
/// <returns>The identifier.</returns>
public string GetOpenTokId() => this.IsShim ? this.applicationId : this.ApiKey.ToString();

/// <summary>
/// Starts archiving an OpenTok session.
/// <para>
Expand Down Expand Up @@ -662,10 +668,11 @@ public Archive StartArchive(string sessionId, string name = "", bool hasVideo =
/// only record one archive at a time for a given session. See
/// <a href="https://tokbox.com/developer/guides/archiving/#simultaneous-archives">Simultaneous archives</a>.
/// </param>
/// <param name="maxBitrate">The maximum video bitrate for the archive, in bits per second. This option is only valid for composed archives. Set the maximum video bitrate to control the size of the composed archive. This maximum bitrate applies to the video bitrate only. If the output archive has audio, those bits will be excluded from the limit.</param>
/// <returns>
/// The Archive object. This object includes properties defining the archive, including the archive ID.
/// </returns>
public async Task<Archive> StartArchiveAsync(string sessionId, string name = "", bool hasVideo = true, bool hasAudio = true, OutputMode outputMode = OutputMode.COMPOSED, string resolution = null, ArchiveLayout layout = null, StreamMode? streamMode = null, string multiArchiveTag = null)
public async Task<Archive> StartArchiveAsync(string sessionId, string name = "", bool hasVideo = true, bool hasAudio = true, OutputMode outputMode = OutputMode.COMPOSED, string resolution = null, ArchiveLayout layout = null, StreamMode? streamMode = null, string multiArchiveTag = null, int? maxBitrate = null)
{
if (string.IsNullOrEmpty(sessionId))
{
Expand Down Expand Up @@ -717,6 +724,11 @@ public async Task<Archive> StartArchiveAsync(string sessionId, string name = "",
data.Add("streamMode", streamMode.Value.ToString().ToLower());
}

if (maxBitrate.HasValue)
{
data.Add("maxBitrate", maxBitrate.Value);
}

string response = await Client.PostAsync(url, headers, data);
return OpenTokUtils.GenerateArchive(response, ApiKey, ApiSecret, OpenTokServer);
}
Expand Down
40 changes: 40 additions & 0 deletions OpenTokTest/ArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,46 @@ public async Task StartArchiveWithMultiArchiveTagAsync()
dictionary[multiArchiveTagName].ToString() == multiArchiveTag)),
Times.Once());
}

[Fact]
public void StartArchiveWithMaxBitrate()
{
var responseJson = GetResponseJson("StartArchive");
var mockClient = new Mock<HttpClient>();
mockClient.Setup(httpClient => httpClient.Post(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(),
It.IsAny<Dictionary<string, object>>()))
.Returns(responseJson);
var opentok = BuildOpenTok(mockClient.Object);
opentok.StartArchive(SessionId, maxBitrate: 300000);
mockClient.Verify(
httpClient => httpClient.Post(
It.Is<string>(url => url.Equals("v2/project/" + ApiKey + "/archive")),
It.IsAny<Dictionary<string, string>>(),
It.Is<Dictionary<string, object>>(dictionary =>
dictionary.ContainsKey("maxBitrate") &&
dictionary["maxBitrate"].ToString() == 300000.ToString())),
Times.Once());
}

[Fact]
public async Task StartArchiveWithMaxBitrateAsync()
{
var responseJson = GetResponseJson("StartArchive");
var mockClient = new Mock<HttpClient>();
mockClient.Setup(httpClient => httpClient.PostAsync(It.IsAny<string>(),
It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, object>>()))
.ReturnsAsync(responseJson);
var opentok = BuildOpenTok(mockClient.Object);
await opentok.StartArchiveAsync(SessionId, maxBitrate: 300000);
mockClient.Verify(
httpClient => httpClient.PostAsync(
It.Is<string>(url => url.Equals("v2/project/" + ApiKey + "/archive")),
It.IsAny<Dictionary<string, string>>(),
It.Is<Dictionary<string, object>>(dictionary =>
dictionary.ContainsKey("maxBitrate") &&
dictionary["maxBitrate"].ToString() == 300000.ToString())),
Times.Once());
}

// AddStreamToArchive

Expand Down

0 comments on commit 7364c5c

Please sign in to comment.