IWebSocketConnection.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Net;
  3. using System.Net.WebSockets;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Controller.Net.WebSocketMessages;
  7. namespace MediaBrowser.Controller.Net
  8. {
  9. /// <summary>
  10. /// Interface for WebSocket connections.
  11. /// </summary>
  12. public interface IWebSocketConnection : IAsyncDisposable, IDisposable
  13. {
  14. /// <summary>
  15. /// Occurs when [closed].
  16. /// </summary>
  17. event EventHandler<EventArgs>? Closed;
  18. /// <summary>
  19. /// Gets the last activity date.
  20. /// </summary>
  21. /// <value>The last activity date.</value>
  22. DateTime LastActivityDate { get; }
  23. /// <summary>
  24. /// Gets or sets the date of last Keepalive received.
  25. /// </summary>
  26. /// <value>The date of last Keepalive received.</value>
  27. DateTime LastKeepAliveDate { get; set; }
  28. /// <summary>
  29. /// Gets or sets the receive action.
  30. /// </summary>
  31. /// <value>The receive action.</value>
  32. Func<WebSocketMessageInfo, Task>? OnReceive { get; set; }
  33. /// <summary>
  34. /// Gets the state.
  35. /// </summary>
  36. /// <value>The state.</value>
  37. WebSocketState State { get; }
  38. /// <summary>
  39. /// Gets the authorization information.
  40. /// </summary>
  41. public AuthorizationInfo AuthorizationInfo { get; }
  42. /// <summary>
  43. /// Gets the remote end point.
  44. /// </summary>
  45. /// <value>The remote end point.</value>
  46. IPAddress? RemoteEndPoint { get; }
  47. /// <summary>
  48. /// Sends a message asynchronously.
  49. /// </summary>
  50. /// <param name="message">The message.</param>
  51. /// <param name="cancellationToken">The cancellation token.</param>
  52. /// <returns>Task.</returns>
  53. /// <exception cref="ArgumentNullException">The message is null.</exception>
  54. Task SendAsync(OutboundWebSocketMessage message, CancellationToken cancellationToken);
  55. /// <summary>
  56. /// Sends a message asynchronously.
  57. /// </summary>
  58. /// <typeparam name="T">The type of websocket message data.</typeparam>
  59. /// <param name="message">The message.</param>
  60. /// <param name="cancellationToken">The cancellation token.</param>
  61. /// <returns>Task.</returns>
  62. /// <exception cref="ArgumentNullException">The message is null.</exception>
  63. Task SendAsync<T>(OutboundWebSocketMessage<T> message, CancellationToken cancellationToken);
  64. /// <summary>
  65. /// Receives a message asynchronously.
  66. /// </summary>
  67. /// <param name="cancellationToken">The cancellation token.</param>
  68. /// <returns>Task.</returns>
  69. Task ReceiveAsync(CancellationToken cancellationToken = default);
  70. }
  71. }