IWebSocketConnection.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /// Gets the id.
  11. /// </summary>
  12. /// <value>The id.</value>
  13. Guid Id { get; }
  14. /// <summary>
  15. /// Gets the last activity date.
  16. /// </summary>
  17. /// <value>The last activity date.</value>
  18. DateTime LastActivityDate { get; }
  19. /// <summary>
  20. /// Gets or sets the receive action.
  21. /// </summary>
  22. /// <value>The receive action.</value>
  23. Action<WebSocketMessageInfo> OnReceive { get; set; }
  24. /// <summary>
  25. /// Gets the state.
  26. /// </summary>
  27. /// <value>The state.</value>
  28. WebSocketState State { get; }
  29. /// <summary>
  30. /// Gets the remote end point.
  31. /// </summary>
  32. /// <value>The remote end point.</value>
  33. string RemoteEndPoint { get; }
  34. /// <summary>
  35. /// Sends a message asynchronously.
  36. /// </summary>
  37. /// <typeparam name="T"></typeparam>
  38. /// <param name="message">The message.</param>
  39. /// <param name="cancellationToken">The cancellation token.</param>
  40. /// <returns>Task.</returns>
  41. /// <exception cref="System.ArgumentNullException">message</exception>
  42. Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
  43. /// <summary>
  44. /// Sends a message asynchronously.
  45. /// </summary>
  46. /// <param name="buffer">The buffer.</param>
  47. /// <param name="cancellationToken">The cancellation token.</param>
  48. /// <returns>Task.</returns>
  49. Task SendAsync(byte[] buffer, CancellationToken cancellationToken);
  50. /// <summary>
  51. /// Sends a message asynchronously.
  52. /// </summary>
  53. /// <param name="buffer">The buffer.</param>
  54. /// <param name="type">The type.</param>
  55. /// <param name="cancellationToken">The cancellation token.</param>
  56. /// <returns>Task.</returns>
  57. /// <exception cref="System.ArgumentNullException">buffer</exception>
  58. Task SendAsync(byte[] buffer, WebSocketMessageType type, CancellationToken cancellationToken);
  59. }
  60. }