IServerManager.cs 3.0 KB

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