@sebbo2002/node-pyatv 6.0.0-develop.1 → 6.0.0-develop.3

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 (120) hide show
  1. package/dist/bin/check.cjs +10 -0
  2. package/dist/bin/check.cjs.map +1 -0
  3. package/dist/bin/check.d.ts +2 -1
  4. package/dist/bin/check.js +4 -45
  5. package/dist/bin/check.js.map +1 -1
  6. package/dist/chunk-TZSWUAOB.js +7 -0
  7. package/dist/chunk-TZSWUAOB.js.map +1 -0
  8. package/dist/lib/index.cjs +7 -0
  9. package/dist/lib/index.cjs.map +1 -0
  10. package/dist/lib/{device.d.ts → index.d.cts} +351 -4
  11. package/dist/lib/index.d.ts +806 -6
  12. package/dist/lib/index.js +1 -7
  13. package/dist/lib/index.js.map +1 -1
  14. package/package.json +23 -14
  15. package/.editorconfig +0 -12
  16. package/.eslintignore +0 -4
  17. package/.eslintrc +0 -60
  18. package/.mocharc.yml +0 -7
  19. package/.nycrc +0 -32
  20. package/CHANGELOG.md +0 -288
  21. package/check.sh +0 -5
  22. package/dist/examples/push.d.ts +0 -1
  23. package/dist/examples/push.js +0 -51
  24. package/dist/examples/push.js.map +0 -1
  25. package/dist/lib/device-event.d.ts +0 -44
  26. package/dist/lib/device-event.js +0 -47
  27. package/dist/lib/device-event.js.map +0 -1
  28. package/dist/lib/device-events.d.ts +0 -30
  29. package/dist/lib/device-events.js +0 -237
  30. package/dist/lib/device-events.js.map +0 -1
  31. package/dist/lib/device.js +0 -756
  32. package/dist/lib/device.js.map +0 -1
  33. package/dist/lib/fake-spawn.d.ts +0 -43
  34. package/dist/lib/fake-spawn.js +0 -85
  35. package/dist/lib/fake-spawn.js.map +0 -1
  36. package/dist/lib/instance.d.ts +0 -97
  37. package/dist/lib/instance.js +0 -208
  38. package/dist/lib/instance.js.map +0 -1
  39. package/dist/lib/tools.d.ts +0 -12
  40. package/dist/lib/tools.js +0 -319
  41. package/dist/lib/tools.js.map +0 -1
  42. package/dist/lib/types.d.ts +0 -199
  43. package/dist/lib/types.js +0 -108
  44. package/dist/lib/types.js.map +0 -1
  45. package/docs/coverage/base.css +0 -224
  46. package/docs/coverage/block-navigation.js +0 -87
  47. package/docs/coverage/cobertura-coverage.xml +0 -2829
  48. package/docs/coverage/device-event.ts.html +0 -256
  49. package/docs/coverage/device-events.ts.html +0 -970
  50. package/docs/coverage/device.ts.html +0 -2401
  51. package/docs/coverage/fake-spawn.ts.html +0 -448
  52. package/docs/coverage/favicon.png +0 -0
  53. package/docs/coverage/index.html +0 -221
  54. package/docs/coverage/index.ts.html +0 -172
  55. package/docs/coverage/instance.ts.html +0 -718
  56. package/docs/coverage/prettify.css +0 -1
  57. package/docs/coverage/prettify.js +0 -2
  58. package/docs/coverage/sort-arrow-sprite.png +0 -0
  59. package/docs/coverage/sorter.js +0 -196
  60. package/docs/coverage/tools.ts.html +0 -1222
  61. package/docs/coverage/types.ts.html +0 -757
  62. package/docs/reference/.nojekyll +0 -1
  63. package/docs/reference/assets/highlight.css +0 -99
  64. package/docs/reference/assets/main.js +0 -58
  65. package/docs/reference/assets/search.js +0 -1
  66. package/docs/reference/assets/style.css +0 -1280
  67. package/docs/reference/classes/NodePyATVDevice.html +0 -1228
  68. package/docs/reference/classes/NodePyATVDeviceEvent.html +0 -123
  69. package/docs/reference/classes/NodePyATVInstance.html +0 -240
  70. package/docs/reference/enums/NodePyATVDeviceState.html +0 -97
  71. package/docs/reference/enums/NodePyATVExecutableType.html +0 -69
  72. package/docs/reference/enums/NodePyATVKeys.html +0 -216
  73. package/docs/reference/enums/NodePyATVListenerState.html +0 -83
  74. package/docs/reference/enums/NodePyATVMediaType.html +0 -83
  75. package/docs/reference/enums/NodePyATVPowerState.html +0 -69
  76. package/docs/reference/enums/NodePyATVProtocol.html +0 -83
  77. package/docs/reference/enums/NodePyATVRepeatState.html +0 -76
  78. package/docs/reference/enums/NodePyATVShuffleState.html +0 -76
  79. package/docs/reference/index.html +0 -139
  80. package/docs/reference/interfaces/NodePyATVDeviceOptions.html +0 -232
  81. package/docs/reference/interfaces/NodePyATVFindAndInstanceOptions.html +0 -193
  82. package/docs/reference/interfaces/NodePyATVFindOptions.html +0 -124
  83. package/docs/reference/interfaces/NodePyATVGetStateOptions.html +0 -66
  84. package/docs/reference/interfaces/NodePyATVInstanceOptions.html +0 -113
  85. package/docs/reference/interfaces/NodePyATVService.html +0 -73
  86. package/docs/reference/interfaces/NodePyATVState.html +0 -164
  87. package/docs/reference/interfaces/NodePyATVVersionResponse.html +0 -73
  88. package/docs/reference/modules.html +0 -106
  89. package/docs/reference/types/NodePyATVEventValueType.html +0 -66
  90. package/docs/tests/assets/MaterialIcons-Regular.woff +0 -0
  91. package/docs/tests/assets/MaterialIcons-Regular.woff2 +0 -0
  92. package/docs/tests/assets/app.css +0 -14
  93. package/docs/tests/assets/app.js +0 -2
  94. package/docs/tests/assets/app.js.LICENSE.txt +0 -55
  95. package/docs/tests/assets/roboto-light-webfont.woff +0 -0
  96. package/docs/tests/assets/roboto-light-webfont.woff2 +0 -0
  97. package/docs/tests/assets/roboto-medium-webfont.woff +0 -0
  98. package/docs/tests/assets/roboto-medium-webfont.woff2 +0 -0
  99. package/docs/tests/assets/roboto-regular-webfont.woff +0 -0
  100. package/docs/tests/assets/roboto-regular-webfont.woff2 +0 -0
  101. package/docs/tests/index.html +0 -2
  102. package/docs/tests/mochawesome.json +0 -4745
  103. package/release.config.cjs +0 -51
  104. package/src/bin/check.ts +0 -41
  105. package/src/examples/push.ts +0 -46
  106. package/src/lib/device-event.ts +0 -57
  107. package/src/lib/device-events.ts +0 -295
  108. package/src/lib/device.ts +0 -772
  109. package/src/lib/fake-spawn.ts +0 -121
  110. package/src/lib/index.ts +0 -29
  111. package/src/lib/instance.ts +0 -211
  112. package/src/lib/tools.ts +0 -379
  113. package/src/lib/types.ts +0 -224
  114. package/test/device-event.ts +0 -88
  115. package/test/device-events.ts +0 -502
  116. package/test/device.ts +0 -784
  117. package/test/instance.ts +0 -428
  118. package/test/tools.ts +0 -301
  119. package/tsconfig.json +0 -19
  120. package/typedoc.json +0 -15
