IWebSocketConnection.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Net.WebSockets;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Model.Net;
  6. using Microsoft.AspNetCore.Http;
  7. namespace MediaBrowser.Controller.Net
  8. {
  9. public interface IWebSocketConnection : IDisposable
  10. {
  11. /// <summary>
  12. /// Occurs when [closed].
  13. /// </summary>
  14. event EventHandler<EventArgs> Closed;
  15. /// <summary>
  16. /// Gets the id.
  17. /// </summary>
  18. /// <value>The id.</value>
  19. Guid Id { get; }
  20. /// <summary>
  21. /// Gets the last activity date.
  22. /// </summary>
  23. /// <value>The last activity date.</value>
  24. DateTime LastActivityDate { get; }
  25. /// <summary>
  26. /// Gets or sets the URL.
  27. /// </summary>
  28. /// <value>The URL.</value>
  29. string Url { get; set; }
  30. /// <summary>
  31. /// Gets or sets the query string.
  32. /// </summary>
  33. /// <value>The query string.</value>
  34. IQueryCollection QueryString { get; set; }
  35. /// <summary>
  36. /// Gets or sets the receive action.
  37. /// </summary>
  38. /// <value>The receive action.</value>
  39. Func<WebSocketMessageInfo, Task> OnReceive { get; set; }
  40. /// <summary>
  41. /// Gets the state.
  42. /// </summary>
  43. /// <value>The state.</value>
  44. WebSocketState State { get; }
  45. /// <summary>
  46. /// Gets the remote end point.
  47. /// </summary>
  48. /// <value>The remote end point.</value>
  49. string RemoteEndPoint { get; }
  50. /// <summary>
  51. /// Sends a message asynchronously.
  52. /// </summary>
  53. /// <typeparam name="T"></typeparam>
  54. /// <param name="message">The message.</param>
  55. /// <param name="cancellationToken">The cancellation token.</param>
  56. /// <returns>Task.</returns>
  57. /// <exception cref="ArgumentNullException">message</exception>
  58. Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
  59. /// <summary>
  60. /// Sends a message asynchronously.
  61. /// </summary>
  62. /// <param name="buffer">The buffer.</param>
  63. /// <param name="cancellationToken">The cancellation token.</param>
  64. /// <returns>Task.</returns>
  65. Task SendAsync(byte[] buffer, CancellationToken cancellationToken);
  66. /// <summary>
  67. /// Sends a message asynchronously.
  68. /// </summary>
  69. /// <param name="text">The text.</param>
  70. /// <param name="cancellationToken">The cancellation token.</param>
  71. /// <returns>Task.</returns>
  72. /// <exception cref="ArgumentNullException">buffer</exception>
  73. Task SendAsync(string text, CancellationToken cancellationToken);
  74. }
  75. }