electron-cast 0.3.0 → 0.4.0

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.
Files changed (204) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +122 -12
  3. package/dist/cjs/client/auth/build-time.d.ts +7 -0
  4. package/dist/cjs/client/auth/build-time.js +11 -0
  5. package/dist/cjs/client/auth/build-time.js.map +1 -0
  6. package/dist/cjs/client/auth/cast-auth.d.ts +44 -0
  7. package/dist/cjs/client/auth/cast-auth.js +145 -0
  8. package/dist/cjs/client/auth/cast-auth.js.map +1 -0
  9. package/dist/cjs/client/auth/cast-cert-validator.d.ts +34 -0
  10. package/dist/cjs/client/auth/cast-cert-validator.js +89 -0
  11. package/dist/cjs/client/auth/cast-cert-validator.js.map +1 -0
  12. package/dist/cjs/client/auth/crl.d.ts +45 -0
  13. package/dist/cjs/client/auth/crl.js +227 -0
  14. package/dist/cjs/client/auth/crl.js.map +1 -0
  15. package/dist/cjs/client/auth/der.d.ts +62 -0
  16. package/dist/cjs/client/auth/der.js +208 -0
  17. package/dist/cjs/client/auth/der.js.map +1 -0
  18. package/dist/cjs/client/auth/names.d.ts +52 -0
  19. package/dist/cjs/client/auth/names.js +447 -0
  20. package/dist/cjs/client/auth/names.js.map +1 -0
  21. package/dist/cjs/client/auth/path-validator.d.ts +29 -0
  22. package/dist/cjs/client/auth/path-validator.js +421 -0
  23. package/dist/cjs/client/auth/path-validator.js.map +1 -0
  24. package/dist/cjs/client/auth/trust-data.d.ts +24 -0
  25. package/dist/cjs/client/auth/trust-data.js +97 -0
  26. package/dist/cjs/client/auth/trust-data.js.map +1 -0
  27. package/dist/cjs/client/auth/x509.d.ts +109 -0
  28. package/dist/cjs/client/auth/x509.js +442 -0
  29. package/dist/cjs/client/auth/x509.js.map +1 -0
  30. package/dist/cjs/client/cast-client.d.ts +111 -0
  31. package/dist/cjs/client/cast-client.js +505 -0
  32. package/dist/cjs/client/cast-client.js.map +1 -0
  33. package/dist/cjs/client/errors.d.ts +28 -0
  34. package/dist/cjs/client/errors.js +50 -0
  35. package/dist/cjs/client/errors.js.map +1 -0
  36. package/dist/cjs/client/index.d.ts +6 -0
  37. package/dist/cjs/client/index.js +21 -0
  38. package/dist/cjs/client/index.js.map +1 -0
  39. package/dist/cjs/client/namespaces.d.ts +9 -0
  40. package/dist/cjs/client/namespaces.js +13 -0
  41. package/dist/cjs/client/namespaces.js.map +1 -0
  42. package/dist/cjs/client/types.d.ts +27 -0
  43. package/dist/cjs/client/types.js +3 -0
  44. package/dist/cjs/client/types.js.map +1 -0
  45. package/dist/cjs/discovery/cast-discovery.d.ts +103 -0
  46. package/dist/cjs/discovery/cast-discovery.js +323 -0
  47. package/dist/cjs/discovery/cast-discovery.js.map +1 -0
  48. package/dist/cjs/discovery/device-cache.d.ts +45 -0
  49. package/dist/cjs/discovery/device-cache.js +240 -0
  50. package/dist/cjs/discovery/device-cache.js.map +1 -0
  51. package/dist/cjs/discovery/dns-packet.d.ts +70 -0
  52. package/dist/cjs/discovery/dns-packet.js +251 -0
  53. package/dist/cjs/discovery/dns-packet.js.map +1 -0
  54. package/dist/cjs/discovery/index.d.ts +4 -0
  55. package/dist/cjs/discovery/index.js +21 -0
  56. package/dist/cjs/discovery/index.js.map +1 -0
  57. package/dist/cjs/discovery/udp-socket.d.ts +16 -0
  58. package/dist/cjs/discovery/udp-socket.js +163 -0
  59. package/dist/cjs/discovery/udp-socket.js.map +1 -0
  60. package/dist/cjs/electron/main.d.ts +86 -0
  61. package/dist/cjs/electron/main.js +408 -0
  62. package/dist/cjs/electron/main.js.map +1 -0
  63. package/dist/cjs/electron/manager-api.d.ts +132 -0
  64. package/dist/cjs/electron/manager-api.js +207 -0
  65. package/dist/cjs/electron/manager-api.js.map +1 -0
  66. package/dist/cjs/electron/preload.d.ts +39 -0
  67. package/dist/cjs/electron/preload.js +96 -0
  68. package/dist/cjs/electron/preload.js.map +1 -0
  69. package/dist/cjs/electron/presentation-envelope.d.ts +60 -0
  70. package/dist/cjs/electron/presentation-envelope.js +318 -0
  71. package/dist/cjs/electron/presentation-envelope.js.map +1 -0
  72. package/dist/cjs/electron/presentation-handler.d.ts +100 -0
  73. package/dist/cjs/electron/presentation-handler.js +499 -0
  74. package/dist/cjs/electron/presentation-handler.js.map +1 -0
  75. package/dist/cjs/electron/session-service.d.ts +174 -0
  76. package/dist/cjs/electron/session-service.js +891 -0
  77. package/dist/cjs/electron/session-service.js.map +1 -0
  78. package/dist/cjs/index.d.ts +8 -0
  79. package/dist/cjs/index.js +26 -0
  80. package/dist/cjs/index.js.map +1 -0
  81. package/dist/cjs/package.json +1 -0
  82. package/dist/cjs/polyfill/bridge-types.d.ts +86 -0
  83. package/dist/cjs/polyfill/bridge-types.js +3 -0
  84. package/dist/cjs/polyfill/bridge-types.js.map +1 -0
  85. package/dist/cjs/polyfill/install.d.ts +12 -0
  86. package/dist/cjs/polyfill/install.js +1569 -0
  87. package/dist/cjs/polyfill/install.js.map +1 -0
  88. package/dist/cjs/polyfill/presentation-standin.d.ts +13 -0
  89. package/dist/cjs/polyfill/presentation-standin.js +279 -0
  90. package/dist/cjs/polyfill/presentation-standin.js.map +1 -0
  91. package/dist/cjs/protocol/cast-message.d.ts +20 -0
  92. package/dist/cjs/protocol/cast-message.js +171 -0
  93. package/dist/cjs/protocol/cast-message.js.map +1 -0
  94. package/dist/cjs/protocol/device-auth.d.ts +61 -0
  95. package/dist/cjs/protocol/device-auth.js +113 -0
  96. package/dist/cjs/protocol/device-auth.js.map +1 -0
  97. package/dist/cjs/protocol/errors.d.ts +4 -0
  98. package/dist/cjs/protocol/errors.js +12 -0
  99. package/dist/cjs/protocol/errors.js.map +1 -0
  100. package/dist/cjs/protocol/framing.d.ts +18 -0
  101. package/dist/cjs/protocol/framing.js +100 -0
  102. package/dist/cjs/protocol/framing.js.map +1 -0
  103. package/dist/cjs/protocol/index.d.ts +4 -0
  104. package/dist/cjs/protocol/index.js +21 -0
  105. package/dist/cjs/protocol/index.js.map +1 -0
  106. package/dist/cjs/protocol/proto-wire.d.ts +11 -0
  107. package/dist/cjs/protocol/proto-wire.js +64 -0
  108. package/dist/cjs/protocol/proto-wire.js.map +1 -0
  109. package/dist/client/auth/build-time.d.ts +7 -0
  110. package/dist/client/auth/build-time.js +8 -0
  111. package/dist/client/auth/build-time.js.map +1 -0
  112. package/dist/client/auth/cast-auth.d.ts +44 -0
  113. package/dist/client/auth/cast-auth.js +141 -0
  114. package/dist/client/auth/cast-auth.js.map +1 -0
  115. package/dist/client/auth/cast-cert-validator.d.ts +34 -0
  116. package/dist/client/auth/cast-cert-validator.js +86 -0
  117. package/dist/client/auth/cast-cert-validator.js.map +1 -0
  118. package/dist/client/auth/crl.d.ts +45 -0
  119. package/dist/client/auth/crl.js +221 -0
  120. package/dist/client/auth/crl.js.map +1 -0
  121. package/dist/client/auth/der.d.ts +62 -0
  122. package/dist/client/auth/der.js +196 -0
  123. package/dist/client/auth/der.js.map +1 -0
  124. package/dist/client/auth/names.d.ts +52 -0
  125. package/dist/client/auth/names.js +438 -0
  126. package/dist/client/auth/names.js.map +1 -0
  127. package/dist/client/auth/path-validator.d.ts +29 -0
  128. package/dist/client/auth/path-validator.js +417 -0
  129. package/dist/client/auth/path-validator.js.map +1 -0
  130. package/dist/client/auth/trust-data.d.ts +24 -0
  131. package/dist/client/auth/trust-data.js +94 -0
  132. package/dist/client/auth/trust-data.js.map +1 -0
  133. package/dist/client/auth/x509.d.ts +109 -0
  134. package/dist/client/auth/x509.js +430 -0
  135. package/dist/client/auth/x509.js.map +1 -0
  136. package/dist/client/cast-client.d.ts +20 -1
  137. package/dist/client/cast-client.js +74 -3
  138. package/dist/client/cast-client.js.map +1 -1
  139. package/dist/client/errors.d.ts +11 -0
  140. package/dist/client/errors.js +13 -0
  141. package/dist/client/errors.js.map +1 -1
  142. package/dist/client/index.d.ts +2 -0
  143. package/dist/discovery/cast-discovery.d.ts +21 -2
  144. package/dist/discovery/cast-discovery.js +94 -14
  145. package/dist/discovery/cast-discovery.js.map +1 -1
  146. package/dist/discovery/device-cache.d.ts +6 -1
  147. package/dist/discovery/device-cache.js +31 -7
  148. package/dist/discovery/device-cache.js.map +1 -1
  149. package/dist/discovery/udp-socket.d.ts +5 -1
  150. package/dist/discovery/udp-socket.js +56 -5
  151. package/dist/discovery/udp-socket.js.map +1 -1
  152. package/dist/electron/main.d.ts +26 -4
  153. package/dist/electron/main.js +193 -55
  154. package/dist/electron/main.js.map +1 -1
  155. package/dist/electron/manager-api.d.ts +132 -0
  156. package/dist/electron/manager-api.js +198 -0
  157. package/dist/electron/manager-api.js.map +1 -0
  158. package/dist/electron/preload.d.ts +5 -0
  159. package/dist/electron/preload.js +9 -1
  160. package/dist/electron/preload.js.map +1 -1
  161. package/dist/electron/presentation-envelope.js +7 -1
  162. package/dist/electron/presentation-envelope.js.map +1 -1
  163. package/dist/electron/presentation-handler.js +16 -9
  164. package/dist/electron/presentation-handler.js.map +1 -1
  165. package/dist/electron/session-service.d.ts +50 -1
  166. package/dist/electron/session-service.js +256 -33
  167. package/dist/electron/session-service.js.map +1 -1
  168. package/dist/polyfill/presentation-standin.js +3 -2
  169. package/dist/polyfill/presentation-standin.js.map +1 -1
  170. package/dist/protocol/device-auth.d.ts +61 -0
  171. package/dist/protocol/device-auth.js +106 -0
  172. package/dist/protocol/device-auth.js.map +1 -0
  173. package/dist/protocol/index.d.ts +1 -0
  174. package/dist/protocol/index.js +1 -0
  175. package/dist/protocol/index.js.map +1 -1
  176. package/dist/protocol/proto-wire.d.ts +11 -0
  177. package/dist/protocol/proto-wire.js +60 -0
  178. package/dist/protocol/proto-wire.js.map +1 -0
  179. package/package.json +47 -12
  180. package/src/client/auth/build-time.ts +7 -0
  181. package/src/client/auth/cast-auth.ts +184 -0
  182. package/src/client/auth/cast-cert-validator.ts +133 -0
  183. package/src/client/auth/crl.ts +228 -0
  184. package/src/client/auth/der.ts +193 -0
  185. package/src/client/auth/names.ts +411 -0
  186. package/src/client/auth/path-validator.ts +449 -0
  187. package/src/client/auth/trust-data.ts +95 -0
  188. package/src/client/auth/x509.ts +488 -0
  189. package/src/client/cast-client.ts +85 -3
  190. package/src/client/errors.ts +29 -0
  191. package/src/client/index.ts +2 -0
  192. package/src/discovery/cast-discovery.ts +104 -19
  193. package/src/discovery/device-cache.ts +38 -8
  194. package/src/discovery/udp-socket.ts +63 -4
  195. package/src/electron/main.ts +220 -60
  196. package/src/electron/manager-api.ts +312 -0
  197. package/src/electron/preload.ts +15 -1
  198. package/src/electron/presentation-envelope.ts +7 -1
  199. package/src/electron/presentation-handler.ts +16 -10
  200. package/src/electron/session-service.ts +265 -34
  201. package/src/polyfill/presentation-standin.ts +3 -2
  202. package/src/protocol/device-auth.ts +126 -0
  203. package/src/protocol/index.ts +1 -0
  204. package/src/protocol/proto-wire.ts +55 -0
