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