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