IWebSocket.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Net.WebSockets;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. namespace Emby.Server.Implementations.Net
  6. {
  7. /// <summary>
  8. /// Interface IWebSocket
  9. /// </summary>
  10. public interface IWebSocket : IDisposable
  11. {
  12. /// <summary>
  13. /// Occurs when [closed].
  14. /// </summary>
  15. event EventHandler<EventArgs> Closed;
  16. /// <summary>
  17. /// Gets or sets the state.
  18. /// </summary>
  19. /// <value>The state.</value>
  20. WebSocketState State { get; }
  21. /// <summary>
  22. /// Gets or sets the receive action.
  23. /// </summary>
  24. /// <value>The receive action.</value>
  25. Action<byte[]> OnReceiveBytes { get; set; }
  26. /// <summary>
  27. /// Sends the async.
  28. /// </summary>
  29. /// <param name="bytes">The bytes.</param>
  30. /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param>
  31. /// <param name="cancellationToken">The cancellation token.</param>
  32. /// <returns>Task.</returns>
  33. Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken);
  34. /// <summary>
  35. /// Sends the asynchronous.
  36. /// </summary>
  37. /// <param name="text">The text.</param>
  38. /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param>
  39. /// <param name="cancellationToken">The cancellation token.</param>
  40. /// <returns>Task.</returns>
  41. Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken);
  42. }
  43. public interface IMemoryWebSocket
  44. {
  45. Action<Memory<byte>, int> OnReceiveMemoryBytes { get; set; }
  46. }
  47. }