IWebSocketConnection.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. using Microsoft.AspNetCore.Http;
  9. namespace MediaBrowser.Controller.Net
  10. {
  11. public interface IWebSocketConnection
  12. {
  13. /// <summary>
  14. /// Occurs when [closed].
  15. /// </summary>
  16. event EventHandler<EventArgs>? Closed;
  17. /// <summary>
  18. /// Gets the last activity date.
  19. /// </summary>
  20. /// <value>The last activity date.</value>
  21. DateTime LastActivityDate { get; }
  22. /// <summary>
  23. /// Gets or sets the date of last Keeplive received.
  24. /// </summary>
  25. /// <value>The date of last Keeplive received.</value>
  26. DateTime LastKeepAliveDate { get; set; }
  27. /// <summary>
  28. /// Gets the query string.
  29. /// </summary>
  30. /// <value>The query string.</value>
  31. IQueryCollection QueryString { get; }
  32. /// <summary>
  33. /// Gets or sets the receive action.
  34. /// </summary>
  35. /// <value>The receive action.</value>
  36. Func<WebSocketMessageInfo, Task>? OnReceive { get; set; }
  37. /// <summary>
  38. /// Gets the state.
  39. /// </summary>
  40. /// <value>The state.</value>
  41. WebSocketState State { 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. /// <typeparam name="T">The type of websocket message data.</typeparam>
  51. /// <param name="message">The message.</param>
  52. /// <param name="cancellationToken">The cancellation token.</param>
  53. /// <returns>Task.</returns>
  54. /// <exception cref="ArgumentNullException">The message is null.</exception>
  55. Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
  56. Task ProcessAsync(CancellationToken cancellationToken = default);
  57. }
  58. }