electron-cast 0.4.0 → 0.5.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +280 -0
- package/CONTRIBUTING.md +305 -0
- package/README.md +211 -165
- package/SECURITY.md +324 -0
- package/dist/cjs/client/auth/build-time.js +1 -1
- package/dist/cjs/client/auth/cast-auth.d.ts +2 -0
- package/dist/cjs/client/auth/cast-auth.js.map +1 -1
- package/dist/cjs/dial/dial-registry.d.ts +104 -0
- package/dist/cjs/dial/dial-registry.js +301 -0
- package/dist/cjs/dial/dial-registry.js.map +1 -0
- package/dist/cjs/dial/dial-sink-service.d.ts +108 -0
- package/dist/cjs/dial/dial-sink-service.js +314 -0
- package/dist/cjs/dial/dial-sink-service.js.map +1 -0
- package/dist/cjs/dial/http.d.ts +40 -0
- package/dist/cjs/dial/http.js +172 -0
- package/dist/cjs/dial/http.js.map +1 -0
- package/dist/cjs/dial/index.d.ts +63 -0
- package/dist/cjs/dial/index.js +134 -0
- package/dist/cjs/dial/index.js.map +1 -0
- package/dist/cjs/dial/origins.d.ts +4 -0
- package/dist/cjs/dial/origins.js +36 -0
- package/dist/cjs/dial/origins.js.map +1 -0
- package/dist/cjs/dial/parse.d.ts +101 -0
- package/dist/cjs/dial/parse.js +296 -0
- package/dist/cjs/dial/parse.js.map +1 -0
- package/dist/cjs/dial/route-provider.d.ts +96 -0
- package/dist/cjs/dial/route-provider.js +376 -0
- package/dist/cjs/dial/route-provider.js.map +1 -0
- package/dist/cjs/dial/ssdp-socket.d.ts +34 -0
- package/dist/cjs/dial/ssdp-socket.js +72 -0
- package/dist/cjs/dial/ssdp-socket.js.map +1 -0
- package/dist/cjs/dial/xml.d.ts +13 -0
- package/dist/cjs/dial/xml.js +208 -0
- package/dist/cjs/dial/xml.js.map +1 -0
- package/dist/cjs/discovery/cast-discovery.d.ts +2 -0
- package/dist/cjs/discovery/cast-discovery.js.map +1 -1
- package/dist/cjs/discovery/device-cache.d.ts +9 -0
- package/dist/cjs/discovery/device-cache.js.map +1 -1
- package/dist/cjs/discovery/index.d.ts +1 -0
- package/dist/cjs/discovery/index.js +1 -0
- package/dist/cjs/discovery/index.js.map +1 -1
- package/dist/cjs/discovery/ip-policy.d.ts +20 -0
- package/dist/cjs/discovery/ip-policy.js +109 -0
- package/dist/cjs/discovery/ip-policy.js.map +1 -0
- package/dist/cjs/discovery/udp-socket.d.ts +3 -0
- package/dist/cjs/discovery/udp-socket.js +3 -0
- package/dist/cjs/discovery/udp-socket.js.map +1 -1
- package/dist/cjs/electron/access-code.d.ts +221 -0
- package/dist/cjs/electron/access-code.js +586 -0
- package/dist/cjs/electron/access-code.js.map +1 -0
- package/dist/cjs/electron/app-discovery.d.ts +82 -0
- package/dist/cjs/electron/app-discovery.js +219 -0
- package/dist/cjs/electron/app-discovery.js.map +1 -0
- package/dist/cjs/electron/default-presentation.d.ts +38 -0
- package/dist/cjs/electron/default-presentation.js +88 -0
- package/dist/cjs/electron/default-presentation.js.map +1 -0
- package/dist/cjs/electron/main.d.ts +98 -11
- package/dist/cjs/electron/main.js +602 -20
- package/dist/cjs/electron/main.js.map +1 -1
- package/dist/cjs/electron/manager-api.d.ts +200 -18
- package/dist/cjs/electron/manager-api.js +199 -4
- package/dist/cjs/electron/manager-api.js.map +1 -1
- package/dist/cjs/electron/media-controller.d.ts +79 -0
- package/dist/cjs/electron/media-controller.js +251 -0
- package/dist/cjs/electron/media-controller.js.map +1 -0
- package/dist/cjs/electron/network-monitor.d.ts +61 -0
- package/dist/cjs/electron/network-monitor.js +124 -0
- package/dist/cjs/electron/network-monitor.js.map +1 -0
- package/dist/cjs/electron/preload.js.map +1 -1
- package/dist/cjs/electron/presentation-handler.d.ts +39 -4
- package/dist/cjs/electron/presentation-handler.js +191 -47
- package/dist/cjs/electron/presentation-handler.js.map +1 -1
- package/dist/cjs/electron/presentation-source.d.ts +76 -0
- package/dist/cjs/electron/presentation-source.js +132 -0
- package/dist/cjs/electron/presentation-source.js.map +1 -0
- package/dist/cjs/electron/session-service.d.ts +198 -24
- package/dist/cjs/electron/session-service.js +630 -248
- package/dist/cjs/electron/session-service.js.map +1 -1
- package/dist/cjs/electron/session-tracker.d.ts +82 -0
- package/dist/cjs/electron/session-tracker.js +225 -0
- package/dist/cjs/electron/session-tracker.js.map +1 -0
- package/dist/cjs/electron/sink-service.d.ts +246 -0
- package/dist/cjs/electron/sink-service.js +606 -0
- package/dist/cjs/electron/sink-service.js.map +1 -0
- package/dist/cjs/electron/wired-display/controller.d.ts +76 -0
- package/dist/cjs/electron/wired-display/controller.js +198 -0
- package/dist/cjs/electron/wired-display/controller.js.map +1 -0
- package/dist/cjs/electron/wired-display/displays.d.ts +44 -0
- package/dist/cjs/electron/wired-display/displays.js +98 -0
- package/dist/cjs/electron/wired-display/displays.js.map +1 -0
- package/dist/cjs/electron/wired-display/electron-windows.d.ts +111 -0
- package/dist/cjs/electron/wired-display/electron-windows.js +306 -0
- package/dist/cjs/electron/wired-display/electron-windows.js.map +1 -0
- package/dist/cjs/electron/wired-display/index.d.ts +90 -0
- package/dist/cjs/electron/wired-display/index.js +115 -0
- package/dist/cjs/electron/wired-display/index.js.map +1 -0
- package/dist/cjs/electron/wired-display/local-presentation.d.ts +98 -0
- package/dist/cjs/electron/wired-display/local-presentation.js +234 -0
- package/dist/cjs/electron/wired-display/local-presentation.js.map +1 -0
- package/dist/cjs/electron/wired-display/provider.d.ts +112 -0
- package/dist/cjs/electron/wired-display/provider.js +202 -0
- package/dist/cjs/electron/wired-display/provider.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mirroring/backend.d.ts +76 -0
- package/dist/cjs/mirroring/backend.js +21 -0
- package/dist/cjs/mirroring/backend.js.map +1 -0
- package/dist/cjs/mirroring/electron/agent-protocol.d.ts +158 -0
- package/dist/cjs/mirroring/electron/agent-protocol.js +11 -0
- package/dist/cjs/mirroring/electron/agent-protocol.js.map +1 -0
- package/dist/cjs/mirroring/electron/agent-source.d.ts +20 -0
- package/dist/cjs/mirroring/electron/agent-source.js +621 -0
- package/dist/cjs/mirroring/electron/agent-source.js.map +1 -0
- package/dist/cjs/mirroring/electron/engine-process.d.ts +87 -0
- package/dist/cjs/mirroring/electron/engine-process.js +81 -0
- package/dist/cjs/mirroring/electron/engine-process.js.map +1 -0
- package/dist/cjs/mirroring/electron/host.d.ts +89 -0
- package/dist/cjs/mirroring/electron/host.js +321 -0
- package/dist/cjs/mirroring/electron/host.js.map +1 -0
- package/dist/cjs/mirroring/electron/port-backend.d.ts +107 -0
- package/dist/cjs/mirroring/electron/port-backend.js +446 -0
- package/dist/cjs/mirroring/electron/port-backend.js.map +1 -0
- package/dist/cjs/mirroring/encoding-support.d.ts +66 -0
- package/dist/cjs/mirroring/encoding-support.js +89 -0
- package/dist/cjs/mirroring/encoding-support.js.map +1 -0
- package/dist/cjs/mirroring/engine.d.ts +16 -0
- package/dist/cjs/mirroring/engine.js +78 -0
- package/dist/cjs/mirroring/engine.js.map +1 -0
- package/dist/cjs/mirroring/mirror-settings.d.ts +101 -0
- package/dist/cjs/mirroring/mirror-settings.js +140 -0
- package/dist/cjs/mirroring/mirror-settings.js.map +1 -0
- package/dist/cjs/mirroring/mirroring-activity.d.ts +207 -0
- package/dist/cjs/mirroring/mirroring-activity.js +367 -0
- package/dist/cjs/mirroring/mirroring-activity.js.map +1 -0
- package/dist/cjs/mirroring/mirroring-manager.d.ts +134 -0
- package/dist/cjs/mirroring/mirroring-manager.js +286 -0
- package/dist/cjs/mirroring/mirroring-manager.js.map +1 -0
- package/dist/cjs/mirroring/protocol/answer.d.ts +87 -0
- package/dist/cjs/mirroring/protocol/answer.js +233 -0
- package/dist/cjs/mirroring/protocol/answer.js.map +1 -0
- package/dist/cjs/mirroring/protocol/constants.d.ts +64 -0
- package/dist/cjs/mirroring/protocol/constants.js +70 -0
- package/dist/cjs/mirroring/protocol/constants.js.map +1 -0
- package/dist/cjs/mirroring/protocol/errors.d.ts +25 -0
- package/dist/cjs/mirroring/protocol/errors.js +34 -0
- package/dist/cjs/mirroring/protocol/errors.js.map +1 -0
- package/dist/cjs/mirroring/protocol/frame-id.d.ts +9 -0
- package/dist/cjs/mirroring/protocol/frame-id.js +24 -0
- package/dist/cjs/mirroring/protocol/frame-id.js.map +1 -0
- package/dist/cjs/mirroring/protocol/messenger.d.ts +42 -0
- package/dist/cjs/mirroring/protocol/messenger.js +122 -0
- package/dist/cjs/mirroring/protocol/messenger.js.map +1 -0
- package/dist/cjs/mirroring/protocol/offer.d.ts +109 -0
- package/dist/cjs/mirroring/protocol/offer.js +192 -0
- package/dist/cjs/mirroring/protocol/offer.js.map +1 -0
- package/dist/cjs/mirroring/protocol/recommendations.d.ts +28 -0
- package/dist/cjs/mirroring/protocol/recommendations.js +103 -0
- package/dist/cjs/mirroring/protocol/recommendations.js.map +1 -0
- package/dist/cjs/mirroring/routing.d.ts +60 -0
- package/dist/cjs/mirroring/routing.js +147 -0
- package/dist/cjs/mirroring/routing.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/ntp.d.ts +27 -0
- package/dist/cjs/mirroring/rtcp/ntp.js +62 -0
- package/dist/cjs/mirroring/rtcp/ntp.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/parser.d.ts +50 -0
- package/dist/cjs/mirroring/rtcp/parser.js +270 -0
- package/dist/cjs/mirroring/rtcp/parser.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/sender-report.d.ts +32 -0
- package/dist/cjs/mirroring/rtcp/sender-report.js +56 -0
- package/dist/cjs/mirroring/rtcp/sender-report.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/wire.d.ts +54 -0
- package/dist/cjs/mirroring/rtcp/wire.js +73 -0
- package/dist/cjs/mirroring/rtcp/wire.js.map +1 -0
- package/dist/cjs/mirroring/rtp/frame-crypto.d.ts +11 -0
- package/dist/cjs/mirroring/rtp/frame-crypto.js +39 -0
- package/dist/cjs/mirroring/rtp/frame-crypto.js.map +1 -0
- package/dist/cjs/mirroring/rtp/frame.d.ts +23 -0
- package/dist/cjs/mirroring/rtp/frame.js +3 -0
- package/dist/cjs/mirroring/rtp/frame.js.map +1 -0
- package/dist/cjs/mirroring/rtp/packetizer.d.ts +27 -0
- package/dist/cjs/mirroring/rtp/packetizer.js +92 -0
- package/dist/cjs/mirroring/rtp/packetizer.js.map +1 -0
- package/dist/cjs/mirroring/sender/audio-sender.d.ts +23 -0
- package/dist/cjs/mirroring/sender/audio-sender.js +52 -0
- package/dist/cjs/mirroring/sender/audio-sender.js.map +1 -0
- package/dist/cjs/mirroring/sender/bandwidth-estimator.d.ts +26 -0
- package/dist/cjs/mirroring/sender/bandwidth-estimator.js +107 -0
- package/dist/cjs/mirroring/sender/bandwidth-estimator.js.map +1 -0
- package/dist/cjs/mirroring/sender/capture-size-oracle.d.ts +121 -0
- package/dist/cjs/mirroring/sender/capture-size-oracle.js +440 -0
- package/dist/cjs/mirroring/sender/capture-size-oracle.js.map +1 -0
- package/dist/cjs/mirroring/sender/frame-sender.d.ts +103 -0
- package/dist/cjs/mirroring/sender/frame-sender.js +217 -0
- package/dist/cjs/mirroring/sender/frame-sender.js.map +1 -0
- package/dist/cjs/mirroring/sender/packet-router.d.ts +74 -0
- package/dist/cjs/mirroring/sender/packet-router.js +196 -0
- package/dist/cjs/mirroring/sender/packet-router.js.map +1 -0
- package/dist/cjs/mirroring/sender/sender-session.d.ts +85 -0
- package/dist/cjs/mirroring/sender/sender-session.js +240 -0
- package/dist/cjs/mirroring/sender/sender-session.js.map +1 -0
- package/dist/cjs/mirroring/sender/sender.d.ts +120 -0
- package/dist/cjs/mirroring/sender/sender.js +457 -0
- package/dist/cjs/mirroring/sender/sender.js.map +1 -0
- package/dist/cjs/mirroring/sender/video-encoder-metrics.d.ts +29 -0
- package/dist/cjs/mirroring/sender/video-encoder-metrics.js +64 -0
- package/dist/cjs/mirroring/sender/video-encoder-metrics.js.map +1 -0
- package/dist/cjs/mirroring/sender/video-sender.d.ts +95 -0
- package/dist/cjs/mirroring/sender/video-sender.js +183 -0
- package/dist/cjs/mirroring/sender/video-sender.js.map +1 -0
- package/dist/cjs/mirroring/session-host.d.ts +185 -0
- package/dist/cjs/mirroring/session-host.js +630 -0
- package/dist/cjs/mirroring/session-host.js.map +1 -0
- package/dist/cjs/mirroring/stats/clock-offset-estimator.d.ts +11 -0
- package/dist/cjs/mirroring/stats/clock-offset-estimator.js +123 -0
- package/dist/cjs/mirroring/stats/clock-offset-estimator.js.map +1 -0
- package/dist/cjs/mirroring/stats/openscreen-stats-client.d.ts +12 -0
- package/dist/cjs/mirroring/stats/openscreen-stats-client.js +21 -0
- package/dist/cjs/mirroring/stats/openscreen-stats-client.js.map +1 -0
- package/dist/cjs/mirroring/stats/sorted-map.d.ts +23 -0
- package/dist/cjs/mirroring/stats/sorted-map.js +70 -0
- package/dist/cjs/mirroring/stats/sorted-map.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-analyzer.d.ts +50 -0
- package/dist/cjs/mirroring/stats/statistics-analyzer.js +339 -0
- package/dist/cjs/mirroring/stats/statistics-analyzer.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-collector.d.ts +29 -0
- package/dist/cjs/mirroring/stats/statistics-collector.js +53 -0
- package/dist/cjs/mirroring/stats/statistics-collector.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-common.d.ts +61 -0
- package/dist/cjs/mirroring/stats/statistics-common.js +45 -0
- package/dist/cjs/mirroring/stats/statistics-common.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-dispatcher.d.ts +28 -0
- package/dist/cjs/mirroring/stats/statistics-dispatcher.js +104 -0
- package/dist/cjs/mirroring/stats/statistics-dispatcher.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics.d.ts +84 -0
- package/dist/cjs/mirroring/stats/statistics.js +147 -0
- package/dist/cjs/mirroring/stats/statistics.js.map +1 -0
- package/dist/cjs/mirroring/transport/udp-environment.d.ts +40 -0
- package/dist/cjs/mirroring/transport/udp-environment.js +97 -0
- package/dist/cjs/mirroring/transport/udp-environment.js.map +1 -0
- package/dist/cjs/polyfill/bridge-types.d.ts +11 -0
- package/dist/cjs/polyfill/presentation-receiver.d.ts +12 -0
- package/dist/cjs/polyfill/presentation-receiver.js +369 -0
- package/dist/cjs/polyfill/presentation-receiver.js.map +1 -0
- package/dist/cjs/polyfill/presentation-standin.js +157 -15
- package/dist/cjs/polyfill/presentation-standin.js.map +1 -1
- package/dist/cjs/protocol/framing.d.ts +1 -1
- package/dist/cjs/protocol/framing.js +1 -1
- package/dist/cjs/protocol/framing.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +56 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/auth/build-time.js +1 -1
- package/dist/client/auth/cast-auth.d.ts +2 -0
- package/dist/client/auth/cast-auth.js.map +1 -1
- package/dist/dial/dial-registry.d.ts +104 -0
- package/dist/dial/dial-registry.js +297 -0
- package/dist/dial/dial-registry.js.map +1 -0
- package/dist/dial/dial-sink-service.d.ts +108 -0
- package/dist/dial/dial-sink-service.js +310 -0
- package/dist/dial/dial-sink-service.js.map +1 -0
- package/dist/dial/http.d.ts +40 -0
- package/dist/dial/http.js +165 -0
- package/dist/dial/http.js.map +1 -0
- package/dist/dial/index.d.ts +63 -0
- package/dist/dial/index.js +115 -0
- package/dist/dial/index.js.map +1 -0
- package/dist/dial/origins.d.ts +4 -0
- package/dist/dial/origins.js +32 -0
- package/dist/dial/origins.js.map +1 -0
- package/dist/dial/parse.d.ts +101 -0
- package/dist/dial/parse.js +281 -0
- package/dist/dial/parse.js.map +1 -0
- package/dist/dial/route-provider.d.ts +96 -0
- package/dist/dial/route-provider.js +369 -0
- package/dist/dial/route-provider.js.map +1 -0
- package/dist/dial/ssdp-socket.d.ts +34 -0
- package/dist/dial/ssdp-socket.js +65 -0
- package/dist/dial/ssdp-socket.js.map +1 -0
- package/dist/dial/xml.d.ts +13 -0
- package/dist/dial/xml.js +204 -0
- package/dist/dial/xml.js.map +1 -0
- package/dist/dial-test/cli-main.d.ts +17 -0
- package/dist/dial-test/cli-main.js +130 -0
- package/dist/dial-test/cli-main.js.map +1 -0
- package/dist/dial-test/report.d.ts +55 -0
- package/dist/dial-test/report.js +77 -0
- package/dist/dial-test/report.js.map +1 -0
- package/dist/dial-test/runner.d.ts +42 -0
- package/dist/dial-test/runner.js +566 -0
- package/dist/dial-test/runner.js.map +1 -0
- package/dist/dial-test/scrub.d.ts +14 -0
- package/dist/dial-test/scrub.js +73 -0
- package/dist/dial-test/scrub.js.map +1 -0
- package/dist/discovery/cast-discovery.d.ts +2 -0
- package/dist/discovery/cast-discovery.js.map +1 -1
- package/dist/discovery/device-cache.d.ts +9 -0
- package/dist/discovery/device-cache.js.map +1 -1
- package/dist/discovery/index.d.ts +1 -0
- package/dist/discovery/index.js +1 -0
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/ip-policy.d.ts +20 -0
- package/dist/discovery/ip-policy.js +103 -0
- package/dist/discovery/ip-policy.js.map +1 -0
- package/dist/discovery/udp-socket.d.ts +3 -0
- package/dist/discovery/udp-socket.js +3 -0
- package/dist/discovery/udp-socket.js.map +1 -1
- package/dist/electron/access-code.d.ts +221 -0
- package/dist/electron/access-code.js +577 -0
- package/dist/electron/access-code.js.map +1 -0
- package/dist/electron/app-discovery.d.ts +82 -0
- package/dist/electron/app-discovery.js +215 -0
- package/dist/electron/app-discovery.js.map +1 -0
- package/dist/electron/default-presentation.d.ts +38 -0
- package/dist/electron/default-presentation.js +83 -0
- package/dist/electron/default-presentation.js.map +1 -0
- package/dist/electron/main.d.ts +98 -11
- package/dist/electron/main.js +597 -21
- package/dist/electron/main.js.map +1 -1
- package/dist/electron/manager-api.d.ts +200 -18
- package/dist/electron/manager-api.js +196 -4
- package/dist/electron/manager-api.js.map +1 -1
- package/dist/electron/media-controller.d.ts +79 -0
- package/dist/electron/media-controller.js +248 -0
- package/dist/electron/media-controller.js.map +1 -0
- package/dist/electron/network-monitor.d.ts +61 -0
- package/dist/electron/network-monitor.js +117 -0
- package/dist/electron/network-monitor.js.map +1 -0
- package/dist/electron/preload.js.map +1 -1
- package/dist/electron/presentation-handler.d.ts +39 -4
- package/dist/electron/presentation-handler.js +192 -48
- package/dist/electron/presentation-handler.js.map +1 -1
- package/dist/electron/presentation-source.d.ts +76 -0
- package/dist/electron/presentation-source.js +125 -0
- package/dist/electron/presentation-source.js.map +1 -0
- package/dist/electron/session-service.d.ts +198 -24
- package/dist/electron/session-service.js +629 -248
- package/dist/electron/session-service.js.map +1 -1
- package/dist/electron/session-tracker.d.ts +82 -0
- package/dist/electron/session-tracker.js +219 -0
- package/dist/electron/session-tracker.js.map +1 -0
- package/dist/electron/sink-service.d.ts +246 -0
- package/dist/electron/sink-service.js +602 -0
- package/dist/electron/sink-service.js.map +1 -0
- package/dist/electron/wired-display/controller.d.ts +76 -0
- package/dist/electron/wired-display/controller.js +194 -0
- package/dist/electron/wired-display/controller.js.map +1 -0
- package/dist/electron/wired-display/displays.d.ts +44 -0
- package/dist/electron/wired-display/displays.js +91 -0
- package/dist/electron/wired-display/displays.js.map +1 -0
- package/dist/electron/wired-display/electron-windows.d.ts +111 -0
- package/dist/electron/wired-display/electron-windows.js +301 -0
- package/dist/electron/wired-display/electron-windows.js.map +1 -0
- package/dist/electron/wired-display/index.d.ts +90 -0
- package/dist/electron/wired-display/index.js +99 -0
- package/dist/electron/wired-display/index.js.map +1 -0
- package/dist/electron/wired-display/local-presentation.d.ts +98 -0
- package/dist/electron/wired-display/local-presentation.js +228 -0
- package/dist/electron/wired-display/local-presentation.js.map +1 -0
- package/dist/electron/wired-display/provider.d.ts +112 -0
- package/dist/electron/wired-display/provider.js +197 -0
- package/dist/electron/wired-display/provider.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mirroring/backend.d.ts +76 -0
- package/dist/mirroring/backend.js +18 -0
- package/dist/mirroring/backend.js.map +1 -0
- package/dist/mirroring/electron/agent-protocol.d.ts +158 -0
- package/dist/mirroring/electron/agent-protocol.js +10 -0
- package/dist/mirroring/electron/agent-protocol.js.map +1 -0
- package/dist/mirroring/electron/agent-source.d.ts +20 -0
- package/dist/mirroring/electron/agent-source.js +618 -0
- package/dist/mirroring/electron/agent-source.js.map +1 -0
- package/dist/mirroring/electron/engine-process.d.ts +87 -0
- package/dist/mirroring/electron/engine-process.js +78 -0
- package/dist/mirroring/electron/engine-process.js.map +1 -0
- package/dist/mirroring/electron/host.d.ts +89 -0
- package/dist/mirroring/electron/host.js +318 -0
- package/dist/mirroring/electron/host.js.map +1 -0
- package/dist/mirroring/electron/port-backend.d.ts +107 -0
- package/dist/mirroring/electron/port-backend.js +441 -0
- package/dist/mirroring/electron/port-backend.js.map +1 -0
- package/dist/mirroring/encoding-support.d.ts +66 -0
- package/dist/mirroring/encoding-support.js +81 -0
- package/dist/mirroring/encoding-support.js.map +1 -0
- package/dist/mirroring/engine.d.ts +16 -0
- package/dist/mirroring/engine.js +75 -0
- package/dist/mirroring/engine.js.map +1 -0
- package/dist/mirroring/mirror-settings.d.ts +101 -0
- package/dist/mirroring/mirror-settings.js +134 -0
- package/dist/mirroring/mirror-settings.js.map +1 -0
- package/dist/mirroring/mirroring-activity.d.ts +207 -0
- package/dist/mirroring/mirroring-activity.js +362 -0
- package/dist/mirroring/mirroring-activity.js.map +1 -0
- package/dist/mirroring/mirroring-manager.d.ts +134 -0
- package/dist/mirroring/mirroring-manager.js +281 -0
- package/dist/mirroring/mirroring-manager.js.map +1 -0
- package/dist/mirroring/protocol/answer.d.ts +87 -0
- package/dist/mirroring/protocol/answer.js +226 -0
- package/dist/mirroring/protocol/answer.js.map +1 -0
- package/dist/mirroring/protocol/constants.d.ts +64 -0
- package/dist/mirroring/protocol/constants.js +66 -0
- package/dist/mirroring/protocol/constants.js.map +1 -0
- package/dist/mirroring/protocol/errors.d.ts +25 -0
- package/dist/mirroring/protocol/errors.js +29 -0
- package/dist/mirroring/protocol/errors.js.map +1 -0
- package/dist/mirroring/protocol/frame-id.d.ts +9 -0
- package/dist/mirroring/protocol/frame-id.js +20 -0
- package/dist/mirroring/protocol/frame-id.js.map +1 -0
- package/dist/mirroring/protocol/messenger.d.ts +42 -0
- package/dist/mirroring/protocol/messenger.js +118 -0
- package/dist/mirroring/protocol/messenger.js.map +1 -0
- package/dist/mirroring/protocol/offer.d.ts +109 -0
- package/dist/mirroring/protocol/offer.js +176 -0
- package/dist/mirroring/protocol/offer.js.map +1 -0
- package/dist/mirroring/protocol/recommendations.d.ts +28 -0
- package/dist/mirroring/protocol/recommendations.js +99 -0
- package/dist/mirroring/protocol/recommendations.js.map +1 -0
- package/dist/mirroring/routing.d.ts +60 -0
- package/dist/mirroring/routing.js +130 -0
- package/dist/mirroring/routing.js.map +1 -0
- package/dist/mirroring/rtcp/ntp.d.ts +27 -0
- package/dist/mirroring/rtcp/ntp.js +57 -0
- package/dist/mirroring/rtcp/ntp.js.map +1 -0
- package/dist/mirroring/rtcp/parser.d.ts +50 -0
- package/dist/mirroring/rtcp/parser.js +265 -0
- package/dist/mirroring/rtcp/parser.js.map +1 -0
- package/dist/mirroring/rtcp/sender-report.d.ts +32 -0
- package/dist/mirroring/rtcp/sender-report.js +51 -0
- package/dist/mirroring/rtcp/sender-report.js.map +1 -0
- package/dist/mirroring/rtcp/wire.d.ts +54 -0
- package/dist/mirroring/rtcp/wire.js +68 -0
- package/dist/mirroring/rtcp/wire.js.map +1 -0
- package/dist/mirroring/rtp/frame-crypto.d.ts +11 -0
- package/dist/mirroring/rtp/frame-crypto.js +35 -0
- package/dist/mirroring/rtp/frame-crypto.js.map +1 -0
- package/dist/mirroring/rtp/frame.d.ts +23 -0
- package/dist/mirroring/rtp/frame.js +2 -0
- package/dist/mirroring/rtp/frame.js.map +1 -0
- package/dist/mirroring/rtp/packetizer.d.ts +27 -0
- package/dist/mirroring/rtp/packetizer.js +88 -0
- package/dist/mirroring/rtp/packetizer.js.map +1 -0
- package/dist/mirroring/sender/audio-sender.d.ts +23 -0
- package/dist/mirroring/sender/audio-sender.js +54 -0
- package/dist/mirroring/sender/audio-sender.js.map +1 -0
- package/dist/mirroring/sender/bandwidth-estimator.d.ts +26 -0
- package/dist/mirroring/sender/bandwidth-estimator.js +103 -0
- package/dist/mirroring/sender/bandwidth-estimator.js.map +1 -0
- package/dist/mirroring/sender/capture-size-oracle.d.ts +121 -0
- package/dist/mirroring/sender/capture-size-oracle.js +433 -0
- package/dist/mirroring/sender/capture-size-oracle.js.map +1 -0
- package/dist/mirroring/sender/frame-sender.d.ts +103 -0
- package/dist/mirroring/sender/frame-sender.js +212 -0
- package/dist/mirroring/sender/frame-sender.js.map +1 -0
- package/dist/mirroring/sender/packet-router.d.ts +74 -0
- package/dist/mirroring/sender/packet-router.js +191 -0
- package/dist/mirroring/sender/packet-router.js.map +1 -0
- package/dist/mirroring/sender/sender-session.d.ts +85 -0
- package/dist/mirroring/sender/sender-session.js +235 -0
- package/dist/mirroring/sender/sender-session.js.map +1 -0
- package/dist/mirroring/sender/sender.d.ts +120 -0
- package/dist/mirroring/sender/sender.js +452 -0
- package/dist/mirroring/sender/sender.js.map +1 -0
- package/dist/mirroring/sender/video-encoder-metrics.d.ts +29 -0
- package/dist/mirroring/sender/video-encoder-metrics.js +58 -0
- package/dist/mirroring/sender/video-encoder-metrics.js.map +1 -0
- package/dist/mirroring/sender/video-sender.d.ts +95 -0
- package/dist/mirroring/sender/video-sender.js +190 -0
- package/dist/mirroring/sender/video-sender.js.map +1 -0
- package/dist/mirroring/session-host.d.ts +185 -0
- package/dist/mirroring/session-host.js +625 -0
- package/dist/mirroring/session-host.js.map +1 -0
- package/dist/mirroring/stats/clock-offset-estimator.d.ts +11 -0
- package/dist/mirroring/stats/clock-offset-estimator.js +120 -0
- package/dist/mirroring/stats/clock-offset-estimator.js.map +1 -0
- package/dist/mirroring/stats/openscreen-stats-client.d.ts +12 -0
- package/dist/mirroring/stats/openscreen-stats-client.js +17 -0
- package/dist/mirroring/stats/openscreen-stats-client.js.map +1 -0
- package/dist/mirroring/stats/sorted-map.d.ts +23 -0
- package/dist/mirroring/stats/sorted-map.js +66 -0
- package/dist/mirroring/stats/sorted-map.js.map +1 -0
- package/dist/mirroring/stats/statistics-analyzer.d.ts +50 -0
- package/dist/mirroring/stats/statistics-analyzer.js +335 -0
- package/dist/mirroring/stats/statistics-analyzer.js.map +1 -0
- package/dist/mirroring/stats/statistics-collector.d.ts +29 -0
- package/dist/mirroring/stats/statistics-collector.js +49 -0
- package/dist/mirroring/stats/statistics-collector.js.map +1 -0
- package/dist/mirroring/stats/statistics-common.d.ts +61 -0
- package/dist/mirroring/stats/statistics-common.js +39 -0
- package/dist/mirroring/stats/statistics-common.js.map +1 -0
- package/dist/mirroring/stats/statistics-dispatcher.d.ts +28 -0
- package/dist/mirroring/stats/statistics-dispatcher.js +100 -0
- package/dist/mirroring/stats/statistics-dispatcher.js.map +1 -0
- package/dist/mirroring/stats/statistics.d.ts +84 -0
- package/dist/mirroring/stats/statistics.js +141 -0
- package/dist/mirroring/stats/statistics.js.map +1 -0
- package/dist/mirroring/transport/udp-environment.d.ts +40 -0
- package/dist/mirroring/transport/udp-environment.js +93 -0
- package/dist/mirroring/transport/udp-environment.js.map +1 -0
- package/dist/polyfill/bridge-types.d.ts +11 -0
- package/dist/polyfill/presentation-receiver.d.ts +12 -0
- package/dist/polyfill/presentation-receiver.js +366 -0
- package/dist/polyfill/presentation-receiver.js.map +1 -0
- package/dist/polyfill/presentation-standin.js +157 -15
- package/dist/polyfill/presentation-standin.js.map +1 -1
- package/dist/protocol/framing.d.ts +1 -1
- package/dist/protocol/framing.js +1 -1
- package/dist/protocol/framing.js.map +1 -1
- package/docs/API.md +724 -0
- package/docs/ARCHITECTURE.md +242 -0
- package/docs/CHROMIUM-MAP.md +176 -0
- package/docs/DESIGN.md +1189 -0
- package/docs/FAQ.md +123 -0
- package/docs/GETTING-STARTED.md +248 -0
- package/docs/MAIN-API.md +524 -0
- package/docs/TROUBLESHOOTING.md +283 -0
- package/docs/guides/audio-and-groups.md +75 -0
- package/docs/guides/custom-receivers.md +109 -0
- package/docs/guides/device-authentication.md +145 -0
- package/docs/guides/device-picker.md +176 -0
- package/docs/guides/index.md +17 -0
- package/docs/guides/low-level-client.md +103 -0
- package/docs/guides/restart-rejoin.md +172 -0
- package/docs/guides/testing.md +162 -0
- package/docs/guides/windows-and-iframes.md +116 -0
- package/docs/readme/badges/dependencies.svg +1 -0
- package/docs/readme/badges/electron.svg +1 -0
- package/docs/readme/badges/license.svg +1 -0
- package/docs/readme/badges/node.svg +1 -0
- package/docs/readme/board.jpg +0 -0
- package/docs/readme/hero-dark.jpg +0 -0
- package/docs/readme/hero-light.jpg +0 -0
- package/docs/readme/nosignal.jpg +0 -0
- package/docs/readme/parity.jpg +0 -0
- package/docs/readme/trace.svg +22 -0
- package/package.json +21 -5
- package/src/cli.ts +57 -0
- package/src/client/auth/cast-auth.ts +2 -0
- package/src/dial/dial-registry.ts +316 -0
- package/src/dial/dial-sink-service.ts +343 -0
- package/src/dial/http.ts +200 -0
- package/src/dial/index.ts +135 -0
- package/src/dial/origins.ts +31 -0
- package/src/dial/parse.ts +319 -0
- package/src/dial/route-provider.ts +429 -0
- package/src/dial/ssdp-socket.ts +79 -0
- package/src/dial/xml.ts +180 -0
- package/src/dial-test/cli-main.ts +146 -0
- package/src/dial-test/report.ts +109 -0
- package/src/dial-test/runner.ts +615 -0
- package/src/dial-test/scrub.ts +74 -0
- package/src/discovery/cast-discovery.ts +2 -0
- package/src/discovery/device-cache.ts +5 -0
- package/src/discovery/index.ts +1 -0
- package/src/discovery/ip-policy.ts +97 -0
- package/src/discovery/udp-socket.ts +3 -0
- package/src/electron/access-code.ts +681 -0
- package/src/electron/app-discovery.ts +244 -0
- package/src/electron/default-presentation.ts +104 -0
- package/src/electron/main.ts +664 -29
- package/src/electron/manager-api.ts +367 -15
- package/src/electron/media-controller.ts +313 -0
- package/src/electron/network-monitor.ts +140 -0
- package/src/electron/preload.ts +1 -1
- package/src/electron/presentation-handler.ts +195 -48
- package/src/electron/presentation-source.ts +155 -0
- package/src/electron/session-service.ts +693 -238
- package/src/electron/session-tracker.ts +248 -0
- package/src/electron/sink-service.ts +726 -0
- package/src/electron/wired-display/controller.ts +212 -0
- package/src/electron/wired-display/displays.ts +107 -0
- package/src/electron/wired-display/electron-windows.ts +386 -0
- package/src/electron/wired-display/index.ts +181 -0
- package/src/electron/wired-display/local-presentation.ts +286 -0
- package/src/electron/wired-display/provider.ts +276 -0
- package/src/index.ts +1 -0
- package/src/mirroring/backend.ts +103 -0
- package/src/mirroring/electron/agent-protocol.ts +84 -0
- package/src/mirroring/electron/agent-source.ts +619 -0
- package/src/mirroring/electron/engine-process.ts +131 -0
- package/src/mirroring/electron/host.ts +361 -0
- package/src/mirroring/electron/port-backend.ts +466 -0
- package/src/mirroring/encoding-support.ts +146 -0
- package/src/mirroring/engine.ts +91 -0
- package/src/mirroring/mirror-settings.ts +174 -0
- package/src/mirroring/mirroring-activity.ts +466 -0
- package/src/mirroring/mirroring-manager.ts +342 -0
- package/src/mirroring/protocol/answer.ts +285 -0
- package/src/mirroring/protocol/constants.ts +75 -0
- package/src/mirroring/protocol/errors.ts +36 -0
- package/src/mirroring/protocol/frame-id.ts +20 -0
- package/src/mirroring/protocol/messenger.ts +128 -0
- package/src/mirroring/protocol/offer.ts +275 -0
- package/src/mirroring/protocol/recommendations.ts +135 -0
- package/src/mirroring/routing.ts +160 -0
- package/src/mirroring/rtcp/ntp.ts +61 -0
- package/src/mirroring/rtcp/parser.ts +292 -0
- package/src/mirroring/rtcp/sender-report.ts +88 -0
- package/src/mirroring/rtcp/wire.ts +76 -0
- package/src/mirroring/rtp/frame-crypto.ts +38 -0
- package/src/mirroring/rtp/frame.ts +25 -0
- package/src/mirroring/rtp/packetizer.ts +95 -0
- package/src/mirroring/sender/audio-sender.ts +59 -0
- package/src/mirroring/sender/bandwidth-estimator.ts +111 -0
- package/src/mirroring/sender/capture-size-oracle.ts +476 -0
- package/src/mirroring/sender/frame-sender.ts +293 -0
- package/src/mirroring/sender/packet-router.ts +228 -0
- package/src/mirroring/sender/sender-session.ts +306 -0
- package/src/mirroring/sender/sender.ts +497 -0
- package/src/mirroring/sender/video-encoder-metrics.ts +64 -0
- package/src/mirroring/sender/video-sender.ts +243 -0
- package/src/mirroring/session-host.ts +725 -0
- package/src/mirroring/stats/clock-offset-estimator.ts +139 -0
- package/src/mirroring/stats/openscreen-stats-client.ts +19 -0
- package/src/mirroring/stats/sorted-map.ts +68 -0
- package/src/mirroring/stats/statistics-analyzer.ts +388 -0
- package/src/mirroring/stats/statistics-collector.ts +69 -0
- package/src/mirroring/stats/statistics-common.ts +112 -0
- package/src/mirroring/stats/statistics-dispatcher.ts +133 -0
- package/src/mirroring/stats/statistics.ts +170 -0
- package/src/mirroring/transport/udp-environment.ts +100 -0
- package/src/polyfill/bridge-types.ts +11 -0
- package/src/polyfill/presentation-receiver.ts +350 -0
- package/src/polyfill/presentation-standin.ts +147 -15
- package/src/protocol/framing.ts +1 -1
package/docs/DESIGN.md
ADDED
|
@@ -0,0 +1,1189 @@
|
|
|
1
|
+
# electron-cast design
|
|
2
|
+
|
|
3
|
+
Electron exposes the Presentation API but has no Chrome Media Router behind it, so web pages that use the Google Cast
|
|
4
|
+
sender SDK (`chrome.cast`) cannot find or talk to Cast devices. Electron closed the upstream request
|
|
5
|
+
(electron/electron#869) in 2025 with no plans to implement it. electron-cast fills the gap from scratch. By default
|
|
6
|
+
the page keeps Google's own SDK, and electron-cast supplies the missing Media Router: a stand-in Presentation API in
|
|
7
|
+
the page, and in the main process a translator for the router's message format plus device discovery and the Cast v2
|
|
8
|
+
protocol. The older alternative (`mode: "chromecast"`) gives the page electron-cast's own `chrome.cast`
|
|
9
|
+
implementation instead.
|
|
10
|
+
|
|
11
|
+
The first app built on it loads YouTube Music's web player, which uses the legacy `chrome.cast` API with the YouTube
|
|
12
|
+
receiver `233637DE` and the `urn:x-cast:com.google.youtube.mdx` namespace. The library is generic: nothing YouTube-specific
|
|
13
|
+
lives in it.
|
|
14
|
+
|
|
15
|
+
## Goals
|
|
16
|
+
|
|
17
|
+
- Works with `sandbox: true` and `contextIsolation: true`. The page never gets Node, sockets or IPC handles; it only
|
|
18
|
+
sees the Presentation API stand-in (or the `chrome.cast` object in `"chromecast"` mode).
|
|
19
|
+
- No native modules. Pure TypeScript on Node's `tls` and `dgram`.
|
|
20
|
+
- The main process decides which pages may cast and which device the user picked. The library ships a picker hook,
|
|
21
|
+
and the app supplies the UI.
|
|
22
|
+
- Small, well-tested modules with no Electron import below the `electron/` layer, so the protocol and discovery code
|
|
23
|
+
run and test in plain Node.
|
|
24
|
+
|
|
25
|
+
## Layers
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
page (main world) Google's Cast SDK on the Presentation API stand-in src/polyfill/presentation-standin.ts
|
|
29
|
+
(or, mode "chromecast": chrome.cast polyfill src/polyfill/install.ts)
|
|
30
|
+
│ window-level bridge object, installed by the preload
|
|
31
|
+
preload (isolated) bridge: contextBridge + ipcRenderer src/electron/preload.ts
|
|
32
|
+
│ IPC channel "electron-cast:*"
|
|
33
|
+
main process CastManager: sessions, picker, IPC src/electron/main.ts
|
|
34
|
+
├─ Presentation handler + envelope src/electron/presentation-*.ts
|
|
35
|
+
├─ Discovery (mDNS) src/discovery/
|
|
36
|
+
└─ CastClient per device (Cast v2) src/client/
|
|
37
|
+
└─ protocol: framing + CastMessage src/protocol/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Protocol layer (`src/protocol/`)
|
|
41
|
+
|
|
42
|
+
### CastMessage (protobuf, from `cast_channel.proto` in the Open Screen library)
|
|
43
|
+
|
|
44
|
+
| Field | No. | Wire type | Tag byte | Notes |
|
|
45
|
+
|---|---|---|---|---|
|
|
46
|
+
| `protocol_version` | 1 | varint | `0x08` | required; always `0` (CASTV2_1_0) |
|
|
47
|
+
| `source_id` | 2 | length-delimited | `0x12` | required string |
|
|
48
|
+
| `destination_id` | 3 | length-delimited | `0x1a` | required string |
|
|
49
|
+
| `namespace` | 4 | length-delimited | `0x22` | required string |
|
|
50
|
+
| `payload_type` | 5 | varint | `0x28` | required; `0` STRING, `1` BINARY |
|
|
51
|
+
| `payload_utf8` | 6 | length-delimited | `0x32` | optional UTF-8 string |
|
|
52
|
+
| `payload_binary` | 7 | length-delimited | `0x3a` | optional bytes |
|
|
53
|
+
|
|
54
|
+
Fields 8 and up (`continued`, `remaining_length` in CASTV2_1_1+) and any other unknown fields are skipped on decode.
|
|
55
|
+
The encoder writes fields in ascending order and writes the required fields even when their value is 0 or empty.
|
|
56
|
+
|
|
57
|
+
### Framing
|
|
58
|
+
|
|
59
|
+
Each message on the TLS socket is a 4-byte big-endian unsigned length followed by that many bytes of encoded
|
|
60
|
+
CastMessage. The maximum body is 65536 bytes (Chromium's `MessageFramer::MessageHeader::max_body_size()`); a larger declared length is a protocol
|
|
61
|
+
error and the connection must be closed.
|
|
62
|
+
|
|
63
|
+
## Client layer (`src/client/`)
|
|
64
|
+
|
|
65
|
+
TLS to the device on its mDNS port (8009 for single devices; groups use their own port). Cast devices present
|
|
66
|
+
self-signed certificates, so the TLS layer cannot verify them; device authenticity is the job of the
|
|
67
|
+
`urn:x-cast:com.google.cast.tp.deviceauth` challenge.
|
|
68
|
+
|
|
69
|
+
### Device authentication (`src/client/auth/`)
|
|
70
|
+
|
|
71
|
+
`CastClient.connect()` runs the challenge after the TLS handshake and before CONNECT, unless `verifyDevice: false`.
|
|
72
|
+
It is a port of Chromium's sender side (`components/media_router/common/providers/cast/channel/cast_auth_util.cc`
|
|
73
|
+
and `.../cast/certificate/`, with BoringSSL's path validator under it):
|
|
74
|
+
|
|
75
|
+
1. Send an `AuthChallenge` (16-byte nonce, SHA-256) as a BINARY CastMessage from `sender-0` to `receiver-0`.
|
|
76
|
+
2. The device replies with an `AuthResponse`: a signature, its certificate, its intermediates and optionally a CRL.
|
|
77
|
+
3. The TLS certificate's validity window must hold now and must end within four days (the lifetime of the proof).
|
|
78
|
+
4. The chain is built and validated to the embedded Cast Root CA or Eureka Root CA with RFC 5280 rules: signatures,
|
|
79
|
+
validity, names, basic constraints and path length, key usage, extended key usage (clientAuth), name constraints,
|
|
80
|
+
certificate policies, unhandled critical extensions, RSA of at least 2048 bits. Trust anchors are not checked for
|
|
81
|
+
expiry. A chain valid for more than five years that has just expired is validated as of a week before it
|
|
82
|
+
expired (Chromium's `GetValidationDate`).
|
|
83
|
+
5. The device certificate must assert digitalSignature, have a common name and a usable key.
|
|
84
|
+
6. Revocation uses the CRL the device sent (verified against the Cast CRL Root CA) or else the built-in fallback CRL,
|
|
85
|
+
which counts as valid for 20 weeks from the package's build time (see below). If the device sent no valid CRL and the
|
|
86
|
+
fallback has lapsed, the revocation check is skipped and `deviceAuth.revocationChecked` is `false`; with a fallback
|
|
87
|
+
that is broken rather than old, or one that is not yet valid, the device is refused (`crl_invalid`).
|
|
88
|
+
7. The signature (RSASSA-PKCS1-v1_5, SHA-1 or SHA-256 as the reply says) must verify under the device certificate's
|
|
89
|
+
key over `sender_nonce || DER of the TLS certificate`, which ties the proof to this connection.
|
|
90
|
+
|
|
91
|
+
A failure rejects `connect()` with `CastAuthError` (with a `reason`) and closes the socket. The session layer reports it
|
|
92
|
+
like any unreachable device (`receiver_unavailable`). The sink service connects to every discovered device and lists it
|
|
93
|
+
only once this has passed, so a device that fails is never a sink and never reaches the picker.
|
|
94
|
+
|
|
95
|
+
Not checked, or different from Chromium:
|
|
96
|
+
|
|
97
|
+
- Chromium's policy result `audio_only` is reported in `CastClient.deviceAuth.policy` but nothing acts on it.
|
|
98
|
+
- A stale fallback CRL skips revocation instead of failing closed. Chromium's `CRL_REQUIRED_WITH_FALLBACK` policy
|
|
99
|
+
returns `ERR_FALLBACK_CRL_INVALID` (`VerifyDeviceCertUsingCustomTrustStore` in
|
|
100
|
+
`components/media_router/common/providers/cast/certificate/cast_cert_validator.cc`) once the fallback is older than 20
|
|
101
|
+
weeks, which is safe there because Chrome auto-updates. An Electron app that stops updating would start refusing every
|
|
102
|
+
device that sends no CRL, about 20 weeks after its electron-cast release. For stale built-in security data Chrome
|
|
103
|
+
degrades the same way: `ChromeCTPolicyEnforcer::IsLogDataTimely` in
|
|
104
|
+
`components/certificate_transparency/chrome_ct_policy_enforcer.cc` treats its built-in CT log list as timely for 70 days
|
|
105
|
+
(`(current_time - log_list_date_).InDays() < 70`), and an untimely build stops CT enforcement
|
|
106
|
+
(`CT_POLICY_BUILD_NOT_TIMELY`) rather than refusing the connection. electron-cast does the same for revocation, and only
|
|
107
|
+
when the fallback CRL is intact but past its window and the device sent no valid CRL. Still enforced: chain to a Cast
|
|
108
|
+
root, the device certificate checks, the signature over this connection's TLS certificate, the device's own CRL
|
|
109
|
+
(including revocation by it), and revocation by a fallback CRL that is still valid. `DeviceAuthResult.revocationChecked`
|
|
110
|
+
is `false` in the skipped case.
|
|
111
|
+
- The fallback CRL's window starts at the package's build time, as Chromium's does at `base::GetBuildTime()`.
|
|
112
|
+
`npm run build` runs `scripts/stamp-build-time.mjs` after `tsc`, which rewrites the one `BUILD_TIME = undefined`
|
|
113
|
+
assignment in `dist/client/auth/build-time.js` and `dist/cjs/client/auth/build-time.js` (honouring
|
|
114
|
+
`SOURCE_DATE_EPOCH`). The source keeps `undefined`, so tests and source checkouts use `FALLBACK_CRL_DEFAULT_BUILD_TIME`
|
|
115
|
+
in `src/client/auth/trust-data.ts`, which still has to be refreshed with the fallback CRL on each release. Patching
|
|
116
|
+
the emit keeps the working tree clean and needs no new dependency, and a published package carries the date of its
|
|
117
|
+
own build, not of the last commit.
|
|
118
|
+
- ML-DSA and other post-quantum keys, and Merkle tree certificates, are not understood (BoringSSL's newer paths).
|
|
119
|
+
- As in Chromium, the reply's `signature_algorithm` field is ignored and a missing or different echoed nonce is
|
|
120
|
+
tolerated (recorded in `deviceAuth.nonceEchoed`).
|
|
121
|
+
|
|
122
|
+
Namespaces (JSON payloads, `payload_type` STRING):
|
|
123
|
+
|
|
124
|
+
| Namespace | Messages |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `urn:x-cast:com.google.cast.tp.connection` | `{type:"CONNECT"}` opens a virtual connection to a destination id; `{type:"CLOSE"}` closes it. |
|
|
127
|
+
| `urn:x-cast:com.google.cast.tp.heartbeat` | `PING` / `PONG`. The sender pings every 5 s; no inbound traffic for 10 s means the connection is dead. Answer the device's `PING` with `PONG`. |
|
|
128
|
+
| `urn:x-cast:com.google.cast.receiver` | `GET_STATUS`, `LAUNCH {appId}`, `STOP {sessionId}`, `SET_VOLUME {volume:{level}}` or `{volume:{muted}}`, `GET_APP_AVAILABILITY {appId:[…]}`. Replies: `RECEIVER_STATUS`, `LAUNCH_ERROR`, `INVALID_REQUEST`, and the availability reply. Requests carry an integer `requestId`; replies echo it. |
|
|
129
|
+
|
|
130
|
+
Ids: the platform receiver is `receiver-0`. Each sender uses `sender-<random>`. After `LAUNCH`, the app's
|
|
131
|
+
`transportId` from `RECEIVER_STATUS.status.applications[]` is the destination for a second `CONNECT` and for all app
|
|
132
|
+
namespace messages.
|
|
133
|
+
|
|
134
|
+
## Discovery layer (`src/discovery/`)
|
|
135
|
+
|
|
136
|
+
mDNS query for PTR `_googlecast._tcp.local`. A device is the join of PTR (instance name) → SRV (target host, port) →
|
|
137
|
+
A/AAAA (address) → TXT (`id`, `fn` friendly name, `md` model, `ca` capability bitmask, `rs` running app status,
|
|
138
|
+
`st`, `ve`, `ic`). Capability bits: 1 video out, 2 video in, 4 audio out, 8 audio in, 16 dev mode, 32 multizone
|
|
139
|
+
group. Groups (`ca & 32`, model `Google Cast Group`) share their leader's address but have their own port and id, so
|
|
140
|
+
devices are keyed by TXT `id`, never by address. TTL 0 is a goodbye.
|
|
141
|
+
|
|
142
|
+
Observed on real devices (fixtures in `test/fixtures/mdns/`):
|
|
143
|
+
|
|
144
|
+
- `ca` carries many more bits than the documented six (e.g. `464901`, `199204`); only test the documented bits.
|
|
145
|
+
- TXT `id` is 32 hex digits for single devices but a dashed UUID for groups: treat it as an opaque string.
|
|
146
|
+
- Fuchsia devices (Nest Hub family) answer with no question section, set the cache-flush bit (class `0x8001`), put
|
|
147
|
+
several PTRs (the device plus every group it leads) in one packet, and send one A plus several AAAA records.
|
|
148
|
+
- On Windows a PC commonly has several adapters (Ethernet, Wi-Fi, Tailscale, WSL/Hyper-V virtual switches) and Cast
|
|
149
|
+
devices answer on only one. Discovery must query and listen on every non-internal IPv4 interface; binding one
|
|
150
|
+
default interface (what `multicast-dns` does) finds nothing on many machines.
|
|
151
|
+
- IPv6 and network changes. Besides IPv4, discovery joins `ff02::fb` on each adapter's link-local address (one
|
|
152
|
+
socket per adapter; if that fails it is reported once and IPv4 carries on). `CastDevice.host` is IPv4 when the
|
|
153
|
+
device has one (Chromium's Cast discovery resolves only A records, so IPv4 is what Chrome would use), else global
|
|
154
|
+
IPv6, else link-local; `addresses` lists them in that order, newest first. Link-local AAAA records get the scope
|
|
155
|
+
of the interface that heard them (`fe80::1%12`), which is what `tls.connect` needs. Devices are still keyed by
|
|
156
|
+
TXT `id`, so a new DHCP address updates the same device (`deviceChanged`). When an interface disappears, devices
|
|
157
|
+
that only it heard are removed at once rather than after their TTL, and a timer that fires far too late (the
|
|
158
|
+
machine slept) makes discovery replace its sockets and query again.
|
|
159
|
+
|
|
160
|
+
### Device addresses
|
|
161
|
+
|
|
162
|
+
Chrome opens a Cast channel only to an address that is neither publicly routable nor loopback, unless the
|
|
163
|
+
`MediaRouterCastAllowAllIPs` policy is set: `CastMediaSinkServiceImpl::OpenChannel`
|
|
164
|
+
(`chrome/browser/media/router/discovery/mdns/cast_media_sink_service_impl.cc`) logs "Did not open a channel to the IP
|
|
165
|
+
endpoint" and reports the channel as not opened, so the sink never appears; the policy is wired in
|
|
166
|
+
`cast_media_sink_service.cc`. The predicates are `net::IPAddress::IsPubliclyRoutable` and `IsLoopback`
|
|
167
|
+
(`net/base/ip_address.cc`), ported in `src/discovery/ip-policy.ts`: IPv4 is routable unless inside one of
|
|
168
|
+
`kReservedIPv4Ranges` (`0/8`, `10/8`, `100.64/10`, `127/8`, `169.254/16`, `172.16/12`, `192.0.0/24`, `192.0.2/24`,
|
|
169
|
+
`192.88.99/24`, `192.168/16`, `198.18/15`, `198.51.100/24`, `203.0.113/24`, `224/3`); IPv6 only inside `2000::/3` and
|
|
170
|
+
`ff00::/8` (unique-local, link-local, `::`, `::1` are not), an IPv4-mapped address by its IPv4 part; a string that is not an
|
|
171
|
+
address counts as routable. Loopback is `127/8` and exactly `::1`, so `::ffff:127.0.0.1` passes, as in Chrome.
|
|
172
|
+
The sink service (`src/electron/sink-service.ts`, `openChannel`) applies them where Chrome does, to the endpoint it is
|
|
173
|
+
about to open, every time; with `sinks.allowAllIps` (`SetCastAllowAllIPs`) it does not.
|
|
174
|
+
|
|
175
|
+
## Polyfill layer (`src/polyfill/`)
|
|
176
|
+
|
|
177
|
+
Implements the legacy Chrome sender API (`chrome.cast`, API version `[1, 2]`), as documented at
|
|
178
|
+
https://developers.google.com/cast/docs/reference/web_sender/chrome.cast. String enums use the official lowercase
|
|
179
|
+
values (`"available"`, `"tab_and_origin_scoped"`, `"cancel"`, …). After install it sets `chrome.cast.isAvailable =
|
|
180
|
+
true` and calls `window.__onGCastApiAvailable(true)` if the page defined it. It covers sessions, custom namespace
|
|
181
|
+
messages, and `chrome.cast.media`: load and queue requests, playback commands, queue operations, media status
|
|
182
|
+
updates (applied to `Media` objects with update listeners), and media listeners on the session. Media traffic rides
|
|
183
|
+
the same bridge as everything else — JSON messages on `urn:x-cast:com.google.cast.media` — so no main-process change
|
|
184
|
+
was needed; joining a session sends a `GET_STATUS` when the receiver supports the media namespace.
|
|
185
|
+
|
|
186
|
+
Google's `cast_sender.js` loader checks for `navigator.presentation`, which Electron exposes, and then loads a
|
|
187
|
+
Presentation API based `chrome.cast` (`www.gstatic.com/eureka/clank/<version>/cast_sender.js`, or one of the Cast
|
|
188
|
+
extension URLs). That script replaces the polyfill's `chrome.cast` and finds no devices, because Electron has no Media
|
|
189
|
+
Router behind the Presentation API. The polyfill refuses those script URLs (through the `src` setter and
|
|
190
|
+
`setAttribute` on script elements) so the loader falls through to loading only `cast_framework.js`, and it calls
|
|
191
|
+
`__onGCastApiAvailable` once, after `DOMContentLoaded` if the page is still loading, for whichever function the page
|
|
192
|
+
assigns. The Cast Application Framework then runs on the polyfill.
|
|
193
|
+
|
|
194
|
+
## Presentation mode (default)
|
|
195
|
+
|
|
196
|
+
Google's `cast_sender.js` loader sees `navigator.presentation` and loads its Presentation API based SDK
|
|
197
|
+
(`www.gstatic.com/eureka/clank/<chrome major>/cast_sender.js`). That SDK implements `chrome.cast` on
|
|
198
|
+
`PresentationRequest` with URLs like `https://google.com/cast#__castAppId__=<appId>/__castClientId__=<id>/...`, and
|
|
199
|
+
talks to Chrome's Media Router over the `PresentationConnection` in a private JSON envelope
|
|
200
|
+
(`{type, message, sequenceNumber, timeoutMillis, clientId}`, defined in Chromium's
|
|
201
|
+
`cast_internal_message_util.cc`). Electron has the Presentation API but no Media Router, so electron-cast supplies
|
|
202
|
+
one:
|
|
203
|
+
|
|
204
|
+
- `src/polyfill/presentation-standin.ts` replaces `PresentationRequest`, `PresentationConnection`,
|
|
205
|
+
`PresentationAvailability` and `navigator.presentation` in the main world. It checks the user gesture (as Blink does:
|
|
206
|
+
`InvalidAccessError`; the preload stamps the real activation on the call and main refuses without it, see SECURITY.md
|
|
207
|
+
"User gesture" for the trust boundary and the known gap against Chrome's browser-side check), allows
|
|
208
|
+
one `start()` at a time, and moves strings over the bridge. It knows nothing about Cast.
|
|
209
|
+
- `src/electron/presentation-envelope.ts` parses the Cast presentation URLs and converts between the envelope and
|
|
210
|
+
the session service's shapes. Examples: receiver labels are hashed, the media-command bitmask becomes strings, and
|
|
211
|
+
null fields are stripped.
|
|
212
|
+
- `src/electron/presentation-handler.ts` (`CastPresentationHandler`) plays the Media Router's part on top of the
|
|
213
|
+
session service: availability, start (picker, launch, `receiver_action` then `new_session`), reconnect
|
|
214
|
+
(`auto-join` and `cast-session_<id>`), app and media messages with request id mapping, volume, leave and stop.
|
|
215
|
+
Its interface (`getAvailability`, `startPresentation`, `reconnectPresentation`, and a connection with `send`,
|
|
216
|
+
`close`, `terminate`, `onmessage` and `onclose`) is the one proposed to Electron as a native hook
|
|
217
|
+
(not shipped). With that hook the stand-in would go away.
|
|
218
|
+
|
|
219
|
+
A navigation (a reload, say) ends the page's connections but parks its sessions instead of leaving them: they stay
|
|
220
|
+
open on the device, get no events, and the sender's next page rejoins them through auto-join or `joinSession`, as with
|
|
221
|
+
Chrome's Media Router. A parked session ends when the receiver app stops or the device drops, and is left for good when
|
|
222
|
+
the webContents is destroyed.
|
|
223
|
+
|
|
224
|
+
After an app restart nothing is persisted, as in Chrome. Chrome's `CastSessionTracker` learns the sessions running on
|
|
225
|
+
every sink from receiver status, and `CastActivityManager::AddNonLocalActivity` turns each into a non-local activity.
|
|
226
|
+
`FindActivityForAutoJoin` skips non-local activities (`route().is_local()`), so `reconnect("auto-join")` finds nothing;
|
|
227
|
+
`FindActivityForSessionJoin` accepts any activity by `cast-session_<id>`, and `AppActivity::CanJoinSession` checks only
|
|
228
|
+
the app, with no origin check. The handler's `reconnect("cast-session_<id>")` calls the service's `joinRunningSession`,
|
|
229
|
+
which joins a session it holds (no origin check either; `joinSession` of `mode: "chromecast"` keeps its own same-origin rule) or else asks each known device for its receiver
|
|
230
|
+
status and registers the session it finds. The one difference from Chrome: the lookup runs on request instead of
|
|
231
|
+
tracking every device continuously. The page must supply the id (Google's SDK stores nothing itself).
|
|
232
|
+
|
|
233
|
+
### Frames
|
|
234
|
+
|
|
235
|
+
Presentation mode follows Chrome: the Presentation API is scoped to a frame. In Chromium,
|
|
236
|
+
`PresentationServiceImpl` (`content/browser/presentation/presentation_service_impl.cc`) is created per
|
|
237
|
+
`RenderFrameHost`; it keeps that frame's availability listeners, passes `render_frame_host_->GetLastCommittedOrigin()`
|
|
238
|
+
as the request origin for start and reconnect, requires transient user activation on that frame
|
|
239
|
+
(`render_frame_host_->HasTransientUserActivation()`), and calls `controller_delegate_->Reset(process_id, frame_id)` when
|
|
240
|
+
the frame is destroyed or commits a non-same-document navigation (`DidFinishNavigation`). The controller delegate
|
|
241
|
+
(`components/media_router/browser/presentation/controller_presentation_service_delegate_impl.cc`) keeps one
|
|
242
|
+
`PresentationFrame` per `GlobalRenderFrameHostId`, and `PresentationFrame::Reset` detaches its routes rather than
|
|
243
|
+
terminating them, which is the "park" here. On the controller side only `SetDefaultPresentationUrls` is limited to the
|
|
244
|
+
outermost document (`is_outermost_document_`); electron-cast keeps the same rule for the default request (see
|
|
245
|
+
[Default presentation request](#default-presentation-request)).
|
|
246
|
+
|
|
247
|
+
electron-cast does the same:
|
|
248
|
+
|
|
249
|
+
- A sender is a frame. The main frame's sender id is its webContents id (unchanged). A subframe gets an id of its own
|
|
250
|
+
(from 2^30 up), allocated on its first call and keyed by `frame.frameTreeNodeId`, which is browser-global and stays
|
|
251
|
+
constant for the frame's lifetime across navigations and process swaps (`processId`/`routingId` change on a
|
|
252
|
+
cross-process navigation, so they can't key a frame that must rejoin its session). The session service and the
|
|
253
|
+
presentation handler still see plain numeric sender ids; only `main.ts` knows about frames (`registerSender`,
|
|
254
|
+
`senderIdOf`, `deliver`).
|
|
255
|
+
- Events go to one frame: `webContents.send` for the main frame, otherwise `frame.send` on the frame found by
|
|
256
|
+
`frameTreeNodeId` in `webContents.mainFrame.framesInSubtree` at send time (a held `WebFrameMain` goes stale when the
|
|
257
|
+
frame navigates).
|
|
258
|
+
- Connections, watches and sessions are owned by the sender; `close`, `terminate` and `send` from another frame are
|
|
259
|
+
ignored, and `senderFrame` of an IPC event is browser-provided, so a frame can't claim another's id. `allowOrigin` and
|
|
260
|
+
the picker see the sending frame's own origin.
|
|
261
|
+
- `did-frame-navigate` for a subframe ends that frame's connections and parks its sessions (`senderNavigated`). A main
|
|
262
|
+
frame `did-navigate` does that for the main frame and ends every subframe sender of that page (`senderGone`). A
|
|
263
|
+
destroyed webContents ends all of them.
|
|
264
|
+
- Electron has no event for a removed iframe (only `frame-created`), so removed frames are found by sweeping: on every
|
|
265
|
+
`did-frame-navigate`, and every 5 seconds (unref'd timer) while a subframe sender exists; a failed `frame.send` also
|
|
266
|
+
ends the sender.
|
|
267
|
+
- The preload only runs in subframes if the app sets `webPreferences.nodeIntegrationInSubFrames: true`; without it
|
|
268
|
+
iframes have no stand-in and behave as before. See the README.
|
|
269
|
+
- `mode: "chromecast"` (`<channel>:call`) stays main-frame only and refuses iframe calls.
|
|
270
|
+
|
|
271
|
+
Not done: Chrome also cancels a pending start whose frame navigated to another origin while the picker was open
|
|
272
|
+
(`HandleStartPresentationResponse` in the controller delegate); here a pending start is cancelled when the frame is
|
|
273
|
+
removed or navigates, not on an origin change alone.
|
|
274
|
+
|
|
275
|
+
### Default presentation request
|
|
276
|
+
|
|
277
|
+
Setting `navigator.presentation.defaultRequest` makes a page castable from the browser's own Cast dialog. Chromium
|
|
278
|
+
(checked against `main`, November 2026):
|
|
279
|
+
|
|
280
|
+
- `third_party/blink/renderer/modules/presentation/presentation.cc`, `Presentation::setDefaultRequest`: stores the
|
|
281
|
+
request and always calls `PresentationService::SetDefaultPresentationUrls` with its URLs, or an empty list for
|
|
282
|
+
`null`. The IDL (`presentation.idl`) types it `PresentationRequest?`, so another value is a `TypeError`.
|
|
283
|
+
- `content/browser/presentation/presentation_service_impl.cc`, `SetDefaultPresentationUrls`: ignored unless the frame is
|
|
284
|
+
the outermost document; ignored when the list equals the one already set; otherwise builds a
|
|
285
|
+
`content::PresentationRequest` (frame id, URLs, last committed origin) and passes it, with
|
|
286
|
+
`OnDefaultPresentationStarted` as the callback, to `ControllerPresentationServiceDelegate::SetDefaultPresentationUrls`.
|
|
287
|
+
`Reset` (a cross-document commit in the same frame, the frame going away) clears it.
|
|
288
|
+
- `components/media_router/browser/presentation/controller_presentation_service_delegate_impl.cc`: one delegate per
|
|
289
|
+
`WebContents`, holding a single `default_presentation_request_`. `SetDefaultPresentationUrls` with no URLs clears it,
|
|
290
|
+
otherwise stores it and calls `NotifyDefaultPresentationChanged`; `Reset` clears it only if the resetting frame owns it.
|
|
291
|
+
`HasDefaultPresentationRequest` / `GetDefaultPresentationRequest` read it (`WebContentsPresentationManager`).
|
|
292
|
+
- `chrome/browser/ui/media_router/media_route_starter.cc`: `InitPresentationSources` and `OnDefaultPresentationChanged` turn
|
|
293
|
+
the request's URLs into the `PRESENTATION` cast mode's sources; `CreateRouteParameters` finds the source for a sink
|
|
294
|
+
(null, hence the "unable to cast" issue in `MediaRouterUI::CreateRoute`, when there is none); `StartRoute` calls
|
|
295
|
+
`MediaRouter::CreateRoute` with `WebContentsPresentationManager::OnPresentationResponse` as the callback. Nothing on
|
|
296
|
+
this path checks a user gesture.
|
|
297
|
+
- `OnPresentationResponse` (the delegate): ignores a result without a route or whose URL is not among the request's;
|
|
298
|
+
records the presentation; and, if the default request equals the one started (`ArePresentationRequestsEqual`), runs
|
|
299
|
+
the callback with a `PresentationConnectionResult`. `PresentationServiceImpl::OnDefaultPresentationStarted` forwards
|
|
300
|
+
it, and `PresentationController::OnDefaultPresentationStarted` (Blink) returns if `defaultRequest` is null, else
|
|
301
|
+
`ControllerPresentationConnection::Create`, which enqueues `connectionavailable` on the request as a task.
|
|
302
|
+
|
|
303
|
+
electron-cast:
|
|
304
|
+
|
|
305
|
+
- The stand-in's `navigator.presentation.defaultRequest` is an accessor with the same semantics, and sends
|
|
306
|
+
`setDefaultRequest { urls }` over the bridge on every set. A `connectionavailable` event from main fires on the current
|
|
307
|
+
default request after the current task; with no default request the connection is dropped (and closed in main), as Blink drops it.
|
|
308
|
+
- `main.ts` keeps a `DefaultPresentationRequests` (`default-presentation.ts`) keyed by `webContents.id`; a call from a
|
|
309
|
+
subframe is ignored, an equal URL list is a no-op, an empty one clears. A main frame navigation or a destroyed window
|
|
310
|
+
clears it (through the same `senderGone` that ends the page's connections).
|
|
311
|
+
- Chrome's launch details (`chrome/browser/media/router/providers/cast/cast_activity_manager.cc`,
|
|
312
|
+
`cast_media_route_provider.cc`, `cast_app_availability_tracker.cc`, `cast_app_discovery_service.cc`,
|
|
313
|
+
`components/media_router/common/providers/cast/cast_media_source.cc`, `chrome/browser/ui/media_router/media_router_ui_helper.cc`):
|
|
314
|
+
`LaunchSession` launches even on a sink with a route and `DoLaunchSession` stops the frame's earlier route
|
|
315
|
+
(`routes_by_frame_`); the launch timeout is the source's `__castLaunchTimeout__` or 60 s, not the dialog's 20 s
|
|
316
|
+
(`GetRouteRequestTimeout`), which the provider ignores; a sink is offered for a source only when the device answered
|
|
317
|
+
`GET_APP_AVAILABILITY` with the app and has the capabilities (`GetAvailableSinks`). The answers are kept in one place,
|
|
318
|
+
`CastAppDiscovery` (`src/electron/app-discovery.ts`, Chrome's `CastAppDiscoveryServiceImpl` with its
|
|
319
|
+
`CastAppAvailabilityTracker`), asked over the sinks' open channels: an available answer is kept, an unavailable one is
|
|
320
|
+
asked again after 60 s (`kRefreshThreshold`, `ShouldRefreshAppAvailability`), an error is kept as `kUnknown` and always
|
|
321
|
+
asked again, and an answer that was in flight when the sink's channel was replaced or the sink went is dropped (a
|
|
322
|
+
generation counter per sink). `checkAppAvailability` asks one sink about one app; the page path observes sources.
|
|
323
|
+
- A page's `PresentationRequest` (`getAvailability()`, `start()`) is served by the same discovery: the handler observes
|
|
324
|
+
the request's source (`StartObservingMediaSinks`: cached sinks at once, the source's new apps asked on every sink,
|
|
325
|
+
`OnSinkAddedOrUpdated` asking the registered apps of a sink whose channel opened, `OnSinkRemoved` dropping a sink's
|
|
326
|
+
answers), observers are told only when an app becomes or stops being available (`UpdateAppAvailability`), and the
|
|
327
|
+
page only when its answer changes (`PresentationMediaSinksObserver::OnSinksReceived`). `start()` offers the sinks of
|
|
328
|
+
the source. `discoverSinksNow()` refreshes (`Refresh`).
|
|
329
|
+
- `startCasting` follows `CreateRouteParameters` (a source for the sink, else `unable_to_cast`), launches through the
|
|
330
|
+
session service's `requestSessionOnDevice` (the same code as `requestSession` with the picker's answer already
|
|
331
|
+
known, reachable from main only), registers the connection like a page's `start()`, and announces it with a
|
|
332
|
+
`connectionavailable` bridge event sent before the first message. As in `OnPresentationResponse`, it is announced only while the
|
|
333
|
+
default request is still the one started. The route is a normal session, so routes observers need nothing more.
|
|
334
|
+
|
|
335
|
+
### Presentation sources
|
|
336
|
+
|
|
337
|
+
Chrome's Cast provider builds a `CastMediaSource` from each presentation URL
|
|
338
|
+
(`components/media_router/common/providers/cast/cast_media_source.cc`, `FromMediaSource`): `remote-playback:` and plain
|
|
339
|
+
https URLs become tab-mirroring sources, a `cast:` URL one app (`ParseCastUrl`), the legacy `https://google.com/cast#` form
|
|
340
|
+
every `__castAppId__` (`ParseLegacyCastUrl`). `ContainsStreamingApp()` (exact match against
|
|
341
|
+
`openscreen::cast::GetCastStreamingAppIds()`: `0F5096E8`, `85CDB22F`) sends the whole source to a `MirroringActivity` in
|
|
342
|
+
`CastActivityManager::DoLaunchSession`, and `IsSiteInitiatedMirroringSource` restricts it to `kPresentationApiAllowlist`
|
|
343
|
+
origins (`CastMediaRouteProvider::GetOrigins`; for others `MediaSinksObserver::OnSinksUpdated` sees an empty list, so
|
|
344
|
+
availability is `UNAVAILABLE`). For `remote-playback:`, `CastMediaRouteProvider::OnSinkQueryUpdated` reports only sinks of
|
|
345
|
+
models known to remote the codec (`media::remoting`). electron-cast has no sink that mirrors or remotes, so
|
|
346
|
+
`src/electron/presentation-source.ts` classifies each URL the same way and the handler treats those as having no sink:
|
|
347
|
+
available `false`, `start` `NotFoundError` "No screens found." (`PresentationServiceImpl::StartPresentation`). Without a
|
|
348
|
+
controller delegate Electron's own browser side reports every URL `UNAVAILABLE`
|
|
349
|
+
(`PresentationServiceImpl::ListenForScreenAvailability`), so `video.remote` never lights up. Several URLs are separate
|
|
350
|
+
sources (`PresentationFrame` listens per URL; `PresentationAvailabilityState::GetScreenAvailability` is available when any
|
|
351
|
+
is), so the first ordinary one is served. Blink drops URLs of unknown protocol in the constructor
|
|
352
|
+
(`PresentationRequest::Create`, `IsKnownProtocolForPresentationUrl`: http family, `cast`, `cast-dial`), which the stand-in
|
|
353
|
+
repeats. Site-initiated mirroring for the allowlisted origins (docs, meet, music.youtube.com) is not available here
|
|
354
|
+
either, though Chrome offers it there. A plain https URL (Chrome's one-UA tab mirroring) is still rejected as
|
|
355
|
+
`NotSupportedError`, not `NotFoundError`. A `cast-dial:` URL is the DIAL kind (`MediaSource::IsDialSource`): with DIAL on,
|
|
356
|
+
`chooseSource` returns it next to the first Cast app URL and the sink the user picks decides which is used (see
|
|
357
|
+
[DIAL](#dial-srcdial)); with DIAL off it is a URL nothing here serves.
|
|
358
|
+
## DIAL (`src/dial/`)
|
|
359
|
+
|
|
360
|
+
Chrome's Media Router has a second provider next to Cast: DIAL (Discovery and Launch), which starts an app on a TV
|
|
361
|
+
or dongle with an HTTP request. Google's SDK uses it when the page passes a `dialRequest`: the SDK then adds
|
|
362
|
+
`cast-dial:<appName>?dialPostData=<data>&clientId=<id>` to the `PresentationRequest`'s URLs next to the `cast:` one,
|
|
363
|
+
and the sink the user picks decides which URL is used. electron-cast follows Chrome's provider rule by rule. Paths
|
|
364
|
+
below are relative to the Chromium source root (read from `chromium/chromium` `main` when this was written).
|
|
365
|
+
|
|
366
|
+
| Part | electron-cast | Chromium |
|
|
367
|
+
|---|---|---|
|
|
368
|
+
| SSDP discovery | `dial-registry.ts`, `ssdp-socket.ts`: one UDP socket per external IPv4 address (the set mDNS uses), bound to an ephemeral port with broadcast on; four `M-SEARCH` requests to `239.255.255.250:1900` a second apart (`MX: 1`, `ST: urn:dial-multiscreen-org:service:dial:1`, `USER-AGENT: <product>/<version> <os>`, a trailing blank line); the cycle ends 2 s after the last one and the sockets close. | `chrome/browser/media/router/discovery/dial/dial_service_impl.cc` (`DialServiceImpl::Discover`, `BuildRequest`, `SendOneRequest`, `FinishDiscovery`, `DialSocket::CreateAndBindSocket`) |
|
|
369
|
+
| SSDP answers | `parse.ts` `parseSsdpResponse`: complete headers, a `LOCATION` that is an http(s) URL whose host is an IP literal that is not publicly routable and equals the sender, a `USN`; `ST` is not checked; `CACHE-CONTROL` max-age capped at 3600; `CONFIGID.UPNP.ORG` accepted when `0 < id <= (2 << 24) - 1`; a 1500-byte read buffer. | `dial_service_impl.cc` (`DialSocket::ParseResponse`), `dial_device_data.cc` (`DialDeviceData::IsValidUrl`) |
|
|
370
|
+
| Registry | A discovery cycle every 120 s; a device expires after 240 s or its max-age; at most 256 devices; keyed by `USN`, labelled by a counter; the list is published only when it changed (or when `discoverNow` forced it). | `dial_registry.cc` (`DialRegistry`, `PruneExpiredDevices`, `MaybeSendDeviceList`, `DiscoverNow`) |
|
|
371
|
+
| Network changes | `DialRegistry.onConnectionChanged`, from the manager's network monitor (`DialService.networksChanged`): each change first counts as offline, which reports `network_disconnected`, stops the periodic search (ending a cycle that is running), forgets every device and publishes the empty list, so the DIAL sinks go; then, when a network is up, discovery starts again: a search at once and the 120 s timer from then. With no network (`__disconnected__`) at `start()` or later, nothing is searched and `discoverNow` refuses. | `dial_registry.cc` (`OnConnectionChanged`, `StartPeriodicDiscovery`, `StopPeriodicDiscovery`, `ReadyToDiscover`, `Clear`); `net/base/network_change_notifier.h` (`OnNetworkChanged` is called with `CONNECTION_NONE` before every online type); `services/network/public/cpp/network_connection_tracker.cc` (`OnNetworkChanged` passes each one to `OnConnectionChanged`) |
|
|
372
|
+
| Device description | `dial-sink-service.ts`: `GET` without an `Origin` header, the `Application-URL` header validated like a `LOCATION` and stripped of a trailing slash, the XML parsed for `UDN`, `friendlyName` (else `<model> [<last 4 of UDN>]`), `modelName` and `deviceType`; cached 12 h by label and `CONFIGID`, 256 entries. | `device_description_fetcher.cc`, `device_description_service.cc` (`ValidateParsedDeviceDescription`), `safe_dial_device_description_parser.cc` |
|
|
373
|
+
| HTTP | `http.ts`: no redirects ("Redirect not allowed"), a 256 KiB body limit, a UTF-8 body, a `GET` with an empty body is an error, `GET` retried twice on 5xx, `POST` and `DELETE` not retried, `POST` as `text/plain`; an `Origin: package:Google-Chrome.<major>.<OS>` header on the app-info `GET`, `POST` and `DELETE` (not on the description `GET`), so a web page cannot make a browser do the same. | `dial_url_fetcher.cc` (`DialURLFetcher`, `GetFakeOriginForDialLaunch`) |
|
|
374
|
+
| App info | `parse.ts` `parseAppInfo`, `dial-sink-service.ts` `fetchAppInfo`: `<service dialVer>` with `name`, `options@allowStop`, `link@href`, `state` (`running` or `stopped`, any case; else invalid) and `additionalData`; the result is a `network_error` (no HTTP status), `http_error` (non-2xx) or `parsing_error` (2xx, unusable body). | `dial_app_discovery_service.cc`, `safe_dial_app_info_parser.cc`, `components/media_router/common/media_source.cc` (`GetDialAppUrl`) |
|
|
375
|
+
| Sinks | `dial-sink-service.ts`: sink id `dial:<UDN without "uuid:" and "-", lower case>`, icon `generic`, extra data `app_url`, `model_name`, `ip_address`; published 3 s after the last change; a sink is available for an app when app info said `running` or `stopped`, unavailable on an `http_error` or `parsing_error`, unknown on a `network_error`; app info is asked only while the answer is unknown, and never of `eureka dongle`, `chromecast audio` or `chromecast ultra`. | `dial_media_sink_service_impl.cc` (`OnDeviceDescriptionAvailable`, `OnDiscoveryComplete`, `FetchAppInfoForSink`, `GetSinkAppStatusFromResponse`), `media_sink_util.cc` |
|
|
376
|
+
| Cast/DIAL dedup | A DIAL sink whose uuid is the `id` of a Cast sink (processed the same way; a Cast sink is a device with an open, authenticated channel, not one mDNS merely heard) is removed from the DIAL sinks: when the Cast sink appears, and whenever DIAL discovery adds or updates it while the Cast sink is there. Nothing adds it back when the Cast sink goes; the next `OnDiscoveryComplete` does (a new device list, a description, or the timer a removal started). | `chrome/browser/media/router/discovery/mdns/cast_media_sink_service_impl.cc` (`OnChannelOpenSucceeded` removes the DIAL sink with the same id; `OnSinkAddedOrUpdated` -> `TryConnectDialDiscoveredSink` removes a DIAL sink that comes after the Cast one), `components/media_router/common/discovery/media_sink_service_base.cc` (`RemoveSinkById` starts the timer), `dial_media_sink_service_impl.cc` (`OnDiscoveryComplete` adds back the round's missing sinks) |
|
|
377
|
+
| Promotion to a Cast sink | `sink-service.ts` `onDialSinksChanged`, `tryConnectDialDiscoveredSink`, `isProbablyNonCastDevice`, `onOpened`: a DIAL sink that is new or changed (and every DIAL sink on `discoverSinksNow()`) is opened as a Cast device at its address on port 8009 (`openChannel(…, "dial")`), with the same retry and timeouts as an mDNS device. The Cast sink has the id of the DIAL sink without `dial:`, its friendly name and its model; once the channel authenticates it has audio out and, unless the device's certificate says audio only, video out. Skipped when a Cast sink has that id or that address (a second channel would be redundant and would end a session on the first). Every failed attempt (not each run) adds one to the device's DIAL count; at 10 the device is taken for a non-Cast device and not tried, whichever way the DIAL sink changes. Opening the device from anything but DIAL (mDNS, a reopen) clears the count, as does a network change. A success does not clear it. The DIAL sink is then removed (previous row). In Chrome this is always on desktop: `DualMediaSinkService` gives the DIAL sink service to `CastMediaSinkService` unconditionally, behind no flag. | `cast_media_sink_service_impl.cc` (`OnSinkAddedOrUpdated`, `TryConnectDialDiscoveredSink`, `CreateCastSinkFromDialSink`, `IsProbablyNonCastDevice`, `OpenChannel`, `OnChannelErrorMayRetry`, `OnChannelOpenSucceeded`, `OnNetworksChanged`, `DiscoverSinksNow`), `cast_media_sink_service_impl.h` (`kMaxDialSinkFailureCount` 10), `chrome/browser/media/router/providers/cast/dual_media_sink_service.cc` (`Initialize`), `chrome/browser/media/router/mojo/media_router_desktop.cc` (`InitializeDialMediaRouteProvider`) |
|
|
378
|
+
| Availability | `session-service.ts` `observeAppAvailability` (the same observation as a Cast source: the handler passes the request's DIAL app next to its Cast app), `origins.ts`: a `cast-dial:` source is available when a sink has the app; for `youtube`, `netflix`, `pandora`, `radio`, `hulu`, `vimeo` and `dailymotion` only to Chrome's list of origins (matched case-insensitively on the app name); a request with a Cast URL too is available if either is. Like Chrome's, the first DIAL answer is what is known now (the app query is still on its way); a DIAL sink that has the app answers yes at once, and a Cast URL next to it waits for the Cast sinks asked, as a Cast-only request does. | `chrome/browser/media/router/providers/dial/dial_media_route_provider.cc` (`StartObservingMediaSinks`, `GetOrigins`), `components/media_router/browser/media_sinks_observer.cc` (`OnSinksUpdated`) |
|
|
379
|
+
| Create a route | `route-provider.ts` `createRoute`: unknown sink, a source that is not a `cast-dial:` launch (the `clientId` is required) and a repeated route fail like `SINK_NOT_FOUND`, `NO_SUPPORTED_PROVIDER`, `ROUTE_ALREADY_EXISTS`; an existing route on the sink is terminated first; the page gets `receiver_action` (`cast`) and `new_session` at once. The route id is `urn:x-org.chromium:media:route:<presentation id>/<sink id>/<source>` and the presentation id `mr_<uuid>`. | `dial_media_route_provider.cc` (`CreateRoute`), `dial_activity_manager.cc` (`DialActivity::From`, `AddActivity`), `dial_internal_message_util.cc`, `components/media_router/common/media_route.cc` (`GetMediaRouteId`), `components/media_router/browser/media_router_base.cc` (`CreatePresentationId`) |
|
|
380
|
+
| The SDK's round trip | `client_connect` makes the provider fetch app info and send `custom_dial_launch` (`{receiver, appState, extraData}` with a fresh sequence number, remembered in a set of at most 10); the page answers with the same number and `{doLaunch, launchParameter}`; an answer to an unknown number is ignored. `dial_app_info` is answered with the app info or an `error` (`network_error`, `parsing_error`, `http_error` with `details.http_error_code`) under the same number. A failed fetch at `client_connect` sends nothing, as in Chrome, and the route stays. | `dial_media_route_provider.cc` (`HandleParsedRouteMessage`, `HandleClientConnect`, `HandleCustomDialLaunchResponse`, `HandleAppInfoRequest`), `dial_internal_message_util.cc` |
|
|
381
|
+
| Launch | `doLaunch: false` marks the route launched without a request; otherwise a `POST` to `<app url>/<app>` whose body is the launch parameter, else the source's `dialPostData` exactly as written in the source (Chrome reads the raw, still escaped query value); a `LOCATION` that is an http URL on the sink's own address becomes the run URL; a failed launch removes the route. | `dial_activity_manager.cc` (`LaunchApp`, `CustomDialLaunchMessageBody::From`, `DialActivity::From`) |
|
|
382
|
+
| Stop | A `v2_message` of type `STOP` or a page's `terminate()` sends `receiver_action` (`stop`) and `DELETE`s the run URL (`<app url>/<app>/run` when the launch gave none); a route that was never launched is dropped without a request; a failure looks at app info again and posts an issue unless the app is no longer running; the connection ends `terminated` either way. | `dial_media_route_provider.cc` (`DoTerminateRoute`, `HandleStopAppResult`), `dial_activity_manager.cc` (`StopApp`) |
|
|
383
|
+
| Join and close | `reconnect` with an `mr_` id joins the route with the same presentation id, source and origin and sends nothing; closing a connection, navigating or closing the page leaves the route and the app running. | `dial_media_route_provider.cc` (`JoinRoute`; `DetachRoute` is `NOTIMPLEMENTED`), `components/media_router/browser/presentation/controller_presentation_service_delegate_impl.cc` |
|
|
384
|
+
|
|
385
|
+
Differences from Chrome, and why:
|
|
386
|
+
|
|
387
|
+
- **Network changes are polled.** Chrome clears the DIAL failure counts when `DiscoveryNetworkMonitor` reports a new
|
|
388
|
+
network id, and its `DialRegistry` restarts discovery when `NetworkConnectionTracker` reports a connection change; the
|
|
389
|
+
manager's monitor drives both, by reading the interfaces (see
|
|
390
|
+
[Network changes](#network-changes-network-monitorts)). A change of the network id stands for Chrome's
|
|
391
|
+
`CONNECTION_NONE` then the new type; Node cannot tell a cellular connection apart, which Chrome never searches on.
|
|
392
|
+
- **Timeouts.** Chrome sets none on its URL fetches (`DialActivityManager::CreateFetcher` has a TODO for it); Node
|
|
393
|
+
would wait forever, so a `GET` gives up after 10 s and a `POST` or `DELETE` after 30 s.
|
|
394
|
+
- **`setMulticastInterface`.** Each SSDP socket also pins its multicast sends to its interface, which Windows needs to
|
|
395
|
+
send from the right adapter.
|
|
396
|
+
- **The `Origin` product.** `package:Google-Chrome.<major>.<OS>` is the syntax in `GetFakeOriginForDialLaunch`'s
|
|
397
|
+
comment; `<major>` comes from the Chromium that Electron ships (`0` outside Electron).
|
|
398
|
+
- **Stop failures.** Chrome posts an issue (`IDS_MEDIA_ROUTER_ISSUE_CANNOT_TERMINATE`); the provider emits an `issue`
|
|
399
|
+
event and rejects `terminateRoute`, and the connection still ends.
|
|
400
|
+
- **Volume.** A DIAL route has none, as in Chrome (`BindMediaController` is `NOTIMPLEMENTED`).
|
|
401
|
+
- **Errors never throw.** Chrome only logs a DIAL discovery error (`DialMediaSinkServiceImpl::OnDialError`) and a failed
|
|
402
|
+
socket is closed while the others carry on (`DialSocket::CheckResult`, `DialServiceImpl::NotifyOnError`, which
|
|
403
|
+
reports `DIAL_SERVICE_NO_INTERFACES` when no socket is left). The registry does the same, `DialService` logs through
|
|
404
|
+
`dial.log`, and an empty interface list ends the cycle without an error (`DiscoverOnAddresses`).
|
|
405
|
+
- **Origins and bounds.** Chrome starts the app query for any page and filters the answer by origin on delivery
|
|
406
|
+
(`StartObservingMediaSinks`, then `MediaSinksObserver::OnSinksUpdated`). Here nothing is queried for an origin that
|
|
407
|
+
could not see the answer, at most 32 apps are monitored at once and 2048 app statuses are kept. A page can still make
|
|
408
|
+
the devices answer app-info requests for app names no allowlist covers, as in Chrome.
|
|
409
|
+
- **A request waits for the devices.** Chrome's dialog observes the sinks of the source while it is open; a `start()`
|
|
410
|
+
that finds no sink yet waits up to 5 s for the app answers instead of failing at once (and only when something is
|
|
411
|
+
being asked, see above).
|
|
412
|
+
- **Cancelled requests.** Stopping the service aborts every request in flight. A route terminated while its launch
|
|
413
|
+
`POST` is in flight cancels it, as erasing the record destroys the fetcher in `DialActivityManager::StopApp`; the
|
|
414
|
+
device may still have started the app, which Chrome cannot tell either.
|
|
415
|
+
- **`mode: "chromecast"`.** Its sinks observers list DIAL sinks too (port 0, no capabilities); `createClient` and Cast
|
|
416
|
+
sessions refuse such a device with an error.
|
|
417
|
+
- **The XML reader** (`xml.ts`) stands in for Chromium's out-of-process `data_decoder`: it refuses entity
|
|
418
|
+
declarations, caps the depth and ignores namespaces.
|
|
419
|
+
|
|
420
|
+
## Electron layer (`src/electron/`)
|
|
421
|
+
|
|
422
|
+
No Electron import: both modules take the Electron objects they need as parameters, typed by small structural
|
|
423
|
+
interfaces, so the library has no Electron dependency and runs in plain Node.
|
|
424
|
+
|
|
425
|
+
- `main.ts`: `createCastManager({ ipcMain, selectDevice, allowOrigin?, discovery?, createClient?, channel?,
|
|
426
|
+
presentation? })` returns `{ start, devices, dispose, ... }` (see MAIN-API.md). It registers one invoke handler on `<channel>:call`; events
|
|
427
|
+
go back to the page on `<channel>:event`. Unless `presentation: false`, it also serves presentation mode:
|
|
428
|
+
`<channel>:presentation` (invoke), `<channel>:presentation:send` (page to main) and `<channel>:presentation:event`
|
|
429
|
+
(main to page). Each connection and availability watch belongs to one frame, and the others can't touch it. `selectDevice(devices, request)` resolves the user's choice: a device, `null` (maps to
|
|
430
|
+
`chrome.cast.ErrorCode.CANCEL`) or `"stop"`
|
|
431
|
+
(stop `request.session`, the sender's current session, which is set when the sender is already casting that app;
|
|
432
|
+
picking that session's device returns it without relaunching). `allowOrigin(origin)` gates every call by the
|
|
433
|
+
sender frame's origin. A sender is one frame (see Frames): the main frame leaves its sessions when its webContents is destroyed and parks them
|
|
434
|
+
when it navigates (`did-navigate`); a subframe likewise on `did-frame-navigate` and removal.
|
|
435
|
+
- `preload.ts`: `installCastBridge({ contextBridge, ipcRenderer, channel?, mode?, bridgeKey?,
|
|
436
|
+
presentationBridgeKey? })` exposes a bridge and, before page scripts run, installs the Presentation API stand-in
|
|
437
|
+
(default) or, with `mode: "chromecast"`, the polyfill.
|
|
438
|
+
|
|
439
|
+
Main process:
|
|
440
|
+
|
|
441
|
+
<!-- no-check -->
|
|
442
|
+
```ts
|
|
443
|
+
import { ipcMain, BrowserWindow } from "electron";
|
|
444
|
+
import { createCastManager } from "electron-cast/main";
|
|
445
|
+
|
|
446
|
+
const manager = createCastManager({
|
|
447
|
+
ipcMain,
|
|
448
|
+
selectDevice: async (devices, request) => {
|
|
449
|
+
const win = new BrowserWindow(); // your picker UI
|
|
450
|
+
await win.loadFile("picker.html");
|
|
451
|
+
return pickFromUI(devices, request); // or null for CANCEL
|
|
452
|
+
},
|
|
453
|
+
allowOrigin: (origin) => origin === "https://music.youtube.com",
|
|
454
|
+
});
|
|
455
|
+
await manager.start();
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Preload script:
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
import { contextBridge, ipcRenderer } from "electron";
|
|
462
|
+
import { installCastBridge } from "electron-cast/preload"; // not the root: it loads node:tls, which a sandboxed preload cannot
|
|
463
|
+
|
|
464
|
+
installCastBridge({ contextBridge, ipcRenderer });
|
|
465
|
+
// the page now has chrome.cast; the bridge key defaults to "__electronCastBridge"
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### Sinks and sessions (`sink-service.ts`, `session-tracker.ts`)
|
|
469
|
+
|
|
470
|
+
Chrome's Media Router does not look a device up when a page asks. It opens a channel to every device mDNS finds, lists
|
|
471
|
+
a device as a sink only when that channel is open and authenticated, keeps the channel open, and learns what each
|
|
472
|
+
device runs from the receiver status that comes over it. electron-cast does the same, with Chromium `main` (November
|
|
473
|
+
2026) as the reference. Paths are relative to the Chromium source root.
|
|
474
|
+
|
|
475
|
+
| Rule | Where here | Chromium |
|
|
476
|
+
|---|---|---|
|
|
477
|
+
| A channel is opened to each discovered device, after a random delay of up to 5 s so that many senders do not hit one receiver together | `CastSinkService.openChannelsWithRandomizedDelay` (`openDelayMaxMs`) | `chrome/browser/media/router/discovery/mdns/cast_media_sink_service_impl.cc`: `OpenChannelsWithRandomizedDelay`; `cast_media_sink_service.cc`: `OnDnsSdEvent` |
|
|
478
|
+
| The channel is a `CastSocket` that has passed device authentication (our `CastClient.connect()`); only then is the device a sink | `onOpened` | `cast_media_sink_service_impl.cc`: `OnChannelOpened`, which runs after `CastSocketImpl` finished the auth handshake (`components/media_router/common/providers/cast/channel/cast_socket.cc`) |
|
|
479
|
+
| A device that fails to open (a connect error or a failed authentication) is retried with `net::BackoffEntry`: 15 s initial, factor 1, 50% jitter, 30 s cap, 3 attempts, then it is dropped and never listed | `onOpenError`, `onOpenGaveUp` (`retry`) | `cast_media_sink_service_impl.h`: `RetryParams`; `.cc`: `OnChannelErrorMayRetry`, `OnChannelOpenFailed`; `net/base/backoff_entry.cc`: `CalculateReleaseTime` |
|
|
480
|
+
| Public and loopback addresses are skipped, unless the `kMediaRouterCastAllowAllIPs` policy is on | `openChannel` (`allowAllIps`) | `cast_media_sink_service_impl.cc`: `OpenChannel`; `cast_media_sink_service.cc`; `net/base/ip_address.cc`: `IsPubliclyRoutable`, `IsLoopback` |
|
|
481
|
+
| The sinks are reported to observers once discovery has been quiet for 3 s, and only when the list changed | `markChanged`, `report` (`reportDelayMs`) | `components/media_router/common/discovery/media_sink_service_base.cc`: `kDiscoveryTimeout`, `StartTimer`, `OnDiscoveryComplete` |
|
|
482
|
+
| mDNS forgetting a device does not close its channel or remove its sink. A sink is removed when its channel fails and cannot be reopened | `onClientClosed`, `removeSink` | `cast_media_sink_service_impl.cc`: `OnError` (reopens through `OpenChannel`), `OnChannelOpenFailed` |
|
|
483
|
+
| One channel per IP endpoint, shared by sink discovery and sessions. A sink whose address changed gets a channel to the new one; two ids at one address are one sink | `sinkMap`, `pending`, `onOpened` | `components/media_router/common/providers/cast/channel/cast_socket_service.cc`: `AddSocket`, `GetSocket`; `cast_media_sink_service_impl.cc`: `OnChannelOpened`, `UpdateCastSink` |
|
|
484
|
+
| The channel is kept alive: a PING every 5 s and a 10 s liveness timeout. A failure closes it, and the sink service reopens it | `CastClient` heartbeat, then `onClientClosed` | `cast_media_sink_service_impl.h`: `ping_interval_in_seconds` 5, `liveness_timeout_in_seconds` 10; `cast_socket.cc`: `KeepAliveDelegate`; `cast_media_sink_service_impl.cc`: `OnError` |
|
|
485
|
+
| When a sink is added or its channel opens, the device is asked for its receiver status | `CastSessionTracker.attach` | `chrome/browser/media/router/providers/cast/cast_session_tracker.cc`: `OnSinkAddedOrUpdated` -> `RequestReceiverStatus` |
|
|
486
|
+
| A status describes a session only if it has exactly one application with a session id, app id, transport id and display name, whose transport is not `receiver-0`, which is not the backdrop app and has namespaces (a multizone leader may have none). Cast's reserved namespaces are dropped except the media one | `sessionFromStatus` | `chrome/browser/media/router/providers/cast/cast_internal_message_util.cc`: `CastSession::From`; `cast_message_util.cc`: `IsCastReservedNamespace` |
|
|
487
|
+
| `MEDIA_STATUS` entries on the device's channel are merged by `mediaSessionId` into the session, fields an update lacks are kept, and a `supportedMediaCommands` bit mask becomes a list of names | `CastSessionTracker.applyMedia` | `cast_session_tracker.cc`: `HandleMediaStatusMessage`, `CopySavedMediaFieldsToMediaList`; `cast_internal_message_util.cc`: `CastSession::UpdateMedia`, `SupportedMediaCommandsToListValue` |
|
|
488
|
+
| Every receiver status that describes a session and every MEDIA_STATUS is passed on, changed or not; the media controller of any route, local or not, takes its volume and media status from them | `sessionStatus` and `mediaStatus` events, `createMediaControllers` | `cast_session_tracker.cc`: `HandleReceiverStatusMessage` (`OnSessionAddedOrUpdated`), `HandleMediaStatusMessage` (`OnMediaStatusUpdated`); `cast_activity_manager.cc`: `BindMediaController`, `AddNonLocalActivity`; `app_activity.cc`: `OnSessionUpdated`, `SendMediaStatusToClients`; `cast_media_controller.cc`: `SetSession`, `SetMediaStatus` |
|
|
489
|
+
| A session no page of this app holds is a route anyway, with no page and not local; its description is the status text, else the display name. It stays while the device runs it | `CastSessionService.mediaRoutes`, `nonLocalRouteOf` | `chrome/browser/media/router/providers/cast/cast_activity_manager.cc`: `AddNonLocalActivity`, `OnSessionAddedOrUpdated`; `cast_internal_message_util.cc`: `GetRouteDescription` |
|
|
490
|
+
| `joinRunningSession` joins a session the tracker already knows, by id and app, with no origin check and no scan. An unknown id, or another app's session, finds nothing | `handleJoinRunningSession` | `cast_activity_manager.cc`: `FindActivityForSessionJoin`; `app_activity.cc`: `CanJoinSession` |
|
|
491
|
+
| A non-local route can be terminated (the receiver's `STOP`) and have its volume set, over the device's own channel | `terminateSession`, `setSessionVolume` | `cast_activity_manager.cc`: `TerminateSession` |
|
|
492
|
+
|
|
493
|
+
Resources: a device costs one TLS connection and one 5 s ping, as in Chrome, however many pages there are. Everything
|
|
494
|
+
is released when a sink is removed, on `dispose()` (every channel is closed, timers are cleared) and after sleep: the
|
|
495
|
+
first missed ping closes the channel and the reopen runs the retry policy, so a device that is back is listed again and
|
|
496
|
+
one that is not is dropped after three attempts. Chrome has no setting that disables this or caps the number of
|
|
497
|
+
channels, so there is none here either; `allowAllIps`, `sinks.retry`, `sinks.openDelayMaxMs` and `sinks.reportDelayMs`
|
|
498
|
+
mirror what Chrome tunes.
|
|
499
|
+
|
|
500
|
+
Where electron-cast differs from Chrome here:
|
|
501
|
+
|
|
502
|
+
- Chrome's connect and liveness timeouts can grow with each failed attempt on a sink (`failure_count_map_`, at most 100,
|
|
503
|
+
times `OpenParams::dynamic_timeout_delta_in_seconds`, capped at `kMaxConnectTimeoutInSeconds` 30 and
|
|
504
|
+
`kMaxLivenessTimeoutInSeconds` 60 in `CreateCastSocketOpenParams`), but that delta is 0 and nothing in the fetched
|
|
505
|
+
sources sets it, so Chrome's timeouts stay 10 s. The same mechanism is here (`sinks.dynamicTimeoutDeltaMs`, default 0;
|
|
506
|
+
each run of attempts keeps the parameters it began with, as the `open_params` carried through
|
|
507
|
+
`OnChannelErrorMayRetry`) and the timeouts reach `createClient` as its second argument.
|
|
508
|
+
- When a sink's endpoint changes, Chrome's `OnChannelOpenSucceeded` just adds the sink with the new channel and leaves the
|
|
509
|
+
old socket alone, so a session on it goes on. Here the replaced channel stays open while a session uses it and closes
|
|
510
|
+
when the last one ends (`CastSinkService.releaseUnused`, `channelRetired`), or on `dispose()`.
|
|
511
|
+
- mDNS lists a device's addresses in no fixed order, and a Chrome sink has one address, so there is no Chrome counterpart
|
|
512
|
+
to a reorder. A sink keeps its endpoint while the device still offers it (same port, host among its addresses): only the
|
|
513
|
+
other details are updated, as `OpenChannel` does for an unchanged endpoint, and a reopen uses that endpoint too.
|
|
514
|
+
- A retry waiting out its backoff is dropped when the device has meanwhile been reached at another endpoint or discovery
|
|
515
|
+
names another one; Chrome's `OnChannelOpenFailed` ignores a failure whose endpoint is no longer the sink's for the same
|
|
516
|
+
reason, but still re-runs the stale `OpenChannel`.
|
|
517
|
+
- A channel is opened to IP addresses only, as Chrome's `IPEndPoint` is. A device whose host is a name (a custom
|
|
518
|
+
discovery) is skipped with a `skipped` event and one `console.warn` per device; `isPubliclyRoutable` answers for IP
|
|
519
|
+
literals only. Chrome logs the same kind of skip in `OpenChannel` (`LoggerList`).
|
|
520
|
+
- A route whose channel is down (the sink stays listed while it is reopened, as in Chrome) stays listed. Terminating it
|
|
521
|
+
fails with `session_error` and Chrome's message: `CastMessageHandler::StopSession` finds no socket and reports a
|
|
522
|
+
failure, and `CastActivityManager::HandleStopSessionResponse` turns that into "StopSession response is not OK. Failed
|
|
523
|
+
to terminate route." and keeps the activity.
|
|
524
|
+
- A page's own launch is not listed as a non-local route while it is in flight: the status the launch causes reaches the
|
|
525
|
+
tracker before the page's session record exists. Chrome has the activity before the launch (`DoLaunchSession` adds it
|
|
526
|
+
first), so the route is never non-local there.
|
|
527
|
+
- `CastSession::UpdateSession` keeps the old session id and app when another session shows up on a device, which would
|
|
528
|
+
leave the tracker naming a session the device no longer runs; a different session replaces the old one here.
|
|
529
|
+
- A status with several applications is never a session, so such a session cannot be joined (as in Chrome).
|
|
530
|
+
- The tracker asks for status when a channel opens and then follows what the device pushes; Chrome asks again whenever
|
|
531
|
+
a sink is added or updated (`OnSinkAddedOrUpdated`), including when only its name changed.
|
|
532
|
+
- The snapshot of a session this app started still passes the app's namespaces unfiltered, as before.
|
|
533
|
+
|
|
534
|
+
### Network changes (`network-monitor.ts`)
|
|
535
|
+
|
|
536
|
+
Chrome's `DiscoveryNetworkMonitor` (`chrome/browser/media/router/discovery/discovery_network_monitor.cc`) keeps one
|
|
537
|
+
network id for the machine and tells its observers when it changes. electron-cast has the same monitor, one per manager:
|
|
538
|
+
`createCastManager` makes it, `start()` starts it and `dispose()` stops it. There is no method for the app to call.
|
|
539
|
+
|
|
540
|
+
| Rule | Here | Chrome |
|
|
541
|
+
|---|---|---|
|
|
542
|
+
| The network list | `discoveryNetworkInfoList`: each interface that is not loopback and has a MAC address, with an id; sorted by id | `GetDiscoveryNetworkInfoList` (`discovery_network_list_win.cc`, `discovery_network_list_posix.cc`): Ethernet and Wi-Fi interfaces that are up, each with its SSID (Wi-Fi) or MAC address; `StableSortDiscoveryNetworkInfo` sorts by id |
|
|
543
|
+
| The network id | `computeNetworkId`: `__disconnected__` for an empty list, `__unknown__` when no network has an id, else the hex SHA-256 of `"!" + id` for each network in order | `ComputeNetworkId`, `kNetworkIdDisconnected`, `kNetworkIdUnknown` |
|
|
544
|
+
| When observers hear | only when the recomputed id differs from the last; the first id is taken without telling anyone | `UpdateNetworkInfo`, run on every `OnConnectionChanged` from the `NetworkConnectionTracker`; the monitor is one per browser and has its id before a profile's services observe it |
|
|
545
|
+
| The Cast sinks | the DIAL failure counts are cleared; the sinks of the network being left are kept by its id (not those added by access code); on coming back to a known network its sinks are opened again after the usual random delay. The sinks are not cleared and discovery is not restarted | `CastMediaSinkServiceImpl::OnNetworksChanged` (`dial_sink_failure_count_`, `sink_cache_`, `OpenChannelsWithRandomizedDelay` with `SinkSource::kNetworkCache`); its `Start` asks `GetNetworkId` first |
|
|
546
|
+
| Devices added by address | those with no route are removed, and the remembered ones are added again 4.45 s later | `AccessCodeCastSinkService::OnNetworksChanged` (`kExpirationDelay` + `kNetworkChangeBuffer`) |
|
|
547
|
+
|
|
548
|
+
| DIAL discovery | each change forgets the DIAL devices and, with a network up, searches at once; no search while disconnected (the "Network changes" row of [DIAL](#dial-srcdial)) | `DialRegistry::OnConnectionChanged`, an observer of the `NetworkConnectionTracker` rather than of this monitor |
|
|
549
|
+
|
|
550
|
+
These are the only two observers of the monitor in Chrome; DIAL follows the connection tracker, which the manager's
|
|
551
|
+
monitor stands in for. Differences, and why:
|
|
552
|
+
|
|
553
|
+
- **A poll, not an event.** Chrome recomputes when `NetworkChangeNotifier` reports a connection change; Node and
|
|
554
|
+
Electron have no such event, so the monitor reads `os.networkInterfaces()` every 5 s (`NETWORK_POLL_MS`). A change is
|
|
555
|
+
seen up to 5 s late, and a drop and return within one interval is not seen.
|
|
556
|
+
- **MAC and IPv4 network instead of SSID.** Node reports neither an interface's type nor its Wi-Fi SSID. An interface
|
|
557
|
+
counts when it is not loopback and has a MAC address (tunnels have none), and its id is the MAC with the IPv4 networks
|
|
558
|
+
it is on (address and netmask, so a new DHCP address on the same network is no change). Joining another Wi-Fi network
|
|
559
|
+
is a change when its subnet differs, which Chrome sees by SSID; two networks with the same subnet on one adapter look
|
|
560
|
+
the same. Virtual adapters with a MAC (Hyper-V, WSL, some VPNs) count, where Chrome counts Ethernet and Wi-Fi only.
|
|
561
|
+
- **Off with a custom `discovery`**, as DIAL is, unless `networkMonitor` is given; `networkMonitor: false` turns it off.
|
|
562
|
+
|
|
563
|
+
### Access code casting (`access-code.ts`)
|
|
564
|
+
|
|
565
|
+
Chrome can cast to a device that mDNS does not reach, by typing the code the device shows on its screen. Chrome calls this
|
|
566
|
+
Access Code Cast (the product around it is Cast Moderator). It is two things, and only the second is here. Chromium `main`
|
|
567
|
+
(November 2026); paths are relative to the Chromium source root, under
|
|
568
|
+
`chrome/browser/media/router/discovery/access_code/` unless a path is given.
|
|
569
|
+
|
|
570
|
+
**1. Turning a code into an address: not supported.** Chrome sends the code to Google's `castedumessaging-pa.googleapis.com`
|
|
571
|
+
(`access_code_cast_constants.cc`: `kDefaultDiscoveryEndpoint`, `kDiscoveryServicePath`; a `GET /v1/receivers/<code>` built in
|
|
572
|
+
`access_code_cast_discovery_interface.cc`: `CreateEndpointFetcher`) with an OAuth token of the signed-in Chrome profile
|
|
573
|
+
(`SetAuthType(OAUTH)`, `ConsentLevel::kSignin`, consumer `OAuthConsumerId::kAccessCodeCastDiscovery`, whose only scope is
|
|
574
|
+
`https://www.googleapis.com/auth/cast-edu-messaging`, `google_apis/gaia/oauth_consumer_registry.cc`). Without a signed-in
|
|
575
|
+
profile the flow stops before the request (`ui/webui/access_code_cast/access_code_cast_handler.cc`: `IsPrimaryAccountSignedIn`,
|
|
576
|
+
`PROFILE_SYNC_ERROR`). The service is an internal Google one (`discovery_resources.proto` points at a google3
|
|
577
|
+
`discovery_service.proto`) with no public documentation and no key for apps; the token comes from Chrome's own sign-in and
|
|
578
|
+
OAuth client, which an Electron app does not have and must not borrow. The feature is also off unless an administrator sets
|
|
579
|
+
`AccessCodeCastEnabled` (default false, for `chrome.*` and `chrome_os` from 102, per profile;
|
|
580
|
+
`components/policy/resources/templates/policy_definitions/GoogleCast/`), and it is not built on Android
|
|
581
|
+
(`access_code_cast_feature.cc`: `!BUILDFLAG(IS_ANDROID)`). So electron-cast cannot resolve codes. The only override is
|
|
582
|
+
`--access-code-cast-url`, which Chrome honours on non-stable, non-beta builds only (`access_code_cast_constants.cc`:
|
|
583
|
+
`IsCommandLineSwitchSupported`), and it points at the same kind of service.
|
|
584
|
+
|
|
585
|
+
**2. Adding the device it names: here, with the address supplied by the app.** What the server returns is a device id, a
|
|
586
|
+
name, capabilities and a network address (`discovery_resources.proto`: `DiscoveryDevice`, `NetworkInfo`). Everything after
|
|
587
|
+
that is a normal Cast sink and does not depend on Google: `CreateAccessCodeMediaSink` builds a `MediaSinkInternal` from it,
|
|
588
|
+
`AddSinkToMediaRouter` has `CastMediaSinkServiceImpl::OpenChannel` open a Cast channel to the address, and the sink is listed
|
|
589
|
+
like an mDNS one. `CastManager.addSinkByAddress(device)` does that part; where the address comes from (a directory, a
|
|
590
|
+
config, the user typing an IP address) is up to the app. The device then goes through the same picker and the same
|
|
591
|
+
Presentation API availability as any other: `CastAppDiscoveryServiceImpl` asks every sink of `CastMediaSinkServiceImpl` for
|
|
592
|
+
app availability (`providers/cast/cast_app_discovery_service.cc`: `StartObservingMediaSinks`, `Refresh`), whatever its
|
|
593
|
+
`discovery_type`, and `CastActivityManager` uses the type only for metrics. Chrome's own entry point is a separate dialog in
|
|
594
|
+
the Cast menu (`chrome/browser/ui/webui/access_code_cast/`); a page cannot open it, and the app's picker takes its place here.
|
|
595
|
+
|
|
596
|
+
Mind what "another network" means: the server returns the address the device has registered, and Chrome opens a channel to
|
|
597
|
+
it by the same rule as for any sink, which refuses public and loopback addresses unless `MediaRouterCastAllowAllIPs` is set
|
|
598
|
+
(`mdns/cast_media_sink_service_impl.cc`: `OpenChannel`). So this reaches devices that are routable but not on mDNS's
|
|
599
|
+
multicast domain (another VLAN or subnet, as in a school or office); it does not traverse NAT, and a public address needs
|
|
600
|
+
`sinks.allowAllIps`.
|
|
601
|
+
|
|
602
|
+
| Rule | Where here | Chromium |
|
|
603
|
+
|---|---|---|
|
|
604
|
+
| Access code casting is off unless enabled; with it off nothing is added, remembered or timed (default `false`) | `accessCode.enabled`, `AccessCodeCastDisabledError` | `access_code_cast_feature.cc`: `GetAccessCodeCastEnabledPref`; `access_code_cast_sink_service_factory.cc`: `GetForProfile`, `BuildServiceInstanceForBrowserContext`; `AccessCodeCastEnabled.yaml` |
|
|
605
|
+
| The device must be an object with a string name and id and a capabilities object whose present values are booleans; otherwise the reply is malformed | `createAccessCodeSink` (`response_malformed`) | `access_code_cast_discovery_interface.cc`: `ConstructDiscoveryDeviceFromJson` |
|
|
606
|
+
| A sink needs, in this order: an IP literal (IPv6 preferred over IPv4), a non-empty id, a non-empty name, a port (a decimal integer in 0..65535, default 8009) | `createAccessCodeSink` (`sink_creation_error` and its `reason`) | `access_code_media_sink_util.cc`: `CreateAccessCodeMediaSink`, `GetIPAddress`; `net/base/port_util.cc`: `IsPortValid`; `mdns/media_sink_util.cc`: `CreateCastMediaSinkResult` |
|
|
607
|
+
| The id is processed as an mDNS id is (`uuid:` and dashes dropped, lower case) and put in angle brackets as the sink id (`cast:<%s>`; an mDNS sink is `cast:%s`); the model name is `Chromecast Cast Moderator`; capabilities are the five flags as the same bits an mDNS `ca` record has | `createAccessCodeSink` | `access_code_media_sink_util.cc`: `kDefaultAccessCodeModelName`, `ConvertDeviceCapabilities`; `components/media_router/common/discovery/media_sink_internal.cc`: `ProcessDeviceUUID` |
|
|
608
|
+
| A device already listed keeps its channel (and endpoint); only its name and capabilities are refreshed, and its stored data and time are replaced | `addSinkToMediaRouter`, `updateExistingSink` | `access_code_cast_sink_service.cc`: `OpenChannelIfNecessary`, `UpdateExistingSink` |
|
|
609
|
+
| Otherwise a channel is opened with its own quick parameters: connect 2 s, liveness 8 s, ping 4 s, retried 1 s apart (50% jitter, no growth) up to the sink service's 3 attempts; a failure is `channel_open_error` | `CastSinkService.openSink` (`params`, `backoff`), `MANUAL_ENTRY_PARAMS`, `MANUAL_ENTRY_BACKOFF` | `access_code_cast_sink_service.cc`: `kConnectTimeoutInSeconds`, `kPingIntervalInSeconds`, `kLivenessTimeoutInSeconds`, `backoff_policy_`, `OpenChannelIfNecessary`, `OnChannelOpenedResult`; `cast_media_sink_service_impl.cc`: `OnChannelErrorMayRetry` |
|
|
610
|
+
| The address rules of discovered devices apply: a public or loopback address is not opened to | `CastSinkService.openChannel` | `cast_media_sink_service_impl.cc`: `OpenChannel` |
|
|
611
|
+
| A device added by code is remembered with its addition time; another entry at the same IP endpoint is replaced | `storeSinkInPrefs`, `AccessCodeStore` | `access_code_cast_pref_updater_impl.cc`: `UpdateDevicesDict`, `UpdateDeviceAddedTimeDict`; `access_code_cast_pref_updater.cc`: `GetMatchingIPEndPoints` |
|
|
612
|
+
| It stays listed for `deviceDuration` seconds from when it was added (policy default 0) plus 20 s, so that a route can be created first | `setExpirationTimer`, `durationTillExpiration` (`accessCode.deviceDuration`) | `access_code_cast_sink_service.cc`: `DoSetExpirationTimer`, `DoCalculateDurationTillExpiration`; `access_code_cast_sink_service.h`: `kExpirationTimerDelay`; `AccessCodeCastDeviceDuration.yaml` |
|
|
613
|
+
| When the time is up, a device a page is casting to (a local route) stays until that route ends; any other is forgotten and its channel removed 450 ms later | `onExpiration`, `expireSink`, `removeAndDisconnectMediaSinkFromRouter` | `access_code_cast_sink_service.cc`: `OnExpiration`, `ExpireSink`, `RemoveAndDisconnectMediaSinkFromRouter`, `kExpirationDelay` |
|
|
614
|
+
| When a route to such a device ends, after 450 ms with no new route its time is checked and, if up, it expires at once | `onRoutesUpdated`, `checkMediaSinkForExpiration` | `access_code_cast_sink_service.cc`: `AccessCodeMediaRoutesObserver::OnRoutesUpdated`, `HandleMediaRouteRemovedByAccessCode`, `OnAccessCodeRouteRemoved`, `DoCheckMediaSinkForExpiration` |
|
|
615
|
+
| Remembered devices are read when the service starts (entries that do not validate are dropped), added again with the sink service's usual open parameters, and their timers set | `AccessCodeSinks.load`, `initAllStoredDevices` | `access_code_cast_sink_service.cc`: `InitAllStoredDevices`, `ValidateStoredDevices`; `access_code_media_sink_util.cc`: `ParseValueDictIntoMediaSinkInternal` |
|
|
616
|
+
| A network change removes the devices that have no route, and after 4.45 s the remembered ones are added again | `onNetworksChanged`, from the manager's network monitor | `access_code_cast_sink_service.cc`: `OnNetworksChanged`, `RemoveAndDisconnectExistingSinksOnNetwork`, `kNetworkChangeBuffer` |
|
|
617
|
+
| The policies apply while running: disabling removes and forgets every device, a new duration resets every timer | `configureAccessCode` | `access_code_cast_sink_service.cc`: `OnEnabledPrefChange`, `OnDurationPrefChange` |
|
|
618
|
+
|
|
619
|
+
Where electron-cast differs from Chrome here:
|
|
620
|
+
|
|
621
|
+
- The device arrives as an object, not as the server's JSON, so `networkInfo` and `deviceCapabilities` are flat fields and
|
|
622
|
+
the "no network info / no capabilities" results (`kMissingNetworkInfo`, `kMissingDeviceCapabilities`) cannot occur: a
|
|
623
|
+
missing capabilities object is `response_malformed`, as a missing dict is in `ConstructDiscoveryDeviceFromJson`. A port
|
|
624
|
+
may be a number as well as the server's string; Chrome would ignore a number and use 8009, which here would hide a typo.
|
|
625
|
+
An address that is not a string counts as absent, as in Chrome.
|
|
626
|
+
- Chrome names an access code sink `cast:<uuid>`, with literal angle brackets, where an mDNS sink is `cast:uuid`, so a
|
|
627
|
+
device found both ways is two sinks until the same-address rule removes one. That is kept: electron-cast's mDNS ids have
|
|
628
|
+
no `cast:` scheme, so an address-added sink is `<uuid>`. As a guard Chrome does not need, the service only remembers and
|
|
629
|
+
expires a sink it opened itself; an already listed sink with the same id (a custom discovery could produce one) is only
|
|
630
|
+
refreshed, so an expiry timer can never remove a device discovery found.
|
|
631
|
+
- Chrome does not check the address beyond `OpenChannel`'s rule (below), and its server is trusted to name real devices.
|
|
632
|
+
Here the address comes from the app, so the app must validate what a user typed: private addresses and any port pass
|
|
633
|
+
Chrome's rules, so an unchecked address turns `addSinkByAddress` into a probe of the LAN (a TLS connection to any
|
|
634
|
+
host and port, and the error says whether it answered). An IPv4-mapped IPv6 address is judged by the IPv4 address in it
|
|
635
|
+
(`net/base/ip_address.cc`: `IsPubliclyRoutableIPv6`); `IsLoopback` does not look inside it.
|
|
636
|
+
- The prefs become `AccessCodeStore` (`load` once when enabled, `save` the whole list after each change), with the app
|
|
637
|
+
deciding where it lives; one entry holds the data of Chrome's two dictionaries. The default store is memory.
|
|
638
|
+
- Chrome learns of a network change from `DiscoveryNetworkMonitor`; the manager's monitor polls for it (see
|
|
639
|
+
[Network changes](#network-changes-network-monitorts)).
|
|
640
|
+
- The result is reported after the device is remembered and its timer set; Chrome reports first.
|
|
641
|
+
- Chrome's metrics, its `chrome://media-router-internals` log (here the optional `accessCode.log`), its offline check
|
|
642
|
+
(`SERVICE_NOT_PRESENT`) and the dialog that goes on to start a route are not here: the app starts a cast through its own
|
|
643
|
+
picker once the device is listed.
|
|
644
|
+
|
|
645
|
+
## Wired displays
|
|
646
|
+
|
|
647
|
+
Opt-in (`wiredDisplay` on `createCastManager`, presentation mode only). It follows Chromium's
|
|
648
|
+
`WiredDisplayMediaRouteProvider` (chrome/browser/media/router/providers/wired_display/), `PresentationReceiverWindowController`
|
|
649
|
+
and `LocalPresentationManager`, with the receiver side of Blink's `PresentationReceiver`. Code: `src/electron/wired-display/`,
|
|
650
|
+
`src/polyfill/presentation-receiver.ts`.
|
|
651
|
+
|
|
652
|
+
- **Sinks** (`displays.ts`): one per display, id `wired_display_<id>`, name "Display N" (N counts from 1 over the sorted
|
|
653
|
+
list: primary first, then by y, then x). Displays that mirror the primary are dropped, so a single or mirrored setup has
|
|
654
|
+
no sinks. The display the controller window is on is hidden only in the picker (see "The picker's display" below), as Chrome's dialog does;
|
|
655
|
+
availability and `getSinks` still list it.
|
|
656
|
+
- **Sources**: https that is not the legacy Cast URL, or http on localhost. Anything else is not served.
|
|
657
|
+
- **Routes** (`provider.ts`): one per presentation, description `Presenting (<host>)`. Creating a route on a display first
|
|
658
|
+
terminates the presentation already there, as `CreateRoute` does.
|
|
659
|
+
- **Local presentations** (`local-presentation.ts`): in-process connection pairs (`ControllerEnd`/`ReceiverEnd`), a
|
|
660
|
+
pending controller per frame until the receiver page registers, and an origin check on join. A connection is
|
|
661
|
+
`connecting` until the receiver page touches `navigator.presentation`, then `connected`.
|
|
662
|
+
- **Termination**: `terminate()` (either side), a closed window, a removed display and navigation of the receiver all end
|
|
663
|
+
through the window closing, and every controller sees `terminated`. A controller going away only unregisters its
|
|
664
|
+
connection.
|
|
665
|
+
- **Receiver window** (`electron-windows.ts`): fullscreen, shown inactive, on the display's bounds, own non-persistent
|
|
666
|
+
session per presentation, downloads refused, only fullscreen permitted, and the first main-frame navigation is the only one
|
|
667
|
+
allowed (`PresentationNavigationPolicy`). Chrome starts the receiver's browsing context with `kPresentationReceiverSandboxFlags`
|
|
668
|
+
(kModals, kPopups, kTopNavigation: `presentation_receiver_flags.h`), which every frame inherits and which makes
|
|
669
|
+
`ShouldSuppressDialogs` moot. Electron cannot set starting flags, so the same sandbox is sent as a `Content-Security-Policy:
|
|
670
|
+
sandbox` header (`RECEIVER_SANDBOX`: every token but `allow-modals`, `allow-popups` and the `allow-top-navigation*` ones) on each
|
|
671
|
+
main-frame and subframe response through `session.webRequest.onHeadersReceived`; an iframe's `alert()` is refused like the
|
|
672
|
+
page's own. `setWindowOpenHandler` denies windows, a `beforeunload` prompt cannot hold the window, and there is no menu
|
|
673
|
+
(`removeMenu`, so no reload or developer-tools accelerator) and no `devTools`, as Chrome's receiver window has no browser UI.
|
|
674
|
+
A finished presentation's in-memory session is cleared and kept for the next one (up to four), instead of one new session each.
|
|
675
|
+
`createReceiverWindows` can be called once per `ipcMain` and channel until its `dispose()`; a second call throws. F11 toggles fullscreen (Control+Command+F on macOS).
|
|
676
|
+
- **Receiver page API** (`presentation-receiver.ts`): `navigator.presentation.receiver.connectionList`,
|
|
677
|
+
`connectionavailable`, `send`, `close`, `terminate`; it registers lazily on first use.
|
|
678
|
+
- **Sizes**: Blink limits only binary, to 4 GiB, with a `RangeError` from `send()` ("ArrayBuffer size exceeds the maximum supported
|
|
679
|
+
size (4294967295)"); text has no limit. Here a local presentation has one cap, 64 MiB, in both directions and for text (UTF-16
|
|
680
|
+
code units), bytes and Blobs alike (`MAX_MESSAGE_SIZE`). Both stand-ins refuse a larger `send()` with that `RangeError` before
|
|
681
|
+
anything crosses IPC, so nothing is lost silently; main drops what a page past the stand-in sends anyway. A Cast connection keeps its
|
|
682
|
+
own 1 MiB limit in main. An ArrayBuffer or view is copied at the call (Blink reads an ArrayBuffer when its turn comes), so a
|
|
683
|
+
detached one is a `TypeError` at the call and never reaches the queue.
|
|
684
|
+
- **Binary messages** (`presentation_connection.cc`, `presentation.mojom`'s `PresentationConnectionMessage` union of `message` and
|
|
685
|
+
`data`): on both stand-ins `send()` takes a string, an ArrayBuffer, an ArrayBufferView or a Blob (anything else is converted
|
|
686
|
+
to a string, as WebIDL picks the DOMString overload). Sends leave through one queue, in order; while a Blob is being read the
|
|
687
|
+
ones behind it wait (`HandleMessageQueue`), a Blob that fails to read is skipped, and a connection that ends drops its queue
|
|
688
|
+
(`TearDown`). A view is copied when sent, an ArrayBuffer when its turn comes. `binaryType` is `arraybuffer` by default;
|
|
689
|
+
`blob` and `arraybuffer` are accepted and anything else is ignored; a received message is converted when it arrives. In main
|
|
690
|
+
the local pair copies the bytes (Blink copies into a Vector). The Cast path matches Chrome by dropping bytes:
|
|
691
|
+
`CastSessionClientImpl::OnMessage` returns at once for a message that is not text, so a page can send them without an error and
|
|
692
|
+
the device never hears of it.
|
|
693
|
+
- **The picker's display** (`MediaRouterUI::GetEnabledSinks` with `WebContentsDisplayObserver`): the display the page's window is on
|
|
694
|
+
is found with `BrowserWindow.fromWebContents(wc)` and `screen.getDisplayMatching(win.getBounds())`, looked up at every start. While a
|
|
695
|
+
picker is open `request.observeSinks` gives the new list when the window moves or resizes to another display or a display
|
|
696
|
+
comes or goes. Without a window for the page (or without the `BrowserWindow` option) every display is offered. `displayOf`
|
|
697
|
+
overrides the lookup.
|
|
698
|
+
|
|
699
|
+
Forced by Electron: a sandboxed preload must be a real bundled file, so the receiver preload is generated into a folder the
|
|
700
|
+
app gives (`preloadDir`); the package never imports Electron, so `screen`, `BrowserWindow`, `session` and `ipcMain` are passed
|
|
701
|
+
in; Electron has no per-window display observer, so the display of a page is derived from its window's bounds on move and
|
|
702
|
+
resize; a binary message over IPC is capped at 64 MiB (`MAX_BINARY_BYTES`; Blink allows 4 GiB) because it is cloned through
|
|
703
|
+
the main process. The Blob is read in the page, as Blink reads it in the renderer, and sent as bytes.
|
|
704
|
+
|
|
705
|
+
- **Mixed requests** (a Cast app URL and a standard source in one `PresentationRequest`): Chrome's dialog lists both kinds of sink.
|
|
706
|
+
When displays and Cast devices both exist, `selectDevice` is the one picker: it gets `request.displays` and answers `{ display: id }`
|
|
707
|
+
for a display, which starts the wired presentation, or a device, which casts. With devices but no displays it is the Cast flow
|
|
708
|
+
unchanged, with displays but no devices `selectDisplay` runs. `reconnect(id)` goes to a display for a local id and to Cast otherwise.
|
|
709
|
+
- **Differences kept on purpose**: `reconnect(id)` with a local id but a URL the presentation was not started with is rejected with
|
|
710
|
+
`NotFoundError`, where Chrome never settles the promise; and one manager serves one provider where Chrome's
|
|
711
|
+
`MediaRouter` is per profile, so presentations of different `createCastManager` calls do not know of each other.
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
## Mirroring (`src/mirroring/`)
|
|
715
|
+
|
|
716
|
+
Tab and desktop mirroring, as Chrome's Cast dialog offers ("Cast tab", "Cast screen"). It is a TypeScript port of the
|
|
717
|
+
sender Chrome uses today, and it keeps Chrome's boundaries so the port can later be swapped for the real Mirroring
|
|
718
|
+
Service (the upstream Electron RFC):
|
|
719
|
+
|
|
720
|
+
```
|
|
721
|
+
MirroringActivity <-> CastMessageChannel <-> Mirroring Service (OpenscreenSessionHost -> openscreen sender)
|
|
722
|
+
mirroring-activity.ts (a callback pair) engine.ts, session-host.ts, sender/
|
|
723
|
+
mirroring-manager.ts (utility process: electron/engine-process.ts)
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
Every module cites the Chromium or openscreen file and function it ports. Chromium paths are from
|
|
727
|
+
`chromium/src@main`; openscreen paths are from `third_party/openscreen/src` (`cast/streaming/...`). Fetched, not
|
|
728
|
+
recalled, on 2026-11-25.
|
|
729
|
+
|
|
730
|
+
### What Chrome does (verified)
|
|
731
|
+
|
|
732
|
+
Chrome no longer has its own RTP stack for this: `media/cast/sender/{video,audio}_sender.cc` and
|
|
733
|
+
`openscreen_frame_sender.cc` wrap openscreen's `SenderSession`/`Sender`/`SenderPacketRouter`, and
|
|
734
|
+
`components/mirroring/service/openscreen_session_host.cc` drives them. `MirroringActivity`
|
|
735
|
+
(`chrome/browser/media/router/providers/cast/mirroring_activity.cc`) sits in the browser: it routes the CastMessages of
|
|
736
|
+
the streaming namespaces and starts and stops the host. So the port is openscreen's sender, plus the Chromium frame
|
|
737
|
+
sender policy, plus the session host, plus the routing.
|
|
738
|
+
|
|
739
|
+
### Module map
|
|
740
|
+
|
|
741
|
+
| Ours (`src/mirroring/`) | Ported from |
|
|
742
|
+
|---|---|
|
|
743
|
+
| `protocol/constants.ts` | openscreen `cast/streaming/public/constants.h`, `impl/rtp_defines.h`, `impl/session_config.h`, `public/capture_recommendations.h`, `impl/ssrc.cc` |
|
|
744
|
+
| `protocol/frame-id.ts` | openscreen `cast/streaming/public/frame_id.h`, `impl/expanded_value_base.h` (`ExpandLessThanOrEqual`, `ExpandGreaterThan`) |
|
|
745
|
+
| `protocol/offer.ts` | openscreen `public/offer_messages.cc` (`Offer::ToJson`, `Stream::ToJson`, `AudioStream`, `VideoStream`), `public/sender_session.cc` (`CreateStream`) |
|
|
746
|
+
| `protocol/answer.ts` | openscreen `public/answer_messages.cc` (`Answer::TryParse`, constraints, display), `public/resolution.cc`, `public/receiver_message.cc` (`ReceiverMessage::Parse`, `ReceiverCapability`) |
|
|
747
|
+
| `protocol/recommendations.ts` | openscreen `public/capture_recommendations.cc` (`GetRecommendations`) |
|
|
748
|
+
| `protocol/messenger.ts` | openscreen `public/session_messenger.cc` (namespaces, 4 s reply timeout, `*` destination), `sender_session.cc` (`Negotiate`, `OnAnswer`, `RequestCapabilities`, `OnCapabilitiesResponse`, `ToCapabilities`) |
|
|
749
|
+
| `rtp/packetizer.ts` | openscreen `impl/rtp_packetizer.cc` |
|
|
750
|
+
| `rtp/frame-crypto.ts` | openscreen `impl/frame_crypto.cc` |
|
|
751
|
+
| `rtcp/ntp.ts`, `rtcp/sender-report.ts` | openscreen `impl/ntp_time.cc`, `impl/sender_report_builder.cc`, `impl/rtcp_common.cc` |
|
|
752
|
+
| `rtcp/parser.ts` | openscreen `impl/compound_rtcp_parser.cc` |
|
|
753
|
+
| `sender/sender.ts` | openscreen `impl/sender_impl.cc` (`Sender`) |
|
|
754
|
+
| `sender/packet-router.ts` | openscreen `impl/sender_packet_router.cc` |
|
|
755
|
+
| `sender/bandwidth-estimator.ts` | openscreen `impl/bandwidth_estimator.cc` |
|
|
756
|
+
| `sender/video-encoder-metrics.ts` | Chromium `media/cast/encoding/media_video_encoder_wrapper.cc` (`CalculateEncoderUtilization`, `ComputeAndRecordUtilization`, `ComputeLossiness`) |
|
|
757
|
+
| `sender/capture-size-oracle.ts` | Chromium `media/capture/content/video_capture_oracle.cc` (`RecordConsumerFeedback`, `AnalyzeAndAdjust`, `AnalyzeForDecreasedArea`, `AnalyzeForIncreasedArea`), `capture_resolution_chooser.cc`, `media/base/feedback_signal_accumulator.h`, `media/capture/video/video_capture_types.cc` (`SuggestConstraints`), `media/base/video_util.cc` (`ScaleSizeToTarget`, `PadToMatchAspectRatio`) |
|
|
758
|
+
| `sender/frame-sender.ts` | Chromium `media/cast/sender/openscreen_frame_sender.cc`, `video_sender.cc`, `audio_sender.cc`, `media/cast/constants.h` |
|
|
759
|
+
| `session-host.ts` | Chromium `components/mirroring/service/openscreen_session_host.cc` (`NegotiateMirroring`, `OnError` fallback offer, `OnVideoEncoderStatus`, `MaybeFallbackHardwareFrameRate`, `MaybeDenylistHardwareCodecAndRenegotiate`), `mirror_settings.cc`, `mirroring_features.cc`, `media/cast/openscreen/config_conversions.cc` |
|
|
760
|
+
| `encoding-support.ts` | Chromium `media/cast/encoding/encoding_support.cc` (`IsHardwareEnabled`, `IsSoftwareEnabled`, the hardware deny list, `GetCodecParameterString`, `ToProfile`) and the `kCastStreamingForce{Enable,Disable}Hardware*` switches of `media/base/media_switches.cc` |
|
|
761
|
+
| `mirroring-activity.ts` | Chromium `mirroring_activity.cc` (`OnAppMessage`, `OnInternalMessage`, `HandleParseJsonResult`, `StartSession`, `StopMirroring`, `ScheduleFetchMirroringStats`, `FetchMirroringStats`) and `cast_activity_manager.cc` (`DoLaunchSession`, `OnActivityStopped`) |
|
|
762
|
+
| `mirroring-manager.ts` | Chromium `cast_activity_manager.cc` (`LaunchSession`, `TerminateSession`, `NotifyAllOnRoutesUpdated`), `media_route.cc` (`GetMediaRouteId`), `media_router_debugger.h` (the mirroring stats methods) |
|
|
763
|
+
| `routing.ts` | Chromium `cast_media_source.cc` (`CastMediaSourceForTabMirroring`, `ForDesktopMirroring`, `ProvidesStreamingAudioCapture`, the streaming `CastAppInfo`s), `components/media_router/common/media_source.cc`, `cast_activity_manager.cc` (`ChooseAppId`), `mirroring_activity.cc` (`StartSession`, `GetRouteDescription`, `GetMirroringNamespace`, `GetScrubbedLogMessage`), `chrome/app/media_router_strings.grdp` |
|
|
764
|
+
| `stats/*.ts` | openscreen `impl/statistics_{collector,dispatcher,analyzer,common}.cc`, `impl/clock_offset_estimator_impl.cc`, `public/statistics.cc`; Chromium `openscreen_stats_client.cc`, `openscreen_session_host.cc` (`GetMirroringStats`), `stats_event_subscriber.cc` (`CastStatToString`) |
|
|
765
|
+
| `engine.ts` | assembles `OpenscreenSessionHost` around a backend, as the Mirroring Service does with its resource provider |
|
|
766
|
+
| `transport/udp-environment.ts` | openscreen `cast/streaming/public/environment.cc` (`SendPacket`, `GetMaxPacketSize`, `OnRead`) and `SenderPacketRouter::OnReceivedPacket` (packets only from the announced endpoint) |
|
|
767
|
+
| `electron/agent-source.ts`, `electron/port-backend.ts`, `electron/agent-protocol.ts` | Chromium `components/mirroring/service/video_capture_client.cc` (`ProcessFeedback`, `SwitchVideoCaptureHost`), `audio_capturing_callback.cc`, `media/cast/encoding/{video_encoder,audio_encoder}.cc` (frame ids, key frames, bitrate), `media_video_encoder_wrapper.cc` (frame duration, utilization, lossiness), `frame_complexity_estimator.cc` (the agent's complexity estimate), `components/viz/service/frame_sinks/video_capture/frame_sink_video_capturer_impl.cc` (what the oracle is shown per frame), `openscreen_session_host.cc` (`OnVideoEncoderStatus`, `ProcessFeedback`), `media/capture/video_capture_types.cc` (`SuggestConstraints`), `content/browser/media/capture/frame_sink_video_capture_device.cc` (`SetResolutionConstraints`), blink `media_stream_constraints_util_video_content.cc` (`SelectResolutionPolicyFromCandidates`), blink `video_encoder.cc` (`GetRequiredEncoderType`, `isConfigSupported`) |
|
|
768
|
+
| `electron/host.ts` | Chromium `chrome/browser/media/cast_mirroring_service_host.cc` (the tab and desktop capture sources) and the hardware encoder query of `openscreen_session_host.cc` (`supported_profiles_`), answered by WebCodecs |
|
|
769
|
+
| `mirroring-activity.ts` `shouldForceLetterboxing` | Chromium `mirroring_activity.cc` (`ShouldForceLetterboxing`) |
|
|
770
|
+
|
|
771
|
+
### Process split
|
|
772
|
+
|
|
773
|
+
One mirroring route is three contexts:
|
|
774
|
+
|
|
775
|
+
- **Main process**: the control plane. `MirroringManager` and `MirroringActivity` launch the streaming app (`0F5096E8`
|
|
776
|
+
audio and video, `85CDB22F` audio only; `GetCastStreamingAudioVideoAppId` and `GetCastStreamingAudioOnlyAppId` in
|
|
777
|
+
openscreen `cast/common/public/cast_streaming_app_ids.h`) over the Cast v2 channel the CastClient already speaks,
|
|
778
|
+
open the virtual connection, relay the `urn:x-cast:com.google.cast.webrtc` and `...remoting` messages to and from the
|
|
779
|
+
engine, and stop the app when the route ends. It never sees a frame.
|
|
780
|
+
- **Engine, an Electron `utilityProcess`** (`electron/engine-process.ts`, one per route): the whole sender. The session
|
|
781
|
+
host (OFFER, ANSWER, bandwidth), `SenderSession`, `Sender`s, `SenderPacketRouter`, the frame sender policy, AES and
|
|
782
|
+
packetizing, and the UDP socket. Pacing is a 10 ms burst timer (`kDefaultBurstInterval`); a busy main process would
|
|
783
|
+
add jitter the receiver's 200 ms playout delay does not forgive, and a stuck page cannot stall a stream. Everything in
|
|
784
|
+
it is plain TypeScript over an injected clock and socket (`SenderEnvironment`), so the same code runs in-process in
|
|
785
|
+
tests. The frame sender policy lives here, not in the renderer: `ShouldDropNextFrame` reads the sender's in-flight
|
|
786
|
+
state, and Chrome makes that call synchronously on one thread.
|
|
787
|
+
- **Capture agent, a hidden `BrowserWindow`** (`electron/agent-source.ts`) on a private in-memory partition, sandboxed,
|
|
788
|
+
with navigation and window creation denied. It captures (`getUserMedia` with `chromeMediaSource: 'tab'` and the id
|
|
789
|
+
from `webContents.getMediaSourceId`; or `getUserMedia` with `chromeMediaSource: 'desktop'` and the `desktopCapturer` id the app chose, plus loopback audio where the OS has it; `getDisplayMedia` would need a user gesture the hidden page never has, and Chrome's `CastMirroringServiceHost` asks for none), reads tracks with `MediaStreamTrackProcessor`, and encodes with WebCodecs
|
|
790
|
+
`VideoEncoder` and `AudioEncoder`. A `MessagePort` goes straight between the agent and the engine, so frame bytes
|
|
791
|
+
never pass through main. A hidden window was chosen over the source page's isolated world because the page cannot
|
|
792
|
+
disturb it (navigation, CSP, `beforeunload`) and the library needs no foothold in the app's page.
|
|
793
|
+
|
|
794
|
+
The agent and the engine split the work as Chrome splits capture and the Mirroring Service. The agent announces each
|
|
795
|
+
raw frame (RTP timestamp, reference time); the engine runs `VideoSender::InsertRawVideoFrame` (the drop decision) and
|
|
796
|
+
answers `encode`; the agent encodes and posts the chunk; the engine assigns the frame id and calls
|
|
797
|
+
`FrameSender::EnqueueFrame`. Audio works the same way per 10 ms buffer. A frame that never yields a chunk (encoder queue full, evicted, unsupported, swallowed by the encoder, encoder error) is reported as `video-drop` or `audio-drop`; the engine turns a video drop into Chrome's empty encoded frame (`VideoSender::OnFrameDroppedByEncoder`) so the sender's in-encoder count never leaks, and an audio drop becomes skipped samples on the next frame. Audio RTP and reference times follow `AudioEncoder::ImplBase::EncodeAudio` (underrun skip above `kUnderrunSkipThreshold`). A bitrate change reconfigures the running encoder in place and forces no key frame. The agent holds at most three raw frames and
|
|
798
|
+
closes the oldest, so a dropped frame costs nothing. A `VideoFrame` goes from the track
|
|
799
|
+
processor into the encoder; the only pixel read is one copy of the frame per encoded frame for the complexity estimate (see "Encoder feedback"). Encoded chunks are copied once, through the port (Electron cannot transfer an
|
|
800
|
+
`ArrayBuffer` over a `MessagePortMain`).
|
|
801
|
+
|
|
802
|
+
The agent keeps at most the session's frame rate with Chrome's `SmoothEventSampler`
|
|
803
|
+
(`media/capture/content/smooth_event_sampler.cc`): a token bucket that fills with the time between frames, holds at most
|
|
804
|
+
1.5 frame periods and pays one period for each frame kept. Chrome runs it in the capturer on compositor updates; the
|
|
805
|
+
agent runs it on the capture timestamps of the frames the track delivers, so frames that arrive bunched after a stall
|
|
806
|
+
are kept, and it allows 0.01 ms for timestamps rounded to microseconds. A frame's reference time is its capture time from
|
|
807
|
+
the frame metadata when the source has one, else its capture timestamp moved onto the wall clock by the smallest delay
|
|
808
|
+
seen; it never goes backwards, so a refresh frame cannot overtake the next real one. A tab switch learns the new
|
|
809
|
+
track's clock offset again.
|
|
810
|
+
|
|
811
|
+
### Encoder feedback: lossiness, utilization and the capture size
|
|
812
|
+
|
|
813
|
+
What Chrome does. `MediaVideoEncoderWrapper::OnFrameEncodeDone` gives every encoded frame an `encoder_utilization`
|
|
814
|
+
(`CalculateEncoderUtilization`: processing time over the target frame duration for a software encoder, the worse of
|
|
815
|
+
backlog and latency for a hardware one, clamped to [0, 2] and smoothed with an exponential average of weight 0.1) and a
|
|
816
|
+
`lossiness`: the frame's bitrate as a share of the target bitrate, times a normalized quantizer (`ComputeLossiness`,
|
|
817
|
+
clamped to [0, 5]). The quantizer is the encoder's QP when it reports one; otherwise the wrapper asks
|
|
818
|
+
`FrameComplexityEstimator` before encoding: the Shannon entropy of the luma differences (neighbouring pixels in a key
|
|
819
|
+
frame, the same pixel of the previous frame otherwise) over 10% of the rows, divided by 7.5 and capped at 1.
|
|
820
|
+
`VideoSender` keeps the last of each, and `ReportResourceUtilization` passes `max(utilization, lossiness) / 0.75` (a key
|
|
821
|
+
frame capped at 1) to `OpenscreenSessionHost::ProcessFeedback` and `VideoCaptureClient::ProcessFeedback`, which attaches
|
|
822
|
+
it to the next buffer it releases. For a tab that reaches `FrameSinkVideoCaptureDevice::OnUtilizationReport` and
|
|
823
|
+
`FrameSinkVideoCapturerImpl`, whose `VideoCaptureOracle` (created with auto-throttling on, in `FrameSinkManagerImpl`)
|
|
824
|
+
turns it into a capture size. The first positive utilization activates throttling. Each report updates an average of the
|
|
825
|
+
area the consumer could handle (capture area divided by utilization). When that, or the buffer pool's utilization, is
|
|
826
|
+
below the current area, the target drops by at least one snapped size (`CaptureResolutionChooser`: steps of 90 lines,
|
|
827
|
+
each at least 15% smaller in area, between the limits of the resolution change policy). When both leave room, it rises
|
|
828
|
+
one step: at once for content that is not animating, after 30 s of contiguous headroom while it is. A change takes
|
|
829
|
+
effect at most every 3 s. A fixed resolution has one size, so nothing adapts. The desktop capturer
|
|
830
|
+
(`DesktopCaptureDevice`) has a `CaptureResolutionChooser` too but never reads the feedback, so a screen is always
|
|
831
|
+
captured at the largest allowed size.
|
|
832
|
+
|
|
833
|
+
What is built. WebCodecs reports no QP, so Chrome's no-QP path is the only path. The agent copies each encoded frame's
|
|
834
|
+
planes once (0.5 to 1.4 ms for 1080p in the smoke test, measured around the copy and the estimate) and runs a port of
|
|
835
|
+
the estimator over the same 10% of rows (`agent-source.ts`), for I420, I420A, I422, I444 and NV12 frames. Other formats
|
|
836
|
+
get no complexity and no lossiness, as in Chrome, where the estimator returns nothing for them. The agent reports
|
|
837
|
+
`complexity` and the frame duration (the frame's own `duration`, else the time since the last frame clamped to 1/60 to
|
|
838
|
+
1/24 s: `GetFrameDuration`). `PortBackend` computes lossiness and utilization with the wrapper's formulas
|
|
839
|
+
(`sender/video-encoder-metrics.ts`), against the target bitrate in force when the chunk arrives. `VideoSender` was
|
|
840
|
+
already the consumer of both. No web API carries a `VideoCaptureFeedback` from a page to the capture device
|
|
841
|
+
(WebCodecs, `MediaStreamTrackProcessor` and the track API have none), so the oracle (`sender/capture-size-oracle.ts`)
|
|
842
|
+
runs in the engine, for tab sources only, and is shown each frame as `FrameSinkVideoCapturerImpl::MaybeCaptureFrame`
|
|
843
|
+
shows it: source size, the event, then the capture with the pipeline utilization (frames in the encoder over 6). Its
|
|
844
|
+
capture size goes to the agent as `capture-size`, rounded down to even numbers as `DesktopCaptureDevice` does with
|
|
845
|
+
`& ~1`. The agent configures the encoder for that size and gives it the unscaled frame, which a WebCodecs encoder
|
|
846
|
+
scales (checked in Electron 45: a 1920x1080 frame encoded with a 640x360 configuration decodes at 640x360). A change
|
|
847
|
+
of size reconfigures the encoder, as a change of source size already did.
|
|
848
|
+
|
|
849
|
+
Differences:
|
|
850
|
+
|
|
851
|
+
- The capture still happens at the source size, since the browser's capturer never sees our oracle: a smaller capture
|
|
852
|
+
size saves encoder and network load, not capture load.
|
|
853
|
+
- `AnimatedContentSampler` finds animation from damage rectangles, which a page cannot see. Frames arriving at most
|
|
854
|
+
200 ms apart (the oracle's own minimum of 5 fps) count as animating here, and a refresh frame does not. A page that
|
|
855
|
+
keeps painting waits the 30 s proving period before each step up; a static one does not.
|
|
856
|
+
- The feedback is applied to the frame whose chunk produced it, not to the next buffer released (one frame later in
|
|
857
|
+
Chrome).
|
|
858
|
+
- Switching the mirrored tab starts a new oracle at the full size, as Chrome's `VideoCaptureClient::SwitchVideoCaptureHost`
|
|
859
|
+
starts a new capture device (with its own oracle) on the new tab.
|
|
860
|
+
- Whether an encoder is hardware for `CalculateEncoderUtilization` is what the session host chose
|
|
861
|
+
(`useHardwareEncoder`, from the WebCodecs hardware query), not what the encoder reports, since WebCodecs does not say
|
|
862
|
+
which implementation it picked under `prefer-hardware`.
|
|
863
|
+
- The estimator runs on the agent's main thread, not on a thread-pool task.
|
|
864
|
+
- `SmoothEventSampler` is ported as the agent's frame-rate limit (above); `AnimatedContentSampler` is not, and
|
|
865
|
+
neither is the max frame rate and max pixels feedback, which `VideoSender` never sends.
|
|
866
|
+
|
|
867
|
+
### Local audio while mirroring
|
|
868
|
+
|
|
869
|
+
Chrome decides whether the sender's own speakers stay on, and we match it (`CastMirroringServiceHost`,
|
|
870
|
+
`chrome/browser/media/cast_mirroring_service_host.cc`):
|
|
871
|
+
|
|
872
|
+
- **Desktop**: `GetDesktopAudioLoopbackDeviceId` returns `kLoopbackInputDeviceId` on Windows, so local playback keeps
|
|
873
|
+
going, when `kCastDesktopMirroringKeepLocalAudio` is enabled (on by default there, `media_router_feature.cc`;
|
|
874
|
+
muting the endpoint silences the loopback on some drivers). Every other platform gets `kLoopbackWithMuteDeviceId`,
|
|
875
|
+
which mutes local playback while mirroring. Here: Windows captures with `getUserMedia` and `chromeMediaSource:
|
|
876
|
+
'desktop'` (loopback, no mute); other platforms take the audio from `getDisplayMedia` on the capture window's private
|
|
877
|
+
session, whose `setDisplayMediaRequestHandler` answers with the app's source id and `audio: 'loopbackWithMute'` (the
|
|
878
|
+
video still comes from `getUserMedia`, see "Letterboxing"). The id goes through as the app gave it,
|
|
879
|
+
as `CastMirroringServiceHost` parses the media id rather than listing the sources again. A machine with no audio
|
|
880
|
+
output device has no loopback to open; the capture fails and the session ends with `AUDIO_CAPTURE_ERROR`, as in
|
|
881
|
+
Chrome (`OpenscreenSessionHost::ReportAndLogError` stops the session). The choice is Chrome's, and like
|
|
882
|
+
`kCastDesktopMirroringKeepLocalAudio` it is an internal flag, not an app setting. The mute path was exercised on Windows (valid Opus reached the fake receiver) but not on
|
|
883
|
+
macOS or Linux, and whether the speakers really went quiet was not listened for.
|
|
884
|
+
- **Tab**: `CreateAudioStream` binds a Muter on the tab's audio group when the first loopback stream is requested, so
|
|
885
|
+
the tab is silent locally for the whole session and restored when the host is destroyed (crbug.com/40708932). Here
|
|
886
|
+
`webContents.setAudioMuted(true)` on the captured page, undone at teardown only if we were the one to mute it. Measured
|
|
887
|
+
in Electron 45: a tab muted this way still delivers its audio to `getUserMedia` tab capture at full level (peak 1.0
|
|
888
|
+
with and without the mute), so the receiver keeps hearing it. An app that wants local audio from the mirrored tab during a session can call
|
|
889
|
+
`setAudioMuted(false)` on its own `webContents`; the library only restores the state it changed.
|
|
890
|
+
|
|
891
|
+
### Switching the source tab, and freezing
|
|
892
|
+
|
|
893
|
+
**Switching** (`CastMirroringServiceHost::SwitchMirroringSourceTab`, `MirroringService::SwitchMirroringSourceTab`,
|
|
894
|
+
`OpenscreenSessionHost::SwitchSourceTab`, `MirroringActivity::DidGetTabSourceId`, `CastActivityManager::OnSourceChanged`).
|
|
895
|
+
The session is **not renegotiated**: the OFFER, the senders, the encoders, the target bitrate, frame ids and RTP timelines
|
|
896
|
+
are untouched, and the receiver sees one uninterrupted stream. What changes, in Chrome's order:
|
|
897
|
+
|
|
898
|
+
1. The host starts observing the new page, drops its video capture host (`video_capture_host_ = nullptr`) and its
|
|
899
|
+
`web_contents_audio_muter_` (so the old tab is audible locally again), and calls the service. Here:
|
|
900
|
+
`host.ts` `switchMirroringSourceTab` unmutes the old page if the library muted it, mutes the new one the same way
|
|
901
|
+
(never touching a page someone else muted), and sends the new page's capture id to the engine.
|
|
902
|
+
2. `SwitchSourceTab` gives the `VideoCaptureClient` a new `VideoCaptureHost` (`SwitchVideoCaptureHost`): the client
|
|
903
|
+
stops the old device and restarts with the same parameters and frame callback, with `accumulated_time_ =
|
|
904
|
+
last_timestamp_ + 1 ms` so the timeline continues. It also does `audio_input_device_->Stop(); Start()`, which asks the
|
|
905
|
+
host for a new audio stream for the new tab (and binds the new tab's Muter). Here: `session-host.ts` `switchSourceTab`
|
|
906
|
+
calls `backend.switchVideoCaptureHost()` and `restartAudioCapture()`; the capture agent opens the new page's
|
|
907
|
+
`getUserMedia` stream, stops the old tracks, starts new pumps, rebases its RTP clock to last RTP + 90 ticks (1 ms), and
|
|
908
|
+
keeps the video and audio encoders. A new capture is not frozen (below). The audio encoder keeps its timeline; the gap
|
|
909
|
+
in capture is resolved by the existing underrun rule.
|
|
910
|
+
3. `DidGetTabSourceId` updates the activity's `frame_tree_node_id_` and `routes_by_frame_`, terminates any other route of
|
|
911
|
+
the new tab, and sets the play state to PLAYING. Here: `MirroringActivity.webContentsId`, the manager's one-route-per-tab
|
|
912
|
+
rule, and `freezeInfo.isFrozen` back to false. **The route's id and `media_source` do not change in Chrome and do not
|
|
913
|
+
here**; the page it is bound to is `route.webContentsId` (and `members`).
|
|
914
|
+
|
|
915
|
+
Public entry point: Chrome has none in the Media Router; the "Share this tab instead" control of the tab-sharing UI
|
|
916
|
+
(`TabSharingUI`, its `SourceCallback`) calls the host. `CastManager.switchMirroringSourceTab(routeId, webContentsId)` takes
|
|
917
|
+
that place, named after the host method. Deviations: a route that is still launching refuses (Chrome has no host yet); a
|
|
918
|
+
page that is already the source is a no-op (Chrome restarts capture and then ignores the unchanged id).
|
|
919
|
+
|
|
920
|
+
Only **tab** routes switch. Chrome's host `CHECK`s that the new source is a web contents, `ShowTabSharingUI` is for tab
|
|
921
|
+
capture only, and the control is behind `AccessCodeCastTabSwitchingUi` (an internal UI flag, not mirrored here). A desktop
|
|
922
|
+
route refuses with `unable_to_cast`; Chrome has no desktop-source switch to port.
|
|
923
|
+
|
|
924
|
+
Not ported: the remoting branch of `SwitchSourceTab` (remoting is not offered).
|
|
925
|
+
|
|
926
|
+
**One route per page** (`CastActivityManager::routes_by_frame_`, keyed by `frame_tree_node_id`, for every kind of route).
|
|
927
|
+
`DoLaunchSession` ("If there is a route from this frame already, stop it") terminates the frame's existing route before a
|
|
928
|
+
new one launches, and `OnSourceChanged` does the same for the new tab's frame on a switch. Here the two route kinds live in
|
|
929
|
+
separate layers, so the rule is a pair of narrow hooks: `MirroringManagerOptions.terminateRoutesOfPage` (called when a page
|
|
930
|
+
becomes a mirroring source, by a launch or a switch; `main.ts` ends the Cast SDK / Presentation API sessions that page
|
|
931
|
+
*launched*, `CastSessionService.sessionsLaunchedBy`, through `terminateSession`) and `CastSessionServiceOptions.onSessionLaunched`
|
|
932
|
+
(called when a page launches a session; `main.ts` ends that page's mirroring routes). A session the page only joined is not
|
|
933
|
+
ended, as Chrome's `routes_by_frame_` records launches only. Deviation: Chrome's key is the frame, here a main frame is
|
|
934
|
+
its page (a subframe's session is not matched to a mirroring route, which in Chrome is also a main frame).
|
|
935
|
+
|
|
936
|
+
**The mirrored page being destroyed** (tab routes only). `CastMirroringServiceHost` is a `WebContentsObserver` on the tab
|
|
937
|
+
(`Observe(GetContents(...))` in `Start`, again for the new tab in `SwitchMirroringSourceTab`); `WebContentsDestroyed()`
|
|
938
|
+
calls `StopMirroringSession()`, which resets `mirroring_service_`. The Mirroring Service's disconnect handler
|
|
939
|
+
(`MirroringService::OnDisconnect`) resets its `OpenscreenSessionHost`, whose destructor runs `StopSession()` and calls
|
|
940
|
+
`observer_->DidStop()`; `MirroringActivity::DidStop()` -> `StopMirroring()` runs `on_stop_` ->
|
|
941
|
+
`CastActivityManager::OnActivityStopped` -> `TerminateSession`, which removes the activity as `TERMINATED` with
|
|
942
|
+
`PresentationConnectionCloseReason::CLOSED` (the same path as a user stopping the route). Here `host.ts` listens for
|
|
943
|
+
`destroyed` on the page being mirrored (the new page after a switch; the old one is ignored) and reports `didStop`, which
|
|
944
|
+
ends the route as `terminateRoute` does. A desktop source observes no `WebContents` (the `Observe` calls are in the tab
|
|
945
|
+
branch only), so nothing happens there when a window closes: capture just ends or goes on.
|
|
946
|
+
|
|
947
|
+
**Freezing** (`MediaRouterUI::FreezeRoute` / `UnfreezeRoute` -> `MirroringMediaControllerHostImpl::Freeze` / `Unfreeze` ->
|
|
948
|
+
`MirroringActivity::Pause` / `Play` -> `CastMirroringServiceHost::Pause` / `Resume`). Freezing pauses the *video capture
|
|
949
|
+
host* only (`VideoCaptureHost::Pause`, `SingleClientVideoCaptureHost::Pause` -> `MaybeSuspendDevice`): the mirroring
|
|
950
|
+
service, its client, senders, refresh timer and the **audio stream are not told**, no frames are produced and the receiver
|
|
951
|
+
keeps the last frame it was given. `RequestRefreshFrame` does nothing while the device is suspended
|
|
952
|
+
(`FrameSinkVideoCaptureDevice::RequestRefreshFrame`), so the refresh timer cannot unfreeze it; `Resume` restarts the
|
|
953
|
+
capturer, which delivers a frame at once. Here: `route.freezeInfo = { canFreeze, isFrozen }` (Chrome's
|
|
954
|
+
`UIMediaSink::freeze_info`), `freezeRoute` / `unfreezeRoute` on the manager, `MirroringService.pause` / `resume`, and in
|
|
955
|
+
the agent a `frozen` flag that drops capture frames and refresh requests and, on unfreeze, sends the last frame again
|
|
956
|
+
(stamped with the time that passed) as the restarted capturer would. The flag is separate from the session's own
|
|
957
|
+
`pause`/`resume` (the capture client's pause during encoder reconfiguration), because Chrome's browser-side pause is below
|
|
958
|
+
the client.
|
|
959
|
+
|
|
960
|
+
- `Freeze()` starts a 500 ms one-shot timer (`kPauseDelay`) and ignores requests while it runs; `Unfreeze()` acts at once.
|
|
961
|
+
- `can_play_pause` becomes true at the end of `NegotiateMirroring` (`OnRemotingStateChanged(false)`) and false while
|
|
962
|
+
remoting; here `canFreeze` becomes true when the session reports `didStart` (the ANSWER is in and capture has begun),
|
|
963
|
+
since a pause before that finds no capture host in Chrome and does nothing. When remoting is ported this should follow
|
|
964
|
+
`OnRemotingStateChanged` too. `is_frozen` is `can_freeze && play_state == PAUSED`, set when the pause request has been
|
|
965
|
+
made (the callback of `CastMirroringServiceHost::Pause` runs after posting to the IO thread), not when the device
|
|
966
|
+
confirmed.
|
|
967
|
+
- The pause request goes main -> engine -> agent because the agent's port belongs to the engine (Chrome's host talks to the
|
|
968
|
+
video capture host directly).
|
|
969
|
+
- The receiver's behaviour while frozen (how long it holds the last frame, whether it shows a spinner) is the receiver's;
|
|
970
|
+
that needs a real device.
|
|
971
|
+
|
|
972
|
+
### Codecs
|
|
973
|
+
|
|
974
|
+
Opus (48 kHz stereo, 10 ms frames, 128 kbps; `audio_encoder.cc` `OpusImpl`) is always offered. Video follows
|
|
975
|
+
`NegotiateMirroring` and `encoding_support.cc`:
|
|
976
|
+
|
|
977
|
+
- **Hardware first.** A codec is offered in hardware when the encoder exists, its feature or switch allows it
|
|
978
|
+
(`IsHardwareEnabled`: H.264, VP8 and VP9 by default; HEVC and AV1 only with
|
|
979
|
+
`--cast-streaming-force-enable-hardware-hevc` / `-av1`; `--cast-streaming-force-disable-hardware-<codec>` wins) and
|
|
980
|
+
it is not on the hardware deny list. Software codecs (VP8 and VP9, `IsSoftwareEnabled`; AV1 only with
|
|
981
|
+
`--enable-features=CastStreamingAv1`) are offered only when no hardware codec was (`kCastStreamingOfferHardwareFirst`, on by default), or in the one fallback
|
|
982
|
+
offer after the receiver selected no stream (`OnError`, `offering_fallback_codecs_`). The order is
|
|
983
|
+
`kSupportedVideoCodecs` (HEVC, AV1, VP9, H.264, VP8). Chrome has no software H.264 encoder in the list, and no
|
|
984
|
+
model-based codec deny list turned up in `openscreen_session_host.cc`, `mirroring_activity.cc` or openscreen's
|
|
985
|
+
`sender_session.cc`: the one receiver-model rule there is `ShouldForceLetterboxing` (below).
|
|
986
|
+
- **How "hardware" is established.** Chrome asks the GPU process for the `VideoEncodeAccelerator` profiles. Here the
|
|
987
|
+
capture page asks WebCodecs: `VideoEncoder.isConfigSupported` with `hardwareAcceleration: "prefer-hardware"`, at the
|
|
988
|
+
session's maximum resolution (1920x1080, 30 fps) and the codec string Chrome would offer (`GetCodecParameterString`).
|
|
989
|
+
In Chromium's blink `video_encoder.cc` `prefer-hardware` makes `GetRequiredEncoderType` return `kHardware`, and
|
|
990
|
+
`CreateMediaVideoEncoder` returns the accelerated encoder's status without the software fallback that
|
|
991
|
+
`no-preference` and `prefer-software` get (it also excludes the OS software encoders, such as Media Foundation's
|
|
992
|
+
software H.264). So a supported answer means a hardware encoder takes that configuration, and the same setting at
|
|
993
|
+
`configure` time makes the encoder refuse to run in software. A hardware offer is encoded with
|
|
994
|
+
`prefer-hardware`, a software offer with `prefer-software`; H.264 is configured as Annex B (`avc: { format: "annexb" }`),
|
|
995
|
+
which is what Cast Streaming carries, with the parameter sets in the key frames.
|
|
996
|
+
- **Profiles.** Chrome's `GetHardwareCodecParameters` accepts any profile in a codec's range; WebCodecs is asked about
|
|
997
|
+
the one profile that is offered (H.264 Main level 4.0, `avc1.4d0028`; Baseline, `avc1.420028`, on macOS as
|
|
998
|
+
`ToProfile` does with `kCastMacForceBaselineProfile`). An encoder that only does another profile is not found.
|
|
999
|
+
- **Failure.** A hardware encoder that reports an error (`codec_runtime_error`, `codec_init_failed`,
|
|
1000
|
+
`unsupported_codec`) is not a session error. As in `OnVideoEncoderStatus`, the frame rate is lowered to 30 in place if
|
|
1001
|
+
it was higher (`MaybeFallbackHardwareFrameRate`; capture is limited to 30 fps here, so this is never taken), else the
|
|
1002
|
+
codec goes on the hardware deny list and the session streams down and negotiates again
|
|
1003
|
+
(`MaybeDenylistHardwareCodecAndRenegotiate`): the next OFFER holds the other hardware codecs or, if none, the
|
|
1004
|
+
software ones. A deny-listed codec is listed once. A software encoder that fails is an `ENCODING_ERROR` and stops the
|
|
1005
|
+
session. Chrome's list is process-wide (`GetHardwareCodecDenyList()` is a static): the main process holds it for as
|
|
1006
|
+
long as the mirroring factory lives and gives it to each engine, which reports additions back. A status from an
|
|
1007
|
+
encoder that has been replaced is ignored, as a destroyed `VideoEncoder` reports nothing.
|
|
1008
|
+
|
|
1009
|
+
HEVC and AV1 are off by default in Chrome and so here. No encoder is bundled.
|
|
1010
|
+
|
|
1011
|
+
### Letterboxing
|
|
1012
|
+
|
|
1013
|
+
`MirrorSettings::GetVideoCaptureParams` gives the capture a `resolution_change_policy`: `fixed_aspect_ratio` when
|
|
1014
|
+
sender-side letterboxing is on (a receiver whose ANSWER does not say `scaling: "receiver"`, or any `Nest Hub` model
|
|
1015
|
+
unless `--disable-cast-letterboxing`: `ShouldForceLetterboxing`), `any_within_limit` otherwise, `fixed_resolution` at the
|
|
1016
|
+
minimum size. Chrome gives those to the capture device, which turns them into `SetResolutionConstraints(min, max,
|
|
1017
|
+
fixed_aspect_ratio)` (`VideoCaptureParams::SuggestConstraints`: the minimum is the maximum for `fixed_resolution`, 180
|
|
1018
|
+
lines of the same aspect ratio for `fixed_aspect_ratio`, 2x2 for `any_within_limit`) and the capture then keeps the
|
|
1019
|
+
aspect ratio of the maximum, 16:9, scaling and padding the source into it. Here the agent reaches the same capture
|
|
1020
|
+
device through `getUserMedia`, whose legacy constraints Blink turns back into a policy
|
|
1021
|
+
(`SelectResolutionPolicyFromCandidates`), so the agent sends the sizes `SuggestConstraints` would give and a unit test
|
|
1022
|
+
runs Blink's rule over them. Before this the agent sent only a maximum, so Blink's default applied (`fixed_resolution` for
|
|
1023
|
+
a tab, which made every tab 1920x1080 whatever its size, as measured, and `any_within_limit` for the desktop). The smoke test checks that a 4:3 page and the screen come out 16:9 (a 640x480 page: 1706x960).
|
|
1024
|
+
|
|
1025
|
+
`getDisplayMedia`, used for desktop audio off Windows, refuses minimum sizes (a TypeError, "min constraints are not
|
|
1026
|
+
supported"), so it cannot carry a policy: without a minimum Blink falls back to `any_within_limit` for a screen. The
|
|
1027
|
+
agent therefore takes only the audio track from it (asked with the maximums), stops its video track, and captures the
|
|
1028
|
+
video with the same `getUserMedia` request as on Windows. `fixed_resolution` is only chosen when the receiver recommends
|
|
1029
|
+
the minimum size.
|
|
1030
|
+
|
|
1031
|
+
On macOS the screen is captured by ScreenCaptureKit, which letterboxes into the frame
|
|
1032
|
+
(`IOSurfaceCaptureDeviceBase::ComputeFrameSizeAndDestRect`) but reports the content rect as the frame's visible rect
|
|
1033
|
+
(`content/browser/media/capture/screen_capture_kit_device_mac.mm`, `OnStreamSample`). Chrome's encoder encodes the
|
|
1034
|
+
visible rect (`MediaVideoEncoderWrapper`, `visible_rect().size()`), and so does WebCodecs here, so a desktop mirrored
|
|
1035
|
+
from a Mac keeps the screen's own shape (a 4:3 screen gives 1024x768 frames, seen with Electron 40 on a macOS runner).
|
|
1036
|
+
|
|
1037
|
+
### Media remoting: capabilities only, the renderer side is not reachable
|
|
1038
|
+
|
|
1039
|
+
Chrome's remoting is started by the renderer, not by the Mirroring Service. In a mirrored tab, `media::remoting::RendererController`
|
|
1040
|
+
(created in `content/renderer/media/media_factory.cc`, `MediaFactory::CreateRendererFactorySelector`, under
|
|
1041
|
+
`BUILDFLAG(ENABLE_MEDIA_REMOTING)`) calls `GetRemoterFactory()->Create(RemotingSource, Remoter)`, a request on the
|
|
1042
|
+
frame's browser interface broker. The embedder answers it through
|
|
1043
|
+
`ContentBrowserClient::CreateMediaRemoter(RenderFrameHost*, PendingRemote<RemotingSource>, PendingReceiver<Remoter>)`
|
|
1044
|
+
(`content/public/browser/content_browser_client.h`); Chrome implements it in
|
|
1045
|
+
`ChromeContentBrowserClient::CreateMediaRemoter` (`chrome/browser/chrome_content_browser_client.cc`), which hands the
|
|
1046
|
+
pipes to `CastRemotingConnector::Get(web_contents)` (`chrome/browser/media/cast_remoting_connector.cc`) through
|
|
1047
|
+
`RemotingBridge`. The connector reaches the Mirroring Service's `MediaRemoter`, which uses `OpenscreenSessionHost`
|
|
1048
|
+
(`StartRemoting`, `NegotiateRemoting`, `CreateRemotingDataStreamSender`, `StopRemoting`).
|
|
1049
|
+
|
|
1050
|
+
Status in Electron (checked 2026-11-25 against `electron/electron@main`):
|
|
1051
|
+
|
|
1052
|
+
- The renderer half is built in: `enable_media_remoting = !is_cast_media_device && !is_ios` in `media/media_options.gni`,
|
|
1053
|
+
and Electron's `build/args/*.gn` do not turn it off. So an Electron renderer does create a `RendererController` and
|
|
1054
|
+
asks for a `RemoterFactory`.
|
|
1055
|
+
- The browser half is missing. `ElectronBrowserClient` (`shell/browser/electron_browser_client.{h,cc}`) does not
|
|
1056
|
+
override `CreateMediaRemoter`; the content default is an empty function, so the request is dropped and the
|
|
1057
|
+
`RendererController` never sees `OnSinkAvailable`. Electron's only `CastRemotingConnector` reference is in the
|
|
1058
|
+
exclusive-access patch (`patches/chromium/fix_adapt_exclusive_access_for_electron_needs.patch`), which turns the `DidAcquireFullscreen` calls into `#if 0`.
|
|
1059
|
+
- There is no JavaScript API for any of it: `RemoterFactory`, `Remoter`, `RemotingSource` and
|
|
1060
|
+
`RemotingDataStreamSender` (`media/mojo/mojom/remoting.mojom`) are Mojo interfaces bound inside the browser process,
|
|
1061
|
+
and the data path is a Mojo data pipe carrying demuxed `DecoderBuffer`s. The sender runs in a utility process here
|
|
1062
|
+
and nothing exposes these to Node.
|
|
1063
|
+
|
|
1064
|
+
So remoting cannot be built in this library without a change in Electron, and it is not faked. What is ported is
|
|
1065
|
+
the part that does not need the renderer: after the first negotiated OFFER the host sends `GET_CAPABILITIES` once
|
|
1066
|
+
(`OpenscreenSessionHost::OnNegotiated`, "We should only request capabilities once"), parses the
|
|
1067
|
+
`CAPABILITIES_RESPONSE`, rejects a receiver whose `remoting` version is above 2 (`kSupportedRemotingVersion`; absent
|
|
1068
|
+
means 1), maps the media capabilities as `ToCapabilities` does (`audio` is `baseline`, `video` is ignored) and keeps
|
|
1069
|
+
the result in `OpenscreenSessionHost.receiverCapabilities`. A missing, errored or too-new response is logged ("Remoting
|
|
1070
|
+
is disabled for this session") and the session continues, as in `OnError` for `kRemotingNotSupported`. In Chrome the
|
|
1071
|
+
result feeds `ToRemotingSinkMetadata` and then the `MediaRemoter`; here nothing reads it yet. (Earlier text said Chrome
|
|
1072
|
+
sends `GET_CAPABILITIES` only for remoting; it sends it for every non-Remote-Playback mirroring session, so a real
|
|
1073
|
+
receiver now gets one extra request.)
|
|
1074
|
+
|
|
1075
|
+
What Electron would need, for the remoting RFC:
|
|
1076
|
+
|
|
1077
|
+
1. An embedder hook that forwards `ContentBrowserClient::CreateMediaRemoter` (render frame host, `RemotingSource`
|
|
1078
|
+
remote, `Remoter` receiver) to the application, per frame, honouring the `IsActive()` and fenced-frame checks of
|
|
1079
|
+
Chrome's implementation, and a way to tie it to an existing cast route for that `WebContents`.
|
|
1080
|
+
2. A JS-visible binding of the four interfaces, or a narrower message API: `RemotingSource.OnSinkAvailable(metadata)`
|
|
1081
|
+
/ `OnSinkGone`, `OnStarted` / `OnStartFailed(reason)` / `OnStopped(reason)`, `OnMessageFromSink(bytes)`;
|
|
1082
|
+
`Remoter.Start`, `Stop(reason)`, `SendMessageToSink(bytes)`, `StartDataStreams(audio_pipe, video_pipe, ...)`; and
|
|
1083
|
+
`RemotingDataStreamSender.SendFrame(DecoderBuffer)` / `CancelInFlightData`. The serialized RPC messages are the
|
|
1084
|
+
protobufs in `media/remoting/proto`, and the pipes carry encoded frames, so a binding must expose the data pipe
|
|
1085
|
+
consumer (for example as a `ReadableStream`) to the utility process that owns the RTP senders.
|
|
1086
|
+
3. Once those exist, the library side is: a remoting OFFER (`castMode: "remoting"`, `CreateRemotingOffer`), the RPC
|
|
1087
|
+
dispatcher on `urn:x-cast:com.google.cast.remoting` (`messenger.ts` already routes that namespace and
|
|
1088
|
+
`SenderSessionMessenger.sendRpcMessage` exists), a `RemotingSender` that pumps pipe data into the frame senders,
|
|
1089
|
+
and the return to mirroring (`StopRemoting`, `StopRemotingAndMaybeResumeMirroring`).
|
|
1090
|
+
|
|
1091
|
+
### Mirroring statistics (`src/mirroring/stats/`)
|
|
1092
|
+
|
|
1093
|
+
Chrome measures a mirroring session for debugging, not for pages: `MirroringActivity::OnSessionSet` asks the
|
|
1094
|
+
`MediaRouterDebugger` (`ShouldFetchMirroringStats`) and, when it is on, starts the session with
|
|
1095
|
+
`enable_rtcp_reporting`; `DidStart` then calls `CastMirroringServiceHost::GetMirroringStats` every
|
|
1096
|
+
`kRtcpReportInterval` (500 ms) and hands the dictionary to the debugger (`OnMirroringStats`), where
|
|
1097
|
+
`chrome://media-router-internals` shows it and `MirroringStatsObserver`s get it. It is off by default and read at the
|
|
1098
|
+
start of a session. Rules, all from openscreen revision `aec59dd1baf42bc7e23963ccbe7b72bbaf28dfe6` (the one Chromium
|
|
1099
|
+
pins; the files are identical on main) unless noted:
|
|
1100
|
+
|
|
1101
|
+
- **Collection** (`statistics_collector.cc`, `statistics_dispatcher.cc`). While a stats client is set on the session
|
|
1102
|
+
(`SenderSession::SetStatsClient`), `Environment::SendPacket` reports every packet to the collector, which parses the
|
|
1103
|
+
wire bytes (RTP timestamp at 4, packet id and max packet id at 14 and 16, size = the packet) and tags it
|
|
1104
|
+
`kPacketRetransmitted` or `kPacketSentToNetwork`. `SenderImpl` dispatches capture begin, capture end and encoded
|
|
1105
|
+
(size, key frame) at the end of `EnqueueFrame`, frame ack received from the receiver's checkpoint and ack vector for
|
|
1106
|
+
slots still in flight, and frame dropped by encoder from `ReportFrameDropEvent`. The receiver's RTCP event log
|
|
1107
|
+
(`receiverRtcpEventLog` is already in the OFFER) is parsed by `CompoundRtcpParser::ParseFrameLogMessages` and
|
|
1108
|
+
dispatched between the receiver report and the checkpoint: packet received, ack sent, decoded and played out (with
|
|
1109
|
+
its signed delay). Event times in the log are `RtcpSession::start_time` (the sender's clock when the `Sender` was
|
|
1110
|
+
made) plus the 24-bit base plus a 12-bit delta; the receiver's own origin is whatever it chose, which the clock
|
|
1111
|
+
offset estimate absorbs.
|
|
1112
|
+
- **Clock offset** (`clock_offset_estimator_impl.cc`). Two Kalman-filtered bounds (process noise 5 ms, measurement
|
|
1113
|
+
noise 30 ms): packet sent against packet received, and ack sent against ack received, each matched by RTP
|
|
1114
|
+
timestamp, packet id and media type in a map capped at 500 entries. Offset is half the sum of the bounds, latency
|
|
1115
|
+
half the difference, and neither exists until both bounds have a measurement.
|
|
1116
|
+
- **Analysis** (`statistics_analyzer.cc`). Every 500 ms the analyzer takes the collected frame events, then packet
|
|
1117
|
+
events, updates its aggregates and latency pairs (the 200 most recent frames and 1000 most recent packets are kept to
|
|
1118
|
+
join events), and gives `SenderStats` to the client. Counts, bitrates and rates cover the whole session since the
|
|
1119
|
+
analyzer was made, not a sliding window; latencies are means over every data point so far; durations are truncated
|
|
1120
|
+
to whole milliseconds as `to_milliseconds` does, so a session shorter than 1 ms yields an infinite rate (shown as
|
|
1121
|
+
the string "null", as Chrome's dictionary does). Histograms are 0 to 800 ms in 20 ms buckets, for capture, encode,
|
|
1122
|
+
queueing, network, packet and end-to-end latency, and lateness.
|
|
1123
|
+
- **Exposure** (`openscreen_stats_client.cc`, `openscreen_session_host.cc` `GetMirroringStats`,
|
|
1124
|
+
`stats_event_subscriber.cc` `CastStatToString`). `{ audio, video }`, each holding every statistic under Chrome's name
|
|
1125
|
+
(`ENQUEUE_FPS`, `AVG_CAPTURE_LATENCY_MS`, ..., `LAST_EVENT_TIME_MS`) and the histograms as lists of single-key
|
|
1126
|
+
objects (`"<0"`, `"20-39"`, `">=800"`; empty buckets are left out). The session host merges its own counters:
|
|
1127
|
+
`TARGET_BITRATE` (kbps), `ENCODER_UTILIZATION` and `LOSSINESS` (percent, -100 when nothing reported yet),
|
|
1128
|
+
`FRAMES_INSERTED`, and `FRAMES_DROPPED` (video: dropped before plus after encoding). The `MediaRouterDebugger` surface
|
|
1129
|
+
is mirrored by `getMirroringStats(routeId)`, `setMirroringStatsEnabled`, `isMirroringStatsEnabled` and
|
|
1130
|
+
`registerMirroringStatsObserver`; like Chrome they are a debugging aid, off by default and applied to sessions that
|
|
1131
|
+
start afterwards, and there is no web API for them.
|
|
1132
|
+
- **Quirks copied on purpose.** The collector reads RTCP sender reports as if they were RTP packets (every packet
|
|
1133
|
+
goes through `Environment::SendPacket`), so they add to `NUM_PACKETS_SENT` and `TRANSMISSION_KBPS` with a garbage
|
|
1134
|
+
packet id. `kNumPacketsRetransmitted` has no case in Chromium's `StatisticTypeToCastStat`, so it is reported under
|
|
1135
|
+
`UNKNOWN_OPEN_SCREEN_STAT`. Receiver events that arrive before the clock offset is known are left out of the frame
|
|
1136
|
+
and end-to-end latencies, the late-frame count and the first and last event times.
|
|
1137
|
+
- **Deviations.** (1) Chrome's debugger is a single global one holding the most recent push of any session (its own
|
|
1138
|
+
TODO says multiple sessions are not handled); `getMirroringStats` takes the route id and each route keeps its own. What Chrome's copy does is kept per route:
|
|
1139
|
+
`MediaRouterDebuggerImpl::GetMirroringStats` returns an empty dictionary while `ShouldFetchMirroringStats` is false
|
|
1140
|
+
and otherwise `most_recent_mirroring_stats_`, which nothing clears when a session ends and which the next push of any
|
|
1141
|
+
session replaces (`NotifyGetMirroringStats`, which also drops pushes while statistics are off). So `getMirroringStats`
|
|
1142
|
+
never throws, returns `{}` while off and for an unknown route, and gives an ended route its last statistics until
|
|
1143
|
+
another route pushes.
|
|
1144
|
+
(2) A video frame's capture begin is its capture time from the frame metadata (or the agent's estimate, see
|
|
1145
|
+
"Process split") and its capture end is when the agent read it from the track; Chrome has `capture_begin_time`
|
|
1146
|
+
and `capture_end_time` from the capturer, so the capture latency here also counts the delivery to the agent. Audio is the same as in Chrome (one time for both). (3) The stats
|
|
1147
|
+
are fetched from the utility process over its message port (`get-stats`/`stats`), where Chrome calls the Mirroring
|
|
1148
|
+
Service over mojo. (4) Not ported: UMA (`RecordCastStreamingSenderUma` and the other histograms Chrome uploads): they
|
|
1149
|
+
need Chrome's metrics pipeline and send usage data to Google, and this library has no backend or consent to
|
|
1150
|
+
report to.
|
|
1151
|
+
|
|
1152
|
+
### Not checked, or different from Chromium
|
|
1153
|
+
|
|
1154
|
+
- The fake receiver in `test/mirroring/` is ours: it implements what openscreen's receiver does for the parts we send
|
|
1155
|
+
to (ANSWER, RTCP reports, ACKs, NACKs), not Chrome's receiver app. On a real device (Windows to a Chromecast Ultra,
|
|
1156
|
+
with the live harness in `examples/live-mirroring/`) tab mirroring ran at 1080p30 with Opus and VP8 in software, the
|
|
1157
|
+
picture smooth and the audio in sync and only on the TV; desktop mirroring sent picture and system audio, with local
|
|
1158
|
+
audio kept on Windows as Chrome keeps it there. Linux and macOS have not been tried.
|
|
1159
|
+
- Not ported: Remoting (RPC playback; see "Media remoting" below), UMA (see Mirroring statistics; each frame's lossiness and utilization are computed, the averages Chrome records are not).
|
|
1160
|
+
- Hardware encoding differs from Chrome in how it is found out and run: the GPU factories (`MirroringGpuFactoriesFactory`,
|
|
1161
|
+
`OnGpuFactoryContextLost`) have no counterpart because the encoder is WebCodecs in the capture page; a lost GPU
|
|
1162
|
+
surfaces as an encoder error, which takes the same deny-list path. Which profile a hardware encoder supports is a
|
|
1163
|
+
yes or no for the offered profile, not Chrome's range check. The `VideoEncodeAccelerator` frame rate is not
|
|
1164
|
+
consulted (Chrome stopped doing that too: crbug.com/586527429).
|
|
1165
|
+
- A receiver that answers a hardware-first offer with audio only (it took no video codec) gets no fallback offer: the
|
|
1166
|
+
fallback is sent on `NoStreamSelected`, which needs the ANSWER to select nothing at all. This is Chrome's behaviour.
|
|
1167
|
+
- Chrome sends the fallback offer after any `NoStreamSelected`, with or without a hardware codec in the first offer.
|
|
1168
|
+
- `kCastStreamingForceEnableHardware*`, `kCastStreamingForceDisableHardware*`, `--disable-cast-letterboxing` and the
|
|
1169
|
+
`CastStreaming*` features (`--enable-features` / `--disable-features`: Vp8, Vp9, Av1, HardwareHevc, Win/MacHardwareH264)
|
|
1170
|
+
are read from Electron's `app.commandLine` (`hasSwitch`, `getSwitchValue`), as Chrome reads `base::CommandLine`, so
|
|
1171
|
+
switches the app appended with `app.commandLine.appendSwitch` count too. The app's `electron` object carries `app`
|
|
1172
|
+
already; there is no option for it. Only these features are read, not the whole `base::FeatureList` (field trials,
|
|
1173
|
+
`::` params); a feature named in both lists is disabled, as there.
|
|
1174
|
+
- `PortBackend` restarts nothing when the 30 fps fallback asks for a capture restart (`RestartWithParams`); it is
|
|
1175
|
+
never asked to, as above.
|
|
1176
|
+
- Chrome's `OnAppMessage` compares a message's `source_id` with the sender's id and its `destination_id` with the
|
|
1177
|
+
session's, which reads as swapped for a message from the receiver; `MirroringActivity` here takes the transport as
|
|
1178
|
+
the source and the sender's id (or `*`) as the destination.
|
|
1179
|
+
- Frame rate: capture is rate-limited to the requested rate, never raised to it, and a hidden page can render slower
|
|
1180
|
+
than 30 fps. In the smoke test a 60 Hz test page mirrors at about 22 fps on the development machine.
|
|
1181
|
+
- `startCasting` is one method for Chrome's three cast modes, as `MediaRouterUI::StartCasting` takes the mode:
|
|
1182
|
+
`presentation` (the default) casts the window's default request, `tab_mirror` and `desktop_mirror` start a
|
|
1183
|
+
mirroring route. Each mode keeps its own argument checks; a mode that is none of the three is a `RangeError`, and a
|
|
1184
|
+
mirroring mode without the `mirroring` option is `unable_to_cast`.
|
|
1185
|
+
- The mirroring session runs on the device's one kept-open channel, as Chrome's `MirroringActivity` sends through
|
|
1186
|
+
`CastMessageHandler` on the sink's one `CastSocket`; the activity's view of the channel only detaches when the route
|
|
1187
|
+
ends and never closes it. Its session on the device is a local route: the session tracker does not report it as a
|
|
1188
|
+
non-local route (`CastActivityManager` adds a non-local activity only for a session no local activity holds), nor
|
|
1189
|
+
while it is being launched.
|