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
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Building your own device picker
|
|
2
|
+
|
|
3
|
+
electron-cast ships no picker UI: you give `createCastManager` a `selectDevice` function and show whatever you like.
|
|
4
|
+
|
|
5
|
+
In Chrome the user picks a device in the Cast dialog, a piece of browser UI. Electron has none, so the page's own cast
|
|
6
|
+
button ends up calling your function. This guide goes from the contract to a picker window that updates while it is open.
|
|
7
|
+
|
|
8
|
+
## The contract
|
|
9
|
+
|
|
10
|
+
```ts no-check
|
|
11
|
+
selectDevice(devices: CastDevice[], request: CastRequestInfo, picker: DevicePickerContext): Promise<DeviceChoice>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- `devices` is the list at the moment the page asked, already filtered to devices that can serve the request. In the
|
|
15
|
+
default mode those are the listed devices (open, authenticated channel) that said they have the page's receiver app,
|
|
16
|
+
as in Chrome.
|
|
17
|
+
- `request` says who is asking: `origin` (show it), `appId`, `capabilities`, `senderId`, and `session` when this sender is
|
|
18
|
+
already casting that app, with `{ sessionId, deviceId }`.
|
|
19
|
+
- `picker` streams devices that appear while your UI is open, and an `AbortSignal` that fires when the request no
|
|
20
|
+
longer waits for an answer. A function that declares only the first two parameters keeps working.
|
|
21
|
+
- Resolve a `CastDevice` to cast to it, `null` when the user cancels, or `"stop"` to stop `request.session`. Choosing the
|
|
22
|
+
device that `request.session` is already on returns the existing session instead of relaunching.
|
|
23
|
+
- A rejection fails the request with `session_error`. The time your UI is open does not count against the page's launch
|
|
24
|
+
timeout.
|
|
25
|
+
|
|
26
|
+
Two rules that follow from the [security model](../../SECURITY.md#user-gesture): this is the real consent step, so always
|
|
27
|
+
show a prompt, show `request.origin`, and never auto-pick; and device names come from the network, so render them as
|
|
28
|
+
plain text, never as HTML.
|
|
29
|
+
|
|
30
|
+
If no device matches when the page asks, the request fails with `receiver_unavailable` before `selectDevice` is called.
|
|
31
|
+
|
|
32
|
+
## The smallest picker: a native menu
|
|
33
|
+
|
|
34
|
+
The [README](../../README.md#quick-start) shows a `Menu` picker. It is enough to start with, and it has one subtlety:
|
|
35
|
+
a menu's close callback can run before the clicked item's handler, so a close only counts as a cancel after a short
|
|
36
|
+
grace period (the `setTimeout(..., 100)`).
|
|
37
|
+
|
|
38
|
+
## A picker window with live updates
|
|
39
|
+
|
|
40
|
+
Devices are listed over several seconds (mDNS answers, then a channel and device authentication per device), so a picker
|
|
41
|
+
that only shows the list from the moment of the click can look empty. This one re-renders as devices come and go. It follows what Chrome's dialog does (it registers a sinks
|
|
42
|
+
observer while it is open) through the third argument.
|
|
43
|
+
|
|
44
|
+
Main process:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { BrowserWindow, ipcMain } from "electron";
|
|
48
|
+
import {
|
|
49
|
+
createCastManager,
|
|
50
|
+
type CastDevice,
|
|
51
|
+
type CastRequestInfo,
|
|
52
|
+
type DeviceChoice,
|
|
53
|
+
type DevicePickerContext,
|
|
54
|
+
} from "electron-cast/main";
|
|
55
|
+
|
|
56
|
+
// Speakers and TVs first, then groups, each alphabetical.
|
|
57
|
+
const order = (a: CastDevice, b: CastDevice) => Number(a.isGroup) - Number(b.isGroup) || a.name.localeCompare(b.name);
|
|
58
|
+
|
|
59
|
+
function pickDevice(devices: CastDevice[], request: CastRequestInfo, picker: DevicePickerContext): Promise<DeviceChoice> {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
const known = new Map(devices.map((d) => [d.id, d]));
|
|
62
|
+
const win = new BrowserWindow({
|
|
63
|
+
width: 320,
|
|
64
|
+
height: 420,
|
|
65
|
+
resizable: false,
|
|
66
|
+
webPreferences: { preload: "/absolute/path/to/picker-preload.cjs", sandbox: true, contextIsolation: true },
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const render = () => {
|
|
70
|
+
if (win.isDestroyed() || win.webContents.isLoading()) return;
|
|
71
|
+
win.webContents.send("picker:state", {
|
|
72
|
+
origin: request.origin,
|
|
73
|
+
canStop: request.session !== undefined,
|
|
74
|
+
devices: [...known.values()].sort(order).map(({ id, name, model, isGroup }) => ({ id, name, model, isGroup })),
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
let settled = false;
|
|
79
|
+
const settle = (choice: DeviceChoice) => {
|
|
80
|
+
if (settled) return;
|
|
81
|
+
settled = true;
|
|
82
|
+
ipcMain.removeListener("picker:choose", onChoose);
|
|
83
|
+
stopWatching();
|
|
84
|
+
if (!win.isDestroyed()) win.close();
|
|
85
|
+
resolve(choice);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// The renderer sends a device id, "stop" or null. Only this window's messages count, and an id has to be one we listed.
|
|
89
|
+
const onChoose = (event: { sender: unknown }, choice: unknown) => {
|
|
90
|
+
if (event.sender !== win.webContents) return;
|
|
91
|
+
if (choice === null) settle(null);
|
|
92
|
+
else if (choice === "stop" && request.session !== undefined) settle("stop");
|
|
93
|
+
else if (typeof choice === "string") {
|
|
94
|
+
const device = known.get(choice);
|
|
95
|
+
if (device !== undefined) settle(device);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
ipcMain.on("picker:choose", onChoose);
|
|
99
|
+
|
|
100
|
+
// Called now with the current list, then whenever a device appears, changes or goes.
|
|
101
|
+
const stopWatching = picker.registerMediaSinksObserver({
|
|
102
|
+
onSinksUpdated(sinks) {
|
|
103
|
+
known.clear();
|
|
104
|
+
for (const sink of sinks) known.set(sink.device.id, sink.device);
|
|
105
|
+
render();
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
win.on("closed", () => settle(null)); // the user closed the window
|
|
110
|
+
picker.signal.addEventListener("abort", () => settle(null)); // the page went away, or the manager was disposed
|
|
111
|
+
win.webContents.once("did-finish-load", render);
|
|
112
|
+
void win.loadFile("picker.html");
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const cast = createCastManager({
|
|
117
|
+
ipcMain,
|
|
118
|
+
allowOrigin: (origin) => origin === "https://music.youtube.com",
|
|
119
|
+
selectDevice: pickDevice,
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The picker's preload exposes two calls and nothing else:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { contextBridge, ipcRenderer } from "electron";
|
|
127
|
+
|
|
128
|
+
contextBridge.exposeInMainWorld("picker", {
|
|
129
|
+
onState: (listener: (state: unknown) => void) => ipcRenderer.on("picker:state", (_event, state) => listener(state)),
|
|
130
|
+
choose: (choice: string | null) => ipcRenderer.send("picker:choose", choice),
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
And `picker.html` draws the list with `textContent`:
|
|
135
|
+
|
|
136
|
+
```html
|
|
137
|
+
<ul id="devices"></ul>
|
|
138
|
+
<button id="stop" hidden>Stop casting</button>
|
|
139
|
+
<button id="cancel">Cancel</button>
|
|
140
|
+
<script>
|
|
141
|
+
const list = document.getElementById("devices");
|
|
142
|
+
window.picker.onState((state) => {
|
|
143
|
+
list.replaceChildren(
|
|
144
|
+
...state.devices.map((d) => {
|
|
145
|
+
const li = document.createElement("li");
|
|
146
|
+
li.textContent = `${d.name} (${d.model})`; // never innerHTML: names come from the network
|
|
147
|
+
li.onclick = () => window.picker.choose(d.id);
|
|
148
|
+
return li;
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
document.getElementById("stop").hidden = !state.canStop;
|
|
152
|
+
});
|
|
153
|
+
document.getElementById("stop").onclick = () => window.picker.choose("stop");
|
|
154
|
+
document.getElementById("cancel").onclick = () => window.picker.choose(null);
|
|
155
|
+
</script>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Notes:
|
|
159
|
+
|
|
160
|
+
- `registerMediaSinksObserver` on the picker context lists only devices that can serve this request, the same way `devices`
|
|
161
|
+
was filtered, and it is dropped when `picker.signal` aborts. Its list replaces yours; `sink.device` is the `CastDevice`
|
|
162
|
+
to resolve with.
|
|
163
|
+
- Resolving the window's `closed` event as a cancel keeps the page from waiting on a window the user dismissed.
|
|
164
|
+
- A page can only have one request pending: a second `start` is refused until the first resolves, so you never need two
|
|
165
|
+
pickers for one frame. Windows can each have one.
|
|
166
|
+
- A request that is cancelled from outside (the page navigated, its window closed, the manager was disposed) aborts
|
|
167
|
+
`picker.signal`, so the picker never outlives the request it answers.
|
|
168
|
+
|
|
169
|
+
## Icons and labels
|
|
170
|
+
|
|
171
|
+
A `MediaSink` (from the observer) carries `iconType`, following Chrome's `GetCastSinkIconType`: a device with video out is
|
|
172
|
+
`"cast"`, otherwise a multizone group is `"cast_audio_group"`, otherwise `"cast_audio"`. Use it to pick an icon, or work
|
|
173
|
+
it out from `CastDevice.capabilities` and `isGroup` yourself. See [Audio-only devices and speaker
|
|
174
|
+
groups](audio-and-groups.md).
|
|
175
|
+
|
|
176
|
+
Next: [Rejoining a session after a restart](restart-rejoin.md).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Guides
|
|
2
|
+
|
|
3
|
+
Recipes for the things most apps do with electron-cast after the [first cast works](../GETTING-STARTED.md).
|
|
4
|
+
|
|
5
|
+
| Guide | Use it when |
|
|
6
|
+
|---|---|
|
|
7
|
+
| [Building your own device picker](device-picker.md) | You want a window instead of a menu, with devices that appear while it is open |
|
|
8
|
+
| [Rejoining a session after a restart](restart-rejoin.md) | The app quits while casting and the user expects the cast to still be theirs when it comes back |
|
|
9
|
+
| [Multiple windows and iframes](windows-and-iframes.md) | More than one window or view casts, or an embedded player in an iframe does |
|
|
10
|
+
| [Custom receivers and the Default Media Receiver](custom-receivers.md) | You choose which receiver app plays, or talk to your own receiver |
|
|
11
|
+
| [Audio-only devices and speaker groups](audio-and-groups.md) | Your picker has to tell a TV, a speaker and a group apart |
|
|
12
|
+
| [Device authentication](device-authentication.md) | A device is refused, or you need to cast to a receiver that is not Google-certified |
|
|
13
|
+
| [Using CastClient directly](low-level-client.md) | You want discovery, the Cast v2 channel or the protocol code without Electron |
|
|
14
|
+
| [Testing your app](testing.md) | You want tests that need neither a Cast device nor a network |
|
|
15
|
+
|
|
16
|
+
Each guide checks its TypeScript against the package's own types (`npm run docs:check`), so the snippets compile as
|
|
17
|
+
written unless marked as fragments. What a guide says was tested, was tested; where it says otherwise, it was not.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Using CastClient directly
|
|
2
|
+
|
|
3
|
+
Every layer of electron-cast is exported from the package root and runs in plain Node, so you can find devices, open the Cast
|
|
4
|
+
v2 channel and send messages with no Electron and no page.
|
|
5
|
+
|
|
6
|
+
Use this for tools, scripts, a headless controller, or to see what the library does under the Electron layer. The layers, from
|
|
7
|
+
the bottom: the protocol (`encodeCastMessage`, `frame`, `FrameDecoder`), discovery (`CastDiscovery`), the client (`CastClient`)
|
|
8
|
+
and the session service (`CastSessionService`). Import from the root, and **not** from a sandboxed preload (the root needs
|
|
9
|
+
Node's `tls` and `dgram`).
|
|
10
|
+
|
|
11
|
+
## Find a device
|
|
12
|
+
|
|
13
|
+
`CastDiscovery` sends mDNS queries for `_googlecast._tcp.local` on every external IPv4 interface and one IPv6 link-local
|
|
14
|
+
address per adapter, and turns the answers into `CastDevice`s. It only asks: it never advertises or answers.
|
|
15
|
+
|
|
16
|
+
`deviceUp`, `deviceChanged` and `deviceDown` report devices as they come and go; `socketError` reports an interface whose
|
|
17
|
+
socket failed while the others carry on. The repository's [examples/discover.ts](../../examples/discover.ts) prints all of
|
|
18
|
+
them (`node examples/discover.ts 15`, on a Node that runs TypeScript, such as 22.18 or 24). To list what discovery sees from
|
|
19
|
+
an installed package, see [Troubleshooting](../TROUBLESHOOTING.md#list-what-discovery-sees).
|
|
20
|
+
|
|
21
|
+
## Connect and ask a device what it is running
|
|
22
|
+
|
|
23
|
+
`CastClient` is a single-use client: one TLS connection to one receiver. `connect()` opens TLS, runs the device
|
|
24
|
+
authentication challenge and sends CONNECT to the platform receiver. After `close()` or a failure, make a new one.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { once } from "node:events";
|
|
28
|
+
import { CastAuthError, CastClient, CastDiscovery, type CastDevice } from "electron-cast";
|
|
29
|
+
|
|
30
|
+
const discovery = new CastDiscovery();
|
|
31
|
+
try {
|
|
32
|
+
await discovery.start();
|
|
33
|
+
// A device already known, or the first one to answer within ten seconds.
|
|
34
|
+
const [device] = discovery.devices().length > 0
|
|
35
|
+
? [discovery.devices()[0] as CastDevice]
|
|
36
|
+
: ((await once(discovery, "deviceUp", { signal: AbortSignal.timeout(10_000) })) as [CastDevice]);
|
|
37
|
+
const client = new CastClient({ host: device.host, port: device.port });
|
|
38
|
+
client.on("close", (error) => console.log("closed", error?.message ?? "on purpose"));
|
|
39
|
+
try {
|
|
40
|
+
await client.connect();
|
|
41
|
+
console.log(device.name, client.deviceAuth); // { policy, hashAlgorithm, nonceEchoed, usedFallbackCrl, revocationChecked }
|
|
42
|
+
const status = await client.getStatus();
|
|
43
|
+
console.log(status.applications.map((a) => a.displayName), status.volume);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error instanceof CastAuthError) console.error("not a Google-certified device:", error.reason);
|
|
46
|
+
else throw error;
|
|
47
|
+
} finally {
|
|
48
|
+
client.close();
|
|
49
|
+
}
|
|
50
|
+
} finally {
|
|
51
|
+
discovery.stop();
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A connection stays up by heartbeat: the client pings every 5 s and fails the connection after 10 s with no traffic
|
|
56
|
+
(`heartbeatIntervalMs`, `heartbeatTimeoutMs`), emitting `close` with an error. Pass `verifyDevice: false` for a receiver that is
|
|
57
|
+
not Google-certified ([why that is a security decision](device-authentication.md)).
|
|
58
|
+
|
|
59
|
+
## Launch an app and message it
|
|
60
|
+
|
|
61
|
+
An app runs under its own **transport id**. Open a virtual connection to it, then message it on its namespaces. A
|
|
62
|
+
`CastClient` method that expects a reply (`request`, `getStatus`, `launch`, `stop`, `setVolume`) resolves with the matching
|
|
63
|
+
reply and rejects with `CastRequestError` for an error reply or `CastTimeoutError`:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { CastClient, type CastDevice } from "electron-cast";
|
|
67
|
+
|
|
68
|
+
const MEDIA = "urn:x-cast:com.google.cast.media";
|
|
69
|
+
|
|
70
|
+
export async function playOnDefaultReceiver(device: CastDevice, url: string): Promise<void> {
|
|
71
|
+
const client = new CastClient({ host: device.host, port: device.port });
|
|
72
|
+
await client.connect();
|
|
73
|
+
try {
|
|
74
|
+
const app = await client.launch("CC1AD845"); // the Default Media Receiver
|
|
75
|
+
client.connectTransport(app.transportId);
|
|
76
|
+
client.on("message", (message) => {
|
|
77
|
+
if (message.namespace === MEDIA) console.log("media:", message.data);
|
|
78
|
+
});
|
|
79
|
+
await client.request(MEDIA, app.transportId, {
|
|
80
|
+
type: "LOAD",
|
|
81
|
+
autoplay: true,
|
|
82
|
+
media: { contentId: url, contentType: "video/mp4", streamType: "BUFFERED" },
|
|
83
|
+
});
|
|
84
|
+
} finally {
|
|
85
|
+
// Leave the app running on the device; client.stop(app.sessionId) would end it.
|
|
86
|
+
client.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`client.send(namespace, destinationId, payload)` sends without waiting (a string as is, an object as JSON, a `Uint8Array` as a
|
|
92
|
+
binary payload); `message` events deliver everything on any namespace except heartbeat and connection control.
|
|
93
|
+
|
|
94
|
+
## Below the client
|
|
95
|
+
|
|
96
|
+
- `encodeCastMessage`, `decodeCastMessage`, `frame` and `FrameDecoder` are the wire format: a 4-byte big-endian length, then
|
|
97
|
+
a protobuf `CastMessage`, at most 65,536 bytes ([protocol notes](../DESIGN.md#protocol-layer-srcprotocol)).
|
|
98
|
+
- `CastDeviceCache`, `decodeDnsPacket` and `encodeMdnsQuery` are the pure mDNS pieces, usable with your own sockets
|
|
99
|
+
(`CastDiscovery`'s `openSocket` option takes your own socket factory, which is how the tests run without a network).
|
|
100
|
+
- `CastSessionService` is the session logic behind `createCastManager`, with no Electron dependency: give it a
|
|
101
|
+
`DeviceSource`, a `createClient`, a `selectDevice` and an `emit`, and call `handle(sender, method, params)`.
|
|
102
|
+
|
|
103
|
+
Every export is in the [API reference](../API.md#electron-cast-root).
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Rejoining a session after a restart
|
|
2
|
+
|
|
3
|
+
How to let a user quit or crash your app while casting and get the same cast back when it starts again, the way Chrome
|
|
4
|
+
lets a page rejoin a session by id.
|
|
5
|
+
|
|
6
|
+
## Why the app has to help
|
|
7
|
+
|
|
8
|
+
A cast session lives on the device, not in your app. When your app quits, the receiver app keeps playing. After a
|
|
9
|
+
**page reload** electron-cast rejoins for you (auto-join: the session stays open, parked, and the next page of the
|
|
10
|
+
same frame joins it, as in Chrome). After an **app restart** it cannot, for the same reason Chrome cannot:
|
|
11
|
+
|
|
12
|
+
- Chrome's auto-join only joins sessions this browser run started (`FindActivityForAutoJoin` skips activities that are
|
|
13
|
+
not local), and electron-cast follows.
|
|
14
|
+
- electron-cast persists nothing. Chrome keeps no file either: its Media Router learns what each device runs from the
|
|
15
|
+
device's own status (`CastSessionTracker`).
|
|
16
|
+
|
|
17
|
+
What Chrome *does* allow is joining a known session by id: `PresentationRequest.reconnect("cast-session_<id>")`, which
|
|
18
|
+
checks only that the receiver app matches and that this client is not already connected (`AppActivity::CanJoinSession`).
|
|
19
|
+
Google's SDK issues that call from `chrome.cast.requestSessionById(id)`. So the recipe is the one Chrome gives a page:
|
|
20
|
+
|
|
21
|
+
1. While casting, the app stores the session id (Google's SDK exposes it as `session.sessionId`).
|
|
22
|
+
2. At the next start, the page calls `chrome.cast.requestSessionById(id)` once the SDK is ready.
|
|
23
|
+
3. electron-cast already knows which device runs that session (its session tracker follows every device's receiver
|
|
24
|
+
status, as Chrome's does), joins it over that device's channel and returns it. The SDK hands it to the
|
|
25
|
+
`sessionListener` you gave `chrome.cast.initialize`, exactly like a session the user just started.
|
|
26
|
+
|
|
27
|
+
Nothing to configure in electron-cast. `allowOrigin` still applies first; no origin check beyond that is made, because
|
|
28
|
+
the session id acts as the capability, as in Chrome ([SECURITY.md](../../SECURITY.md#scoping-of-sessions-and-messages)).
|
|
29
|
+
|
|
30
|
+
## The app side
|
|
31
|
+
|
|
32
|
+
The main process owns the stored id, so it survives anything the page does. Write it to disk when it changes, not on
|
|
33
|
+
quit: an app that is killed never reaches a quit handler.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { app, ipcMain } from "electron";
|
|
37
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
38
|
+
import { join } from "node:path";
|
|
39
|
+
|
|
40
|
+
interface SavedSession { sessionId: string; appId: string }
|
|
41
|
+
|
|
42
|
+
const file = join(app.getPath("userData"), "cast-session.json");
|
|
43
|
+
const ORIGIN = "https://music.youtube.com"; // the origin allowOrigin admits
|
|
44
|
+
|
|
45
|
+
let saved: SavedSession | null = null;
|
|
46
|
+
try {
|
|
47
|
+
saved = JSON.parse(readFileSync(file, "utf8")) as SavedSession | null;
|
|
48
|
+
} catch {
|
|
49
|
+
// none yet
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The page asks once per app start; later asks get null, so a page reload does not rejoin a session the user ended.
|
|
53
|
+
let taken = false;
|
|
54
|
+
ipcMain.handle("cast-app:take-saved-session", (event) => {
|
|
55
|
+
if (event.senderFrame?.origin !== ORIGIN || taken) return null;
|
|
56
|
+
taken = true;
|
|
57
|
+
return saved;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
ipcMain.on("cast-app:session-changed", (event, session: unknown) => {
|
|
61
|
+
if (event.senderFrame?.origin !== ORIGIN) return;
|
|
62
|
+
let next: SavedSession | null = null;
|
|
63
|
+
if (typeof session === "object" && session !== null) {
|
|
64
|
+
const { sessionId, appId } = session as Record<string, unknown>;
|
|
65
|
+
if (typeof sessionId !== "string" || sessionId === "" || typeof appId !== "string") return;
|
|
66
|
+
next = { sessionId, appId };
|
|
67
|
+
}
|
|
68
|
+
saved = next;
|
|
69
|
+
writeFileSync(file, JSON.stringify(saved));
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Expose both calls from the preload next to `installCastBridge`:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { contextBridge, ipcRenderer } from "electron";
|
|
77
|
+
|
|
78
|
+
contextBridge.exposeInMainWorld("castApp", {
|
|
79
|
+
takeSavedSession: () => ipcRenderer.invoke("cast-app:take-saved-session"),
|
|
80
|
+
sessionChanged: (session: { sessionId: string; appId: string } | null) => ipcRenderer.send("cast-app:session-changed", session),
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## The page side
|
|
85
|
+
|
|
86
|
+
If you write the page, wire it into the SDK calls you already make. The three jobs are: report a session when the SDK
|
|
87
|
+
adopts one, forget it only when the user ended it, and rejoin once at startup.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
declare const chrome: any;
|
|
91
|
+
declare const castApp: {
|
|
92
|
+
takeSavedSession(): Promise<{ sessionId: string; appId: string } | null>;
|
|
93
|
+
sessionChanged(session: { sessionId: string; appId: string } | null): void;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const APP_ID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
|
|
97
|
+
const JOIN_TIMEOUT_MS = 15_000;
|
|
98
|
+
let adopted = false;
|
|
99
|
+
|
|
100
|
+
// Every session the SDK hands you, started by the user or rejoined, arrives here.
|
|
101
|
+
function sessionListener(session: any): void {
|
|
102
|
+
adopted = true;
|
|
103
|
+
castApp.sessionChanged({ sessionId: session.sessionId, appId: session.appId });
|
|
104
|
+
session.addUpdateListener((isAlive: boolean) => {
|
|
105
|
+
// Forget it only when the user stopped the cast. A dropped connection (the app quitting or being killed) keeps it,
|
|
106
|
+
// so the next start rejoins.
|
|
107
|
+
if (!isAlive && session.status === chrome.cast.SessionStatus.STOPPED) castApp.sessionChanged(null);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
window.__onGCastApiAvailable = async (available: boolean) => {
|
|
112
|
+
if (!available) return;
|
|
113
|
+
const config = new chrome.cast.ApiConfig(
|
|
114
|
+
new chrome.cast.SessionRequest(APP_ID),
|
|
115
|
+
sessionListener,
|
|
116
|
+
() => {}, // receiver availability
|
|
117
|
+
chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED,
|
|
118
|
+
);
|
|
119
|
+
chrome.cast.initialize(config, () => {}, () => {});
|
|
120
|
+
|
|
121
|
+
const saved = await castApp.takeSavedSession();
|
|
122
|
+
if (saved === null) return;
|
|
123
|
+
// The SDK reports a failed join to no one, so a session that never arrives is how failure shows.
|
|
124
|
+
setTimeout(() => {
|
|
125
|
+
if (!adopted) castApp.sessionChanged(null);
|
|
126
|
+
}, JOIN_TIMEOUT_MS);
|
|
127
|
+
chrome.cast.requestSessionById(saved.sessionId);
|
|
128
|
+
};
|
|
129
|
+
declare global {
|
|
130
|
+
interface Window { __onGCastApiAvailable?: (available: boolean) => void }
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Why these choices:
|
|
135
|
+
|
|
136
|
+
- **Rejoin once, and give up.** A session that is gone (the device was restarted, someone else took the device, the
|
|
137
|
+
receiver app was stopped from a phone) makes the join fail with `NotFoundError`, and Google's SDK does not tell the page.
|
|
138
|
+
The timeout turns "nothing arrived" into "forget it", so the next start does not retry a dead id forever.
|
|
139
|
+
- **The device has to be listed first.** electron-cast answers from what each listed device's channel reports, so a join
|
|
140
|
+
attempted before the device's channel is open (a few seconds after `start()`) fails. Start the manager early (before
|
|
141
|
+
the page loads, as the worked example below does) and use a join timeout of several seconds. If your page loads very fast,
|
|
142
|
+
retry `requestSessionById` after receiver availability turns true instead of only once.
|
|
143
|
+
- **Do not save on every update.** Report on adoption and on stop; the session id does not change while it lives.
|
|
144
|
+
|
|
145
|
+
## A worked example: an app that does not control its page
|
|
146
|
+
|
|
147
|
+
This app loads `music.youtube.com`, whose own script drives
|
|
148
|
+
Google's SDK through `chrome.cast`. It does not control the page, so it wraps the SDK's
|
|
149
|
+
`chrome.cast.Session.prototype.addUpdateListener`: every session the page adopts, whether from the user's pick or from a
|
|
150
|
+
rejoin delivered to the page's session listener, gets an update listener, and that is the point where the app learns the
|
|
151
|
+
session id. It then:
|
|
152
|
+
|
|
153
|
+
- sends `{ sessionId, appId, deviceName }` to the main process, which keeps it in the app's persisted state and writes
|
|
154
|
+
it to disk at once (the app's normal state file lags by 30 seconds, which a killed app would never reach);
|
|
155
|
+
- forgets it only when `session.status` is `STOPPED`, so quitting or killing the app keeps it;
|
|
156
|
+
- at each start asks main for the saved session once, calls `chrome.cast.requestSessionById`, and clears the saved
|
|
157
|
+
session if none arrives within 15 seconds.
|
|
158
|
+
|
|
159
|
+
This was tested on Windows and on Linux (Ubuntu under WSL2), in dev and packaged builds: the app was force-killed
|
|
160
|
+
mid-song, restarted, and rejoined the same session on the same device with no picker; Stop casting cleared it. It has
|
|
161
|
+
not been tried on macOS.
|
|
162
|
+
|
|
163
|
+
## What happens in electron-cast
|
|
164
|
+
|
|
165
|
+
For the curious, `reconnect("cast-session_<id>")` reaches the session service's `joinRunningSession`
|
|
166
|
+
([API](../API.md#joinrunningsession)): a session this run already holds is joined at once; otherwise the session tracker,
|
|
167
|
+
which keeps what every device runs from the receiver status on its open channel, names the device, and the page joins
|
|
168
|
+
over that channel. Until then the session is listed as a non-local route, as in Chrome (`CastSessionTracker`, then
|
|
169
|
+
`CastActivityManager::AddNonLocalActivity`). The message flow is drawn in
|
|
170
|
+
[Architecture](../ARCHITECTURE.md#reconnect-and-rejoin).
|
|
171
|
+
|
|
172
|
+
`mode: "chromecast"` does not do this.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Testing your app
|
|
2
|
+
|
|
3
|
+
How to test code that uses electron-cast without a Cast device or a network: fakes for the manager, a fake receiver for the
|
|
4
|
+
client, and the smoke-test approach that runs the real package in a real Electron.
|
|
5
|
+
|
|
6
|
+
electron-cast takes everything it touches as a parameter, which is what makes this practical: Electron objects (`ipcMain`,
|
|
7
|
+
`contextBridge`, `ipcRenderer`), device discovery (`discovery`) and the connection to a device (`createClient`) can each be
|
|
8
|
+
replaced.
|
|
9
|
+
|
|
10
|
+
## Fakes for the manager
|
|
11
|
+
|
|
12
|
+
`createCastManager` accepts a `discovery` (anything with `devices()`, `start()`, `stop()` and `on`/`off` for `deviceUp`,
|
|
13
|
+
`deviceDown`, `deviceChanged`) and a `createClient` (anything shaped like `CastClientLike`). With those and a fake
|
|
14
|
+
`ipcMain`, a unit test drives the whole main-process path without Electron. As in Chrome, a device is offered only once
|
|
15
|
+
its channel is open and authenticated, after a random delay of up to 5 s and a 3 s quiet period; a test sets both to 0
|
|
16
|
+
with `sinks` and waits for `cast.settled()` after `cast.start()`:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import assert from "node:assert/strict";
|
|
20
|
+
import { EventEmitter } from "node:events";
|
|
21
|
+
import { test } from "node:test";
|
|
22
|
+
import type { CastClientLike, CastDevice, IpcMainLike, ReceiverApplication } from "electron-cast";
|
|
23
|
+
import { createCastManager } from "electron-cast/main";
|
|
24
|
+
|
|
25
|
+
const TV: CastDevice = {
|
|
26
|
+
id: "dev-tv", name: "Test TV", model: "Chromecast", host: "10.0.0.10", addresses: ["10.0.0.10"], port: 8009,
|
|
27
|
+
capabilities: 5, isGroup: false, statusText: "", instanceName: "Chromecast-dev-tv._googlecast._tcp.local", txt: {},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class FakeDiscovery extends EventEmitter {
|
|
31
|
+
devices(): CastDevice[] { return [TV]; }
|
|
32
|
+
async start(): Promise<void> {}
|
|
33
|
+
stop(): void {}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class FakeClient extends EventEmitter implements CastClientLike {
|
|
37
|
+
connected = false;
|
|
38
|
+
async connect(): Promise<void> { this.connected = true; }
|
|
39
|
+
close(): void { this.connected = false; this.emit("close"); }
|
|
40
|
+
send(): void {}
|
|
41
|
+
async launch(appId: string): Promise<ReceiverApplication> {
|
|
42
|
+
return { appId, displayName: "Test app", sessionId: "session-1", transportId: "transport-1", namespaces: [] };
|
|
43
|
+
}
|
|
44
|
+
async stop() { return { applications: [], volume: {} }; }
|
|
45
|
+
async setVolume() { return { applications: [], volume: {} }; }
|
|
46
|
+
async getStatus() { return { applications: [], volume: { level: 0.5, muted: false } }; }
|
|
47
|
+
connectTransport(): void {}
|
|
48
|
+
closeTransport(): void {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
test("a page can start a session on the picked device", async () => {
|
|
52
|
+
// A fake ipcMain keeps the handlers the manager registers, so the test can call them like Electron would.
|
|
53
|
+
const handlers = new Map<string, (event: unknown, ...args: unknown[]) => unknown>();
|
|
54
|
+
const ipcMain: IpcMainLike = {
|
|
55
|
+
handle: (channel, listener) => handlers.set(channel, listener as (event: unknown, ...args: unknown[]) => unknown),
|
|
56
|
+
removeHandler: (channel) => handlers.delete(channel),
|
|
57
|
+
on: () => {},
|
|
58
|
+
removeListener: () => {},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let asked: CastDevice[] = [];
|
|
62
|
+
const client = new FakeClient();
|
|
63
|
+
const cast = createCastManager({
|
|
64
|
+
ipcMain,
|
|
65
|
+
discovery: new FakeDiscovery(),
|
|
66
|
+
createClient: () => client,
|
|
67
|
+
sinks: { openDelayMaxMs: 0, reportDelayMs: 0 },
|
|
68
|
+
allowOrigin: (origin) => origin === "https://app.example.com",
|
|
69
|
+
selectDevice: async (devices) => ((asked = devices), devices[0] ?? null),
|
|
70
|
+
});
|
|
71
|
+
await cast.start();
|
|
72
|
+
await cast.settled(); // the fake device's channel is open and it is listed
|
|
73
|
+
|
|
74
|
+
// The "page": one webContents with a main frame at an allowed origin.
|
|
75
|
+
const sender = Object.assign(new EventEmitter(), { id: 1, send() {}, isDestroyed: () => false });
|
|
76
|
+
const event = { sender, senderFrame: { url: "https://app.example.com/index.html", origin: "https://app.example.com" } };
|
|
77
|
+
const call = handlers.get("electron-cast:call")!;
|
|
78
|
+
|
|
79
|
+
const init = (await call(event, "initialize", { appId: "CC1AD845", capabilities: [], autoJoinPolicy: "origin_scoped" })) as any;
|
|
80
|
+
assert.equal(init.value.available, true);
|
|
81
|
+
|
|
82
|
+
const started = (await call(event, "requestSession", { appId: "CC1AD845", capabilities: [] })) as any;
|
|
83
|
+
assert.equal(started.ok, true);
|
|
84
|
+
assert.equal(started.value.sessionId, "session-1");
|
|
85
|
+
assert.deepEqual(asked.map((d) => d.id), ["dev-tv"]);
|
|
86
|
+
|
|
87
|
+
await cast.dispose();
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
That exercises `mode: "chromecast"`'s channel (`electron-cast:call`), which is the shortest path to the session service. The
|
|
92
|
+
default presentation mode's channel is `electron-cast:presentation` and also needs `ipcMain.on` for
|
|
93
|
+
`electron-cast:presentation:send`; the repository's own tests for it
|
|
94
|
+
([test/electron/presentation-wiring.test.ts](../../test/electron/presentation-wiring.test.ts)) show the calls and fake frames
|
|
95
|
+
to copy. The `presentation: false` option serves only the `chromecast` channel and does not need `ipcMain.on`.
|
|
96
|
+
|
|
97
|
+
Things worth testing in your own code, all possible this way: that `allowOrigin` refuses what it should, that your picker
|
|
98
|
+
resolves `null` on cancel and a device otherwise, that a device whose client's `connect()` rejects (a `CastAuthError` or
|
|
99
|
+
`CastConnectionError`) never reaches your picker, and what your UI does when a client emits `close` mid-session (the channel
|
|
100
|
+
is reopened, and the device dropped if that fails).
|
|
101
|
+
|
|
102
|
+
## A fake receiver for `CastClient`
|
|
103
|
+
|
|
104
|
+
To test code that uses `CastClient` itself, run a fake receiver: a TLS server on `127.0.0.1` that speaks the real wire format
|
|
105
|
+
using the library's own codec (`frame`, `FrameDecoder`, `encodeCastMessage`, `decodeCastMessage`). The repository's
|
|
106
|
+
[test/client/fake-receiver.ts](../../test/client/fake-receiver.ts) is one, with a self-signed certificate from
|
|
107
|
+
[test/fixtures/tls](../../test/fixtures/tls/README.md); copy it into your project. Point a client at it with
|
|
108
|
+
`verifyDevice: false`, since a fake is not Google-certified:
|
|
109
|
+
|
|
110
|
+
```ts no-check
|
|
111
|
+
const receiver = new FakeReceiver();
|
|
112
|
+
const port = await receiver.listen();
|
|
113
|
+
const client = new CastClient({ host: "127.0.0.1", port, verifyDevice: false });
|
|
114
|
+
await client.connect();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
To exercise device authentication itself, the `deviceAuth` client option replaces the trust anchors and the clock, so a test
|
|
118
|
+
can mint its own chain ([test/client/device-auth.test.ts](../../test/client/device-auth.test.ts) does).
|
|
119
|
+
|
|
120
|
+
## The smoke-test approach: the real package in a real Electron
|
|
121
|
+
|
|
122
|
+
Unit tests with fakes prove your logic; they cannot prove that the preload bundles and runs sandboxed, that
|
|
123
|
+
`contextBridge.executeInMainWorld` works in your Electron, or that the page really sees the stand-in. electron-cast's own
|
|
124
|
+
`npm run smoke` does, and its method is the one to copy for your app:
|
|
125
|
+
|
|
126
|
+
- **Real:** a sandboxed preload built from `electron-cast/preload` (bundled with esbuild, as in [Getting
|
|
127
|
+
started](../GETTING-STARTED.md#2-the-preload)), the real `ipcMain`, `contextBridge` and `webContents`, and the built package
|
|
128
|
+
loaded by name (`electron-cast/main`), so the `exports` map and `dist/` are what get tested.
|
|
129
|
+
- **Faked:** only the network. `createCastManager({ ipcMain, discovery: new FakeDiscovery(), createClient: (d) => new FakeClient(d), ... })`
|
|
130
|
+
with a fake device, so there is no mDNS, no TLS and no device. The fake client answers `getStatus` and
|
|
131
|
+
`getAppAvailability`, which the manager asks over the channel it keeps open to the device.
|
|
132
|
+
- **A page with a real origin.** A `file:` page has an opaque origin, so the test registers a standard, secure custom scheme
|
|
133
|
+
(`protocol.registerSchemesAsPrivileged`) and loads a page from it, which `allowOrigin` can name.
|
|
134
|
+
- **A user gesture.** The page's code runs through `webContents.executeJavaScript(code, true)`, whose second argument makes
|
|
135
|
+
Electron treat it as a user gesture, so `navigator.userActivation.isActive` is true and `start()` is allowed. The same
|
|
136
|
+
call with `false` is how the smoke test checks that a start without a gesture is refused.
|
|
137
|
+
- **Assertions from inside the page:** that the stand-in exists, that availability resolves true for the fake device, that
|
|
138
|
+
`start()` reaches your `selectDevice`, and that the page's connection receives the session.
|
|
139
|
+
|
|
140
|
+
The files: [smoke/run.mjs](../../smoke/run.mjs) installs and finds an Electron and runs [smoke/main.mjs](../../smoke/main.mjs),
|
|
141
|
+
with its fakes in [smoke/fakes.mjs](../../smoke/fakes.mjs) and preload build in
|
|
142
|
+
[smoke/build-preloads.mjs](../../smoke/build-preloads.mjs). CI runs it on Electron 35, 40 and the latest stable, on Linux,
|
|
143
|
+
Windows and macOS; none of those runs touches a real device or network. To run it yourself:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
npm i --prefix smoke/.out/electron --no-package-lock electron@45
|
|
147
|
+
npm run smoke
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
(Electron is installed into its own folder because it is an optional peer dependency that npm skips in the repository's own
|
|
151
|
+
`node_modules`.)
|
|
152
|
+
|
|
153
|
+
## What no fake can tell you
|
|
154
|
+
|
|
155
|
+
Real networks, real firewalls, and real devices. Discovery on a VPN-laden Windows PC, a speaker group that renames itself, a
|
|
156
|
+
TV that drops off Wi-Fi: these need a device. When you probe one, [read-only is the rule](../../CONTRIBUTING.md#test-on-real-devices):
|
|
157
|
+
discover, connect, authenticate and read status; do not launch apps, change volume or stop playback on a device that is
|
|
158
|
+
not yours to disturb.
|
|
159
|
+
|
|
160
|
+
For a DIAL TV there is a command that does this for you: `npx electron-cast@next dial-test` discovers DIAL devices, reads
|
|
161
|
+
their description and app info, and opens and closes YouTube only if you say yes. It writes a scrubbed report to
|
|
162
|
+
paste into an issue ([README](../../README.md#test-a-dial-tv)).
|