IWebSocketConnection.cs 1.9 KB

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