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/API.md
ADDED
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
This reference reflects **v0.4.0**.
|
|
4
|
+
|
|
5
|
+
electron-cast ships an ES module build and a CommonJS build (`dist/cjs`, no extra dependencies). Every entry point has an
|
|
6
|
+
`import` and a `require` condition in `exports`, so `import` and `require("electron-cast/preload")` both work, and a
|
|
7
|
+
non-sandboxed CommonJS preload or main process can load the package without a bundler. Electron is an optional peer
|
|
8
|
+
dependency (`electron >=35`): the library never imports it (Electron objects are passed in), and the version matters
|
|
9
|
+
only because the preload needs `contextBridge.executeInMainWorld`, added in Electron 35. Node 20 or later.
|
|
10
|
+
|
|
11
|
+
There are four entry points:
|
|
12
|
+
|
|
13
|
+
| Entry point | Import it from | Contains |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `electron-cast/main` | the Electron main process | [`createCastManager`](#createcastmanageroptions) and its types |
|
|
16
|
+
| `electron-cast/preload` | a preload script | [`installCastBridge`](#installcastbridgeoptions) and its types |
|
|
17
|
+
| `electron-cast/polyfill` | code that runs in a page | [`installChromeCast`](#installchromecastbridgekey) and the bridge types |
|
|
18
|
+
| `electron-cast` | plain Node code, or anywhere you want every layer | everything above, plus the session service, `CastClient`, discovery and the protocol layer |
|
|
19
|
+
|
|
20
|
+
Do not import the root from a preload script: it also pulls in Node's `tls` and `dgram`, which a sandboxed preload
|
|
21
|
+
cannot load. Use `electron-cast/preload`. A sandboxed preload can load no packages at all, so bundle it; see
|
|
22
|
+
[examples/electron-app](../examples/electron-app).
|
|
23
|
+
|
|
24
|
+
Electron objects (`ipcMain`, `contextBridge`, `ipcRenderer`) are passed in, never imported by the library. The
|
|
25
|
+
`...Like` interfaces below describe the part of each object the library uses.
|
|
26
|
+
|
|
27
|
+
How the library behaves: on the default Presentation API path it does what Chrome does, and the code cites
|
|
28
|
+
the Chromium source for each rule it copies. `mode: "chromecast"` (electron-cast's own `chrome.cast`) is a frozen
|
|
29
|
+
fallback that gets no new features, and nothing in the library is specific to one app.
|
|
30
|
+
|
|
31
|
+
Contents: [`electron-cast/main`](#electron-castmain) · [`electron-cast/preload`](#electron-castpreload) ·
|
|
32
|
+
[`electron-cast/polyfill`](#electron-castpolyfill) · [`electron-cast` (root)](#electron-cast-root):
|
|
33
|
+
[session service](#session-service), [`CastClient`](#castclient), [discovery](#discovery), [protocol](#protocol)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## `electron-cast/main`
|
|
38
|
+
|
|
39
|
+
### `createCastManager(options)`
|
|
40
|
+
|
|
41
|
+
<!-- no-check -->
|
|
42
|
+
```ts
|
|
43
|
+
function createCastManager(options: CastManagerOptions): CastManager
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Registers the IPC handlers, creates the session service and discovery, and returns a manager. Nothing touches the
|
|
47
|
+
network until `start()`. Throws `TypeError` if `presentation` is not `false` and `ipcMain` has no `on` or
|
|
48
|
+
`removeListener`.
|
|
49
|
+
|
|
50
|
+
It registers `ipcMain.handle` on `<channel>:call` and `<channel>:presentation`, and `ipcMain.on` on
|
|
51
|
+
`<channel>:presentation:send`. It sends `<channel>:event` and `<channel>:presentation:event` to the one frame that
|
|
52
|
+
owns the sender. A frame is tracked from its first call. When its webContents is destroyed, or the page navigates,
|
|
53
|
+
its connections end; a navigation keeps its sessions open on the device so the next page can rejoin them.
|
|
54
|
+
|
|
55
|
+
**Frames and iframes.** In presentation mode every frame is its own sender: its availability watches, connections and
|
|
56
|
+
sessions belong to it, its events go only to it, and the `origin` checked by `allowOrigin` and shown to
|
|
57
|
+
`selectDevice` is that frame's own. The preload only runs in iframes when the window sets
|
|
58
|
+
`nodeIntegrationInSubFrames: true` in its `webPreferences`; without it nothing changes and an iframe has no cast. An
|
|
59
|
+
iframe that navigates parks its sessions as a reloading page does; a removed iframe (found by a 5 s sweep of the
|
|
60
|
+
frame tree, since Electron does not announce it) or a navigating page ends them. `mode: "chromecast"` is main-frame
|
|
61
|
+
only: a call from an iframe is refused with `extension_missing`. `CastRequestInfo.senderId` is the webContents id for a
|
|
62
|
+
main frame and a synthetic id (2^30 and up) for an iframe.
|
|
63
|
+
|
|
64
|
+
#### `CastManagerOptions`
|
|
65
|
+
|
|
66
|
+
| Option | Type | Default | Description |
|
|
67
|
+
|---|---|---|---|
|
|
68
|
+
| `ipcMain` | `IpcMainLike` | required | Electron's `ipcMain`. |
|
|
69
|
+
| `selectDevice` | `(devices: CastDevice[], request: CastRequestInfo, picker: DevicePickerContext) => Promise<DeviceChoice \| DisplayChoice>` | required | Called when a page asks to start a session. Show your picker and resolve a device, `null` to cancel, or `"stop"` to stop `request.session`; with `wiredDisplay`, `{ display: id }` picks one of `request.displays`. A rejection fails the request with `session_error`. A function that declares only the first two parameters works. See [`selectDevice`](#selectdevice). |
|
|
70
|
+
| `allowOrigin` | `(origin: string) => boolean` | none (every origin allowed) | Called on every page call with the origin of the calling frame. Return `false` to refuse. A throw refuses too. See [SECURITY.md](../SECURITY.md#alloworigin). |
|
|
71
|
+
| `discovery` | `DeviceSource & { start(): Promise<void>; stop(): void }` | `new CastDiscovery()` | Replaces device discovery. Mainly for tests. |
|
|
72
|
+
| `createClient` | `(device: CastDevice, params: ChannelParams) => CastClientLike` | `new CastClient({ host, port, verifyDevice: verifyDevices !== false, connectTimeoutMs, heartbeatTimeoutMs })` | Creates the connection to a device. `params` is `{ connectTimeoutMs, livenessTimeoutMs }` for this attempt (10 s unless `sinks.dynamicTimeoutDeltaMs` is set). Use it to pass `CastClient` options such as `tls`. When you give it, `verifyDevices` is ignored: pass `verifyDevice` to your own `CastClient`. |
|
|
73
|
+
| `channel` | `string` | `"electron-cast"` | Prefix of the IPC channel names. Must match the preload's `channel`. |
|
|
74
|
+
| `presentation` | `boolean` | `true` | Serve the preload's default (`"presentation"`) mode. With `false`, only `mode: "chromecast"` pages are served, and `ipcMain.on` and `removeListener` are not needed. |
|
|
75
|
+
| `verifyDevices` | `boolean` | `true` | Verify each device is a genuine Google-certified Cast device when connecting, as Chrome does (see [device authentication](#device-authentication)). `false` allows uncertified receivers such as open-source ones. A device that fails is never listed (see [sinks](MAIN-API.md#sinks)). |
|
|
76
|
+
| `sinks` | `CastSinkOptions` | Chrome's values | When and how channels to devices open and the list is reported: `openDelayMaxMs` (5000), `reportDelayMs` (3000), `retry` (a `SinkRetryOptions`: `initialDelayMs` 15000, `maxAttempts` 3, `multiplyFactor` 1, `jitter` 0.5, `maxDelayMs` 30000), `dynamicTimeoutDeltaMs` (0, as in Chrome: added to the 10 s connect and liveness timeouts per failed attempt, up to 30 s and 60 s) and `allowAllIps` (false: no channel is opened to a publicly routable or loopback address, as Chrome's `CastMediaSinkServiceImpl::OpenChannel` refuses them unless the `MediaRouterCastAllowAllIPs` policy is set; the address checked is the one being opened, with the predicates of [`isPubliclyRoutable` and `isLoopback`](#other-discovery-exports); see [SECURITY.md](../SECURITY.md#device-addresses)). Channels are opened to IP addresses only; a device whose `host` is a name is skipped with one `console.warn`. Each is Chrome's own setting (see [DESIGN.md](DESIGN.md#sinks-and-sessions-sink-servicets-session-trackerts)); mostly for tests. |
|
|
77
|
+
| `dial` | `boolean \| { registry?, http?, httpOptions?, settleMs?, log? }` | `true`, but `false` when a custom `discovery` is given | DIAL: SSDP discovery and the `cast-dial:` sources of presentation mode (see [DESIGN.md](DESIGN.md#dial-srcdial)). `false` sends no SSDP and no request to any device for DIAL. An object replaces the network layers (`registry`: `DialRegistryOptions`, `http`: a `DialHttp`, `httpOptions`: `origin`, `getTimeoutMs`, `actionTimeoutMs`), mostly for tests; `log` receives discovery problems, which are never thrown. A DIAL sink that is also a Cast sink (its UDN is the Cast id) is listed as Cast only, as in Chrome. |
|
|
78
|
+
| `wiredDisplay` | `WiredDisplayOptions` | none (off) | Presentation mode: other screens are presentation sinks, as Chrome's wired display provider has them; `screen`, `createReceiverWindow`, `selectDisplay`, and optional `BrowserWindow` and `displayOf` ([MAIN-API](MAIN-API.md#wired-displays)). |
|
|
79
|
+
| `accessCode` | `AccessCodeOptions` | off | Adding a device by its address, as Chrome's access code casting adds the device a code resolved to: `enabled` (Chrome's `AccessCodeCastEnabled`), `deviceDuration`, `store` ([MAIN-API](MAIN-API.md#adding-a-device-by-address)). |
|
|
80
|
+
| `networkMonitor` | `NetworkMonitor \| false` | reads `os.networkInterfaces()` every 5 s while started; none with a custom `discovery` | Network changes, as Chrome's `DiscoveryNetworkMonitor` reports them: DIAL devices given up on are tried again, the sinks of a network the machine comes back to are reopened, and devices added by address are removed and re-added 4.45 s later. A `NetworkMonitor` is `{ networkId(), observe(listener), start(), stop() }`; pass a fake to drive changes in tests, or `false` to turn it off ([DESIGN](DESIGN.md#network-changes-network-monitorts)). |
|
|
81
|
+
| `mirroring` | `ElectronMirroringOptions \| { createService }` | none (off) | Tab and desktop mirroring (`startCasting` with `castMode: "tab_mirror"` or `"desktop_mirror"`): the Electron classes it needs (with `app`, Chrome's codec switches on `app.commandLine` are honoured), and optional `engineModulePath`, `log`; `createService` replaces the engine (tests) ([MAIN-API](MAIN-API.md#tab-and-desktop-mirroring)). |
|
|
82
|
+
|
|
83
|
+
#### `CastManager`
|
|
84
|
+
|
|
85
|
+
| Member | Description |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `start(): Promise<void>` | Starts discovery: opens an mDNS socket on every external IPv4 interface and on each adapter's IPv6 link-local address, and queries (see [Discovery](#discovery)). Safe to call more than once. Rejects only if the manager was disposed. |
|
|
88
|
+
| `devices(): CastDevice[]` | The devices that can be cast to: those whose channel has opened and passed device authentication, as last reported (see [sinks](MAIN-API.md#sinks)). Not the same as what mDNS has heard. Fresh copies. |
|
|
89
|
+
| `discoverSinksNow(): void` | Opens channels at once to every discovered device that has none, with no random delay (Chrome: `DiscoverSinksNow`). A device that gave up after its retries is only tried again by this or when discovery reports it again. It also tries the DIAL sinks again (Chrome: `CastMediaSinkServiceImpl::DiscoverSinksNow`). |
|
|
90
|
+
| `settled(options?: { retries?: boolean }): Promise<void>` | Resolves when no channel is being opened or waiting to be, and the list is reported. A retry waiting out its backoff counts only with `retries: true`. For tests and start-up. |
|
|
91
|
+
| `addSinkByAddress(device): Promise<AddSinkResult>` | Opens a channel to a device the app knows the address of and lists it for `accessCode.deviceDuration` seconds, as Chrome adds the device an access code resolved to. Validate the address first ([MAIN-API](MAIN-API.md#adding-a-device-by-address)). |
|
|
92
|
+
| `configureAccessCode({ enabled?, deviceDuration? }): Promise<void>`, `rememberedSinks()` | Change the access code settings while running; the devices remembered now. |
|
|
93
|
+
| `dispose(): Promise<void>` | Removes the IPC handlers, stops discovery, closes every device connection and ends all sessions. Idempotent. A disposed manager cannot be restarted; create a new one. |
|
|
94
|
+
| `registerMediaSinksObserver(observer, query?)`, `registerMediaRoutesObserver(observer)`, `getRoutes()`, `terminateRoute(id)`, `detachRoute(id)`, `getRouteController(id)`, `getMediaController(id, observer?)` | The main-process Media Router API: observe devices (sinks) and sessions (routes), stop or detach a session, set its volume. Documented in [MAIN-API.md](MAIN-API.md), with the types `MediaSink`, `MediaSinksObserver`, `MediaSinksQuery`, `SinkIconType`, `MediaRoute`, `MediaRoutesObserver`, `MediaRouteController`, `MediaController`, `MediaStatus`, `MediaStatusObserver`, `CastManagerApi`, `DevicePickerContext` and the error class `MediaRouteError`, all exported from `electron-cast/main`. |
|
|
95
|
+
| `hasDefaultPresentationRequest(webContentsId)`, `getDefaultPresentationRequest(webContentsId)`, `addPresentationObserver(webContentsId, observer)`, `startCasting(sinkId, options: StartCastingOptions)` | Casting from the app's own UI on the page's `navigator.presentation.defaultRequest`, as Chrome's Cast dialog does: read and observe the window's default request (`PresentationRequest`: `{ webContentsId, presentationUrls, frameOrigin }`; `PresentationObserver`: `onDefaultPresentationChanged(request \| null)`), and start it on a sink. `startCasting` resolves with the `MediaRoute`, hands the page `connectionavailable` with a connection, needs no user gesture, and rejects with `MediaRouteError` (`unable_to_cast`, `timed_out`, `sink_not_found`, `invalid_origin`, `cancelled`, `redundant_request`, `unknown_error`). `MediaSinksQuery.presentationUrls` lists the sinks that can run those URLs. With `castMode: "tab_mirror"` (`webContentsId` is then the page to mirror) or `"desktop_mirror"` (`desktopSourceId`, `withAudio`) the same method starts mirroring, and `MediaSinksQuery.castMode` lists the sinks for it. See [MAIN-API.md](MAIN-API.md#casting-from-the-apps-own-ui) and [mirroring](MAIN-API.md#tab-and-desktop-mirroring). |
|
|
96
|
+
| `switchMirroringSourceTab(routeId, webContentsId)`, `freezeRoute(routeId)`, `unfreezeRoute(routeId)` | Chrome's "share this tab instead" and freeze for a running mirroring route: `switchMirroringSourceTab` moves a `tab_mirror` route to another page in the same session (same route id, no renegotiation; local muting moves with it; throws `route_not_found`, or `unable_to_cast` for a desktop route, a route still launching or a page that cannot be captured). `freezeRoute` pauses the video on its last frame after 500 ms (the audio goes on) and `unfreezeRoute` resumes it at once; both do nothing for a route that is not a mirroring route. Mirroring routes carry `freezeInfo: { canFreeze, isFrozen }`. See [MAIN-API.md](MAIN-API.md#tab-and-desktop-mirroring). |
|
|
97
|
+
| `setMirroringStatsEnabled(enabled)`, `isMirroringStatsEnabled()`, `getMirroringStats(routeId)`, `registerMirroringStatsObserver(observer)` | Mirroring statistics, a debugging aid like Chrome's `chrome://media-router-internals` "Mirroring stats" (`MediaRouterDebugger`): off by default and read when a session starts, so enable them before `startCasting`; then each mirroring route has `{ audio, video }` with Chrome's names and units, refreshed every 500 ms (`MirroringStats`). `getMirroringStats` never throws: like Chrome's `MediaRouterDebuggerImpl::GetMirroringStats`, which has no error path, it returns `{}` while statistics are off, before the first fetch and for a route id it does not know, and an ended route keeps its last statistics (Chrome's copy outlives the session) until another route pushes newer ones. Not a web API, nothing is uploaded. See [MAIN-API.md](MAIN-API.md#tab-and-desktop-mirroring). |
|
|
98
|
+
|
|
99
|
+
#### `selectDevice`
|
|
100
|
+
|
|
101
|
+
`devices` holds only devices that have the capabilities the page asked for (default mode asks for none, so it lists
|
|
102
|
+
every device). The list is live at call time and is not updated while your picker is open.
|
|
103
|
+
|
|
104
|
+
`request` is a `CastRequestInfo`:
|
|
105
|
+
|
|
106
|
+
| Field | Type | Description |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| `appId` | `string` | The receiver application the page wants to launch (for example `CC1AD845`, the default media receiver). |
|
|
109
|
+
| `capabilities` | `string[]` | Capabilities the page requires: `video_out`, `video_in`, `audio_out`, `audio_in`, `multizone_group`. |
|
|
110
|
+
| `origin` | `string` | Origin of the requesting frame. Show it to the user. |
|
|
111
|
+
| `senderId` | `number` | The requesting webContents id. |
|
|
112
|
+
| `session` | `{ sessionId: string; deviceId: string }` (optional) | The sender's current session for this `appId`. The key is absent when there is none. |
|
|
113
|
+
|
|
114
|
+
The result is a `DeviceChoice` (`CastDevice | null | "stop"`):
|
|
115
|
+
|
|
116
|
+
- a `CastDevice`: cast to it. If it is the device of `request.session`, the existing session is returned and nothing is
|
|
117
|
+
relaunched.
|
|
118
|
+
- `null`: the user cancelled. The page gets a cancel error.
|
|
119
|
+
- `"stop"`: stop `request.session`. The page's receiver action listeners are told, the session ends, and the
|
|
120
|
+
request resolves as cancelled. Without a `request.session`, it is treated as cancelled.
|
|
121
|
+
|
|
122
|
+
The time the picker is open does not count against the page's launch timeout.
|
|
123
|
+
|
|
124
|
+
When the page's request carries a `cast-dial:` URL (Google's SDK adds one when the page passes a `dialRequest`),
|
|
125
|
+
`devices` also holds the DIAL sinks that have that app and may be shown to the page's origin; `request.appId` is then `""`
|
|
126
|
+
for a request that has no Cast URL. A DIAL sink has `device.dial` set. Choose it like any device: the manager creates the
|
|
127
|
+
DIAL route, and `request.session` does not apply to it.
|
|
128
|
+
|
|
129
|
+
The third argument, a `DevicePickerContext` (`{ signal: AbortSignal; registerMediaSinksObserver(observer): () => void }`),
|
|
130
|
+
streams devices that appear while the picker is open (mDNS often needs seconds). `signal` aborts when the request no
|
|
131
|
+
longer waits for a choice. See [MAIN-API.md](MAIN-API.md#a-live-device-picker).
|
|
132
|
+
|
|
133
|
+
#### App availability
|
|
134
|
+
|
|
135
|
+
In the default (Presentation API) mode a device counts for a page's request only once it has said, over its open
|
|
136
|
+
channel, that it has the request's receiver app, as in Chrome, where a `PresentationRequest`'s availability and the
|
|
137
|
+
sinks its `start()` offers come from `CastAppDiscoveryServiceImpl` (`cast_app_discovery_service.cc`). When a page asks
|
|
138
|
+
(`getAvailability()`) or starts (`start()`), every device with an open channel is asked `GET_APP_AVAILABILITY` for the
|
|
139
|
+
app, unless an answer stands; a device whose channel opens later is asked then. The answers follow Chrome's rules
|
|
140
|
+
(`ShouldRefreshAppAvailability`): "available" stands until the device goes away, "unavailable" for a minute
|
|
141
|
+
(`APP_AVAILABILITY_REFRESH_MS`), and no answer (a timeout, an error) is asked again each time.
|
|
142
|
+
|
|
143
|
+
- `getAvailability()` resolves at once from answers that stand; otherwise as soon as one device says yes, or when every
|
|
144
|
+
device asked has answered. Its `change` events follow each answer that makes a device available or not, and each
|
|
145
|
+
device that comes or goes, without waiting for the device list's 3 s report. So a page that asks at load, before the
|
|
146
|
+
channels are open, gets `false` and then a `change` to `true` a moment later.
|
|
147
|
+
- `start()` offers the picker the devices that have the app (and the capabilities the URL names), waiting for the
|
|
148
|
+
answers when none stands yet; with none, it rejects with `NotFoundError`. The picker's live list follows the answers.
|
|
149
|
+
- `mode: "chromecast"` is unchanged: `chrome.cast` availability and `requestSession` go by capabilities only.
|
|
150
|
+
|
|
151
|
+
Chrome's first answer waits for a device's result with no bound of its own; here it is bounded by the asks in flight
|
|
152
|
+
(each has the client's request timeout).
|
|
153
|
+
|
|
154
|
+
#### Errors the page sees
|
|
155
|
+
|
|
156
|
+
In `mode: "chromecast"`, `chrome.cast.ErrorCode` values: `cancel`, `timeout`, `receiver_unavailable`,
|
|
157
|
+
`session_error`, `channel_error`, `invalid_parameter`, `extension_missing` (origin not allowed, no sender frame, or a
|
|
158
|
+
call from an iframe).
|
|
159
|
+
In default mode they are mapped onto `DOMException` names: a cancelled request is `AbortError`, no receiver (or a
|
|
160
|
+
session that is gone, or one that does not match) is `NotFoundError`, a rejected parameter is `InvalidAccessError`, an
|
|
161
|
+
unusable presentation URL is `NotSupportedError`, and anything else is `OperationError`. An origin refused by
|
|
162
|
+
`allowOrigin` reads as no receivers and `start` fails; a call with no sender frame gets `NotAllowedError`.
|
|
163
|
+
|
|
164
|
+
`start` needs transient user activation, as in Chrome: the preload reads `navigator.userActivation.isActive` in its
|
|
165
|
+
own (isolated) world when the page calls the bridge's `start` and sends the result, replacing anything the page
|
|
166
|
+
passed; the main process refuses a start without it with `AbortError` ("PresentationRequest::start() requires user
|
|
167
|
+
gesture.", what Chromium's `PresentationServiceImpl::StartPresentation` reports as `PRESENTATION_REQUEST_CANCELLED`).
|
|
168
|
+
The page-side stand-in rejects with `InvalidAccessError` first, as Blink's `PresentationRequest::start()` does.
|
|
169
|
+
`mode: "chromecast"` has no gesture check. See [SECURITY.md](../SECURITY.md#user-gesture) for what this does and does
|
|
170
|
+
not protect against.
|
|
171
|
+
|
|
172
|
+
#### Sources electron-cast does not serve
|
|
173
|
+
|
|
174
|
+
electron-cast launches receiver apps; it does not mirror or remote. A presentation URL that names a Cast Streaming app
|
|
175
|
+
(`0F5096E8` or `85CDB22F`, in `cast:` or the legacy `https://google.com/cast#__castAppId__=` form, also when
|
|
176
|
+
listed beside ordinary apps in one legacy URL) is a mirroring source in Chrome, and a `remote-playback:` source (made
|
|
177
|
+
by `HTMLMediaElement.remote`) is served by media remoting. Neither is launched here: the request reads as having no
|
|
178
|
+
screen, so `getAvailability()` resolves `false` and `start()` rejects with `NotFoundError` ("No screens found.").
|
|
179
|
+
When a request lists several URLs, the first ordinary Cast app URL is served, so a normal app next to a mirroring one
|
|
180
|
+
still casts. The stand-in's `PresentationRequest` keeps only `http`, `https`, `cast` and `cast-dial` URLs and throws
|
|
181
|
+
`NotSupportedError` ("An empty sequence of URLs is not supported.") when none is left, as Blink does, so a page cannot
|
|
182
|
+
make a `remote-playback:` request. `video.remote` is not touched and never reports a device. See
|
|
183
|
+
[DESIGN.md](DESIGN.md#presentation-sources).
|
|
184
|
+
|
|
185
|
+
#### Rejoining after a reload or restart
|
|
186
|
+
|
|
187
|
+
- **Page reload or navigation.** The sessions stay open on the device (parked) and the next page of the same sender
|
|
188
|
+
rejoins them by auto-join, as in Chrome.
|
|
189
|
+
- **App restart.** The library persists nothing. A session may still be playing on the device; Chrome's auto-join does
|
|
190
|
+
not find sessions started by an earlier run, and neither does electron-cast. The app keeps the session id (Google's
|
|
191
|
+
SDK exposes it as `session.sessionId`) and the page calls `chrome.cast.requestSessionById(id)` at startup. The SDK
|
|
192
|
+
turns that into `PresentationRequest.reconnect("cast-session_<id>")`, which reaches
|
|
193
|
+
[`joinRunningSession`](#joinrunningsession): electron-cast already knows what each device runs (it follows
|
|
194
|
+
every device's receiver status, as Chrome does) and joins the session if the app matches. This checks no origin (Chrome's `AppActivity::CanJoinSession` checks only the
|
|
195
|
+
app and that the client is not already connected), but `allowOrigin` still applies first. If the device no longer
|
|
196
|
+
runs the session, the call fails with `NotFoundError`. `mode: "chromecast"` does not do this.
|
|
197
|
+
|
|
198
|
+
#### Structural types
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
interface FrameLike {
|
|
202
|
+
url: string;
|
|
203
|
+
origin?: string;
|
|
204
|
+
frameTreeNodeId?: number; // identifies a subframe across navigations
|
|
205
|
+
parent?: unknown; // null or absent on a main frame
|
|
206
|
+
processId?: number;
|
|
207
|
+
routingId?: number;
|
|
208
|
+
send?(channel: string, ...args: any[]): void; // reaches only this frame
|
|
209
|
+
}
|
|
210
|
+
interface WebContentsLike {
|
|
211
|
+
readonly id: number;
|
|
212
|
+
send(channel: string, ...args: any[]): void;
|
|
213
|
+
isDestroyed(): boolean;
|
|
214
|
+
readonly mainFrame?: { readonly framesInSubtree: readonly FrameLike[] };
|
|
215
|
+
once(event: "destroyed", listener: () => void): unknown;
|
|
216
|
+
on(event: "did-navigate" | "did-frame-navigate", listener: (...args: any[]) => void): unknown;
|
|
217
|
+
}
|
|
218
|
+
interface IpcMainInvokeEventLike { sender: WebContentsLike; senderFrame: FrameLike | null }
|
|
219
|
+
interface IpcMainEventLike { sender: WebContentsLike; senderFrame?: FrameLike | null }
|
|
220
|
+
interface IpcMainLike {
|
|
221
|
+
handle(channel: string, listener: (event: IpcMainInvokeEventLike, ...args: any[]) => unknown): void;
|
|
222
|
+
removeHandler(channel: string): void;
|
|
223
|
+
on?(channel: string, listener: (event: IpcMainEventLike, ...args: any[]) => void): unknown;
|
|
224
|
+
removeListener?(channel: string, listener: (event: IpcMainEventLike, ...args: any[]) => void): unknown;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Electron's `ipcMain`, `WebContents` and `WebFrameMain` satisfy these. The main entry also exports the types
|
|
229
|
+
`CastRequestInfo`, `DeviceChoice` and `CastDevice`, and the manager API types listed above.
|
|
230
|
+
|
|
231
|
+
#### `CastDevice`
|
|
232
|
+
|
|
233
|
+
| Field | Type | Description |
|
|
234
|
+
|---|---|---|
|
|
235
|
+
| `id` | `string` | The device's stable id (mDNS TXT `id`). Devices are de-duplicated by it. |
|
|
236
|
+
| `name` | `string` | Friendly name (TXT `fn`), or the first label of the instance name. |
|
|
237
|
+
| `model` | `string` | Model name (TXT `md`), or `""`. |
|
|
238
|
+
| `host` | `string` | Address to connect to: the first of `addresses`. |
|
|
239
|
+
| `addresses` | `string[]` | All addresses: IPv4 first, then global IPv6, then link-local IPv6 (`fe80::1%12`, with its zone so it can be connected to); newest first within each group. |
|
|
240
|
+
| `port` | `number` | The Cast port, usually 8009. |
|
|
241
|
+
| `capabilities` | `number` | Capability bit mask (TXT `ca`): 1 `video_out`, 2 `video_in`, 4 `audio_out`, 8 `audio_in`, 32 `multizone_group`. |
|
|
242
|
+
| `isGroup` | `boolean` | True when the `multizone_group` bit is set. |
|
|
243
|
+
| `statusText` | `string` | TXT `rs`, or `""`. |
|
|
244
|
+
| `instanceName` | `string` | The full mDNS instance name. |
|
|
245
|
+
| `txt` | `Record<string, string>` | All TXT records. Treat the values as untrusted. |
|
|
246
|
+
| `dial` | `{ appUrl: string; modelName: string; ipAddress: string }` (optional) | Set only on a DIAL sink, which is shown to `selectDevice` when a request carries a `cast-dial:` URL. Then `id` is `dial:<uuid>`, `host` and `addresses` hold the device's address, `port` is 0, `capabilities` is 0 and `txt` is empty. Do not connect to it: return it from `selectDevice` and the manager launches the app over DIAL. |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## `electron-cast/preload`
|
|
251
|
+
|
|
252
|
+
### `installCastBridge(options)`
|
|
253
|
+
|
|
254
|
+
<!-- no-check -->
|
|
255
|
+
```ts
|
|
256
|
+
function installCastBridge(options: CastBridgeOptions): void
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Call it once from a preload script. It exposes a bridge object to the page's main world with
|
|
260
|
+
`contextBridge.exposeInMainWorld`, then runs the page-side code in the main world with
|
|
261
|
+
`contextBridge.executeInMainWorld` (Electron 35 or later), before the page's own scripts run.
|
|
262
|
+
|
|
263
|
+
- `mode: "presentation"` (default): installs a stand-in for the Presentation API (`PresentationRequest`,
|
|
264
|
+
`PresentationConnection`, `PresentationAvailability`, `navigator.presentation`). Google's own Cast SDK then loads
|
|
265
|
+
and runs unmodified. It runs in every frame the preload runs in (iframes need `nodeIntegrationInSubFrames: true`).
|
|
266
|
+
- `mode: "chromecast"`: installs electron-cast's own `chrome.cast` and `chrome.cast.media` (and `cast.framework`)
|
|
267
|
+
and blocks Google's loader scripts from replacing them. Nothing is installed if `chrome.cast` already exists.
|
|
268
|
+
|
|
269
|
+
Throws `TypeError` for an unknown `mode`, and in default mode if `ipcRenderer.send` is missing.
|
|
270
|
+
|
|
271
|
+
#### `CastBridgeOptions`
|
|
272
|
+
|
|
273
|
+
| Option | Type | Default | Description |
|
|
274
|
+
|---|---|---|---|
|
|
275
|
+
| `contextBridge` | `ContextBridgeLike` | required | Electron's `contextBridge`. |
|
|
276
|
+
| `ipcRenderer` | `IpcRendererLike` | required | Electron's `ipcRenderer`. Default mode also needs `send`. |
|
|
277
|
+
| `channel` | `string` | `"electron-cast"` | Prefix of the IPC channel names. Must match the manager's `channel`. |
|
|
278
|
+
| `mode` | `"presentation" \| "chromecast"` | `"presentation"` | See above. |
|
|
279
|
+
| `bridgeKey` | `string` | `"__electronCastBridge"` | Name of the global the bridge is exposed as. `"chromecast"` mode only. |
|
|
280
|
+
| `presentationBridgeKey` | `string` | `"__electronCastPresentationBridge"` | Name of the global the bridge is exposed as. `"presentation"` mode only. |
|
|
281
|
+
| `isUserActive` | `() => boolean` | reads `navigator.userActivation.isActive` in the preload's isolated world (`false` if missing) | Whether the frame has transient user activation right now, asked when the page calls `start`. `"presentation"` mode only. Mainly for tests. |
|
|
282
|
+
|
|
283
|
+
The page can read the bridge global and call it. See [SECURITY.md](../SECURITY.md).
|
|
284
|
+
|
|
285
|
+
#### Structural types
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
interface ContextBridgeLike {
|
|
289
|
+
exposeInMainWorld(key: string, api: unknown): void;
|
|
290
|
+
executeInMainWorld(script: { func: (...args: any[]) => unknown; args?: unknown[] }): unknown;
|
|
291
|
+
}
|
|
292
|
+
interface IpcRendererLike {
|
|
293
|
+
invoke(channel: string, ...args: unknown[]): Promise<unknown>;
|
|
294
|
+
on(channel: string, listener: (event: unknown, ...args: any[]) => void): unknown;
|
|
295
|
+
send?(channel: string, ...args: unknown[]): void; // needed in "presentation" mode
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## `electron-cast/polyfill`
|
|
302
|
+
|
|
303
|
+
### `installChromeCast(bridgeKey)`
|
|
304
|
+
|
|
305
|
+
<!-- no-check -->
|
|
306
|
+
```ts
|
|
307
|
+
function installChromeCast(bridgeKey: string): boolean
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Installs electron-cast's own `chrome.cast` (API version `[1, 2]`), `chrome.cast.media` and `cast.framework` on the
|
|
311
|
+
page's global object, talking to the bridge at `globalThis[bridgeKey]`. Returns `true` when installed, `false`
|
|
312
|
+
when the bridge is missing or `chrome.cast` already exists (nothing is changed).
|
|
313
|
+
|
|
314
|
+
You normally do not call this: `installCastBridge({ mode: "chromecast" })` does. The function must stay
|
|
315
|
+
self-contained because Electron serializes it to source to run it in the main world.
|
|
316
|
+
|
|
317
|
+
The default mode's Presentation API stand-in is internal and has no public entry.
|
|
318
|
+
|
|
319
|
+
### Bridge types
|
|
320
|
+
|
|
321
|
+
Also exported from the root. These describe the messages between the page-side polyfill and the main process.
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
type BridgeResult<T = unknown> =
|
|
325
|
+
| { ok: true; value: T }
|
|
326
|
+
| { ok: false; code: string; description?: string };
|
|
327
|
+
|
|
328
|
+
type BridgeMethod = "initialize" | "requestSession" | "joinSession" | "sendMessage" | "stopSession"
|
|
329
|
+
| "leaveSession" | "setReceiverVolume" | "setReceiverMuted";
|
|
330
|
+
|
|
331
|
+
interface CastBridge {
|
|
332
|
+
call(method: BridgeMethod, params: unknown): Promise<BridgeResult>; // never rejects
|
|
333
|
+
onEvent(listener: (event: BridgeEvent) => void): void; // one listener
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
type BridgeEvent =
|
|
337
|
+
| { type: "receiverAvailability"; available: boolean }
|
|
338
|
+
| { type: "sessionUpdated"; session: SessionSnapshot }
|
|
339
|
+
| { type: "sessionEnded"; sessionId: string; status: "stopped" | "disconnected" }
|
|
340
|
+
| { type: "receiverAction"; sessionId: string; action: "stop" }
|
|
341
|
+
| { type: "message"; sessionId: string; namespace: string; message: string };
|
|
342
|
+
|
|
343
|
+
interface InitializeParams { appId: string; capabilities: string[]; autoJoinPolicy: string }
|
|
344
|
+
interface InitializeResult { available: boolean; sessions: SessionSnapshot[] }
|
|
345
|
+
interface RequestSessionParams { appId: string; capabilities: string[]; timeoutMs: number }
|
|
346
|
+
interface VolumeSnapshot { level: number | null; muted: boolean | null; controlType?: string; stepInterval?: number }
|
|
347
|
+
interface ImageSnapshot { url: string; height?: number | null; width?: number | null }
|
|
348
|
+
interface ReceiverSnapshot {
|
|
349
|
+
label: string; friendlyName: string; capabilities: string[]; volume: VolumeSnapshot;
|
|
350
|
+
isActiveInput?: boolean | null; displayStatus?: { statusText: string; appImages: ImageSnapshot[] } | null;
|
|
351
|
+
}
|
|
352
|
+
interface SessionSnapshot {
|
|
353
|
+
sessionId: string; appId: string; displayName: string; appImages: ImageSnapshot[]; statusText: string | null;
|
|
354
|
+
namespaces: { name: string }[]; transportId: string; receiver: ReceiverSnapshot;
|
|
355
|
+
senderApps?: { platform: string; url?: string | null; packageId?: string | null }[];
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## `electron-cast` (root)
|
|
362
|
+
|
|
363
|
+
The root re-exports every layer below and everything from the three entry points above. The layers need Node and
|
|
364
|
+
have no Electron dependency, so they run in plain Node.
|
|
365
|
+
|
|
366
|
+
### Session service
|
|
367
|
+
|
|
368
|
+
<!-- no-check -->
|
|
369
|
+
```ts
|
|
370
|
+
class CastSessionService {
|
|
371
|
+
constructor(options: CastSessionServiceOptions)
|
|
372
|
+
handle(sender: SenderInfo, method: string, params: unknown): Promise<BridgeResult>
|
|
373
|
+
senderGone(senderId: number): void
|
|
374
|
+
senderNavigated(senderId: number): void
|
|
375
|
+
dispose(): Promise<void>
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
The session logic behind `createCastManager`: it tracks initialized senders, one client per device and the sessions
|
|
380
|
+
pages hold, and pushes events through `options.emit`.
|
|
381
|
+
|
|
382
|
+
| Member | Description |
|
|
383
|
+
|---|---|
|
|
384
|
+
| `handle(sender, method, params)` | Handles one bridge call (`BridgeMethod`). Checks `allowOrigin`, validates `params`, and returns a `BridgeResult`. Never throws or rejects. An unknown method gives `invalid_parameter`. |
|
|
385
|
+
| `senderGone(senderId)` | The sender is gone for good: cancels its pending request and leaves its sessions. |
|
|
386
|
+
| `senderNavigated(senderId)` | The sender's page navigated: cancels its pending request but keeps its sessions open, parked, for a rejoin. |
|
|
387
|
+
| `dispose()` | Unsubscribes from devices, closes every client and clears all state. Idempotent. |
|
|
388
|
+
|
|
389
|
+
`handle` method names and parameters:
|
|
390
|
+
|
|
391
|
+
| Method | Params | Success value |
|
|
392
|
+
|---|---|---|
|
|
393
|
+
| `initialize` | `{ appId: string, capabilities: string[], autoJoinPolicy: string }` | `InitializeResult`: availability, and the sessions auto-joined (`origin_scoped`, or `tab_and_origin_scoped` for this sender's own sessions) |
|
|
394
|
+
| `requestSession` | `{ appId: string, capabilities: string[], timeoutMs?: number }` (default 60000) | `SessionSnapshot` |
|
|
395
|
+
| `joinSession` | `{ sessionId: string }` (the session must have been started from the same origin) | `SessionSnapshot` |
|
|
396
|
+
| `joinRunningSession` | `{ sessionId: string, appId?: string }` | `SessionSnapshot` |
|
|
397
|
+
| `sendMessage` | `{ sessionId: string, namespace: string, message: string }` | `undefined` |
|
|
398
|
+
| `stopSession` | `{ sessionId: string }` | `undefined` |
|
|
399
|
+
| `leaveSession` | `{ sessionId: string }` | `undefined` |
|
|
400
|
+
| `setReceiverVolume` | `{ sessionId: string, level: number }` (0 to 1) | `undefined` |
|
|
401
|
+
| `setReceiverMuted` | `{ sessionId: string, muted: boolean }` | `undefined` |
|
|
402
|
+
|
|
403
|
+
##### `joinRunningSession`
|
|
404
|
+
|
|
405
|
+
Joins a session by id the way Chrome's Media Router does for `reconnect("cast-session_<id>")`. A session this service
|
|
406
|
+
already holds is joined at once. Otherwise the session tracker, which keeps what every device runs from the receiver
|
|
407
|
+
status on its open channel, is asked, and the caller joins over that device's channel; the session then belongs to the
|
|
408
|
+
caller's origin. Nothing is looked up when asked, so the device must have been found (its channel open and status
|
|
409
|
+
received) by then. `appId`, when given, must be the session's app. No origin is compared with the session's (unlike
|
|
410
|
+
`joinSession`); `allowOrigin` still applies. Fails with `session_error` when no known device runs the session, the
|
|
411
|
+
app differs, or the service was disposed; with `invalid_parameter` for a bad `sessionId`. The presentation handler calls it for `reconnect`;
|
|
412
|
+
`mode: "chromecast"` does not (its `requestSessionById` uses `joinSession`). Only main calls it: it is not a
|
|
413
|
+
`BridgeMethod`, and the IPC channel refuses it from a page as an unknown method (`invalid_parameter`).
|
|
414
|
+
|
|
415
|
+
Error codes: `invalid_parameter`, `extension_missing` (origin not allowed), `receiver_unavailable`, `cancel`, `timeout`,
|
|
416
|
+
`session_error`, `channel_error`.
|
|
417
|
+
|
|
418
|
+
#### `CastSessionServiceOptions`
|
|
419
|
+
|
|
420
|
+
| Option | Type | Description |
|
|
421
|
+
|---|---|---|
|
|
422
|
+
| `devices` | `DeviceSource` | Source of devices and change events. The service opens a channel to each and lists it only once the channel is open. |
|
|
423
|
+
| `sinks` | `CastSinkOptions` (optional) | As for the manager. |
|
|
424
|
+
| `createClient` | `(device: CastDevice, params: ChannelParams) => CastClientLike` | Creates a connection for a device. |
|
|
425
|
+
| `selectDevice` | `(devices, request, picker) => Promise<DeviceChoice>` | As in [`selectDevice`](#selectdevice). |
|
|
426
|
+
| `allowOrigin` | `(origin: string) => boolean` (optional) | As for the manager. |
|
|
427
|
+
| `emit` | `(senderId: number, event: BridgeEvent) => void` | Receives every event for a sender. |
|
|
428
|
+
|
|
429
|
+
The root also exports the DIAL layer from `src/dial/`. They are the pieces [DESIGN.md](DESIGN.md#dial-srcdial)
|
|
430
|
+
describes, each with the Chromium function it follows, and are not needed to use the manager:
|
|
431
|
+
|
|
432
|
+
| Export | What it is |
|
|
433
|
+
|---|---|
|
|
434
|
+
| `DialService`, `DialServiceOptions` | The registry, sink service and route provider behind the manager's `dial` option. `isCastDevice` tells it which processed uuids are Cast sinks, whose DIAL sinks it then hides. |
|
|
435
|
+
| `DialRegistry`, `DialRegistryOptions` | SSDP discovery cycles and the device list (`DialRegistry`). |
|
|
436
|
+
| `DialSinkService`, `DialSink` | Device descriptions, app info and the sinks (`DialMediaSinkServiceImpl`). |
|
|
437
|
+
| `DialRouteProvider`, `DialRouteInfo`, `DialRouteError` | The DIAL routes and the SDK's round trip (`DialMediaRouteProvider`); `DialRouteError` carries Chrome's result code. |
|
|
438
|
+
| `dialEnvelope`, `parseDialMessage` | Build and read the router messages of a DIAL route (`dial_internal_message_util.cc`). |
|
|
439
|
+
| `createDialHttp`, `DialHttp`, `DialHttpOptions`, `DialHttpResult`, `defaultDialOrigin` | The HTTP layer (`DialURLFetcher`) and the fake `Origin` it sends (`GetFakeOriginForDialLaunch`). |
|
|
440
|
+
| `dialOriginAllowed`, `dialOriginsFor` | Which origins may see an app (`DialMediaRouteProvider::GetOrigins`). |
|
|
441
|
+
| `DIAL_SCHEME`, `isDialSource`, `appNameFromDialSource`, `parseDialLaunchSource` | `cast-dial:` sources (`MediaSource::IsDialSource`, `AppNameFromDialSource`, `DialActivity::From`). |
|
|
442
|
+
| `dialSinkToDevice` | A DIAL sink as a `CastDevice` with its `dial` field set, the shape pickers and sinks observers see. |
|
|
443
|
+
|
|
444
|
+
#### Other exports
|
|
445
|
+
|
|
446
|
+
| Export | Description |
|
|
447
|
+
|---|---|
|
|
448
|
+
| `capabilityNames(bits: number): string[]` | Capability bit mask to names, in bit order. |
|
|
449
|
+
| `DeviceSource` | `devices(): CastDevice[]` and `on`/`off` for `"deviceUp"`, `"deviceDown"`, `"deviceChanged"` (listener gets a `CastDevice`). `CastDiscovery` fits it. |
|
|
450
|
+
| `CastClientLike` | The part of `CastClient` the service uses: `connected`, `connect`, `close`, `send`, `launch`, `stop`, `setVolume`, `getStatus`, `connectTransport`, `closeTransport`, and `on` for `message`, `receiverStatus`, `transportClosed`, `close`. |
|
|
451
|
+
| `ClientMessage` | `{ namespace, sourceId, destinationId, data: string \| Buffer }`. |
|
|
452
|
+
| `SenderInfo` | `{ id: number, origin: string }`: a frame (the webContents id for a main frame; the manager gives each iframe its own id) and its origin. |
|
|
453
|
+
| `CastRequestInfo`, `DeviceChoice` | As above. |
|
|
454
|
+
| `APP_AVAILABILITY_REFRESH_MS` | `60000`: how long a device's "unavailable" answer to `GET_APP_AVAILABILITY` stands before it is asked again (Chrome's `kRefreshThreshold` in `cast_app_discovery_service.cc`). |
|
|
455
|
+
|
|
456
|
+
The service also has `mediaRoutes()`, `observeSessions(listener)`, `terminateSession(id)`, `setSessionVolume(id, volume)`,
|
|
457
|
+
`detachSession(id)`, `sendSessionMessage(id, namespace, message)`, `sessionVolume(id)`,
|
|
458
|
+
`observeSessionStatus(listener)` and `observeMediaStatus(listener)`, the hooks the manager's
|
|
459
|
+
[main-process API](MAIN-API.md) is built on (the last four serve the media controller, for local and non-local routes
|
|
460
|
+
alike), and the [app availability](#app-availability) the presentation handler and `startCasting` use:
|
|
461
|
+
`observeAppAvailability(sender, { appIds, capabilities }, onchange)` (`{ available: Promise<boolean>; close() }`),
|
|
462
|
+
`checkAppAvailability(device, appId)` and `cachedAppAvailability(device, appId)`.
|
|
463
|
+
|
|
464
|
+
### `CastClient`
|
|
465
|
+
|
|
466
|
+
<!-- no-check -->
|
|
467
|
+
```ts
|
|
468
|
+
class CastClient extends EventEmitter<CastClientEvents> {
|
|
469
|
+
constructor(options: CastClientOptions)
|
|
470
|
+
readonly senderId: string
|
|
471
|
+
get connected(): boolean
|
|
472
|
+
get deviceAuth(): DeviceAuthResult | undefined
|
|
473
|
+
connect(): Promise<void>
|
|
474
|
+
close(): void
|
|
475
|
+
send(namespace: string, destinationId: string, payload: string | Uint8Array | object): void
|
|
476
|
+
request<T = Record<string, unknown>>(namespace: string, destinationId: string,
|
|
477
|
+
payload: Record<string, unknown>, options?: { timeoutMs?: number }): Promise<T>
|
|
478
|
+
getStatus(): Promise<ReceiverStatus>
|
|
479
|
+
launch(appId: string): Promise<ReceiverApplication>
|
|
480
|
+
stop(sessionId: string): Promise<ReceiverStatus>
|
|
481
|
+
setVolume(volume: { level: number } | { muted: boolean }): Promise<ReceiverStatus>
|
|
482
|
+
getAppAvailability(appIds: string[]): Promise<Record<string, boolean>>
|
|
483
|
+
connectTransport(transportId: string): void
|
|
484
|
+
closeTransport(transportId: string): void
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
A single-use Cast v2 client: one TLS connection to one receiver. After `close()` or a failure it cannot be
|
|
489
|
+
reconnected; make a new one. The TLS socket is opened with `rejectUnauthorized: false`, as Cast devices present
|
|
490
|
+
self-signed certificates; the device is authenticated instead by the [device authentication](#device-authentication)
|
|
491
|
+
challenge that `connect()` runs by default (see [SECURITY.md](../SECURITY.md#tls-and-device-authentication)).
|
|
492
|
+
|
|
493
|
+
#### `CastClientOptions`
|
|
494
|
+
|
|
495
|
+
| Option | Type | Default | Description |
|
|
496
|
+
|---|---|---|---|
|
|
497
|
+
| `host` | `string` | required | Receiver address. |
|
|
498
|
+
| `port` | `number` | `8009` | Receiver port. |
|
|
499
|
+
| `senderId` | `string` | `"sender-"` plus 8 random hex digits | The `sourceId` of the client's messages. |
|
|
500
|
+
| `connectTimeoutMs` | `number` | `10000` | Limit for the TLS handshake. |
|
|
501
|
+
| `verifyDevice` | `boolean` | `true` | Verify the device is a genuine Google-certified Cast device before use. `false` skips the challenge, for uncertified receivers. |
|
|
502
|
+
| `authTimeoutMs` | `number` | `10000` | Limit for the device's reply to the authentication challenge, counted from the end of the TLS handshake. |
|
|
503
|
+
| `deviceAuth` | `DeviceAuthOptions` | none | Trust roots and clock overrides for the check, for tests and private Cast deployments (see [below](#deviceauthoptions)). |
|
|
504
|
+
| `requestTimeoutMs` | `number` | `10000` | Default limit for `request` and the calls built on it. |
|
|
505
|
+
| `launchTimeoutMs` | `number` | `30000` | Limit for `launch`. |
|
|
506
|
+
| `heartbeatIntervalMs` | `number` | `5000` | How often a PING is sent. |
|
|
507
|
+
| `heartbeatTimeoutMs` | `number` | `10000` | The connection fails after this long with no traffic. |
|
|
508
|
+
| `tls` | `Omit<tls.ConnectionOptions, "host" \| "port">` | none | Extra `tls.connect` options, applied after the defaults (so they can override `rejectUnauthorized`). |
|
|
509
|
+
| `connectPayload` | `Record<string, unknown>` | none | Extra fields merged into every CONNECT message. |
|
|
510
|
+
|
|
511
|
+
#### Methods
|
|
512
|
+
|
|
513
|
+
| Method | Description |
|
|
514
|
+
|---|---|
|
|
515
|
+
| `connect()` | Opens the TLS connection, runs device authentication (unless `verifyDevice` is `false`) and sends CONNECT to the platform receiver (`receiver-0`). Rejects with `CastConnectionError`, `CastTimeoutError` (TLS handshake) or `CastAuthError` (the device failed or did not answer the challenge; the socket is closed). Only valid once, from the idle state. |
|
|
516
|
+
| `deviceAuth` (getter) | What authentication established: a `DeviceAuthResult` once `connect()` has verified the device, `undefined` before that or with `verifyDevice: false`. |
|
|
517
|
+
| `close()` | Sends CLOSE for every open transport and the receiver, ends the socket, rejects pending work with `CastConnectionError`, and emits `close`. Idempotent. |
|
|
518
|
+
| `send(namespace, destinationId, payload)` | Sends a message. A string is sent as is, an object as JSON, a `Uint8Array` as a binary payload. Throws `CastConnectionError` when not connected. |
|
|
519
|
+
| `request(namespace, destinationId, payload, options?)` | Adds a `requestId`, sends, and resolves with the matching reply. Rejects with `CastRequestError` for an error reply, `CastTimeoutError` on timeout, `CastConnectionError` if the connection ends. |
|
|
520
|
+
| `getStatus()` | The receiver's current status. |
|
|
521
|
+
| `launch(appId)` | Launches an app and resolves when it appears in a `RECEIVER_STATUS`. Rejects with `CastRequestError` (for `LAUNCH_ERROR` or `INVALID_REQUEST`) or `CastTimeoutError`. |
|
|
522
|
+
| `stop(sessionId)` | Stops a session. Resolves with the new status. |
|
|
523
|
+
| `setVolume(volume)` | Sets the device volume level (0 to 1) or muted flag. Resolves with the new status. |
|
|
524
|
+
| `getAppAvailability(appIds)` | Which of the apps the receiver can run. |
|
|
525
|
+
| `connectTransport(transportId)` | Opens a virtual connection to an app's transport. Idempotent. Needed before messaging the app. Ignored when not connected. |
|
|
526
|
+
| `closeTransport(transportId)` | Closes it. |
|
|
527
|
+
|
|
528
|
+
#### Events
|
|
529
|
+
|
|
530
|
+
| Event | Payload | When |
|
|
531
|
+
|---|---|---|
|
|
532
|
+
| `message` | `{ namespace, sourceId, destinationId, data: string \| Buffer }` | A message arrives on any namespace except heartbeat and connection control. |
|
|
533
|
+
| `receiverStatus` | `ReceiverStatus` | A `RECEIVER_STATUS` arrives. |
|
|
534
|
+
| `transportClosed` | `transportId: string` | The receiver closed a transport. |
|
|
535
|
+
| `close` | `error?: Error` | The client closed. The error is absent after a deliberate `close()`. |
|
|
536
|
+
|
|
537
|
+
#### Constants and types
|
|
538
|
+
|
|
539
|
+
| Export | Description |
|
|
540
|
+
|---|---|
|
|
541
|
+
| `NS` | Namespace urns: `CONNECTION` (`urn:x-cast:com.google.cast.tp.connection`), `HEARTBEAT` (`...tp.heartbeat`), `RECEIVER` (`urn:x-cast:com.google.cast.receiver`) and `DEVICE_AUTH` (`...tp.deviceauth`). `DEVICE_AUTH` is used by the authentication challenge. |
|
|
542
|
+
| `PLATFORM_RECEIVER_ID` | `"receiver-0"`, the destination id of the device itself. |
|
|
543
|
+
| `ReceiverApplication` | `{ appId, displayName, sessionId, transportId, namespaces: { name }[], statusText?, isIdleScreen?, iconUrl?, ... }` |
|
|
544
|
+
| `ReceiverVolume` | `{ level?, muted?, controlType?, stepInterval? }` |
|
|
545
|
+
| `ReceiverStatus` | `{ applications: ReceiverApplication[], volume: ReceiverVolume, ... }` |
|
|
546
|
+
| `CastClientOptions`, `CastClientEvents` | The option and event types above. |
|
|
547
|
+
|
|
548
|
+
#### Device authentication
|
|
549
|
+
|
|
550
|
+
Like Chrome, `connect()` proves the device is a genuine, Google-certified Cast device before CONNECT, as a port of
|
|
551
|
+
Chromium's sender side (`cast_auth_util.cc` and the certificate code beside it): it sends a challenge (16-byte nonce,
|
|
552
|
+
SHA-256) on the `deviceauth` namespace, then checks the TLS certificate's validity window, the device's certificate
|
|
553
|
+
chain against Google's built-in Cast root certificates, revocation, and a signature over the nonce and this
|
|
554
|
+
connection's TLS certificate. There are no dependencies and no network access. How it works and where it differs from
|
|
555
|
+
Chromium: [DESIGN.md](DESIGN.md#device-authentication-srcclientauth).
|
|
556
|
+
|
|
557
|
+
**Revocation and the stale fallback CRL.** Revocation uses the CRL the device sends, or else a fallback CRL built into
|
|
558
|
+
the package, which counts for 20 weeks from the package's build time (stamped by `npm run build`; Chromium uses the
|
|
559
|
+
binary's build time). When that window has lapsed and the device sent no valid CRL, the revocation check is skipped and
|
|
560
|
+
`deviceAuth.revocationChecked` is `false`, where Chromium would refuse the device (Chrome updates itself; an app may
|
|
561
|
+
not). Everything else is still checked, and revocation by a device CRL or a still-valid fallback is always enforced.
|
|
562
|
+
Update the package to get a fresh fallback CRL.
|
|
563
|
+
|
|
564
|
+
##### `DeviceAuthResult`
|
|
565
|
+
|
|
566
|
+
Returned by the `deviceAuth` getter. Exported as a type.
|
|
567
|
+
|
|
568
|
+
| Field | Type | Meaning |
|
|
569
|
+
|---|---|---|
|
|
570
|
+
| `policy` | `"unrestricted" \| "audio_only"` | Chromium's certificate policy result. `audio_only` is reported; nothing in electron-cast acts on it. |
|
|
571
|
+
| `hashAlgorithm` | `"sha1" \| "sha256"` | The digest the device signed with. |
|
|
572
|
+
| `nonceEchoed` | `boolean` | `false` when the reply did not echo our nonce. Chromium records this and carries on, and so does electron-cast. |
|
|
573
|
+
| `usedFallbackCrl` | `boolean` | The device sent no usable CRL and the built-in fallback CRL was used. |
|
|
574
|
+
| `revocationChecked` | `boolean` | `false` only in the stale-fallback case above. |
|
|
575
|
+
|
|
576
|
+
`CastDeviceCertPolicy` (an exported type) is the type of `policy`: `"unrestricted"` or `"audio_only"`.
|
|
577
|
+
|
|
578
|
+
`CastCertError` (an exported type) is the outcome of the certificate-chain check that device authentication runs, named after
|
|
579
|
+
Chromium's `CastCertError`: `OK`, `OK_FALLBACK_CRL`, `OK_FALLBACK_CRL_STALE`, `ERR_CERTS_MISSING`, `ERR_CERTS_PARSE`,
|
|
580
|
+
`ERR_CERTS_DATE_INVALID`, `ERR_CERTS_VERIFY_GENERIC`, `ERR_CERTS_RESTRICTIONS`, `ERR_CERTS_REVOKED`,
|
|
581
|
+
`ERR_CERTS_REVOKED_BY_FALLBACK_CRL` and `ERR_FALLBACK_CRL_INVALID`. A client reports it through `CastAuthError.reason`, never
|
|
582
|
+
directly: the `ERR_CERTS_MISSING`, `_PARSE`, `_DATE_INVALID` and `_RESTRICTIONS` outcomes become `invalid_certificate`,
|
|
583
|
+
`ERR_CERTS_VERIFY_GENERIC` becomes `untrusted_chain`, both `REVOKED` outcomes become `revoked`, and `ERR_FALLBACK_CRL_INVALID`
|
|
584
|
+
becomes `crl_invalid`. The three `OK` outcomes pass; `OK_FALLBACK_CRL_STALE` is the stale-fallback case above.
|
|
585
|
+
|
|
586
|
+
##### `DeviceAuthOptions`
|
|
587
|
+
|
|
588
|
+
The `deviceAuth` client option, exported as the type `DeviceAuthOptions`. All fields are optional.
|
|
589
|
+
|
|
590
|
+
| Field | Type | Meaning |
|
|
591
|
+
|---|---|---|
|
|
592
|
+
| `now` | `number` | Verification time, epoch milliseconds. Default: now. |
|
|
593
|
+
| `roots` | `Uint8Array[]` | DER trust anchors replacing the Cast Root CA and Eureka Root CA. |
|
|
594
|
+
| `crlRoots` | `Uint8Array[]` | DER CRL trust anchors replacing the Cast CRL Root CA. |
|
|
595
|
+
| `fallbackCrl` | `Uint8Array \| null` | Replacement fallback CRL (a serialized CrlBundle), or `null` for none. |
|
|
596
|
+
| `fallbackCrlBuildTime` | `number` | The build time the fallback's 20-week window starts at, epoch milliseconds. |
|
|
597
|
+
|
|
598
|
+
#### Errors
|
|
599
|
+
|
|
600
|
+
All are `Error` subclasses with `name` set to the class name.
|
|
601
|
+
|
|
602
|
+
| Class | Thrown or rejected when | Extra fields |
|
|
603
|
+
|---|---|---|
|
|
604
|
+
| `CastConnectionError` | The connection could not be made, was closed, failed, or timed out on heartbeat; `send` while disconnected. | `cause` (the underlying error, if any) |
|
|
605
|
+
| `CastTimeoutError` | The TLS handshake, a request, or a launch did not finish in time. | none |
|
|
606
|
+
| `CastAuthError` | The device did not prove it is a genuine Cast device (reasons below). The message names the device address when known. | `reason: CastAuthReason`, `host: string \| undefined` |
|
|
607
|
+
| `CastRequestError` | The receiver replied with an error: type `INVALID_REQUEST`, `LOAD_FAILED`, `LOAD_CANCELLED`, `INVALID_PLAYER_STATE`, or ending in `_ERROR`. | `type: string`, `reason: string \| undefined`, `response: Record<string, unknown>` |
|
|
608
|
+
|
|
609
|
+
`CastAuthReason` (an exported type) is one of:
|
|
610
|
+
|
|
611
|
+
| `reason` | Meaning |
|
|
612
|
+
|---|---|
|
|
613
|
+
| `timeout` | No authentication reply within `authTimeoutMs`. |
|
|
614
|
+
| `no_tls_certificate` | The device presented no TLS certificate. |
|
|
615
|
+
| `tls_certificate_invalid` | The TLS certificate does not parse, is not yet valid, has expired, or is valid for more than 4 days (it bounds the proof's lifetime). |
|
|
616
|
+
| `device_error` | The device answered with an authentication error. |
|
|
617
|
+
| `malformed_reply` | The reply was not a binary, parseable `DeviceAuthMessage` with a response, or the framing broke during authentication. |
|
|
618
|
+
| `unsupported_algorithm` | The reply's hash algorithm is neither SHA-1 nor SHA-256. |
|
|
619
|
+
| `invalid_certificate` | No device certificate, one that does not parse, is outside its validity dates, or breaks a certificate restriction. |
|
|
620
|
+
| `untrusted_chain` | The chain does not lead to a Cast root. |
|
|
621
|
+
| `revoked` | The device certificate (or a CA) is revoked by the device's CRL or the fallback CRL. |
|
|
622
|
+
| `crl_invalid` | The device sent no valid CRL and the built-in fallback CRL is itself invalid (broken or not yet valid; a merely lapsed one skips revocation instead). |
|
|
623
|
+
| `bad_signature` | The signature over the nonce and TLS certificate is empty or does not verify. |
|
|
624
|
+
|
|
625
|
+
Through the manager, any `connect()` failure, `CastAuthError` included, reaches the page as an unreachable device.
|
|
626
|
+
|
|
627
|
+
### Discovery
|
|
628
|
+
|
|
629
|
+
#### `CastDiscovery`
|
|
630
|
+
|
|
631
|
+
<!-- no-check -->
|
|
632
|
+
```ts
|
|
633
|
+
class CastDiscovery extends EventEmitter<CastDiscoveryEvents> {
|
|
634
|
+
constructor(options?: CastDiscoveryOptions)
|
|
635
|
+
start(): Promise<void>
|
|
636
|
+
query(): void
|
|
637
|
+
devices(): CastDevice[]
|
|
638
|
+
interfaces(): NetworkInterfaceInfo[]
|
|
639
|
+
stop(): void
|
|
640
|
+
}
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
Finds Cast devices by sending mDNS PTR queries on every external IPv4 interface and on one IPv6 link-local address
|
|
644
|
+
per adapter (group `ff02::fb`), and joining the answers into `CastDevice`s, so IPv6-only devices are found too. What
|
|
645
|
+
users see:
|
|
646
|
+
|
|
647
|
+
- A device's `host` is its IPv4 address when it has one (Chromium's Cast discovery resolves only A records), else a
|
|
648
|
+
global IPv6, else link-local. Link-local addresses carry the interface's zone (`fe80::1%12`) so they can be
|
|
649
|
+
connected to; one heard on an interface with no known zone is dropped.
|
|
650
|
+
- Interfaces that appear or disappear are picked up (checked every `interfaceCheckMs`). Devices that only a vanished
|
|
651
|
+
interface heard are removed at once (`deviceDown`) instead of after their TTL.
|
|
652
|
+
- After the machine wakes from sleep (an interface check that runs more than `resumeGapMs` late) all sockets are
|
|
653
|
+
replaced and queried again, since they can come back deaf.
|
|
654
|
+
- If the socket for an interface fails (IPv6 included), `socketError` is emitted once and the other interfaces carry on.
|
|
655
|
+
|
|
656
|
+
| Member | Description |
|
|
657
|
+
|---|---|
|
|
658
|
+
| `start()` | Opens a socket on every interface and starts querying: right away, at each `followUpQueriesMs` offset, then every `refreshMs`. Resolves when every interface has been tried; an interface that fails emits `socketError` and does not fail the call. Calling it again returns the same promise. Rejects after `stop()`. |
|
|
659
|
+
| `query()` | Sends one query now on every open socket. |
|
|
660
|
+
| `devices()` | Copies of the devices known now. |
|
|
661
|
+
| `interfaces()` | The interfaces that have an open socket. |
|
|
662
|
+
| `stop()` | Stops timers, closes sockets and forgets devices. Idempotent. The instance cannot be restarted. |
|
|
663
|
+
|
|
664
|
+
##### `CastDiscoveryOptions`
|
|
665
|
+
|
|
666
|
+
| Option | Type | Default | Description |
|
|
667
|
+
|---|---|---|---|
|
|
668
|
+
| `serviceName` | `string` | `"_googlecast._tcp.local"` | The mDNS service to query. |
|
|
669
|
+
| `interfaces` | `() => NetworkInterfaceInfo[]` | `listMdnsInterfaces()` | Which interfaces to use: external IPv4 addresses plus one IPv6 link-local address per adapter. |
|
|
670
|
+
| `openSocket` | `OpenMdnsSocket` | `openUdpMdnsSocket` | How to open a socket (for tests). |
|
|
671
|
+
| `followUpQueriesMs` | `number[]` | `[1000, 3000]` | Extra queries, in ms after `start()`. |
|
|
672
|
+
| `refreshMs` | `number` | `60000` | Query interval after the follow-ups. |
|
|
673
|
+
| `expireCheckMs` | `number` | `1000` | How often expired records are dropped (and `deviceDown` emitted). |
|
|
674
|
+
| `interfaceCheckMs` | `number` | `10000` | How often the interface list is re-read. |
|
|
675
|
+
| `resumeGapMs` | `number` | `3 * interfaceCheckMs` | A check this much later than due means the machine slept; sockets are then replaced. |
|
|
676
|
+
|
|
677
|
+
##### `CastDiscoveryEvents`
|
|
678
|
+
|
|
679
|
+
| Event | Payload |
|
|
680
|
+
|---|---|
|
|
681
|
+
| `deviceUp` | `CastDevice`: a new device. |
|
|
682
|
+
| `deviceChanged` | `CastDevice`: a known device's details changed. |
|
|
683
|
+
| `deviceDown` | `CastDevice`: a device's records expired or it said goodbye. |
|
|
684
|
+
| `socketError` | `(iface: NetworkInterfaceInfo, error: Error)` |
|
|
685
|
+
|
|
686
|
+
#### Other discovery exports
|
|
687
|
+
|
|
688
|
+
| Export | Description |
|
|
689
|
+
|---|---|
|
|
690
|
+
| `listIPv4Interfaces(nets?)` | External IPv4 interfaces: not internal, not link-local (`169.254.`), one entry per address. `nets` defaults to `os.networkInterfaces()`. |
|
|
691
|
+
| `listMdnsInterfaces(nets?)` | `listIPv4Interfaces` plus one IPv6 link-local entry per adapter (`family: "IPv6"`, with its `scopeId`); an IPv4 entry gets the `scopeId` of the same adapter's link-local address. |
|
|
692
|
+
| `NetworkInterfaceInfo` | `{ name: string, address: string, family?: "IPv4" \| "IPv6", scopeId?: number }` (IPv4 when `family` is absent) |
|
|
693
|
+
| `MdnsSocket`, `MdnsSocketHandlers`, `OpenMdnsSocket` | The socket abstraction: `send(packet)` and `close()`; handlers `message(packet, from)` and `error(error)`. |
|
|
694
|
+
| `openUdpMdnsSocket(iface, handlers, options?)` | The default `OpenMdnsSocket`: multicast on port 5353 if it can bind, else a unicast socket on an ephemeral port; an IPv6 interface uses `ff02::fb` on its scope. |
|
|
695
|
+
| `MDNS_GROUP`, `MDNS_GROUP_V6`, `MDNS_PORT` | `"224.0.0.251"`, `"ff02::fb"` and `5353`. |
|
|
696
|
+
| `CastDeviceCache` | A pure, time-explicit cache that joins records into devices. `new CastDeviceCache(serviceName?)`, `ingest(records, now, source?): CacheChange`, `expire(now): CacheChange`, `dropSource(source): CacheChange` (forget what one interface heard), `devices(): CastDevice[]`. |
|
|
697
|
+
| `CacheChange` | `{ added, updated, removed }`, each a `CastDevice[]`. |
|
|
698
|
+
| `CastDevice` | See [`CastDevice`](#castdevice). |
|
|
699
|
+
| `decodeDnsPacket(buf)` | Parses a DNS packet into a `DnsPacket`. Throws `DnsFormatError` if it is malformed or truncated. |
|
|
700
|
+
| `encodeMdnsQuery(name, type, opts?)` | A one-question mDNS query as a `Buffer`. `opts.unicastResponse` sets the unicast-response bit. Throws `RangeError` for an empty or oversized label or name. |
|
|
701
|
+
| `formatIPv6(bytes)` | 16 bytes to an RFC 5952 string. |
|
|
702
|
+
| `RecordType` | `{ A: 1, PTR: 12, TXT: 16, AAAA: 28, SRV: 33 }` |
|
|
703
|
+
| `DnsFormatError`, `DnsQuestion`, `DnsRecord`, `DnsPacket` | DNS types. `DnsRecord` is a union discriminated by `type` (`A`, `AAAA`, `PTR`, `TXT`, `SRV`, `UNKNOWN`). |
|
|
704
|
+
| `isPubliclyRoutable(address)`, `isLoopback(address)` | Ports of `net::IPAddress::IsPubliclyRoutable` and `IsLoopback` (`net/base/ip_address.cc`), byte for byte: an IPv4-mapped IPv6 address is judged by its IPv4 part, a string that is not an IP address counts as publicly routable. |
|
|
705
|
+
| `isCastAddressAllowed(address, allowAllIps?)` | Whether a Cast channel may be opened to `address`: neither publicly routable nor loopback, unless `allowAllIps` (Chrome's `CastMediaSinkServiceImpl::OpenChannel` rule). |
|
|
706
|
+
| `parseIpBytes(address)` | An IPv4 or IPv6 literal (zone ignored, brackets allowed) as its 4 or 16 bytes, or `null`. |
|
|
707
|
+
|
|
708
|
+
### Protocol
|
|
709
|
+
|
|
710
|
+
The Cast v2 wire format.
|
|
711
|
+
|
|
712
|
+
| Export | Description |
|
|
713
|
+
|---|---|
|
|
714
|
+
| `CastMessage` | `{ protocolVersion: 0, sourceId, destinationId, namespace, payloadType, payloadUtf8?, payloadBinary? }` |
|
|
715
|
+
| `PayloadType` | `{ STRING: 0, BINARY: 1 }`, also a type. |
|
|
716
|
+
| `encodeCastMessage(msg)` | `CastMessage` to protobuf bytes (`Buffer`). Throws `TypeError` for an inconsistent payload. |
|
|
717
|
+
| `decodeCastMessage(bytes)` | Protobuf bytes to a `CastMessage`. Throws `CastProtocolError` if invalid. Unknown fields are skipped. |
|
|
718
|
+
| `frame(body)` | Adds the 4-byte big-endian length prefix. Throws `RangeError` over `MAX_MESSAGE_SIZE`. |
|
|
719
|
+
| `FrameDecoder` | `push(chunk): Buffer[]` returns every complete body from a chunked stream; `bufferedBytes` is the incomplete amount. Throws `CastProtocolError` on an oversized length and is unusable afterwards. |
|
|
720
|
+
| `MAX_MESSAGE_SIZE` | `65536` bytes. |
|
|
721
|
+
| `DeviceAuthMessage`, `AuthResponse` | A decoded device-authentication message (`response` or `error`) and its response parts (`signature`, `clientAuthCertificate`, `intermediateCertificates`, `signatureAlgorithm`, `senderNonce`, `hashAlgorithm`, `crl`). |
|
|
722
|
+
| `encodeAuthChallenge(challenge)`, `encodeAuthResponse(response)`, `encodeAuthError(errorType)`, `decodeDeviceAuthMessage(bytes)` | Encode and decode the `deviceauth` payloads (`encodeAuthResponse` and `encodeAuthError` are for tests and fake receivers). `decodeDeviceAuthMessage` throws `CastProtocolError` if invalid. |
|
|
723
|
+
| `SignatureAlgorithm`, `HashAlgorithm`, `AuthErrorType` | The enums of `cast_channel.proto` (`HashAlgorithm`: `SHA1` 0, `SHA256` 1), also types. |
|
|
724
|
+
| `CastProtocolError` | A message or frame broke the protocol. |
|