VrtcServerMessage.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Text.Json;
  2. using System.Text.Json.Serialization;
  3. namespace VRTC
  4. {
  5. public class VrtcServerMessage
  6. {
  7. /// <summary>
  8. /// The commad from client
  9. /// </summary>
  10. [JsonPropertyName("command")]
  11. public VrtcCommands Command { get; set; }
  12. /// <summary>
  13. /// The rtc room ID
  14. /// </summary>
  15. [JsonPropertyName("roomId")]
  16. public uint RoomId { get; set; }
  17. /// <summary>
  18. /// The client ID
  19. /// </summary>
  20. [JsonPropertyName("clientId")]
  21. public string ClientId { get; set; }
  22. public string ToJson()
  23. {
  24. return JsonSerializer.Serialize(this);
  25. }
  26. }
  27. public class VrtcServerSdpMessage : VrtcServerMessage
  28. {
  29. /// <summary>
  30. /// The Web rtc protocol
  31. /// </summary>
  32. [JsonPropertyName("sdp")]
  33. public string Sdp { get; set; }
  34. public new string ToJson()
  35. {
  36. return JsonSerializer.Serialize(this);
  37. }
  38. }
  39. public class VrtcServerCandidateMessage : VrtcServerMessage
  40. {
  41. /// <summary>
  42. /// If present, this is the value of the "a=mid" attribute of the candidate's
  43. /// </summary>
  44. [JsonPropertyName("sdpMid")]
  45. public string SdpMid { get; set; }
  46. /// <summary>
  47. /// This indicates the index (starting at zero) of m= section this candidate is associated with. Needed when an endpoint doesn't support MIDs.
  48. /// </summary>
  49. [JsonPropertyName("sdpMLineIndex")]
  50. public int SdpMlineIndex { get; set; }
  51. /// <summary>
  52. /// The Web rtc protocol
  53. /// </summary>
  54. [JsonPropertyName("candidate")]
  55. public string Candidate { get; set; }
  56. public new string ToJson()
  57. {
  58. return JsonSerializer.Serialize(this);
  59. }
  60. [Test]
  61. public void ToJson_WhenCalled_ReturnsJsonString()
  62. {
  63. // Arrange
  64. var testObject = new TestObject();
  65. // Act
  66. var result = testObject.ToJson();
  67. // Assert
  68. Assert.IsNotNull(result);
  69. Assert.IsInstanceOfType(result, typeof(string));
  70. Assert.IsTrue(result.StartsWith("{"));
  71. Assert.IsTrue(result.EndsWith("}"));
  72. }
  73. }
  74. }