@@ -0,0 +1,174 @@
1
+ import type { BridgeEvent, BridgeResult } from "../polyfill/bridge-types.ts";
2
+ import type { CastDevice } from "../discovery/index.ts";
3
+ import type { ReceiverApplication, ReceiverStatus } from "../client/index.ts";
4
+ import { type DevicePickerContext, type MediaRoute } from "./manager-api.ts";
5
+ /** Capability bit names in bit order: 1 video_out, 2 video_in, 4 audio_out, 8 audio_in, 32 multizone_group. */
6
+ export declare function capabilityNames(bits: number): string[];
7
+ /** A source of known Cast devices and their change events. */
8
+ export interface DeviceSource {
9
+ devices(): CastDevice[];
10
+ on(event: "deviceUp" | "deviceDown" | "deviceChanged", listener: (device: CastDevice) => void): unknown;
11
+ off(event: "deviceUp" | "deviceDown" | "deviceChanged", listener: (device: CastDevice) => void): unknown;
12
+ }
13
+ /** The subset of {@link CastClient} used by the session service. */
14
+ export interface CastClientLike {
15
+ readonly connected: boolean;
16
+ connect(): Promise<void>;
17
+ close(): void;
18
+ send(namespace: string, destinationId: string, payload: string): void;
19
+ launch(appId: string): Promise<ReceiverApplication>;
20
+ stop(sessionId: string): Promise<ReceiverStatus>;
21
+ setVolume(volume: {
22
+ level: number;
23
+ } | {
24
+ muted: boolean;
25
+ }): Promise<ReceiverStatus>;
26
+ getStatus(): Promise<ReceiverStatus>;
27
+ connectTransport(transportId: string): void;
28
+ closeTransport(transportId: string): void;
29
+ on(event: "message", listener: (msg: ClientMessage) => void): unknown;
30
+ on(event: "receiverStatus", listener: (status: ReceiverStatus) => void): unknown;
31
+ on(event: "transportClosed", listener: (transportId: string) => void): unknown;
32
+ on(event: "close", listener: (error?: Error) => void): unknown;
33
+ }
34
+ /** An inbound app message delivered by a client. */
35
+ export interface ClientMessage {
36
+ namespace: string;
37
+ sourceId: string;
38
+ destinationId: string;
39
+ data: string | Buffer;
40
+ }
41
+ /** Identity of a page (frame) talking to the service. */
42
+ export interface SenderInfo {
43
+ id: number;
44
+ origin: string;
45
+ }
46
+ /** What the picker is told about a requestSession call. */
47
+ export interface CastRequestInfo {
48
+ appId: string;
49
+ capabilities: string[];
50
+ origin: string;
51
+ senderId: number;
52
+ /** The sender's current session for this app, if it has one; the key is absent when it does not. */
53
+ session?: {
54
+ sessionId: string;
55
+ deviceId: string;
56
+ };
57
+ }
58
+ /** The picker's answer: a device to cast to, `null` (cancel) or `"stop"` (stop the sender's current session). */
59
+ export type DeviceChoice = CastDevice | null | "stop";
60
+ /** Dependencies and callbacks of {@link CastSessionService}. */
61
+ export interface CastSessionServiceOptions {
62
+ devices: DeviceSource;
63
+ createClient(device: CastDevice): CastClientLike;
64
+ /**
65
+ * Ask the user which device to cast to. Resolves a device, `null` (cancel) or
66
+ * `"stop"` (stop `request.session`, the sender's current session, if it has one).
67
+ */
68
+ selectDevice(devices: CastDevice[], request: CastRequestInfo, picker: DevicePickerContext): Promise<DeviceChoice>;
69
+ allowOrigin?(origin: string): boolean;
70
+ emit(senderId: number, event: BridgeEvent): void;
71
+ }
72
+ /**
73
+ * Main-process cast session manager: tracks initialized senders, one client per
74
+ * device and the sessions pages hold; pushes BridgeEvents back via options.emit.
75
+ */
76
+ export declare class CastSessionService {
77
+ private readonly options;
78
+ private readonly senders;
79
+ private readonly sessions;
80
+ private readonly sessionListeners;
81
+ private readonly sinks;
82
+ private readonly clients;
83
+ private readonly pendingRequests;
84
+ private readonly deviceListener;
85
+ private disposed;
86
+ constructor(options: CastSessionServiceOptions);
87
+ /** Handle one bridge call; never throws or rejects. */
88
+ handle(sender: SenderInfo, method: string, params: unknown): Promise<BridgeResult>;
89
+ /** Detach a sender that went away: cancel its pending request, leave its sessions, drop its bookkeeping. */
90
+ senderGone(senderId: number): void;
91
+ /**
92
+ * The sender's page navigated (a reload or a new page): cancel its pending request and drop its bookkeeping, but
93
+ * keep its sessions open on the device, parked, so the next page can rejoin them (auto-join or joinSession) as it
94
+ * would in Chrome. A parked session ends as usual if the receiver app stops or the device drops; senderGone ends
95
+ * the sender's share of it for good.
96
+ */
97
+ senderNavigated(senderId: number): void;
98
+ private forgetSender;
99
+ /** Unsubscribe, close every client and clear all state. */
100
+ dispose(): Promise<void>;
101
+ private handleInitialize;
102
+ private handleRequestSession;
103
+ /**
104
+ * `checkOrigin` is joinSession's own rule (mode "chromecast", which is frozen and has no
105
+ * Chromium counterpart). Joining by id, as Chrome's Presentation API path does, has none: AppActivity::CanJoinSession checks only
106
+ * the app and that the client is not connected yet.
107
+ */
108
+ private handleJoinSession;
109
+ private handleSendMessage;
110
+ private handleStopSession;
111
+ /**
112
+ * Stop a session on the device and tear it down. `stoppingBy` keeps an echoed
113
+ * receiverStatus from notifying the caller; the other members learn from that echo
114
+ * or from the sessionEnded emitted here. When `tellCaller` is set (a picker "stop"),
115
+ * the caller gets sessionEnded too, because it did not call stop itself.
116
+ */
117
+ private stopSessionRecord;
118
+ /** The sender's current session for the app, if it has one (the first one found). */
119
+ private currentSessionFor;
120
+ private handleLeaveSession;
121
+ private handleSetVolume;
122
+ private handleSetMuted;
123
+ /** The device's client entry, created and connecting on first use. */
124
+ private clientFor;
125
+ /**
126
+ * Join a session by its id, as Chrome's Media Router does for `reconnect("cast-session_<id>")`. A session this
127
+ * service already holds is joined without an origin check, like one found on a device. Otherwise the id is looked up
128
+ * in the receiver status of
129
+ * every known device: Chrome's CastSessionTracker learns the sessions running on all sinks and
130
+ * CastActivityManager::AddNonLocalActivity makes them joinable by id (and only by id: auto-join skips them, and no
131
+ * origin is checked). `appId`, when given, must be the session's app (CastActivity::CanJoinSession). Unlike Chrome
132
+ * the lookup runs when asked instead of tracking every device all the time.
133
+ */
134
+ private handleJoinRunningSession;
135
+ /**
136
+ * Ask every known device what it runs and resolve with the one running `sessionId`. The winner's `opening` count
137
+ * stays raised for the caller to release; a device that cannot be reached or runs something else is let go.
138
+ */
139
+ private findRunningSession;
140
+ /** Connect (or reuse) the device's client, launch the app and register the session. */
141
+ private openSession;
142
+ /** Remove a sender from a session; when it was the last one, tear the session down. */
143
+ private leave;
144
+ /** Subscribe to a freshly created client's events. */
145
+ private bindClient;
146
+ private onClientMessage;
147
+ private onClientStatus;
148
+ private onTransportClosed;
149
+ private onClientClose;
150
+ /** Re-check availability for every initialized sender; emit only on change. */
151
+ private onDevicesChanged;
152
+ /** Close the client when no session uses it any more and no openSession is in flight. */
153
+ private cleanupIdle;
154
+ /** Forget a client and close it; a no-op unless it is still the registered entry for the device. */
155
+ private dropClient;
156
+ /** Every live session, parked ones included. */
157
+ mediaRoutes(): MediaRoute[];
158
+ /** Be told when a session starts, changes (status, volume, pages) or ends; returns the unsubscribe function. */
159
+ observeSessions(listener: () => void): () => void;
160
+ /** Stop a session on the device for every page, as if a member had called stopSession. */
161
+ terminateSession(sessionId: string): Promise<BridgeResult>;
162
+ setSessionVolume(sessionId: string, volume: {
163
+ level: number;
164
+ } | {
165
+ muted: boolean;
166
+ }): Promise<BridgeResult>;
167
+ /** Detach every page from the session and close its transport; the receiver app keeps running. */
168
+ detachSession(sessionId: string): BridgeResult;
169
+ /** Tell the route observers something changed (the arguments only fit the ObservedMap callback). */
170
+ private notifySession;
171
+ private routeOf;
172
+ private snapshotOf;
173
+ private emitTo;
174
+ }