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
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
// Opens and keeps a Cast channel to every discovered device and reports a device (a "sink") only while it has one, as
|
|
2
|
+
// Chrome's CastMediaSinkServiceImpl does (chrome/browser/media/router/discovery/mdns/cast_media_sink_service_impl.cc;
|
|
3
|
+
// docs/DESIGN.md lists each rule with its Chromium source). Nothing here is specific to an app.
|
|
4
|
+
import { EventEmitter } from "node:events";
|
|
5
|
+
import type { CastDevice } from "../discovery/index.ts";
|
|
6
|
+
import { isLoopback, isPubliclyRoutable, parseIpBytes } from "../discovery/ip-policy.ts";
|
|
7
|
+
import { processDeviceUuid } from "../dial/parse.ts";
|
|
8
|
+
import { isNetworkIdUnknownOrDisconnected } from "./network-monitor.ts";
|
|
9
|
+
import type { CastClientLike, DeviceSource } from "./session-service.ts";
|
|
10
|
+
|
|
11
|
+
/** How a channel is opened (Chrome: `CastSocketOpenParams`, built by `CreateCastSocketOpenParams`). */
|
|
12
|
+
export interface ChannelParams {
|
|
13
|
+
/** Connect timeout (TLS handshake and authentication reply). 10 s, longer after failures when a delta is set. */
|
|
14
|
+
connectTimeoutMs: number;
|
|
15
|
+
/** Idle time without a reply before the channel is declared dead. 10 s, longer after failures when a delta is set. */
|
|
16
|
+
livenessTimeoutMs: number;
|
|
17
|
+
/** Idle time before the device is pinged (Chrome: `ping_interval_in_seconds`). 5 s; 4 s for a device added by access code. */
|
|
18
|
+
pingIntervalMs: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A device and the open channel to it. */
|
|
22
|
+
export interface SinkChannel {
|
|
23
|
+
device: CastDevice;
|
|
24
|
+
client: CastClientLike;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Retry policy for opening a channel (Chrome: `CastMediaSinkServiceImpl::RetryParams` and the `BackoffEntry` policy
|
|
29
|
+
* built in its constructor). The defaults are Chrome's; they are exposed for tests.
|
|
30
|
+
*/
|
|
31
|
+
export interface SinkRetryOptions {
|
|
32
|
+
/** Delay before the first retry; later ones multiply by `multiplyFactor`. Default 15000 (`initial_delay_in_milliseconds`). */
|
|
33
|
+
initialDelayMs?: number;
|
|
34
|
+
/** Attempts in a row before the device is given up on. Default 3 (`max_retry_attempts`). */
|
|
35
|
+
maxAttempts?: number;
|
|
36
|
+
/** Default 1 (`multiply_factor`). */
|
|
37
|
+
multiplyFactor?: number;
|
|
38
|
+
/** A delay is cut by up to this fraction at random. Default 0.5 (the policy's `jitter_factor`). */
|
|
39
|
+
jitter?: number;
|
|
40
|
+
/** Default 30000 (the policy's `maximum_backoff_ms`). */
|
|
41
|
+
maxDelayMs?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** What the sink service does when and how; the defaults follow Chrome. */
|
|
45
|
+
export interface CastSinkOptions {
|
|
46
|
+
/**
|
|
47
|
+
* After discovery reports devices, channels open after a random delay of up to this many ms, so several apps do not
|
|
48
|
+
* hit one receiver at once. Default 5000 (`OpenChannelsWithRandomizedDelay`).
|
|
49
|
+
*/
|
|
50
|
+
openDelayMaxMs?: number;
|
|
51
|
+
/** Changes to the list of devices are reported once this quiet. Default 3000 (`kDiscoveryTimeout` in `MediaSinkServiceBase`). */
|
|
52
|
+
reportDelayMs?: number;
|
|
53
|
+
retry?: SinkRetryOptions;
|
|
54
|
+
/**
|
|
55
|
+
* Open channels to publicly routable and loopback addresses too. Default false: Chrome refuses them unless its
|
|
56
|
+
* `MediaRouterCastAllowAllIPs` policy is set (`CastMediaSinkServiceImpl::OpenChannel`, `SetCastAllowAllIPs`). The
|
|
57
|
+
* address checked is the one the channel is opened to, when it is opened. Mind that device addresses come from mDNS,
|
|
58
|
+
* which anyone on the network can answer.
|
|
59
|
+
*/
|
|
60
|
+
allowAllIps?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Added to the connect and liveness timeouts for each failed attempt on a device, up to 30 s and 60 s. Default 0, as in
|
|
63
|
+
* Chrome (`OpenParams::dynamic_timeout_delta_in_seconds` is 0 and nothing sets it), so the timeouts stay 10 s.
|
|
64
|
+
*/
|
|
65
|
+
dynamicTimeoutDeltaMs?: number;
|
|
66
|
+
/** For tests: a source of numbers in [0, 1). Default `Math.random`. */
|
|
67
|
+
random?: () => number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CastSinkServiceOptions extends CastSinkOptions {
|
|
71
|
+
source: DeviceSource;
|
|
72
|
+
createClient(device: CastDevice, params: ChannelParams): CastClientLike;
|
|
73
|
+
/**
|
|
74
|
+
* The DIAL sinks (devices with `dial` set; their `deviceChanged` says the list changed). A DIAL sink that is new or
|
|
75
|
+
* changed is tried as a Cast device, as `CastMediaSinkServiceImpl` observes `DialMediaSinkServiceImpl`
|
|
76
|
+
* (`OnSinkAddedOrUpdated` -> `TryConnectDialDiscoveredSink`).
|
|
77
|
+
*/
|
|
78
|
+
dial?: DeviceSource;
|
|
79
|
+
/**
|
|
80
|
+
* Whether something still uses a client the sink no longer lists. A replaced channel is not closed while it is in use
|
|
81
|
+
* (Chrome leaves the old socket alone, so a session on it goes on); call {@link CastSinkService.releaseUnused} when
|
|
82
|
+
* that may have changed. Default: nothing uses it.
|
|
83
|
+
*/
|
|
84
|
+
isClientInUse?(client: CastClientLike): boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface SinkRecord {
|
|
88
|
+
device: CastDevice;
|
|
89
|
+
/** How the sink was first opened (Chrome keeps it as the sink's `discovery_type`); a reopen keeps it. */
|
|
90
|
+
openedBy: OpenSource;
|
|
91
|
+
/** Undefined while the channel is down and being reopened (Chrome keeps the sink listed meanwhile). */
|
|
92
|
+
client: CastClientLike | undefined;
|
|
93
|
+
endpoint: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface SinkEvents {
|
|
97
|
+
deviceUp: [device: CastDevice];
|
|
98
|
+
deviceDown: [device: CastDevice];
|
|
99
|
+
deviceChanged: [device: CastDevice];
|
|
100
|
+
/** A channel opened (after device authentication); the sink is in `sinks()` but may not be reported yet. */
|
|
101
|
+
channelOpened: [channel: SinkChannel];
|
|
102
|
+
/** An open channel failed (keep-alive timeout, remote close...); a reopen follows. The sink stays until that gives up. */
|
|
103
|
+
channelClosed: [channel: SinkChannel, error: Error | undefined];
|
|
104
|
+
/** The sink left the list because its channel could not be reopened. */
|
|
105
|
+
sinkRemoved: [device: CastDevice];
|
|
106
|
+
/** A discovered device was left alone: its address is not an IP address a channel may be opened to. */
|
|
107
|
+
skipped: [device: CastDevice, reason: string];
|
|
108
|
+
/** The sink has a new channel; this one is no longer its own and is closed once nothing uses it. */
|
|
109
|
+
channelRetired: [client: CastClientLike];
|
|
110
|
+
/** An attempt to open a channel failed (it may be retried). */
|
|
111
|
+
openFailed: [device: CastDevice, error: Error, willRetry: boolean];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const endpointOf = (device: CastDevice): string => `${device.host}:${device.port}`;
|
|
115
|
+
|
|
116
|
+
const sameDevice = (a: CastDevice, b: CastDevice): boolean => JSON.stringify(a) === JSON.stringify(b);
|
|
117
|
+
|
|
118
|
+
type OpenSource = "discovery" | "retry-on-error" | "access-code" | "dial" | "network-cache";
|
|
119
|
+
|
|
120
|
+
/** The delays between attempts (`BackoffEntry`'s policy); the number of attempts is the service's `retry.maxAttempts`. */
|
|
121
|
+
export type OpenBackoff = Required<Omit<SinkRetryOptions, "maxAttempts">>;
|
|
122
|
+
|
|
123
|
+
/** What a caller of {@link CastSinkService.openSink} may change about the run of attempts to open a channel. */
|
|
124
|
+
export interface OpenSinkOptions {
|
|
125
|
+
/** Timeouts for the channel, instead of the service's own (Chrome: the `CastSocketOpenParams` passed to `OpenChannel`). */
|
|
126
|
+
params?: ChannelParams;
|
|
127
|
+
/** Delays between attempts, instead of the service's `retry` (Chrome: the `BackoffEntry` passed to `OpenChannel`). */
|
|
128
|
+
backoff?: OpenBackoff;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Carries one run of attempts: its options and who to tell how it ended (Chrome's `ChannelOpenedCallback`). */
|
|
132
|
+
interface OpenContext extends OpenSinkOptions {
|
|
133
|
+
done?: (opened: boolean, error?: Error) => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** `CastMediaSinkServiceImpl::kMaxDialSinkFailureCount`: failed attempts on a device found by DIAL before it is given up on. */
|
|
137
|
+
const MAX_DIAL_SINK_FAILURE_COUNT = 10;
|
|
138
|
+
/** `kCastControlPort`, the port `CreateCastSinkFromDialSink` opens the channel to. */
|
|
139
|
+
const CAST_CONTROL_PORT = 8009;
|
|
140
|
+
/** `cast_channel::CastDeviceCapability` bits as the mDNS `ca` record has them. */
|
|
141
|
+
const VIDEO_OUT = 1;
|
|
142
|
+
const AUDIO_OUT = 4;
|
|
143
|
+
|
|
144
|
+
const sameAddress = (a: string, b: string): boolean => {
|
|
145
|
+
if (a === b) return true;
|
|
146
|
+
const x = parseIpBytes(a);
|
|
147
|
+
const y = parseIpBytes(b);
|
|
148
|
+
return x !== null && y !== null && x.length === y.length && x.every((byte, i) => byte === y[i]);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const MAX_CONNECT_TIMEOUT_MS = 30_000;
|
|
152
|
+
const MAX_LIVENESS_TIMEOUT_MS = 60_000;
|
|
153
|
+
const MAX_FAILURE_COUNT = 100;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Whether a sink's endpoint is still one of the device's addresses. mDNS lists a device's addresses in no fixed order, so
|
|
157
|
+
* a reorder alone is no reason to replace a working channel (Chrome has one address per record, so there is no
|
|
158
|
+
* counterpart; a changed address does replace the endpoint there, `OpenChannel`).
|
|
159
|
+
*/
|
|
160
|
+
function endpointStillOffered(endpoint: string, device: CastDevice): boolean {
|
|
161
|
+
const cut = endpoint.lastIndexOf(":");
|
|
162
|
+
const host = endpoint.slice(0, cut);
|
|
163
|
+
return Number(endpoint.slice(cut + 1)) === device.port && (device.host === host || device.addresses.includes(host));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The devices that have an open, authenticated channel. It is itself a {@link DeviceSource}: `devices()` and the
|
|
168
|
+
* `deviceUp`/`deviceDown`/`deviceChanged` events describe that list (as MediaSinkServiceBase reports sinks), not what
|
|
169
|
+
* mDNS has heard. A device appears once a channel to it has opened and passed device authentication; one that fails
|
|
170
|
+
* authentication is retried like any other failure and never listed.
|
|
171
|
+
*/
|
|
172
|
+
export class CastSinkService extends EventEmitter<SinkEvents> implements DeviceSource {
|
|
173
|
+
private readonly source: DeviceSource;
|
|
174
|
+
private readonly createClient: (device: CastDevice, params: ChannelParams) => CastClientLike;
|
|
175
|
+
private readonly openDelayMaxMs: number;
|
|
176
|
+
private readonly reportDelayMs: number;
|
|
177
|
+
private readonly retry: Required<SinkRetryOptions>;
|
|
178
|
+
private readonly allowAllIps: boolean;
|
|
179
|
+
private readonly random: () => number;
|
|
180
|
+
private readonly dynamicTimeoutDeltaMs: number;
|
|
181
|
+
private readonly isClientInUse: (client: CastClientLike) => boolean;
|
|
182
|
+
/** Failed attempts per device since its last success, as `failure_count_map_`. */
|
|
183
|
+
private readonly failureCounts = new Map<string, number>();
|
|
184
|
+
/**
|
|
185
|
+
* Failed attempts on devices that DIAL found, by Cast sink id (`dial_sink_failure_count_`): every attempt counts, not
|
|
186
|
+
* only a run of them; reset when the device is opened from any other source, or when the network changes.
|
|
187
|
+
*/
|
|
188
|
+
private readonly dialFailureCounts = new Map<string, number>();
|
|
189
|
+
/** `current_network_id_`; empty until the first network id comes. */
|
|
190
|
+
private networkId = "";
|
|
191
|
+
/** `sink_cache_`: the sinks of each network the machine has left, by network id. */
|
|
192
|
+
private readonly sinkCache = new Map<string, CastDevice[]>();
|
|
193
|
+
/** The DIAL sinks as last seen, to tell the new or changed ones (`AddOrUpdateSink` notifies only those). */
|
|
194
|
+
private dialSeen = new Map<string, string>();
|
|
195
|
+
private readonly dialSource: DeviceSource | undefined;
|
|
196
|
+
/** Clients of replaced channels that were in use when replaced. */
|
|
197
|
+
private readonly retired = new Set<CastClientLike>();
|
|
198
|
+
private readonly warned = new Set<string>();
|
|
199
|
+
/** The last error of each device whose channel is not open, for explaining an empty list. */
|
|
200
|
+
private readonly lastErrors = new Map<string, string>();
|
|
201
|
+
|
|
202
|
+
/** Sinks as they are now (Chrome: `GetSinks()`), keyed by device id. */
|
|
203
|
+
private readonly sinkMap = new Map<string, SinkRecord>();
|
|
204
|
+
/** Sinks as last reported (Chrome: `previous_sinks_`). */
|
|
205
|
+
private reported = new Map<string, CastDevice>();
|
|
206
|
+
/** Endpoints with a channel being opened (Chrome: `pending_for_open_ip_endpoints_`). */
|
|
207
|
+
private readonly pending = new Set<string>();
|
|
208
|
+
private readonly timers = new Set<ReturnType<typeof setTimeout>>();
|
|
209
|
+
private reportTimer: ReturnType<typeof setTimeout> | undefined;
|
|
210
|
+
private batchTimer: ReturnType<typeof setTimeout> | undefined;
|
|
211
|
+
private reopening = 0;
|
|
212
|
+
/** Callers of {@link openSink} still waiting; they are told "not opened" on `dispose()`. */
|
|
213
|
+
private readonly waiting = new Set<(opened: boolean) => void>();
|
|
214
|
+
private disposed = false;
|
|
215
|
+
private readonly onSourceEvent = (): void => this.openChannelsWithRandomizedDelay();
|
|
216
|
+
private readonly onDialEvent = (): void => this.onDialSinksChanged();
|
|
217
|
+
|
|
218
|
+
constructor(options: CastSinkServiceOptions) {
|
|
219
|
+
super();
|
|
220
|
+
this.source = options.source;
|
|
221
|
+
this.createClient = options.createClient;
|
|
222
|
+
this.openDelayMaxMs = options.openDelayMaxMs ?? 5000;
|
|
223
|
+
this.reportDelayMs = options.reportDelayMs ?? 3000;
|
|
224
|
+
this.allowAllIps = options.allowAllIps ?? false;
|
|
225
|
+
this.random = options.random ?? Math.random;
|
|
226
|
+
this.dynamicTimeoutDeltaMs = options.dynamicTimeoutDeltaMs ?? 0;
|
|
227
|
+
this.isClientInUse = options.isClientInUse ?? (() => false);
|
|
228
|
+
const r = options.retry ?? {};
|
|
229
|
+
this.retry = {
|
|
230
|
+
initialDelayMs: r.initialDelayMs ?? 15000,
|
|
231
|
+
maxAttempts: r.maxAttempts ?? 3,
|
|
232
|
+
multiplyFactor: r.multiplyFactor ?? 1,
|
|
233
|
+
jitter: r.jitter ?? 0.5,
|
|
234
|
+
maxDelayMs: r.maxDelayMs ?? 30000,
|
|
235
|
+
};
|
|
236
|
+
this.source.on("deviceUp", this.onSourceEvent);
|
|
237
|
+
this.source.on("deviceChanged", this.onSourceEvent);
|
|
238
|
+
this.dialSource = options.dial;
|
|
239
|
+
this.dialSource?.on("deviceChanged", this.onDialEvent);
|
|
240
|
+
// Chrome opens channels for what discovery already knows when it starts (`Start()` then the first DNS-SD event).
|
|
241
|
+
if (this.source.devices().length > 0) this.openChannelsWithRandomizedDelay();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The devices as last reported. */
|
|
245
|
+
devices(): CastDevice[] {
|
|
246
|
+
return [...this.reported.values()].map((d) => ({ ...d }));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** The current sinks, reported or not (Chrome: `GetSinks()`); the tracker and sessions use these. */
|
|
250
|
+
sinks(): CastDevice[] {
|
|
251
|
+
return [...this.sinkMap.values()].map((s) => ({ ...s.device }));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** The open channel's client for a device; undefined when it has none right now. */
|
|
255
|
+
clientOf(deviceId: string): CastClientLike | undefined {
|
|
256
|
+
return this.sinkMap.get(deviceId)?.client;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The device (as a sink) with this id, if it is one now. */
|
|
260
|
+
sinkOf(deviceId: string): CastDevice | undefined {
|
|
261
|
+
const rec = this.sinkMap.get(deviceId);
|
|
262
|
+
return rec === undefined ? undefined : { ...rec.device };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Whether a device is a sink now (Chrome: `CastMediaSinkServiceImpl::HasSink`). */
|
|
266
|
+
hasSink(deviceId: string): boolean {
|
|
267
|
+
return this.sinkMap.has(deviceId);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Open a channel to a device that discovery did not report, and list it once the channel has opened and authenticated
|
|
272
|
+
* (what `AccessCodeCastSinkService` does through `CastMediaSinkServiceImpl::OpenChannel`). Resolves true when the sink
|
|
273
|
+
* has a channel, false when none could be opened: the address is not one a channel may be opened to, the attempts ran
|
|
274
|
+
* out, or the service was disposed. Failed attempts are retried as discovery's are, with `options.backoff` between them.
|
|
275
|
+
*/
|
|
276
|
+
openSink(device: CastDevice, options: OpenSinkOptions = {}): Promise<boolean> {
|
|
277
|
+
return new Promise<boolean>((resolve) => {
|
|
278
|
+
if (this.disposed) {
|
|
279
|
+
resolve(false);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
this.waiting.add(resolve);
|
|
283
|
+
this.openChannel(device, "access-code", 0, {
|
|
284
|
+
...options,
|
|
285
|
+
done: (opened) => {
|
|
286
|
+
this.waiting.delete(resolve);
|
|
287
|
+
resolve(opened);
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A sink takes a new name and capabilities (Chrome: `AddOrUpdateSink` on a copy of the existing sink, as `UpdateExistingSink` does). */
|
|
294
|
+
updateSinkDetails(deviceId: string, details: { name: string; capabilities: number }): void {
|
|
295
|
+
const record = this.sinkMap.get(deviceId);
|
|
296
|
+
if (record === undefined) return;
|
|
297
|
+
const next: CastDevice = { ...record.device, name: details.name, capabilities: details.capabilities };
|
|
298
|
+
if (sameDevice(next, record.device)) return;
|
|
299
|
+
record.device = next;
|
|
300
|
+
this.markChanged();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Remove a sink and close its channel (Chrome: `CastMediaSinkServiceImpl::DisconnectAndRemoveSink`). */
|
|
304
|
+
disconnectAndRemoveSink(deviceId: string): void {
|
|
305
|
+
const record = this.sinkMap.get(deviceId);
|
|
306
|
+
if (record !== undefined) this.removeSink(record);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Open channels now to every discovered device that has none, with no random delay (Chrome:
|
|
311
|
+
* `CastMediaSinkService::DiscoverSinksNow`, which calls `OpenChannelsNow`). A device that gave up after its retries is
|
|
312
|
+
* only tried again by this or when discovery reports it again.
|
|
313
|
+
*/
|
|
314
|
+
discoverSinksNow(): void {
|
|
315
|
+
this.openChannels("discovery");
|
|
316
|
+
// `CastMediaSinkServiceImpl::DiscoverSinksNow` tries the DIAL sinks again, which recovers a sink lost to a flaky network.
|
|
317
|
+
for (const sink of this.dialSource?.devices() ?? []) this.tryConnectDialDiscoveredSink(sink);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* `CastMediaSinkServiceImpl::OnNetworksChanged`, from the manager's network monitor (and once with the current id, as
|
|
322
|
+
* `Start` asks `GetNetworkId`). Devices DIAL found that were given up on may be tried again; the sinks of the network
|
|
323
|
+
* being left are remembered (not those added by access code, which expire on their own), and on coming back to a
|
|
324
|
+
* network seen before its sinks are opened again after the usual random delay, without waiting for mDNS. The sinks
|
|
325
|
+
* themselves stay: Chrome neither clears them nor restarts discovery here.
|
|
326
|
+
*/
|
|
327
|
+
onNetworksChanged(networkId: string): void {
|
|
328
|
+
if (this.disposed || networkId === this.networkId) return;
|
|
329
|
+
const last = this.networkId;
|
|
330
|
+
this.networkId = networkId;
|
|
331
|
+
this.dialFailureCounts.clear();
|
|
332
|
+
if (!isNetworkIdUnknownOrDisconnected(last)) {
|
|
333
|
+
const sinks = [...this.sinkMap.values()].filter((r) => r.openedBy !== "access-code").map((r) => ({ ...r.device }));
|
|
334
|
+
this.sinkCache.set(last, sinks);
|
|
335
|
+
}
|
|
336
|
+
if (isNetworkIdUnknownOrDisconnected(networkId)) return;
|
|
337
|
+
const cached = this.sinkCache.get(networkId);
|
|
338
|
+
if (cached === undefined) return;
|
|
339
|
+
// `OpenChannelsWithRandomizedDelay(cache_entry->second, SinkSource::kNetworkCache)`
|
|
340
|
+
this.later(this.random() * this.openDelayMaxMs, () => {
|
|
341
|
+
for (const device of cached) this.openChannel(device, "network-cache", 0);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Resolves when no channel is being opened and none is scheduled to be; for tests. A retry waiting out its backoff does
|
|
347
|
+
* not count unless `retries` is set (a real backoff is 15 s).
|
|
348
|
+
*/
|
|
349
|
+
async settled(options: { retries?: boolean } = {}): Promise<void> {
|
|
350
|
+
const busy = (): boolean =>
|
|
351
|
+
this.pending.size > 0 || this.reopening > 0 || this.batchTimer !== undefined || this.reportTimer !== undefined ||
|
|
352
|
+
(options.retries === true && this.timers.size > 0);
|
|
353
|
+
for (let i = 0; i < 2000 && busy(); i++) {
|
|
354
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The distinct errors of the devices that could not be opened, none for a device that has since opened. */
|
|
359
|
+
openErrors(): string[] {
|
|
360
|
+
return [...new Set(this.lastErrors.values())];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Close the clients of replaced channels that nothing uses any more. */
|
|
364
|
+
releaseUnused(): void {
|
|
365
|
+
for (const client of [...this.retired]) {
|
|
366
|
+
if (this.isClientInUse(client)) continue;
|
|
367
|
+
this.retired.delete(client);
|
|
368
|
+
this.closeQuietly(client);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private closeQuietly(client: CastClientLike): void {
|
|
373
|
+
try {
|
|
374
|
+
client.close();
|
|
375
|
+
} catch {
|
|
376
|
+
// already closed
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** `CreateCastSocketOpenParams`: the timeouts for the next run of attempts on a device. */
|
|
381
|
+
private paramsFor(deviceId: string): ChannelParams {
|
|
382
|
+
const failures = this.failureCounts.get(deviceId) ?? 0;
|
|
383
|
+
const grow = failures * this.dynamicTimeoutDeltaMs;
|
|
384
|
+
return {
|
|
385
|
+
connectTimeoutMs: Math.min(10_000 + grow, MAX_CONNECT_TIMEOUT_MS),
|
|
386
|
+
livenessTimeoutMs: Math.min(10_000 + grow, MAX_LIVENESS_TIMEOUT_MS),
|
|
387
|
+
pingIntervalMs: 5000,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Stop everything and close every channel. */
|
|
392
|
+
dispose(): void {
|
|
393
|
+
if (this.disposed) return;
|
|
394
|
+
this.disposed = true;
|
|
395
|
+
this.source.off("deviceUp", this.onSourceEvent);
|
|
396
|
+
this.source.off("deviceChanged", this.onSourceEvent);
|
|
397
|
+
this.dialSource?.off("deviceChanged", this.onDialEvent);
|
|
398
|
+
for (const t of this.timers) clearTimeout(t);
|
|
399
|
+
this.timers.clear();
|
|
400
|
+
this.reopening = 0;
|
|
401
|
+
if (this.batchTimer !== undefined) clearTimeout(this.batchTimer);
|
|
402
|
+
if (this.reportTimer !== undefined) clearTimeout(this.reportTimer);
|
|
403
|
+
this.batchTimer = this.reportTimer = undefined;
|
|
404
|
+
const records = [...this.sinkMap.values()];
|
|
405
|
+
this.sinkMap.clear();
|
|
406
|
+
this.reported.clear();
|
|
407
|
+
for (const rec of records) this.closeClient(rec);
|
|
408
|
+
for (const client of this.retired) this.closeQuietly(client);
|
|
409
|
+
this.retired.clear();
|
|
410
|
+
for (const resolve of [...this.waiting]) resolve(false);
|
|
411
|
+
this.waiting.clear();
|
|
412
|
+
this.removeAllListeners();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private later(ms: number, run: () => void): void {
|
|
416
|
+
const t = setTimeout(() => {
|
|
417
|
+
this.timers.delete(t);
|
|
418
|
+
run();
|
|
419
|
+
}, ms);
|
|
420
|
+
t.unref?.();
|
|
421
|
+
this.timers.add(t);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** `OpenChannelsWithRandomizedDelay`; calls arriving while one is waiting are covered by it, as it reads the list when it runs. */
|
|
425
|
+
private openChannelsWithRandomizedDelay(): void {
|
|
426
|
+
if (this.disposed || this.batchTimer !== undefined) return;
|
|
427
|
+
this.batchTimer = setTimeout(() => {
|
|
428
|
+
this.batchTimer = undefined;
|
|
429
|
+
this.openChannels("discovery");
|
|
430
|
+
}, this.random() * this.openDelayMaxMs);
|
|
431
|
+
this.batchTimer.unref?.();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** The DIAL sinks new or changed since the last look are tried, as `OnSinkAddedOrUpdated` is called for those only. */
|
|
435
|
+
private onDialSinksChanged(): void {
|
|
436
|
+
if (this.disposed || this.dialSource === undefined) return;
|
|
437
|
+
const now = new Map<string, string>();
|
|
438
|
+
const fresh: CastDevice[] = [];
|
|
439
|
+
for (const sink of this.dialSource.devices()) {
|
|
440
|
+
const key = JSON.stringify(sink);
|
|
441
|
+
now.set(sink.id, key);
|
|
442
|
+
if (this.dialSeen.get(sink.id) !== key) fresh.push(sink);
|
|
443
|
+
}
|
|
444
|
+
this.dialSeen = now;
|
|
445
|
+
for (const sink of fresh) this.tryConnectDialDiscoveredSink(sink);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* `TryConnectDialDiscoveredSink`: a device found by DIAL may be a Cast device too, so a channel is opened to it on port
|
|
450
|
+
* 8009. Not when it has failed too often to be one, when a Cast sink has its id (the manager hides the DIAL sink, which
|
|
451
|
+
* is Chrome's removing it from the DIAL service) or when a Cast sink already has its address (a second channel would be
|
|
452
|
+
* redundant and would tear down a session on the first).
|
|
453
|
+
*/
|
|
454
|
+
private tryConnectDialDiscoveredSink(dialSink: CastDevice): void {
|
|
455
|
+
if (this.disposed || dialSink.dial === undefined || !dialSink.id.startsWith("dial:")) return;
|
|
456
|
+
// `GetCastSinkIdFromDial`: "dial:" becomes "cast:"; ids here carry no prefix, so the bare uuid is the id.
|
|
457
|
+
const id = dialSink.id.slice("dial:".length);
|
|
458
|
+
if (this.isProbablyNonCastDevice(id)) return;
|
|
459
|
+
const address = dialSink.dial.ipAddress;
|
|
460
|
+
for (const record of this.sinkMap.values()) {
|
|
461
|
+
if (processDeviceUuid(record.device.id) === id || sameAddress(record.device.host, address)) return;
|
|
462
|
+
}
|
|
463
|
+
// `CreateCastSinkFromDialSink`: the DIAL sink's name and model, its address with the Cast control port; the
|
|
464
|
+
// capabilities are learnt from the opened channel (`onOpened`).
|
|
465
|
+
this.openChannel({
|
|
466
|
+
id,
|
|
467
|
+
name: dialSink.name,
|
|
468
|
+
model: dialSink.dial.modelName,
|
|
469
|
+
host: address,
|
|
470
|
+
addresses: [address],
|
|
471
|
+
port: CAST_CONTROL_PORT,
|
|
472
|
+
capabilities: 0,
|
|
473
|
+
isGroup: false,
|
|
474
|
+
statusText: "",
|
|
475
|
+
instanceName: id,
|
|
476
|
+
txt: {},
|
|
477
|
+
}, "dial", 0);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** `IsProbablyNonCastDevice`: a device found by DIAL only that a channel could not be opened to ten times over. */
|
|
481
|
+
private isProbablyNonCastDevice(id: string): boolean {
|
|
482
|
+
return (this.dialFailureCounts.get(id) ?? 0) >= MAX_DIAL_SINK_FAILURE_COUNT;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private openChannels(source: OpenSource): void {
|
|
486
|
+
if (this.disposed) return;
|
|
487
|
+
for (const device of this.source.devices()) this.openChannel(device, source, 0);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** `CastMediaSinkServiceImpl::OpenChannel`. `failures` counts the failed attempts so far in this run of retries. */
|
|
491
|
+
private openChannel(device: CastDevice, source: OpenSource, failures: number, ctx: OpenContext = {}): void {
|
|
492
|
+
if (this.disposed) {
|
|
493
|
+
ctx.done?.(false);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (parseIpBytes(device.host) === null) {
|
|
497
|
+
// Chrome opens channels to IP endpoints only (`IPEndPoint`), and a name cannot be vetted against the address rules.
|
|
498
|
+
this.skip(device, `"${device.host}" is a host name, not an IP address; a channel is opened to IP addresses only`);
|
|
499
|
+
ctx.done?.(false);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
// Chrome checks the one endpoint it is about to open, here and nowhere else (`OpenChannel`), with
|
|
503
|
+
// net::IPAddress::IsPubliclyRoutable and IsLoopback (ported byte for byte in ip-policy.ts)
|
|
504
|
+
if (!this.allowAllIps && (isPubliclyRoutable(device.host) || isLoopback(device.host))) {
|
|
505
|
+
this.skip(device, `${device.host} is ${isLoopback(device.host) ? "a loopback" : "a publicly routable"} address (allowAllIps is off)`);
|
|
506
|
+
ctx.done?.(false);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
// Anything but DIAL opening the device shows it to be a Cast device (`OpenChannel`).
|
|
510
|
+
if (source !== "dial") this.dialFailureCounts.delete(processDeviceUuid(device.id));
|
|
511
|
+
const existing = this.sinkMap.get(device.id);
|
|
512
|
+
// The sink's own endpoint stays while the device still offers it, so an address list reordered by mDNS does not
|
|
513
|
+
// replace a channel that works.
|
|
514
|
+
if (source === "discovery" && existing !== undefined && endpointStillOffered(existing.endpoint, device)) {
|
|
515
|
+
device = { ...device, host: existing.device.host, port: existing.device.port };
|
|
516
|
+
}
|
|
517
|
+
const endpoint = endpointOf(device);
|
|
518
|
+
// A sink whose endpoint stayed the same needs no new channel, only its details updated (only discovery's: a retry
|
|
519
|
+
// after an error reopens the channel).
|
|
520
|
+
if (source !== "retry-on-error" && existing !== undefined && existing.endpoint === endpoint) {
|
|
521
|
+
if (source === "discovery") this.updateSink(existing, device);
|
|
522
|
+
ctx.done?.(true);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (this.pending.has(endpoint)) {
|
|
526
|
+
ctx.done?.(false);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
this.pending.add(endpoint);
|
|
530
|
+
const run: OpenContext = { ...ctx, params: ctx.params ?? this.paramsFor(device.id) };
|
|
531
|
+
const openParams = run.params as ChannelParams;
|
|
532
|
+
let client: CastClientLike;
|
|
533
|
+
try {
|
|
534
|
+
client = this.createClient(device, openParams);
|
|
535
|
+
} catch (err) {
|
|
536
|
+
this.pending.delete(endpoint);
|
|
537
|
+
this.onOpenError(device, source, failures, err, run);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
client.connect().then(
|
|
541
|
+
() => {
|
|
542
|
+
this.pending.delete(endpoint);
|
|
543
|
+
if (this.disposed) {
|
|
544
|
+
client.close();
|
|
545
|
+
run.done?.(false);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
this.onOpened(device, client, source);
|
|
549
|
+
run.done?.(true);
|
|
550
|
+
},
|
|
551
|
+
(err: unknown) => {
|
|
552
|
+
this.pending.delete(endpoint);
|
|
553
|
+
client.close();
|
|
554
|
+
this.onOpenError(device, source, failures, err, run);
|
|
555
|
+
},
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** `OnChannelErrorMayRetry`: wait out the backoff and try again, or give up after `maxAttempts` failures in a row. */
|
|
560
|
+
private onOpenError(device: CastDevice, source: OpenSource, failuresBefore: number, err: unknown, run: OpenContext): void {
|
|
561
|
+
if (this.disposed) {
|
|
562
|
+
run.done?.(false);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (source === "dial") {
|
|
566
|
+
const key = processDeviceUuid(device.id);
|
|
567
|
+
this.dialFailureCounts.set(key, (this.dialFailureCounts.get(key) ?? 0) + 1);
|
|
568
|
+
}
|
|
569
|
+
this.failureCounts.set(device.id, Math.min((this.failureCounts.get(device.id) ?? 0) + 1, MAX_FAILURE_COUNT));
|
|
570
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
571
|
+
this.lastErrors.set(device.id, error.message);
|
|
572
|
+
const failures = failuresBefore + 1;
|
|
573
|
+
const giveUp = failures >= this.retry.maxAttempts;
|
|
574
|
+
this.emit("openFailed", device, error, !giveUp);
|
|
575
|
+
if (giveUp) {
|
|
576
|
+
this.onOpenGaveUp(device);
|
|
577
|
+
run.done?.(false, error);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
// BackoffEntry::CalculateReleaseTime: initial * factor^(failures - 1), cut by up to `jitter`, at most the maximum
|
|
581
|
+
const backoff = run.backoff ?? this.retry;
|
|
582
|
+
const nominal = backoff.initialDelayMs * backoff.multiplyFactor ** (failures - 1);
|
|
583
|
+
const delay = Math.min(nominal - this.random() * backoff.jitter * nominal, backoff.maxDelayMs);
|
|
584
|
+
const endpoint = endpointOf(device);
|
|
585
|
+
this.later(delay, () => {
|
|
586
|
+
// A retry captured an endpoint; if the device has meanwhile been reached at another one, or discovery now names
|
|
587
|
+
// another, the newer attempt is the one that counts (Chrome's `OnChannelOpenFailed` ignores a failure whose
|
|
588
|
+
// endpoint is no longer the sink's for the same reason).
|
|
589
|
+
const now = this.sinkMap.get(device.id);
|
|
590
|
+
const offered = this.source.devices().find((d) => d.id === device.id);
|
|
591
|
+
if ((now !== undefined && now.endpoint !== endpoint) || (offered !== undefined && !endpointStillOffered(endpoint, offered))) {
|
|
592
|
+
run.done?.(false);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
this.openChannel(device, source, failures, run);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** `OnChannelOpenFailed`: drop the sink, unless it was meanwhile reconnected at another address. */
|
|
600
|
+
private onOpenGaveUp(device: CastDevice): void {
|
|
601
|
+
const existing = this.sinkMap.get(device.id);
|
|
602
|
+
if (existing === undefined || existing.endpoint !== endpointOf(device)) return;
|
|
603
|
+
this.removeSink(existing);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/** `OnChannelOpenSucceeded`. */
|
|
607
|
+
private onOpened(opened: CastDevice, client: CastClientLike, source: OpenSource): void {
|
|
608
|
+
let device = opened;
|
|
609
|
+
// DIAL says nothing of capabilities: a Cast device plays audio, and video unless its certificate restricts it to audio
|
|
610
|
+
// (`socket->audio_only()`); the icon follows from them.
|
|
611
|
+
if (source === "dial") {
|
|
612
|
+
const audioOnly = client.deviceAuth?.policy === "audio_only";
|
|
613
|
+
device = { ...device, capabilities: AUDIO_OUT | (audioOnly ? 0 : VIDEO_OUT) };
|
|
614
|
+
}
|
|
615
|
+
const endpoint = endpointOf(device);
|
|
616
|
+
const previous = this.sinkMap.get(device.id);
|
|
617
|
+
const openedBy = source === "retry-on-error" ? previous?.openedBy ?? source : source;
|
|
618
|
+
const record: SinkRecord = { device: { ...device }, openedBy, client, endpoint };
|
|
619
|
+
this.failureCounts.delete(device.id);
|
|
620
|
+
this.lastErrors.delete(device.id);
|
|
621
|
+
// Chrome leaves the old socket alone when a sink gets a new one (`OnChannelOpenSucceeded` only adds the sink with
|
|
622
|
+
// the new channel id), so a session on it goes on; ours is closed once no session uses it.
|
|
623
|
+
const old = previous?.client;
|
|
624
|
+
if (previous !== undefined) previous.client = undefined;
|
|
625
|
+
if (old !== undefined && old !== client) {
|
|
626
|
+
if (this.isClientInUse(old)) this.retired.add(old);
|
|
627
|
+
else this.closeQuietly(old);
|
|
628
|
+
this.emit("channelRetired", old);
|
|
629
|
+
}
|
|
630
|
+
this.sinkMap.set(device.id, record);
|
|
631
|
+
// An address appears in at most one sink: a sink with another id at this address is stale.
|
|
632
|
+
for (const other of [...this.sinkMap.values()]) {
|
|
633
|
+
if (other !== record && other.endpoint === endpoint) this.removeSink(other);
|
|
634
|
+
}
|
|
635
|
+
client.on("close", (error?: Error) => this.onClientClosed(record, client, error));
|
|
636
|
+
this.markChanged();
|
|
637
|
+
this.emit("channelOpened", { device: record.device, client });
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** `OnError` of the cast socket observer: the channel failed, so reopen it (as a retry after an error). */
|
|
641
|
+
private onClientClosed(record: SinkRecord, client: CastClientLike, error: Error | undefined): void {
|
|
642
|
+
this.retired.delete(client);
|
|
643
|
+
if (this.disposed || record.client !== client || this.sinkMap.get(record.device.id) !== record) return;
|
|
644
|
+
record.client = undefined;
|
|
645
|
+
this.emit("channelClosed", { device: record.device, client }, error);
|
|
646
|
+
this.reopening += 1;
|
|
647
|
+
this.later(0, () => {
|
|
648
|
+
this.reopening -= 1;
|
|
649
|
+
this.openChannel(this.reopenTarget(record), "retry-on-error", 0);
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** The device to reopen: as discovery knows it now, at the sink's own endpoint while the device still offers it. */
|
|
654
|
+
private reopenTarget(record: SinkRecord): CastDevice {
|
|
655
|
+
const fresh = this.latest(record.device);
|
|
656
|
+
return endpointStillOffered(record.endpoint, fresh) ? { ...fresh, host: record.device.host, port: record.device.port } : fresh;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
private skip(device: CastDevice, reason: string): void {
|
|
660
|
+
const key = `${device.id} ${reason}`;
|
|
661
|
+
if (!this.warned.has(key)) {
|
|
662
|
+
this.warned.add(key);
|
|
663
|
+
console.warn(`electron-cast: no channel is opened to device ${device.id}: ${reason}`);
|
|
664
|
+
}
|
|
665
|
+
this.emit("skipped", device, reason);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** The device as discovery knows it now (its address may have changed), else as it was. */
|
|
669
|
+
private latest(device: CastDevice): CastDevice {
|
|
670
|
+
return this.source.devices().find((d) => d.id === device.id) ?? device;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** `UpdateCastSink`: a sink already open takes its new name and capabilities. */
|
|
674
|
+
private updateSink(record: SinkRecord, fresh: CastDevice): void {
|
|
675
|
+
const next: CastDevice = { ...fresh, host: record.device.host, addresses: record.device.addresses, port: record.device.port };
|
|
676
|
+
if (sameDevice(next, record.device)) return;
|
|
677
|
+
record.device = next;
|
|
678
|
+
this.markChanged();
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
private removeSink(record: SinkRecord): void {
|
|
682
|
+
if (this.sinkMap.get(record.device.id) !== record) return;
|
|
683
|
+
this.sinkMap.delete(record.device.id);
|
|
684
|
+
this.closeClient(record);
|
|
685
|
+
this.markChanged();
|
|
686
|
+
this.emit("sinkRemoved", record.device);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/** Close a record's client without the close being taken for a channel error. */
|
|
690
|
+
private closeClient(record: SinkRecord): void {
|
|
691
|
+
const client = record.client;
|
|
692
|
+
record.client = undefined;
|
|
693
|
+
try {
|
|
694
|
+
client?.close();
|
|
695
|
+
} catch {
|
|
696
|
+
// already closed
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/** `MediaSinkServiceBase::StartTimer`: the changed list is reported once discovery has been quiet for a while. */
|
|
701
|
+
private markChanged(): void {
|
|
702
|
+
if (this.disposed || this.reportTimer !== undefined) return;
|
|
703
|
+
this.reportTimer = setTimeout(() => {
|
|
704
|
+
this.reportTimer = undefined;
|
|
705
|
+
this.report();
|
|
706
|
+
}, this.reportDelayMs);
|
|
707
|
+
this.reportTimer.unref?.();
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/** `OnDiscoveryComplete`: report only if the list differs from the one last reported. */
|
|
711
|
+
private report(): void {
|
|
712
|
+
if (this.disposed) return;
|
|
713
|
+
const next = new Map<string, CastDevice>();
|
|
714
|
+
for (const rec of this.sinkMap.values()) next.set(rec.device.id, { ...rec.device });
|
|
715
|
+
const previous = this.reported;
|
|
716
|
+
this.reported = next;
|
|
717
|
+
for (const [id, device] of previous) {
|
|
718
|
+
if (!next.has(id)) this.emit("deviceDown", { ...device });
|
|
719
|
+
}
|
|
720
|
+
for (const [id, device] of next) {
|
|
721
|
+
const before = previous.get(id);
|
|
722
|
+
if (before === undefined) this.emit("deviceUp", { ...device });
|
|
723
|
+
else if (!sameDevice(before, device)) this.emit("deviceChanged", { ...device });
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|