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
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { CastTimeoutError } from "../client/index.js";
|
|
2
|
+
import { ObservedMap, combineSources, createPickerContext, createSinksObservers, } from "./manager-api.js";
|
|
3
|
+
import { CastSinkService } from "./sink-service.js";
|
|
4
|
+
import { CastSessionTracker } from "./session-tracker.js";
|
|
5
|
+
import { CastAppDiscovery } from "./app-discovery.js";
|
|
6
|
+
import { EventEmitter } from "node:events";
|
|
7
|
+
import { AccessCodeSinks, } from "./access-code.js";
|
|
2
8
|
/** Capability bit names in bit order: 1 video_out, 2 video_in, 4 audio_out, 8 audio_in, 32 multizone_group. */
|
|
3
9
|
export function capabilityNames(bits) {
|
|
4
10
|
const names = [];
|
|
@@ -14,6 +20,27 @@ export function capabilityNames(bits) {
|
|
|
14
20
|
names.push("multizone_group");
|
|
15
21
|
return names;
|
|
16
22
|
}
|
|
23
|
+
export { APP_AVAILABILITY_REFRESH_MS } from "./app-discovery.js";
|
|
24
|
+
/** How long a request that finds no DIAL sink yet waits for the devices' app info (the dialog of Chrome waits for as long as it is open). */
|
|
25
|
+
const DIAL_PROBE_WAIT_MS = 5000;
|
|
26
|
+
/** Resolves when `done()` is true after a device change, or after `ms`. */
|
|
27
|
+
function waitForDevices(source, ms, done) {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
if (done())
|
|
30
|
+
return resolve();
|
|
31
|
+
const finish = () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
source.off("deviceChanged", onChange);
|
|
34
|
+
resolve();
|
|
35
|
+
};
|
|
36
|
+
const onChange = () => {
|
|
37
|
+
if (done())
|
|
38
|
+
finish();
|
|
39
|
+
};
|
|
40
|
+
const timer = setTimeout(finish, ms);
|
|
41
|
+
source.on("deviceChanged", onChange);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
17
44
|
const CAPABILITY_BITS = {
|
|
18
45
|
video_out: 1,
|
|
19
46
|
video_in: 2,
|
|
@@ -22,6 +49,8 @@ const CAPABILITY_BITS = {
|
|
|
22
49
|
multizone_group: 32,
|
|
23
50
|
};
|
|
24
51
|
const DEFAULT_TIMEOUT_MS = 60000;
|
|
52
|
+
/** The caller id of a stop that comes from the main process, not from a page. */
|
|
53
|
+
const MAIN_CALLER = -1;
|
|
25
54
|
/** A request that must be reported as a specific chrome.cast error code. */
|
|
26
55
|
class MappedError extends Error {
|
|
27
56
|
code;
|
|
@@ -65,7 +94,30 @@ function parseRequestSession(params) {
|
|
|
65
94
|
const timeout = timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : timeoutMs;
|
|
66
95
|
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0)
|
|
67
96
|
return null;
|
|
68
|
-
return { appId, capabilities, timeoutMs: timeout };
|
|
97
|
+
return { appId, capabilities, timeoutMs: timeout, appAvailability: params.appAvailability === true };
|
|
98
|
+
}
|
|
99
|
+
/** `requestSession`'s parameters as a picker request with no DIAL app. */
|
|
100
|
+
function parseRequestSessionParams(params) {
|
|
101
|
+
const p = parseRequestSession(params);
|
|
102
|
+
return p === null ? null : { ...p, dialApp: null };
|
|
103
|
+
}
|
|
104
|
+
/** `requestSink` parameters: like `requestSession`'s, with the Cast app id optional and a DIAL app name. */
|
|
105
|
+
function parseRequestSink(params) {
|
|
106
|
+
if (!isRecord(params))
|
|
107
|
+
return null;
|
|
108
|
+
const { appId, dialApp, capabilities, timeoutMs } = params;
|
|
109
|
+
if (appId !== null && typeof appId !== "string")
|
|
110
|
+
return null;
|
|
111
|
+
if (dialApp !== null && typeof dialApp !== "string")
|
|
112
|
+
return null;
|
|
113
|
+
if (appId === null && dialApp === null)
|
|
114
|
+
return null;
|
|
115
|
+
if (!isStringArray(capabilities))
|
|
116
|
+
return null;
|
|
117
|
+
const timeout = timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : timeoutMs;
|
|
118
|
+
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0)
|
|
119
|
+
return null;
|
|
120
|
+
return { appId, dialApp, capabilities, timeoutMs: timeout, appAvailability: params.appAvailability === true };
|
|
69
121
|
}
|
|
70
122
|
function parseSessionId(params) {
|
|
71
123
|
if (!isRecord(params) || typeof params.sessionId !== "string")
|
|
@@ -143,16 +195,113 @@ function sameValue(a, b) {
|
|
|
143
195
|
export class CastSessionService {
|
|
144
196
|
options;
|
|
145
197
|
senders = new Map();
|
|
146
|
-
sessions = new
|
|
147
|
-
|
|
198
|
+
sessions = new ObservedMap((kind, rec) => this.notifySession(kind, rec));
|
|
199
|
+
sessionListeners = new Set();
|
|
200
|
+
sinks;
|
|
201
|
+
/** The devices with an open channel; the only devices the service offers or casts to. */
|
|
202
|
+
sinkService;
|
|
203
|
+
tracker = new CastSessionTracker();
|
|
204
|
+
accessCode;
|
|
205
|
+
lastRoutesKey = "";
|
|
206
|
+
/** Devices a page's launch is in flight on, with how many: the session it starts is the page's, not a non-local one. */
|
|
207
|
+
launching = new Map();
|
|
148
208
|
pendingRequests = new Map();
|
|
149
209
|
deviceListener = () => this.onDevicesChanged();
|
|
210
|
+
/** Which sinks have which apps, asked over their open channels (Chrome: CastAppDiscoveryServiceImpl). */
|
|
211
|
+
appDiscovery;
|
|
212
|
+
/** The availability observations that follow the DIAL sinks (see `watchDialSinks`). */
|
|
213
|
+
dialWatchers = new Set();
|
|
214
|
+
onDialSinks = () => {
|
|
215
|
+
for (const watcher of [...this.dialWatchers])
|
|
216
|
+
watcher();
|
|
217
|
+
};
|
|
150
218
|
disposed = false;
|
|
219
|
+
unobserveNetwork;
|
|
151
220
|
constructor(options) {
|
|
152
221
|
this.options = options;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
222
|
+
this.sinkService = new CastSinkService({
|
|
223
|
+
...options.sinks,
|
|
224
|
+
source: options.devices,
|
|
225
|
+
...(options.dial !== undefined ? { dial: options.dial.source } : {}),
|
|
226
|
+
createClient: options.createClient,
|
|
227
|
+
isClientInUse: (client) => [...this.sessions.values()].some((rec) => rec.client === client),
|
|
228
|
+
});
|
|
229
|
+
this.sinks = createSinksObservers(this.sinkService);
|
|
230
|
+
this.appDiscovery = new CastAppDiscovery(this.sinkService);
|
|
231
|
+
this.sinkService.on("deviceUp", this.deviceListener);
|
|
232
|
+
this.sinkService.on("deviceDown", this.deviceListener);
|
|
233
|
+
this.sinkService.on("deviceChanged", this.deviceListener);
|
|
234
|
+
this.sinkService.on("channelOpened", ({ device, client }) => {
|
|
235
|
+
// The tracker goes first so that, when a status ends a session, it no longer lists it by the time this one reports.
|
|
236
|
+
this.tracker.attach(device.id, client);
|
|
237
|
+
this.bindClient(client, device);
|
|
238
|
+
});
|
|
239
|
+
// MediaSinkServiceBase::AddOrUpdateSink tells CastAppDiscoveryServiceImpl at once, not after the 3 s report
|
|
240
|
+
this.sinkService.on("channelOpened", ({ device }) => this.appDiscovery.onSinkAddedOrUpdated(device));
|
|
241
|
+
this.sinkService.on("sinkRemoved", (device) => {
|
|
242
|
+
this.tracker.removeSink(device.id);
|
|
243
|
+
this.appDiscovery.onSinkRemoved(device);
|
|
244
|
+
});
|
|
245
|
+
this.tracker.on("sessionAddedOrUpdated", () => this.onTrackerChanged());
|
|
246
|
+
this.tracker.on("sessionRemoved", () => this.onTrackerChanged());
|
|
247
|
+
this.accessCode = new AccessCodeSinks(this.sinkService, {
|
|
248
|
+
current: () => this.mediaRoutes().map((r) => ({ id: r.id, sinkId: r.sinkId, isLocal: r.isLocal })),
|
|
249
|
+
observe: (listener) => this.observeSessions(listener),
|
|
250
|
+
}, options.accessCode);
|
|
251
|
+
// The two observers of Chrome's DiscoveryNetworkMonitor; the sink service asks for the current id first (`Start`).
|
|
252
|
+
const monitor = options.networkMonitor;
|
|
253
|
+
if (monitor !== undefined)
|
|
254
|
+
this.sinkService.onNetworksChanged(monitor.networkId());
|
|
255
|
+
this.unobserveNetwork = monitor?.observe((networkId) => {
|
|
256
|
+
this.sinkService.onNetworksChanged(networkId);
|
|
257
|
+
this.accessCode.onNetworksChanged(networkId);
|
|
258
|
+
}) ?? (() => { });
|
|
259
|
+
}
|
|
260
|
+
/** The devices that can be cast to: those with an open, authenticated channel (as Chrome lists sinks). */
|
|
261
|
+
devices() {
|
|
262
|
+
return this.sinkService.devices();
|
|
263
|
+
}
|
|
264
|
+
/** The devices as a {@link DeviceSource}: what `devices()` lists, with the events of that list changing. */
|
|
265
|
+
deviceSource() {
|
|
266
|
+
return this.sinkService;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Open channels to the discovered devices that have none now, without Chrome's random delay, and ask the sinks again
|
|
270
|
+
* about the apps being observed, by the refresh rules (`CastMediaRouteProvider::DiscoverSinksNow` ->
|
|
271
|
+
* `CastAppDiscoveryServiceImpl::Refresh`).
|
|
272
|
+
*/
|
|
273
|
+
discoverSinksNow() {
|
|
274
|
+
this.sinkService.discoverSinksNow();
|
|
275
|
+
this.appDiscovery.refresh();
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The client of the device's open channel, which every activity on the device shares (Chrome: one `CastSocket` per
|
|
279
|
+
* sink, used by `CastMessageHandler` for every session); undefined when the device is not a sink now.
|
|
280
|
+
*/
|
|
281
|
+
channelClient(deviceId) {
|
|
282
|
+
return this.sinkService.clientOf(deviceId);
|
|
283
|
+
}
|
|
284
|
+
/** Resolves when no channel is being opened and none is scheduled to be; for tests. */
|
|
285
|
+
settled(options) {
|
|
286
|
+
// no extra wait when nothing is being read: callers of settled() depend on how soon it resolves
|
|
287
|
+
const reading = this.accessCode.ready();
|
|
288
|
+
return reading === undefined ? this.sinkService.settled(options) : reading.then(() => this.sinkService.settled(options));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Add a device whose address the app knows, as Chrome adds the one an access code resolved to: a channel is opened and
|
|
292
|
+
* the device is listed like any other, remembered for `accessCode.deviceDuration`, then removed. Rejects with
|
|
293
|
+
* `AccessCodeCastDisabledError` unless access code casting is enabled.
|
|
294
|
+
*/
|
|
295
|
+
addSinkByAddress(device) {
|
|
296
|
+
return this.accessCode.addSinkByAddress(device);
|
|
297
|
+
}
|
|
298
|
+
/** Change `enabled` and `deviceDuration` while running, as Chrome applies its policies. */
|
|
299
|
+
configureAccessCode(settings) {
|
|
300
|
+
return this.accessCode.configure(settings);
|
|
301
|
+
}
|
|
302
|
+
/** The devices added by address that are remembered now. */
|
|
303
|
+
rememberedSinks() {
|
|
304
|
+
return this.accessCode.remembered();
|
|
156
305
|
}
|
|
157
306
|
/** Handle one bridge call; never throws or rejects. */
|
|
158
307
|
async handle(sender, method, params) {
|
|
@@ -166,8 +315,19 @@ export class CastSessionService {
|
|
|
166
315
|
return this.handleInitialize(sender, params);
|
|
167
316
|
case "requestSession":
|
|
168
317
|
return await this.handleRequestSession(sender, params);
|
|
318
|
+
case "requestSessionOnDevice":
|
|
319
|
+
// main only: the app's own UI chose the device (see the manager's startCasting)
|
|
320
|
+
return await this.handleRequestSession(sender, params, { presetDeviceId: isRecord(params) && typeof params.deviceId === "string" ? params.deviceId : "" });
|
|
169
321
|
case "joinSession":
|
|
170
|
-
return this.handleJoinSession(sender, params);
|
|
322
|
+
return this.handleJoinSession(sender, params, true);
|
|
323
|
+
case "requestSink":
|
|
324
|
+
// main only: the presentation handler's request with a `cast-dial:` source
|
|
325
|
+
return await this.handleRequestSession(sender, params, {
|
|
326
|
+
sink: true,
|
|
327
|
+
...(isRecord(params) && typeof params.deviceId === "string" ? { presetDeviceId: params.deviceId } : {}),
|
|
328
|
+
});
|
|
329
|
+
case "joinRunningSession":
|
|
330
|
+
return await this.handleJoinRunningSession(sender, params);
|
|
171
331
|
case "sendMessage":
|
|
172
332
|
return this.handleSendMessage(sender, params);
|
|
173
333
|
case "stopSession":
|
|
@@ -207,12 +367,15 @@ export class CastSessionService {
|
|
|
207
367
|
if (!rec.members.delete(senderId))
|
|
208
368
|
continue;
|
|
209
369
|
rec.parked.add(senderId);
|
|
370
|
+
this.notifySession("updated", rec);
|
|
210
371
|
}
|
|
211
372
|
}
|
|
212
373
|
forgetSender(senderId) {
|
|
213
374
|
const pending = this.pendingRequests.get(senderId);
|
|
214
|
-
if (pending !== undefined)
|
|
375
|
+
if (pending !== undefined) {
|
|
215
376
|
pending.cancelled.value = true;
|
|
377
|
+
pending.picker?.close();
|
|
378
|
+
}
|
|
216
379
|
this.pendingRequests.delete(senderId);
|
|
217
380
|
this.senders.delete(senderId);
|
|
218
381
|
}
|
|
@@ -221,23 +384,158 @@ export class CastSessionService {
|
|
|
221
384
|
if (this.disposed)
|
|
222
385
|
return;
|
|
223
386
|
this.disposed = true;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this.clients.clear();
|
|
230
|
-
for (const entry of entries)
|
|
231
|
-
entry.client.close();
|
|
387
|
+
this.unobserveNetwork();
|
|
388
|
+
this.sinks.dispose();
|
|
389
|
+
this.accessCode.dispose();
|
|
390
|
+
for (const pending of this.pendingRequests.values())
|
|
391
|
+
pending.picker?.close();
|
|
232
392
|
this.sessions.clear();
|
|
393
|
+
this.tracker.dispose();
|
|
394
|
+
this.appDiscovery.dispose();
|
|
395
|
+
this.sinkService.dispose();
|
|
233
396
|
this.senders.clear();
|
|
234
397
|
this.pendingRequests.clear();
|
|
235
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* What the device said about the app (`GET_APP_AVAILABILITY`), or undefined when it has to be asked: never asked, no
|
|
401
|
+
* answer last time, or "unavailable" longer than `APP_AVAILABILITY_REFRESH_MS` ago. This is
|
|
402
|
+
* CastAppDiscoveryServiceImpl::ShouldRefreshAppAvailability: kAvailable is kept, kUnavailable is asked again after
|
|
403
|
+
* kRefreshThreshold, kUnknown always.
|
|
404
|
+
*/
|
|
405
|
+
cachedAppAvailability(device, appId) {
|
|
406
|
+
return this.appDiscovery.cached(device.id, appId);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Ask the device whether it has the app (`GET_APP_AVAILABILITY`) unless a still-valid answer is cached. An error or
|
|
410
|
+
* no answer is not cached (Chrome's kUnknown): this resolves false, and the next call asks again. Callers that ask on
|
|
411
|
+
* every change (sinks observers) must pace themselves; see createSinksObservers.
|
|
412
|
+
*/
|
|
413
|
+
async checkAppAvailability(device, appId) {
|
|
414
|
+
// Asked over the device's kept-open channel (Chrome: the sink's CastSocket); no channel now is kUnknown. An answer
|
|
415
|
+
// about a channel that was replaced while it was asked is dropped, so it is unknown too.
|
|
416
|
+
await this.appDiscovery.request(device.id, appId);
|
|
417
|
+
return this.appDiscovery.availability(device.id, appId).result === "available";
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* A page's `PresentationRequest` availability (`getAvailability()`), as Chrome serves it: a
|
|
421
|
+
* `PresentationMediaSinksObserver` on the source, fed by `CastAppDiscoveryServiceImpl::StartObservingMediaSinks`, so
|
|
422
|
+
* a sink counts once it has said over its open channel that it has the app (`GET_APP_AVAILABILITY`). With `dialApp`
|
|
423
|
+
* (a `cast-dial:` source of the same request) the DIAL sinks that have that app for the page's origin count too, as
|
|
424
|
+
* Blink ORs the sources of a request; the DIAL sink service is asked to find out while the observation lasts.
|
|
425
|
+
* `available` is the first answer: at once from the answers that stand, else once the Cast sinks asked have answered
|
|
426
|
+
* (a sink that says yes answers it at once). `onchange` is called after that only when the answer changes, as
|
|
427
|
+
* `PresentationMediaSinksObserver::OnSinksReceived` skips a repeated one. `close()` stops the observation
|
|
428
|
+
* (`StopObservingMediaSinks`). A disallowed origin is never available.
|
|
429
|
+
*/
|
|
430
|
+
observeAppAvailability(sender, source, onchange) {
|
|
431
|
+
const allow = this.options.allowOrigin;
|
|
432
|
+
if (this.disposed || (allow !== undefined && !allow(sender.origin)))
|
|
433
|
+
return { available: Promise.resolve(false), close: () => { } };
|
|
434
|
+
const dialApp = source.dialApp;
|
|
435
|
+
const dial = dialApp !== undefined ? this.options.dial : undefined;
|
|
436
|
+
const castSource = { appIds: source.appIds, capabilities: source.capabilities };
|
|
437
|
+
const hasCast = castSource.appIds.length > 0;
|
|
438
|
+
const anyAvailable = () => (hasCast && this.appDiscovery.availableSinks(castSource).length > 0)
|
|
439
|
+
|| (dial !== undefined && dialApp !== undefined && dial.available(dialApp, sender.origin).length > 0);
|
|
440
|
+
let last;
|
|
441
|
+
let closed = false;
|
|
442
|
+
let first;
|
|
443
|
+
const available = new Promise((resolve) => (first = resolve));
|
|
444
|
+
const report = (value) => {
|
|
445
|
+
if (closed || value === last)
|
|
446
|
+
return;
|
|
447
|
+
const answered = last !== undefined;
|
|
448
|
+
last = value;
|
|
449
|
+
if (answered)
|
|
450
|
+
onchange(value);
|
|
451
|
+
else
|
|
452
|
+
first(value);
|
|
453
|
+
};
|
|
454
|
+
const stopCast = hasCast ? this.appDiscovery.startObserving(castSource, () => report(anyAvailable())) : () => { };
|
|
455
|
+
let stopDial = () => { };
|
|
456
|
+
if (dial !== undefined && dialApp !== undefined) {
|
|
457
|
+
const release = dial.monitor(dialApp, sender.origin) ?? (() => undefined);
|
|
458
|
+
// before the first answer only a yes is final; after it every change counts
|
|
459
|
+
const onDial = () => {
|
|
460
|
+
const value = anyAvailable();
|
|
461
|
+
if (last !== undefined || value)
|
|
462
|
+
report(value);
|
|
463
|
+
};
|
|
464
|
+
const off = this.watchDialSinks(dial.source, onDial);
|
|
465
|
+
stopDial = () => {
|
|
466
|
+
off();
|
|
467
|
+
release();
|
|
468
|
+
};
|
|
469
|
+
if (anyAvailable())
|
|
470
|
+
report(true);
|
|
471
|
+
}
|
|
472
|
+
if (last === undefined) {
|
|
473
|
+
const ready = hasCast ? this.appDiscovery.settled(castSource) : Promise.resolve();
|
|
474
|
+
void ready.then(() => {
|
|
475
|
+
if (last === undefined)
|
|
476
|
+
report(anyAvailable());
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
available,
|
|
481
|
+
close: () => {
|
|
482
|
+
if (closed)
|
|
483
|
+
return;
|
|
484
|
+
closed = true;
|
|
485
|
+
stopCast();
|
|
486
|
+
stopDial();
|
|
487
|
+
if (last === undefined)
|
|
488
|
+
first(false);
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* One listener on the DIAL sinks for every availability observation: a page may hold many, and a listener each would
|
|
494
|
+
* trip EventEmitter's limit of ten.
|
|
495
|
+
*/
|
|
496
|
+
watchDialSinks(source, callback) {
|
|
497
|
+
if (this.dialWatchers.size === 0)
|
|
498
|
+
source.on("deviceChanged", this.onDialSinks);
|
|
499
|
+
this.dialWatchers.add(callback);
|
|
500
|
+
return () => {
|
|
501
|
+
if (!this.dialWatchers.delete(callback))
|
|
502
|
+
return;
|
|
503
|
+
if (this.dialWatchers.size === 0)
|
|
504
|
+
source.off("deviceChanged", this.onDialSinks);
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* The sinks a request for an app is offered, as Chrome's dialog and `StartPresentation` offer the sinks of the
|
|
509
|
+
* source: those that have the app. Observes the source until `close()`, so the picker sees the list change; the
|
|
510
|
+
* first list is waited for when no answer stands yet.
|
|
511
|
+
*/
|
|
512
|
+
async appSinks(source) {
|
|
513
|
+
const events = new EventEmitter();
|
|
514
|
+
const devices = () => this.appDiscovery.availableSinks(source);
|
|
515
|
+
const stop = this.appDiscovery.startObserving(source, () => events.emit("deviceChanged"));
|
|
516
|
+
const sinks = {
|
|
517
|
+
devices,
|
|
518
|
+
on: (e, l) => events.on(e, l),
|
|
519
|
+
off: (e, l) => events.off(e, l),
|
|
520
|
+
};
|
|
521
|
+
const observers = createSinksObservers(sinks);
|
|
522
|
+
if (devices().length === 0)
|
|
523
|
+
await this.appDiscovery.settled(source);
|
|
524
|
+
return {
|
|
525
|
+
devices,
|
|
526
|
+
source: sinks,
|
|
527
|
+
observers,
|
|
528
|
+
close: () => {
|
|
529
|
+
observers.dispose();
|
|
530
|
+
stop();
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
}
|
|
236
534
|
handleInitialize(sender, params) {
|
|
237
535
|
const p = parseInitialize(params);
|
|
238
536
|
if (p === null)
|
|
239
537
|
return bad("invalid_parameter");
|
|
240
|
-
const available = this.
|
|
538
|
+
const available = this.sinkService.devices().some((d) => deviceMatches(d, p.capabilities));
|
|
241
539
|
this.senders.set(sender.id, { appId: p.appId, capabilities: p.capabilities, lastAvailable: available });
|
|
242
540
|
const joined = [];
|
|
243
541
|
for (const rec of this.sessions.values()) {
|
|
@@ -248,43 +546,103 @@ export class CastSessionService {
|
|
|
248
546
|
if (p.autoJoinPolicy === "origin_scoped" || (p.autoJoinPolicy === "tab_and_origin_scoped" && sameTab)) {
|
|
249
547
|
rec.parked.delete(sender.id);
|
|
250
548
|
rec.members.add(sender.id);
|
|
549
|
+
this.notifySession("updated", rec);
|
|
251
550
|
joined.push(this.snapshotOf(rec));
|
|
252
551
|
}
|
|
253
552
|
}
|
|
254
553
|
return good({ available, sessions: joined });
|
|
255
554
|
}
|
|
256
|
-
|
|
257
|
-
|
|
555
|
+
/**
|
|
556
|
+
* `requestSession`; with `presetDeviceId` (`requestSessionOnDevice`) the picker is skipped: that device is the choice
|
|
557
|
+
* (and must still be eligible). With `sink` (`requestSink`) the request may name a DIAL app as well as, or instead
|
|
558
|
+
* of, a Cast app, and the picker is offered the DIAL sinks that have it too; a DIAL choice is returned as
|
|
559
|
+
* `{ dialSink }` and nothing is launched here (the presentation handler creates the DIAL route).
|
|
560
|
+
*/
|
|
561
|
+
async handleRequestSession(sender, params, opts = {}) {
|
|
562
|
+
const presetDeviceId = opts.presetDeviceId;
|
|
563
|
+
const p = opts.sink === true ? parseRequestSink(params) : parseRequestSessionParams(params);
|
|
258
564
|
if (p === null)
|
|
259
565
|
return bad("invalid_parameter");
|
|
566
|
+
const appId = p.appId;
|
|
567
|
+
const dialApp = p.dialApp;
|
|
568
|
+
const capabilities = p.capabilities;
|
|
569
|
+
const dial = dialApp !== null ? this.options.dial : undefined;
|
|
570
|
+
const dialAvailable = () => (dial !== undefined && dialApp !== null ? dial.available(dialApp, sender.origin) : []);
|
|
260
571
|
if (this.pendingRequests.has(sender.id))
|
|
261
572
|
return bad("invalid_parameter");
|
|
262
573
|
const discard = { value: false };
|
|
263
574
|
const cancelled = { value: false };
|
|
264
|
-
|
|
575
|
+
const pending = { discard, cancelled };
|
|
576
|
+
this.pendingRequests.set(sender.id, pending);
|
|
577
|
+
// Chrome's dialog starts observing the sinks of the source when it opens (StartObservingMediaSinks), and the
|
|
578
|
+
// observer then waits for the answers; so the DIAL monitor starts before the first look, and a request with no sink
|
|
579
|
+
// yet waits a while for the devices' app info instead of failing on a page that never watched availability.
|
|
580
|
+
const stopMonitoring = dial !== undefined && dialApp !== null ? dial.monitor(dialApp, sender.origin) ?? undefined : undefined;
|
|
581
|
+
let appSinks;
|
|
582
|
+
let combined;
|
|
265
583
|
try {
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
|
|
584
|
+
// A page's presentation request is offered the sinks that have the app; chrome.cast's requestSession is unchanged
|
|
585
|
+
if (p.appAvailability && appId !== null)
|
|
586
|
+
appSinks = await this.appSinks({ appIds: [appId], capabilities });
|
|
587
|
+
if (cancelled.value || this.disposed)
|
|
588
|
+
return bad("cancel");
|
|
589
|
+
const castEligible = () => appId === null ? [] : (appSinks?.devices() ?? this.sinkService.devices()).filter((d) => deviceMatches(d, capabilities));
|
|
590
|
+
let eligible = [...castEligible(), ...dialAvailable()];
|
|
591
|
+
if (eligible.length === 0 && dial !== undefined && stopMonitoring !== undefined) {
|
|
592
|
+
await waitForDevices(dial.source, Math.min(p.timeoutMs, DIAL_PROBE_WAIT_MS), () => cancelled.value || discard.value || dialAvailable().length > 0);
|
|
593
|
+
if (cancelled.value || this.disposed)
|
|
594
|
+
return bad("cancel");
|
|
595
|
+
eligible = [...castEligible(), ...dialAvailable()];
|
|
596
|
+
}
|
|
597
|
+
if (eligible.length === 0) {
|
|
598
|
+
// Say why the devices found are not offered, when they failed to open (Chrome shows no sink and logs the error)
|
|
599
|
+
const why = this.sinkService.openErrors();
|
|
600
|
+
return bad("receiver_unavailable", why.length > 0 ? `no device could be reached: ${why.join("; ")}` : undefined);
|
|
601
|
+
}
|
|
269
602
|
const request = {
|
|
270
|
-
appId:
|
|
271
|
-
capabilities
|
|
603
|
+
appId: appId ?? "",
|
|
604
|
+
capabilities,
|
|
272
605
|
origin: sender.origin,
|
|
273
606
|
senderId: sender.id,
|
|
274
607
|
};
|
|
275
|
-
const current = this.currentSessionFor(sender.id,
|
|
608
|
+
const current = appId === null ? undefined : this.currentSessionFor(sender.id, appId);
|
|
276
609
|
if (current !== undefined) {
|
|
277
610
|
request.session = { sessionId: current.app.sessionId, deviceId: current.device.id };
|
|
278
611
|
}
|
|
279
612
|
let choice;
|
|
280
|
-
|
|
281
|
-
choice =
|
|
613
|
+
if (presetDeviceId !== undefined) {
|
|
614
|
+
choice = eligible.find((d) => d.id === presetDeviceId) ?? null;
|
|
615
|
+
if (choice === null)
|
|
616
|
+
return bad("receiver_unavailable");
|
|
282
617
|
}
|
|
283
|
-
|
|
284
|
-
|
|
618
|
+
else {
|
|
619
|
+
// The picker gets live device updates until it answers; closing aborts its signal. With a DIAL app it watches
|
|
620
|
+
// the DIAL sinks too.
|
|
621
|
+
const castObservers = appSinks?.observers ?? this.sinks;
|
|
622
|
+
if (dial !== undefined)
|
|
623
|
+
combined = createSinksObservers(combineSources(appSinks?.source ?? this.sinkService, dial.source));
|
|
624
|
+
const pick = createPickerContext(combined ?? castObservers, (d) => d.dial !== undefined ? dialAvailable().some((x) => x.id === d.id) : appId !== null && deviceMatches(d, capabilities));
|
|
625
|
+
pending.picker = pick;
|
|
626
|
+
try {
|
|
627
|
+
choice = await this.options.selectDevice(eligible, request, pick.context);
|
|
628
|
+
}
|
|
629
|
+
catch (err) {
|
|
630
|
+
return bad("session_error", describe(err));
|
|
631
|
+
}
|
|
632
|
+
finally {
|
|
633
|
+
pick.close();
|
|
634
|
+
}
|
|
285
635
|
}
|
|
286
636
|
if (choice === null)
|
|
287
637
|
return bad("cancel");
|
|
638
|
+
if (choice !== "stop" && choice.dial !== undefined) {
|
|
639
|
+
// Only a device offered for this request can be chosen.
|
|
640
|
+
if (!eligible.some((d) => d.id === choice.id))
|
|
641
|
+
return bad("receiver_unavailable");
|
|
642
|
+
return good({ dialSink: choice });
|
|
643
|
+
}
|
|
644
|
+
if (appId === null)
|
|
645
|
+
return bad("invalid_parameter");
|
|
288
646
|
if (choice === "stop") {
|
|
289
647
|
const rec = request.session !== undefined ? this.sessions.get(request.session.sessionId) : undefined;
|
|
290
648
|
if (rec === undefined)
|
|
@@ -294,7 +652,9 @@ export class CastSessionService {
|
|
|
294
652
|
const stopped = await this.stopSessionRecord(rec, sender.id, true);
|
|
295
653
|
return stopped.ok ? bad("cancel") : stopped;
|
|
296
654
|
}
|
|
297
|
-
|
|
655
|
+
// Chrome's CastActivityManager::LaunchSession launches anew even on a sink that has a route (the receiver's status
|
|
656
|
+
// update then removes the old one), so only the page's own picker reuses the sender's session
|
|
657
|
+
if (presetDeviceId === undefined && request.session !== undefined && choice.id === request.session.deviceId) {
|
|
298
658
|
const rec = this.sessions.get(request.session.sessionId);
|
|
299
659
|
if (rec !== undefined)
|
|
300
660
|
return good(this.snapshotOf(rec));
|
|
@@ -308,7 +668,7 @@ export class CastSessionService {
|
|
|
308
668
|
}, p.timeoutMs);
|
|
309
669
|
});
|
|
310
670
|
try {
|
|
311
|
-
const snapshot = await Promise.race([this.openSession(choice,
|
|
671
|
+
const snapshot = await Promise.race([this.openSession(choice, appId, sender, discard, cancelled), bound]);
|
|
312
672
|
return good(snapshot);
|
|
313
673
|
}
|
|
314
674
|
catch (err) {
|
|
@@ -324,18 +684,27 @@ export class CastSessionService {
|
|
|
324
684
|
}
|
|
325
685
|
}
|
|
326
686
|
finally {
|
|
687
|
+
combined?.dispose();
|
|
688
|
+
appSinks?.close();
|
|
689
|
+
stopMonitoring?.();
|
|
327
690
|
this.pendingRequests.delete(sender.id);
|
|
328
691
|
}
|
|
329
692
|
}
|
|
330
|
-
|
|
693
|
+
/**
|
|
694
|
+
* `checkOrigin` is joinSession's own rule (mode "chromecast", which is frozen and has no
|
|
695
|
+
* Chromium counterpart). Joining by id, as Chrome's Presentation API path does, has none: AppActivity::CanJoinSession checks only
|
|
696
|
+
* the app and that the client is not connected yet.
|
|
697
|
+
*/
|
|
698
|
+
handleJoinSession(sender, params, checkOrigin) {
|
|
331
699
|
const p = parseSessionId(params);
|
|
332
700
|
if (p === null)
|
|
333
701
|
return bad("invalid_parameter");
|
|
334
702
|
const rec = this.sessions.get(p.sessionId);
|
|
335
|
-
if (rec === undefined || rec.origin !== sender.origin)
|
|
703
|
+
if (rec === undefined || (checkOrigin && rec.origin !== sender.origin))
|
|
336
704
|
return bad("session_error");
|
|
337
705
|
rec.parked.delete(sender.id);
|
|
338
706
|
rec.members.add(sender.id);
|
|
707
|
+
this.notifySession("updated", rec);
|
|
339
708
|
return good(this.snapshotOf(rec));
|
|
340
709
|
}
|
|
341
710
|
handleSendMessage(sender, params) {
|
|
@@ -371,7 +740,7 @@ export class CastSessionService {
|
|
|
371
740
|
async stopSessionRecord(rec, caller, tellCaller) {
|
|
372
741
|
rec.stoppingBy = caller;
|
|
373
742
|
try {
|
|
374
|
-
await rec.client.stop(rec.app.sessionId);
|
|
743
|
+
this.tracker.applyStatus(rec.device.id, rec.client, await rec.client.stop(rec.app.sessionId));
|
|
375
744
|
}
|
|
376
745
|
catch (err) {
|
|
377
746
|
rec.stoppingBy = undefined;
|
|
@@ -390,7 +759,6 @@ export class CastSessionService {
|
|
|
390
759
|
else if (tellCaller) {
|
|
391
760
|
this.emitTo(caller, { type: "sessionEnded", sessionId: rec.app.sessionId, status: "stopped" });
|
|
392
761
|
}
|
|
393
|
-
this.cleanupIdle(rec.device.id, rec.client);
|
|
394
762
|
return good(undefined);
|
|
395
763
|
}
|
|
396
764
|
/** The sender's current session for the app, if it has one (the first one found). */
|
|
@@ -419,7 +787,7 @@ export class CastSessionService {
|
|
|
419
787
|
if (rec === undefined || !rec.members.has(sender.id))
|
|
420
788
|
return bad("session_error");
|
|
421
789
|
try {
|
|
422
|
-
await rec.client.setVolume({ level: p.level });
|
|
790
|
+
this.tracker.applyStatus(rec.device.id, rec.client, await rec.client.setVolume({ level: p.level }));
|
|
423
791
|
}
|
|
424
792
|
catch (err) {
|
|
425
793
|
return bad("session_error", describe(err));
|
|
@@ -434,105 +802,142 @@ export class CastSessionService {
|
|
|
434
802
|
if (rec === undefined || !rec.members.has(sender.id))
|
|
435
803
|
return bad("session_error");
|
|
436
804
|
try {
|
|
437
|
-
await rec.client.setVolume({ muted: p.muted });
|
|
805
|
+
this.tracker.applyStatus(rec.device.id, rec.client, await rec.client.setVolume({ muted: p.muted }));
|
|
438
806
|
}
|
|
439
807
|
catch (err) {
|
|
440
808
|
return bad("session_error", describe(err));
|
|
441
809
|
}
|
|
442
810
|
return good(undefined);
|
|
443
811
|
}
|
|
444
|
-
/**
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
this.
|
|
812
|
+
/**
|
|
813
|
+
* Join a session by its id, as Chrome's Media Router does for `reconnect("cast-session_<id>")`. A session this
|
|
814
|
+
* service already holds is joined without an origin check, like one found on a device. Otherwise the id is looked up
|
|
815
|
+
* in the session tracker, which knows what every device with an open channel runs: Chrome's CastActivityManager adds
|
|
816
|
+
* a non-local activity for each session its CastSessionTracker learns (AddNonLocalActivity) and
|
|
817
|
+
* FindActivityForSessionJoin finds it by id alone; auto-join skips it and no origin is checked. `appId`, when given,
|
|
818
|
+
* must be the session's app (AppActivity::CanJoinSession). Joining makes the route local, as in Chrome.
|
|
819
|
+
*/
|
|
820
|
+
async handleJoinRunningSession(sender, params) {
|
|
821
|
+
const p = parseSessionId(params);
|
|
822
|
+
if (p === null)
|
|
823
|
+
return bad("invalid_parameter");
|
|
824
|
+
const appId = isRecord(params) && typeof params.appId === "string" ? params.appId : undefined;
|
|
825
|
+
const known = this.sessions.get(p.sessionId);
|
|
826
|
+
if (known !== undefined) {
|
|
827
|
+
if (appId !== undefined && known.appId !== appId)
|
|
828
|
+
return bad("session_error");
|
|
829
|
+
return this.handleJoinSession(sender, params, false);
|
|
462
830
|
}
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
831
|
+
const tracked = this.tracker.sessionById(p.sessionId);
|
|
832
|
+
if (tracked === undefined || this.disposed || (appId !== undefined && tracked.appId !== appId))
|
|
833
|
+
return bad("session_error");
|
|
834
|
+
const client = this.sinkService.clientOf(tracked.sinkId);
|
|
835
|
+
const device = this.sinkService.sinkOf(tracked.sinkId);
|
|
836
|
+
if (client === undefined || device === undefined)
|
|
837
|
+
return bad("session_error");
|
|
838
|
+
client.connectTransport(tracked.app.transportId);
|
|
839
|
+
const rec = {
|
|
840
|
+
device,
|
|
841
|
+
client,
|
|
842
|
+
app: tracked.app,
|
|
843
|
+
origin: sender.origin,
|
|
844
|
+
appId: tracked.appId,
|
|
845
|
+
members: new Set([sender.id]),
|
|
846
|
+
parked: new Set(),
|
|
847
|
+
lastVolume: tracked.volume,
|
|
848
|
+
lastSnapshot: null,
|
|
849
|
+
};
|
|
850
|
+
rec.lastSnapshot = this.snapshotOf(rec);
|
|
851
|
+
this.sessions.set(tracked.sessionId, rec);
|
|
852
|
+
return good(rec.lastSnapshot);
|
|
853
|
+
}
|
|
854
|
+
/** Launch the app on the device's open channel and register the session. */
|
|
855
|
+
async openSession(device, appId, sender, discard, cancelled) {
|
|
856
|
+
// A DIAL sink has no Cast port: it is launched by the presentation handler's DIAL route, never as a Cast session.
|
|
857
|
+
if (device.dial !== undefined)
|
|
858
|
+
throw new MappedError("session_error", "A DIAL device cannot host a Cast session");
|
|
859
|
+
// Casting needs a channel that is open now; a device that is not a sink (or whose channel dropped) is unavailable.
|
|
860
|
+
const client = this.sinkService.clientOf(device.id);
|
|
861
|
+
if (client === undefined)
|
|
862
|
+
throw new MappedError("receiver_unavailable", "no open channel to the device");
|
|
863
|
+
if (discard.value)
|
|
864
|
+
throw new Discarded();
|
|
865
|
+
if (cancelled.value)
|
|
866
|
+
throw new MappedError("cancel", "cancelled");
|
|
867
|
+
this.launching.set(device.id, (this.launching.get(device.id) ?? 0) + 1);
|
|
466
868
|
try {
|
|
467
|
-
|
|
468
|
-
await entry.ready;
|
|
469
|
-
}
|
|
470
|
-
catch (err) {
|
|
471
|
-
if (err instanceof CastTimeoutError)
|
|
472
|
-
throw new MappedError("timeout", err.message);
|
|
473
|
-
throw new MappedError("receiver_unavailable", describe(err));
|
|
474
|
-
}
|
|
475
|
-
if (discard.value)
|
|
476
|
-
throw new Discarded();
|
|
477
|
-
if (cancelled.value)
|
|
478
|
-
throw new MappedError("cancel", "cancelled");
|
|
479
|
-
let app;
|
|
480
|
-
try {
|
|
481
|
-
app = await client.launch(appId);
|
|
482
|
-
}
|
|
483
|
-
catch (err) {
|
|
484
|
-
if (err instanceof CastTimeoutError)
|
|
485
|
-
throw new MappedError("timeout", err.message);
|
|
486
|
-
throw new MappedError("session_error", describe(err));
|
|
487
|
-
}
|
|
488
|
-
if (discard.value) {
|
|
489
|
-
client.closeTransport(app.transportId);
|
|
490
|
-
throw new Discarded();
|
|
491
|
-
}
|
|
492
|
-
if (cancelled.value) {
|
|
493
|
-
client.closeTransport(app.transportId);
|
|
494
|
-
throw new MappedError("cancel", "cancelled");
|
|
495
|
-
}
|
|
496
|
-
client.connectTransport(app.transportId);
|
|
497
|
-
let status;
|
|
498
|
-
try {
|
|
499
|
-
status = await client.getStatus();
|
|
500
|
-
}
|
|
501
|
-
catch (err) {
|
|
502
|
-
client.closeTransport(app.transportId);
|
|
503
|
-
throw new MappedError("session_error", describe(err));
|
|
504
|
-
}
|
|
505
|
-
if (discard.value) {
|
|
506
|
-
client.closeTransport(app.transportId);
|
|
507
|
-
throw new Discarded();
|
|
508
|
-
}
|
|
509
|
-
if (cancelled.value) {
|
|
510
|
-
client.closeTransport(app.transportId);
|
|
511
|
-
throw new MappedError("cancel", "cancelled");
|
|
512
|
-
}
|
|
513
|
-
const rec = {
|
|
514
|
-
device,
|
|
515
|
-
client,
|
|
516
|
-
app,
|
|
517
|
-
origin: sender.origin,
|
|
518
|
-
appId,
|
|
519
|
-
members: new Set([sender.id]),
|
|
520
|
-
parked: new Set(),
|
|
521
|
-
lastVolume: status.volume,
|
|
522
|
-
lastSnapshot: null,
|
|
523
|
-
};
|
|
524
|
-
const snapshot = this.snapshotOf(rec);
|
|
525
|
-
rec.lastSnapshot = snapshot;
|
|
526
|
-
this.sessions.set(app.sessionId, rec);
|
|
527
|
-
registered = true;
|
|
528
|
-
return snapshot;
|
|
869
|
+
return await this.launchOn(device, client, appId, sender, discard, cancelled);
|
|
529
870
|
}
|
|
530
871
|
finally {
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
this.
|
|
872
|
+
const left = (this.launching.get(device.id) ?? 1) - 1;
|
|
873
|
+
if (left > 0)
|
|
874
|
+
this.launching.set(device.id, left);
|
|
875
|
+
else
|
|
876
|
+
this.launching.delete(device.id);
|
|
877
|
+
// A launch that ended without a session leaves the device's own session listed again
|
|
878
|
+
if (left === 0)
|
|
879
|
+
this.onTrackerChanged();
|
|
534
880
|
}
|
|
535
881
|
}
|
|
882
|
+
async launchOn(device, client, appId, sender, discard, cancelled) {
|
|
883
|
+
let app;
|
|
884
|
+
try {
|
|
885
|
+
app = await client.launch(appId);
|
|
886
|
+
}
|
|
887
|
+
catch (err) {
|
|
888
|
+
if (err instanceof CastTimeoutError)
|
|
889
|
+
throw new MappedError("timeout", err.message);
|
|
890
|
+
throw new MappedError("session_error", describe(err));
|
|
891
|
+
}
|
|
892
|
+
if (discard.value) {
|
|
893
|
+
client.closeTransport(app.transportId);
|
|
894
|
+
throw new Discarded();
|
|
895
|
+
}
|
|
896
|
+
if (cancelled.value) {
|
|
897
|
+
client.closeTransport(app.transportId);
|
|
898
|
+
throw new MappedError("cancel", "cancelled");
|
|
899
|
+
}
|
|
900
|
+
client.connectTransport(app.transportId);
|
|
901
|
+
let status;
|
|
902
|
+
try {
|
|
903
|
+
status = await client.getStatus();
|
|
904
|
+
this.tracker.applyStatus(device.id, client, status);
|
|
905
|
+
}
|
|
906
|
+
catch (err) {
|
|
907
|
+
client.closeTransport(app.transportId);
|
|
908
|
+
throw new MappedError("session_error", describe(err));
|
|
909
|
+
}
|
|
910
|
+
if (discard.value) {
|
|
911
|
+
client.closeTransport(app.transportId);
|
|
912
|
+
throw new Discarded();
|
|
913
|
+
}
|
|
914
|
+
if (cancelled.value) {
|
|
915
|
+
client.closeTransport(app.transportId);
|
|
916
|
+
throw new MappedError("cancel", "cancelled");
|
|
917
|
+
}
|
|
918
|
+
const rec = {
|
|
919
|
+
device,
|
|
920
|
+
client,
|
|
921
|
+
app,
|
|
922
|
+
origin: sender.origin,
|
|
923
|
+
appId,
|
|
924
|
+
launchedBy: sender.id,
|
|
925
|
+
members: new Set([sender.id]),
|
|
926
|
+
parked: new Set(),
|
|
927
|
+
lastVolume: status.volume,
|
|
928
|
+
lastSnapshot: null,
|
|
929
|
+
};
|
|
930
|
+
const snapshot = this.snapshotOf(rec);
|
|
931
|
+
rec.lastSnapshot = snapshot;
|
|
932
|
+
this.sessions.set(app.sessionId, rec);
|
|
933
|
+
try {
|
|
934
|
+
this.options.onSessionLaunched?.(sender.id);
|
|
935
|
+
}
|
|
936
|
+
catch (err) {
|
|
937
|
+
console.error("electron-cast: onSessionLaunched failed", err);
|
|
938
|
+
}
|
|
939
|
+
return snapshot;
|
|
940
|
+
}
|
|
536
941
|
/** Remove a sender from a session; when it was the last one, tear the session down. */
|
|
537
942
|
leave(rec, senderId) {
|
|
538
943
|
rec.members.delete(senderId);
|
|
@@ -540,15 +945,17 @@ export class CastSessionService {
|
|
|
540
945
|
if (rec.members.size === 0 && rec.parked.size === 0) {
|
|
541
946
|
rec.client.closeTransport(rec.app.transportId);
|
|
542
947
|
this.sessions.delete(rec.app.sessionId);
|
|
543
|
-
|
|
948
|
+
}
|
|
949
|
+
else {
|
|
950
|
+
this.notifySession("updated", rec);
|
|
544
951
|
}
|
|
545
952
|
}
|
|
546
|
-
/** Subscribe to a freshly
|
|
547
|
-
bindClient(client,
|
|
953
|
+
/** Subscribe to a freshly opened channel's events. */
|
|
954
|
+
bindClient(client, _device) {
|
|
548
955
|
client.on("message", (msg) => this.onClientMessage(client, msg));
|
|
549
|
-
client.on("receiverStatus", (status) => this.onClientStatus(client,
|
|
956
|
+
client.on("receiverStatus", (status) => this.onClientStatus(client, status));
|
|
550
957
|
client.on("transportClosed", (transportId) => this.onTransportClosed(client, transportId));
|
|
551
|
-
client.on("close", () => this.onClientClose(client
|
|
958
|
+
client.on("close", () => this.onClientClose(client));
|
|
552
959
|
}
|
|
553
960
|
onClientMessage(client, msg) {
|
|
554
961
|
if (typeof msg.data !== "string")
|
|
@@ -566,7 +973,7 @@ export class CastSessionService {
|
|
|
566
973
|
}
|
|
567
974
|
}
|
|
568
975
|
}
|
|
569
|
-
onClientStatus(client,
|
|
976
|
+
onClientStatus(client, status) {
|
|
570
977
|
for (const rec of [...this.sessions.values()]) {
|
|
571
978
|
if (rec.client !== client)
|
|
572
979
|
continue;
|
|
@@ -585,12 +992,12 @@ export class CastSessionService {
|
|
|
585
992
|
const snapshot = this.snapshotOf(rec);
|
|
586
993
|
if (!sameValue(snapshot, rec.lastSnapshot)) {
|
|
587
994
|
rec.lastSnapshot = snapshot;
|
|
995
|
+
this.notifySession("updated", rec);
|
|
588
996
|
for (const member of rec.members) {
|
|
589
997
|
this.emitTo(member, { type: "sessionUpdated", session: snapshot });
|
|
590
998
|
}
|
|
591
999
|
}
|
|
592
1000
|
}
|
|
593
|
-
this.cleanupIdle(device.id, client);
|
|
594
1001
|
}
|
|
595
1002
|
onTransportClosed(client, transportId) {
|
|
596
1003
|
for (const rec of [...this.sessions.values()]) {
|
|
@@ -602,10 +1009,7 @@ export class CastSessionService {
|
|
|
602
1009
|
}
|
|
603
1010
|
}
|
|
604
1011
|
}
|
|
605
|
-
onClientClose(client
|
|
606
|
-
const entry = this.clients.get(deviceId);
|
|
607
|
-
if (entry !== undefined && entry.client === client)
|
|
608
|
-
this.clients.delete(deviceId);
|
|
1012
|
+
onClientClose(client) {
|
|
609
1013
|
for (const rec of [...this.sessions.values()]) {
|
|
610
1014
|
if (rec.client !== client)
|
|
611
1015
|
continue;
|
|
@@ -619,7 +1023,7 @@ export class CastSessionService {
|
|
|
619
1023
|
onDevicesChanged() {
|
|
620
1024
|
if (this.disposed)
|
|
621
1025
|
return;
|
|
622
|
-
const devices = this.
|
|
1026
|
+
const devices = this.sinkService.devices();
|
|
623
1027
|
for (const [id, rec] of this.senders) {
|
|
624
1028
|
const available = devices.some((d) => deviceMatches(d, rec.capabilities));
|
|
625
1029
|
if (available !== rec.lastAvailable) {
|
|
@@ -628,24 +1032,204 @@ export class CastSessionService {
|
|
|
628
1032
|
}
|
|
629
1033
|
}
|
|
630
1034
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
1035
|
+
// Main-process API (see manager-api.ts). Control goes through the paths the pages use, so pages see the same events.
|
|
1036
|
+
/** The sessions `senderId` launched and that still run (`routes_by_frame_` lookup by frame). */
|
|
1037
|
+
sessionsLaunchedBy(senderId) {
|
|
1038
|
+
return [...this.sessions.values()].filter((rec) => rec.launchedBy === senderId).map((rec) => rec.app.sessionId);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Every live session, parked ones included, then the sessions the devices run that this service does not hold
|
|
1042
|
+
* (started elsewhere, or let go of here), as Chrome's non-local routes.
|
|
1043
|
+
*/
|
|
1044
|
+
mediaRoutes() {
|
|
1045
|
+
const local = [...this.sessions.values()].map((rec) => this.routeOf(rec));
|
|
1046
|
+
return [...local, ...this.nonLocalSessions().map((s) => this.nonLocalRouteOf(s))];
|
|
1047
|
+
}
|
|
1048
|
+
/** The tracked sessions no page of this service holds (Chrome: activities with `is_local` false). */
|
|
1049
|
+
nonLocalSessions() {
|
|
1050
|
+
return this.tracker.sessions().filter((s) => !this.sessions.has(s.sessionId) && !this.launching.has(s.sinkId)
|
|
1051
|
+
&& this.options.ownsSession?.(s.sessionId, s.sinkId) !== true);
|
|
1052
|
+
}
|
|
1053
|
+
/** Be told when a session starts, changes (status, volume, pages) or ends; returns the unsubscribe function. */
|
|
1054
|
+
observeSessions(listener) {
|
|
1055
|
+
this.sessionListeners.add(listener);
|
|
1056
|
+
return () => void this.sessionListeners.delete(listener);
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Stop a session on the device for every page, as if a member had called stopSession. A session this service does not
|
|
1060
|
+
* hold is stopped on its device as it is (Chrome's TerminateSession works on non-local activities too).
|
|
1061
|
+
*/
|
|
1062
|
+
async terminateSession(sessionId) {
|
|
1063
|
+
const rec = this.sessions.get(sessionId);
|
|
1064
|
+
// No page is the caller, so every member is told sessionEnded.
|
|
1065
|
+
if (rec !== undefined)
|
|
1066
|
+
return this.stopSessionRecord(rec, MAIN_CALLER, false);
|
|
1067
|
+
const tracked = this.nonLocalSessions().find((s) => s.sessionId === sessionId);
|
|
1068
|
+
if (tracked === undefined)
|
|
1069
|
+
return bad("session_error", "unknown session");
|
|
1070
|
+
// With no open channel the stop cannot be sent: Chrome's `CastMessageHandler::StopSession` finds no socket and
|
|
1071
|
+
// reports a failure, which `HandleStopSessionResponse` turns into this message while the route stays.
|
|
1072
|
+
const client = this.sinkService.clientOf(tracked.sinkId);
|
|
1073
|
+
if (client === undefined)
|
|
1074
|
+
return bad("session_error", "StopSession response is not OK. Failed to terminate route.");
|
|
1075
|
+
try {
|
|
1076
|
+
this.tracker.applyStatus(tracked.sinkId, client, await client.stop(sessionId));
|
|
1077
|
+
}
|
|
1078
|
+
catch (err) {
|
|
1079
|
+
return bad("session_error", describe(err));
|
|
1080
|
+
}
|
|
1081
|
+
return good(undefined);
|
|
1082
|
+
}
|
|
1083
|
+
async setSessionVolume(sessionId, volume) {
|
|
1084
|
+
const rec = this.sessions.get(sessionId);
|
|
1085
|
+
const tracked = rec === undefined ? this.nonLocalSessions().find((s) => s.sessionId === sessionId) : undefined;
|
|
1086
|
+
const client = rec?.client ?? (tracked === undefined ? undefined : this.sinkService.clientOf(tracked.sinkId));
|
|
1087
|
+
const sinkId = rec?.device.id ?? tracked?.sinkId;
|
|
1088
|
+
if (client === undefined || sinkId === undefined)
|
|
1089
|
+
return bad("session_error", "unknown session");
|
|
1090
|
+
try {
|
|
1091
|
+
this.tracker.applyStatus(sinkId, client, await client.setVolume(volume));
|
|
1092
|
+
}
|
|
1093
|
+
catch (err) {
|
|
1094
|
+
return bad("session_error", describe(err));
|
|
1095
|
+
}
|
|
1096
|
+
return good(undefined);
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Every receiver status that describes a session, changed or not, with its volume (the tracker's
|
|
1100
|
+
* `OnSessionAddedOrUpdated`); for the media controller. Returns the unsubscribe function.
|
|
1101
|
+
*/
|
|
1102
|
+
observeSessionStatus(listener) {
|
|
1103
|
+
const on = (s) => listener(s.sessionId, s.volume);
|
|
1104
|
+
this.tracker.on("sessionStatus", on);
|
|
1105
|
+
return () => void this.tracker.off("sessionStatus", on);
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Every MEDIA_STATUS on a device's channel, credited to the session the device runs and merged with the media saved
|
|
1109
|
+
* before (`CastSessionTracker::HandleMediaStatusMessage`); for the media controller. Returns the unsubscribe function.
|
|
1110
|
+
*/
|
|
1111
|
+
observeMediaStatus(listener) {
|
|
1112
|
+
const on = (s, message) => listener(s.sessionId, message);
|
|
1113
|
+
this.tracker.on("mediaStatus", on);
|
|
1114
|
+
return () => void this.tracker.off("mediaStatus", on);
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Send a message to a session's receiver app from main, with no page involved, over the device's channel. A session
|
|
1118
|
+
* this service does not hold is reached too, as Chrome's `CastMessageHandler::SendMediaRequest` reaches a non-local
|
|
1119
|
+
* activity's session: a virtual connection to its transport is opened first (`SendCastMessageToSocket` -> `DoEnsureConnection`).
|
|
1120
|
+
*/
|
|
1121
|
+
sendSessionMessage(sessionId, namespace, message) {
|
|
1122
|
+
const rec = this.sessions.get(sessionId);
|
|
1123
|
+
let client = rec?.client;
|
|
1124
|
+
let transportId = rec?.app.transportId;
|
|
1125
|
+
if (rec === undefined) {
|
|
1126
|
+
const tracked = this.nonLocalSessions().find((s) => s.sessionId === sessionId);
|
|
1127
|
+
if (tracked === undefined)
|
|
1128
|
+
return bad("session_error", "unknown session");
|
|
1129
|
+
client = this.sinkService.clientOf(tracked.sinkId);
|
|
1130
|
+
transportId = tracked.transportId;
|
|
1131
|
+
if (client === undefined)
|
|
1132
|
+
return bad("channel_error", "no open channel to the device");
|
|
1133
|
+
}
|
|
1134
|
+
if (client === undefined || transportId === undefined)
|
|
1135
|
+
return bad("session_error", "unknown session");
|
|
1136
|
+
try {
|
|
1137
|
+
if (rec === undefined)
|
|
1138
|
+
client.connectTransport(transportId);
|
|
1139
|
+
client.send(namespace, transportId, message);
|
|
1140
|
+
}
|
|
1141
|
+
catch (err) {
|
|
1142
|
+
return bad("channel_error", describe(err));
|
|
639
1143
|
}
|
|
640
|
-
|
|
1144
|
+
return good(undefined);
|
|
1145
|
+
}
|
|
1146
|
+
/** The volume the receiver last reported for a session, local or not (Chrome: `receiver.volume` of the CastSession). */
|
|
1147
|
+
sessionVolume(sessionId) {
|
|
1148
|
+
return this.sessions.get(sessionId)?.lastVolume ?? this.tracker.sessionById(sessionId)?.volume;
|
|
641
1149
|
}
|
|
642
|
-
/**
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
1150
|
+
/**
|
|
1151
|
+
* Detach every page from the session and close its transport; the receiver app keeps running (and is then listed as a
|
|
1152
|
+
* non-local route). A route no page holds has nothing to detach.
|
|
1153
|
+
*/
|
|
1154
|
+
detachSession(sessionId) {
|
|
1155
|
+
const rec = this.sessions.get(sessionId);
|
|
1156
|
+
if (rec === undefined) {
|
|
1157
|
+
return this.nonLocalSessions().some((s) => s.sessionId === sessionId) ? good(undefined) : bad("session_error", "unknown session");
|
|
1158
|
+
}
|
|
1159
|
+
for (const member of rec.members) {
|
|
1160
|
+
this.emitTo(member, { type: "sessionEnded", sessionId, status: "disconnected" });
|
|
1161
|
+
}
|
|
1162
|
+
rec.members.clear();
|
|
1163
|
+
rec.parked.clear();
|
|
1164
|
+
rec.client.closeTransport(rec.app.transportId);
|
|
1165
|
+
this.sessions.delete(sessionId);
|
|
1166
|
+
return good(undefined);
|
|
1167
|
+
}
|
|
1168
|
+
/** Tell the route observers something changed (the arguments only fit the ObservedMap callback). */
|
|
1169
|
+
notifySession(_kind, _rec) {
|
|
1170
|
+
if (this.disposed)
|
|
1171
|
+
return;
|
|
1172
|
+
if (_kind === "ended")
|
|
1173
|
+
this.sinkService.releaseUnused();
|
|
1174
|
+
this.lastRoutesKey = JSON.stringify(this.mediaRoutes());
|
|
1175
|
+
this.fireSessionListeners();
|
|
1176
|
+
}
|
|
1177
|
+
/** The tracker learned something; route observers hear of it only if the routes they see differ now. */
|
|
1178
|
+
onTrackerChanged() {
|
|
1179
|
+
if (this.disposed)
|
|
1180
|
+
return;
|
|
1181
|
+
const key = JSON.stringify(this.mediaRoutes());
|
|
1182
|
+
if (key === this.lastRoutesKey)
|
|
646
1183
|
return;
|
|
647
|
-
this.
|
|
648
|
-
|
|
1184
|
+
this.lastRoutesKey = key;
|
|
1185
|
+
this.fireSessionListeners();
|
|
1186
|
+
}
|
|
1187
|
+
fireSessionListeners() {
|
|
1188
|
+
for (const listener of [...this.sessionListeners]) {
|
|
1189
|
+
try {
|
|
1190
|
+
listener();
|
|
1191
|
+
}
|
|
1192
|
+
catch (err) {
|
|
1193
|
+
console.error("electron-cast: a session listener failed", err);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
routeOf(rec) {
|
|
1198
|
+
return {
|
|
1199
|
+
id: rec.app.sessionId,
|
|
1200
|
+
providerId: "cast",
|
|
1201
|
+
mediaSource: `cast:${rec.appId}`,
|
|
1202
|
+
sinkId: rec.device.id,
|
|
1203
|
+
sinkName: rec.device.name,
|
|
1204
|
+
description: rec.app.statusText || rec.app.displayName,
|
|
1205
|
+
isLocal: true,
|
|
1206
|
+
appId: rec.appId,
|
|
1207
|
+
displayName: rec.app.displayName,
|
|
1208
|
+
origin: rec.origin,
|
|
1209
|
+
volume: { level: rec.lastVolume.level ?? null, muted: rec.lastVolume.muted ?? null },
|
|
1210
|
+
members: [...rec.members],
|
|
1211
|
+
parkedSenders: [...rec.parked],
|
|
1212
|
+
parked: rec.members.size === 0,
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
/** Chrome's `AddNonLocalActivity`: the route has no page, and its description is the session's (`GetRouteDescription`). */
|
|
1216
|
+
nonLocalRouteOf(session) {
|
|
1217
|
+
return {
|
|
1218
|
+
id: session.sessionId,
|
|
1219
|
+
providerId: "cast",
|
|
1220
|
+
mediaSource: `cast:${session.appId}`,
|
|
1221
|
+
sinkId: session.sinkId,
|
|
1222
|
+
sinkName: this.sinkService.sinkOf(session.sinkId)?.name ?? "",
|
|
1223
|
+
description: session.statusText || session.displayName,
|
|
1224
|
+
isLocal: false,
|
|
1225
|
+
appId: session.appId,
|
|
1226
|
+
displayName: session.displayName,
|
|
1227
|
+
origin: "",
|
|
1228
|
+
volume: { level: session.volume.level ?? null, muted: session.volume.muted ?? null },
|
|
1229
|
+
members: [],
|
|
1230
|
+
parkedSenders: [],
|
|
1231
|
+
parked: false,
|
|
1232
|
+
};
|
|
649
1233
|
}
|
|
650
1234
|
snapshotOf(rec) {
|
|
651
1235
|
const app = rec.app;
|