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