electron-cast 0.3.1 → 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 (758) hide show
  1. package/CHANGELOG.md +340 -0
  2. package/CONTRIBUTING.md +305 -0
  3. package/README.md +215 -60
  4. package/SECURITY.md +324 -0
  5. package/dist/cjs/client/auth/build-time.d.ts +7 -0
  6. package/dist/cjs/client/auth/build-time.js +11 -0
  7. package/dist/cjs/client/auth/build-time.js.map +1 -0
  8. package/dist/cjs/client/auth/cast-auth.d.ts +46 -0
  9. package/dist/cjs/client/auth/cast-auth.js +145 -0
  10. package/dist/cjs/client/auth/cast-auth.js.map +1 -0
  11. package/dist/cjs/client/auth/cast-cert-validator.d.ts +34 -0
  12. package/dist/cjs/client/auth/cast-cert-validator.js +89 -0
  13. package/dist/cjs/client/auth/cast-cert-validator.js.map +1 -0
  14. package/dist/cjs/client/auth/crl.d.ts +45 -0
  15. package/dist/cjs/client/auth/crl.js +227 -0
  16. package/dist/cjs/client/auth/crl.js.map +1 -0
  17. package/dist/cjs/client/auth/der.d.ts +62 -0
  18. package/dist/cjs/client/auth/der.js +208 -0
  19. package/dist/cjs/client/auth/der.js.map +1 -0
  20. package/dist/cjs/client/auth/names.d.ts +52 -0
  21. package/dist/cjs/client/auth/names.js +447 -0
  22. package/dist/cjs/client/auth/names.js.map +1 -0
  23. package/dist/cjs/client/auth/path-validator.d.ts +29 -0
  24. package/dist/cjs/client/auth/path-validator.js +421 -0
  25. package/dist/cjs/client/auth/path-validator.js.map +1 -0
  26. package/dist/cjs/client/auth/trust-data.d.ts +24 -0
  27. package/dist/cjs/client/auth/trust-data.js +97 -0
  28. package/dist/cjs/client/auth/trust-data.js.map +1 -0
  29. package/dist/cjs/client/auth/x509.d.ts +109 -0
  30. package/dist/cjs/client/auth/x509.js +442 -0
  31. package/dist/cjs/client/auth/x509.js.map +1 -0
  32. package/dist/cjs/client/cast-client.d.ts +111 -0
  33. package/dist/cjs/client/cast-client.js +505 -0
  34. package/dist/cjs/client/cast-client.js.map +1 -0
  35. package/dist/cjs/client/errors.d.ts +28 -0
  36. package/dist/cjs/client/errors.js +50 -0
  37. package/dist/cjs/client/errors.js.map +1 -0
  38. package/dist/cjs/client/index.d.ts +6 -0
  39. package/dist/cjs/client/index.js +21 -0
  40. package/dist/cjs/client/index.js.map +1 -0
  41. package/dist/cjs/client/namespaces.d.ts +9 -0
  42. package/dist/cjs/client/namespaces.js +13 -0
  43. package/dist/cjs/client/namespaces.js.map +1 -0
  44. package/dist/cjs/client/types.d.ts +27 -0
  45. package/dist/cjs/client/types.js +3 -0
  46. package/dist/cjs/client/types.js.map +1 -0
  47. package/dist/cjs/dial/dial-registry.d.ts +104 -0
  48. package/dist/cjs/dial/dial-registry.js +301 -0
  49. package/dist/cjs/dial/dial-registry.js.map +1 -0
  50. package/dist/cjs/dial/dial-sink-service.d.ts +108 -0
  51. package/dist/cjs/dial/dial-sink-service.js +314 -0
  52. package/dist/cjs/dial/dial-sink-service.js.map +1 -0
  53. package/dist/cjs/dial/http.d.ts +40 -0
  54. package/dist/cjs/dial/http.js +172 -0
  55. package/dist/cjs/dial/http.js.map +1 -0
  56. package/dist/cjs/dial/index.d.ts +63 -0
  57. package/dist/cjs/dial/index.js +134 -0
  58. package/dist/cjs/dial/index.js.map +1 -0
  59. package/dist/cjs/dial/origins.d.ts +4 -0
  60. package/dist/cjs/dial/origins.js +36 -0
  61. package/dist/cjs/dial/origins.js.map +1 -0
  62. package/dist/cjs/dial/parse.d.ts +101 -0
  63. package/dist/cjs/dial/parse.js +296 -0
  64. package/dist/cjs/dial/parse.js.map +1 -0
  65. package/dist/cjs/dial/route-provider.d.ts +96 -0
  66. package/dist/cjs/dial/route-provider.js +376 -0
  67. package/dist/cjs/dial/route-provider.js.map +1 -0
  68. package/dist/cjs/dial/ssdp-socket.d.ts +34 -0
  69. package/dist/cjs/dial/ssdp-socket.js +72 -0
  70. package/dist/cjs/dial/ssdp-socket.js.map +1 -0
  71. package/dist/cjs/dial/xml.d.ts +13 -0
  72. package/dist/cjs/dial/xml.js +208 -0
  73. package/dist/cjs/dial/xml.js.map +1 -0
  74. package/dist/cjs/discovery/cast-discovery.d.ts +105 -0
  75. package/dist/cjs/discovery/cast-discovery.js +323 -0
  76. package/dist/cjs/discovery/cast-discovery.js.map +1 -0
  77. package/dist/cjs/discovery/device-cache.d.ts +54 -0
  78. package/dist/cjs/discovery/device-cache.js +240 -0
  79. package/dist/cjs/discovery/device-cache.js.map +1 -0
  80. package/dist/cjs/discovery/dns-packet.d.ts +70 -0
  81. package/dist/cjs/discovery/dns-packet.js +251 -0
  82. package/dist/cjs/discovery/dns-packet.js.map +1 -0
  83. package/dist/cjs/discovery/index.d.ts +5 -0
  84. package/dist/cjs/discovery/index.js +22 -0
  85. package/dist/cjs/discovery/index.js.map +1 -0
  86. package/dist/cjs/discovery/ip-policy.d.ts +20 -0
  87. package/dist/cjs/discovery/ip-policy.js +109 -0
  88. package/dist/cjs/discovery/ip-policy.js.map +1 -0
  89. package/dist/cjs/discovery/udp-socket.d.ts +19 -0
  90. package/dist/cjs/discovery/udp-socket.js +166 -0
  91. package/dist/cjs/discovery/udp-socket.js.map +1 -0
  92. package/dist/cjs/electron/access-code.d.ts +221 -0
  93. package/dist/cjs/electron/access-code.js +586 -0
  94. package/dist/cjs/electron/access-code.js.map +1 -0
  95. package/dist/cjs/electron/app-discovery.d.ts +82 -0
  96. package/dist/cjs/electron/app-discovery.js +219 -0
  97. package/dist/cjs/electron/app-discovery.js.map +1 -0
  98. package/dist/cjs/electron/default-presentation.d.ts +38 -0
  99. package/dist/cjs/electron/default-presentation.js +88 -0
  100. package/dist/cjs/electron/default-presentation.js.map +1 -0
  101. package/dist/cjs/electron/main.d.ts +173 -0
  102. package/dist/cjs/electron/main.js +990 -0
  103. package/dist/cjs/electron/main.js.map +1 -0
  104. package/dist/cjs/electron/manager-api.d.ts +314 -0
  105. package/dist/cjs/electron/manager-api.js +402 -0
  106. package/dist/cjs/electron/manager-api.js.map +1 -0
  107. package/dist/cjs/electron/media-controller.d.ts +79 -0
  108. package/dist/cjs/electron/media-controller.js +251 -0
  109. package/dist/cjs/electron/media-controller.js.map +1 -0
  110. package/dist/cjs/electron/network-monitor.d.ts +61 -0
  111. package/dist/cjs/electron/network-monitor.js +124 -0
  112. package/dist/cjs/electron/network-monitor.js.map +1 -0
  113. package/dist/cjs/electron/preload.d.ts +39 -0
  114. package/dist/cjs/electron/preload.js +96 -0
  115. package/dist/cjs/electron/preload.js.map +1 -0
  116. package/dist/cjs/electron/presentation-envelope.d.ts +60 -0
  117. package/dist/cjs/electron/presentation-envelope.js +318 -0
  118. package/dist/cjs/electron/presentation-envelope.js.map +1 -0
  119. package/dist/cjs/electron/presentation-handler.d.ts +135 -0
  120. package/dist/cjs/electron/presentation-handler.js +643 -0
  121. package/dist/cjs/electron/presentation-handler.js.map +1 -0
  122. package/dist/cjs/electron/presentation-source.d.ts +76 -0
  123. package/dist/cjs/electron/presentation-source.js +132 -0
  124. package/dist/cjs/electron/presentation-source.js.map +1 -0
  125. package/dist/cjs/electron/session-service.d.ts +348 -0
  126. package/dist/cjs/electron/session-service.js +1273 -0
  127. package/dist/cjs/electron/session-service.js.map +1 -0
  128. package/dist/cjs/electron/session-tracker.d.ts +82 -0
  129. package/dist/cjs/electron/session-tracker.js +225 -0
  130. package/dist/cjs/electron/session-tracker.js.map +1 -0
  131. package/dist/cjs/electron/sink-service.d.ts +246 -0
  132. package/dist/cjs/electron/sink-service.js +606 -0
  133. package/dist/cjs/electron/sink-service.js.map +1 -0
  134. package/dist/cjs/electron/wired-display/controller.d.ts +76 -0
  135. package/dist/cjs/electron/wired-display/controller.js +198 -0
  136. package/dist/cjs/electron/wired-display/controller.js.map +1 -0
  137. package/dist/cjs/electron/wired-display/displays.d.ts +44 -0
  138. package/dist/cjs/electron/wired-display/displays.js +98 -0
  139. package/dist/cjs/electron/wired-display/displays.js.map +1 -0
  140. package/dist/cjs/electron/wired-display/electron-windows.d.ts +111 -0
  141. package/dist/cjs/electron/wired-display/electron-windows.js +306 -0
  142. package/dist/cjs/electron/wired-display/electron-windows.js.map +1 -0
  143. package/dist/cjs/electron/wired-display/index.d.ts +90 -0
  144. package/dist/cjs/electron/wired-display/index.js +115 -0
  145. package/dist/cjs/electron/wired-display/index.js.map +1 -0
  146. package/dist/cjs/electron/wired-display/local-presentation.d.ts +98 -0
  147. package/dist/cjs/electron/wired-display/local-presentation.js +234 -0
  148. package/dist/cjs/electron/wired-display/local-presentation.js.map +1 -0
  149. package/dist/cjs/electron/wired-display/provider.d.ts +112 -0
  150. package/dist/cjs/electron/wired-display/provider.js +202 -0
  151. package/dist/cjs/electron/wired-display/provider.js.map +1 -0
  152. package/dist/cjs/index.d.ts +9 -0
  153. package/dist/cjs/index.js +27 -0
  154. package/dist/cjs/index.js.map +1 -0
  155. package/dist/cjs/mirroring/backend.d.ts +76 -0
  156. package/dist/cjs/mirroring/backend.js +21 -0
  157. package/dist/cjs/mirroring/backend.js.map +1 -0
  158. package/dist/cjs/mirroring/electron/agent-protocol.d.ts +158 -0
  159. package/dist/cjs/mirroring/electron/agent-protocol.js +11 -0
  160. package/dist/cjs/mirroring/electron/agent-protocol.js.map +1 -0
  161. package/dist/cjs/mirroring/electron/agent-source.d.ts +20 -0
  162. package/dist/cjs/mirroring/electron/agent-source.js +621 -0
  163. package/dist/cjs/mirroring/electron/agent-source.js.map +1 -0
  164. package/dist/cjs/mirroring/electron/engine-process.d.ts +87 -0
  165. package/dist/cjs/mirroring/electron/engine-process.js +81 -0
  166. package/dist/cjs/mirroring/electron/engine-process.js.map +1 -0
  167. package/dist/cjs/mirroring/electron/host.d.ts +89 -0
  168. package/dist/cjs/mirroring/electron/host.js +321 -0
  169. package/dist/cjs/mirroring/electron/host.js.map +1 -0
  170. package/dist/cjs/mirroring/electron/port-backend.d.ts +107 -0
  171. package/dist/cjs/mirroring/electron/port-backend.js +446 -0
  172. package/dist/cjs/mirroring/electron/port-backend.js.map +1 -0
  173. package/dist/cjs/mirroring/encoding-support.d.ts +66 -0
  174. package/dist/cjs/mirroring/encoding-support.js +89 -0
  175. package/dist/cjs/mirroring/encoding-support.js.map +1 -0
  176. package/dist/cjs/mirroring/engine.d.ts +16 -0
  177. package/dist/cjs/mirroring/engine.js +78 -0
  178. package/dist/cjs/mirroring/engine.js.map +1 -0
  179. package/dist/cjs/mirroring/mirror-settings.d.ts +101 -0
  180. package/dist/cjs/mirroring/mirror-settings.js +140 -0
  181. package/dist/cjs/mirroring/mirror-settings.js.map +1 -0
  182. package/dist/cjs/mirroring/mirroring-activity.d.ts +207 -0
  183. package/dist/cjs/mirroring/mirroring-activity.js +367 -0
  184. package/dist/cjs/mirroring/mirroring-activity.js.map +1 -0
  185. package/dist/cjs/mirroring/mirroring-manager.d.ts +134 -0
  186. package/dist/cjs/mirroring/mirroring-manager.js +286 -0
  187. package/dist/cjs/mirroring/mirroring-manager.js.map +1 -0
  188. package/dist/cjs/mirroring/protocol/answer.d.ts +87 -0
  189. package/dist/cjs/mirroring/protocol/answer.js +233 -0
  190. package/dist/cjs/mirroring/protocol/answer.js.map +1 -0
  191. package/dist/cjs/mirroring/protocol/constants.d.ts +64 -0
  192. package/dist/cjs/mirroring/protocol/constants.js +70 -0
  193. package/dist/cjs/mirroring/protocol/constants.js.map +1 -0
  194. package/dist/cjs/mirroring/protocol/errors.d.ts +25 -0
  195. package/dist/cjs/mirroring/protocol/errors.js +34 -0
  196. package/dist/cjs/mirroring/protocol/errors.js.map +1 -0
  197. package/dist/cjs/mirroring/protocol/frame-id.d.ts +9 -0
  198. package/dist/cjs/mirroring/protocol/frame-id.js +24 -0
  199. package/dist/cjs/mirroring/protocol/frame-id.js.map +1 -0
  200. package/dist/cjs/mirroring/protocol/messenger.d.ts +42 -0
  201. package/dist/cjs/mirroring/protocol/messenger.js +122 -0
  202. package/dist/cjs/mirroring/protocol/messenger.js.map +1 -0
  203. package/dist/cjs/mirroring/protocol/offer.d.ts +109 -0
  204. package/dist/cjs/mirroring/protocol/offer.js +192 -0
  205. package/dist/cjs/mirroring/protocol/offer.js.map +1 -0
  206. package/dist/cjs/mirroring/protocol/recommendations.d.ts +28 -0
  207. package/dist/cjs/mirroring/protocol/recommendations.js +103 -0
  208. package/dist/cjs/mirroring/protocol/recommendations.js.map +1 -0
  209. package/dist/cjs/mirroring/routing.d.ts +60 -0
  210. package/dist/cjs/mirroring/routing.js +147 -0
  211. package/dist/cjs/mirroring/routing.js.map +1 -0
  212. package/dist/cjs/mirroring/rtcp/ntp.d.ts +27 -0
  213. package/dist/cjs/mirroring/rtcp/ntp.js +62 -0
  214. package/dist/cjs/mirroring/rtcp/ntp.js.map +1 -0
  215. package/dist/cjs/mirroring/rtcp/parser.d.ts +50 -0
  216. package/dist/cjs/mirroring/rtcp/parser.js +270 -0
  217. package/dist/cjs/mirroring/rtcp/parser.js.map +1 -0
  218. package/dist/cjs/mirroring/rtcp/sender-report.d.ts +32 -0
  219. package/dist/cjs/mirroring/rtcp/sender-report.js +56 -0
  220. package/dist/cjs/mirroring/rtcp/sender-report.js.map +1 -0
  221. package/dist/cjs/mirroring/rtcp/wire.d.ts +54 -0
  222. package/dist/cjs/mirroring/rtcp/wire.js +73 -0
  223. package/dist/cjs/mirroring/rtcp/wire.js.map +1 -0
  224. package/dist/cjs/mirroring/rtp/frame-crypto.d.ts +11 -0
  225. package/dist/cjs/mirroring/rtp/frame-crypto.js +39 -0
  226. package/dist/cjs/mirroring/rtp/frame-crypto.js.map +1 -0
  227. package/dist/cjs/mirroring/rtp/frame.d.ts +23 -0
  228. package/dist/cjs/mirroring/rtp/frame.js +3 -0
  229. package/dist/cjs/mirroring/rtp/frame.js.map +1 -0
  230. package/dist/cjs/mirroring/rtp/packetizer.d.ts +27 -0
  231. package/dist/cjs/mirroring/rtp/packetizer.js +92 -0
  232. package/dist/cjs/mirroring/rtp/packetizer.js.map +1 -0
  233. package/dist/cjs/mirroring/sender/audio-sender.d.ts +23 -0
  234. package/dist/cjs/mirroring/sender/audio-sender.js +52 -0
  235. package/dist/cjs/mirroring/sender/audio-sender.js.map +1 -0
  236. package/dist/cjs/mirroring/sender/bandwidth-estimator.d.ts +26 -0
  237. package/dist/cjs/mirroring/sender/bandwidth-estimator.js +107 -0
  238. package/dist/cjs/mirroring/sender/bandwidth-estimator.js.map +1 -0
  239. package/dist/cjs/mirroring/sender/capture-size-oracle.d.ts +121 -0
  240. package/dist/cjs/mirroring/sender/capture-size-oracle.js +440 -0
  241. package/dist/cjs/mirroring/sender/capture-size-oracle.js.map +1 -0
  242. package/dist/cjs/mirroring/sender/frame-sender.d.ts +103 -0
  243. package/dist/cjs/mirroring/sender/frame-sender.js +217 -0
  244. package/dist/cjs/mirroring/sender/frame-sender.js.map +1 -0
  245. package/dist/cjs/mirroring/sender/packet-router.d.ts +74 -0
  246. package/dist/cjs/mirroring/sender/packet-router.js +196 -0
  247. package/dist/cjs/mirroring/sender/packet-router.js.map +1 -0
  248. package/dist/cjs/mirroring/sender/sender-session.d.ts +85 -0
  249. package/dist/cjs/mirroring/sender/sender-session.js +240 -0
  250. package/dist/cjs/mirroring/sender/sender-session.js.map +1 -0
  251. package/dist/cjs/mirroring/sender/sender.d.ts +120 -0
  252. package/dist/cjs/mirroring/sender/sender.js +457 -0
  253. package/dist/cjs/mirroring/sender/sender.js.map +1 -0
  254. package/dist/cjs/mirroring/sender/video-encoder-metrics.d.ts +29 -0
  255. package/dist/cjs/mirroring/sender/video-encoder-metrics.js +64 -0
  256. package/dist/cjs/mirroring/sender/video-encoder-metrics.js.map +1 -0
  257. package/dist/cjs/mirroring/sender/video-sender.d.ts +95 -0
  258. package/dist/cjs/mirroring/sender/video-sender.js +183 -0
  259. package/dist/cjs/mirroring/sender/video-sender.js.map +1 -0
  260. package/dist/cjs/mirroring/session-host.d.ts +185 -0
  261. package/dist/cjs/mirroring/session-host.js +630 -0
  262. package/dist/cjs/mirroring/session-host.js.map +1 -0
  263. package/dist/cjs/mirroring/stats/clock-offset-estimator.d.ts +11 -0
  264. package/dist/cjs/mirroring/stats/clock-offset-estimator.js +123 -0
  265. package/dist/cjs/mirroring/stats/clock-offset-estimator.js.map +1 -0
  266. package/dist/cjs/mirroring/stats/openscreen-stats-client.d.ts +12 -0
  267. package/dist/cjs/mirroring/stats/openscreen-stats-client.js +21 -0
  268. package/dist/cjs/mirroring/stats/openscreen-stats-client.js.map +1 -0
  269. package/dist/cjs/mirroring/stats/sorted-map.d.ts +23 -0
  270. package/dist/cjs/mirroring/stats/sorted-map.js +70 -0
  271. package/dist/cjs/mirroring/stats/sorted-map.js.map +1 -0
  272. package/dist/cjs/mirroring/stats/statistics-analyzer.d.ts +50 -0
  273. package/dist/cjs/mirroring/stats/statistics-analyzer.js +339 -0
  274. package/dist/cjs/mirroring/stats/statistics-analyzer.js.map +1 -0
  275. package/dist/cjs/mirroring/stats/statistics-collector.d.ts +29 -0
  276. package/dist/cjs/mirroring/stats/statistics-collector.js +53 -0
  277. package/dist/cjs/mirroring/stats/statistics-collector.js.map +1 -0
  278. package/dist/cjs/mirroring/stats/statistics-common.d.ts +61 -0
  279. package/dist/cjs/mirroring/stats/statistics-common.js +45 -0
  280. package/dist/cjs/mirroring/stats/statistics-common.js.map +1 -0
  281. package/dist/cjs/mirroring/stats/statistics-dispatcher.d.ts +28 -0
  282. package/dist/cjs/mirroring/stats/statistics-dispatcher.js +104 -0
  283. package/dist/cjs/mirroring/stats/statistics-dispatcher.js.map +1 -0
  284. package/dist/cjs/mirroring/stats/statistics.d.ts +84 -0
  285. package/dist/cjs/mirroring/stats/statistics.js +147 -0
  286. package/dist/cjs/mirroring/stats/statistics.js.map +1 -0
  287. package/dist/cjs/mirroring/transport/udp-environment.d.ts +40 -0
  288. package/dist/cjs/mirroring/transport/udp-environment.js +97 -0
  289. package/dist/cjs/mirroring/transport/udp-environment.js.map +1 -0
  290. package/dist/cjs/package.json +1 -0
  291. package/dist/cjs/polyfill/bridge-types.d.ts +97 -0
  292. package/dist/cjs/polyfill/bridge-types.js +3 -0
  293. package/dist/cjs/polyfill/bridge-types.js.map +1 -0
  294. package/dist/cjs/polyfill/install.d.ts +12 -0
  295. package/dist/cjs/polyfill/install.js +1569 -0
  296. package/dist/cjs/polyfill/install.js.map +1 -0
  297. package/dist/cjs/polyfill/presentation-receiver.d.ts +12 -0
  298. package/dist/cjs/polyfill/presentation-receiver.js +369 -0
  299. package/dist/cjs/polyfill/presentation-receiver.js.map +1 -0
  300. package/dist/cjs/polyfill/presentation-standin.d.ts +13 -0
  301. package/dist/cjs/polyfill/presentation-standin.js +421 -0
  302. package/dist/cjs/polyfill/presentation-standin.js.map +1 -0
  303. package/dist/cjs/protocol/cast-message.d.ts +20 -0
  304. package/dist/cjs/protocol/cast-message.js +171 -0
  305. package/dist/cjs/protocol/cast-message.js.map +1 -0
  306. package/dist/cjs/protocol/device-auth.d.ts +61 -0
  307. package/dist/cjs/protocol/device-auth.js +113 -0
  308. package/dist/cjs/protocol/device-auth.js.map +1 -0
  309. package/dist/cjs/protocol/errors.d.ts +4 -0
  310. package/dist/cjs/protocol/errors.js +12 -0
  311. package/dist/cjs/protocol/errors.js.map +1 -0
  312. package/dist/cjs/protocol/framing.d.ts +18 -0
  313. package/dist/cjs/protocol/framing.js +100 -0
  314. package/dist/cjs/protocol/framing.js.map +1 -0
  315. package/dist/cjs/protocol/index.d.ts +4 -0
  316. package/dist/cjs/protocol/index.js +21 -0
  317. package/dist/cjs/protocol/index.js.map +1 -0
  318. package/dist/cjs/protocol/proto-wire.d.ts +11 -0
  319. package/dist/cjs/protocol/proto-wire.js +64 -0
  320. package/dist/cjs/protocol/proto-wire.js.map +1 -0
  321. package/dist/cli.d.ts +2 -0
  322. package/dist/cli.js +56 -0
  323. package/dist/cli.js.map +1 -0
  324. package/dist/client/auth/build-time.d.ts +7 -0
  325. package/dist/client/auth/build-time.js +8 -0
  326. package/dist/client/auth/build-time.js.map +1 -0
  327. package/dist/client/auth/cast-auth.d.ts +46 -0
  328. package/dist/client/auth/cast-auth.js +141 -0
  329. package/dist/client/auth/cast-auth.js.map +1 -0
  330. package/dist/client/auth/cast-cert-validator.d.ts +34 -0
  331. package/dist/client/auth/cast-cert-validator.js +86 -0
  332. package/dist/client/auth/cast-cert-validator.js.map +1 -0
  333. package/dist/client/auth/crl.d.ts +45 -0
  334. package/dist/client/auth/crl.js +221 -0
  335. package/dist/client/auth/crl.js.map +1 -0
  336. package/dist/client/auth/der.d.ts +62 -0
  337. package/dist/client/auth/der.js +196 -0
  338. package/dist/client/auth/der.js.map +1 -0
  339. package/dist/client/auth/names.d.ts +52 -0
  340. package/dist/client/auth/names.js +438 -0
  341. package/dist/client/auth/names.js.map +1 -0
  342. package/dist/client/auth/path-validator.d.ts +29 -0
  343. package/dist/client/auth/path-validator.js +417 -0
  344. package/dist/client/auth/path-validator.js.map +1 -0
  345. package/dist/client/auth/trust-data.d.ts +24 -0
  346. package/dist/client/auth/trust-data.js +94 -0
  347. package/dist/client/auth/trust-data.js.map +1 -0
  348. package/dist/client/auth/x509.d.ts +109 -0
  349. package/dist/client/auth/x509.js +430 -0
  350. package/dist/client/auth/x509.js.map +1 -0
  351. package/dist/client/cast-client.d.ts +20 -1
  352. package/dist/client/cast-client.js +74 -3
  353. package/dist/client/cast-client.js.map +1 -1
  354. package/dist/client/errors.d.ts +11 -0
  355. package/dist/client/errors.js +13 -0
  356. package/dist/client/errors.js.map +1 -1
  357. package/dist/client/index.d.ts +2 -0
  358. package/dist/dial/dial-registry.d.ts +104 -0
  359. package/dist/dial/dial-registry.js +297 -0
  360. package/dist/dial/dial-registry.js.map +1 -0
  361. package/dist/dial/dial-sink-service.d.ts +108 -0
  362. package/dist/dial/dial-sink-service.js +310 -0
  363. package/dist/dial/dial-sink-service.js.map +1 -0
  364. package/dist/dial/http.d.ts +40 -0
  365. package/dist/dial/http.js +165 -0
  366. package/dist/dial/http.js.map +1 -0
  367. package/dist/dial/index.d.ts +63 -0
  368. package/dist/dial/index.js +115 -0
  369. package/dist/dial/index.js.map +1 -0
  370. package/dist/dial/origins.d.ts +4 -0
  371. package/dist/dial/origins.js +32 -0
  372. package/dist/dial/origins.js.map +1 -0
  373. package/dist/dial/parse.d.ts +101 -0
  374. package/dist/dial/parse.js +281 -0
  375. package/dist/dial/parse.js.map +1 -0
  376. package/dist/dial/route-provider.d.ts +96 -0
  377. package/dist/dial/route-provider.js +369 -0
  378. package/dist/dial/route-provider.js.map +1 -0
  379. package/dist/dial/ssdp-socket.d.ts +34 -0
  380. package/dist/dial/ssdp-socket.js +65 -0
  381. package/dist/dial/ssdp-socket.js.map +1 -0
  382. package/dist/dial/xml.d.ts +13 -0
  383. package/dist/dial/xml.js +204 -0
  384. package/dist/dial/xml.js.map +1 -0
  385. package/dist/dial-test/cli-main.d.ts +17 -0
  386. package/dist/dial-test/cli-main.js +130 -0
  387. package/dist/dial-test/cli-main.js.map +1 -0
  388. package/dist/dial-test/report.d.ts +55 -0
  389. package/dist/dial-test/report.js +77 -0
  390. package/dist/dial-test/report.js.map +1 -0
  391. package/dist/dial-test/runner.d.ts +42 -0
  392. package/dist/dial-test/runner.js +566 -0
  393. package/dist/dial-test/runner.js.map +1 -0
  394. package/dist/dial-test/scrub.d.ts +14 -0
  395. package/dist/dial-test/scrub.js +73 -0
  396. package/dist/dial-test/scrub.js.map +1 -0
  397. package/dist/discovery/cast-discovery.d.ts +23 -2
  398. package/dist/discovery/cast-discovery.js +94 -14
  399. package/dist/discovery/cast-discovery.js.map +1 -1
  400. package/dist/discovery/device-cache.d.ts +15 -1
  401. package/dist/discovery/device-cache.js +31 -7
  402. package/dist/discovery/device-cache.js.map +1 -1
  403. package/dist/discovery/index.d.ts +1 -0
  404. package/dist/discovery/index.js +1 -0
  405. package/dist/discovery/index.js.map +1 -1
  406. package/dist/discovery/ip-policy.d.ts +20 -0
  407. package/dist/discovery/ip-policy.js +103 -0
  408. package/dist/discovery/ip-policy.js.map +1 -0
  409. package/dist/discovery/udp-socket.d.ts +8 -1
  410. package/dist/discovery/udp-socket.js +59 -5
  411. package/dist/discovery/udp-socket.js.map +1 -1
  412. package/dist/electron/access-code.d.ts +221 -0
  413. package/dist/electron/access-code.js +577 -0
  414. package/dist/electron/access-code.js.map +1 -0
  415. package/dist/electron/app-discovery.d.ts +82 -0
  416. package/dist/electron/app-discovery.js +215 -0
  417. package/dist/electron/app-discovery.js.map +1 -0
  418. package/dist/electron/default-presentation.d.ts +38 -0
  419. package/dist/electron/default-presentation.js +83 -0
  420. package/dist/electron/default-presentation.js.map +1 -0
  421. package/dist/electron/main.d.ts +122 -13
  422. package/dist/electron/main.js +776 -63
  423. package/dist/electron/main.js.map +1 -1
  424. package/dist/electron/manager-api.d.ts +314 -0
  425. package/dist/electron/manager-api.js +390 -0
  426. package/dist/electron/manager-api.js.map +1 -0
  427. package/dist/electron/media-controller.d.ts +79 -0
  428. package/dist/electron/media-controller.js +248 -0
  429. package/dist/electron/media-controller.js.map +1 -0
  430. package/dist/electron/network-monitor.d.ts +61 -0
  431. package/dist/electron/network-monitor.js +117 -0
  432. package/dist/electron/network-monitor.js.map +1 -0
  433. package/dist/electron/preload.d.ts +5 -0
  434. package/dist/electron/preload.js +9 -1
  435. package/dist/electron/preload.js.map +1 -1
  436. package/dist/electron/presentation-envelope.js +7 -1
  437. package/dist/electron/presentation-envelope.js.map +1 -1
  438. package/dist/electron/presentation-handler.d.ts +39 -4
  439. package/dist/electron/presentation-handler.js +208 -57
  440. package/dist/electron/presentation-handler.js.map +1 -1
  441. package/dist/electron/presentation-source.d.ts +76 -0
  442. package/dist/electron/presentation-source.js +125 -0
  443. package/dist/electron/presentation-source.js.map +1 -0
  444. package/dist/electron/session-service.d.ts +225 -10
  445. package/dist/electron/session-service.js +735 -151
  446. package/dist/electron/session-service.js.map +1 -1
  447. package/dist/electron/session-tracker.d.ts +82 -0
  448. package/dist/electron/session-tracker.js +219 -0
  449. package/dist/electron/session-tracker.js.map +1 -0
  450. package/dist/electron/sink-service.d.ts +246 -0
  451. package/dist/electron/sink-service.js +602 -0
  452. package/dist/electron/sink-service.js.map +1 -0
  453. package/dist/electron/wired-display/controller.d.ts +76 -0
  454. package/dist/electron/wired-display/controller.js +194 -0
  455. package/dist/electron/wired-display/controller.js.map +1 -0
  456. package/dist/electron/wired-display/displays.d.ts +44 -0
  457. package/dist/electron/wired-display/displays.js +91 -0
  458. package/dist/electron/wired-display/displays.js.map +1 -0
  459. package/dist/electron/wired-display/electron-windows.d.ts +111 -0
  460. package/dist/electron/wired-display/electron-windows.js +301 -0
  461. package/dist/electron/wired-display/electron-windows.js.map +1 -0
  462. package/dist/electron/wired-display/index.d.ts +90 -0
  463. package/dist/electron/wired-display/index.js +99 -0
  464. package/dist/electron/wired-display/index.js.map +1 -0
  465. package/dist/electron/wired-display/local-presentation.d.ts +98 -0
  466. package/dist/electron/wired-display/local-presentation.js +228 -0
  467. package/dist/electron/wired-display/local-presentation.js.map +1 -0
  468. package/dist/electron/wired-display/provider.d.ts +112 -0
  469. package/dist/electron/wired-display/provider.js +197 -0
  470. package/dist/electron/wired-display/provider.js.map +1 -0
  471. package/dist/index.d.ts +1 -0
  472. package/dist/index.js +1 -0
  473. package/dist/index.js.map +1 -1
  474. package/dist/mirroring/backend.d.ts +76 -0
  475. package/dist/mirroring/backend.js +18 -0
  476. package/dist/mirroring/backend.js.map +1 -0
  477. package/dist/mirroring/electron/agent-protocol.d.ts +158 -0
  478. package/dist/mirroring/electron/agent-protocol.js +10 -0
  479. package/dist/mirroring/electron/agent-protocol.js.map +1 -0
  480. package/dist/mirroring/electron/agent-source.d.ts +20 -0
  481. package/dist/mirroring/electron/agent-source.js +618 -0
  482. package/dist/mirroring/electron/agent-source.js.map +1 -0
  483. package/dist/mirroring/electron/engine-process.d.ts +87 -0
  484. package/dist/mirroring/electron/engine-process.js +78 -0
  485. package/dist/mirroring/electron/engine-process.js.map +1 -0
  486. package/dist/mirroring/electron/host.d.ts +89 -0
  487. package/dist/mirroring/electron/host.js +318 -0
  488. package/dist/mirroring/electron/host.js.map +1 -0
  489. package/dist/mirroring/electron/port-backend.d.ts +107 -0
  490. package/dist/mirroring/electron/port-backend.js +441 -0
  491. package/dist/mirroring/electron/port-backend.js.map +1 -0
  492. package/dist/mirroring/encoding-support.d.ts +66 -0
  493. package/dist/mirroring/encoding-support.js +81 -0
  494. package/dist/mirroring/encoding-support.js.map +1 -0
  495. package/dist/mirroring/engine.d.ts +16 -0
  496. package/dist/mirroring/engine.js +75 -0
  497. package/dist/mirroring/engine.js.map +1 -0
  498. package/dist/mirroring/mirror-settings.d.ts +101 -0
  499. package/dist/mirroring/mirror-settings.js +134 -0
  500. package/dist/mirroring/mirror-settings.js.map +1 -0
  501. package/dist/mirroring/mirroring-activity.d.ts +207 -0
  502. package/dist/mirroring/mirroring-activity.js +362 -0
  503. package/dist/mirroring/mirroring-activity.js.map +1 -0
  504. package/dist/mirroring/mirroring-manager.d.ts +134 -0
  505. package/dist/mirroring/mirroring-manager.js +281 -0
  506. package/dist/mirroring/mirroring-manager.js.map +1 -0
  507. package/dist/mirroring/protocol/answer.d.ts +87 -0
  508. package/dist/mirroring/protocol/answer.js +226 -0
  509. package/dist/mirroring/protocol/answer.js.map +1 -0
  510. package/dist/mirroring/protocol/constants.d.ts +64 -0
  511. package/dist/mirroring/protocol/constants.js +66 -0
  512. package/dist/mirroring/protocol/constants.js.map +1 -0
  513. package/dist/mirroring/protocol/errors.d.ts +25 -0
  514. package/dist/mirroring/protocol/errors.js +29 -0
  515. package/dist/mirroring/protocol/errors.js.map +1 -0
  516. package/dist/mirroring/protocol/frame-id.d.ts +9 -0
  517. package/dist/mirroring/protocol/frame-id.js +20 -0
  518. package/dist/mirroring/protocol/frame-id.js.map +1 -0
  519. package/dist/mirroring/protocol/messenger.d.ts +42 -0
  520. package/dist/mirroring/protocol/messenger.js +118 -0
  521. package/dist/mirroring/protocol/messenger.js.map +1 -0
  522. package/dist/mirroring/protocol/offer.d.ts +109 -0
  523. package/dist/mirroring/protocol/offer.js +176 -0
  524. package/dist/mirroring/protocol/offer.js.map +1 -0
  525. package/dist/mirroring/protocol/recommendations.d.ts +28 -0
  526. package/dist/mirroring/protocol/recommendations.js +99 -0
  527. package/dist/mirroring/protocol/recommendations.js.map +1 -0
  528. package/dist/mirroring/routing.d.ts +60 -0
  529. package/dist/mirroring/routing.js +130 -0
  530. package/dist/mirroring/routing.js.map +1 -0
  531. package/dist/mirroring/rtcp/ntp.d.ts +27 -0
  532. package/dist/mirroring/rtcp/ntp.js +57 -0
  533. package/dist/mirroring/rtcp/ntp.js.map +1 -0
  534. package/dist/mirroring/rtcp/parser.d.ts +50 -0
  535. package/dist/mirroring/rtcp/parser.js +265 -0
  536. package/dist/mirroring/rtcp/parser.js.map +1 -0
  537. package/dist/mirroring/rtcp/sender-report.d.ts +32 -0
  538. package/dist/mirroring/rtcp/sender-report.js +51 -0
  539. package/dist/mirroring/rtcp/sender-report.js.map +1 -0
  540. package/dist/mirroring/rtcp/wire.d.ts +54 -0
  541. package/dist/mirroring/rtcp/wire.js +68 -0
  542. package/dist/mirroring/rtcp/wire.js.map +1 -0
  543. package/dist/mirroring/rtp/frame-crypto.d.ts +11 -0
  544. package/dist/mirroring/rtp/frame-crypto.js +35 -0
  545. package/dist/mirroring/rtp/frame-crypto.js.map +1 -0
  546. package/dist/mirroring/rtp/frame.d.ts +23 -0
  547. package/dist/mirroring/rtp/frame.js +2 -0
  548. package/dist/mirroring/rtp/frame.js.map +1 -0
  549. package/dist/mirroring/rtp/packetizer.d.ts +27 -0
  550. package/dist/mirroring/rtp/packetizer.js +88 -0
  551. package/dist/mirroring/rtp/packetizer.js.map +1 -0
  552. package/dist/mirroring/sender/audio-sender.d.ts +23 -0
  553. package/dist/mirroring/sender/audio-sender.js +54 -0
  554. package/dist/mirroring/sender/audio-sender.js.map +1 -0
  555. package/dist/mirroring/sender/bandwidth-estimator.d.ts +26 -0
  556. package/dist/mirroring/sender/bandwidth-estimator.js +103 -0
  557. package/dist/mirroring/sender/bandwidth-estimator.js.map +1 -0
  558. package/dist/mirroring/sender/capture-size-oracle.d.ts +121 -0
  559. package/dist/mirroring/sender/capture-size-oracle.js +433 -0
  560. package/dist/mirroring/sender/capture-size-oracle.js.map +1 -0
  561. package/dist/mirroring/sender/frame-sender.d.ts +103 -0
  562. package/dist/mirroring/sender/frame-sender.js +212 -0
  563. package/dist/mirroring/sender/frame-sender.js.map +1 -0
  564. package/dist/mirroring/sender/packet-router.d.ts +74 -0
  565. package/dist/mirroring/sender/packet-router.js +191 -0
  566. package/dist/mirroring/sender/packet-router.js.map +1 -0
  567. package/dist/mirroring/sender/sender-session.d.ts +85 -0
  568. package/dist/mirroring/sender/sender-session.js +235 -0
  569. package/dist/mirroring/sender/sender-session.js.map +1 -0
  570. package/dist/mirroring/sender/sender.d.ts +120 -0
  571. package/dist/mirroring/sender/sender.js +452 -0
  572. package/dist/mirroring/sender/sender.js.map +1 -0
  573. package/dist/mirroring/sender/video-encoder-metrics.d.ts +29 -0
  574. package/dist/mirroring/sender/video-encoder-metrics.js +58 -0
  575. package/dist/mirroring/sender/video-encoder-metrics.js.map +1 -0
  576. package/dist/mirroring/sender/video-sender.d.ts +95 -0
  577. package/dist/mirroring/sender/video-sender.js +190 -0
  578. package/dist/mirroring/sender/video-sender.js.map +1 -0
  579. package/dist/mirroring/session-host.d.ts +185 -0
  580. package/dist/mirroring/session-host.js +625 -0
  581. package/dist/mirroring/session-host.js.map +1 -0
  582. package/dist/mirroring/stats/clock-offset-estimator.d.ts +11 -0
  583. package/dist/mirroring/stats/clock-offset-estimator.js +120 -0
  584. package/dist/mirroring/stats/clock-offset-estimator.js.map +1 -0
  585. package/dist/mirroring/stats/openscreen-stats-client.d.ts +12 -0
  586. package/dist/mirroring/stats/openscreen-stats-client.js +17 -0
  587. package/dist/mirroring/stats/openscreen-stats-client.js.map +1 -0
  588. package/dist/mirroring/stats/sorted-map.d.ts +23 -0
  589. package/dist/mirroring/stats/sorted-map.js +66 -0
  590. package/dist/mirroring/stats/sorted-map.js.map +1 -0
  591. package/dist/mirroring/stats/statistics-analyzer.d.ts +50 -0
  592. package/dist/mirroring/stats/statistics-analyzer.js +335 -0
  593. package/dist/mirroring/stats/statistics-analyzer.js.map +1 -0
  594. package/dist/mirroring/stats/statistics-collector.d.ts +29 -0
  595. package/dist/mirroring/stats/statistics-collector.js +49 -0
  596. package/dist/mirroring/stats/statistics-collector.js.map +1 -0
  597. package/dist/mirroring/stats/statistics-common.d.ts +61 -0
  598. package/dist/mirroring/stats/statistics-common.js +39 -0
  599. package/dist/mirroring/stats/statistics-common.js.map +1 -0
  600. package/dist/mirroring/stats/statistics-dispatcher.d.ts +28 -0
  601. package/dist/mirroring/stats/statistics-dispatcher.js +100 -0
  602. package/dist/mirroring/stats/statistics-dispatcher.js.map +1 -0
  603. package/dist/mirroring/stats/statistics.d.ts +84 -0
  604. package/dist/mirroring/stats/statistics.js +141 -0
  605. package/dist/mirroring/stats/statistics.js.map +1 -0
  606. package/dist/mirroring/transport/udp-environment.d.ts +40 -0
  607. package/dist/mirroring/transport/udp-environment.js +93 -0
  608. package/dist/mirroring/transport/udp-environment.js.map +1 -0
  609. package/dist/polyfill/bridge-types.d.ts +11 -0
  610. package/dist/polyfill/presentation-receiver.d.ts +12 -0
  611. package/dist/polyfill/presentation-receiver.js +366 -0
  612. package/dist/polyfill/presentation-receiver.js.map +1 -0
  613. package/dist/polyfill/presentation-standin.js +160 -17
  614. package/dist/polyfill/presentation-standin.js.map +1 -1
  615. package/dist/protocol/device-auth.d.ts +61 -0
  616. package/dist/protocol/device-auth.js +106 -0
  617. package/dist/protocol/device-auth.js.map +1 -0
  618. package/dist/protocol/framing.d.ts +1 -1
  619. package/dist/protocol/framing.js +1 -1
  620. package/dist/protocol/framing.js.map +1 -1
  621. package/dist/protocol/index.d.ts +1 -0
  622. package/dist/protocol/index.js +1 -0
  623. package/dist/protocol/index.js.map +1 -1
  624. package/dist/protocol/proto-wire.d.ts +11 -0
  625. package/dist/protocol/proto-wire.js +60 -0
  626. package/dist/protocol/proto-wire.js.map +1 -0
  627. package/docs/API.md +724 -0
  628. package/docs/ARCHITECTURE.md +242 -0
  629. package/docs/CHROMIUM-MAP.md +176 -0
  630. package/docs/DESIGN.md +1189 -0
  631. package/docs/FAQ.md +123 -0
  632. package/docs/GETTING-STARTED.md +248 -0
  633. package/docs/MAIN-API.md +524 -0
  634. package/docs/TROUBLESHOOTING.md +283 -0
  635. package/docs/guides/audio-and-groups.md +75 -0
  636. package/docs/guides/custom-receivers.md +109 -0
  637. package/docs/guides/device-authentication.md +145 -0
  638. package/docs/guides/device-picker.md +176 -0
  639. package/docs/guides/index.md +17 -0
  640. package/docs/guides/low-level-client.md +103 -0
  641. package/docs/guides/restart-rejoin.md +172 -0
  642. package/docs/guides/testing.md +162 -0
  643. package/docs/guides/windows-and-iframes.md +116 -0
  644. package/docs/readme/badges/dependencies.svg +1 -0
  645. package/docs/readme/badges/electron.svg +1 -0
  646. package/docs/readme/badges/license.svg +1 -0
  647. package/docs/readme/badges/node.svg +1 -0
  648. package/docs/readme/board.jpg +0 -0
  649. package/docs/readme/hero-dark.jpg +0 -0
  650. package/docs/readme/hero-light.jpg +0 -0
  651. package/docs/readme/nosignal.jpg +0 -0
  652. package/docs/readme/parity.jpg +0 -0
  653. package/docs/readme/trace.svg +22 -0
  654. package/package.json +67 -16
  655. package/src/cli.ts +57 -0
  656. package/src/client/auth/build-time.ts +7 -0
  657. package/src/client/auth/cast-auth.ts +186 -0
  658. package/src/client/auth/cast-cert-validator.ts +133 -0
  659. package/src/client/auth/crl.ts +228 -0
  660. package/src/client/auth/der.ts +193 -0
  661. package/src/client/auth/names.ts +411 -0
  662. package/src/client/auth/path-validator.ts +449 -0
  663. package/src/client/auth/trust-data.ts +95 -0
  664. package/src/client/auth/x509.ts +488 -0
  665. package/src/client/cast-client.ts +85 -3
  666. package/src/client/errors.ts +29 -0
  667. package/src/client/index.ts +2 -0
  668. package/src/dial/dial-registry.ts +316 -0
  669. package/src/dial/dial-sink-service.ts +343 -0
  670. package/src/dial/http.ts +200 -0
  671. package/src/dial/index.ts +135 -0
  672. package/src/dial/origins.ts +31 -0
  673. package/src/dial/parse.ts +319 -0
  674. package/src/dial/route-provider.ts +429 -0
  675. package/src/dial/ssdp-socket.ts +79 -0
  676. package/src/dial/xml.ts +180 -0
  677. package/src/dial-test/cli-main.ts +146 -0
  678. package/src/dial-test/report.ts +109 -0
  679. package/src/dial-test/runner.ts +615 -0
  680. package/src/dial-test/scrub.ts +74 -0
  681. package/src/discovery/cast-discovery.ts +106 -19
  682. package/src/discovery/device-cache.ts +43 -8
  683. package/src/discovery/index.ts +1 -0
  684. package/src/discovery/ip-policy.ts +97 -0
  685. package/src/discovery/udp-socket.ts +66 -4
  686. package/src/electron/access-code.ts +681 -0
  687. package/src/electron/app-discovery.ts +244 -0
  688. package/src/electron/default-presentation.ts +104 -0
  689. package/src/electron/main.ts +866 -72
  690. package/src/electron/manager-api.ts +664 -0
  691. package/src/electron/media-controller.ts +313 -0
  692. package/src/electron/network-monitor.ts +140 -0
  693. package/src/electron/preload.ts +16 -2
  694. package/src/electron/presentation-envelope.ts +7 -1
  695. package/src/electron/presentation-handler.ts +211 -58
  696. package/src/electron/presentation-source.ts +155 -0
  697. package/src/electron/session-service.ts +808 -149
  698. package/src/electron/session-tracker.ts +248 -0
  699. package/src/electron/sink-service.ts +726 -0
  700. package/src/electron/wired-display/controller.ts +212 -0
  701. package/src/electron/wired-display/displays.ts +107 -0
  702. package/src/electron/wired-display/electron-windows.ts +386 -0
  703. package/src/electron/wired-display/index.ts +181 -0
  704. package/src/electron/wired-display/local-presentation.ts +286 -0
  705. package/src/electron/wired-display/provider.ts +276 -0
  706. package/src/index.ts +1 -0
  707. package/src/mirroring/backend.ts +103 -0
  708. package/src/mirroring/electron/agent-protocol.ts +84 -0
  709. package/src/mirroring/electron/agent-source.ts +619 -0
  710. package/src/mirroring/electron/engine-process.ts +131 -0
  711. package/src/mirroring/electron/host.ts +361 -0
  712. package/src/mirroring/electron/port-backend.ts +466 -0
  713. package/src/mirroring/encoding-support.ts +146 -0
  714. package/src/mirroring/engine.ts +91 -0
  715. package/src/mirroring/mirror-settings.ts +174 -0
  716. package/src/mirroring/mirroring-activity.ts +466 -0
  717. package/src/mirroring/mirroring-manager.ts +342 -0
  718. package/src/mirroring/protocol/answer.ts +285 -0
  719. package/src/mirroring/protocol/constants.ts +75 -0
  720. package/src/mirroring/protocol/errors.ts +36 -0
  721. package/src/mirroring/protocol/frame-id.ts +20 -0
  722. package/src/mirroring/protocol/messenger.ts +128 -0
  723. package/src/mirroring/protocol/offer.ts +275 -0
  724. package/src/mirroring/protocol/recommendations.ts +135 -0
  725. package/src/mirroring/routing.ts +160 -0
  726. package/src/mirroring/rtcp/ntp.ts +61 -0
  727. package/src/mirroring/rtcp/parser.ts +292 -0
  728. package/src/mirroring/rtcp/sender-report.ts +88 -0
  729. package/src/mirroring/rtcp/wire.ts +76 -0
  730. package/src/mirroring/rtp/frame-crypto.ts +38 -0
  731. package/src/mirroring/rtp/frame.ts +25 -0
  732. package/src/mirroring/rtp/packetizer.ts +95 -0
  733. package/src/mirroring/sender/audio-sender.ts +59 -0
  734. package/src/mirroring/sender/bandwidth-estimator.ts +111 -0
  735. package/src/mirroring/sender/capture-size-oracle.ts +476 -0
  736. package/src/mirroring/sender/frame-sender.ts +293 -0
  737. package/src/mirroring/sender/packet-router.ts +228 -0
  738. package/src/mirroring/sender/sender-session.ts +306 -0
  739. package/src/mirroring/sender/sender.ts +497 -0
  740. package/src/mirroring/sender/video-encoder-metrics.ts +64 -0
  741. package/src/mirroring/sender/video-sender.ts +243 -0
  742. package/src/mirroring/session-host.ts +725 -0
  743. package/src/mirroring/stats/clock-offset-estimator.ts +139 -0
  744. package/src/mirroring/stats/openscreen-stats-client.ts +19 -0
  745. package/src/mirroring/stats/sorted-map.ts +68 -0
  746. package/src/mirroring/stats/statistics-analyzer.ts +388 -0
  747. package/src/mirroring/stats/statistics-collector.ts +69 -0
  748. package/src/mirroring/stats/statistics-common.ts +112 -0
  749. package/src/mirroring/stats/statistics-dispatcher.ts +133 -0
  750. package/src/mirroring/stats/statistics.ts +170 -0
  751. package/src/mirroring/transport/udp-environment.ts +100 -0
  752. package/src/polyfill/bridge-types.ts +11 -0
  753. package/src/polyfill/presentation-receiver.ts +350 -0
  754. package/src/polyfill/presentation-standin.ts +150 -17
  755. package/src/protocol/device-auth.ts +126 -0
  756. package/src/protocol/framing.ts +1 -1
  757. package/src/protocol/index.ts +1 -0
  758. package/src/protocol/proto-wire.ts +55 -0
