-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
16 changed files
with
144 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using OpenTokSDK.Exception; | ||
|
||
namespace OpenTokSDK | ||
{ | ||
/// <summary> | ||
/// Represents a BitRate for broadcasts. | ||
/// </summary> | ||
public class BroadcastBitrate | ||
{ | ||
private const int MaxBitrate = 2000000; | ||
private const int MinBitrate = 400000; | ||
|
||
/// <summary> | ||
/// The maximum BitRate allowed for the broadcast composing. | ||
/// </summary> | ||
public long Bitrate { get; } | ||
|
||
/// <summary> | ||
/// Creates a BroadcastBitrate with the maximum BitRate. | ||
/// </summary> | ||
public BroadcastBitrate() => this.Bitrate = MaxBitrate; | ||
|
||
/// <summary> | ||
/// Creates a BroadcastBitrate with a specific Bitrate. | ||
/// </summary> | ||
/// <param name="bitrate">The Bitrate.</param> | ||
/// <exception cref="OpenTokArgumentException"> | ||
/// When specified bitrate is lower than the minimum value, or higher than the | ||
/// maximum value. | ||
/// </exception> | ||
public BroadcastBitrate(long bitrate) => | ||
this.Bitrate = ValidateBitrate(bitrate) | ||
? bitrate | ||
: throw new OpenTokArgumentException($"Bitrate value must be between {MinBitrate} and {MaxBitrate}."); | ||
|
||
private static bool ValidateBitrate(long bitrate) => bitrate <= MaxBitrate && bitrate >= MinBitrate; | ||
} | ||
|
||
internal class BroadcastBitrateConverter : JsonConverter<BroadcastBitrate> | ||
{ | ||
public override void WriteJson(JsonWriter writer, BroadcastBitrate value, JsonSerializer serializer) => | ||
writer.WriteValue(value?.Bitrate); | ||
|
||
public override BroadcastBitrate ReadJson(JsonReader reader, Type objectType, BroadcastBitrate existingValue, bool hasExistingValue, | ||
JsonSerializer serializer) | ||
{ | ||
var value = (long?)reader.Value; | ||
return value.HasValue ? new BroadcastBitrate(value.Value) : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using OpenTokSDK; | ||
using OpenTokSDK.Exception; | ||
using Xunit; | ||
|
||
namespace OpenTokSDKTest | ||
{ | ||
public class BroadcastBitrateTest | ||
{ | ||
[Fact] | ||
public void Bitrate_ShouldHaveDefaultValue() => | ||
Assert.Equal(2000000, new BroadcastBitrate().Bitrate); | ||
|
||
[Fact] | ||
public void Bitrate_ShouldAllowMaximumValue()=> | ||
Assert.Equal(2000000, new BroadcastBitrate(2000000).Bitrate); | ||
|
||
[Fact] | ||
public void Bitrate_ShouldAllowMinimumValue()=> | ||
Assert.Equal(400000, new BroadcastBitrate(400000).Bitrate); | ||
|
||
[Theory] | ||
[InlineData(399999)] | ||
[InlineData(2000001)] | ||
public void Bitrate_ShouldThrowException_GivenValueIsOutsideRange(int invalidBitrate) | ||
{ | ||
var exception = Assert.Throws<OpenTokArgumentException>(() => new BroadcastBitrate(invalidBitrate)); | ||
Assert.Equal("Bitrate value must be between 400000 and 2000000.", exception.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters