CefMediaRouter.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Supports discovery of and communication with media devices on the local
  10. /// network via the Cast and DIAL protocols. The methods of this class may be
  11. /// called on any browser process thread unless otherwise indicated.
  12. /// </summary>
  13. public sealed unsafe partial class CefMediaRouter
  14. {
  15. /// <summary>
  16. /// Returns the MediaRouter object associated with the global request context.
  17. /// If |callback| is non-NULL it will be executed asnychronously on the UI
  18. /// thread after the manager's storage has been initialized. Equivalent to
  19. /// calling CefRequestContext::GetGlobalContext()->GetMediaRouter().
  20. /// </summary>
  21. public static CefMediaRouter GetGlobalMediaRouter(CefCompletionCallback? callback)
  22. {
  23. var nCallback = callback != null ? callback.ToNative() : null;
  24. var nResult = cef_media_router_t.get_global(nCallback);
  25. return CefMediaRouter.FromNative(nResult);
  26. }
  27. /// <summary>
  28. /// Add an observer for MediaRouter events. The observer will remain registered
  29. /// until the returned Registration object is destroyed.
  30. /// </summary>
  31. public CefRegistration AddObserver(CefMediaObserver observer)
  32. {
  33. var n_result = cef_media_router_t.add_observer(_self, observer.ToNative());
  34. return CefRegistration.FromNative(n_result);
  35. }
  36. /// <summary>
  37. /// Returns a MediaSource object for the specified media source URN. Supported
  38. /// URN schemes include "cast:" and "dial:", and will be already known by the
  39. /// client application (e.g. "cast:&lt;appId&gt;?clientId=&lt;clientId&gt;").
  40. /// </summary>
  41. public CefMediaSource GetSource(string urn)
  42. {
  43. fixed (char* urn_str = urn)
  44. {
  45. var n_urn = new cef_string_t(urn_str, urn.Length);
  46. var n_result = cef_media_router_t.get_source(_self, &n_urn);
  47. return CefMediaSource.FromNativeOrNull(n_result);
  48. }
  49. }
  50. /// <summary>
  51. /// Trigger an asynchronous call to CefMediaObserver::OnSinks on all
  52. /// registered observers.
  53. /// </summary>
  54. public void NotifyCurrentSinks()
  55. {
  56. cef_media_router_t.notify_current_sinks(_self);
  57. }
  58. /// <summary>
  59. /// Create a new route between |source| and |sink|. Source and sink must be
  60. /// valid, compatible (as reported by CefMediaSink::IsCompatibleWith), and a
  61. /// route between them must not already exist. |callback| will be executed
  62. /// on success or failure. If route creation succeeds it will also trigger an
  63. /// asynchronous call to CefMediaObserver::OnRoutes on all registered
  64. /// observers.
  65. /// </summary>
  66. public void CreateRoute(CefMediaSource source, CefMediaSink sink, CefMediaRouteCreateCallback callback)
  67. {
  68. cef_media_router_t.create_route(_self,
  69. source.ToNative(),
  70. sink.ToNative(),
  71. callback.ToNative());
  72. }
  73. /// <summary>
  74. /// Trigger an asynchronous call to CefMediaObserver::OnRoutes on all
  75. /// registered observers.
  76. /// </summary>
  77. public void NotifyCurrentRoutes()
  78. {
  79. cef_media_router_t.notify_current_routes(_self);
  80. }
  81. }
  82. }