@@ -1,9 +1,35 @@
1
1
  import { CastSessionService } from "./session-service.js";
2
2
  import { CastDiscovery } from "../discovery/index.js";
3
3
  import { CastClient } from "../client/index.js";
4
- import { CastPresentationHandler } from "./presentation-handler.js";
5
- /** Availability watches kept per webContents; the page never releases one, so the oldest are dropped. */
4
+ import { CastPresentationHandler, PresentationError } from "./presentation-handler.js";
5
+ import { randomBytes, randomUUID } from "node:crypto";
6
+ import { MediaRouteError, combineSources, createManagerApi, createSinksObservers, presentationUrlForDevice, } from "./manager-api.js";
7
+ import { parsePresentationUrl } from "./presentation-envelope.js";
8
+ import { DefaultPresentationRequests, samePresentationRequest } from "./default-presentation.js";
9
+ import { MAX_MESSAGE_SIZE, asBytes, messageFields } from "./wired-display/local-presentation.js";
10
+ import { createWiredDisplay, isWiredDisplaySource } from "./wired-display/index.js";
11
+ import { DiscoveryNetworkMonitor, NETWORK_ID_DISCONNECTED } from "./network-monitor.js";
12
+ import { MirroringManager, MirroringRouteError } from "../mirroring/mirroring-manager.js";
13
+ import { createElectronMirroringServiceFactory } from "../mirroring/electron/host.js";
14
+ import { DialService } from "../dial/index.js";
15
+ import { appNameFromDialSource, isDialSource, processDeviceUuid } from "../dial/parse.js";
16
+ /**
17
+ * The methods a page may call over IPC: the bridge's own. The service also handles methods that only main calls
18
+ * (joinRunningSession, from the presentation handler), which a page must not reach directly.
19
+ */
20
+ const PAGE_METHODS = new Set([
21
+ "initialize", "requestSession", "joinSession", "sendMessage", "stopSession",
22
+ "leaveSession", "setReceiverVolume", "setReceiverMuted",
23
+ ]);
24
+ export { MediaRouteError } from "./manager-api.js";
25
+ export { createReceiverWindows, isWiredDisplaySource, availableDisplays, wiredDisplaySinks, } from "./wired-display/index.js";
26
+ export { AccessCodeCastDisabledError, createAccessCodeSink } from "./access-code.js";
27
+ /** Availability watches kept per frame; the page never releases one, so the oldest are dropped. */
6
28
  const MAX_WATCHES_PER_PAGE = 32;