package/src/lib/device.ts DELETED
@@ -1,772 +0,0 @@
1
- 'use strict';
2
-
3
- import {
4
- NodePyATVDeviceOptions,
5
- NodePyATVDeviceState,
6
- NodePyATVExecutableType,
7
- NodePyATVGetStateOptions,
8
- NodePyATVInternalKeys,
9
- NodePyATVKeys,
10
- NodePyATVMediaType,
11
- NodePyATVProtocol,
12
- NodePyATVRepeatState,
13
- NodePyATVService,
14
- NodePyATVShuffleState,
15
- NodePyATVState
16
- } from './types.js';
17
-
18
- import { addRequestId, getParamters, parseState, removeRequestId, request } from './tools.js';
19
- import { NodePyATVDeviceEvent, NodePyATVDeviceEvents } from '../lib/index.js';
20
- import { EventEmitter } from 'events';
21
-
22
- /**
23
- * Represents an Apple TV. Use [[getState]] to query the current state (e.g. media
24
- * type and title). You can also use the attribute methods (e.g. [[getTitle]] to get
25
- * the state. If you want realtime updates, subscribe to it's events with an
26
- * `EventEmitter` like API, so for example by using [[on]], [[once]] or [[addListener]].
27
- * It's also possible to send key commands by using [[pressKey]] or methods like [[pause]].
28
- */
29
- export default class NodePyATVDevice implements EventEmitter{
30
- private readonly options: NodePyATVDeviceOptions;
31
- private readonly state: NodePyATVState;
32
- private readonly events: NodePyATVDeviceEvents;
33
-
34
- constructor(options: NodePyATVDeviceOptions) {
35
- this.options = Object.assign({}, options);
36
- this.state = parseState({}, '', {});
37
- this.events = new NodePyATVDeviceEvents(this.state, this, this.options);
38
-
39
- // @todo basic validation
40
- }
41
-
42
- /**
43
- * Get the name of the Apple TV.
44
- *
45
- * ```typescript
46
- * import pyatv from '@sebbo2002/node-pyatv';
47
- * const devices = await pyatv.find();
48
- * devices.forEach(device =>
49
- * console.log(device.name)
50
- * );
51
- * ```
52
- */
53
- get name(): string {
54
- return this.options.name;
55
- }
56
-
57
- /**
58
- * Get the IP address of the Apple TV.
59
- */
60
- get host(): string {
61
- return this.options.host;
62
- }
63
-
64
- /**
65
- * Get the ID of the Apple TV.
66
- */
67
- get id(): string | undefined {
68
- return this.options.id;
69
- }
70
-
71
- /**
72
- * Get the used protocol to connect to the Apple TV.
73
- */
74
- get protocol(): NodePyATVProtocol | undefined {
75
- return this.options.protocol;
76
- }
77
-
78
- /**
79
- * Get the model identifier of the device. Only set, if the
80
- * device was found using [[find()]]. Requires pyatv ≧ 0.10.3.
81
- *
82
- * @example device.model → "Gen4K"
83
- */
84
- get model(): string | undefined {
85
- return this.options.model;
86
- }
87
-
88
- /**
89
- * Get the model name of the device. Only set, if the device
90
- * was found with [[find()]]. Requires pyatv ≧ 0.10.3.
91
- *
92
- * @example device.modelName → "Apple TV 4K"
93
- */
94
- get modelName(): string | undefined {
95
- return this.options.modelName;
96
- }
97
-
98
- /**
99
- * Get the operating system of the device. Only set, if the
100
- * device was found with [[find()]]. Requires pyatv ≧ 0.10.3.
101
- *
102
- * @example device.os → "TvOS"
103
- */
104
- get os(): string | undefined {
105
- return this.options.os;
106
- }
107
-
108
- /**
109
- * Get the device version. Only set, if the device was found
110
- * during a scan using [[find()]]. Requires pyatv ≧ 0.10.3.
111
- *
112
- * @example device.version → "15.5.1"
113
- */
114
- get version(): string | undefined {
115
- return this.options.version;
116
- }
117
-
118
- /**
119
- * Returns a list of services supported by the device. Ony set, if
120
- * the device was found during a scan using [[find()]]. Requires
121
- * pyatv ≧ 0.10.3.
122
- *
123
- * @example device.services → [
124
- * {
125
- * "protocol": "airplay",
126
- * "port": 7000
127
- * },
128
- * {
129
- * "protocol": "dmap",
130
- * "port": 3689
131
- * }
132
- * ]
133
- */
134
- get services(): NodePyATVService[] | undefined {
135
- return this.options.services;
136
- }
137
-
138
-
139
- /**
140
- * Returns true, if debugging is enabled. Returns the custom
141
- * logging method, if one was specified. Otherwise, if debug
142
- * log is disabled, returns undefined.
143
- */
144
- get debug(): true | ((msg: string) => void) | undefined {
145
- return this.options.debug;
146
- }
147
-
148
- /**
149
- * Enable or disable debugging or set a custom
150
- * debugging method to use.
151
- *
152
- * @param debug
153
- */
154
- set debug(debug: true | ((msg: string) => void) | undefined) {
155
- if (typeof debug === 'function') {
156
- this.options.debug = debug;
157
- }
158
- else {
159
- this.options.debug = Boolean(debug) || undefined;
160
- }
161
- }
162
-
163
- /**
164
- * Returns an object with `name`, `host`, `id` and `protocol`.
165
- * Can be used to initiate a new device instance.
166
- *
167
- * @category Basic
168
- */
169
- toJSON(): { name: string; host: string; id: string | undefined; protocol: NodePyATVProtocol | undefined } {
170
- return {
171
- name: this.name,
172
- host: this.host,
173
- id: this.id,
174
- protocol: this.protocol
175
- };
176
- }
177
-
178
- /**
179
- * Returns a string. Just for debugging, etc.
180
- *
181
- * @category Basic
182
- */
183
- toString(): string {
184
- return `NodePyATVDevice(${this.name}, ${this.host})`;
185
- }
186
-
187
- /**
188
- * Returns an [[NodePyATVState]] object representing the current state
189
- * of the device. Has an internal cache, which has a default TTL of 5s.
190
- * You can change this default value by passing the `maxAge` option.
191
- *
192
- * ```typescript
193
- * await device.getState({maxAge: 10000}); // cache TTL: 10s
194
- * ```
195
- *
196
- * @param options
197
- * @category State
198
- */
199
- async getState(options: NodePyATVGetStateOptions = {}): Promise<NodePyATVState> {
200
- if (this.state?.dateTime && new Date().getTime() - this.state.dateTime.getTime() < (options.maxAge || 5000)) {
201
- let position = null;
202
- if (this.state.position && this.state.dateTime) {
203
- position = Math.round(
204
- this.state.position +
205
- ((new Date().getTime() - this.state.dateTime.getTime()) / 1000)
206
- );
207
- }
208
-
209
- return Object.assign({}, this.state, {position});
210
- }
211
-
212
- const id = addRequestId();
213
-
214
- try {
215
- const parameters = getParamters(this.options);
216
-
217
- const result = await request(id, NodePyATVExecutableType.atvscript, [...parameters, 'playing'], this.options);
218
- const newState = parseState(result, id, this.options);
219
-
220
- this.applyState(newState);
221
- return newState;
222
- }
223
- finally {
224
- removeRequestId(id);
225
- }
226
- }
227
-
228
- /**
229
- * Removes the state node-pyatv cached for this device.
230
- *
231
- * @category State
232
- */
233
- clearState(): void {
234
- this.applyState(parseState({}, '', {}));
235
- }
236
-
237
- private applyState(newState: NodePyATVState): void {
238
- this.events.applyStateAndEmitEvents(newState);
239
- }
240
-
241
- /**
242
- * Get the date and time when the state was last updated.
243
- * @param options
244
- * @category State
245
- */
246
- async getDateTime(options: NodePyATVGetStateOptions = {}): Promise<Date | null> {
247
- const state = await this.getState(options);
248
- return state.dateTime;
249
- }
250
-
251
- /**
252
- * Get the hash of the current media
253
- * @param options
254
- * @category State
255
- */
256
- async getHash(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
257
- const state = await this.getState(options);
258
- return state.hash;
259
- }
260
-
261
- /**
262
- * Get the media type of the current media
263
- * @param options
264
- * @category State
265
- */
266
- async getMediaType(options: NodePyATVGetStateOptions = {}): Promise<NodePyATVMediaType | null> {
267
- const state = await this.getState(options);
268
- return state.mediaType;
269
- }
270
-
271
- /**
272
- * Get the state of this device (e.g. playing, etc.)
273
- * @param options
274
- * @category State
275
- */
276
- async getDeviceState(options: NodePyATVGetStateOptions = {}): Promise<NodePyATVDeviceState | null> {
277
- const state = await this.getState(options);
278
- return state.deviceState;
279
- }
280
-
281
- /**
282
- * Returns the title of the current playing media
283
- * @param options
284
- * @category State
285
- */
286
- async getTitle(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
287
- const state = await this.getState(options);
288
- return state.title;
289
- }
290
-
291
- /**
292
- * Returns the artist of the current playing media
293
- * @param options
294
- * @category State
295
- */
296
- async getArtist(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
297
- const state = await this.getState(options);
298
- return state.artist;
299
- }
300
-
301
- /**
302
- * Returns the album of the current playing media
303
- * @param options
304
- * @category State
305
- */
306
- async getAlbum(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
307
- const state = await this.getState(options);
308
- return state.album;
309
- }
310
-
311
- /**
312
- * Returns the genre of the current playing media
313
- * @param options
314
- * @category State
315
- */
316
- async getGenre(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
317
- const state = await this.getState(options);
318
- return state.genre;
319
- }
320
-
321
- /**
322
- * Returns the media length of the current playing media
323
- * @param options
324
- * @category State
325
- */
326
- async getTotalTime(options: NodePyATVGetStateOptions = {}): Promise<number | null> {
327
- const state = await this.getState(options);
328
- return state.totalTime;
329
- }
330
-
331
- /**
332
- * Returns the title of the current playing media
333
- * @param options
334
- * @category State
335
- */
336
- async getPosition(options: NodePyATVGetStateOptions = {}): Promise<number | null> {
337
- const state = await this.getState(options);
338
- return state.position;
339
- }
340
-
341
- /**
342
- * Returns the shuffle state
343
- * @param options
344
- * @category State
345
- */
346
- async getShuffle(options: NodePyATVGetStateOptions = {}): Promise<NodePyATVShuffleState | null> {
347
- const state = await this.getState(options);
348
- return state.shuffle;
349
- }
350
-
351
- /**
352
- * Returns the repeat state
353
- * @param options
354
- * @category State
355
- */
356
- async getRepeat(options: NodePyATVGetStateOptions = {}): Promise<NodePyATVRepeatState | null> {
357
- const state = await this.getState(options);
358
- return state.repeat;
359
- }
360
-
361
- /**
362
- * Returns the currently used app
363
- * @param options
364
- * @category State
365
- */
366
- async getApp(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
367
- const state = await this.getState(options);
368
- return state.app;
369
- }
370
-
371
- /**
372
- * Returns the id of the currently used app
373
- * @param options
374
- * @category State
375
- */
376
- async getAppId(options: NodePyATVGetStateOptions = {}): Promise<string | null> {
377
- const state = await this.getState(options);
378
- return state.appId;
379
- }
380
-
381
- private async _pressKey(key: NodePyATVInternalKeys, executableType: NodePyATVExecutableType) {
382
- const id = addRequestId();
383
- const parameters = getParamters(this.options);
384
-
385
- const result = await request(id, executableType, [...parameters, key], this.options);
386
- if (
387
- executableType === NodePyATVExecutableType.atvscript &&
388
- (typeof result !== 'object' || result.result !== 'success')
389
- ) {
390
- throw new Error(`Unable to parse pyatv response: ${JSON.stringify(result, null, ' ')}`);
391
- }
392
-
393
- removeRequestId(id);
394
- }
395
-
396
- /**
397
- * Send a key press to the Apple TV
398
- *
399
- * ```typescript
400
- * await device.pressKey(NodePyATVKeys.home);
401
- * ```
402
- *
403
- * <br />
404
- *
405
- * ```javascript
406
- * await device.pressKey('home');
407
- * ```
408
- *
409
- * @param key
410
- * @category Control
411
- */
412
- async pressKey(key: NodePyATVKeys): Promise<void> {
413
- const internalKeyEntry = Object.entries(NodePyATVInternalKeys)
414
- .find(([k]) => key === k);
415
-
416
- if(!internalKeyEntry) {
417
- throw new Error(`Unsupported key value ${key}!`);
418
- }
419
-
420
- const internalKey = internalKeyEntry[1];
421
- const executableType = [NodePyATVKeys.turnOn, NodePyATVKeys.turnOff].includes(key) ?
422
- NodePyATVExecutableType.atvremote :
423
- NodePyATVExecutableType.atvscript;
424
-
425
- await this._pressKey(internalKey, executableType);
426
- }
427
-
428
- /**
429
- * Send the "down" command
430
- * @category Control
431
- */
432
- async down(): Promise<void> {
433
- await this._pressKey(NodePyATVInternalKeys.down, NodePyATVExecutableType.atvscript);
434
- }
435
-
436
- /**
437
- * Send the "home" command
438
- * @category Control
439
- */
440
- async home(): Promise<void> {
441
- await this._pressKey(NodePyATVInternalKeys.home, NodePyATVExecutableType.atvscript);
442
- }
443
-
444
- /**
445
- * Send the "homeHold" command
446
- * @category Control
447
- */
448
- async homeHold(): Promise<void> {
449
- await this._pressKey(NodePyATVInternalKeys.homeHold, NodePyATVExecutableType.atvscript);
450
- }
451
-
452
- /**
453
- * Send the "left" command
454
- * @category Control
455
- */
456
- async left(): Promise<void> {
457
- await this._pressKey(NodePyATVInternalKeys.left, NodePyATVExecutableType.atvscript);
458
- }
459
-
460
- /**
461
- * Send the "menu" command
462
- * @category Control
463
- */
464
- async menu(): Promise<void> {
465
- await this._pressKey(NodePyATVInternalKeys.menu, NodePyATVExecutableType.atvscript);
466
- }
467
-
468
- /**
469
- * Send the "next" command
470
- * @category Control
471
- */
472
- async next(): Promise<void> {
473
- await this._pressKey(NodePyATVInternalKeys.next, NodePyATVExecutableType.atvscript);
474
- }
475
-
476
- /**
477
- * Send the "pause" command
478
- * @category Control
479
- */
480
- async pause(): Promise<void> {
481
- await this._pressKey(NodePyATVInternalKeys.pause, NodePyATVExecutableType.atvscript);
482
- }
483
-
484
- /**
485
- * Send the "play" command
486
- * @category Control
487
- */
488
- async play(): Promise<void> {
489
- await this._pressKey(NodePyATVInternalKeys.play, NodePyATVExecutableType.atvscript);
490
- }
491
-
492
- /**
493
- * Send the "playPause" command
494
- * @category Control
495
- */
496
- async playPause(): Promise<void> {
497
- await this._pressKey(NodePyATVInternalKeys.playPause, NodePyATVExecutableType.atvscript);
498
- }
499
-
500
- /**
501
- * Send the "previous" command
502
- * @category Control
503
- */
504
- async previous(): Promise<void> {
505
- await this._pressKey(NodePyATVInternalKeys.previous, NodePyATVExecutableType.atvscript);
506
- }
507
-
508
- /**
509
- * Send the "right" command
510
- * @category Control
511
- */
512
- async right(): Promise<void> {
513
- await this._pressKey(NodePyATVInternalKeys.right, NodePyATVExecutableType.atvscript);
514
- }
515
-
516
- /**
517
- * Send the "select" command
518
- * @category Control
519
- */
520
- async select(): Promise<void> {
521
- await this._pressKey(NodePyATVInternalKeys.select, NodePyATVExecutableType.atvscript);
522
- }
523
-
524
- /**
525
- * Send the "skipBackward" command
526
- * @category Control
527
- */
528
- async skipBackward(): Promise<void> {
529
- await this._pressKey(NodePyATVInternalKeys.skipBackward, NodePyATVExecutableType.atvscript);
530
- }
531
-
532
- /**
533
- * Send the "skipForward" command
534
- * @category Control
535
- */
536
- async skipForward(): Promise<void> {
537
- await this._pressKey(NodePyATVInternalKeys.skipForward, NodePyATVExecutableType.atvscript);
538
- }
539
-
540
- /**
541
- * Send the "stop" command
542
- * @category Control
543
- */
544
- async stop(): Promise<void> {
545
- await this._pressKey(NodePyATVInternalKeys.stop, NodePyATVExecutableType.atvscript);
546
- }
547
-
548
- /**
549
- * Send the "suspend" command
550
- * @category Control
551
- * @deprecated
552
- */
553
- async suspend(): Promise<void> {
554
- await this._pressKey(NodePyATVInternalKeys.suspend, NodePyATVExecutableType.atvscript);
555
- }
556
-
557
- /**
558
- * Send the "topMenu" command
559
- * @category Control
560
- */
561
- async topMenu(): Promise<void> {
562
- await this._pressKey(NodePyATVInternalKeys.topMenu, NodePyATVExecutableType.atvscript);
563
- }
564
-
565
- /**
566
- * Send the "up" command
567
- * @category Control
568
- */
569
- async up(): Promise<void> {
570
- await this._pressKey(NodePyATVInternalKeys.up, NodePyATVExecutableType.atvscript);
571
- }
572
-
573
- /**
574
- * Send the "volumeDown" command
575
- * @category Control
576
- */
577
- async volumeDown(): Promise<void> {
578
- await this._pressKey(NodePyATVInternalKeys.volumeDown, NodePyATVExecutableType.atvscript);
579
- }
580
-
581
- /**
582
- * Send the "volumeUp" command
583
- * @category Control
584
- */
585
- async volumeUp(): Promise<void> {
586
- await this._pressKey(NodePyATVInternalKeys.volumeUp, NodePyATVExecutableType.atvscript);
587
- }
588
-
589
- /**
590
- * Send the "wakeup" command
591
- * @category Control
592
- * @deprecated
593
- */
594
- async wakeup(): Promise<void> {
595
- await this._pressKey(NodePyATVInternalKeys.wakeup, NodePyATVExecutableType.atvscript);
596
- }
597
-
598
- /**
599
- * Send the "turn_off" command
600
- * @category Control
601
- */
602
- async turnOff(): Promise<void> {
603
- await this._pressKey(NodePyATVInternalKeys.turnOff, NodePyATVExecutableType.atvremote);
604
- }
605
-
606
- /**
607
- * Send the "turn_on" command
608
- * @category Control
609
- */
610
- async turnOn(): Promise<void> {
611
- await this._pressKey(NodePyATVInternalKeys.turnOn, NodePyATVExecutableType.atvremote);
612
- }
613
-
614
- /**
615
- * Add an event listener. Will start the event subscription with the
616
- * Apple TV as long as there are listeners for any event registered.
617
- * @param event
618
- * @param listener
619
- * @category Event
620
- */
621
- addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
622
- this.events.addListener(event, listener);
623
- return this;
624
- }
625
-
626
- /**
627
- * Emit an event.
628
- * @param event
629
- * @param payload
630
- * @category Event
631
- */
632
- emit(event: string | symbol, payload: NodePyATVDeviceEvent): boolean {
633
- return this.events.emit(event, payload);
634
- }
635
-
636
- /**
637
- * Get all event names which are currently known.
638
- * @category Event
639
- */
640
- eventNames(): Array<string | symbol> {
641
- return this.events.eventNames();
642
- }
643
-
644
- /**
645
- * Get max number of listeners allowed
646
- * @category Event
647
- */
648
- getMaxListeners(): number {
649
- return this.events.getMaxListeners();
650
- }
651
-
652
- /**
653
- * Get number of listeners for event
654
- * @param event
655
- * @category Event
656
- */
657
- listenerCount(event: string | symbol): number {
658
- return this.events.listenerCount(event);
659
- }
660
-
661
- /**
662
- * Get listeners for event. Will also return
663
- * node-pyatv wrappers (e.g. once)
664
- *
665
- * @param event
666
- * @category Event
667
- */
668
- // eslint-disable-next-line @typescript-eslint/ban-types
669
- listeners(event: string | symbol): Function[] {
670
- return this.events.listeners(event);
671
- }
672
-
673
- /**
674
- * Remove an event listener. Will stop the event subscription with the
675
- * Apple TV if this was the last event listener.
676
- * @param event
677
- * @param listener
678
- * @category Event
679
- */
680
- off(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this {
681
- this.events.off(event, listener);
682
- return this;
683
- }
684
-
685
- /**
686
- * Add an event listener. Will start the event subscription with the
687
- * Apple TV as long as there are listeners for any event registered.
688
- * @param event
689
- * @param listener
690
- * @category Event
691
- */
692
- on(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this {
693
- this.events.on(event, listener);
694
- return this;
695
- }
696
-
697
- /**
698
- * Add an event listener. Will start the event subscription with the
699
- * Apple TV as long as there are listeners for any event registered.
700
- * Removes the listener automatically after the first occurrence.
701
- * @param event
702
- * @param listener
703
- * @category Event
704
- */
705
- once(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this {
706
- this.events.once(event, listener);
707
- return this;
708
- }
709
-
710
- /**
711
- * @param event
712
- * @param listener
713
- * @category Event
714
- */
715
- prependListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this {
716
- this.events.prependListener(event, listener);
717
- return this;
718
- }
719
-
720
- /**
721
- * @param event
722
- * @param listener
723
- * @category Event
724
- */
725
- prependOnceListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this {
726
- this.events.prependOnceListener(event, listener);
727
- return this;
728
- }
729
-
730
- /**
731
- * @param event
732
- * @category Event
733
- */
734
- // eslint-disable-next-line @typescript-eslint/ban-types
735
- rawListeners(event: string | symbol): Function[] {
736
- return this.events.rawListeners(event);
737
- }
738
-
739
- /**
740
- * Removes all listeners, either for the given event or
741
- * for every event. Will stop the event subscription with
742
- * the Apple TV if this was the last event listener.
743
- *
744
- * @param event
745
- * @category Event
746
- */
747
- removeAllListeners(event?: string | symbol): this {
748
- this.events.removeAllListeners(event);
749
- return this;
750
- }
751
-
752
- /**
753
- * Remove an event listener. Will stop the event subscription with the
754
- * Apple TV if this was the last event listener.
755
- * @param event
756
- * @param listener
757
- * @category Event
758
- */
759
- removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
760
- this.events.removeListener(event, listener);
761
- return this;
762
- }
763
-
764
- /**
765
- * @param n
766
- * @category Event
767
- */
768
- setMaxListeners(n: number): this {
769
- this.events.setMaxListeners(n);
770
- return this;
771
- }
772
- }