electron-cast 0.4.0 → 0.5.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (626) hide show
  1. package/CHANGELOG.md +280 -0
  2. package/CONTRIBUTING.md +305 -0
  3. package/README.md +211 -165
  4. package/SECURITY.md +324 -0
  5. package/dist/cjs/client/auth/build-time.js +1 -1
  6. package/dist/cjs/client/auth/cast-auth.d.ts +2 -0
  7. package/dist/cjs/client/auth/cast-auth.js.map +1 -1
  8. package/dist/cjs/dial/dial-registry.d.ts +104 -0
  9. package/dist/cjs/dial/dial-registry.js +301 -0
  10. package/dist/cjs/dial/dial-registry.js.map +1 -0
  11. package/dist/cjs/dial/dial-sink-service.d.ts +108 -0
  12. package/dist/cjs/dial/dial-sink-service.js +314 -0
  13. package/dist/cjs/dial/dial-sink-service.js.map +1 -0
  14. package/dist/cjs/dial/http.d.ts +40 -0
  15. package/dist/cjs/dial/http.js +172 -0
  16. package/dist/cjs/dial/http.js.map +1 -0
  17. package/dist/cjs/dial/index.d.ts +63 -0
  18. package/dist/cjs/dial/index.js +134 -0
  19. package/dist/cjs/dial/index.js.map +1 -0
  20. package/dist/cjs/dial/origins.d.ts +4 -0
  21. package/dist/cjs/dial/origins.js +36 -0
  22. package/dist/cjs/dial/origins.js.map +1 -0
  23. package/dist/cjs/dial/parse.d.ts +101 -0
  24. package/dist/cjs/dial/parse.js +296 -0
  25. package/dist/cjs/dial/parse.js.map +1 -0
  26. package/dist/cjs/dial/route-provider.d.ts +96 -0
  27. package/dist/cjs/dial/route-provider.js +376 -0
  28. package/dist/cjs/dial/route-provider.js.map +1 -0
  29. package/dist/cjs/dial/ssdp-socket.d.ts +34 -0
  30. package/dist/cjs/dial/ssdp-socket.js +72 -0
  31. package/dist/cjs/dial/ssdp-socket.js.map +1 -0
  32. package/dist/cjs/dial/xml.d.ts +13 -0
  33. package/dist/cjs/dial/xml.js +208 -0
  34. package/dist/cjs/dial/xml.js.map +1 -0
  35. package/dist/cjs/discovery/cast-discovery.d.ts +2 -0
  36. package/dist/cjs/discovery/cast-discovery.js.map +1 -1
  37. package/dist/cjs/discovery/device-cache.d.ts +9 -0
  38. package/dist/cjs/discovery/device-cache.js.map +1 -1
  39. package/dist/cjs/discovery/index.d.ts +1 -0
  40. package/dist/cjs/discovery/index.js +1 -0
  41. package/dist/cjs/discovery/index.js.map +1 -1
  42. package/dist/cjs/discovery/ip-policy.d.ts +20 -0
  43. package/dist/cjs/discovery/ip-policy.js +109 -0
  44. package/dist/cjs/discovery/ip-policy.js.map +1 -0
  45. package/dist/cjs/discovery/udp-socket.d.ts +3 -0
  46. package/dist/cjs/discovery/udp-socket.js +3 -0
  47. package/dist/cjs/discovery/udp-socket.js.map +1 -1
  48. package/dist/cjs/electron/access-code.d.ts +221 -0
  49. package/dist/cjs/electron/access-code.js +586 -0
  50. package/dist/cjs/electron/access-code.js.map +1 -0
  51. package/dist/cjs/electron/app-discovery.d.ts +82 -0
  52. package/dist/cjs/electron/app-discovery.js +219 -0
  53. package/dist/cjs/electron/app-discovery.js.map +1 -0
  54. package/dist/cjs/electron/default-presentation.d.ts +38 -0
  55. package/dist/cjs/electron/default-presentation.js +88 -0
  56. package/dist/cjs/electron/default-presentation.js.map +1 -0
  57. package/dist/cjs/electron/main.d.ts +98 -11
  58. package/dist/cjs/electron/main.js +602 -20
  59. package/dist/cjs/electron/main.js.map +1 -1
  60. package/dist/cjs/electron/manager-api.d.ts +200 -18
  61. package/dist/cjs/electron/manager-api.js +199 -4
  62. package/dist/cjs/electron/manager-api.js.map +1 -1
  63. package/dist/cjs/electron/media-controller.d.ts +79 -0
  64. package/dist/cjs/electron/media-controller.js +251 -0
  65. package/dist/cjs/electron/media-controller.js.map +1 -0
  66. package/dist/cjs/electron/network-monitor.d.ts +61 -0
  67. package/dist/cjs/electron/network-monitor.js +124 -0
  68. package/dist/cjs/electron/network-monitor.js.map +1 -0
  69. package/dist/cjs/electron/preload.js.map +1 -1
  70. package/dist/cjs/electron/presentation-handler.d.ts +39 -4
  71. package/dist/cjs/electron/presentation-handler.js +191 -47
  72. package/dist/cjs/electron/presentation-handler.js.map +1 -1
  73. package/dist/cjs/electron/presentation-source.d.ts +76 -0
  74. package/dist/cjs/electron/presentation-source.js +132 -0
  75. package/dist/cjs/electron/presentation-source.js.map +1 -0
  76. package/dist/cjs/electron/session-service.d.ts +198 -24
  77. package/dist/cjs/electron/session-service.js +630 -248
  78. package/dist/cjs/electron/session-service.js.map +1 -1
  79. package/dist/cjs/electron/session-tracker.d.ts +82 -0
  80. package/dist/cjs/electron/session-tracker.js +225 -0
  81. package/dist/cjs/electron/session-tracker.js.map +1 -0
  82. package/dist/cjs/electron/sink-service.d.ts +246 -0
  83. package/dist/cjs/electron/sink-service.js +606 -0
  84. package/dist/cjs/electron/sink-service.js.map +1 -0
  85. package/dist/cjs/electron/wired-display/controller.d.ts +76 -0
  86. package/dist/cjs/electron/wired-display/controller.js +198 -0
  87. package/dist/cjs/electron/wired-display/controller.js.map +1 -0
  88. package/dist/cjs/electron/wired-display/displays.d.ts +44 -0
  89. package/dist/cjs/electron/wired-display/displays.js +98 -0
  90. package/dist/cjs/electron/wired-display/displays.js.map +1 -0
  91. package/dist/cjs/electron/wired-display/electron-windows.d.ts +111 -0
  92. package/dist/cjs/electron/wired-display/electron-windows.js +306 -0
  93. package/dist/cjs/electron/wired-display/electron-windows.js.map +1 -0
  94. package/dist/cjs/electron/wired-display/index.d.ts +90 -0
  95. package/dist/cjs/electron/wired-display/index.js +115 -0
  96. package/dist/cjs/electron/wired-display/index.js.map +1 -0
  97. package/dist/cjs/electron/wired-display/local-presentation.d.ts +98 -0
  98. package/dist/cjs/electron/wired-display/local-presentation.js +234 -0
  99. package/dist/cjs/electron/wired-display/local-presentation.js.map +1 -0
  100. package/dist/cjs/electron/wired-display/provider.d.ts +112 -0
  101. package/dist/cjs/electron/wired-display/provider.js +202 -0
  102. package/dist/cjs/electron/wired-display/provider.js.map +1 -0
  103. package/dist/cjs/index.d.ts +1 -0
  104. package/dist/cjs/index.js +1 -0
  105. package/dist/cjs/index.js.map +1 -1
  106. package/dist/cjs/mirroring/backend.d.ts +76 -0
  107. package/dist/cjs/mirroring/backend.js +21 -0
  108. package/dist/cjs/mirroring/backend.js.map +1 -0
  109. package/dist/cjs/mirroring/electron/agent-protocol.d.ts +158 -0
  110. package/dist/cjs/mirroring/electron/agent-protocol.js +11 -0
  111. package/dist/cjs/mirroring/electron/agent-protocol.js.map +1 -0
  112. package/dist/cjs/mirroring/electron/agent-source.d.ts +20 -0
  113. package/dist/cjs/mirroring/electron/agent-source.js +621 -0
  114. package/dist/cjs/mirroring/electron/agent-source.js.map +1 -0
  115. package/dist/cjs/mirroring/electron/engine-process.d.ts +87 -0
  116. package/dist/cjs/mirroring/electron/engine-process.js +81 -0
  117. package/dist/cjs/mirroring/electron/engine-process.js.map +1 -0
  118. package/dist/cjs/mirroring/electron/host.d.ts +89 -0
  119. package/dist/cjs/mirroring/electron/host.js +321 -0
  120. package/dist/cjs/mirroring/electron/host.js.map +1 -0
  121. package/dist/cjs/mirroring/electron/port-backend.d.ts +107 -0
  122. package/dist/cjs/mirroring/electron/port-backend.js +446 -0
  123. package/dist/cjs/mirroring/electron/port-backend.js.map +1 -0
  124. package/dist/cjs/mirroring/encoding-support.d.ts +66 -0
  125. package/dist/cjs/mirroring/encoding-support.js +89 -0
  126. package/dist/cjs/mirroring/encoding-support.js.map +1 -0
  127. package/dist/cjs/mirroring/engine.d.ts +16 -0
  128. package/dist/cjs/mirroring/engine.js +78 -0
  129. package/dist/cjs/mirroring/engine.js.map +1 -0
  130. package/dist/cjs/mirroring/mirror-settings.d.ts +101 -0
  131. package/dist/cjs/mirroring/mirror-settings.js +140 -0
  132. package/dist/cjs/mirroring/mirror-settings.js.map +1 -0
  133. package/dist/cjs/mirroring/mirroring-activity.d.ts +207 -0
  134. package/dist/cjs/mirroring/mirroring-activity.js +367 -0
  135. package/dist/cjs/mirroring/mirroring-activity.js.map +1 -0
  136. package/dist/cjs/mirroring/mirroring-manager.d.ts +134 -0
  137. package/dist/cjs/mirroring/mirroring-manager.js +286 -0
  138. package/dist/cjs/mirroring/mirroring-manager.js.map +1 -0
  139. package/dist/cjs/mirroring/protocol/answer.d.ts +87 -0
  140. package/dist/cjs/mirroring/protocol/answer.js +233 -0
  141. package/dist/cjs/mirroring/protocol/answer.js.map +1 -0
  142. package/dist/cjs/mirroring/protocol/constants.d.ts +64 -0
  143. package/dist/cjs/mirroring/protocol/constants.js +70 -0
  144. package/dist/cjs/mirroring/protocol/constants.js.map +1 -0
  145. package/dist/cjs/mirroring/protocol/errors.d.ts +25 -0
  146. package/dist/cjs/mirroring/protocol/errors.js +34 -0
  147. package/dist/cjs/mirroring/protocol/errors.js.map +1 -0
  148. package/dist/cjs/mirroring/protocol/frame-id.d.ts +9 -0
  149. package/dist/cjs/mirroring/protocol/frame-id.js +24 -0
  150. package/dist/cjs/mirroring/protocol/frame-id.js.map +1 -0
  151. package/dist/cjs/mirroring/protocol/messenger.d.ts +42 -0
  152. package/dist/cjs/mirroring/protocol/messenger.js +122 -0
  153. package/dist/cjs/mirroring/protocol/messenger.js.map +1 -0
  154. package/dist/cjs/mirroring/protocol/offer.d.ts +109 -0
  155. package/dist/cjs/mirroring/protocol/offer.js +192 -0
  156. package/dist/cjs/mirroring/protocol/offer.js.map +1 -0
  157. package/dist/cjs/mirroring/protocol/recommendations.d.ts +28 -0
  158. package/dist/cjs/mirroring/protocol/recommendations.js +103 -0
  159. package/dist/cjs/mirroring/protocol/recommendations.js.map +1 -0
  160. package/dist/cjs/mirroring/routing.d.ts +60 -0
  161. package/dist/cjs/mirroring/routing.js +147 -0
  162. package/dist/cjs/mirroring/routing.js.map +1 -0
  163. package/dist/cjs/mirroring/rtcp/ntp.d.ts +27 -0
  164. package/dist/cjs/mirroring/rtcp/ntp.js +62 -0
  165. package/dist/cjs/mirroring/rtcp/ntp.js.map +1 -0
  166. package/dist/cjs/mirroring/rtcp/parser.d.ts +50 -0
  167. package/dist/cjs/mirroring/rtcp/parser.js +270 -0
  168. package/dist/cjs/mirroring/rtcp/parser.js.map +1 -0
  169. package/dist/cjs/mirroring/rtcp/sender-report.d.ts +32 -0
  170. package/dist/cjs/mirroring/rtcp/sender-report.js +56 -0
  171. package/dist/cjs/mirroring/rtcp/sender-report.js.map +1 -0
  172. package/dist/cjs/mirroring/rtcp/wire.d.ts +54 -0
  173. package/dist/cjs/mirroring/rtcp/wire.js +73 -0
  174. package/dist/cjs/mirroring/rtcp/wire.js.map +1 -0
  175. package/dist/cjs/mirroring/rtp/frame-crypto.d.ts +11 -0
  176. package/dist/cjs/mirroring/rtp/frame-crypto.js +39 -0
  177. package/dist/cjs/mirroring/rtp/frame-crypto.js.map +1 -0
  178. package/dist/cjs/mirroring/rtp/frame.d.ts +23 -0
  179. package/dist/cjs/mirroring/rtp/frame.js +3 -0
  180. package/dist/cjs/mirroring/rtp/frame.js.map +1 -0
  181. package/dist/cjs/mirroring/rtp/packetizer.d.ts +27 -0
  182. package/dist/cjs/mirroring/rtp/packetizer.js +92 -0
  183. package/dist/cjs/mirroring/rtp/packetizer.js.map +1 -0
  184. package/dist/cjs/mirroring/sender/audio-sender.d.ts +23 -0
  185. package/dist/cjs/mirroring/sender/audio-sender.js +52 -0
  186. package/dist/cjs/mirroring/sender/audio-sender.js.map +1 -0
  187. package/dist/cjs/mirroring/sender/bandwidth-estimator.d.ts +26 -0
  188. package/dist/cjs/mirroring/sender/bandwidth-estimator.js +107 -0
  189. package/dist/cjs/mirroring/sender/bandwidth-estimator.js.map +1 -0
  190. package/dist/cjs/mirroring/sender/capture-size-oracle.d.ts +121 -0
  191. package/dist/cjs/mirroring/sender/capture-size-oracle.js +440 -0
  192. package/dist/cjs/mirroring/sender/capture-size-oracle.js.map +1 -0
  193. package/dist/cjs/mirroring/sender/frame-sender.d.ts +103 -0
  194. package/dist/cjs/mirroring/sender/frame-sender.js +217 -0
  195. package/dist/cjs/mirroring/sender/frame-sender.js.map +1 -0
  196. package/dist/cjs/mirroring/sender/packet-router.d.ts +74 -0
  197. package/dist/cjs/mirroring/sender/packet-router.js +196 -0
  198. package/dist/cjs/mirroring/sender/packet-router.js.map +1 -0
  199. package/dist/cjs/mirroring/sender/sender-session.d.ts +85 -0
  200. package/dist/cjs/mirroring/sender/sender-session.js +240 -0
  201. package/dist/cjs/mirroring/sender/sender-session.js.map +1 -0
  202. package/dist/cjs/mirroring/sender/sender.d.ts +120 -0
  203. package/dist/cjs/mirroring/sender/sender.js +457 -0
  204. package/dist/cjs/mirroring/sender/sender.js.map +1 -0
  205. package/dist/cjs/mirroring/sender/video-encoder-metrics.d.ts +29 -0
  206. package/dist/cjs/mirroring/sender/video-encoder-metrics.js +64 -0
  207. package/dist/cjs/mirroring/sender/video-encoder-metrics.js.map +1 -0
  208. package/dist/cjs/mirroring/sender/video-sender.d.ts +95 -0
  209. package/dist/cjs/mirroring/sender/video-sender.js +183 -0
  210. package/dist/cjs/mirroring/sender/video-sender.js.map +1 -0
  211. package/dist/cjs/mirroring/session-host.d.ts +185 -0
  212. package/dist/cjs/mirroring/session-host.js +630 -0
  213. package/dist/cjs/mirroring/session-host.js.map +1 -0
  214. package/dist/cjs/mirroring/stats/clock-offset-estimator.d.ts +11 -0
  215. package/dist/cjs/mirroring/stats/clock-offset-estimator.js +123 -0
  216. package/dist/cjs/mirroring/stats/clock-offset-estimator.js.map +1 -0
  217. package/dist/cjs/mirroring/stats/openscreen-stats-client.d.ts +12 -0
  218. package/dist/cjs/mirroring/stats/openscreen-stats-client.js +21 -0
  219. package/dist/cjs/mirroring/stats/openscreen-stats-client.js.map +1 -0
  220. package/dist/cjs/mirroring/stats/sorted-map.d.ts +23 -0
  221. package/dist/cjs/mirroring/stats/sorted-map.js +70 -0
  222. package/dist/cjs/mirroring/stats/sorted-map.js.map +1 -0
  223. package/dist/cjs/mirroring/stats/statistics-analyzer.d.ts +50 -0
  224. package/dist/cjs/mirroring/stats/statistics-analyzer.js +339 -0
  225. package/dist/cjs/mirroring/stats/statistics-analyzer.js.map +1 -0
  226. package/dist/cjs/mirroring/stats/statistics-collector.d.ts +29 -0
  227. package/dist/cjs/mirroring/stats/statistics-collector.js +53 -0
  228. package/dist/cjs/mirroring/stats/statistics-collector.js.map +1 -0
  229. package/dist/cjs/mirroring/stats/statistics-common.d.ts +61 -0
  230. package/dist/cjs/mirroring/stats/statistics-common.js +45 -0
  231. package/dist/cjs/mirroring/stats/statistics-common.js.map +1 -0
  232. package/dist/cjs/mirroring/stats/statistics-dispatcher.d.ts +28 -0
  233. package/dist/cjs/mirroring/stats/statistics-dispatcher.js +104 -0
  234. package/dist/cjs/mirroring/stats/statistics-dispatcher.js.map +1 -0
  235. package/dist/cjs/mirroring/stats/statistics.d.ts +84 -0
  236. package/dist/cjs/mirroring/stats/statistics.js +147 -0
  237. package/dist/cjs/mirroring/stats/statistics.js.map +1 -0
  238. package/dist/cjs/mirroring/transport/udp-environment.d.ts +40 -0
  239. package/dist/cjs/mirroring/transport/udp-environment.js +97 -0
  240. package/dist/cjs/mirroring/transport/udp-environment.js.map +1 -0
  241. package/dist/cjs/polyfill/bridge-types.d.ts +11 -0
  242. package/dist/cjs/polyfill/presentation-receiver.d.ts +12 -0
  243. package/dist/cjs/polyfill/presentation-receiver.js +369 -0
  244. package/dist/cjs/polyfill/presentation-receiver.js.map +1 -0
  245. package/dist/cjs/polyfill/presentation-standin.js +157 -15
  246. package/dist/cjs/polyfill/presentation-standin.js.map +1 -1
  247. package/dist/cjs/protocol/framing.d.ts +1 -1
  248. package/dist/cjs/protocol/framing.js +1 -1
  249. package/dist/cjs/protocol/framing.js.map +1 -1
  250. package/dist/cli.d.ts +2 -0
  251. package/dist/cli.js +56 -0
  252. package/dist/cli.js.map +1 -0
  253. package/dist/client/auth/build-time.js +1 -1
  254. package/dist/client/auth/cast-auth.d.ts +2 -0
  255. package/dist/client/auth/cast-auth.js.map +1 -1
  256. package/dist/dial/dial-registry.d.ts +104 -0
  257. package/dist/dial/dial-registry.js +297 -0
  258. package/dist/dial/dial-registry.js.map +1 -0
  259. package/dist/dial/dial-sink-service.d.ts +108 -0
  260. package/dist/dial/dial-sink-service.js +310 -0
  261. package/dist/dial/dial-sink-service.js.map +1 -0
  262. package/dist/dial/http.d.ts +40 -0
  263. package/dist/dial/http.js +165 -0
  264. package/dist/dial/http.js.map +1 -0
  265. package/dist/dial/index.d.ts +63 -0
  266. package/dist/dial/index.js +115 -0
  267. package/dist/dial/index.js.map +1 -0
  268. package/dist/dial/origins.d.ts +4 -0
  269. package/dist/dial/origins.js +32 -0
  270. package/dist/dial/origins.js.map +1 -0
  271. package/dist/dial/parse.d.ts +101 -0
  272. package/dist/dial/parse.js +281 -0
  273. package/dist/dial/parse.js.map +1 -0
  274. package/dist/dial/route-provider.d.ts +96 -0
  275. package/dist/dial/route-provider.js +369 -0
  276. package/dist/dial/route-provider.js.map +1 -0
  277. package/dist/dial/ssdp-socket.d.ts +34 -0
  278. package/dist/dial/ssdp-socket.js +65 -0
  279. package/dist/dial/ssdp-socket.js.map +1 -0
  280. package/dist/dial/xml.d.ts +13 -0
  281. package/dist/dial/xml.js +204 -0
  282. package/dist/dial/xml.js.map +1 -0
  283. package/dist/dial-test/cli-main.d.ts +17 -0
  284. package/dist/dial-test/cli-main.js +130 -0
  285. package/dist/dial-test/cli-main.js.map +1 -0
  286. package/dist/dial-test/report.d.ts +55 -0
  287. package/dist/dial-test/report.js +77 -0
  288. package/dist/dial-test/report.js.map +1 -0
  289. package/dist/dial-test/runner.d.ts +42 -0
  290. package/dist/dial-test/runner.js +566 -0
  291. package/dist/dial-test/runner.js.map +1 -0
  292. package/dist/dial-test/scrub.d.ts +14 -0
  293. package/dist/dial-test/scrub.js +73 -0
  294. package/dist/dial-test/scrub.js.map +1 -0
  295. package/dist/discovery/cast-discovery.d.ts +2 -0
  296. package/dist/discovery/cast-discovery.js.map +1 -1
  297. package/dist/discovery/device-cache.d.ts +9 -0
  298. package/dist/discovery/device-cache.js.map +1 -1
  299. package/dist/discovery/index.d.ts +1 -0
  300. package/dist/discovery/index.js +1 -0
  301. package/dist/discovery/index.js.map +1 -1
  302. package/dist/discovery/ip-policy.d.ts +20 -0
  303. package/dist/discovery/ip-policy.js +103 -0
  304. package/dist/discovery/ip-policy.js.map +1 -0
  305. package/dist/discovery/udp-socket.d.ts +3 -0
  306. package/dist/discovery/udp-socket.js +3 -0
  307. package/dist/discovery/udp-socket.js.map +1 -1
  308. package/dist/electron/access-code.d.ts +221 -0
  309. package/dist/electron/access-code.js +577 -0
  310. package/dist/electron/access-code.js.map +1 -0
  311. package/dist/electron/app-discovery.d.ts +82 -0
  312. package/dist/electron/app-discovery.js +215 -0
  313. package/dist/electron/app-discovery.js.map +1 -0
  314. package/dist/electron/default-presentation.d.ts +38 -0
  315. package/dist/electron/default-presentation.js +83 -0
  316. package/dist/electron/default-presentation.js.map +1 -0
  317. package/dist/electron/main.d.ts +98 -11
  318. package/dist/electron/main.js +597 -21
  319. package/dist/electron/main.js.map +1 -1
  320. package/dist/electron/manager-api.d.ts +200 -18
  321. package/dist/electron/manager-api.js +196 -4
  322. package/dist/electron/manager-api.js.map +1 -1
  323. package/dist/electron/media-controller.d.ts +79 -0
  324. package/dist/electron/media-controller.js +248 -0
  325. package/dist/electron/media-controller.js.map +1 -0
  326. package/dist/electron/network-monitor.d.ts +61 -0
  327. package/dist/electron/network-monitor.js +117 -0
  328. package/dist/electron/network-monitor.js.map +1 -0
  329. package/dist/electron/preload.js.map +1 -1
  330. package/dist/electron/presentation-handler.d.ts +39 -4
  331. package/dist/electron/presentation-handler.js +192 -48
  332. package/dist/electron/presentation-handler.js.map +1 -1
  333. package/dist/electron/presentation-source.d.ts +76 -0
  334. package/dist/electron/presentation-source.js +125 -0
  335. package/dist/electron/presentation-source.js.map +1 -0
  336. package/dist/electron/session-service.d.ts +198 -24
  337. package/dist/electron/session-service.js +629 -248
  338. package/dist/electron/session-service.js.map +1 -1
  339. package/dist/electron/session-tracker.d.ts +82 -0
  340. package/dist/electron/session-tracker.js +219 -0
  341. package/dist/electron/session-tracker.js.map +1 -0
  342. package/dist/electron/sink-service.d.ts +246 -0
  343. package/dist/electron/sink-service.js +602 -0
  344. package/dist/electron/sink-service.js.map +1 -0
  345. package/dist/electron/wired-display/controller.d.ts +76 -0
  346. package/dist/electron/wired-display/controller.js +194 -0
  347. package/dist/electron/wired-display/controller.js.map +1 -0
  348. package/dist/electron/wired-display/displays.d.ts +44 -0
  349. package/dist/electron/wired-display/displays.js +91 -0
  350. package/dist/electron/wired-display/displays.js.map +1 -0
  351. package/dist/electron/wired-display/electron-windows.d.ts +111 -0
  352. package/dist/electron/wired-display/electron-windows.js +301 -0
  353. package/dist/electron/wired-display/electron-windows.js.map +1 -0
  354. package/dist/electron/wired-display/index.d.ts +90 -0
  355. package/dist/electron/wired-display/index.js +99 -0
  356. package/dist/electron/wired-display/index.js.map +1 -0
  357. package/dist/electron/wired-display/local-presentation.d.ts +98 -0
  358. package/dist/electron/wired-display/local-presentation.js +228 -0
  359. package/dist/electron/wired-display/local-presentation.js.map +1 -0
  360. package/dist/electron/wired-display/provider.d.ts +112 -0
  361. package/dist/electron/wired-display/provider.js +197 -0
  362. package/dist/electron/wired-display/provider.js.map +1 -0
  363. package/dist/index.d.ts +1 -0
  364. package/dist/index.js +1 -0
  365. package/dist/index.js.map +1 -1
  366. package/dist/mirroring/backend.d.ts +76 -0
  367. package/dist/mirroring/backend.js +18 -0
  368. package/dist/mirroring/backend.js.map +1 -0
  369. package/dist/mirroring/electron/agent-protocol.d.ts +158 -0
  370. package/dist/mirroring/electron/agent-protocol.js +10 -0
  371. package/dist/mirroring/electron/agent-protocol.js.map +1 -0
  372. package/dist/mirroring/electron/agent-source.d.ts +20 -0
  373. package/dist/mirroring/electron/agent-source.js +618 -0
  374. package/dist/mirroring/electron/agent-source.js.map +1 -0
  375. package/dist/mirroring/electron/engine-process.d.ts +87 -0
  376. package/dist/mirroring/electron/engine-process.js +78 -0
  377. package/dist/mirroring/electron/engine-process.js.map +1 -0
  378. package/dist/mirroring/electron/host.d.ts +89 -0
  379. package/dist/mirroring/electron/host.js +318 -0
  380. package/dist/mirroring/electron/host.js.map +1 -0
  381. package/dist/mirroring/electron/port-backend.d.ts +107 -0
  382. package/dist/mirroring/electron/port-backend.js +441 -0
  383. package/dist/mirroring/electron/port-backend.js.map +1 -0
  384. package/dist/mirroring/encoding-support.d.ts +66 -0
  385. package/dist/mirroring/encoding-support.js +81 -0
  386. package/dist/mirroring/encoding-support.js.map +1 -0
  387. package/dist/mirroring/engine.d.ts +16 -0
  388. package/dist/mirroring/engine.js +75 -0
  389. package/dist/mirroring/engine.js.map +1 -0
  390. package/dist/mirroring/mirror-settings.d.ts +101 -0
  391. package/dist/mirroring/mirror-settings.js +134 -0
  392. package/dist/mirroring/mirror-settings.js.map +1 -0
  393. package/dist/mirroring/mirroring-activity.d.ts +207 -0
  394. package/dist/mirroring/mirroring-activity.js +362 -0
  395. package/dist/mirroring/mirroring-activity.js.map +1 -0
  396. package/dist/mirroring/mirroring-manager.d.ts +134 -0
  397. package/dist/mirroring/mirroring-manager.js +281 -0
  398. package/dist/mirroring/mirroring-manager.js.map +1 -0
  399. package/dist/mirroring/protocol/answer.d.ts +87 -0
  400. package/dist/mirroring/protocol/answer.js +226 -0
  401. package/dist/mirroring/protocol/answer.js.map +1 -0
  402. package/dist/mirroring/protocol/constants.d.ts +64 -0
  403. package/dist/mirroring/protocol/constants.js +66 -0
  404. package/dist/mirroring/protocol/constants.js.map +1 -0
  405. package/dist/mirroring/protocol/errors.d.ts +25 -0
  406. package/dist/mirroring/protocol/errors.js +29 -0
  407. package/dist/mirroring/protocol/errors.js.map +1 -0
  408. package/dist/mirroring/protocol/frame-id.d.ts +9 -0
  409. package/dist/mirroring/protocol/frame-id.js +20 -0
  410. package/dist/mirroring/protocol/frame-id.js.map +1 -0
  411. package/dist/mirroring/protocol/messenger.d.ts +42 -0
  412. package/dist/mirroring/protocol/messenger.js +118 -0
  413. package/dist/mirroring/protocol/messenger.js.map +1 -0
  414. package/dist/mirroring/protocol/offer.d.ts +109 -0
  415. package/dist/mirroring/protocol/offer.js +176 -0
  416. package/dist/mirroring/protocol/offer.js.map +1 -0
  417. package/dist/mirroring/protocol/recommendations.d.ts +28 -0
  418. package/dist/mirroring/protocol/recommendations.js +99 -0
  419. package/dist/mirroring/protocol/recommendations.js.map +1 -0
  420. package/dist/mirroring/routing.d.ts +60 -0
  421. package/dist/mirroring/routing.js +130 -0
  422. package/dist/mirroring/routing.js.map +1 -0
  423. package/dist/mirroring/rtcp/ntp.d.ts +27 -0
  424. package/dist/mirroring/rtcp/ntp.js +57 -0
  425. package/dist/mirroring/rtcp/ntp.js.map +1 -0
  426. package/dist/mirroring/rtcp/parser.d.ts +50 -0
  427. package/dist/mirroring/rtcp/parser.js +265 -0
  428. package/dist/mirroring/rtcp/parser.js.map +1 -0
  429. package/dist/mirroring/rtcp/sender-report.d.ts +32 -0
  430. package/dist/mirroring/rtcp/sender-report.js +51 -0
  431. package/dist/mirroring/rtcp/sender-report.js.map +1 -0
  432. package/dist/mirroring/rtcp/wire.d.ts +54 -0
  433. package/dist/mirroring/rtcp/wire.js +68 -0
  434. package/dist/mirroring/rtcp/wire.js.map +1 -0
  435. package/dist/mirroring/rtp/frame-crypto.d.ts +11 -0
  436. package/dist/mirroring/rtp/frame-crypto.js +35 -0
  437. package/dist/mirroring/rtp/frame-crypto.js.map +1 -0
  438. package/dist/mirroring/rtp/frame.d.ts +23 -0
  439. package/dist/mirroring/rtp/frame.js +2 -0
  440. package/dist/mirroring/rtp/frame.js.map +1 -0
  441. package/dist/mirroring/rtp/packetizer.d.ts +27 -0
  442. package/dist/mirroring/rtp/packetizer.js +88 -0
  443. package/dist/mirroring/rtp/packetizer.js.map +1 -0
  444. package/dist/mirroring/sender/audio-sender.d.ts +23 -0
  445. package/dist/mirroring/sender/audio-sender.js +54 -0
  446. package/dist/mirroring/sender/audio-sender.js.map +1 -0
  447. package/dist/mirroring/sender/bandwidth-estimator.d.ts +26 -0
  448. package/dist/mirroring/sender/bandwidth-estimator.js +103 -0
  449. package/dist/mirroring/sender/bandwidth-estimator.js.map +1 -0
  450. package/dist/mirroring/sender/capture-size-oracle.d.ts +121 -0
  451. package/dist/mirroring/sender/capture-size-oracle.js +433 -0
  452. package/dist/mirroring/sender/capture-size-oracle.js.map +1 -0
  453. package/dist/mirroring/sender/frame-sender.d.ts +103 -0
  454. package/dist/mirroring/sender/frame-sender.js +212 -0
  455. package/dist/mirroring/sender/frame-sender.js.map +1 -0
  456. package/dist/mirroring/sender/packet-router.d.ts +74 -0
  457. package/dist/mirroring/sender/packet-router.js +191 -0
  458. package/dist/mirroring/sender/packet-router.js.map +1 -0
  459. package/dist/mirroring/sender/sender-session.d.ts +85 -0
  460. package/dist/mirroring/sender/sender-session.js +235 -0
  461. package/dist/mirroring/sender/sender-session.js.map +1 -0
  462. package/dist/mirroring/sender/sender.d.ts +120 -0
  463. package/dist/mirroring/sender/sender.js +452 -0
  464. package/dist/mirroring/sender/sender.js.map +1 -0
  465. package/dist/mirroring/sender/video-encoder-metrics.d.ts +29 -0
  466. package/dist/mirroring/sender/video-encoder-metrics.js +58 -0
  467. package/dist/mirroring/sender/video-encoder-metrics.js.map +1 -0
  468. package/dist/mirroring/sender/video-sender.d.ts +95 -0
  469. package/dist/mirroring/sender/video-sender.js +190 -0
  470. package/dist/mirroring/sender/video-sender.js.map +1 -0
  471. package/dist/mirroring/session-host.d.ts +185 -0
  472. package/dist/mirroring/session-host.js +625 -0
  473. package/dist/mirroring/session-host.js.map +1 -0
  474. package/dist/mirroring/stats/clock-offset-estimator.d.ts +11 -0
  475. package/dist/mirroring/stats/clock-offset-estimator.js +120 -0
  476. package/dist/mirroring/stats/clock-offset-estimator.js.map +1 -0
  477. package/dist/mirroring/stats/openscreen-stats-client.d.ts +12 -0
  478. package/dist/mirroring/stats/openscreen-stats-client.js +17 -0
  479. package/dist/mirroring/stats/openscreen-stats-client.js.map +1 -0
  480. package/dist/mirroring/stats/sorted-map.d.ts +23 -0
  481. package/dist/mirroring/stats/sorted-map.js +66 -0
  482. package/dist/mirroring/stats/sorted-map.js.map +1 -0
  483. package/dist/mirroring/stats/statistics-analyzer.d.ts +50 -0
  484. package/dist/mirroring/stats/statistics-analyzer.js +335 -0
  485. package/dist/mirroring/stats/statistics-analyzer.js.map +1 -0
  486. package/dist/mirroring/stats/statistics-collector.d.ts +29 -0
  487. package/dist/mirroring/stats/statistics-collector.js +49 -0
  488. package/dist/mirroring/stats/statistics-collector.js.map +1 -0
  489. package/dist/mirroring/stats/statistics-common.d.ts +61 -0
  490. package/dist/mirroring/stats/statistics-common.js +39 -0
  491. package/dist/mirroring/stats/statistics-common.js.map +1 -0
  492. package/dist/mirroring/stats/statistics-dispatcher.d.ts +28 -0
  493. package/dist/mirroring/stats/statistics-dispatcher.js +100 -0
  494. package/dist/mirroring/stats/statistics-dispatcher.js.map +1 -0
  495. package/dist/mirroring/stats/statistics.d.ts +84 -0
  496. package/dist/mirroring/stats/statistics.js +141 -0
  497. package/dist/mirroring/stats/statistics.js.map +1 -0
  498. package/dist/mirroring/transport/udp-environment.d.ts +40 -0
  499. package/dist/mirroring/transport/udp-environment.js +93 -0
  500. package/dist/mirroring/transport/udp-environment.js.map +1 -0
  501. package/dist/polyfill/bridge-types.d.ts +11 -0
  502. package/dist/polyfill/presentation-receiver.d.ts +12 -0
  503. package/dist/polyfill/presentation-receiver.js +366 -0
  504. package/dist/polyfill/presentation-receiver.js.map +1 -0
  505. package/dist/polyfill/presentation-standin.js +157 -15
  506. package/dist/polyfill/presentation-standin.js.map +1 -1
  507. package/dist/protocol/framing.d.ts +1 -1
  508. package/dist/protocol/framing.js +1 -1
  509. package/dist/protocol/framing.js.map +1 -1
  510. package/docs/API.md +724 -0
  511. package/docs/ARCHITECTURE.md +242 -0
  512. package/docs/CHROMIUM-MAP.md +176 -0
  513. package/docs/DESIGN.md +1189 -0
  514. package/docs/FAQ.md +123 -0
  515. package/docs/GETTING-STARTED.md +248 -0
  516. package/docs/MAIN-API.md +524 -0
  517. package/docs/TROUBLESHOOTING.md +283 -0
  518. package/docs/guides/audio-and-groups.md +75 -0
  519. package/docs/guides/custom-receivers.md +109 -0
  520. package/docs/guides/device-authentication.md +145 -0
  521. package/docs/guides/device-picker.md +176 -0
  522. package/docs/guides/index.md +17 -0
  523. package/docs/guides/low-level-client.md +103 -0
  524. package/docs/guides/restart-rejoin.md +172 -0
  525. package/docs/guides/testing.md +162 -0
  526. package/docs/guides/windows-and-iframes.md +116 -0
  527. package/docs/readme/badges/dependencies.svg +1 -0
  528. package/docs/readme/badges/electron.svg +1 -0
  529. package/docs/readme/badges/license.svg +1 -0
  530. package/docs/readme/badges/node.svg +1 -0
  531. package/docs/readme/board.jpg +0 -0
  532. package/docs/readme/hero-dark.jpg +0 -0
  533. package/docs/readme/hero-light.jpg +0 -0
  534. package/docs/readme/nosignal.jpg +0 -0
  535. package/docs/readme/parity.jpg +0 -0
  536. package/docs/readme/trace.svg +22 -0
  537. package/package.json +21 -5
  538. package/src/cli.ts +57 -0
  539. package/src/client/auth/cast-auth.ts +2 -0
  540. package/src/dial/dial-registry.ts +316 -0
  541. package/src/dial/dial-sink-service.ts +343 -0
  542. package/src/dial/http.ts +200 -0
  543. package/src/dial/index.ts +135 -0
  544. package/src/dial/origins.ts +31 -0
  545. package/src/dial/parse.ts +319 -0
  546. package/src/dial/route-provider.ts +429 -0
  547. package/src/dial/ssdp-socket.ts +79 -0
  548. package/src/dial/xml.ts +180 -0
  549. package/src/dial-test/cli-main.ts +146 -0
  550. package/src/dial-test/report.ts +109 -0
  551. package/src/dial-test/runner.ts +615 -0
  552. package/src/dial-test/scrub.ts +74 -0
  553. package/src/discovery/cast-discovery.ts +2 -0
  554. package/src/discovery/device-cache.ts +5 -0
  555. package/src/discovery/index.ts +1 -0
  556. package/src/discovery/ip-policy.ts +97 -0
  557. package/src/discovery/udp-socket.ts +3 -0
  558. package/src/electron/access-code.ts +681 -0
  559. package/src/electron/app-discovery.ts +244 -0
  560. package/src/electron/default-presentation.ts +104 -0
  561. package/src/electron/main.ts +664 -29
  562. package/src/electron/manager-api.ts +367 -15
  563. package/src/electron/media-controller.ts +313 -0
  564. package/src/electron/network-monitor.ts +140 -0
  565. package/src/electron/preload.ts +1 -1
  566. package/src/electron/presentation-handler.ts +195 -48
  567. package/src/electron/presentation-source.ts +155 -0
  568. package/src/electron/session-service.ts +693 -238
  569. package/src/electron/session-tracker.ts +248 -0
  570. package/src/electron/sink-service.ts +726 -0
  571. package/src/electron/wired-display/controller.ts +212 -0
  572. package/src/electron/wired-display/displays.ts +107 -0
  573. package/src/electron/wired-display/electron-windows.ts +386 -0
  574. package/src/electron/wired-display/index.ts +181 -0
  575. package/src/electron/wired-display/local-presentation.ts +286 -0
  576. package/src/electron/wired-display/provider.ts +276 -0
  577. package/src/index.ts +1 -0
  578. package/src/mirroring/backend.ts +103 -0
  579. package/src/mirroring/electron/agent-protocol.ts +84 -0
  580. package/src/mirroring/electron/agent-source.ts +619 -0
  581. package/src/mirroring/electron/engine-process.ts +131 -0
  582. package/src/mirroring/electron/host.ts +361 -0
  583. package/src/mirroring/electron/port-backend.ts +466 -0
  584. package/src/mirroring/encoding-support.ts +146 -0
  585. package/src/mirroring/engine.ts +91 -0
  586. package/src/mirroring/mirror-settings.ts +174 -0
  587. package/src/mirroring/mirroring-activity.ts +466 -0
  588. package/src/mirroring/mirroring-manager.ts +342 -0
  589. package/src/mirroring/protocol/answer.ts +285 -0
  590. package/src/mirroring/protocol/constants.ts +75 -0
  591. package/src/mirroring/protocol/errors.ts +36 -0
  592. package/src/mirroring/protocol/frame-id.ts +20 -0
  593. package/src/mirroring/protocol/messenger.ts +128 -0
  594. package/src/mirroring/protocol/offer.ts +275 -0
  595. package/src/mirroring/protocol/recommendations.ts +135 -0
  596. package/src/mirroring/routing.ts +160 -0
  597. package/src/mirroring/rtcp/ntp.ts +61 -0
  598. package/src/mirroring/rtcp/parser.ts +292 -0
  599. package/src/mirroring/rtcp/sender-report.ts +88 -0
  600. package/src/mirroring/rtcp/wire.ts +76 -0
  601. package/src/mirroring/rtp/frame-crypto.ts +38 -0
  602. package/src/mirroring/rtp/frame.ts +25 -0
  603. package/src/mirroring/rtp/packetizer.ts +95 -0
  604. package/src/mirroring/sender/audio-sender.ts +59 -0
  605. package/src/mirroring/sender/bandwidth-estimator.ts +111 -0
  606. package/src/mirroring/sender/capture-size-oracle.ts +476 -0
  607. package/src/mirroring/sender/frame-sender.ts +293 -0
  608. package/src/mirroring/sender/packet-router.ts +228 -0
  609. package/src/mirroring/sender/sender-session.ts +306 -0
  610. package/src/mirroring/sender/sender.ts +497 -0
  611. package/src/mirroring/sender/video-encoder-metrics.ts +64 -0
  612. package/src/mirroring/sender/video-sender.ts +243 -0
  613. package/src/mirroring/session-host.ts +725 -0
  614. package/src/mirroring/stats/clock-offset-estimator.ts +139 -0
  615. package/src/mirroring/stats/openscreen-stats-client.ts +19 -0
  616. package/src/mirroring/stats/sorted-map.ts +68 -0
  617. package/src/mirroring/stats/statistics-analyzer.ts +388 -0
  618. package/src/mirroring/stats/statistics-collector.ts +69 -0
  619. package/src/mirroring/stats/statistics-common.ts +112 -0
  620. package/src/mirroring/stats/statistics-dispatcher.ts +133 -0
  621. package/src/mirroring/stats/statistics.ts +170 -0
  622. package/src/mirroring/transport/udp-environment.ts +100 -0
  623. package/src/polyfill/bridge-types.ts +11 -0
  624. package/src/polyfill/presentation-receiver.ts +350 -0
  625. package/src/polyfill/presentation-standin.ts +147 -15
  626. package/src/protocol/framing.ts +1 -1