29
+ /** Sender ids of subframes start here, far above any webContents id (a main frame's sender id is its webContents id). */
30
+ const SUBFRAME_ID_BASE = 2 ** 30;
31
+ /** How often removed iframes (which Electron does not announce) are noticed and their sessions released. */
32
+ const FRAME_SWEEP_MS = 5000;
7
33
  /** Largest page-to-receiver message accepted (Cast messages are capped at 64 KiB on the wire). */
8
34
  const MAX_MESSAGE_CHARS = 1 << 20;
9
35
  /** The sending frame's origin; null when there is no frame. An unparseable URL gives "" so allowOrigin decides. */
@@ -25,20 +51,260 @@ function originOf(frame) {
25
51
  * a sender that leaves its sessions when it is destroyed or navigates. Unless
26
52
  * `presentation: false` it also serves `<channel>:presentation` (see {@link CastManagerOptions.presentation}).
27
53
  */
54
+ /**
55
+ * A mirroring activity's view of the device's shared channel. Chrome runs every activity on a sink over its one
56
+ * `CastSocket`; here the activity's `connect()` only checks that channel is open and `close()` detaches the activity
57
+ * (its listeners go quiet) without closing the channel the other sessions and the session tracker use.
58
+ */
59
+ function sharedChannelClient(deviceId, channel) {
60
+ let attached = true;
61
+ const need = () => {
62
+ if (channel === undefined || !channel.connected)
63
+ throw new Error(`no open channel to ${deviceId}`);
64
+ if (channel.senderId === undefined)
65
+ throw new Error("the Cast client has no senderId, which mirroring needs");
66
+ return channel;
67
+ };
68
+ return {
69
+ get senderId() {
70
+ return channel?.senderId ?? "";
71
+ },
72
+ async connect() {
73
+ need();
74
+ },
75
+ close() {
76
+ attached = false;
77
+ },
78
+ send: (namespace, destinationId, payload) => {
79
+ if (attached)
80
+ need().send(namespace, destinationId, payload);
81
+ },
82
+ launch: (appId) => need().launch(appId),
83
+ stop: (sessionId) => need().stop(sessionId),
84
+ connectTransport: (transportId) => need().connectTransport(transportId),
85
+ closeTransport: (transportId) => need().closeTransport(transportId),
86
+ on(event, listener) {
87
+ channel?.on(event, (...args) => {
88
+ if (attached)
89
+ listener(...args);
90
+ });
91
+ return this;
92
+ },
93
+ };
94
+ }
95
+ /** How long starting a default request on a DIAL sink waits for its app info, as a page's request does. */
96
+ const DIAL_APP_WAIT_MS = 5000;
97
+ /**
98
+ * The first `cast-dial:` URL, in order, whose app the DIAL sink has for a page at `origin`. Apps not known yet are
99
+ * asked about and the answers waited for (up to 5 s), as the Cast path asks the device (`checkAppAvailability`).
100
+ */
101
+ async function dialUrlFor(dial, device, urls, origin) {
102
+ const candidates = urls.map((url) => ({ url, app: isDialSource(url) ? appNameFromDialSource(url) : "" })).filter((c) => c.app !== "");
103
+ const first = () => candidates.find((c) => dial.availableFor(c.app, origin).some((d) => d.id === device.id))?.url ?? null;
104
+ if (candidates.length === 0 || first() !== null)
105
+ return first();
106
+ const releases = candidates.map((c) => dial.monitorApp(c.app, origin)).filter((r) => r !== null);
107
+ if (releases.length === 0)
108
+ return null;
109
+ try {
110
+ await new Promise((resolve) => {
111
+ const done = () => {
112
+ clearTimeout(timer);
113
+ dial.off("change", check);
114
+ resolve();
115
+ };
116
+ const check = () => {
117
+ if (first() !== null)
118
+ done();
119
+ };
120
+ const timer = setTimeout(done, DIAL_APP_WAIT_MS);
121
+ dial.on("change", check);
122
+ });
123
+ }
124
+ finally {
125
+ for (const release of releases)
126
+ release();
127
+ }
128
+ return first();
129
+ }
28
130
  export function createCastManager(options) {
29
131
  const channel = options.channel ?? "electron-cast";
30
132
  if (options.presentation !== false && (typeof options.ipcMain.on !== "function" || typeof options.ipcMain.removeListener !== "function")) {
31
133
  throw new TypeError("presentation mode needs ipcMain.on and ipcMain.removeListener");
32
134
  }
33
135
  const discovery = options.discovery ?? new CastDiscovery();
34
- const createClient = options.createClient ?? ((d) => new CastClient({ host: d.host, port: d.port }));
35
- const contents = new Map();
136
+ const networkMonitor = options.networkMonitor === false ? undefined
137
+ : options.networkMonitor ?? (options.discovery === undefined ? new DiscoveryNetworkMonitor() : undefined);
138
+ const createClient = options.createClient ?? ((d, params) => new CastClient({
139
+ host: d.host,
140
+ port: d.port,
141
+ verifyDevice: options.verifyDevices !== false,
142
+ connectTimeoutMs: params.connectTimeoutMs,
143
+ heartbeatTimeoutMs: params.livenessTimeoutMs,
144
+ heartbeatIntervalMs: params.pingIntervalMs,
145
+ }));
146
+ // The receiver labels of Cast and DIAL routes are hashed with one per-process token, as in Chrome.
147
+ const hashToken = randomBytes(16).toString("hex");
148
+ const dialOption = options.dial ?? (options.discovery === undefined);
149
+ // A DIAL sink whose processed UDN is a Cast sink's id is removed: CastMediaSinkServiceImpl removes it from the DIAL
150
+ // sink service when the Cast channel opens (OnChannelOpenSucceeded) and when the DIAL sink comes after the Cast one
151
+ // (TryConnectDialDiscoveredSink), and only DIAL discovery adds it back. A Cast sink is a device with an open, authenticated channel, not one mDNS merely
152
+ // heard, so this asks the session service; `service` exists before DIAL is started.
153
+ let castSinks = () => [];
154
+ const dial = dialOption === false ? undefined : new DialService({
155
+ hashToken,
156
+ isCastDevice: (uuid) => castSinks().some((d) => processDeviceUuid(d.id) === uuid),
157
+ ...(typeof dialOption === "object" ? dialOption : {}),
158
+ });
159
+ const routeListeners = new Set();
160
+ const notifyRoutes = () => {
161
+ for (const l of [...routeListeners])
162
+ l();
163
+ };
164
+ dial?.provider.on("routes", notifyRoutes);
165
+ // DIAL discovery follows the connection itself, as Chrome's DialRegistry observes the NetworkConnectionTracker.
166
+ const unobserveDialNetwork = dial === undefined || networkMonitor === undefined ? () => { }
167
+ : networkMonitor.observe((networkId) => dial.networksChanged(networkId !== NETWORK_ID_DISCONNECTED));
168
+ /** The DIAL sinks as a device source: their one change event stands for a changed device. */
169
+ const dialSource = dial === undefined ? undefined : {
170
+ devices: () => dial.devices(),
171
+ on: (event, listener) => (event === "deviceChanged" ? dial.on("change", listener) : undefined),
172
+ off: (event, listener) => (event === "deviceChanged" ? dial.off("change", listener) : undefined),
173
+ };
174
+ const senders = new Map();
175
+ const subframeIds = new Map(); // frameTreeNodeId -> sender id
176
+ const watched = new Set(); // webContents ids
177
+ let nextSubframeId = SUBFRAME_ID_BASE;
178
+ let sweepTimer;
36
179
  let handler;
180
+ /** Each window's default presentation request (Chrome keeps it per WebContents, from its outermost frame only). */
181
+ const defaults = new DefaultPresentationRequests();
182
+ /** The route each window's main frame launched last (CastActivityManager's routes_by_frame_). */
183
+ const launchedFrom = new Map();
184
+ const findFrame = (wc, frameTreeNodeId) => {
185
+ try {
186
+ return wc.mainFrame?.framesInSubtree.find((f) => f.frameTreeNodeId === frameTreeNodeId);
187
+ }
188
+ catch {
189
+ return undefined; // the webContents is gone
190
+ }
191
+ };
192
+ const isMainFrame = (frame) => frame.parent === undefined || frame.parent === null;
193
+ /**
194
+ * The sender id of an IPC event's frame, without registering it; undefined when it is not a known sender. An event
195
+ * with no `senderFrame` property at all is the main frame's; a null one is a frame that is already gone.
196
+ */
197
+ const senderIdOf = (wc, frame) => {
198
+ if (frame === undefined)
199
+ return wc.id;
200
+ if (frame === null)
201
+ return undefined;
202
+ if (isMainFrame(frame))
203
+ return wc.id;
204
+ return typeof frame.frameTreeNodeId === "number" ? subframeIds.get(frame.frameTreeNodeId) : undefined;
205
+ };
206
+ /** The sender id of an IPC event's frame, registering a subframe (and watching its webContents) on first use. */
207
+ const registerSender = (wc, frame) => {
208
+ if (isMainFrame(frame)) {
209
+ watch(wc);
210
+ if (!senders.has(wc.id))
211
+ senders.set(wc.id, { wc, frameTreeNodeId: null });
212
+ return wc.id;
213
+ }
214
+ const node = frame.frameTreeNodeId;
215
+ if (typeof node !== "number")
216
+ return null;
217
+ watch(wc);
218
+ let id = subframeIds.get(node);
219
+ if (id === undefined) {
220
+ id = nextSubframeId++;
221
+ subframeIds.set(node, id);
222
+ senders.set(id, { wc, frameTreeNodeId: node });
223
+ sweepTimer ??= setInterval(sweepFrames, FRAME_SWEEP_MS);
224
+ sweepTimer.unref?.();
225
+ }
226
+ return id;
227
+ };
228
+ /** Forget a subframe sender for good: its connections, watches and sessions end. */
229
+ const dropSubframe = (id) => {
230
+ const entry = senders.get(id);
231
+ if (entry === undefined || entry.frameTreeNodeId === null)
232
+ return;
233
+ presentation?.senderGone(id);
234
+ senders.delete(id);
235
+ subframeIds.delete(entry.frameTreeNodeId);
236
+ service.senderGone(id);
237
+ if (subframeIds.size === 0 && sweepTimer !== undefined) {
238
+ clearInterval(sweepTimer);
239
+ sweepTimer = undefined;
240
+ }
241
+ };
242
+ /** Drop subframe senders whose frame was removed (Electron announces neither an iframe's removal nor its page's). */
243
+ function sweepFrames() {
244
+ for (const [id, entry] of [...senders]) {
245
+ if (entry.frameTreeNodeId === null)
246
+ continue;
247
+ if (entry.wc.isDestroyed() || findFrame(entry.wc, entry.frameTreeNodeId) === undefined)
248
+ dropSubframe(id);
249
+ }
250
+ }
251
+ /** Send to the one frame that owns the sender; a frame that is gone ends the sender. */
252
+ const deliver = (senderId, ch, payload) => {
253
+ const entry = senders.get(senderId);
254
+ if (entry === undefined || entry.wc.isDestroyed())
255
+ return;
256
+ try {
257
+ if (entry.frameTreeNodeId === null) {
258
+ entry.wc.send(ch, payload);
259
+ return;
260
+ }
261
+ const frame = findFrame(entry.wc, entry.frameTreeNodeId);
262
+ if (frame?.send === undefined) {
263
+ queueMicrotask(() => dropSubframe(senderId)); // not inside the service's own emit
264
+ return;
265
+ }
266
+ frame.send(ch, payload);
267
+ }
268
+ catch {
269
+ // the webContents or frame was destroyed between the check and the send
270
+ }
271
+ };
272
+ /**
273
+ * Starts whose URLs a display and a Cast device can both serve, while their picker is open. The one picker lists both kinds
274
+ * of sink, as Chrome's dialog does; a display chosen in it is recorded here and the Cast flow is told the user cancelled.
275
+ */
276
+ const mixedStarts = new Map();
277
+ /** Tab and desktop mirroring, when the `mirroring` option is given (set up once the service exists). */
278
+ let mirroring;
37
279
  const service = new CastSessionService({
38
280
  devices: discovery,
39
281
  createClient,
40
- selectDevice: options.selectDevice,
282
+ // a mirroring route's session, or one being launched on the sink, is a local activity
283
+ ownsSession: (sessionId, sinkId) => mirroring?.routes().some((r) => r.sinkId === sinkId && (r.sessionId === sessionId || r.sessionId === "")) ?? false,
284
+ async selectDevice(devices, request, picker) {
285
+ const mixed = mixedStarts.get(request.senderId);
286
+ const choice = await options.selectDevice(devices, mixed === undefined ? request : { ...request, displays: mixed.displays }, picker);
287
+ if (typeof choice === "object" && choice !== null && "display" in choice) {
288
+ if (mixed !== undefined && mixed.displays.some((d) => d.id === choice.display))
289
+ mixed.chosen = choice.display;
290
+ return null;
291
+ }
292
+ return choice;
293
+ },
41
294
  allowOrigin: options.allowOrigin,
295
+ sinks: options.sinks,
296
+ ...(dial !== undefined && dialSource !== undefined ? {
297
+ dial: {
298
+ source: dialSource,
299
+ available: (app, origin) => dial.availableFor(app, origin),
300
+ monitor: (app, origin) => dial.monitorApp(app, origin),
301
+ },
302
+ } : {}),
303
+ accessCode: options.accessCode,
304
+ ...(networkMonitor !== undefined ? { networkMonitor } : {}),
305
+ // The same one-route-per-frame rule (`routes_by_frame_`) from the other side: a page's Cast SDK or Presentation API
306
+ // session ends a mirroring route of that page. Subframe sender ids never match a tab, as only the main frame is one.
307
+ onSessionLaunched: (senderId) => mirroring?.stopMirroringRoutesOfTab(senderId),
42
308
  emit(senderId, event) {
43
309
  try {
44
310
  handler?.onServiceEvent(senderId, event);
@@ -46,69 +312,82 @@ export function createCastManager(options) {
46
312
  catch (err) {
47
313
  console.error("electron-cast: presentation handler failed on a service event", err);
48
314
  }
49
- const wc = contents.get(senderId);
50
- if (wc === undefined || wc.isDestroyed())
51
- return;
52
- try {
53
- wc.send(`${channel}:event`, event);
54
- }
55
- catch {
56
- // the webContents was destroyed between the check and the send
57
- }
315
+ deliver(senderId, `${channel}:event`, event);
58
316
  },
59
317
  });
60
- /** Record a webContents on first use and watch it once. */
61
- const watch = (wc) => {
62
- if (contents.has(wc.id))
318
+ /** Watch a webContents once: its destruction and its navigations end or park its senders. */
319
+ function watch(wc) {
320
+ if (watched.has(wc.id))
63
321
  return;
64
- contents.set(wc.id, wc);
322
+ watched.add(wc.id);
323
+ const subframes = () => [...senders].filter(([, e]) => e.wc === wc && e.frameTreeNodeId !== null).map(([id]) => id);
65
324
  wc.once("destroyed", () => {
325
+ watched.delete(wc.id);
326
+ for (const id of subframes())
327
+ dropSubframe(id);
66
328
  presentation?.senderGone(wc.id);
67
- contents.delete(wc.id);
329
+ defaults.forget(wc.id);
330
+ senders.delete(wc.id);
68
331
  service.senderGone(wc.id);
69
332
  });
70
333
  // A navigation ends the page's connections, but its sessions stay open (parked) so the next page can rejoin them
71
334
  wc.on("did-navigate", () => {
72
335
  presentation?.senderGone(wc.id);
73
336
  service.senderNavigated(wc.id);
337
+ for (const id of subframes())
338
+ dropSubframe(id); // the page's iframes went with it
74
339
  });
75
- };
340
+ // An iframe that navigates on its own is treated the same way (the main frame is handled above).
341
+ wc.on("did-frame-navigate", (_event, _url, _code, _text, mainFrame, processId, routingId) => {
342
+ if (mainFrame === true)
343
+ return;
344
+ const frame = wc.mainFrame?.framesInSubtree.find((f) => f.processId === processId && f.routingId === routingId);
345
+ const id = typeof frame?.frameTreeNodeId === "number" ? subframeIds.get(frame.frameTreeNodeId) : undefined;
346
+ if (id !== undefined) {
347
+ presentation?.senderGone(id);
348
+ service.senderNavigated(id);
349
+ }
350
+ sweepFrames();
351
+ });
352
+ }
76
353
  options.ipcMain.handle(`${channel}:call`, (event, method, params) => {
77
354
  const origin = originOf(event.senderFrame);
78
- if (origin === null) {
355
+ if (origin === null || event.senderFrame === null) {
79
356
  return Promise.resolve({ ok: false, code: "extension_missing", description: "No sender frame" });
80
357
  }
81
- watch(event.sender);
82
- return service.handle({ id: event.sender.id, origin }, method, params);
358
+ // mode "chromecast" is main-frame only; iframes are served in presentation mode, as in Chrome
359
+ if (!isMainFrame(event.senderFrame)) {
360
+ return Promise.resolve({ ok: false, code: "extension_missing", description: "chrome.cast is not available in iframes; use presentation mode" });
361
+ }
362
+ if (typeof method !== "string" || !PAGE_METHODS.has(method)) {
363
+ return Promise.resolve({ ok: false, code: "invalid_parameter", description: `unknown method: ${String(method)}` });
364
+ }
365
+ const id = registerSender(event.sender, event.senderFrame);
366
+ return service.handle({ id, origin }, method, params);
83
367
  });
368
+ const wired = options.wiredDisplay !== undefined && options.presentation !== false ? createWiredDisplay(options.wiredDisplay) : undefined;
84
369
  /** Presentation mode: IPC for the page's stand-in Presentation API, answered by a CastPresentationHandler. */
85
370
  const setUpPresentation = () => {
86
371
  const ipc = options.ipcMain;
87
372
  const on = ipc.on.bind(ipc);
88
373
  const off = ipc.removeListener.bind(ipc);
89
- const h = new CastPresentationHandler({ service });
374
+ const h = new CastPresentationHandler({ service, token: hashToken, ...(dial !== undefined ? { dial } : {}), dialRoutesChanged: notifyRoutes });
90
375
  handler = h;
91
376
  const connections = new Map();
92
377
  const watches = new Map();
93
- const sendTo = (wcId, payload) => {
94
- const wc = contents.get(wcId);
95
- if (wc === undefined || wc.isDestroyed())
96
- return;
97
- try {
98
- wc.send(`${channel}:presentation:event`, payload);
99
- }
100
- catch {
101
- // destroyed between the check and the send
102
- }
378
+ const sendTo = (sid, payload) => {
379
+ deliver(sid, `${channel}:presentation:event`, payload);
103
380
  };
104
381
  const invalid = (description) => ({ ok: false, code: "InvalidAccessError", description });
105
382
  const isId = (v) => typeof v === "string" && v !== "" && v.length <= 256;
106
383
  const isUrls = (v) => Array.isArray(v) && v.length > 0 && v.length <= 16 && v.every((u) => typeof u === "string");
107
384
  /** Finish a start/reconnect: register the connection and route its traffic to the page. */
108
- const open = async (wcId, connectionId, opening) => {
385
+ const open = async (sid, connectionId, opening,
386
+ /** Runs once the connection exists and before any of its messages reach the page; false declines it. */
387
+ opened) => {
109
388
  if (connections.has(connectionId))
110
389
  return invalid("connectionId in use");
111
- const slot = { conn: null, wcId };
390
+ const slot = { conn: null, sid };
112
391
  connections.set(connectionId, slot); // reserved while the picker or join is pending
113
392
  let conn;
114
393
  try {
@@ -121,26 +400,89 @@ export function createCastManager(options) {
121
400
  const name = typeof e?.name === "string" && e.name !== "" && e.name !== "Error" ? e.name : "OperationError";
122
401
  return { ok: false, code: name, description: typeof e?.message === "string" ? e.message : String(err) };
123
402
  }
124
- if (!contents.has(wcId) || connections.get(connectionId) !== slot) {
403
+ if (!senders.has(sid) || connections.get(connectionId) !== slot) {
125
404
  conn.close();
126
405
  return { ok: false, code: "AbortError", description: "The page went away" };
127
406
  }
128
407
  slot.conn = conn;
408
+ // A wired display connection starts out connecting, as Blink's does, and connects when the receiver page is ready
409
+ const local = conn;
410
+ if (typeof local.connecting === "boolean") {
411
+ conn.onconnect = () => sendTo(sid, { type: "statechange", connectionId, state: "connected" });
412
+ }
129
413
  conn.onclose = (state) => {
130
414
  if (connections.get(connectionId) === slot)
131
415
  connections.delete(connectionId);
132
- sendTo(wcId, { type: "statechange", connectionId, state });
416
+ sendTo(sid, { type: "statechange", connectionId, state });
133
417
  };
418
+ if (opened?.(conn) === false) {
419
+ // Declined (OnPresentationResponse hands a connection only to the request it answers): the session stays, but the
420
+ // connection belongs to nobody, so nothing of it reaches the page that has the sender id now
421
+ connections.delete(connectionId);
422
+ conn.onclose = null;
423
+ conn.onmessage = () => { };
424
+ return { ok: true, value: { id: conn.id, url: conn.url } };
425
+ }
134
426
  // The stand-in registered this connectionId before calling, so it buffers anything sent before the reply.
135
- conn.onmessage = (data) => sendTo(wcId, { type: "message", connectionId, data });
136
- return { ok: true, value: { id: conn.id, url: conn.url } };
427
+ if (typeof local.connecting === "boolean") {
428
+ conn.onmessage = (data) => sendTo(sid, { type: "message", connectionId, ...messageFields(data) });
429
+ }
430
+ else {
431
+ conn.onmessage = (data) => sendTo(sid, { type: "message", connectionId, data });
432
+ }
433
+ return { ok: true, value: { id: conn.id, url: conn.url, ...(local.connecting === true ? { state: "connecting" } : {}), ...(typeof local.connecting === "boolean" ? { local: true } : {}) } };
434
+ };
435
+ /** A start() whose URLs only a display can show: the app picks a display, a window opens on it. */
436
+ const startOnDisplay = async (sid, origin, urls) => {
437
+ const w = wired;
438
+ const wc = senders.get(sid)?.wc;
439
+ const sinks = w.sinksFor(wc);
440
+ const request = { urls: [...urls], origin, senderId: sid, observeSinks: (l) => w.observeSinksFor(wc, l) };
441
+ const choice = await w.selectDisplay(sinks, request);
442
+ if (choice === null)
443
+ throw new PresentationError("AbortError", "The user cancelled the request");
444
+ return w.controllers.start(request, choice);
445
+ };
446
+ /** A URL the Cast provider serves (a Cast app URL), or the DIAL provider (a `cast-dial:` URL, when DIAL is on). */
447
+ const providerUrl = (u) => parsePresentationUrl(u) !== null || (dial !== undefined && isDialSource(u));
448
+ /** The URLs of a request that the Cast and DIAL providers serve. */
449
+ const castUrlsOf = (urls) => urls.filter(providerUrl);
450
+ /**
451
+ * A start() whose URLs a display and a Cast device can both serve: one picker offers both kinds and the sink it returns
452
+ * decides (a display starts a wired display presentation, a device the Cast flow). With no displays or no devices there
453
+ * is nothing to choose between and the flow of the one kind that exists runs.
454
+ */
455
+ const startMixed = async (sid, origin, urls) => {
456
+ const w = wired;
457
+ const wc = senders.get(sid)?.wc;
458
+ const displays = w.sinksFor(wc);
459
+ const castUrls = castUrlsOf(urls);
460
+ if (displays.length === 0 || service.devices().length + (dial?.devices().length ?? 0) === 0) {
461
+ return displays.length > 0 ? startOnDisplay(sid, origin, urls) : h.startPresentation({ urls: castUrls, origin, senderId: sid });
462
+ }
463
+ const mixed = { displays, chosen: null };
464
+ mixedStarts.set(sid, mixed);
465
+ try {
466
+ return await h.startPresentation({ urls: castUrls, origin, senderId: sid });
467
+ }
468
+ catch (err) {
469
+ if (mixed.chosen === null)
470
+ throw err;
471
+ return w.controllers.start({ urls: [...urls], origin, senderId: sid }, mixed.chosen);
472
+ }
473
+ finally {
474
+ mixedStarts.delete(sid);
475
+ }
137
476
  };
477
+ /** Only a display serves these URLs: one is a standard presentation source and none is a Cast or DIAL one. */
478
+ const displayOnly = (urls) => wired !== undefined && urls.some((u) => isWiredDisplaySource(u)) && !urls.some(providerUrl);
138
479
  ipc.handle(`${channel}:presentation`, async (event, method, params) => {
139
480
  const origin = originOf(event.senderFrame);
140
- if (origin === null)
481
+ if (origin === null || event.senderFrame === null)
141
482
  return { ok: false, code: "NotAllowedError", description: "No sender frame" };
142
- watch(event.sender);
143
- const wcId = event.sender.id;
483
+ const sid = registerSender(event.sender, event.senderFrame);
484
+ if (sid === null)
485
+ return { ok: false, code: "NotAllowedError", description: "Unidentifiable sender frame" };
144
486
  const p = (typeof params === "object" && params !== null ? params : {});
145
487
  try {
146
488
  switch (method) {
@@ -149,29 +491,74 @@ export function createCastManager(options) {
149
491
  return invalid("getAvailability expects { watchId, urls }");
150
492
  const watchId = p.watchId;
151
493
  const old = watches.get(watchId);
152
- if (old !== undefined && old.wcId !== wcId)
494
+ if (old !== undefined && old.sid !== sid)
153
495
  return invalid("watchId in use");
154
496
  old?.ac.abort();
155
497
  watches.delete(watchId);
156
- const mine = [...watches].filter(([, w]) => w.wcId === wcId);
498
+ const mine = [...watches].filter(([, w]) => w.sid === sid);
157
499
  for (const [id, w] of mine.slice(0, Math.max(0, mine.length - (MAX_WATCHES_PER_PAGE - 1)))) {
158
500
  w.ac.abort();
159
501
  watches.delete(id);
160
502
  }
161
503
  const ac = new AbortController();
162
- watches.set(watchId, { ac, wcId });
504
+ watches.set(watchId, { ac, sid });
505
+ if (wired !== undefined && p.urls.some((u) => isWiredDisplaySource(u))) {
506
+ // Blink ORs the sources of a request: available when displays exist for a standard source, or the
507
+ // request's Cast URLs have a device. Displays are not hidden here (only the dialog hides one).
508
+ const castUrls = p.urls.filter((u) => !isWiredDisplaySource(u));
509
+ let displays = false;
510
+ let cast = false;
511
+ let ready = false;
512
+ let last = false;
513
+ const update = () => {
514
+ const next = displays || cast;
515
+ if (!ready || next === last)
516
+ return;
517
+ last = next;
518
+ sendTo(sid, { type: "availability", watchId, value: next });
519
+ };
520
+ const stop = wired.provider.observeSinks((sinks) => {
521
+ displays = sinks.length > 0;
522
+ update();
523
+ });
524
+ ac.signal.addEventListener("abort", stop, { once: true });
525
+ if (ac.signal.aborted)
526
+ stop();
527
+ if (castUrls.length > 0) {
528
+ cast = await h.getAvailability({
529
+ urls: castUrls, origin, senderId: sid, signal: ac.signal,
530
+ onchange: (value) => {
531
+ cast = value;
532
+ update();
533
+ },
534
+ });
535
+ }
536
+ ready = true;
537
+ last = displays || cast;
538
+ return { ok: true, value: { available: last } };
539
+ }
163
540
  const available = await h.getAvailability({
164
541
  urls: p.urls,
165
542
  origin,
166
- senderId: wcId,
543
+ senderId: sid,
167
544
  signal: ac.signal,
168
- onchange: (value) => sendTo(wcId, { type: "availability", watchId, value }),
545
+ onchange: (value) => sendTo(sid, { type: "availability", watchId, value }),
169
546
  });
170
547
  return { ok: true, value: { available } };
171
548
  }
549
+ case "setDefaultRequest": {
550
+ // Blink's Presentation::setDefaultRequest sends the URLs on every set (none when it is cleared)
551
+ if (!Array.isArray(p.urls) || p.urls.length > 16 || !p.urls.every((u) => typeof u === "string" && u.length <= 4096)) {
552
+ return invalid("setDefaultRequest expects { urls }");
553
+ }
554
+ // PresentationServiceImpl::SetDefaultPresentationUrls ignores a frame that is not the outermost document
555
+ if (isMainFrame(event.senderFrame))
556
+ defaults.set(event.sender.id, p.urls, origin);
557
+ return { ok: true, value: undefined };
558
+ }
172
559
  case "stopWatching": {
173
560
  const w = isId(p.watchId) ? watches.get(p.watchId) : undefined;
174
- if (w !== undefined && w.wcId === wcId) {
561
+ if (w !== undefined && w.sid === sid) {
175
562
  w.ac.abort();
176
563
  watches.delete(p.watchId);
177
564
  }
@@ -180,9 +567,23 @@ export function createCastManager(options) {
180
567
  case "start":
181
568
  if (!isId(p.connectionId) || !isUrls(p.urls))
182
569
  return invalid("start expects { connectionId, urls }");
570
+ // PresentationServiceImpl::StartPresentation: PRESENTATION_REQUEST_CANCELLED, which the page sees as AbortError
571
+ if (p.hasGesture !== true) {
572
+ return { ok: false, code: "AbortError", description: "PresentationRequest::start() requires user gesture." };
573
+ }
183
574
  {
184
575
  const urls = p.urls;
185
- return await open(wcId, p.connectionId, () => h.startPresentation({ urls, origin, senderId: wcId }));
576
+ // A display-only request opens a window on a display; a request a display and a sink can both serve goes to
577
+ // the one picker; the rest is the Cast (and DIAL) provider's
578
+ if (displayOnly(urls))
579
+ return await open(sid, p.connectionId, () => startOnDisplay(sid, origin, urls));
580
+ const started = wired !== undefined && urls.some((u) => isWiredDisplaySource(u))
581
+ ? await open(sid, p.connectionId, () => startMixed(sid, origin, urls))
582
+ : await open(sid, p.connectionId, () => h.startPresentation({ urls, origin, senderId: sid }));
583
+ // CastActivityManager's earlier-route rule is for Cast sessions only
584
+ if (started.ok && started.value.id.startsWith("cast-session_"))
585
+ launchedFrom.set(sid, started.value.id.slice("cast-session_".length));
586
+ return started;
186
587
  }
187
588
  case "reconnect":
188
589
  if (!isId(p.connectionId) || !isUrls(p.urls) || !isId(p.presentationId)) {
@@ -190,12 +591,17 @@ export function createCastManager(options) {
190
591
  }
191
592
  {
192
593
  const { urls, presentationId } = p;
193
- return await open(wcId, p.connectionId, () => h.reconnectPresentation({ urls, origin, senderId: wcId, presentationId }));
594
+ // A local presentation (a display) is joined again from any page, by its id; for a URL only a display
595
+ // serves, an id that is not local is the provider's unknown error, which the page sees as NotFoundError
596
+ if (wired !== undefined && (displayOnly(urls) || wired.provider.local.isLocalPresentation(presentationId))) {
597
+ return await open(sid, p.connectionId, async () => wired.controllers.reconnect({ urls, senderId: sid }, presentationId));
598
+ }
599
+ return await open(sid, p.connectionId, () => h.reconnectPresentation({ urls: wired !== undefined && castUrlsOf(urls).length > 0 ? castUrlsOf(urls) : urls, origin, senderId: sid, presentationId }));
194
600
  }
195
601
  case "close":
196
602
  case "terminate": {
197
603
  const c = isId(p.connectionId) ? connections.get(p.connectionId) : undefined;
198
- if (c !== undefined && c.wcId === wcId && c.conn !== null) {
604
+ if (c !== undefined && c.sid === sid && c.conn !== null) {
199
605
  if (method === "close")
200
606
  c.conn.close();
201
607
  else
@@ -212,30 +618,135 @@ export function createCastManager(options) {
212
618
  }
213
619
  });
214
620
  const onSend = (event, connectionId, data) => {
215
- if (typeof connectionId !== "string" || typeof data !== "string")
621
+ if (typeof connectionId !== "string")
216
622
  return;
217
623
  const c = connections.get(connectionId);
218
- if (c === undefined || c.wcId !== event.sender.id || c.conn === null)
624
+ if (c === undefined || c.sid !== senderIdOf(event.sender, event.senderFrame) || c.conn === null)
219
625
  return;
220
- if (data.length > MAX_MESSAGE_CHARS)
626
+ const isLocal = typeof c.conn.connecting === "boolean";
627
+ if (typeof data === "string") {
628
+ // The stand-in refuses an oversized send() with a RangeError; this is for a page that does not use it
629
+ if (data.length <= (isLocal ? MAX_MESSAGE_SIZE : MAX_MESSAGE_CHARS))
630
+ c.conn.send(data);
631
+ return;
632
+ }
633
+ const bytes = asBytes(data);
634
+ if (bytes === null || bytes.byteLength > MAX_MESSAGE_SIZE)
221
635
  return;
222
- c.conn.send(data);
636
+ // A wired display carries bytes (PresentationConnectionMessage.data). A Cast connection drops them, as Chrome's
637
+ // CastSessionClientImpl::OnMessage does with anything that is not text.
638
+ if (isLocal)
639
+ c.conn.send(bytes);
223
640
  };
224
641
  on(`${channel}:presentation:send`, onSend);
225
642
  return {
226
643
  /** Close the page's connections and watches before the service drops it. */
227
- senderGone(wcId) {
228
- h.senderGone(wcId);
644
+ senderGone(sid) {
645
+ // PresentationServiceImpl::Reset (navigation, frame gone): the frame's default request goes with it
646
+ defaults.clear(sid);
647
+ launchedFrom.delete(sid);
648
+ h.senderGone(sid);
649
+ wired?.controllers.senderGone(sid);
229
650
  for (const [id, c] of connections)
230
- if (c.wcId === wcId)
651
+ if (c.sid === sid)
231
652
  connections.delete(id);
232
653
  for (const [id, w] of watches) {
233
- if (w.wcId !== wcId)
654
+ if (w.sid !== sid)
234
655
  continue;
235
656
  w.ac.abort();
236
657
  watches.delete(id);
237
658
  }
238
659
  },
660
+ /**
661
+ * MediaRouterUI::StartCasting(sink, PRESENTATION) on the window's default request: MediaRouteStarter's
662
+ * CreateRouteParameters, MediaRouter::CreateRoute, then WebContentsPresentationManager::OnPresentationResponse.
663
+ */
664
+ async startDefaultPresentation(webContentsId, sinkId) {
665
+ const request = defaults.get(webContentsId);
666
+ const serial = defaults.serialOf(webContentsId);
667
+ // No source for the sink (no default request, or its URLs do not suit the sink): CreateRouteParameters is null
668
+ const unable = (why) => new MediaRouteError("unable_to_cast", why);
669
+ if (request === null)
670
+ throw unable("the window has no default presentation request");
671
+ // The dialog's sinks are the Cast sinks and the DIAL sinks (QueryResultManager observes each URL's source, and
672
+ // the DIAL provider serves the cast-dial: ones)
673
+ const device = [...service.devices(), ...(dial?.devices() ?? [])].find((d) => d.id === sinkId);
674
+ if (device === undefined)
675
+ throw unable(`no sink ${sinkId}`);
676
+ // GetSourceForCastModeAndSink: the first URL, in order, the sink is compatible with. A Cast sink is a source's
677
+ // once the device says the app is there (CastAppAvailabilityTracker::GetAvailableSinks); a DIAL sink once its
678
+ // DIAL server says so for the page's origin (DialMediaSinkServiceImpl, DialMediaRouteProvider::GetOrigins).
679
+ let url = null;
680
+ if (device.dial !== undefined) {
681
+ url = dial === undefined ? null : await dialUrlFor(dial, device, request.presentationUrls, request.frameOrigin);
682
+ }
683
+ else {
684
+ for (const candidate of request.presentationUrls) {
685
+ const parsed = parsePresentationUrl(candidate);
686
+ if (parsed === null || presentationUrlForDevice(device, [candidate]) === null)
687
+ continue;
688
+ if (await service.checkAppAvailability(device, parsed.appId)) {
689
+ url = candidate;
690
+ break;
691
+ }
692
+ }
693
+ }
694
+ if (url === null)
695
+ throw unable("the sink cannot run the default presentation request's URLs");
696
+ // the page navigated or cleared its request while the device was asked
697
+ if (defaults.serialOf(webContentsId) !== serial) {
698
+ throw new MediaRouteError("cancelled", "the window's default presentation request changed while the device was asked");
699
+ }
700
+ // CastActivityManager::DoLaunchSession stops the route this frame launched before, then launches
701
+ const earlier = launchedFrom.get(webContentsId);
702
+ if (earlier !== undefined && routes().some((r) => r.id === earlier))
703
+ void service.terminateSession(earlier);
704
+ if (!senders.has(webContentsId))
705
+ throw unable("the window is gone");
706
+ const connectionId = randomUUID();
707
+ let failure;
708
+ const result = await open(webContentsId, connectionId, () => h.startPresentation({
709
+ urls: [url, ...request.presentationUrls.filter((u) => u !== url)],
710
+ origin: request.frameOrigin,
711
+ senderId: webContentsId,
712
+ deviceId: device.id,
713
+ }).catch((err) => {
714
+ failure = err;
715
+ throw err;
716
+ }), (conn) => {
717
+ // OnPresentationResponse hands the connection to the page only while the request it answers is still the default one
718
+ const current = defaults.get(webContentsId);
719
+ if (current === null || !samePresentationRequest(current, request))
720
+ return false;
721
+ sendTo(webContentsId, { type: "connectionavailable", connectionId, id: conn.id, url: conn.url });
722
+ return true;
723
+ });
724
+ if (!result.ok) {
725
+ // RouteRequestResultCode, from the cause the handler saw
726
+ const bridge = failure?.bridgeCode;
727
+ const code = bridge === "timeout" ? "timed_out"
728
+ : bridge === "cancel" || (failure === undefined && result.code === "AbortError") ? "cancelled"
729
+ : bridge === "receiver_unavailable" ? "sink_not_found"
730
+ : bridge === "extension_missing" ? "invalid_origin"
731
+ : bridge === "invalid_parameter" ? "redundant_request"
732
+ : "unknown_error";
733
+ throw new MediaRouteError(code, result.description);
734
+ }
735
+ if (device.dial !== undefined) {
736
+ // A DIAL route's id is MediaRoute::GetMediaRouteId(presentation id, sink id, source)
737
+ const prefix = `urn:x-org.chromium:media:route:${result.value.id}/`;
738
+ const dialRoute = routes().find((r) => r.providerId === "dial" && r.id.startsWith(prefix));
739
+ if (dialRoute === undefined)
740
+ throw new MediaRouteError("route_not_found", `no route for ${result.value.id}`);
741
+ return dialRoute;
742
+ }
743
+ const sessionId = result.value.id.slice("cast-session_".length);
744
+ launchedFrom.set(webContentsId, sessionId);
745
+ const route = routes().find((r) => r.id === sessionId);
746
+ if (route === undefined)
747
+ throw new MediaRouteError("route_not_found", `no route ${sessionId}`);
748
+ return route;
749
+ },
239
750
  dispose() {
240
751
  ipc.removeHandler(`${channel}:presentation`);
241
752
  off(`${channel}:presentation:send`, onSend);
@@ -247,19 +758,221 @@ export function createCastManager(options) {
247
758
  };
248
759
  };
249
760
  const presentation = options.presentation !== false ? setUpPresentation() : undefined;
761
+ // The service knows frames by sender id (an iframe has a synthetic one); the API speaks of windows, so a route's
762
+ // pages are reported as `webContents.id`s, once each however many of its frames hold the route.
763
+ const windowIds = (ids) => [...new Set(ids.map((id) => senders.get(id)?.wc.id ?? id))];
764
+ // Tab and desktop mirroring: MirroringActivity, a CastActivity that runs on the device's one channel
765
+ let disposeMirroring;
766
+ if (options.mirroring !== undefined) {
767
+ const m = options.mirroring;
768
+ let createService;
769
+ if ("createService" in m) {
770
+ createService = m.createService;
771
+ }
772
+ else {
773
+ const electron = createElectronMirroringServiceFactory(m);
774
+ createService = electron.factory;
775
+ disposeMirroring = () => electron.dispose();
776
+ }
777
+ mirroring = new MirroringManager({
778
+ // only a sink (an open, authenticated channel) can be cast to
779
+ findDevice: (id) => service.devices().find((d) => d.id === id),
780
+ createClient: (d) => sharedChannelClient(d.id, service.channelClient(d.id)),
781
+ createService,
782
+ terminateRoutesOfPage: (wcId) => {
783
+ for (const id of service.sessionsLaunchedBy(wcId))
784
+ void service.terminateSession(id);
785
+ },
786
+ commandLine: "electron" in m ? m.electron.app?.commandLine : undefined,
787
+ log: (level, message) => (level === "error" ? console.error : console.debug)(`electron-cast mirroring: ${message}`),
788
+ });
789
+ }
790
+ const dialRoutes = () => (dial?.provider.routes() ?? []).map((r) => {
791
+ const members = windowIds(handler?.dialMembers(r.id) ?? []);
792
+ return {
793
+ id: r.id,
794
+ providerId: "dial",
795
+ mediaSource: r.mediaSource,
796
+ sinkId: r.sinkId,
797
+ sinkName: dial?.devices().find((d) => d.id === r.sinkId)?.name ?? "",
798
+ isLocal: true,
799
+ description: r.appName,
800
+ appId: "",
801
+ displayName: r.appName,
802
+ origin: r.origin,
803
+ volume: { level: null, muted: null },
804
+ members,
805
+ parkedSenders: [],
806
+ parked: members.length === 0,
807
+ };
808
+ });
809
+ const mirroringRoutes = () => (mirroring?.routes() ?? []).map((r) => ({
810
+ id: r.id,
811
+ providerId: "cast",
812
+ mediaSource: r.mediaSource,
813
+ sinkId: r.sinkId,
814
+ sinkName: service.devices().find((d) => d.id === r.sinkId)?.name ?? "",
815
+ isLocal: true,
816
+ description: r.description,
817
+ appId: r.appId,
818
+ displayName: r.displayName,
819
+ origin: "",
820
+ volume: { level: null, muted: null },
821
+ members: r.webContentsId === undefined ? [] : [r.webContentsId],
822
+ parkedSenders: [],
823
+ parked: false,
824
+ freezeInfo: r.freezeInfo,
825
+ }));
826
+ const routes = () => [
827
+ ...service.mediaRoutes().map((r) => ({ ...r, members: windowIds(r.members), parkedSenders: windowIds(r.parkedSenders) })),
828
+ ...dialRoutes(),
829
+ ...mirroringRoutes(),
830
+ ];
831
+ const isMirroringRoute = (id) => mirroring?.routes().some((r) => r.id === id) ?? false;
832
+ const isDialRoute = (id) => dial?.provider.routes().some((r) => r.id === id) ?? false;
833
+ const notDial = { ok: false, code: "invalid_parameter", description: "A DIAL route has no volume or media control" };
834
+ const castDevices = service.deviceSource();
835
+ const api = createManagerApi(createSinksObservers(dialSource === undefined ? castDevices : combineSources(castDevices, dialSource), {
836
+ cached: (d, appId) => service.cachedAppAvailability(d, appId),
837
+ check: (d, appId) => service.checkAppAvailability(d, appId),
838
+ ...(dial === undefined ? {} : {
839
+ dial: {
840
+ available: (d, app, origin) => dial.availableFor(app, origin).some((x) => x.id === d.id),
841
+ monitor: (app, origin) => dial.monitorApp(app, origin),
842
+ },
843
+ }),
844
+ }), {
845
+ mediaRoutes: routes,
846
+ observeSessions: (l) => {
847
+ const off = service.observeSessions(l);
848
+ const offMirroring = mirroring?.observe(l);
849
+ routeListeners.add(l);
850
+ return () => {
851
+ off();
852
+ offMirroring?.();
853
+ routeListeners.delete(l);
854
+ };
855
+ },
856
+ async terminateSession(id) {
857
+ if (mirroring?.terminate(id) === true)
858
+ return { ok: true, value: undefined };
859
+ if (!isDialRoute(id))
860
+ return service.terminateSession(id);
861
+ try {
862
+ await dial.provider.terminateRoute(id);
863
+ return { ok: true, value: undefined };
864
+ }
865
+ catch (err) {
866
+ const e = err;
867
+ return { ok: false, code: typeof e.code === "string" ? e.code : "session_error", description: String(e.message ?? err) };
868
+ }
869
+ },
870
+ setSessionVolume: async (id, v) => (isDialRoute(id) ? notDial : service.setSessionVolume(id, v)),
871
+ startCasting: mirroring === undefined
872
+ ? undefined
873
+ : async (sinkId, o) => {
874
+ const m = mirroring;
875
+ try {
876
+ const route = await m.startMirroring(sinkId, o);
877
+ const listed = routes().find((r) => r.id === route.id);
878
+ if (listed === undefined)
879
+ throw new MediaRouteError("route_not_found", `no route ${route.id}`);
880
+ return listed;
881
+ }
882
+ catch (err) {
883
+ if (err instanceof MirroringRouteError)
884
+ throw new MediaRouteError(err.code, err.message);
885
+ throw err;
886
+ }
887
+ },
888
+ detachSession(id) {
889
+ if (isMirroringRoute(id))
890
+ return { ok: false, code: "invalid_parameter", description: "A mirroring route cannot be detached" };
891
+ if (!isDialRoute(id))
892
+ return service.detachSession(id);
893
+ handler?.detachDialRoute(id);
894
+ return { ok: true, value: undefined };
895
+ },
896
+ sendSessionMessage: (id, ns, m) => (isDialRoute(id) ? notDial : service.sendSessionMessage(id, ns, m)),
897
+ observeSessionStatus: (l) => service.observeSessionStatus(l),
898
+ observeMediaStatus: (l) => service.observeMediaStatus(l),
899
+ sessionVolume: (id) => service.sessionVolume(id),
900
+ switchMirroringSourceTab: mirroring === undefined
901
+ ? undefined
902
+ : (id, webContentsId) => {
903
+ try {
904
+ mirroring.switchMirroringSourceTab(id, webContentsId);
905
+ }
906
+ catch (err) {
907
+ if (err instanceof MirroringRouteError)
908
+ throw new MediaRouteError(err.code, err.message);
909
+ throw err;
910
+ }
911
+ },
912
+ freezeRoute: (id) => mirroring?.freezeRoute(id) ?? false,
913
+ unfreezeRoute: (id) => mirroring?.unfreezeRoute(id) ?? false,
914
+ mirroringStats: mirroring === undefined
915
+ ? undefined
916
+ : {
917
+ get: (id) => mirroring.getMirroringStats(id),
918
+ setEnabled: (enabled) => mirroring.setMirroringStatsEnabled(enabled),
919
+ isEnabled: () => mirroring.isMirroringStatsEnabled(),
920
+ observe: (observer) => mirroring.observeMirroringStats(observer),
921
+ },
922
+ }, {
923
+ requests: defaults,
924
+ start: (webContentsId, sinkId) => {
925
+ if (presentation === undefined)
926
+ return Promise.reject(new MediaRouteError("unable_to_cast", "presentation mode is off"));
927
+ return presentation.startDefaultPresentation(webContentsId, sinkId);
928
+ },
929
+ });
930
+ // Cast sinks coming and going decide which DIAL sinks are shown; the DIAL sinks are looked up again.
931
+ castSinks = () => service.devices();
932
+ const castChanged = () => dial?.castDevicesChanged();
933
+ if (dial !== undefined)
934
+ for (const e of ["deviceUp", "deviceDown", "deviceChanged"])
935
+ castDevices.on(e, castChanged);
250
936
  let disposed = false;
251
937
  return {
252
- start: () => discovery.start(),
253
- devices: () => discovery.devices(),
938
+ ...api,
939
+ ...(wired !== undefined ? { wiredDisplay: wired.api } : {}),
940
+ async start() {
941
+ networkMonitor?.start();
942
+ await discovery.start();
943
+ dial?.start({ online: networkMonitor === undefined || networkMonitor.networkId() !== NETWORK_ID_DISCONNECTED });
944
+ },
945
+ devices: () => service.devices(),
946
+ discoverSinksNow: () => service.discoverSinksNow(),
947
+ settled: (options) => service.settled(options),
948
+ addSinkByAddress: (device) => service.addSinkByAddress(device),
949
+ configureAccessCode: (settings) => service.configureAccessCode(settings),
950
+ rememberedSinks: () => service.rememberedSinks(),
254
951
  async dispose() {
255
952
  if (disposed)
256
953
  return;
257
954
  disposed = true;
955
+ api.dispose();
956
+ defaults.dispose();
957
+ mirroring?.dispose();
958
+ disposeMirroring?.();
258
959
  options.ipcMain.removeHandler(`${channel}:call`);
259
960
  presentation?.dispose();
961
+ if (dial !== undefined)
962
+ for (const e of ["deviceUp", "deviceDown", "deviceChanged"])
963
+ castDevices.off(e, castChanged);
964
+ unobserveDialNetwork();
965
+ dial?.stop();
966
+ networkMonitor?.stop();
967
+ wired?.dispose();
260
968
  discovery.stop();
261
969
  await service.dispose();
262
- contents.clear();
970
+ senders.clear();
971
+ subframeIds.clear();
972
+ watched.clear();
973
+ if (sweepTimer !== undefined)
974
+ clearInterval(sweepTimer);
975
+ sweepTimer = undefined;
263
976
  },
264
977
  };
265
978
  }