IWebSocketConnection.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Net;
  4. using System.Net.WebSockets;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using MediaBrowser.Model.Net;
  8. namespace MediaBrowser.Controller.Net
  9. {
  10. public interface IWebSocketConnection : IAsyncDisposable, IDisposable
  11. {
  12. /// <summary>
  13. /// Occurs when [closed].
  14. /// </summary>
  15. event EventHandler<EventArgs>? Closed;
  16. /// <summary>
  17. /// Gets the last activity date.
  18. /// </summary>
  19. /// <value>The last activity date.</value>
  20. DateTime LastActivityDate { get; }
  21. /// <summary>
  22. /// Gets or sets the date of last Keeplive received.
  23. /// </summary>
  24. /// <value>The date of last Keeplive received.</value>
  25. DateTime LastKeepAliveDate { get; set; }
  26. /// <summary>
  27. /// Gets or sets the receive action.
  28. /// </summary>
  29. /// <value>The receive action.</value>
  30. Func<WebSocketMessageInfo, Task>? OnReceive { get; set; }
  31. /// <summary>
  32. /// Gets the state.
  33. /// </summary>
  34. /// <value>The state.</value>
  35. WebSocketState State { get; }
  36. /// <summary>
  37. /// Gets the remote end point.
  38. /// </summary>
  39. /// <value>The remote end point.</value>
  40. IPAddress? RemoteEndPoint { get; }
  41. /// <summary>
  42. /// Sends a message asynchronously.
  43. /// </summary>
  44. /// <typeparam name="T">The type of websocket message data.</typeparam>
  45. /// <param name="message">The message.</param>
  46. /// <param name="cancellationToken">The cancellation token.</param>
  47. /// <returns>Task.</returns>
  48. /// <exception cref="ArgumentNullException">The message is null.</exception>
  49. Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
  50. Task ProcessAsync(CancellationToken cancellationToken = default);
  51. }
  52. }