1 | import { EventEmitter } from "events";
|
2 | import { AudioBitrate, AudioSamplerate } from "../camera";
|
3 | import { HDSProtocolSpecificErrorReason, DataStreamConnection, DataStreamProtocolHandler, EventHandler, RequestHandler } from "../datastream";
|
4 | import type { AudioStreamManagement, DataStreamTransportManagement, Siri, TargetControl, TargetControlManagement } from "../definitions";
|
5 | import { ControllerIdentifier, ControllerServiceMap, SerializableController, StateChangeDelegate } from "./Controller";
|
6 |
|
7 |
|
8 |
|
9 | export declare const enum ButtonType {
|
10 | UNDEFINED = 0,
|
11 | MENU = 1,
|
12 | PLAY_PAUSE = 2,
|
13 | TV_HOME = 3,
|
14 | SELECT = 4,
|
15 | ARROW_UP = 5,
|
16 | ARROW_RIGHT = 6,
|
17 | ARROW_DOWN = 7,
|
18 | ARROW_LEFT = 8,
|
19 | VOLUME_UP = 9,
|
20 | VOLUME_DOWN = 10,
|
21 | SIRI = 11,
|
22 | POWER = 12,
|
23 | GENERIC = 13
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 | export declare const enum TargetCategory {
|
29 | UNDEFINED = 0,
|
30 | APPLE_TV = 24
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | export declare const enum ButtonState {
|
36 | UP = 0,
|
37 | DOWN = 1
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 | export type SupportedConfiguration = {
|
43 | maximumTargets: number;
|
44 | ticksPerSecond: number;
|
45 | supportedButtonConfiguration: SupportedButtonConfiguration[];
|
46 | hardwareImplemented: boolean;
|
47 | };
|
48 |
|
49 |
|
50 |
|
51 | export type SupportedButtonConfiguration = {
|
52 | buttonID: number;
|
53 | buttonType: ButtonType;
|
54 | };
|
55 |
|
56 |
|
57 |
|
58 | export type TargetConfiguration = {
|
59 | targetIdentifier: number;
|
60 | targetName?: string;
|
61 | targetCategory?: TargetCategory;
|
62 | buttonConfiguration: Record<number, ButtonConfiguration>;
|
63 | };
|
64 |
|
65 |
|
66 |
|
67 | export type ButtonConfiguration = {
|
68 | buttonID: number;
|
69 | buttonType: ButtonType;
|
70 | buttonName?: string;
|
71 | };
|
72 |
|
73 |
|
74 |
|
75 | export declare const enum AudioCodecTypes {
|
76 | PCMU = 0,
|
77 | PCMA = 1,
|
78 | AAC_ELD = 2,
|
79 | OPUS = 3,
|
80 | MSBC = 4,
|
81 | AMR = 5,
|
82 | AMR_WB = 6
|
83 | }
|
84 | type SupportedAudioStreamConfiguration = {
|
85 | audioCodecConfiguration: AudioCodecConfiguration;
|
86 | };
|
87 |
|
88 |
|
89 |
|
90 | export type AudioCodecConfiguration = {
|
91 | codecType: AudioCodecTypes;
|
92 | parameters: AudioCodecParameters;
|
93 | };
|
94 |
|
95 |
|
96 |
|
97 | export type AudioCodecParameters = {
|
98 | channels: number;
|
99 | bitrate: AudioBitrate;
|
100 | samplerate: AudioSamplerate;
|
101 | rtpTime?: RTPTime;
|
102 | };
|
103 |
|
104 |
|
105 |
|
106 | export type RTPTime = 20 | 30 | 40 | 60;
|
107 | declare const enum SiriAudioSessionState {
|
108 | STARTING = 0,
|
109 | SENDING = 1,
|
110 | CLOSING = 2,
|
111 | CLOSED = 3
|
112 | }
|
113 |
|
114 |
|
115 |
|
116 | export type AudioFrame = {
|
117 | data: Buffer;
|
118 | rms: number;
|
119 | };
|
120 |
|
121 |
|
122 |
|
123 | export type FrameHandler = (frame: AudioFrame) => void;
|
124 |
|
125 |
|
126 |
|
127 | export type ErrorHandler = (error: HDSProtocolSpecificErrorReason) => void;
|
128 |
|
129 |
|
130 |
|
131 | export interface SiriAudioStreamProducer {
|
132 | startAudioProduction(selectedAudioConfiguration: AudioCodecConfiguration): void;
|
133 | stopAudioProduction(): void;
|
134 | }
|
135 |
|
136 |
|
137 |
|
138 | export interface SiriAudioStreamProducerConstructor {
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | new (frameHandler: FrameHandler, errorHandler: ErrorHandler, options?: any): SiriAudioStreamProducer;
|
147 | }
|
148 |
|
149 |
|
150 |
|
151 | export declare const enum TargetUpdates {
|
152 | NAME = 0,
|
153 | CATEGORY = 1,
|
154 | UPDATED_BUTTONS = 2,
|
155 | REMOVED_BUTTONS = 3
|
156 | }
|
157 |
|
158 |
|
159 |
|
160 | export declare const enum RemoteControllerEvents {
|
161 | |
162 |
|
163 |
|
164 |
|
165 | ACTIVE_CHANGE = "active-change",
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | ACTIVE_IDENTIFIER_CHANGE = "active-identifier-change",
|
173 | |
174 |
|
175 |
|
176 |
|
177 | TARGET_ADDED = "target-add",
|
178 | |
179 |
|
180 |
|
181 |
|
182 | TARGET_UPDATED = "target-update",
|
183 | |
184 |
|
185 |
|
186 | TARGET_REMOVED = "target-remove",
|
187 | |
188 |
|
189 |
|
190 |
|
191 |
|
192 | TARGETS_RESET = "targets-reset"
|
193 | }
|
194 |
|
195 |
|
196 |
|
197 | export declare interface RemoteController {
|
198 | on(event: "active-change", listener: (active: boolean) => void): this;
|
199 | on(event: "active-identifier-change", listener: (activeIdentifier: number) => void): this;
|
200 | on(event: "target-add", listener: (targetConfiguration: TargetConfiguration) => void): this;
|
201 | on(event: "target-update", listener: (targetConfiguration: TargetConfiguration, updates: TargetUpdates[]) => void): this;
|
202 | on(event: "target-remove", listener: (targetIdentifier: number) => void): this;
|
203 | on(event: "targets-reset", listener: () => void): this;
|
204 | emit(event: "active-change", active: boolean): boolean;
|
205 | emit(event: "active-identifier-change", activeIdentifier: number): boolean;
|
206 | emit(event: "target-add", targetConfiguration: TargetConfiguration): boolean;
|
207 | emit(event: "target-update", targetConfiguration: TargetConfiguration, updates: TargetUpdates[]): boolean;
|
208 | emit(event: "target-remove", targetIdentifier: number): boolean;
|
209 | emit(event: "targets-reset"): boolean;
|
210 | }
|
211 |
|
212 |
|
213 |
|
214 | export interface RemoteControllerServiceMap extends ControllerServiceMap {
|
215 | targetControlManagement: TargetControlManagement;
|
216 | targetControl: TargetControl;
|
217 | siri?: Siri;
|
218 | audioStreamManagement?: AudioStreamManagement;
|
219 | dataStreamTransportManagement?: DataStreamTransportManagement;
|
220 | }
|
221 |
|
222 |
|
223 |
|
224 | export interface SerializedControllerState {
|
225 | activeIdentifier: number;
|
226 | targetConfigurations: Record<number, TargetConfiguration>;
|
227 | }
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 | export declare class RemoteController extends EventEmitter implements SerializableController<RemoteControllerServiceMap, SerializedControllerState>, DataStreamProtocolHandler {
|
234 | private stateChangeDelegate?;
|
235 | private readonly audioSupported;
|
236 | private readonly audioProducerConstructor?;
|
237 | private readonly audioProducerOptions?;
|
238 | private targetControlManagementService?;
|
239 | private targetControlService?;
|
240 | private siriService?;
|
241 | private audioStreamManagementService?;
|
242 | private dataStreamManagement?;
|
243 | private buttons;
|
244 | private readonly supportedConfiguration;
|
245 | targetConfigurations: Map<number, TargetConfiguration>;
|
246 | private targetConfigurationsString;
|
247 | private lastButtonEvent;
|
248 | activeIdentifier: number;
|
249 | private activeConnection?;
|
250 | private activeConnectionDisconnectListener?;
|
251 | private readonly supportedAudioConfiguration;
|
252 | private selectedAudioConfiguration;
|
253 | private selectedAudioConfigurationString;
|
254 | private dataStreamConnections;
|
255 | private activeAudioSession?;
|
256 | private nextAudioSession?;
|
257 | |
258 |
|
259 |
|
260 | eventHandler?: Record<string, EventHandler>;
|
261 | |
262 |
|
263 |
|
264 | requestHandler?: Record<string, RequestHandler>;
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | constructor(audioProducerConstructor?: SiriAudioStreamProducerConstructor, producerOptions?: any);
|
277 | /**
|
278 | * @private
|
279 | */
|
280 | controllerId(): ControllerIdentifier;
|
281 | /**
|
282 | * Set a new target as active target. A value of 0 indicates that no target is selected currently.
|
283 | *
|
284 | * @param activeIdentifier - target identifier
|
285 | */
|
286 | setActiveIdentifier(activeIdentifier: number): void;
|
287 | /**
|
288 | * @returns if the current target is active, meaning the active device is listening for button events or audio sessions
|
289 | */
|
290 | isActive(): boolean;
|
291 | /**
|
292 | * Checks if the supplied targetIdentifier is configured.
|
293 | *
|
294 | * @param targetIdentifier - The target identifier.
|
295 | */
|
296 | isConfigured(targetIdentifier: number): boolean;
|
297 | /**
|
298 | * Returns the targetIdentifier for a give device name
|
299 | *
|
300 | * @param name - The name of the device.
|
301 | * @returns The targetIdentifier of the device or undefined if not existent.
|
302 | */
|
303 | getTargetIdentifierByName(name: string): number | undefined;
|
304 | /**
|
305 | * Sends a button event to press the supplied button.
|
306 | *
|
307 | * @param button - button to be pressed
|
308 | */
|
309 | pushButton(button: ButtonType): void;
|
310 | /**
|
311 | * Sends a button event that the supplied button was released.
|
312 | *
|
313 | * @param button - button which was released
|
314 | */
|
315 | releaseButton(button: ButtonType): void;
|
316 | /**
|
317 | * Presses a supplied button for a given time.
|
318 | *
|
319 | * @param button - button to be pressed and released
|
320 | * @param time - time in milliseconds (defaults to 200ms)
|
321 | */
|
322 | pushAndReleaseButton(button: ButtonType, time?: number): void;
|
323 | protected constructSupportedConfiguration(): SupportedConfiguration;
|
324 | protected constructSupportedAudioConfiguration(): SupportedAudioStreamConfiguration;
|
325 | private handleTargetControlWrite;
|
326 | private handleAddTarget;
|
327 | private handleUpdateTarget;
|
328 | private handleRemoveTarget;
|
329 | private handleResetTargets;
|
330 | private handleListTargets;
|
331 | private handleActiveWrite;
|
332 | private setInactive;
|
333 | private handleActiveSessionDisconnected;
|
334 | private sendButtonEvent;
|
335 | private parseTargetConfigurationTLV;
|
336 | private updatedTargetConfiguration;
|
337 | private buildTargetControlSupportedConfigurationTLV;
|
338 | private handleTargetControlWhoAmI;
|
339 | private handleSiriAudioStart;
|
340 | private handleSiriAudioStop;
|
341 | private handleDataSendAckEvent;
|
342 | private handleDataSendCloseEvent;
|
343 | private handleSiriAudioSessionClosed;
|
344 | private handleDataStreamConnectionClosed;
|
345 | private handleSelectedAudioConfigurationWrite;
|
346 | private static buildSupportedAudioConfigurationTLV;
|
347 | private static buildSelectedAudioConfigurationTLV;
|
348 | private static buildCodecConfigurationTLV;
|
349 | /**
|
350 | * @private
|
351 | */
|
352 | constructServices(): RemoteControllerServiceMap;
|
353 | /**
|
354 | * @private
|
355 | */
|
356 | initWithServices(serviceMap: RemoteControllerServiceMap): void | RemoteControllerServiceMap;
|
357 | /**
|
358 | * @private
|
359 | */
|
360 | configureServices(): void;
|
361 | /**
|
362 | * @private
|
363 | */
|
364 | handleControllerRemoved(): void;
|
365 | /**
|
366 | * @private
|
367 | */
|
368 | handleFactoryReset(): void;
|
369 | /**
|
370 | * @private
|
371 | */
|
372 | serialize(): SerializedControllerState | undefined;
|
373 | /**
|
374 | * @private
|
375 | */
|
376 | deserialize(serialized: SerializedControllerState): void;
|
377 | /**
|
378 | * @private
|
379 | */
|
380 | setupStateChangeDelegate(delegate?: StateChangeDelegate): void;
|
381 | }
|
382 | /**
|
383 | * @group Apple TV Remote
|
384 | */
|
385 | export declare const enum SiriAudioSessionEvents {
|
386 | CLOSE = "close"
|
387 | }
|
388 |
|
389 |
|
390 |
|
391 | export declare interface SiriAudioSession {
|
392 | on(event: "close", listener: () => void): this;
|
393 | emit(event: "close"): boolean;
|
394 | }
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | export declare class SiriAudioSession extends EventEmitter {
|
400 | readonly connection: DataStreamConnection;
|
401 | private readonly selectedAudioConfiguration;
|
402 | private readonly producer;
|
403 | private producerRunning;
|
404 | private producerTimer?;
|
405 | |
406 |
|
407 |
|
408 | state: SiriAudioSessionState;
|
409 | streamId?: number;
|
410 | endOfStream: boolean;
|
411 | private audioFrameQueue;
|
412 | private readonly maxQueueSize;
|
413 | private sequenceNumber;
|
414 | private readonly closeListener;
|
415 | constructor(connection: DataStreamConnection, selectedAudioConfiguration: AudioCodecConfiguration, producerConstructor: SiriAudioStreamProducerConstructor, producerOptions?: any);
|
416 | /**
|
417 | * Called when siri button is pressed
|
418 | */
|
419 | start(): void;
|
420 | /**
|
421 | * @returns if the audio session is closing
|
422 | */
|
423 | isClosing(): boolean;
|
424 | /**
|
425 | * Called when siri button is released (or active identifier is changed to another device)
|
426 | */
|
427 | stop(): void;
|
428 | private startAudioProducer;
|
429 | private stopAudioProducer;
|
430 | private handleSiriAudioFrame;
|
431 | private handleProducerError;
|
432 | handleDataSendAckEvent(endOfStream: boolean): void;
|
433 | handleDataSendCloseEvent(reason: HDSProtocolSpecificErrorReason): void;
|
434 | private sendDataSendCloseEvent;
|
435 | private handleDataStreamConnectionClosed;
|
436 | private closed;
|
437 | private popSome;
|
438 | }
|
439 | export {};
|
440 |
|
\ | No newline at end of file |