electron-cast 0.4.0 → 0.5.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +280 -0
- package/CONTRIBUTING.md +305 -0
- package/README.md +211 -165
- package/SECURITY.md +324 -0
- package/dist/cjs/client/auth/build-time.js +1 -1
- package/dist/cjs/client/auth/cast-auth.d.ts +2 -0
- package/dist/cjs/client/auth/cast-auth.js.map +1 -1
- package/dist/cjs/dial/dial-registry.d.ts +104 -0
- package/dist/cjs/dial/dial-registry.js +301 -0
- package/dist/cjs/dial/dial-registry.js.map +1 -0
- package/dist/cjs/dial/dial-sink-service.d.ts +108 -0
- package/dist/cjs/dial/dial-sink-service.js +314 -0
- package/dist/cjs/dial/dial-sink-service.js.map +1 -0
- package/dist/cjs/dial/http.d.ts +40 -0
- package/dist/cjs/dial/http.js +172 -0
- package/dist/cjs/dial/http.js.map +1 -0
- package/dist/cjs/dial/index.d.ts +63 -0
- package/dist/cjs/dial/index.js +134 -0
- package/dist/cjs/dial/index.js.map +1 -0
- package/dist/cjs/dial/origins.d.ts +4 -0
- package/dist/cjs/dial/origins.js +36 -0
- package/dist/cjs/dial/origins.js.map +1 -0
- package/dist/cjs/dial/parse.d.ts +101 -0
- package/dist/cjs/dial/parse.js +296 -0
- package/dist/cjs/dial/parse.js.map +1 -0
- package/dist/cjs/dial/route-provider.d.ts +96 -0
- package/dist/cjs/dial/route-provider.js +376 -0
- package/dist/cjs/dial/route-provider.js.map +1 -0
- package/dist/cjs/dial/ssdp-socket.d.ts +34 -0
- package/dist/cjs/dial/ssdp-socket.js +72 -0
- package/dist/cjs/dial/ssdp-socket.js.map +1 -0
- package/dist/cjs/dial/xml.d.ts +13 -0
- package/dist/cjs/dial/xml.js +208 -0
- package/dist/cjs/dial/xml.js.map +1 -0
- package/dist/cjs/discovery/cast-discovery.d.ts +2 -0
- package/dist/cjs/discovery/cast-discovery.js.map +1 -1
- package/dist/cjs/discovery/device-cache.d.ts +9 -0
- package/dist/cjs/discovery/device-cache.js.map +1 -1
- package/dist/cjs/discovery/index.d.ts +1 -0
- package/dist/cjs/discovery/index.js +1 -0
- package/dist/cjs/discovery/index.js.map +1 -1
- package/dist/cjs/discovery/ip-policy.d.ts +20 -0
- package/dist/cjs/discovery/ip-policy.js +109 -0
- package/dist/cjs/discovery/ip-policy.js.map +1 -0
- package/dist/cjs/discovery/udp-socket.d.ts +3 -0
- package/dist/cjs/discovery/udp-socket.js +3 -0
- package/dist/cjs/discovery/udp-socket.js.map +1 -1
- package/dist/cjs/electron/access-code.d.ts +221 -0
- package/dist/cjs/electron/access-code.js +586 -0
- package/dist/cjs/electron/access-code.js.map +1 -0
- package/dist/cjs/electron/app-discovery.d.ts +82 -0
- package/dist/cjs/electron/app-discovery.js +219 -0
- package/dist/cjs/electron/app-discovery.js.map +1 -0
- package/dist/cjs/electron/default-presentation.d.ts +38 -0
- package/dist/cjs/electron/default-presentation.js +88 -0
- package/dist/cjs/electron/default-presentation.js.map +1 -0
- package/dist/cjs/electron/main.d.ts +98 -11
- package/dist/cjs/electron/main.js +602 -20
- package/dist/cjs/electron/main.js.map +1 -1
- package/dist/cjs/electron/manager-api.d.ts +200 -18
- package/dist/cjs/electron/manager-api.js +199 -4
- package/dist/cjs/electron/manager-api.js.map +1 -1
- package/dist/cjs/electron/media-controller.d.ts +79 -0
- package/dist/cjs/electron/media-controller.js +251 -0
- package/dist/cjs/electron/media-controller.js.map +1 -0
- package/dist/cjs/electron/network-monitor.d.ts +61 -0
- package/dist/cjs/electron/network-monitor.js +124 -0
- package/dist/cjs/electron/network-monitor.js.map +1 -0
- package/dist/cjs/electron/preload.js.map +1 -1
- package/dist/cjs/electron/presentation-handler.d.ts +39 -4
- package/dist/cjs/electron/presentation-handler.js +191 -47
- package/dist/cjs/electron/presentation-handler.js.map +1 -1
- package/dist/cjs/electron/presentation-source.d.ts +76 -0
- package/dist/cjs/electron/presentation-source.js +132 -0
- package/dist/cjs/electron/presentation-source.js.map +1 -0
- package/dist/cjs/electron/session-service.d.ts +198 -24
- package/dist/cjs/electron/session-service.js +630 -248
- package/dist/cjs/electron/session-service.js.map +1 -1
- package/dist/cjs/electron/session-tracker.d.ts +82 -0
- package/dist/cjs/electron/session-tracker.js +225 -0
- package/dist/cjs/electron/session-tracker.js.map +1 -0
- package/dist/cjs/electron/sink-service.d.ts +246 -0
- package/dist/cjs/electron/sink-service.js +606 -0
- package/dist/cjs/electron/sink-service.js.map +1 -0
- package/dist/cjs/electron/wired-display/controller.d.ts +76 -0
- package/dist/cjs/electron/wired-display/controller.js +198 -0
- package/dist/cjs/electron/wired-display/controller.js.map +1 -0
- package/dist/cjs/electron/wired-display/displays.d.ts +44 -0
- package/dist/cjs/electron/wired-display/displays.js +98 -0
- package/dist/cjs/electron/wired-display/displays.js.map +1 -0
- package/dist/cjs/electron/wired-display/electron-windows.d.ts +111 -0
- package/dist/cjs/electron/wired-display/electron-windows.js +306 -0
- package/dist/cjs/electron/wired-display/electron-windows.js.map +1 -0
- package/dist/cjs/electron/wired-display/index.d.ts +90 -0
- package/dist/cjs/electron/wired-display/index.js +115 -0
- package/dist/cjs/electron/wired-display/index.js.map +1 -0
- package/dist/cjs/electron/wired-display/local-presentation.d.ts +98 -0
- package/dist/cjs/electron/wired-display/local-presentation.js +234 -0
- package/dist/cjs/electron/wired-display/local-presentation.js.map +1 -0
- package/dist/cjs/electron/wired-display/provider.d.ts +112 -0
- package/dist/cjs/electron/wired-display/provider.js +202 -0
- package/dist/cjs/electron/wired-display/provider.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mirroring/backend.d.ts +76 -0
- package/dist/cjs/mirroring/backend.js +21 -0
- package/dist/cjs/mirroring/backend.js.map +1 -0
- package/dist/cjs/mirroring/electron/agent-protocol.d.ts +158 -0
- package/dist/cjs/mirroring/electron/agent-protocol.js +11 -0
- package/dist/cjs/mirroring/electron/agent-protocol.js.map +1 -0
- package/dist/cjs/mirroring/electron/agent-source.d.ts +20 -0
- package/dist/cjs/mirroring/electron/agent-source.js +621 -0
- package/dist/cjs/mirroring/electron/agent-source.js.map +1 -0
- package/dist/cjs/mirroring/electron/engine-process.d.ts +87 -0
- package/dist/cjs/mirroring/electron/engine-process.js +81 -0
- package/dist/cjs/mirroring/electron/engine-process.js.map +1 -0
- package/dist/cjs/mirroring/electron/host.d.ts +89 -0
- package/dist/cjs/mirroring/electron/host.js +321 -0
- package/dist/cjs/mirroring/electron/host.js.map +1 -0
- package/dist/cjs/mirroring/electron/port-backend.d.ts +107 -0
- package/dist/cjs/mirroring/electron/port-backend.js +446 -0
- package/dist/cjs/mirroring/electron/port-backend.js.map +1 -0
- package/dist/cjs/mirroring/encoding-support.d.ts +66 -0
- package/dist/cjs/mirroring/encoding-support.js +89 -0
- package/dist/cjs/mirroring/encoding-support.js.map +1 -0
- package/dist/cjs/mirroring/engine.d.ts +16 -0
- package/dist/cjs/mirroring/engine.js +78 -0
- package/dist/cjs/mirroring/engine.js.map +1 -0
- package/dist/cjs/mirroring/mirror-settings.d.ts +101 -0
- package/dist/cjs/mirroring/mirror-settings.js +140 -0
- package/dist/cjs/mirroring/mirror-settings.js.map +1 -0
- package/dist/cjs/mirroring/mirroring-activity.d.ts +207 -0
- package/dist/cjs/mirroring/mirroring-activity.js +367 -0
- package/dist/cjs/mirroring/mirroring-activity.js.map +1 -0
- package/dist/cjs/mirroring/mirroring-manager.d.ts +134 -0
- package/dist/cjs/mirroring/mirroring-manager.js +286 -0
- package/dist/cjs/mirroring/mirroring-manager.js.map +1 -0
- package/dist/cjs/mirroring/protocol/answer.d.ts +87 -0
- package/dist/cjs/mirroring/protocol/answer.js +233 -0
- package/dist/cjs/mirroring/protocol/answer.js.map +1 -0
- package/dist/cjs/mirroring/protocol/constants.d.ts +64 -0
- package/dist/cjs/mirroring/protocol/constants.js +70 -0
- package/dist/cjs/mirroring/protocol/constants.js.map +1 -0
- package/dist/cjs/mirroring/protocol/errors.d.ts +25 -0
- package/dist/cjs/mirroring/protocol/errors.js +34 -0
- package/dist/cjs/mirroring/protocol/errors.js.map +1 -0
- package/dist/cjs/mirroring/protocol/frame-id.d.ts +9 -0
- package/dist/cjs/mirroring/protocol/frame-id.js +24 -0
- package/dist/cjs/mirroring/protocol/frame-id.js.map +1 -0
- package/dist/cjs/mirroring/protocol/messenger.d.ts +42 -0
- package/dist/cjs/mirroring/protocol/messenger.js +122 -0
- package/dist/cjs/mirroring/protocol/messenger.js.map +1 -0
- package/dist/cjs/mirroring/protocol/offer.d.ts +109 -0
- package/dist/cjs/mirroring/protocol/offer.js +192 -0
- package/dist/cjs/mirroring/protocol/offer.js.map +1 -0
- package/dist/cjs/mirroring/protocol/recommendations.d.ts +28 -0
- package/dist/cjs/mirroring/protocol/recommendations.js +103 -0
- package/dist/cjs/mirroring/protocol/recommendations.js.map +1 -0
- package/dist/cjs/mirroring/routing.d.ts +60 -0
- package/dist/cjs/mirroring/routing.js +147 -0
- package/dist/cjs/mirroring/routing.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/ntp.d.ts +27 -0
- package/dist/cjs/mirroring/rtcp/ntp.js +62 -0
- package/dist/cjs/mirroring/rtcp/ntp.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/parser.d.ts +50 -0
- package/dist/cjs/mirroring/rtcp/parser.js +270 -0
- package/dist/cjs/mirroring/rtcp/parser.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/sender-report.d.ts +32 -0
- package/dist/cjs/mirroring/rtcp/sender-report.js +56 -0
- package/dist/cjs/mirroring/rtcp/sender-report.js.map +1 -0
- package/dist/cjs/mirroring/rtcp/wire.d.ts +54 -0
- package/dist/cjs/mirroring/rtcp/wire.js +73 -0
- package/dist/cjs/mirroring/rtcp/wire.js.map +1 -0
- package/dist/cjs/mirroring/rtp/frame-crypto.d.ts +11 -0
- package/dist/cjs/mirroring/rtp/frame-crypto.js +39 -0
- package/dist/cjs/mirroring/rtp/frame-crypto.js.map +1 -0
- package/dist/cjs/mirroring/rtp/frame.d.ts +23 -0
- package/dist/cjs/mirroring/rtp/frame.js +3 -0
- package/dist/cjs/mirroring/rtp/frame.js.map +1 -0
- package/dist/cjs/mirroring/rtp/packetizer.d.ts +27 -0
- package/dist/cjs/mirroring/rtp/packetizer.js +92 -0
- package/dist/cjs/mirroring/rtp/packetizer.js.map +1 -0
- package/dist/cjs/mirroring/sender/audio-sender.d.ts +23 -0
- package/dist/cjs/mirroring/sender/audio-sender.js +52 -0
- package/dist/cjs/mirroring/sender/audio-sender.js.map +1 -0
- package/dist/cjs/mirroring/sender/bandwidth-estimator.d.ts +26 -0
- package/dist/cjs/mirroring/sender/bandwidth-estimator.js +107 -0
- package/dist/cjs/mirroring/sender/bandwidth-estimator.js.map +1 -0
- package/dist/cjs/mirroring/sender/capture-size-oracle.d.ts +121 -0
- package/dist/cjs/mirroring/sender/capture-size-oracle.js +440 -0
- package/dist/cjs/mirroring/sender/capture-size-oracle.js.map +1 -0
- package/dist/cjs/mirroring/sender/frame-sender.d.ts +103 -0
- package/dist/cjs/mirroring/sender/frame-sender.js +217 -0
- package/dist/cjs/mirroring/sender/frame-sender.js.map +1 -0
- package/dist/cjs/mirroring/sender/packet-router.d.ts +74 -0
- package/dist/cjs/mirroring/sender/packet-router.js +196 -0
- package/dist/cjs/mirroring/sender/packet-router.js.map +1 -0
- package/dist/cjs/mirroring/sender/sender-session.d.ts +85 -0
- package/dist/cjs/mirroring/sender/sender-session.js +240 -0
- package/dist/cjs/mirroring/sender/sender-session.js.map +1 -0
- package/dist/cjs/mirroring/sender/sender.d.ts +120 -0
- package/dist/cjs/mirroring/sender/sender.js +457 -0
- package/dist/cjs/mirroring/sender/sender.js.map +1 -0
- package/dist/cjs/mirroring/sender/video-encoder-metrics.d.ts +29 -0
- package/dist/cjs/mirroring/sender/video-encoder-metrics.js +64 -0
- package/dist/cjs/mirroring/sender/video-encoder-metrics.js.map +1 -0
- package/dist/cjs/mirroring/sender/video-sender.d.ts +95 -0
- package/dist/cjs/mirroring/sender/video-sender.js +183 -0
- package/dist/cjs/mirroring/sender/video-sender.js.map +1 -0
- package/dist/cjs/mirroring/session-host.d.ts +185 -0
- package/dist/cjs/mirroring/session-host.js +630 -0
- package/dist/cjs/mirroring/session-host.js.map +1 -0
- package/dist/cjs/mirroring/stats/clock-offset-estimator.d.ts +11 -0
- package/dist/cjs/mirroring/stats/clock-offset-estimator.js +123 -0
- package/dist/cjs/mirroring/stats/clock-offset-estimator.js.map +1 -0
- package/dist/cjs/mirroring/stats/openscreen-stats-client.d.ts +12 -0
- package/dist/cjs/mirroring/stats/openscreen-stats-client.js +21 -0
- package/dist/cjs/mirroring/stats/openscreen-stats-client.js.map +1 -0
- package/dist/cjs/mirroring/stats/sorted-map.d.ts +23 -0
- package/dist/cjs/mirroring/stats/sorted-map.js +70 -0
- package/dist/cjs/mirroring/stats/sorted-map.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-analyzer.d.ts +50 -0
- package/dist/cjs/mirroring/stats/statistics-analyzer.js +339 -0
- package/dist/cjs/mirroring/stats/statistics-analyzer.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-collector.d.ts +29 -0
- package/dist/cjs/mirroring/stats/statistics-collector.js +53 -0
- package/dist/cjs/mirroring/stats/statistics-collector.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-common.d.ts +61 -0
- package/dist/cjs/mirroring/stats/statistics-common.js +45 -0
- package/dist/cjs/mirroring/stats/statistics-common.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics-dispatcher.d.ts +28 -0
- package/dist/cjs/mirroring/stats/statistics-dispatcher.js +104 -0
- package/dist/cjs/mirroring/stats/statistics-dispatcher.js.map +1 -0
- package/dist/cjs/mirroring/stats/statistics.d.ts +84 -0
- package/dist/cjs/mirroring/stats/statistics.js +147 -0
- package/dist/cjs/mirroring/stats/statistics.js.map +1 -0
- package/dist/cjs/mirroring/transport/udp-environment.d.ts +40 -0
- package/dist/cjs/mirroring/transport/udp-environment.js +97 -0
- package/dist/cjs/mirroring/transport/udp-environment.js.map +1 -0
- package/dist/cjs/polyfill/bridge-types.d.ts +11 -0
- package/dist/cjs/polyfill/presentation-receiver.d.ts +12 -0
- package/dist/cjs/polyfill/presentation-receiver.js +369 -0
- package/dist/cjs/polyfill/presentation-receiver.js.map +1 -0
- package/dist/cjs/polyfill/presentation-standin.js +157 -15
- package/dist/cjs/polyfill/presentation-standin.js.map +1 -1
- package/dist/cjs/protocol/framing.d.ts +1 -1
- package/dist/cjs/protocol/framing.js +1 -1
- package/dist/cjs/protocol/framing.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +56 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/auth/build-time.js +1 -1
- package/dist/client/auth/cast-auth.d.ts +2 -0
- package/dist/client/auth/cast-auth.js.map +1 -1
- package/dist/dial/dial-registry.d.ts +104 -0
- package/dist/dial/dial-registry.js +297 -0
- package/dist/dial/dial-registry.js.map +1 -0
- package/dist/dial/dial-sink-service.d.ts +108 -0
- package/dist/dial/dial-sink-service.js +310 -0
- package/dist/dial/dial-sink-service.js.map +1 -0
- package/dist/dial/http.d.ts +40 -0
- package/dist/dial/http.js +165 -0
- package/dist/dial/http.js.map +1 -0
- package/dist/dial/index.d.ts +63 -0
- package/dist/dial/index.js +115 -0
- package/dist/dial/index.js.map +1 -0
- package/dist/dial/origins.d.ts +4 -0
- package/dist/dial/origins.js +32 -0
- package/dist/dial/origins.js.map +1 -0
- package/dist/dial/parse.d.ts +101 -0
- package/dist/dial/parse.js +281 -0
- package/dist/dial/parse.js.map +1 -0
- package/dist/dial/route-provider.d.ts +96 -0
- package/dist/dial/route-provider.js +369 -0
- package/dist/dial/route-provider.js.map +1 -0
- package/dist/dial/ssdp-socket.d.ts +34 -0
- package/dist/dial/ssdp-socket.js +65 -0
- package/dist/dial/ssdp-socket.js.map +1 -0
- package/dist/dial/xml.d.ts +13 -0
- package/dist/dial/xml.js +204 -0
- package/dist/dial/xml.js.map +1 -0
- package/dist/dial-test/cli-main.d.ts +17 -0
- package/dist/dial-test/cli-main.js +130 -0
- package/dist/dial-test/cli-main.js.map +1 -0
- package/dist/dial-test/report.d.ts +55 -0
- package/dist/dial-test/report.js +77 -0
- package/dist/dial-test/report.js.map +1 -0
- package/dist/dial-test/runner.d.ts +42 -0
- package/dist/dial-test/runner.js +566 -0
- package/dist/dial-test/runner.js.map +1 -0
- package/dist/dial-test/scrub.d.ts +14 -0
- package/dist/dial-test/scrub.js +73 -0
- package/dist/dial-test/scrub.js.map +1 -0
- package/dist/discovery/cast-discovery.d.ts +2 -0
- package/dist/discovery/cast-discovery.js.map +1 -1
- package/dist/discovery/device-cache.d.ts +9 -0
- package/dist/discovery/device-cache.js.map +1 -1
- package/dist/discovery/index.d.ts +1 -0
- package/dist/discovery/index.js +1 -0
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/ip-policy.d.ts +20 -0
- package/dist/discovery/ip-policy.js +103 -0
- package/dist/discovery/ip-policy.js.map +1 -0
- package/dist/discovery/udp-socket.d.ts +3 -0
- package/dist/discovery/udp-socket.js +3 -0
- package/dist/discovery/udp-socket.js.map +1 -1
- package/dist/electron/access-code.d.ts +221 -0
- package/dist/electron/access-code.js +577 -0
- package/dist/electron/access-code.js.map +1 -0
- package/dist/electron/app-discovery.d.ts +82 -0
- package/dist/electron/app-discovery.js +215 -0
- package/dist/electron/app-discovery.js.map +1 -0
- package/dist/electron/default-presentation.d.ts +38 -0
- package/dist/electron/default-presentation.js +83 -0
- package/dist/electron/default-presentation.js.map +1 -0
- package/dist/electron/main.d.ts +98 -11
- package/dist/electron/main.js +597 -21
- package/dist/electron/main.js.map +1 -1
- package/dist/electron/manager-api.d.ts +200 -18
- package/dist/electron/manager-api.js +196 -4
- package/dist/electron/manager-api.js.map +1 -1
- package/dist/electron/media-controller.d.ts +79 -0
- package/dist/electron/media-controller.js +248 -0
- package/dist/electron/media-controller.js.map +1 -0
- package/dist/electron/network-monitor.d.ts +61 -0
- package/dist/electron/network-monitor.js +117 -0
- package/dist/electron/network-monitor.js.map +1 -0
- package/dist/electron/preload.js.map +1 -1
- package/dist/electron/presentation-handler.d.ts +39 -4
- package/dist/electron/presentation-handler.js +192 -48
- package/dist/electron/presentation-handler.js.map +1 -1
- package/dist/electron/presentation-source.d.ts +76 -0
- package/dist/electron/presentation-source.js +125 -0
- package/dist/electron/presentation-source.js.map +1 -0
- package/dist/electron/session-service.d.ts +198 -24
- package/dist/electron/session-service.js +629 -248
- package/dist/electron/session-service.js.map +1 -1
- package/dist/electron/session-tracker.d.ts +82 -0
- package/dist/electron/session-tracker.js +219 -0
- package/dist/electron/session-tracker.js.map +1 -0
- package/dist/electron/sink-service.d.ts +246 -0
- package/dist/electron/sink-service.js +602 -0
- package/dist/electron/sink-service.js.map +1 -0
- package/dist/electron/wired-display/controller.d.ts +76 -0
- package/dist/electron/wired-display/controller.js +194 -0
- package/dist/electron/wired-display/controller.js.map +1 -0
- package/dist/electron/wired-display/displays.d.ts +44 -0
- package/dist/electron/wired-display/displays.js +91 -0
- package/dist/electron/wired-display/displays.js.map +1 -0
- package/dist/electron/wired-display/electron-windows.d.ts +111 -0
- package/dist/electron/wired-display/electron-windows.js +301 -0
- package/dist/electron/wired-display/electron-windows.js.map +1 -0
- package/dist/electron/wired-display/index.d.ts +90 -0
- package/dist/electron/wired-display/index.js +99 -0
- package/dist/electron/wired-display/index.js.map +1 -0
- package/dist/electron/wired-display/local-presentation.d.ts +98 -0
- package/dist/electron/wired-display/local-presentation.js +228 -0
- package/dist/electron/wired-display/local-presentation.js.map +1 -0
- package/dist/electron/wired-display/provider.d.ts +112 -0
- package/dist/electron/wired-display/provider.js +197 -0
- package/dist/electron/wired-display/provider.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mirroring/backend.d.ts +76 -0
- package/dist/mirroring/backend.js +18 -0
- package/dist/mirroring/backend.js.map +1 -0
- package/dist/mirroring/electron/agent-protocol.d.ts +158 -0
- package/dist/mirroring/electron/agent-protocol.js +10 -0
- package/dist/mirroring/electron/agent-protocol.js.map +1 -0
- package/dist/mirroring/electron/agent-source.d.ts +20 -0
- package/dist/mirroring/electron/agent-source.js +618 -0
- package/dist/mirroring/electron/agent-source.js.map +1 -0
- package/dist/mirroring/electron/engine-process.d.ts +87 -0
- package/dist/mirroring/electron/engine-process.js +78 -0
- package/dist/mirroring/electron/engine-process.js.map +1 -0
- package/dist/mirroring/electron/host.d.ts +89 -0
- package/dist/mirroring/electron/host.js +318 -0
- package/dist/mirroring/electron/host.js.map +1 -0
- package/dist/mirroring/electron/port-backend.d.ts +107 -0
- package/dist/mirroring/electron/port-backend.js +441 -0
- package/dist/mirroring/electron/port-backend.js.map +1 -0
- package/dist/mirroring/encoding-support.d.ts +66 -0
- package/dist/mirroring/encoding-support.js +81 -0
- package/dist/mirroring/encoding-support.js.map +1 -0
- package/dist/mirroring/engine.d.ts +16 -0
- package/dist/mirroring/engine.js +75 -0
- package/dist/mirroring/engine.js.map +1 -0
- package/dist/mirroring/mirror-settings.d.ts +101 -0
- package/dist/mirroring/mirror-settings.js +134 -0
- package/dist/mirroring/mirror-settings.js.map +1 -0
- package/dist/mirroring/mirroring-activity.d.ts +207 -0
- package/dist/mirroring/mirroring-activity.js +362 -0
- package/dist/mirroring/mirroring-activity.js.map +1 -0
- package/dist/mirroring/mirroring-manager.d.ts +134 -0
- package/dist/mirroring/mirroring-manager.js +281 -0
- package/dist/mirroring/mirroring-manager.js.map +1 -0
- package/dist/mirroring/protocol/answer.d.ts +87 -0
- package/dist/mirroring/protocol/answer.js +226 -0
- package/dist/mirroring/protocol/answer.js.map +1 -0
- package/dist/mirroring/protocol/constants.d.ts +64 -0
- package/dist/mirroring/protocol/constants.js +66 -0
- package/dist/mirroring/protocol/constants.js.map +1 -0
- package/dist/mirroring/protocol/errors.d.ts +25 -0
- package/dist/mirroring/protocol/errors.js +29 -0
- package/dist/mirroring/protocol/errors.js.map +1 -0
- package/dist/mirroring/protocol/frame-id.d.ts +9 -0
- package/dist/mirroring/protocol/frame-id.js +20 -0
- package/dist/mirroring/protocol/frame-id.js.map +1 -0
- package/dist/mirroring/protocol/messenger.d.ts +42 -0
- package/dist/mirroring/protocol/messenger.js +118 -0
- package/dist/mirroring/protocol/messenger.js.map +1 -0
- package/dist/mirroring/protocol/offer.d.ts +109 -0
- package/dist/mirroring/protocol/offer.js +176 -0
- package/dist/mirroring/protocol/offer.js.map +1 -0
- package/dist/mirroring/protocol/recommendations.d.ts +28 -0
- package/dist/mirroring/protocol/recommendations.js +99 -0
- package/dist/mirroring/protocol/recommendations.js.map +1 -0
- package/dist/mirroring/routing.d.ts +60 -0
- package/dist/mirroring/routing.js +130 -0
- package/dist/mirroring/routing.js.map +1 -0
- package/dist/mirroring/rtcp/ntp.d.ts +27 -0
- package/dist/mirroring/rtcp/ntp.js +57 -0
- package/dist/mirroring/rtcp/ntp.js.map +1 -0
- package/dist/mirroring/rtcp/parser.d.ts +50 -0
- package/dist/mirroring/rtcp/parser.js +265 -0
- package/dist/mirroring/rtcp/parser.js.map +1 -0
- package/dist/mirroring/rtcp/sender-report.d.ts +32 -0
- package/dist/mirroring/rtcp/sender-report.js +51 -0
- package/dist/mirroring/rtcp/sender-report.js.map +1 -0
- package/dist/mirroring/rtcp/wire.d.ts +54 -0
- package/dist/mirroring/rtcp/wire.js +68 -0
- package/dist/mirroring/rtcp/wire.js.map +1 -0
- package/dist/mirroring/rtp/frame-crypto.d.ts +11 -0
- package/dist/mirroring/rtp/frame-crypto.js +35 -0
- package/dist/mirroring/rtp/frame-crypto.js.map +1 -0
- package/dist/mirroring/rtp/frame.d.ts +23 -0
- package/dist/mirroring/rtp/frame.js +2 -0
- package/dist/mirroring/rtp/frame.js.map +1 -0
- package/dist/mirroring/rtp/packetizer.d.ts +27 -0
- package/dist/mirroring/rtp/packetizer.js +88 -0
- package/dist/mirroring/rtp/packetizer.js.map +1 -0
- package/dist/mirroring/sender/audio-sender.d.ts +23 -0
- package/dist/mirroring/sender/audio-sender.js +54 -0
- package/dist/mirroring/sender/audio-sender.js.map +1 -0
- package/dist/mirroring/sender/bandwidth-estimator.d.ts +26 -0
- package/dist/mirroring/sender/bandwidth-estimator.js +103 -0
- package/dist/mirroring/sender/bandwidth-estimator.js.map +1 -0
- package/dist/mirroring/sender/capture-size-oracle.d.ts +121 -0
- package/dist/mirroring/sender/capture-size-oracle.js +433 -0
- package/dist/mirroring/sender/capture-size-oracle.js.map +1 -0
- package/dist/mirroring/sender/frame-sender.d.ts +103 -0
- package/dist/mirroring/sender/frame-sender.js +212 -0
- package/dist/mirroring/sender/frame-sender.js.map +1 -0
- package/dist/mirroring/sender/packet-router.d.ts +74 -0
- package/dist/mirroring/sender/packet-router.js +191 -0
- package/dist/mirroring/sender/packet-router.js.map +1 -0
- package/dist/mirroring/sender/sender-session.d.ts +85 -0
- package/dist/mirroring/sender/sender-session.js +235 -0
- package/dist/mirroring/sender/sender-session.js.map +1 -0
- package/dist/mirroring/sender/sender.d.ts +120 -0
- package/dist/mirroring/sender/sender.js +452 -0
- package/dist/mirroring/sender/sender.js.map +1 -0
- package/dist/mirroring/sender/video-encoder-metrics.d.ts +29 -0
- package/dist/mirroring/sender/video-encoder-metrics.js +58 -0
- package/dist/mirroring/sender/video-encoder-metrics.js.map +1 -0
- package/dist/mirroring/sender/video-sender.d.ts +95 -0
- package/dist/mirroring/sender/video-sender.js +190 -0
- package/dist/mirroring/sender/video-sender.js.map +1 -0
- package/dist/mirroring/session-host.d.ts +185 -0
- package/dist/mirroring/session-host.js +625 -0
- package/dist/mirroring/session-host.js.map +1 -0
- package/dist/mirroring/stats/clock-offset-estimator.d.ts +11 -0
- package/dist/mirroring/stats/clock-offset-estimator.js +120 -0
- package/dist/mirroring/stats/clock-offset-estimator.js.map +1 -0
- package/dist/mirroring/stats/openscreen-stats-client.d.ts +12 -0
- package/dist/mirroring/stats/openscreen-stats-client.js +17 -0
- package/dist/mirroring/stats/openscreen-stats-client.js.map +1 -0
- package/dist/mirroring/stats/sorted-map.d.ts +23 -0
- package/dist/mirroring/stats/sorted-map.js +66 -0
- package/dist/mirroring/stats/sorted-map.js.map +1 -0
- package/dist/mirroring/stats/statistics-analyzer.d.ts +50 -0
- package/dist/mirroring/stats/statistics-analyzer.js +335 -0
- package/dist/mirroring/stats/statistics-analyzer.js.map +1 -0
- package/dist/mirroring/stats/statistics-collector.d.ts +29 -0
- package/dist/mirroring/stats/statistics-collector.js +49 -0
- package/dist/mirroring/stats/statistics-collector.js.map +1 -0
- package/dist/mirroring/stats/statistics-common.d.ts +61 -0
- package/dist/mirroring/stats/statistics-common.js +39 -0
- package/dist/mirroring/stats/statistics-common.js.map +1 -0
- package/dist/mirroring/stats/statistics-dispatcher.d.ts +28 -0
- package/dist/mirroring/stats/statistics-dispatcher.js +100 -0
- package/dist/mirroring/stats/statistics-dispatcher.js.map +1 -0
- package/dist/mirroring/stats/statistics.d.ts +84 -0
- package/dist/mirroring/stats/statistics.js +141 -0
- package/dist/mirroring/stats/statistics.js.map +1 -0
- package/dist/mirroring/transport/udp-environment.d.ts +40 -0
- package/dist/mirroring/transport/udp-environment.js +93 -0
- package/dist/mirroring/transport/udp-environment.js.map +1 -0
- package/dist/polyfill/bridge-types.d.ts +11 -0
- package/dist/polyfill/presentation-receiver.d.ts +12 -0
- package/dist/polyfill/presentation-receiver.js +366 -0
- package/dist/polyfill/presentation-receiver.js.map +1 -0
- package/dist/polyfill/presentation-standin.js +157 -15
- package/dist/polyfill/presentation-standin.js.map +1 -1
- package/dist/protocol/framing.d.ts +1 -1
- package/dist/protocol/framing.js +1 -1
- package/dist/protocol/framing.js.map +1 -1
- package/docs/API.md +724 -0
- package/docs/ARCHITECTURE.md +242 -0
- package/docs/CHROMIUM-MAP.md +176 -0
- package/docs/DESIGN.md +1189 -0
- package/docs/FAQ.md +123 -0
- package/docs/GETTING-STARTED.md +248 -0
- package/docs/MAIN-API.md +524 -0
- package/docs/TROUBLESHOOTING.md +283 -0
- package/docs/guides/audio-and-groups.md +75 -0
- package/docs/guides/custom-receivers.md +109 -0
- package/docs/guides/device-authentication.md +145 -0
- package/docs/guides/device-picker.md +176 -0
- package/docs/guides/index.md +17 -0
- package/docs/guides/low-level-client.md +103 -0
- package/docs/guides/restart-rejoin.md +172 -0
- package/docs/guides/testing.md +162 -0
- package/docs/guides/windows-and-iframes.md +116 -0
- package/docs/readme/badges/dependencies.svg +1 -0
- package/docs/readme/badges/electron.svg +1 -0
- package/docs/readme/badges/license.svg +1 -0
- package/docs/readme/badges/node.svg +1 -0
- package/docs/readme/board.jpg +0 -0
- package/docs/readme/hero-dark.jpg +0 -0
- package/docs/readme/hero-light.jpg +0 -0
- package/docs/readme/nosignal.jpg +0 -0
- package/docs/readme/parity.jpg +0 -0
- package/docs/readme/trace.svg +22 -0
- package/package.json +21 -5
- package/src/cli.ts +57 -0
- package/src/client/auth/cast-auth.ts +2 -0
- package/src/dial/dial-registry.ts +316 -0
- package/src/dial/dial-sink-service.ts +343 -0
- package/src/dial/http.ts +200 -0
- package/src/dial/index.ts +135 -0
- package/src/dial/origins.ts +31 -0
- package/src/dial/parse.ts +319 -0
- package/src/dial/route-provider.ts +429 -0
- package/src/dial/ssdp-socket.ts +79 -0
- package/src/dial/xml.ts +180 -0
- package/src/dial-test/cli-main.ts +146 -0
- package/src/dial-test/report.ts +109 -0
- package/src/dial-test/runner.ts +615 -0
- package/src/dial-test/scrub.ts +74 -0
- package/src/discovery/cast-discovery.ts +2 -0
- package/src/discovery/device-cache.ts +5 -0
- package/src/discovery/index.ts +1 -0
- package/src/discovery/ip-policy.ts +97 -0
- package/src/discovery/udp-socket.ts +3 -0
- package/src/electron/access-code.ts +681 -0
- package/src/electron/app-discovery.ts +244 -0
- package/src/electron/default-presentation.ts +104 -0
- package/src/electron/main.ts +664 -29
- package/src/electron/manager-api.ts +367 -15
- package/src/electron/media-controller.ts +313 -0
- package/src/electron/network-monitor.ts +140 -0
- package/src/electron/preload.ts +1 -1
- package/src/electron/presentation-handler.ts +195 -48
- package/src/electron/presentation-source.ts +155 -0
- package/src/electron/session-service.ts +693 -238
- package/src/electron/session-tracker.ts +248 -0
- package/src/electron/sink-service.ts +726 -0
- package/src/electron/wired-display/controller.ts +212 -0
- package/src/electron/wired-display/displays.ts +107 -0
- package/src/electron/wired-display/electron-windows.ts +386 -0
- package/src/electron/wired-display/index.ts +181 -0
- package/src/electron/wired-display/local-presentation.ts +286 -0
- package/src/electron/wired-display/provider.ts +276 -0
- package/src/index.ts +1 -0
- package/src/mirroring/backend.ts +103 -0
- package/src/mirroring/electron/agent-protocol.ts +84 -0
- package/src/mirroring/electron/agent-source.ts +619 -0
- package/src/mirroring/electron/engine-process.ts +131 -0
- package/src/mirroring/electron/host.ts +361 -0
- package/src/mirroring/electron/port-backend.ts +466 -0
- package/src/mirroring/encoding-support.ts +146 -0
- package/src/mirroring/engine.ts +91 -0
- package/src/mirroring/mirror-settings.ts +174 -0
- package/src/mirroring/mirroring-activity.ts +466 -0
- package/src/mirroring/mirroring-manager.ts +342 -0
- package/src/mirroring/protocol/answer.ts +285 -0
- package/src/mirroring/protocol/constants.ts +75 -0
- package/src/mirroring/protocol/errors.ts +36 -0
- package/src/mirroring/protocol/frame-id.ts +20 -0
- package/src/mirroring/protocol/messenger.ts +128 -0
- package/src/mirroring/protocol/offer.ts +275 -0
- package/src/mirroring/protocol/recommendations.ts +135 -0
- package/src/mirroring/routing.ts +160 -0
- package/src/mirroring/rtcp/ntp.ts +61 -0
- package/src/mirroring/rtcp/parser.ts +292 -0
- package/src/mirroring/rtcp/sender-report.ts +88 -0
- package/src/mirroring/rtcp/wire.ts +76 -0
- package/src/mirroring/rtp/frame-crypto.ts +38 -0
- package/src/mirroring/rtp/frame.ts +25 -0
- package/src/mirroring/rtp/packetizer.ts +95 -0
- package/src/mirroring/sender/audio-sender.ts +59 -0
- package/src/mirroring/sender/bandwidth-estimator.ts +111 -0
- package/src/mirroring/sender/capture-size-oracle.ts +476 -0
- package/src/mirroring/sender/frame-sender.ts +293 -0
- package/src/mirroring/sender/packet-router.ts +228 -0
- package/src/mirroring/sender/sender-session.ts +306 -0
- package/src/mirroring/sender/sender.ts +497 -0
- package/src/mirroring/sender/video-encoder-metrics.ts +64 -0
- package/src/mirroring/sender/video-sender.ts +243 -0
- package/src/mirroring/session-host.ts +725 -0
- package/src/mirroring/stats/clock-offset-estimator.ts +139 -0
- package/src/mirroring/stats/openscreen-stats-client.ts +19 -0
- package/src/mirroring/stats/sorted-map.ts +68 -0
- package/src/mirroring/stats/statistics-analyzer.ts +388 -0
- package/src/mirroring/stats/statistics-collector.ts +69 -0
- package/src/mirroring/stats/statistics-common.ts +112 -0
- package/src/mirroring/stats/statistics-dispatcher.ts +133 -0
- package/src/mirroring/stats/statistics.ts +170 -0
- package/src/mirroring/transport/udp-environment.ts +100 -0
- package/src/polyfill/bridge-types.ts +11 -0
- package/src/polyfill/presentation-receiver.ts +350 -0
- package/src/polyfill/presentation-standin.ts +147 -15
- package/src/protocol/framing.ts +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { CastTimeoutError } from "../client/index.js";
|
|
2
|
-
import { ObservedMap, createPickerContext, createSinksObservers, } from "./manager-api.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";
|
|
3
8
|
/** Capability bit names in bit order: 1 video_out, 2 video_in, 4 audio_out, 8 audio_in, 32 multizone_group. */
|
|
4
9
|
export function capabilityNames(bits) {
|
|
5
10
|
const names = [];
|
|
@@ -15,6 +20,27 @@ export function capabilityNames(bits) {
|
|
|
15
20
|
names.push("multizone_group");
|
|
16
21
|
return names;
|
|
17
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
|
+
}
|
|
18
44
|
const CAPABILITY_BITS = {
|
|
19
45
|
video_out: 1,
|
|
20
46
|
video_in: 2,
|
|
@@ -68,7 +94,30 @@ function parseRequestSession(params) {
|
|
|
68
94
|
const timeout = timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : timeoutMs;
|
|
69
95
|
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0)
|
|
70
96
|
return null;
|
|
71
|
-
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 };
|
|
72
121
|
}
|
|
73
122
|
function parseSessionId(params) {
|
|
74
123
|
if (!isRecord(params) || typeof params.sessionId !== "string")
|
|
@@ -149,16 +198,110 @@ export class CastSessionService {
|
|
|
149
198
|
sessions = new ObservedMap((kind, rec) => this.notifySession(kind, rec));
|
|
150
199
|
sessionListeners = new Set();
|
|
151
200
|
sinks;
|
|
152
|
-
|
|
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();
|
|
153
208
|
pendingRequests = new Map();
|
|
154
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
|
+
};
|
|
155
218
|
disposed = false;
|
|
219
|
+
unobserveNetwork;
|
|
156
220
|
constructor(options) {
|
|
157
221
|
this.options = options;
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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();
|
|
162
305
|
}
|
|
163
306
|
/** Handle one bridge call; never throws or rejects. */
|
|
164
307
|
async handle(sender, method, params) {
|
|
@@ -172,8 +315,17 @@ export class CastSessionService {
|
|
|
172
315
|
return this.handleInitialize(sender, params);
|
|
173
316
|
case "requestSession":
|
|
174
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 : "" });
|
|
175
321
|
case "joinSession":
|
|
176
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
|
+
});
|
|
177
329
|
case "joinRunningSession":
|
|
178
330
|
return await this.handleJoinRunningSession(sender, params);
|
|
179
331
|
case "sendMessage":
|
|
@@ -232,26 +384,158 @@ export class CastSessionService {
|
|
|
232
384
|
if (this.disposed)
|
|
233
385
|
return;
|
|
234
386
|
this.disposed = true;
|
|
387
|
+
this.unobserveNetwork();
|
|
235
388
|
this.sinks.dispose();
|
|
236
|
-
|
|
237
|
-
d.off("deviceUp", this.deviceListener);
|
|
238
|
-
d.off("deviceDown", this.deviceListener);
|
|
239
|
-
d.off("deviceChanged", this.deviceListener);
|
|
389
|
+
this.accessCode.dispose();
|
|
240
390
|
for (const pending of this.pendingRequests.values())
|
|
241
391
|
pending.picker?.close();
|
|
242
|
-
const entries = [...this.clients.values()];
|
|
243
|
-
this.clients.clear();
|
|
244
|
-
for (const entry of entries)
|
|
245
|
-
entry.client.close();
|
|
246
392
|
this.sessions.clear();
|
|
393
|
+
this.tracker.dispose();
|
|
394
|
+
this.appDiscovery.dispose();
|
|
395
|
+
this.sinkService.dispose();
|
|
247
396
|
this.senders.clear();
|
|
248
397
|
this.pendingRequests.clear();
|
|
249
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
|
+
}
|
|
250
534
|
handleInitialize(sender, params) {
|
|
251
535
|
const p = parseInitialize(params);
|
|
252
536
|
if (p === null)
|
|
253
537
|
return bad("invalid_parameter");
|
|
254
|
-
const available = this.
|
|
538
|
+
const available = this.sinkService.devices().some((d) => deviceMatches(d, p.capabilities));
|
|
255
539
|
this.senders.set(sender.id, { appId: p.appId, capabilities: p.capabilities, lastAvailable: available });
|
|
256
540
|
const joined = [];
|
|
257
541
|
for (const rec of this.sessions.values()) {
|
|
@@ -268,45 +552,97 @@ export class CastSessionService {
|
|
|
268
552
|
}
|
|
269
553
|
return good({ available, sessions: joined });
|
|
270
554
|
}
|
|
271
|
-
|
|
272
|
-
|
|
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);
|
|
273
564
|
if (p === null)
|
|
274
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) : []);
|
|
275
571
|
if (this.pendingRequests.has(sender.id))
|
|
276
572
|
return bad("invalid_parameter");
|
|
277
573
|
const discard = { value: false };
|
|
278
574
|
const cancelled = { value: false };
|
|
279
575
|
const pending = { discard, cancelled };
|
|
280
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;
|
|
281
583
|
try {
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
|
|
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
|
+
}
|
|
285
602
|
const request = {
|
|
286
|
-
appId:
|
|
287
|
-
capabilities
|
|
603
|
+
appId: appId ?? "",
|
|
604
|
+
capabilities,
|
|
288
605
|
origin: sender.origin,
|
|
289
606
|
senderId: sender.id,
|
|
290
607
|
};
|
|
291
|
-
const current = this.currentSessionFor(sender.id,
|
|
608
|
+
const current = appId === null ? undefined : this.currentSessionFor(sender.id, appId);
|
|
292
609
|
if (current !== undefined) {
|
|
293
610
|
request.session = { sessionId: current.app.sessionId, deviceId: current.device.id };
|
|
294
611
|
}
|
|
295
612
|
let choice;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
choice = await this.options.selectDevice(eligible, request, pick.context);
|
|
613
|
+
if (presetDeviceId !== undefined) {
|
|
614
|
+
choice = eligible.find((d) => d.id === presetDeviceId) ?? null;
|
|
615
|
+
if (choice === null)
|
|
616
|
+
return bad("receiver_unavailable");
|
|
301
617
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
+
}
|
|
307
635
|
}
|
|
308
636
|
if (choice === null)
|
|
309
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");
|
|
310
646
|
if (choice === "stop") {
|
|
311
647
|
const rec = request.session !== undefined ? this.sessions.get(request.session.sessionId) : undefined;
|
|
312
648
|
if (rec === undefined)
|
|
@@ -316,7 +652,9 @@ export class CastSessionService {
|
|
|
316
652
|
const stopped = await this.stopSessionRecord(rec, sender.id, true);
|
|
317
653
|
return stopped.ok ? bad("cancel") : stopped;
|
|
318
654
|
}
|
|
319
|
-
|
|
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) {
|
|
320
658
|
const rec = this.sessions.get(request.session.sessionId);
|
|
321
659
|
if (rec !== undefined)
|
|
322
660
|
return good(this.snapshotOf(rec));
|
|
@@ -330,7 +668,7 @@ export class CastSessionService {
|
|
|
330
668
|
}, p.timeoutMs);
|
|
331
669
|
});
|
|
332
670
|
try {
|
|
333
|
-
const snapshot = await Promise.race([this.openSession(choice,
|
|
671
|
+
const snapshot = await Promise.race([this.openSession(choice, appId, sender, discard, cancelled), bound]);
|
|
334
672
|
return good(snapshot);
|
|
335
673
|
}
|
|
336
674
|
catch (err) {
|
|
@@ -346,6 +684,9 @@ export class CastSessionService {
|
|
|
346
684
|
}
|
|
347
685
|
}
|
|
348
686
|
finally {
|
|
687
|
+
combined?.dispose();
|
|
688
|
+
appSinks?.close();
|
|
689
|
+
stopMonitoring?.();
|
|
349
690
|
this.pendingRequests.delete(sender.id);
|
|
350
691
|
}
|
|
351
692
|
}
|
|
@@ -399,7 +740,7 @@ export class CastSessionService {
|
|
|
399
740
|
async stopSessionRecord(rec, caller, tellCaller) {
|
|
400
741
|
rec.stoppingBy = caller;
|
|
401
742
|
try {
|
|
402
|
-
await rec.client.stop(rec.app.sessionId);
|
|
743
|
+
this.tracker.applyStatus(rec.device.id, rec.client, await rec.client.stop(rec.app.sessionId));
|
|
403
744
|
}
|
|
404
745
|
catch (err) {
|
|
405
746
|
rec.stoppingBy = undefined;
|
|
@@ -418,7 +759,6 @@ export class CastSessionService {
|
|
|
418
759
|
else if (tellCaller) {
|
|
419
760
|
this.emitTo(caller, { type: "sessionEnded", sessionId: rec.app.sessionId, status: "stopped" });
|
|
420
761
|
}
|
|
421
|
-
this.cleanupIdle(rec.device.id, rec.client);
|
|
422
762
|
return good(undefined);
|
|
423
763
|
}
|
|
424
764
|
/** The sender's current session for the app, if it has one (the first one found). */
|
|
@@ -447,7 +787,7 @@ export class CastSessionService {
|
|
|
447
787
|
if (rec === undefined || !rec.members.has(sender.id))
|
|
448
788
|
return bad("session_error");
|
|
449
789
|
try {
|
|
450
|
-
await rec.client.setVolume({ level: p.level });
|
|
790
|
+
this.tracker.applyStatus(rec.device.id, rec.client, await rec.client.setVolume({ level: p.level }));
|
|
451
791
|
}
|
|
452
792
|
catch (err) {
|
|
453
793
|
return bad("session_error", describe(err));
|
|
@@ -462,43 +802,20 @@ export class CastSessionService {
|
|
|
462
802
|
if (rec === undefined || !rec.members.has(sender.id))
|
|
463
803
|
return bad("session_error");
|
|
464
804
|
try {
|
|
465
|
-
await rec.client.setVolume({ muted: p.muted });
|
|
805
|
+
this.tracker.applyStatus(rec.device.id, rec.client, await rec.client.setVolume({ muted: p.muted }));
|
|
466
806
|
}
|
|
467
807
|
catch (err) {
|
|
468
808
|
return bad("session_error", describe(err));
|
|
469
809
|
}
|
|
470
810
|
return good(undefined);
|
|
471
811
|
}
|
|
472
|
-
/** The device's client entry, created and connecting on first use. */
|
|
473
|
-
clientFor(device) {
|
|
474
|
-
const existing = this.clients.get(device.id);
|
|
475
|
-
if (existing !== undefined)
|
|
476
|
-
return existing;
|
|
477
|
-
const client = this.options.createClient(device);
|
|
478
|
-
this.bindClient(client, device);
|
|
479
|
-
const entry = {
|
|
480
|
-
client,
|
|
481
|
-
device,
|
|
482
|
-
ready: client.connect().catch((err) => {
|
|
483
|
-
// Remove the entry and close the client once so the next request starts fresh.
|
|
484
|
-
this.dropClient(device.id, client);
|
|
485
|
-
throw err;
|
|
486
|
-
}),
|
|
487
|
-
opening: 0,
|
|
488
|
-
};
|
|
489
|
-
// A lookup may never await this; openSession still sees the rejection.
|
|
490
|
-
entry.ready.catch(() => { });
|
|
491
|
-
this.clients.set(device.id, entry);
|
|
492
|
-
return entry;
|
|
493
|
-
}
|
|
494
812
|
/**
|
|
495
813
|
* Join a session by its id, as Chrome's Media Router does for `reconnect("cast-session_<id>")`. A session this
|
|
496
814
|
* service already holds is joined without an origin check, like one found on a device. Otherwise the id is looked up
|
|
497
|
-
* in the
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
* the lookup runs when asked instead of tracking every device all the time.
|
|
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.
|
|
502
819
|
*/
|
|
503
820
|
async handleJoinRunningSession(sender, params) {
|
|
504
821
|
const p = parseSessionId(params);
|
|
@@ -511,153 +828,115 @@ export class CastSessionService {
|
|
|
511
828
|
return bad("session_error");
|
|
512
829
|
return this.handleJoinSession(sender, params, false);
|
|
513
830
|
}
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
831
|
+
const tracked = this.tracker.sessionById(p.sessionId);
|
|
832
|
+
if (tracked === undefined || this.disposed || (appId !== undefined && tracked.appId !== appId))
|
|
516
833
|
return bad("session_error");
|
|
517
|
-
const
|
|
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);
|
|
518
868
|
try {
|
|
519
|
-
|
|
520
|
-
return bad("session_error");
|
|
521
|
-
// Another join of the same session finished while this one looked.
|
|
522
|
-
if (this.sessions.has(app.sessionId))
|
|
523
|
-
return this.handleJoinSession(sender, params, false);
|
|
524
|
-
entry.client.connectTransport(app.transportId);
|
|
525
|
-
const rec = {
|
|
526
|
-
device: entry.device,
|
|
527
|
-
client: entry.client,
|
|
528
|
-
app,
|
|
529
|
-
origin: sender.origin,
|
|
530
|
-
appId: app.appId,
|
|
531
|
-
members: new Set([sender.id]),
|
|
532
|
-
parked: new Set(),
|
|
533
|
-
lastVolume: volume,
|
|
534
|
-
lastSnapshot: null,
|
|
535
|
-
};
|
|
536
|
-
rec.lastSnapshot = this.snapshotOf(rec);
|
|
537
|
-
this.sessions.set(app.sessionId, rec);
|
|
538
|
-
return good(rec.lastSnapshot);
|
|
869
|
+
return await this.launchOn(device, client, appId, sender, discard, cancelled);
|
|
539
870
|
}
|
|
540
871
|
finally {
|
|
541
|
-
|
|
542
|
-
if (
|
|
543
|
-
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();
|
|
544
880
|
}
|
|
545
881
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
* stays raised for the caller to release; a device that cannot be reached or runs something else is let go.
|
|
549
|
-
*/
|
|
550
|
-
findRunningSession(sessionId) {
|
|
551
|
-
const devices = this.options.devices.devices();
|
|
552
|
-
return new Promise((resolve) => {
|
|
553
|
-
let pending = devices.length;
|
|
554
|
-
let won = false;
|
|
555
|
-
if (pending === 0)
|
|
556
|
-
resolve(undefined);
|
|
557
|
-
for (const device of devices) {
|
|
558
|
-
const entry = this.clientFor(device);
|
|
559
|
-
entry.opening += 1;
|
|
560
|
-
void (async () => {
|
|
561
|
-
let app;
|
|
562
|
-
let volume;
|
|
563
|
-
try {
|
|
564
|
-
await entry.ready;
|
|
565
|
-
const status = await entry.client.getStatus();
|
|
566
|
-
app = status.applications.find((a) => a.sessionId === sessionId);
|
|
567
|
-
volume = status.volume;
|
|
568
|
-
}
|
|
569
|
-
catch {
|
|
570
|
-
// unreachable: not this device
|
|
571
|
-
}
|
|
572
|
-
if (app !== undefined && volume !== undefined && !won) {
|
|
573
|
-
won = true;
|
|
574
|
-
resolve({ entry, app, volume });
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
entry.opening -= 1;
|
|
578
|
-
this.cleanupIdle(device.id, entry.client);
|
|
579
|
-
pending -= 1;
|
|
580
|
-
if (pending === 0 && !won)
|
|
581
|
-
resolve(undefined);
|
|
582
|
-
})();
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
/** Connect (or reuse) the device's client, launch the app and register the session. */
|
|
587
|
-
async openSession(device, appId, sender, discard, cancelled) {
|
|
588
|
-
const entry = this.clientFor(device);
|
|
589
|
-
const client = entry.client;
|
|
590
|
-
entry.opening += 1;
|
|
591
|
-
let registered = false;
|
|
882
|
+
async launchOn(device, client, appId, sender, discard, cancelled) {
|
|
883
|
+
let app;
|
|
592
884
|
try {
|
|
593
|
-
|
|
594
|
-
await entry.ready;
|
|
595
|
-
}
|
|
596
|
-
catch (err) {
|
|
597
|
-
if (err instanceof CastTimeoutError)
|
|
598
|
-
throw new MappedError("timeout", err.message);
|
|
599
|
-
throw new MappedError("receiver_unavailable", describe(err));
|
|
600
|
-
}
|
|
601
|
-
if (discard.value)
|
|
602
|
-
throw new Discarded();
|
|
603
|
-
if (cancelled.value)
|
|
604
|
-
throw new MappedError("cancel", "cancelled");
|
|
605
|
-
let app;
|
|
606
|
-
try {
|
|
607
|
-
app = await client.launch(appId);
|
|
608
|
-
}
|
|
609
|
-
catch (err) {
|
|
610
|
-
if (err instanceof CastTimeoutError)
|
|
611
|
-
throw new MappedError("timeout", err.message);
|
|
612
|
-
throw new MappedError("session_error", describe(err));
|
|
613
|
-
}
|
|
614
|
-
if (discard.value) {
|
|
615
|
-
client.closeTransport(app.transportId);
|
|
616
|
-
throw new Discarded();
|
|
617
|
-
}
|
|
618
|
-
if (cancelled.value) {
|
|
619
|
-
client.closeTransport(app.transportId);
|
|
620
|
-
throw new MappedError("cancel", "cancelled");
|
|
621
|
-
}
|
|
622
|
-
client.connectTransport(app.transportId);
|
|
623
|
-
let status;
|
|
624
|
-
try {
|
|
625
|
-
status = await client.getStatus();
|
|
626
|
-
}
|
|
627
|
-
catch (err) {
|
|
628
|
-
client.closeTransport(app.transportId);
|
|
629
|
-
throw new MappedError("session_error", describe(err));
|
|
630
|
-
}
|
|
631
|
-
if (discard.value) {
|
|
632
|
-
client.closeTransport(app.transportId);
|
|
633
|
-
throw new Discarded();
|
|
634
|
-
}
|
|
635
|
-
if (cancelled.value) {
|
|
636
|
-
client.closeTransport(app.transportId);
|
|
637
|
-
throw new MappedError("cancel", "cancelled");
|
|
638
|
-
}
|
|
639
|
-
const rec = {
|
|
640
|
-
device,
|
|
641
|
-
client,
|
|
642
|
-
app,
|
|
643
|
-
origin: sender.origin,
|
|
644
|
-
appId,
|
|
645
|
-
members: new Set([sender.id]),
|
|
646
|
-
parked: new Set(),
|
|
647
|
-
lastVolume: status.volume,
|
|
648
|
-
lastSnapshot: null,
|
|
649
|
-
};
|
|
650
|
-
const snapshot = this.snapshotOf(rec);
|
|
651
|
-
rec.lastSnapshot = snapshot;
|
|
652
|
-
this.sessions.set(app.sessionId, rec);
|
|
653
|
-
registered = true;
|
|
654
|
-
return snapshot;
|
|
885
|
+
app = await client.launch(appId);
|
|
655
886
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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);
|
|
660
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;
|
|
661
940
|
}
|
|
662
941
|
/** Remove a sender from a session; when it was the last one, tear the session down. */
|
|
663
942
|
leave(rec, senderId) {
|
|
@@ -666,18 +945,17 @@ export class CastSessionService {
|
|
|
666
945
|
if (rec.members.size === 0 && rec.parked.size === 0) {
|
|
667
946
|
rec.client.closeTransport(rec.app.transportId);
|
|
668
947
|
this.sessions.delete(rec.app.sessionId);
|
|
669
|
-
this.cleanupIdle(rec.device.id, rec.client);
|
|
670
948
|
}
|
|
671
949
|
else {
|
|
672
950
|
this.notifySession("updated", rec);
|
|
673
951
|
}
|
|
674
952
|
}
|
|
675
|
-
/** Subscribe to a freshly
|
|
676
|
-
bindClient(client,
|
|
953
|
+
/** Subscribe to a freshly opened channel's events. */
|
|
954
|
+
bindClient(client, _device) {
|
|
677
955
|
client.on("message", (msg) => this.onClientMessage(client, msg));
|
|
678
|
-
client.on("receiverStatus", (status) => this.onClientStatus(client,
|
|
956
|
+
client.on("receiverStatus", (status) => this.onClientStatus(client, status));
|
|
679
957
|
client.on("transportClosed", (transportId) => this.onTransportClosed(client, transportId));
|
|
680
|
-
client.on("close", () => this.onClientClose(client
|
|
958
|
+
client.on("close", () => this.onClientClose(client));
|
|
681
959
|
}
|
|
682
960
|
onClientMessage(client, msg) {
|
|
683
961
|
if (typeof msg.data !== "string")
|
|
@@ -695,7 +973,7 @@ export class CastSessionService {
|
|
|
695
973
|
}
|
|
696
974
|
}
|
|
697
975
|
}
|
|
698
|
-
onClientStatus(client,
|
|
976
|
+
onClientStatus(client, status) {
|
|
699
977
|
for (const rec of [...this.sessions.values()]) {
|
|
700
978
|
if (rec.client !== client)
|
|
701
979
|
continue;
|
|
@@ -720,7 +998,6 @@ export class CastSessionService {
|
|
|
720
998
|
}
|
|
721
999
|
}
|
|
722
1000
|
}
|
|
723
|
-
this.cleanupIdle(device.id, client);
|
|
724
1001
|
}
|
|
725
1002
|
onTransportClosed(client, transportId) {
|
|
726
1003
|
for (const rec of [...this.sessions.values()]) {
|
|
@@ -732,10 +1009,7 @@ export class CastSessionService {
|
|
|
732
1009
|
}
|
|
733
1010
|
}
|
|
734
1011
|
}
|
|
735
|
-
onClientClose(client
|
|
736
|
-
const entry = this.clients.get(deviceId);
|
|
737
|
-
if (entry !== undefined && entry.client === client)
|
|
738
|
-
this.clients.delete(deviceId);
|
|
1012
|
+
onClientClose(client) {
|
|
739
1013
|
for (const rec of [...this.sessions.values()]) {
|
|
740
1014
|
if (rec.client !== client)
|
|
741
1015
|
continue;
|
|
@@ -749,7 +1023,7 @@ export class CastSessionService {
|
|
|
749
1023
|
onDevicesChanged() {
|
|
750
1024
|
if (this.disposed)
|
|
751
1025
|
return;
|
|
752
|
-
const devices = this.
|
|
1026
|
+
const devices = this.sinkService.devices();
|
|
753
1027
|
for (const [id, rec] of this.senders) {
|
|
754
1028
|
const available = devices.some((d) => deviceMatches(d, rec.capabilities));
|
|
755
1029
|
if (available !== rec.lastAvailable) {
|
|
@@ -758,60 +1032,130 @@ export class CastSessionService {
|
|
|
758
1032
|
}
|
|
759
1033
|
}
|
|
760
1034
|
}
|
|
761
|
-
/** Close the client when no session uses it any more and no openSession is in flight. */
|
|
762
|
-
cleanupIdle(deviceId, client) {
|
|
763
|
-
const entry = this.clients.get(deviceId);
|
|
764
|
-
if (entry !== undefined && entry.client === client && entry.opening > 0)
|
|
765
|
-
return;
|
|
766
|
-
for (const rec of this.sessions.values()) {
|
|
767
|
-
if (rec.client === client)
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
this.dropClient(deviceId, client);
|
|
771
|
-
}
|
|
772
|
-
/** Forget a client and close it; a no-op unless it is still the registered entry for the device. */
|
|
773
|
-
dropClient(deviceId, client) {
|
|
774
|
-
const entry = this.clients.get(deviceId);
|
|
775
|
-
if (entry === undefined || entry.client !== client)
|
|
776
|
-
return;
|
|
777
|
-
this.clients.delete(deviceId);
|
|
778
|
-
client.close();
|
|
779
|
-
}
|
|
780
1035
|
// Main-process API (see manager-api.ts). Control goes through the paths the pages use, so pages see the same events.
|
|
781
|
-
/**
|
|
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
|
+
*/
|
|
782
1044
|
mediaRoutes() {
|
|
783
|
-
|
|
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);
|
|
784
1052
|
}
|
|
785
1053
|
/** Be told when a session starts, changes (status, volume, pages) or ends; returns the unsubscribe function. */
|
|
786
1054
|
observeSessions(listener) {
|
|
787
1055
|
this.sessionListeners.add(listener);
|
|
788
1056
|
return () => void this.sessionListeners.delete(listener);
|
|
789
1057
|
}
|
|
790
|
-
/**
|
|
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
|
+
*/
|
|
791
1062
|
async terminateSession(sessionId) {
|
|
792
1063
|
const rec = this.sessions.get(sessionId);
|
|
793
|
-
if (rec === undefined)
|
|
794
|
-
return bad("session_error", "unknown session");
|
|
795
1064
|
// No page is the caller, so every member is told sessionEnded.
|
|
796
|
-
|
|
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);
|
|
797
1082
|
}
|
|
798
1083
|
async setSessionVolume(sessionId, volume) {
|
|
799
1084
|
const rec = this.sessions.get(sessionId);
|
|
800
|
-
|
|
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)
|
|
801
1089
|
return bad("session_error", "unknown session");
|
|
802
1090
|
try {
|
|
803
|
-
await
|
|
1091
|
+
this.tracker.applyStatus(sinkId, client, await client.setVolume(volume));
|
|
804
1092
|
}
|
|
805
1093
|
catch (err) {
|
|
806
1094
|
return bad("session_error", describe(err));
|
|
807
1095
|
}
|
|
808
1096
|
return good(undefined);
|
|
809
1097
|
}
|
|
810
|
-
/**
|
|
811
|
-
|
|
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) {
|
|
812
1122
|
const rec = this.sessions.get(sessionId);
|
|
813
|
-
|
|
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)
|
|
814
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));
|
|
1143
|
+
}
|
|
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;
|
|
1149
|
+
}
|
|
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
|
+
}
|
|
815
1159
|
for (const member of rec.members) {
|
|
816
1160
|
this.emitTo(member, { type: "sessionEnded", sessionId, status: "disconnected" });
|
|
817
1161
|
}
|
|
@@ -819,13 +1163,28 @@ export class CastSessionService {
|
|
|
819
1163
|
rec.parked.clear();
|
|
820
1164
|
rec.client.closeTransport(rec.app.transportId);
|
|
821
1165
|
this.sessions.delete(sessionId);
|
|
822
|
-
this.cleanupIdle(rec.device.id, rec.client);
|
|
823
1166
|
return good(undefined);
|
|
824
1167
|
}
|
|
825
1168
|
/** Tell the route observers something changed (the arguments only fit the ObservedMap callback). */
|
|
826
1169
|
notifySession(_kind, _rec) {
|
|
827
1170
|
if (this.disposed)
|
|
828
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)
|
|
1183
|
+
return;
|
|
1184
|
+
this.lastRoutesKey = key;
|
|
1185
|
+
this.fireSessionListeners();
|
|
1186
|
+
}
|
|
1187
|
+
fireSessionListeners() {
|
|
829
1188
|
for (const listener of [...this.sessionListeners]) {
|
|
830
1189
|
try {
|
|
831
1190
|
listener();
|
|
@@ -838,9 +1197,12 @@ export class CastSessionService {
|
|
|
838
1197
|
routeOf(rec) {
|
|
839
1198
|
return {
|
|
840
1199
|
id: rec.app.sessionId,
|
|
1200
|
+
providerId: "cast",
|
|
841
1201
|
mediaSource: `cast:${rec.appId}`,
|
|
842
1202
|
sinkId: rec.device.id,
|
|
1203
|
+
sinkName: rec.device.name,
|
|
843
1204
|
description: rec.app.statusText || rec.app.displayName,
|
|
1205
|
+
isLocal: true,
|
|
844
1206
|
appId: rec.appId,
|
|
845
1207
|
displayName: rec.app.displayName,
|
|
846
1208
|
origin: rec.origin,
|
|
@@ -850,6 +1212,25 @@ export class CastSessionService {
|
|
|
850
1212
|
parked: rec.members.size === 0,
|
|
851
1213
|
};
|
|
852
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
|
+
};
|
|
1233
|
+
}
|
|
853
1234
|
snapshotOf(rec) {
|
|
854
1235
|
const app = rec.app;
|
|
855
1236
|
const volume = {
|