IServerManager.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. namespace MediaBrowser.Common.Net
  6. {
  7. public interface IServerManager : IDisposable
  8. {
  9. /// <summary>
  10. /// Gets a value indicating whether [supports web socket].
  11. /// </summary>
  12. /// <value><c>true</c> if [supports web socket]; otherwise, <c>false</c>.</value>
  13. bool SupportsNativeWebSocket { get; }
  14. /// <summary>
  15. /// Gets the web socket port number.
  16. /// </summary>
  17. /// <value>The web socket port number.</value>
  18. int WebSocketPortNumber { get; }
  19. /// <summary>
  20. /// Starts this instance.
  21. /// </summary>
  22. void Start();
  23. /// <summary>
  24. /// Sends a message to all clients currently connected via a web socket
  25. /// </summary>
  26. /// <typeparam name="T"></typeparam>
  27. /// <param name="messageType">Type of the message.</param>
  28. /// <param name="data">The data.</param>
  29. /// <returns>Task.</returns>
  30. void SendWebSocketMessage<T>(string messageType, T data);
  31. /// <summary>
  32. /// Sends a message to all clients currently connected via a web socket
  33. /// </summary>
  34. /// <typeparam name="T"></typeparam>
  35. /// <param name="messageType">Type of the message.</param>
  36. /// <param name="dataFunction">The function that generates the data to send, if there are any connected clients</param>
  37. void SendWebSocketMessage<T>(string messageType, Func<T> dataFunction);
  38. /// <summary>
  39. /// Sends a message to all clients currently connected via a web socket
  40. /// </summary>
  41. /// <typeparam name="T"></typeparam>
  42. /// <param name="messageType">Type of the message.</param>
  43. /// <param name="dataFunction">The function that generates the data to send, if there are any connected clients</param>
  44. /// <param name="cancellationToken">The cancellation token.</param>
  45. /// <returns>Task.</returns>
  46. /// <exception cref="System.ArgumentNullException">messageType</exception>
  47. Task SendWebSocketMessageAsync<T>(string messageType, Func<T> dataFunction, CancellationToken cancellationToken);
  48. /// <summary>
  49. /// Sends the web socket message async.
  50. /// </summary>
  51. /// <typeparam name="T"></typeparam>
  52. /// <param name="messageType">Type of the message.</param>
  53. /// <param name="dataFunction">The data function.</param>
  54. /// <param name="connections">The connections.</param>
  55. /// <param name="cancellationToken">The cancellation token.</param>
  56. /// <returns>Task.</returns>
  57. Task SendWebSocketMessageAsync<T>(string messageType, Func<T> dataFunction, IEnumerable<IWebSocketConnection> connections, CancellationToken cancellationToken);
  58. /// <summary>
  59. /// Adds the web socket listeners.
  60. /// </summary>
  61. /// <param name="listeners">The listeners.</param>
  62. void AddWebSocketListeners(IEnumerable<IWebSocketListener> listeners);
  63. /// <summary>
  64. /// Gets the web socket connections.
  65. /// </summary>
  66. /// <value>The web socket connections.</value>
  67. IEnumerable<IWebSocketConnection> WebSocketConnections { get; }
  68. }
  69. }