IWebSocketConnection.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using MediaBrowser.Model.Net;
  2. using System;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. namespace MediaBrowser.Common.Net
  6. {
  7. public interface IWebSocketConnection : IDisposable
  8. {
  9. /// <summary>
  10. /// Occurs when [closed].
  11. /// </summary>
  12. event EventHandler<EventArgs> Closed;
  13. /// <summary>
  14. /// Gets the id.
  15. /// </summary>
  16. /// <value>The id.</value>
  17. Guid Id { get; }
  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 receive action.
  25. /// </summary>
  26. /// <value>The receive action.</value>
  27. Action<WebSocketMessageInfo> OnReceive { get; set; }
  28. /// <summary>
  29. /// Gets the state.
  30. /// </summary>
  31. /// <value>The state.</value>
  32. WebSocketState State { get; }
  33. /// <summary>
  34. /// Gets the remote end point.
  35. /// </summary>
  36. /// <value>The remote end point.</value>
  37. string RemoteEndPoint { get; }
  38. /// <summary>
  39. /// Sends a message asynchronously.
  40. /// </summary>
  41. /// <typeparam name="T"></typeparam>
  42. /// <param name="message">The message.</param>
  43. /// <param name="cancellationToken">The cancellation token.</param>
  44. /// <returns>Task.</returns>
  45. /// <exception cref="System.ArgumentNullException">message</exception>
  46. Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
  47. /// <summary>
  48. /// Sends a message asynchronously.
  49. /// </summary>
  50. /// <param name="buffer">The buffer.</param>
  51. /// <param name="cancellationToken">The cancellation token.</param>
  52. /// <returns>Task.</returns>
  53. Task SendAsync(byte[] buffer, CancellationToken cancellationToken);
  54. /// <summary>
  55. /// Sends a message asynchronously.
  56. /// </summary>
  57. /// <param name="buffer">The buffer.</param>
  58. /// <param name="type">The type.</param>
  59. /// <param name="cancellationToken">The cancellation token.</param>
  60. /// <returns>Task.</returns>
  61. /// <exception cref="System.ArgumentNullException">buffer</exception>
  62. Task SendAsync(byte[] buffer, WebSocketMessageType type, CancellationToken cancellationToken);
  63. }
  64. }