@@ -0,0 +1,524 @@
1
+ # Main-process API
2
+
3
+ `createCastManager` returns a `CastManager`: `start()`, `devices()`, `discoverSinksNow()`, `settled()`, `dispose()`, `addSinkByAddress()` (see [Adding a device by address](#adding-a-device-by-address)) and the API below, which lets the
4
+ app observe and control casting from the main process. It follows Chrome's Media Router, so the same concepts and
5
+ method names apply: devices are **sinks**, running sessions are **routes**, and you watch both with **observers**.
6
+
7
+ This API does not touch the preload's `mode: "chromecast"`; it works for both modes, because both end in the same
8
+ session service.
9
+
10
+ Media control, casting from the app's own UI, wired displays, adding a device by address and tab and desktop mirroring
11
+ are new in 0.5. Until 0.5.0 is released they are in the `next` prerelease: `npm i electron-cast@next`.
12
+
13
+ ## Mapping to Chrome
14
+
15
+ Checked against Chromium `main` (November 2026). Paths are relative to the Chromium source root.
16
+
17
+ | electron-cast | Chrome | Chromium source |
18
+ |---|---|---|
19
+ | `registerMediaSinksObserver(observer, query?)` | `MediaSinksObserver` (constructed with a `MediaSource` and an origin, or for all sinks; `Init()` registers it) and its `OnSinksUpdated(sinks, origins)`. `MediaRouter::RegisterMediaSinksObserver` is private to the observer class | `components/media_router/browser/media_router.h`, `components/media_router/browser/media_sinks_observer.h` |
20
+ | `MediaSink` | `media_router::MediaSink`: `id`, `name`, `icon_type`, `provider_id` (no description) | `components/media_router/common/media_sink.h` |
21
+ | `MediaSink.iconType` | `GetCastSinkIconType`: `video_out` gives `CAST`, else a multizone group gives `CAST_AUDIO_GROUP`, else `CAST_AUDIO` | `chrome/browser/media/router/discovery/mdns/media_sink_util.cc` |
22
+ | `registerMediaRoutesObserver(observer)` | `MediaRoutesObserver` (constructed with the router) and `OnRoutesUpdated(routes)`; `MediaRouter::RegisterMediaRoutesObserver` is private to it | `components/media_router/browser/media_routes_observer.h` |
23
+ | `MediaRoute` (`mediaSource`, `sinkId`, `description`) | `media_router::MediaRoute` (`media_source`, `media_sink_id`, `description`; the id is `media_route_id`) | `components/media_router/common/media_route.h`, `media_route.cc` |
24
+ | `MediaRoute.description` | `CastSession::GetRouteDescription`: the status text, else the display name | `chrome/browser/media/router/providers/cast/cast_internal_message_util.cc` |
25
+ | `terminateRoute(id)` | `MediaRouter::TerminateRoute`, called by the Cast dialog's stop (`MediaRouterUI::StopCasting`) and by the global media controls' `CastMediaNotificationItem::StopCasting`; `CastActivityManager::TerminateSession` stops the receiver app | `media_router.h`, `chrome/browser/ui/media_router/media_router_ui.cc`, `chrome/browser/ui/global_media_controls/cast_media_notification_item.cc`, `chrome/browser/media/router/providers/cast/cast_activity_manager.cc` |
26
+ | `detachRoute(id)` | `MediaRouter::DetachRoute` exists, but the Cast provider does not implement it (`CastMediaRouteProvider::DetachRoute` is `NOTIMPLEMENTED`): a page lets go through its Presentation connection closing (`CastSessionClientImpl::DidClose`). No counterpart for "every page lets go" | `media_router.h`, `chrome/browser/media/router/providers/cast/cast_media_route_provider.cc`, `cast_session_client_impl.cc` |
27
+ | `getRouteController(id).setVolume / setMute` | `MediaRouter::GetMediaController` binds a `mojom::MediaController` (`SetVolume`, `SetMute`); on a Cast route `CastMediaController` sends a receiver `SET_VOLUME` request. Used by the global media controls (`CastMediaNotificationItem::SetVolume / SetMute`, controller bound in `cast_media_notification_producer.cc`), not by the Cast dialog. There is no class named `MediaRouteController` in current Chromium | `components/media_router/common/mojom/media_controller.mojom`, `chrome/browser/media/router/providers/cast/cast_media_controller.cc`, `app_activity.cc`, `chrome/browser/ui/global_media_controls/` |
28
+ | `hasDefaultPresentationRequest(webContentsId)`, `getDefaultPresentationRequest(webContentsId)`, `addPresentationObserver(webContentsId, observer)` | `WebContentsPresentationManager` (`HasDefaultPresentationRequest`, `GetDefaultPresentationRequest`, `AddObserver`; implemented by `ControllerPresentationServiceDelegateImpl`, one per `WebContents`), `content::PresentationObserver::OnDefaultPresentationChanged`, `content::PresentationRequest` (`render_frame_host_id`, `presentation_urls`, `frame_origin`) | `components/media_router/browser/presentation/web_contents_presentation_manager.h`, `controller_presentation_service_delegate_impl.cc`, `content/public/browser/presentation_request.h` |
29
+ | `startCasting(sinkId, { webContentsId, castMode: "presentation" })` | `MediaRouterUI::StartCasting(sink_id, MediaCastMode::PRESENTATION)`, then `MediaRouteStarter::CreateRouteParameters` (the source for the sink comes from the default request's URLs; none gives an "unable to cast" issue), `StartRoute` (`MediaRouter::CreateRoute`, with `WebContentsPresentationManager::OnPresentationResponse` as the response callback) and `OnPresentationResponse`, which adds the presentation and runs the default-presentation callback; `RouteRequestResultCode` is the error set | `chrome/browser/ui/media_router/media_router_ui.cc`, `media_route_starter.cc`, `components/media_router/common/mojom/route_request_result_code.mojom` |
30
+ | `getMediaController(id, observer?)` | `MediaRouter::GetMediaController`: binds a `mojom::MediaController` (`Play`, `Pause`, `SetMute`, `SetVolume`, `Seek`, `NextTrack`, `PreviousTrack`) and a `mojom::MediaStatusObserver` (`OnMediaStatusUpdated(MediaStatus)`). `CastMediaController` builds the status from the receiver volume (`SetSession`) and MEDIA_STATUS messages (`SetMediaStatus`, `UpdateMediaStatus`), which `CastSessionTracker::HandleMediaStatusMessage` first completes from the media it saved | `components/media_router/common/mojom/media_controller.mojom`, `media_status.mojom`, `chrome/browser/media/router/providers/cast/cast_media_controller.cc`, `app_activity.cc`, `cast_session_tracker.cc` |
31
+ | `selectDevice`'s third argument | `QueryResultManager` (owns the sinks observers the dialog's `MediaRouteStarter` / `MediaRouterUI` uses while open) | `chrome/browser/ui/media_router/query_result_manager.cc` |
32
+ | `addSinkByAddress`, `configureAccessCode`, network changes (the `networkMonitor` option) | `AccessCodeCastSinkService` after the discovery server has answered (`OnAccessCodeValidated`, `OnEnabledPrefChange`, `OnNetworksChanged`) | `chrome/browser/media/router/discovery/access_code/access_code_cast_sink_service.cc`; see [DESIGN.md](DESIGN.md#access-code-casting-access-codets) |
33
+ | Sinks listed only once a channel is open and authenticated, with retry and removal; the session tracker; non-local routes | `CastMediaSinkServiceImpl`, `MediaSinkServiceBase`, `CastSessionTracker`, `CastActivityManager::AddNonLocalActivity` | see [DESIGN.md](DESIGN.md#sinks-and-sessions-sink-servicets-session-trackerts) for each rule and its source |
34
+ | the Cast provider behind routes | `CastMediaRouteProvider`, `CastActivityManager`, `AppActivity` | `chrome/browser/media/router/providers/cast/` |
35
+
36
+ Where electron-cast differs from Chrome:
37
+
38
+ - Observers get the full list straight away on registration, then after each change, as Chrome's observers do once
39
+ the router has a list. A sinks observer is only called when its (filtered) list actually changed.
40
+ - Chrome's sinks observer is scoped by a `MediaSource` and origin; here `query.capabilities` filters instead. Chrome's
41
+ `MediaSink` has no description; `description` here is the device model (Chrome keeps it in
42
+ `CastSinkExtraData::model_name`, not on the sink).
43
+ - Registration returns the unregister function; Chrome unregisters when the observer object is destroyed.
44
+ - `terminateRoute`, `setVolume` and `setMute` return promises and reject with `MediaRouteError` (`code`:
45
+ `route_not_found` or a bridge code such as `session_error`); `setVolume` rejects with `RangeError` for a level outside
46
+ 0 to 1 and `setMute` with `TypeError` for a non-boolean. `detachRoute` and `getRouteController` are synchronous and
47
+ throw `MediaRouteError` `route_not_found` for an unknown route. Chrome's are fire-and-forget.
48
+ - A route's id is the Cast session id. Chrome's `media_route_id` is `urn:x-org.chromium:media:route:<presentation id>/<sink id>/<source id>`
49
+ (`MediaRoute::GetMediaRouteId`).
50
+ - `MediaRoute` also carries `appId`, `displayName`, `sinkName`, `isLocal`, `origin`, `volume`, `members` (`webContents.id`s, once each however
51
+ many of a window's frames hold the route), `parkedSenders` and `parked`, because in an Electron app main wants to
52
+ know which windows hold a route. A route is `parked` when its pages navigated away (a reload, say) and none is
53
+ attached; it stays on the device so the next page can rejoin (see CHANGELOG 0.3.1).
54
+ - `detachRoute` has no Chrome counterpart (see the table). It is electron-cast's own.
55
+ - Volume matches Chrome: both send the receiver's `SET_VOLUME` (`level` or `muted`), the volume of the device, not of
56
+ a media session; the route's `volume` shows what the device last reported. Chrome additionally ignores the call
57
+ when the route has no session yet (every route here has one). The rest of Chrome's controller is
58
+ [`getMediaController`](#media-control).
59
+
60
+ ## Sinks
61
+
62
+ <!-- no-check -->
63
+ ```ts
64
+ import { createCastManager, type MediaSink } from "electron-cast/main";
65
+
66
+ const manager = createCastManager({ ipcMain, selectDevice });
67
+ await manager.start();
68
+
69
+ const stop = manager.registerMediaSinksObserver({
70
+ onSinksUpdated(sinks: MediaSink[]) {
71
+ // called now with the current devices, then whenever one appears, changes or goes
72
+ tray.setDevices(sinks.map((s) => s.name));
73
+ },
74
+ }, { capabilities: ["video_out"] }); // optional, same names as requestSession's
75
+ // stop() unregisters
76
+ ```
77
+
78
+ A `MediaSink` is `{ id, providerId: "cast" | "dial", name, description (the model), iconType: "cast" | "cast_audio" | "cast_audio_group" | "generic", device }`
79
+ where `device` is the discovered `CastDevice`. A DIAL sink (`providerId: "dial"`, id `dial:<uuid>`, icon `generic`, as
80
+ `DialMediaSinkServiceImpl` creates it) has `device.dial` set. A device that both mDNS and SSDP found is reported once,
81
+ as the Cast sink (`CastMediaSinkServiceImpl::TryConnectDialDiscoveredSink`). DIAL sinks have no capabilities, so a
82
+ `capabilities` query never lists them; `manager.devices()` stays the Cast devices.
83
+
84
+ A device is a sink only once electron-cast has opened a channel to it and it has passed device authentication, as in
85
+ Chrome. Channels open after discovery with a random delay of up to 5 s, so right after `start()` the list is empty for
86
+ a moment; a failed attempt is retried (15 s, 3 attempts), and a device that never opens is never listed. The list is
87
+ reported once it has been quiet for 3 s. A device that mDNS stops reporting stays listed while its channel is up; it
88
+ goes when the channel fails and cannot be reopened (a ping every 5 s notices within 10 s). `manager.devices()` and
89
+ `selectDevice`'s list are these sinks. `manager.discoverSinksNow()` skips the delay, and `createCastManager({ sinks })`
90
+ tunes the numbers (see [API.md](API.md#castmanageroptions)); `sinks.allowAllIps` lets it reach public and loopback
91
+ addresses, which Chrome refuses by default.
92
+
93
+ ## Routes
94
+
95
+ <!-- no-check -->
96
+ ```ts
97
+ manager.registerMediaRoutesObserver({
98
+ onRoutesUpdated(routes) {
99
+ // now, then when a route starts, ends, or its status, volume or pages change
100
+ },
101
+ });
102
+
103
+ manager.getRoutes(); // the current list: local, parked and non-local routes
104
+ await manager.terminateRoute(routeId); // stop the app on the device
105
+ manager.detachRoute(routeId); // let go, leave the app running
106
+ const controller = manager.getRouteController(routeId);
107
+ await controller.setVolume(0.4); // 0 to 1
108
+ await controller.setMute(true);
109
+ ```
110
+
111
+ A device that runs a session no page of this app holds (started by another sender, or by this app before it restarted)
112
+ has a route too, as in Chrome (`AddNonLocalActivity`): `isLocal` is `false`, `members` and `origin` are empty, and
113
+ `sinkName` names the device. It follows the device's receiver status, goes when the app stops, and can be
114
+ terminated and have its volume set (while its channel is down, because the device is being reopened, terminating fails with `session_error` "StopSession response is not OK. Failed to terminate route." and the route stays, as in Chrome); `detachRoute` on it does nothing. A route a page held, once every page has let go
115
+ of it without stopping the app, becomes a non-local route. `isLocal` is `true` for the routes of this app's pages.
116
+
117
+ A DIAL route (`providerId: "dial"`) is the route of a `cast-dial:` presentation. Its `id` is Chrome's
118
+ `urn:x-org.chromium:media:route:<presentation id>/<sink id>/<source>`, `mediaSource` the `cast-dial:` source, `appId` is `""`
119
+ and `description` and `displayName` the app name, and `isLocal` is `true`. It has no volume and no media control:
120
+ `getRouteController(id).setVolume()` rejects and `getMediaController(id)` throws `MediaRouteError` `route_not_found`, as
121
+ Chrome's DIAL provider does not implement `BindMediaController`. `terminateRoute` sends the `DELETE` that stops the app
122
+ (and tells the page's connection it ended); `detachRoute` ends the page's connections and leaves the app running, which
123
+ is also what a page closing its connection does (`DialMediaRouteProvider::DetachRoute` is not implemented in Chrome, so
124
+ nothing stops the app).
125
+
126
+ Control goes through the same `CastSessionService` code the page's calls use, so the page sees what it would see if
127
+ the change came from the device:
128
+
129
+ - `terminateRoute`: every page on the route gets `sessionEnded` (`stopped`); the Presentation connection of
130
+ presentation mode closes.
131
+ - `detachRoute`: every page gets `sessionEnded` (`disconnected`); the device keeps running the app.
132
+ - `setVolume` / `setMute`: the device reports its new volume, and the pages get `sessionUpdated`.
133
+
134
+ `dispose()` stops the observers (they are not called again) and closes the device connections; it does not stop the
135
+ apps running on the devices.
136
+
137
+ ## Media control
138
+
139
+ <!-- no-check -->
140
+ ```ts
141
+ const controller = manager.getMediaController(routeId, {
142
+ onMediaStatusUpdated(status) {
143
+ // title, secondaryTitle, playState (a MediaPlayState: "playing" | "paused" | "buffering"), currentTime,
144
+ // duration (seconds), volume, isMuted, canPlayPause, canSeek, canMute, canSetVolume, canSkipToNextTrack,
145
+ // canSkipToPreviousTrack, images (MediaImage[]: { url, size: { width, height } | null })
146
+ },
147
+ });
148
+ await controller.play();
149
+ await controller.pause();
150
+ await controller.seek(90); // seconds
151
+ await controller.nextTrack(); // QUEUE_UPDATE with jump 1, as Chrome does
152
+ await controller.setVolume(0.4); // the receiver's volume, as getRouteController
153
+ controller.close(); // stop the reports
154
+ ```
155
+
156
+ It is what Chrome offers for a Cast route (`CastMediaController`), sent over the device's open channel, so it is
157
+ available on every route electron-cast has, non-local ones included: Chrome binds a controller to any activity
158
+ (`CastActivityManager::BindMediaController`), and a session started elsewhere is an `AppActivity` too
159
+ (`AddNonLocalActivity`); for one, a virtual connection to its transport is opened first, as Chrome's message handler
160
+ does. (All routes here are app routes; Chrome's mirroring routes have a controller of their own, and there is no
161
+ mirroring here.) The status comes from the session tracker on that channel: the volume of every receiver status
162
+ (`SetSession`) and every MEDIA_STATUS the device sends, whoever started the media, merged with the fields saved from
163
+ earlier ones (`CastSessionTracker::HandleMediaStatusMessage`). Messages go out as Chrome writes them (`CreateMediaRequest`): `PLAY`, `PAUSE`,
164
+ `SEEK` with `currentTime`, `QUEUE_UPDATE` with `jump` 1 or -1, each with the `mediaSessionId` last seen in a
165
+ MEDIA_STATUS (-1 before any, which the receiver refuses, as for Chrome) and the `sessionId`. Binding asks the receiver
166
+ for its media status (`GET_STATUS`).
167
+
168
+ Observers are called as Chrome calls them: on every receiver status that has a volume and every MEDIA_STATUS, repeated
169
+ or not, and on binding (any controller's binding tells every observer of the route, as `SetSession` does).
170
+
171
+ Where it differs from Chrome:
172
+
173
+ - Commands return promises, resolved when the message is written, not when the receiver has acted. They reject with
174
+ `MediaRouteError` `route_not_found` once the route is gone. `seek` rejects with `RangeError` for a time that is not a
175
+ number of seconds from 0 up. `getMediaController` throws `MediaRouteError` for an unknown route.
176
+ - Times are seconds, not `TimeDelta`. `MediaStatus.images` keeps only `https` URLs, as Chrome does.
177
+ - electron-cast has one Cast sender id per device connection where Chrome gives the controller its own, so the
178
+ receiver's replies to a command also reach the route's pages. Request ids start at 2^30 so they cannot be mistaken
179
+ for the page SDK's.
180
+ - Chrome's controller is a mojo pipe that closes with its route; here, after the route ends the commands reject and the
181
+ observer is not called again.
182
+
183
+ ## A live device picker
184
+
185
+ `selectDevice(devices, request, picker)` gets the devices at request time and, as a third argument, a handle that
186
+ works like Chrome's dialog watching sinks while it is open. mDNS often needs a few seconds, so devices can appear
187
+ after the picker opens:
188
+
189
+ <!-- no-check -->
190
+ ```ts
191
+ selectDevice: (devices, request, picker) =>
192
+ new Promise((resolve) => {
193
+ const win = openPickerWindow(devices, resolve);
194
+ // only the devices that can serve this request, the same way `devices` was filtered
195
+ picker.registerMediaSinksObserver({ onSinksUpdated: (sinks) => win.setDevices(sinks.map((s) => s.device)) });
196
+ picker.signal.addEventListener("abort", () => win.close()); // answered, cancelled, page gone or disposed
197
+ }),
198
+ ```
199
+
200
+ The observer is called at once with the current list, and is dropped when `picker.signal` aborts. Existing pickers
201
+ with two parameters keep working; they just ignore the third. If no device matches when the page asks, the request
202
+ still fails with `receiver_unavailable` before the picker opens.
203
+
204
+ ## Casting from the app's own UI
205
+
206
+ In Chrome a page that wants to be castable from the browser's Cast dialog sets
207
+ `navigator.presentation.defaultRequest = new PresentationRequest(urls)`, and Google's Cast SDK listens for
208
+ `connectionavailable` on it. The dialog (opened from the toolbar or menu, not from the page) lists that request as its presentation
209
+ source, and when the user picks a device Chrome starts the presentation and fires `connectionavailable` on the default
210
+ request with the new connection; the SDK adopts the session. The app's own cast UI does the same here:
211
+
212
+ <!-- no-check -->
213
+ ```ts
214
+ const id = win.webContents.id;
215
+
216
+ // is the page castable from my UI? (has it set defaultRequest?)
217
+ manager.hasDefaultPresentationRequest(id);
218
+ manager.getDefaultPresentationRequest(id); // { webContentsId, presentationUrls, frameOrigin } or null
219
+ const off = manager.addPresentationObserver(id, {
220
+ onDefaultPresentationChanged(request) { menu.setCastEnabled(request !== null); },
221
+ });
222
+
223
+ // the devices that can run it, kept current (the dialog's sinks observers for its presentation source)
224
+ manager.registerMediaSinksObserver(
225
+ { onSinksUpdated: (sinks) => menu.setDevices(sinks) },
226
+ {
227
+ presentationUrls: manager.getDefaultPresentationRequest(id)?.presentationUrls ?? [],
228
+ origin: manager.getDefaultPresentationRequest(id)?.frameOrigin,
229
+ },
230
+ );
231
+
232
+ // the user picked a device in my menu
233
+ try {
234
+ const route = await manager.startCasting(sink.id, { webContentsId: id }); // the page's connectionavailable fires
235
+ } catch (err) {
236
+ if (err instanceof MediaRouteError) showCastError(err.code, err.message);
237
+ }
238
+ ```
239
+
240
+ What happens, with Chrome's counterparts:
241
+
242
+ 1. **The page sets `defaultRequest`.** Blink's `Presentation::setDefaultRequest` sends the request's URLs (none for
243
+ `null`) to the browser on every set, and the stand-in does the same. `PresentationServiceImpl::SetDefaultPresentationUrls`
244
+ ignores a frame that is not the outermost document and a list equal to the current one, then hands the request to
245
+ `ControllerPresentationServiceDelegateImpl::SetDefaultPresentationUrls`, which keeps one default request per
246
+ `WebContents` and tells its observers. electron-cast keeps one per window, from its main frame only (an iframe's
247
+ `defaultRequest` is not reported to the app, as in Chrome), keyed by `webContents.id`.
248
+ 2. **It is cleared** when the page sets `null` (or a request with no URLs), navigates to another document
249
+ (`PresentationServiceImpl::DidFinishNavigation` → `Reset` → `ClearDefaultPresentationRequest`; a same-document
250
+ navigation keeps it) or goes away. Observers then get `null`.
251
+ 3. **`startCasting(sinkId, { webContentsId })`** is `MediaRouterUI::StartCasting(sink_id, PRESENTATION)`.
252
+ `MediaRouteStarter::CreateRouteParameters` needs a presentation source for the sink: the first of the request's URLs
253
+ the sink can run (`QueryResultManager::GetSourceForCastModeAndSink`): a Cast app URL for a Cast sink, a `cast-dial:`
254
+ URL for a DIAL sink (`MediaRouteStarter::OnDefaultPresentationChanged` makes a source of every URL, and the DIAL
255
+ provider serves the `cast-dial:` ones). With no default request, an unknown sink, or no
256
+ URL the sink suits (a Cast URL that is not one, or capabilities the sink lacks), Chrome shows an "unable to cast"
257
+ issue and starts nothing; here the promise rejects with `unable_to_cast`. Otherwise `MediaRouter::CreateRoute` runs,
258
+ here a launch on the sink with no picker. The session is a route like any other: routes observers see it, and it is
259
+ owned by the window's main frame.
260
+ 4. **`WebContentsPresentationManager::OnPresentationResponse`** adds the presentation, and only when the default
261
+ request is still the one that was started (`ArePresentationRequestsEqual`) does it run the default-presentation
262
+ callback: `PresentationServiceImpl::OnDefaultPresentationStarted` →
263
+ `PresentationController::OnDefaultPresentationStarted` → `ControllerPresentationConnection::Create`, which
264
+ enqueues `connectionavailable` on the page's current `defaultRequest` (and does nothing if it is null). The stand-in
265
+ does the same: the event fires after the current task with a `connected` connection whose first messages are
266
+ `receiver_action` and `new_session`, which Google's SDK turns into its session. If the page replaced the request during the
267
+ launch, the session stays up as a route but the page is not handed a connection (Chrome likewise records the
268
+ presentation and tells nobody).
269
+
270
+ There is **no user gesture** on this path. The gesture check (`HasTransientUserActivation`) is in
271
+ `PresentationServiceImpl::StartPresentation`, which serves the page's own `PresentationRequest.start()`; the dialog's
272
+ route creation does not call it, because the browser UI is the user's action. The app is trusted the same way: only
273
+ code in the main process can call `startCasting`, never a page.
274
+
275
+ Errors are `MediaRouteError`s whose `code` is Chrome's `RouteRequestResultCode` in lower case, from the cause the
276
+ launch reports: `timed_out` (`TIMED_OUT`, the app did not launch in time), `sink_not_found` (`SINK_NOT_FOUND`, the device
277
+ cannot be reached), `invalid_origin` (`INVALID_ORIGIN`, `allowOrigin` refuses the page), `cancelled` (`CANCELLED`, the page
278
+ navigated or went away during the launch), `redundant_request` (`REDUNDANT_REQUEST`, the window already has a start in
279
+ progress, for the page's own or the app's) and `unknown_error` (`UNKNOWN_ERROR`). `unable_to_cast` is the dialog's own
280
+ check, above. `TypeError` and `RangeError` are thrown, as elsewhere here, for arguments of the wrong type or a cast mode
281
+ other than `"presentation"`, the only one electron-cast has (no tab or desktop mirroring).
282
+
283
+ Differences from Chrome:
284
+
285
+ - `getDefaultPresentationRequest` returns `null` without a request, where Chrome calls it an error. Observers are not
286
+ called on registration, like Chrome's, so read the current request first. They are called with `null` when the window is
287
+ destroyed, which Chrome does not announce.
288
+ - A `PresentationRequest` has `webContentsId` where Chrome has `render_frame_host_id`: only the outermost frame can own
289
+ one, so the window identifies it.
290
+ - The sinks for a presentation source are asked for with `MediaSinksQuery.presentationUrls`; Chrome builds a
291
+ `MediaSource` per URL. A sink matches when the URL is a Cast URL (`https://google.com/cast#__castAppId__=...` or
292
+ `cast:<appId>`), the sink has the capabilities its app id names **and the device answered `GET_APP_AVAILABILITY`
293
+ with the app available**, as Chrome's `CastAppAvailabilityTracker::GetAvailableSinks` requires
294
+ (`CastAppDiscoveryServiceImpl::StartObservingMediaSinks` asks every sink when a source is first observed). So a
295
+ sinks observer with `presentationUrls` first reports the sinks that were already asked, and the others when the
296
+ device has answered; `startCasting` asks (once per device and app) before launching, so it works without an observer. The
297
+ answers follow `CastAppDiscoveryServiceImpl::ShouldRefreshAppAvailability` (`cast_app_discovery_service.cc`): an
298
+ available app is kept until the device goes away and comes back, an unavailable one is asked again after
299
+ `kRefreshThreshold` (1 minute), and a device that cannot be reached or does not answer is unknown (always asked again
300
+ by `startCasting`; a sinks observer retries it at most once a minute, not at every change). `discoverSinksNow()`
301
+ asks again too, by the same rules (`CastAppDiscoveryServiceImpl::Refresh`). The question goes over the channel the
302
+ device already has open; nothing else is connected. The page's own `getAvailability()` and `start()` use the same
303
+ answers (see [API.md](API.md#app-availability)).
304
+ - A DIAL sink matches a `cast-dial:` URL whose app its DIAL server said it has, for the query's `origin` when the app is
305
+ one Chrome offers to some origins only (`DialMediaRouteProvider::GetOrigins`); pass the request's `frameOrigin`. While
306
+ the observer is registered the DIAL sinks are asked about those apps, as the DIAL provider's `StartObservingMediaSinks`
307
+ does. `startCasting` on a DIAL sink asks too and waits up to 5 s for the answer, then starts the DIAL route; the page
308
+ gets `connectionavailable` with an `mr_` presentation id, and the SDK's DIAL launch round trip runs on it as for its own
309
+ `start()`. A DIAL route has no earlier-route rule: `CastActivityManager`'s is Cast's, and the DIAL provider stops the
310
+ route already on the sink itself.
311
+ - Launching: `CastMediaRouteProvider::CreateRoute` ignores the `timeout` it is given (the dialog's
312
+ `GetRouteRequestTimeout(PRESENTATION)`, 20 s, `media_router_ui_helper.cc`). `CastActivityManager::DoLaunchSession`
313
+ gives the receiver the source's own `launch_timeout()`: `__castLaunchTimeout__` from the URL when it is a positive
314
+ number of milliseconds, else `kDefaultLaunchTimeout`, 60 s (`cast_media_source.cc` / `.h`). `startCasting` does the same,
315
+ as the page's own `start()` does.
316
+ - A sink that already has a route: `CastActivityManager::LaunchSession` launches anyway (a pending removal is noted for
317
+ the old activity, which goes when the receiver's status update says its session is gone). It does not reuse the route, so
318
+ neither does `startCasting` (the page's own picker path here still returns an existing session on the chosen sink).
319
+ `DoLaunchSession` also stops the route this frame launched before (`routes_by_frame_`); `startCasting` stops the
320
+ route its window's main frame last launched, by `startCasting` or by the page's `start()`, if it is still running.
321
+ - A default request replaced during the launch: `OnPresentationResponse` records the presentation and the route stays
322
+ (`DoLaunchSession` already added it); only the connection is not handed over. The route stays here too, listed by
323
+ routes observers, until the window launches another, the app terminates it or the receiver ends it. The connection of a
324
+ declined start is not wired to the page (nothing it sends reaches the page that has the window now). If the request
325
+ changed, or the page navigated, while the device was still being asked about the app, the start is `cancelled` before
326
+ anything is launched.
327
+
328
+ ## Wired displays
329
+
330
+ With the `wiredDisplay` option, other screens are presentation sinks, as Chrome's `WiredDisplayMediaRouteProvider`
331
+ makes them: a page's `PresentationRequest` for an https URL (not the legacy Cast URL) or http on localhost can start on
332
+ a display, which opens that page fullscreen in a locked-down receiver window; the presented page gets
333
+ `navigator.presentation.receiver`. The package never imports Electron, so the app passes `screen`, `BrowserWindow` and
334
+ a receiver window factory. Rules and their Chromium counterparts: [DESIGN.md](DESIGN.md#wired-displays).
335
+
336
+ <!-- no-check -->
337
+ ```ts
338
+ import { app, BrowserWindow, ipcMain, screen, session } from "electron";
339
+ import { join } from "node:path";
340
+ import { createCastManager, createReceiverWindows } from "electron-cast/main";
341
+
342
+ const receivers = createReceiverWindows({
343
+ BrowserWindow, session, ipcMain,
344
+ preloadDir: join(app.getPath("userData"), "electron-cast-receiver"), // the generated receiver preload goes here
345
+ });
346
+ const manager = createCastManager({
347
+ ipcMain,
348
+ selectDevice, // may now answer { display: id } when request.displays is set (below)
349
+ wiredDisplay: {
350
+ screen,
351
+ BrowserWindow, // finds the page's own display, which the picker leaves out
352
+ createReceiverWindow: receivers.factory,
353
+ async selectDisplay(sinks, request) { // the picker for a request only a display can show
354
+ return (await myDisplayPicker(sinks, request.observeSinks))?.id ?? null;
355
+ },
356
+ },
357
+ });
358
+ manager.wiredDisplay?.registerMediaRoutesObserver({ onRoutesUpdated: (routes) => menu.setPresentations(routes) });
359
+ ```
360
+
361
+ - **The pickers.** A request whose URLs only a display serves calls `selectDisplay(sinks, request)` (a
362
+ `WiredDisplayRequest`; `observeSinks` follows the list while the picker is open), which resolves a sink id or `null`.
363
+ A request that also has a Cast (or `cast-dial:`) URL is one picker, as Chrome's dialog lists both kinds of sink: when
364
+ displays and devices both exist, `selectDevice` gets `request.displays` and may answer a `DisplayChoice`
365
+ (`{ display: id }`), or a device as usual.
366
+ - **Sinks and routes** (`manager.wiredDisplay`, a `WiredDisplayApi`): `getSinks`, `registerMediaSinksObserver`,
367
+ `getRoutes`, `registerMediaRoutesObserver` and `terminateRoute`, which closes the receiver window. A
368
+ `WiredDisplaySink` is `wired_display_<id>`, "Display N", with its `display`; a `WiredDisplayRoute` has the
369
+ presentation URL, `Presenting (<host>)` and `isLocalPresentation: true`. They are kept apart from the Cast and DIAL
370
+ sinks of `registerMediaSinksObserver`.
371
+ - **Messages** are `PresentationMessage`s, a string or bytes, up to 64 MiB either way.
372
+
373
+ | Export | What it is |
374
+ |---|---|
375
+ | `createReceiverWindows(options)` | The Electron part: a `ReceiverWindows` whose `factory` opens receiver windows, and `dispose()`. `ReceiverWindowsOptions`: `BrowserWindow`, `session`, `ipcMain`, `preloadDir`, and optional `channel` and `platform`. Once per `ipcMain` and channel. |
376
+ | `isWiredDisplaySource(url)` | Whether a display can show the URL (`IsValidStandardPresentationSource`). |
377
+ | `availableDisplays(all, primary)`, `wiredDisplaySinks(all, primary)` | The displays that are sinks, in Chrome's order (primary first, then top-left; none for a single or mirrored setup), and their sinks. |
378
+ | `WiredDisplayOptions`, `WiredDisplayRequest`, `WiredDisplayApi`, `WiredDisplaySink`, `WiredDisplayRoute`, `DisplayChoice` | The types above. |
379
+ | `ScreenLike`, `DisplayLike`, `WindowLike` | The parts of Electron's `screen`, `Display` and `BrowserWindow` that are used. |
380
+
381
+ ## Adding a device by address
382
+
383
+ Chrome's Access Code Cast lets a user type the code a device shows to cast to it from another network. electron-cast does
384
+ not turn codes into addresses (that is a Google service that needs Chrome's own sign-in; see
385
+ [DESIGN.md](DESIGN.md#access-code-casting-access-codets)), but it does what Chrome does once the address is known: the app
386
+ supplies it.
387
+
388
+ <!-- no-check -->
389
+ ```ts
390
+ const manager = createCastManager({
391
+ ipcMain, selectDevice,
392
+ accessCode: { enabled: true, deviceDuration: 3600 }, // Chrome's AccessCodeCastEnabled and AccessCodeCastDeviceDuration
393
+ });
394
+ const result = await manager.addSinkByAddress({
395
+ id: "a1b2c3d4e5f60718293a4b5c6d7e8f90", // the device's unique id
396
+ name: "Seminar Room 4",
397
+ capabilities: { videoOut: true, audioOut: true },
398
+ ipV4Address: "10.20.30.40", // or ipV6Address, which is preferred
399
+ port: 8009, // optional, 8009 by default
400
+ });
401
+ // { code: "ok", sinkId } | { code: "response_malformed" | "sink_creation_error" | "channel_open_error", message, ... }
402
+ ```
403
+
404
+ The device is then in `devices()` and the sinks observers, offered to the picker and to pages' availability checks like any
405
+ discovered device. It is removed `deviceDuration` seconds after it was added (plus 20 s), or when the cast to it ends after
406
+ that. A public or loopback address is refused as for any device, unless `sinks.allowAllIps` is set. When the machine's
407
+ network changes the manager removes such devices and adds the remembered ones back, as Chrome does (it watches the
408
+ network itself; see the `networkMonitor` option). `configureAccessCode({ enabled, deviceDuration })` changes the settings while running,
409
+ `rememberedSinks()` lists what is remembered, and `accessCode.store` (`load`, `save`) keeps it between runs.
410
+
411
+ **Validate the address.** In Chrome it comes from Google's server; here it comes from your app. electron-cast only applies
412
+ Chrome's rules, which allow every private address and every port, so an address a user typed and you passed on unchecked
413
+ lets that user make the app open TLS connections to any host and port on your network and read from the result whether
414
+ something answered. Accept only addresses you expect (a known subnet, port 8009 unless you know otherwise) before
415
+ calling `addSinkByAddress`. The sink's id is the device id, in lower case without dashes, in angle brackets (`<uuid>`, Chrome's `cast:<uuid>`), so a
416
+ device that mDNS also finds is a second sink until the same-address rule removes one, as in Chrome.
417
+
418
+ | Export | What it is |
419
+ |---|---|
420
+ | `AccessCodeOptions` | The `accessCode` option: `enabled`, `deviceDuration` (seconds), `store`, and optional `log` and `now` (tests). |
421
+ | `AccessCodeDevice`, `AccessCodeCapabilities` | What `addSinkByAddress` takes: `id`, `name`, `capabilities` (`videoOut`, `videoIn`, `audioOut`, `audioIn`, `devMode`), `ipV6Address` or `ipV4Address`, and `port`. |
422
+ | `AddSinkResult`, `SinkCreationFailure` | How adding ended: `ok` with the `sinkId`, or `response_malformed`, `sink_creation_error` (with its `reason`) or `channel_open_error`. |
423
+ | `AccessCodeRememberedSink`, `AccessCodeStore` | A remembered device, and where they are kept between runs (`load`, `save`). |
424
+ | `AccessCodeCastDisabledError` | What `addSinkByAddress` rejects with unless access code casting is enabled. |
425
+ | `createAccessCodeSink(device)` | Chrome's checks on a device, without opening anything: the sink it would be, or why it cannot be one. |
426
+
427
+ ## Tab and desktop mirroring
428
+
429
+ `startCasting` also starts Chrome's other two cast modes, tab and desktop mirroring ("Cast tab" and "Cast screen"):
430
+ the app chooses what to send. They are off unless you pass `mirroring` to `createCastManager`:
431
+
432
+ <!-- no-check -->
433
+ ```ts
434
+ import { app, BrowserWindow, MessageChannelMain, utilityProcess, webContents } from "electron";
435
+
436
+ const manager = createCastManager({
437
+ ipcMain,
438
+ selectDevice,
439
+ mirroring: { electron: { BrowserWindow, utilityProcess, MessageChannelMain, webContents, app } },
440
+ });
441
+ await manager.start();
442
+
443
+ // Only the devices that can receive this kind of mirroring (audio-only speakers cannot take "desktop_mirror" without audio).
444
+ manager.registerMediaSinksObserver({ onSinksUpdated: showDevices }, { castMode: "tab_mirror" });
445
+
446
+ const route = await manager.startCasting(sink.id, { castMode: "tab_mirror", webContentsId: win.webContents.id });
447
+ // route.description is "Casting tab"; route.id is Chrome's urn:x-org.chromium:media:route:... form.
448
+ // The mirrored page is muted locally while the route runs, as in Chrome, and unmuted when it ends (an app that wants
449
+ // local audio can call webContents.setAudioMuted(false) itself). Desktop audio follows Chrome per platform: local
450
+ // playback keeps going on Windows and is muted elsewhere; there is no setting for it.
451
+ await manager.terminateRoute(route.id); // stops the receiver app, as Chrome does
452
+ ```
453
+
454
+ `startCasting(sinkId, options)` is one method for the three modes, as `MediaRouterUI::StartCasting` takes the cast mode;
455
+ `options` is a `StartCastingOptions`, one shape per mode (`MediaCastMode`; the mirroring ones are `MirroringCastMode`). Note that `webContentsId` means two things:
456
+
457
+ - `castMode: "presentation"` (or none) with `webContentsId`: the window whose **default presentation request** is cast
458
+ (above).
459
+ - `castMode: "tab_mirror"` with `webContentsId`: the **page to mirror** (video and its audio).
460
+ - `castMode: "desktop_mirror"` with `desktopSourceId` (an id from `desktopCapturer.getSources`) and optionally
461
+ `withAudio` (system loopback audio, where the OS provides it).
462
+ - `targetPlayoutDelayMs` overrides the receiver playout delay (Chrome's default is 200 ms, `kDefaultPlayoutDelay`).
463
+
464
+ A mirroring start rejects with a `MediaRouteError` (`code`: `sink_not_found`, `unable_to_cast`, `unknown_error`,
465
+ `cancelled`); `unable_to_cast` too when the `mirroring` option was not given. A mode that is none of the three is a
466
+ `RangeError`. The sinks query for a mode is `MediaSinksQuery.castMode` (with `withAudio` for desktop mirroring): the Cast
467
+ sinks that can run one of its streaming apps; DIAL sinks never match. The mirroring session runs on the device's one
468
+ kept-open channel, as Chrome's runs on its `CastSocket`, and its route is a local route, not a non-local one. A new
469
+ route on a device ends the one already running there, as in Chrome. Mirroring routes show up in
470
+ `registerMediaRoutesObserver` and end on `terminateRoute`, when the receiver's app closes, or on a stream error.
471
+
472
+ While a tab route runs, the source can change and the video can be frozen, as in Chrome:
473
+
474
+ <!-- no-check -->
475
+ ```ts
476
+ // "Share this tab instead": same route, same Cast session, no renegotiation; the new page is muted locally and the
477
+ // old one is unmuted (if the library muted it). A page has one route: a mirroring route already on it ends.
478
+ manager.switchMirroringSourceTab(route.id, otherWin.webContents.id);
479
+
480
+ // Pause the picture on its last frame (the audio goes on). It takes effect after 500 ms; unfreezing is immediate.
481
+ manager.registerMediaRoutesObserver({ onRoutesUpdated: (routes) => routes.forEach((r) => console.log(r.id, r.freezeInfo)) });
482
+ manager.freezeRoute(route.id); // ignored unless freezeInfo.canFreeze is true
483
+ manager.unfreezeRoute(route.id);
484
+ ```
485
+
486
+ `route.id` and `route.mediaSource` keep their values across a switch (Chrome's route does not change either); the page the
487
+ route is bound to is in `route.members`. Switching is for `tab_mirror` routes only (`unable_to_cast` for a desktop route,
488
+ a route still launching, or a page that cannot be captured). `freezeInfo` is `{ canFreeze, isFrozen }` on mirroring
489
+ routes. A frozen route unfreezes when its tab is switched.
490
+
491
+ Mirroring statistics are a debugging aid, as in Chrome's `chrome://media-router-internals` "Mirroring stats" (not a web
492
+ API; nothing is uploaded, and Chrome's UMA is not ported):
493
+
494
+ ```js
495
+ manager.setMirroringStatsEnabled(true); // off by default; read when a session starts, so call it before startCasting
496
+ const route = await manager.startCasting(sink.id, { castMode: "tab_mirror", webContentsId });
497
+ const off = manager.registerMirroringStatsObserver((routeId, stats) => {}); // every 500 ms, as Chrome's observers
498
+ manager.getMirroringStats(route.id); // { audio: {...}, video: {...} }; {} until the first fetch, while off, or for an unknown route
499
+ manager.isMirroringStatsEnabled();
500
+ ```
501
+
502
+ The dictionary has Chrome's names and units. Per stream: `ENQUEUE_FPS`, `AVG_CAPTURE_LATENCY_MS`, `AVG_ENCODE_TIME_MS`,
503
+ `AVG_QUEUEING_LATENCY_MS`, `AVG_NETWORK_LATENCY_MS`, `AVG_PACKET_LATENCY_MS`, `AVG_FRAME_LATENCY_MS`,
504
+ `AVG_E2E_LATENCY_MS`, `ENCODE_KBPS`, `TRANSMISSION_KBPS`, `MS_SINCE_LAST_RECEIVER_RESPONSE`, `NUM_FRAMES_CAPTURED`,
505
+ `NUM_FRAMES_DROPPED_BY_ENCODER`, `NUM_FRAMES_LATE`, `NUM_PACKETS_SENT`, `NUM_PACKETS_RECEIVED`, `FIRST_EVENT_TIME_MS`,
506
+ `LAST_EVENT_TIME_MS`, `UNKNOWN_OPEN_SCREEN_STAT` (retransmitted packets), the histograms (`CAPTURE_LATENCY_MS_HISTO`,
507
+ `ENCODE_TIME_MS_HISTO`, `QUEUEING_LATENCY_MS_HISTO`, `NETWORK_LATENCY_MS_HISTO`, `PACKET_LATENCY_MS_HISTO`,
508
+ `E2E_LATENCY_MS_HISTO`, `LATE_FRAME_MS_HISTO`, each a list like `[{ "0-19": 12 }, { ">=800": 1 }]`), and from the session
509
+ host `TARGET_BITRATE`, `ENCODER_UTILIZATION`, `LOSSINESS`, `FRAMES_INSERTED`, `FRAMES_DROPPED`. A value that is not
510
+ finite is the string `"null"`. As in Chrome the structure is for logs, not a contract. `getMirroringStats` takes a route
511
+ id because several routes can run (Chrome's debugger keeps one global copy). It never throws: like Chrome's `MediaRouterDebuggerImpl::GetMirroringStats`, which has no error path, it returns `{}` while statistics are off, before the first fetch and for a route id it does not know, and a route that has ended keeps its last statistics (Chrome's copy outlives the session) until another route pushes newer ones.
512
+
513
+ `mirroring` options (`ElectronMirroringOptions`): `electron` (the Electron objects to use, an `ElectronMirroringApi`:
514
+ `BrowserWindow`, `utilityProcess`, `MessageChannelMain`, `webContents`, and `app` so that Chrome's
515
+ switches are seen), `engineModulePath` (only if a bundler moved the library's files) and `log`. Opus audio is always offered. Video is
516
+ chosen as Chrome chooses it: H.264, VP8 and VP9 in hardware when the machine has an encoder for them
517
+ (`VideoEncoder.isConfigSupported` with `prefer-hardware`), VP8 and VP9 in software when it has none; Chrome's own
518
+ switches on `app.commandLine` change that (`--cast-streaming-force-{enable,disable}-hardware-<codec>`,
519
+ `--enable-features` / `--disable-features` with `CastStreamingVp8`, `CastStreamingVp9`, `CastStreamingAv1`,
520
+ `CastStreamingHardwareHevc`, and `--disable-cast-letterboxing`), including ones the app appends itself. A hardware
521
+ encoder that fails during a session is dropped for the rest of the app's run and the session offers again without it.
522
+ Capture happens in a hidden window and encoding in WebCodecs; the network sender runs in a utility process, one per
523
+ route. See [DESIGN.md](DESIGN.md#mirroring-srcmirroring) for the layout and [examples/live-mirroring](../examples/live-mirroring/)
524
+ to try it on a real device.