@sebbo2002/node-pyatv 8.0.0-develop.2 → 8.0.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.
@@ -36,218 +36,6 @@ declare class FakeChildProcessController {
36
36
  end(content?: string | Record<string, unknown>): this;
37
37
  }
38
38
 
39
- declare enum NodePyATVExecutableType {
40
- atvremote = "atvremote",
41
- atvscript = "atvscript"
42
- }
43
- declare enum NodePyATVProtocol {
44
- dmap = "dmap",
45
- mrp = "mrp",
46
- airplay = "airplay",
47
- mdns = "mdns"
48
- }
49
- declare enum NodePyATVMediaType {
50
- music = "music",
51
- tv = "tv",
52
- video = "video",
53
- unknown = "unknown"
54
- }
55
- declare enum NodePyATVDeviceState {
56
- idle = "idle",
57
- loading = "loading",
58
- paused = "paused",
59
- playing = "playing",
60
- seeking = "seeking",
61
- stopped = "stopped"
62
- }
63
- declare enum NodePyATVRepeatState {
64
- all = "all",
65
- track = "track",
66
- off = "off"
67
- }
68
- declare enum NodePyATVShuffleState {
69
- albums = "albums",
70
- songs = "songs",
71
- off = "off"
72
- }
73
- declare enum NodePyATVPowerState {
74
- on = "on",
75
- off = "off"
76
- }
77
- declare enum NodePyATVFocusState {
78
- focued = "focused",
79
- unfocused = "unfocused"
80
- }
81
- declare enum NodePyATVKeys {
82
- down = "down",
83
- home = "home",
84
- homeHold = "homeHold",
85
- left = "left",
86
- menu = "menu",
87
- next = "next",
88
- pause = "pause",
89
- play = "play",
90
- playPause = "playPause",
91
- previous = "previous",
92
- right = "right",
93
- select = "select",
94
- skipBackward = "skipBackward",
95
- skipForward = "skipForward",
96
- stop = "stop",
97
- suspend = "suspend",
98
- topMenu = "topMenu",
99
- up = "up",
100
- volumeDown = "volumeDown",
101
- volumeUp = "volumeUp",
102
- wakeup = "wakeup",
103
- turnOff = "turnOff",
104
- turnOn = "turnOn"
105
- }
106
- declare enum NodePyATVListenerState {
107
- stopped = 0,
108
- starting = 1,
109
- started = 2,
110
- stopping = 3
111
- }
112
- type NodePyATVStateIndex = keyof NodePyATVState;
113
- type NodePyATVEventValueType = (string | number | NodePyATVMediaType | NodePyATVDeviceState | NodePyATVShuffleState | NodePyATVRepeatState);
114
- interface NodePyATVInstanceOptions {
115
- atvremotePath?: string;
116
- atvscriptPath?: string;
117
- debug?: true | ((msg: string) => void);
118
- noColors?: true;
119
- spawn?: (command: string, args: Array<string>, options: SpawnOptions) => (ChildProcess | FakeChildProcess);
120
- }
121
- interface NodePyATVVersionResponse {
122
- pyatv: string | null;
123
- module: string | null;
124
- }
125
- interface NodePyATVFindOptions {
126
- host?: string;
127
- hosts?: string[];
128
- id?: string;
129
- protocol?: NodePyATVProtocol;
130
- dmapCredentials?: string;
131
- mrpCredentials?: string;
132
- airplayCredentials?: string;
133
- companionCredentials?: string;
134
- raopCredentials?: string;
135
- }
136
- interface NodePyATVFindAndInstanceOptions extends NodePyATVInstanceOptions, NodePyATVFindOptions {
137
- }
138
- interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
139
- host: string;
140
- name: string;
141
- mac?: string;
142
- model?: string;
143
- modelName?: string;
144
- os?: string;
145
- version?: string;
146
- services?: NodePyATVService[];
147
- allIDs?: string[];
148
- }
149
- interface NodePyATVGetStateOptions {
150
- maxAge?: number;
151
- }
152
- interface NodePyATVService {
153
- protocol: NodePyATVProtocol;
154
- port: number;
155
- }
156
- interface NodePyATVState {
157
- dateTime: Date | null;
158
- hash: string | null;
159
- mediaType: NodePyATVMediaType | null;
160
- deviceState: NodePyATVDeviceState | null;
161
- title: string | null;
162
- artist: string | null;
163
- album: string | null;
164
- genre: string | null;
165
- totalTime: number | null;
166
- position: number | null;
167
- shuffle: NodePyATVShuffleState | null;
168
- repeat: NodePyATVRepeatState | null;
169
- app: string | null;
170
- appId: string | null;
171
- powerState: NodePyATVPowerState | null;
172
- volume: number | null;
173
- focusState: NodePyATVFocusState | null;
174
- }
175
- interface NodePyATVApp {
176
- id: string;
177
- name: string;
178
- launch: () => Promise<void>;
179
- }
180
-
181
- declare class NodePyATVDeviceEvent {
182
- protected readonly values: {
183
- key: NodePyATVStateIndex;
184
- old: NodePyATVEventValueType;
185
- new: NodePyATVEventValueType;
186
- device: NodePyATVDevice;
187
- };
188
- /**
189
- *
190
- * @param values
191
- * @internal
192
- */
193
- constructor(values: {
194
- key: NodePyATVStateIndex;
195
- old: NodePyATVEventValueType;
196
- new: NodePyATVEventValueType;
197
- device: NodePyATVDevice;
198
- });
199
- /**
200
- * References the attribute name which was changed. So if the
201
- * title has been updated, this would be `title`.
202
- */
203
- get key(): NodePyATVStateIndex;
204
- /**
205
- * Holds the old value which was there
206
- * before the value was changed.
207
- */
208
- get oldValue(): NodePyATVEventValueType;
209
- /**
210
- * @alias value
211
- */
212
- get newValue(): NodePyATVEventValueType;
213
- /**
214
- * New, current value for `key`
215
- */
216
- get value(): NodePyATVEventValueType;
217
- /**
218
- * References the device instance this
219
- * event originates from
220
- */
221
- get device(): NodePyATVDevice;
222
- }
223
-
224
- /**
225
- * @internal
226
- */
227
- declare class NodePyATVDeviceEvents extends EventEmitter {
228
- private readonly options;
229
- private readonly state;
230
- private readonly device;
231
- private pyatv;
232
- private timeout;
233
- private listenerState;
234
- constructor(state: NodePyATVState, device: NodePyATVDevice, options: NodePyATVDeviceOptions);
235
- applyStateAndEmitEvents(newState: NodePyATVState): void;
236
- private parsePushUpdate;
237
- private applyPushUpdate;
238
- private checkListener;
239
- private startListening;
240
- protected stopListening(reqId: string): Promise<void>;
241
- addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
242
- on(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
243
- once(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
244
- prependListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
245
- off(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
246
- removeAllListeners(event?: string | symbol): this;
247
- removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
248
- listenerCount(event?: string | symbol): number;
249
- }
250
-
251
39
  /**
252
40
  * Represents an Apple TV. Use [[getState]] to query the current state (e.g. media
253
41
  * type and title). You can also use the attribute methods (e.g. [[getTitle]] to get
@@ -282,6 +70,7 @@ declare class NodePyATVDevice implements EventEmitter {
282
70
  get id(): string | undefined;
283
71
  /**
284
72
  * Get all IDs of the Apple TV.
73
+ * Requires pyatv >= 0.14.5.
285
74
  */
286
75
  get allIDs(): string[] | undefined;
287
76
  /**
@@ -290,6 +79,7 @@ declare class NodePyATVDevice implements EventEmitter {
290
79
  get protocol(): NodePyATVProtocol | undefined;
291
80
  /**
292
81
  * Get the MAC address of the Apple TV.
82
+ * Requires pyatv >= 0.14.5.
293
83
  */
294
84
  get mac(): string | undefined;
295
85
  /**
@@ -477,7 +267,8 @@ declare class NodePyATVDevice implements EventEmitter {
477
267
  * see https://pyatv.dev/documentation/atvremote/#apps for more details.
478
268
  */
479
269
  listApps(): Promise<NodePyATVApp[]>;
480
- private _pressKey;
270
+ private _pressKeyWithScript;
271
+ private _pressKeyWithRemote;
481
272
  /**
482
273
  * Send a key press to the Apple TV
483
274
  *
@@ -723,6 +514,230 @@ declare class NodePyATVDevice implements EventEmitter {
723
514
  setMaxListeners(n: number): this;
724
515
  }
725
516
 
517
+ declare enum NodePyATVExecutableType {
518
+ atvremote = "atvremote",
519
+ atvscript = "atvscript"
520
+ }
521
+ declare enum NodePyATVProtocol {
522
+ dmap = "dmap",
523
+ mrp = "mrp",
524
+ airplay = "airplay",
525
+ mdns = "mdns"
526
+ }
527
+ declare enum NodePyATVMediaType {
528
+ music = "music",
529
+ tv = "tv",
530
+ video = "video",
531
+ unknown = "unknown"
532
+ }
533
+ declare enum NodePyATVDeviceState {
534
+ idle = "idle",
535
+ loading = "loading",
536
+ paused = "paused",
537
+ playing = "playing",
538
+ seeking = "seeking",
539
+ stopped = "stopped"
540
+ }
541
+ declare enum NodePyATVRepeatState {
542
+ all = "all",
543
+ track = "track",
544
+ off = "off"
545
+ }
546
+ declare enum NodePyATVShuffleState {
547
+ albums = "albums",
548
+ songs = "songs",
549
+ off = "off"
550
+ }
551
+ declare enum NodePyATVPowerState {
552
+ on = "on",
553
+ off = "off"
554
+ }
555
+ declare enum NodePyATVFocusState {
556
+ focued = "focused",
557
+ focused = "focused",
558
+ unfocused = "unfocused"
559
+ }
560
+ declare enum NodePyATVKeys {
561
+ down = "down",
562
+ home = "home",
563
+ homeHold = "homeHold",
564
+ left = "left",
565
+ menu = "menu",
566
+ next = "next",
567
+ pause = "pause",
568
+ play = "play",
569
+ playPause = "playPause",
570
+ previous = "previous",
571
+ right = "right",
572
+ select = "select",
573
+ skipBackward = "skipBackward",
574
+ skipForward = "skipForward",
575
+ stop = "stop",
576
+ suspend = "suspend",
577
+ topMenu = "topMenu",
578
+ up = "up",
579
+ volumeDown = "volumeDown",
580
+ volumeUp = "volumeUp",
581
+ wakeup = "wakeup",
582
+ turnOff = "turnOff",
583
+ turnOn = "turnOn"
584
+ }
585
+ declare enum NodePyATVListenerState {
586
+ stopped = 0,
587
+ starting = 1,
588
+ started = 2,
589
+ stopping = 3
590
+ }
591
+ type NodePyATVStateIndex = keyof NodePyATVState;
592
+ type NodePyATVEventValueType = (string | number | NodePyATVMediaType | NodePyATVDeviceState | NodePyATVShuffleState | NodePyATVRepeatState);
593
+ interface NodePyATVInstanceOptions {
594
+ atvremotePath?: string;
595
+ atvscriptPath?: string;
596
+ debug?: true | ((msg: string) => void);
597
+ noColors?: true;
598
+ spawn?: (command: string, args: Array<string>, options: SpawnOptions) => (ChildProcess | FakeChildProcess);
599
+ }
600
+ interface NodePyATVRequestOptions extends NodePyATVInstanceOptions {
601
+ allowMultipleResponses?: boolean;
602
+ }
603
+ interface NodePyATVVersionResponse {
604
+ pyatv: string | null;
605
+ module: string | null;
606
+ }
607
+ interface NodePyATVFindOptions {
608
+ host?: string;
609
+ hosts?: string[];
610
+ id?: string;
611
+ protocol?: NodePyATVProtocol;
612
+ dmapCredentials?: string;
613
+ mrpCredentials?: string;
614
+ airplayCredentials?: string;
615
+ companionCredentials?: string;
616
+ raopCredentials?: string;
617
+ }
618
+ interface NodePyATVFindAndInstanceOptions extends NodePyATVInstanceOptions, NodePyATVFindOptions {
619
+ }
620
+ interface NodePyATVFindResponseObject {
621
+ devices: NodePyATVDevice[];
622
+ errors: Record<string, unknown>[];
623
+ }
624
+ interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
625
+ host: string;
626
+ name: string;
627
+ mac?: string;
628
+ model?: string;
629
+ modelName?: string;
630
+ os?: string;
631
+ version?: string;
632
+ services?: NodePyATVService[];
633
+ allIDs?: string[];
634
+ }
635
+ interface NodePyATVGetStateOptions {
636
+ maxAge?: number;
637
+ }
638
+ interface NodePyATVService {
639
+ protocol: NodePyATVProtocol;
640
+ port: number;
641
+ }
642
+ interface NodePyATVState {
643
+ dateTime: Date | null;
644
+ hash: string | null;
645
+ mediaType: NodePyATVMediaType | null;
646
+ deviceState: NodePyATVDeviceState | null;
647
+ title: string | null;
648
+ artist: string | null;
649
+ album: string | null;
650
+ genre: string | null;
651
+ totalTime: number | null;
652
+ position: number | null;
653
+ shuffle: NodePyATVShuffleState | null;
654
+ repeat: NodePyATVRepeatState | null;
655
+ app: string | null;
656
+ appId: string | null;
657
+ powerState: NodePyATVPowerState | null;
658
+ volume: number | null;
659
+ focusState: NodePyATVFocusState | null;
660
+ outputDevices: Array<{
661
+ name: string;
662
+ identifier: string;
663
+ }> | null;
664
+ }
665
+ interface NodePyATVApp {
666
+ id: string;
667
+ name: string;
668
+ launch: () => Promise<void>;
669
+ }
670
+
671
+ declare class NodePyATVDeviceEvent {
672
+ protected readonly values: {
673
+ key: NodePyATVStateIndex;
674
+ old: NodePyATVEventValueType;
675
+ new: NodePyATVEventValueType;
676
+ device: NodePyATVDevice;
677
+ };
678
+ /**
679
+ *
680
+ * @param values
681
+ * @internal
682
+ */
683
+ constructor(values: {
684
+ key: NodePyATVStateIndex;
685
+ old: NodePyATVEventValueType;
686
+ new: NodePyATVEventValueType;
687
+ device: NodePyATVDevice;
688
+ });
689
+ /**
690
+ * References the attribute name which was changed. So if the
691
+ * title has been updated, this would be `title`.
692
+ */
693
+ get key(): NodePyATVStateIndex;
694
+ /**
695
+ * Holds the old value which was there
696
+ * before the value was changed.
697
+ */
698
+ get oldValue(): NodePyATVEventValueType;
699
+ /**
700
+ * @alias value
701
+ */
702
+ get newValue(): NodePyATVEventValueType;
703
+ /**
704
+ * New, current value for `key`
705
+ */
706
+ get value(): NodePyATVEventValueType;
707
+ /**
708
+ * References the device instance this
709
+ * event originates from
710
+ */
711
+ get device(): NodePyATVDevice;
712
+ }
713
+
714
+ /**
715
+ * @internal
716
+ */
717
+ declare class NodePyATVDeviceEvents extends EventEmitter {
718
+ private readonly options;
719
+ private readonly state;
720
+ private readonly device;
721
+ private pyatv;
722
+ private timeout;
723
+ private listenerState;
724
+ constructor(state: NodePyATVState, device: NodePyATVDevice, options: NodePyATVDeviceOptions);
725
+ applyStateAndEmitEvents(newState: NodePyATVState): void;
726
+ private parsePushUpdate;
727
+ private applyPushUpdate;
728
+ private checkListener;
729
+ private startListening;
730
+ protected stopListening(reqId: string): Promise<void>;
731
+ addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
732
+ on(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
733
+ once(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
734
+ prependListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
735
+ off(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
736
+ removeAllListeners(event?: string | symbol): this;
737
+ removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
738
+ listenerCount(event?: string | symbol): number;
739
+ }
740
+
726
741
  /**
727
742
  * Default class exported by `@sebbo2002/node-pyatv`. Use [[find]] to scan for devices in your local network. Use
728
743
  * [[device]] to connect to a known device by passing (at least) it's name and IP.
@@ -758,9 +773,19 @@ declare class NodePyATVInstance {
758
773
  * console.log(devices);
759
774
  * ```
760
775
  *
776
+ * Normally `node-pyatv` ignores error messages if at least one device has been found, but if you
777
+ * always want to receive the error messages, you can set the second argument to `true`:
778
+ *
779
+ * ```typescript
780
+ * const result = await pyatv.find({}, true);
781
+ * console.log(result.devices);
782
+ * console.log(result.errors);
783
+ * ```
784
+ *
761
785
  * @param options
762
786
  */
763
787
  static find(options?: NodePyATVFindAndInstanceOptions): Promise<NodePyATVDevice[]>;
788
+ static find(options: NodePyATVFindAndInstanceOptions, returnDevicesAndErrors: true): Promise<NodePyATVFindResponseObject>;
764
789
  /**
765
790
  * Create a [[NodePyATVDevice]] to query the state and control it.
766
791
  * At least `host` and `name` are required.
@@ -819,4 +844,4 @@ declare class NodePyATVInstance {
819
844
  device(options: NodePyATVDeviceOptions): NodePyATVDevice;
820
845
  }
821
846
 
822
- export { NodePyATVDevice, NodePyATVDeviceEvent, NodePyATVDeviceEvents, type NodePyATVDeviceOptions, NodePyATVDeviceState, type NodePyATVEventValueType, NodePyATVExecutableType, type NodePyATVFindAndInstanceOptions, type NodePyATVFindOptions, type NodePyATVGetStateOptions, NodePyATVInstance, type NodePyATVInstanceOptions, NodePyATVKeys, NodePyATVListenerState, NodePyATVMediaType, NodePyATVPowerState, NodePyATVProtocol, NodePyATVRepeatState, type NodePyATVService, NodePyATVShuffleState, type NodePyATVState, type NodePyATVVersionResponse, NodePyATVInstance as default };
847
+ export { NodePyATVDevice, NodePyATVDeviceEvent, NodePyATVDeviceEvents, type NodePyATVDeviceOptions, NodePyATVDeviceState, type NodePyATVEventValueType, NodePyATVExecutableType, type NodePyATVFindAndInstanceOptions, type NodePyATVFindOptions, type NodePyATVFindResponseObject, type NodePyATVGetStateOptions, NodePyATVInstance, type NodePyATVInstanceOptions, NodePyATVKeys, NodePyATVListenerState, NodePyATVMediaType, NodePyATVPowerState, NodePyATVProtocol, NodePyATVRepeatState, type NodePyATVRequestOptions, type NodePyATVService, NodePyATVShuffleState, type NodePyATVState, type NodePyATVVersionResponse, NodePyATVInstance as default };
package/dist/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m}from"../chunk-D57T7NS2.js";export{l as NodePyATVDevice,j as NodePyATVDeviceEvent,k as NodePyATVDeviceEvents,d as NodePyATVDeviceState,a as NodePyATVExecutableType,m as NodePyATVInstance,h as NodePyATVKeys,i as NodePyATVListenerState,c as NodePyATVMediaType,g as NodePyATVPowerState,b as NodePyATVProtocol,e as NodePyATVRepeatState,f as NodePyATVShuffleState,m as default};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"../chunk-5OFZ5MPK.js";export{l as NodePyATVDevice,j as NodePyATVDeviceEvent,k as NodePyATVDeviceEvents,d as NodePyATVDeviceState,a as NodePyATVExecutableType,m as NodePyATVInstance,h as NodePyATVKeys,i as NodePyATVListenerState,c as NodePyATVMediaType,g as NodePyATVPowerState,b as NodePyATVProtocol,e as NodePyATVRepeatState,f as NodePyATVShuffleState,m as default};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -5,37 +5,39 @@
5
5
  "url": "http://github.com/sebbo2002/node-pyatv/issues"
6
6
  },
7
7
  "dependencies": {
8
- "semver": "^7.5.4"
8
+ "semver": "^7.6.3"
9
9
  },
10
10
  "description": "A lightweight wrapper around pyatv…",
11
11
  "devDependencies": {
12
- "@qiwi/semantic-release-gh-pages-plugin": "^5.2.10",
12
+ "@eslint/js": "^9.9.0",
13
+ "@qiwi/semantic-release-gh-pages-plugin": "^5.2.12",
13
14
  "@semantic-release/changelog": "^6.0.3",
14
15
  "@semantic-release/exec": "^6.0.3",
15
16
  "@semantic-release/git": "^10.0.1",
16
- "@semantic-release/npm": "^11.0.2",
17
- "@types/mocha": "^10.0.6",
18
- "@types/node": "^20.10.2",
19
- "@types/semver": "^7.5.6",
20
- "@typescript-eslint/eslint-plugin": "^6.13.2",
21
- "@typescript-eslint/parser": "^6.13.2",
22
- "c8": "^8.0.1",
23
- "eslint": "^8.55.0",
24
- "eslint-plugin-jsonc": "^2.10.0",
17
+ "@semantic-release/npm": "^12.0.1",
18
+ "@types/eslint__js": "^8.42.3",
19
+ "@types/express": "^4.17.21",
20
+ "@types/mocha": "^10.0.7",
21
+ "@types/node": "^22.5.0",
22
+ "@types/semver": "^7.5.8",
23
+ "c8": "^10.1.2",
24
+ "eslint": "^9.9.0",
25
+ "eslint-plugin-jsonc": "^2.16.0",
25
26
  "esm": "^3.2.25",
26
27
  "license-checker": "^25.0.1",
27
- "mocha": "^10.2.0",
28
+ "mocha": "^10.7.3",
28
29
  "mochawesome": "^7.1.3",
29
- "semantic-release": "^22.0.12",
30
+ "semantic-release": "^24.1.0",
30
31
  "semantic-release-license": "^1.0.3",
31
32
  "source-map-support": "^0.5.21",
32
- "ts-node": "^10.9.2",
33
- "tsup": "^8.0.1",
34
- "typedoc": "^0.25.4",
35
- "typescript": "^5.3.3"
33
+ "tsup": "^8.2.4",
34
+ "tsx": "^4.16.2",
35
+ "typedoc": "^0.26.6",
36
+ "typescript": "^5.5.3",
37
+ "typescript-eslint": "^8.2.0"
36
38
  },
37
39
  "engines": {
38
- "node": ">=18.0.0"
40
+ "node": "18 || 20 || >=22.0.0"
39
41
  },
40
42
  "exports": {
41
43
  "import": "./dist/lib/index.js",
@@ -60,13 +62,13 @@
60
62
  "build-all": "./.github/workflows/build.sh",
61
63
  "check": "./check.sh",
62
64
  "coverage": "c8 mocha",
63
- "develop": "TS_NODE_TRANSPILE_ONLY=true node --no-warnings --enable-source-maps --loader ts-node/esm src/bin/start.ts",
65
+ "develop": "tsx src/bin/start.ts",
64
66
  "example": "node ./dist/examples/push.js",
65
67
  "license-check": "license-checker --production --summary",
66
- "lint": "eslint . --ext .ts",
68
+ "lint": "eslint .",
67
69
  "postinstall": "./check.sh",
68
70
  "test": "mocha"
69
71
  },
70
72
  "type": "module",
71
- "version": "8.0.0-develop.2"
73
+ "version": "8.0.0"
72
74
  }
@@ -1,7 +0,0 @@
1
- var o=(s,e,t)=>new Promise((i,n)=>{var a=c=>{try{p(t.next(c))}catch(u){n(u)}},r=c=>{try{p(t.throw(c))}catch(u){n(u)}},p=c=>c.done?i(c.value):Promise.resolve(c.value).then(a,r);p((t=t.apply(s,e)).next())});var N=(t=>(t.atvremote="atvremote",t.atvscript="atvscript",t))(N||{}),R=(n=>(n.dmap="dmap",n.mrp="mrp",n.airplay="airplay",n.mdns="mdns",n))(R||{}),k=(n=>(n.music="music",n.tv="tv",n.video="video",n.unknown="unknown",n))(k||{}),x=(r=>(r.idle="idle",r.loading="loading",r.paused="paused",r.playing="playing",r.seeking="seeking",r.stopped="stopped",r))(x||{}),E=(i=>(i.all="all",i.track="track",i.off="off",i))(E||{}),_=(i=>(i.albums="albums",i.songs="songs",i.off="off",i))(_||{}),D=(t=>(t.on="on",t.off="off",t))(D||{}),L=(t=>(t.focued="focused",t.unfocused="unfocused",t))(L||{}),U=(d=>(d.down="down",d.home="home",d.homeHold="homeHold",d.left="left",d.menu="menu",d.next="next",d.pause="pause",d.play="play",d.playPause="playPause",d.previous="previous",d.right="right",d.select="select",d.skipBackward="skipBackward",d.skipForward="skipForward",d.stop="stop",d.suspend="suspend",d.topMenu="topMenu",d.up="up",d.volumeDown="volumeDown",d.volumeUp="volumeUp",d.wakeup="wakeup",d.turnOff="turnOff",d.turnOn="turnOn",d))(U||{}),j=(d=>(d.down="down",d.home="home",d.homeHold="home_hold",d.left="left",d.menu="menu",d.next="next",d.pause="pause",d.play="play",d.playPause="play_pause",d.previous="previous",d.right="right",d.select="select",d.skipBackward="skip_backward",d.skipForward="skip_forward",d.stop="stop",d.suspend="suspend",d.topMenu="top_menu",d.up="up",d.volumeDown="volume_down",d.volumeUp="volume_up",d.wakeup="wakeup",d.turnOff="turn_off",d.turnOn="turn_on",d))(j||{}),F=(n=>(n[n.stopped=0]="stopped",n[n.starting=1]="starting",n[n.started=2]="started",n[n.stopping=3]="stopping",n))(F||{});var A=class{constructor(e){this.values=Object.assign({},e,{key:e.key})}get key(){return this.values.key}get oldValue(){return this.values.old}get newValue(){return this.values.new}get value(){return this.values.new}get device(){return this.values.device}};import{EventEmitter as B}from"events";import{spawn as J}from"child_process";var $=[];function y(){let s="?";for(let e=0;e<1e3;e+=1)if(s=Math.round(Math.random()*(e+6)*36).toString(36).toUpperCase(),!$.includes(s)){$.push(s);break}return s}function h(s){s&&$.includes(s)&&$.splice($.indexOf(s),1)}function l(s,e,t){if(t.debug){let i=typeof t.debug=="function"?t.debug:console.log,n=!process.env.NO_COLOR&&!t.noColors,a=[n?"\x1B[0m":"",n?"\x1B[90m":"","[node-pyatv][",n?"\x1B[37m":"",s,n?"\x1B[90m":"","] ",n?"\x1B[0m":"",e];i.apply(null,[a.join("")])}}function M(s,e){return s==="atvremote"&&typeof e.atvremotePath=="string"?e.atvremotePath:s==="atvscript"&&typeof e.atvscriptPath=="string"?e.atvscriptPath:s}function I(s,e,t,i){let n=M(e,i),a=typeof i.spawn=="function"?i.spawn:J;l(s,`${n} ${t.join(" ")}`,i);let r=a(n,t,{env:process.env}),p=v=>l(s,`stdout: ${String(v).trim()}`,i),c=v=>l(s,`stderr: ${String(v).trim()}`,i),u=v=>l(s,`error: ${String(v).trim()}`,i),m=v=>{l(s,`${n} exited with code: ${v}`,i),r.stdout&&r.stdout.off("data",p),r.stderr&&r.stderr.off("data",c),r.off("error",u),r.off("close",m)};return r.stdout&&r.stdout.on("data",p),r.stderr&&r.stderr.on("data",c),r.on("error",u),r.on("close",m),r}function T(s,e,t,i){return o(this,null,function*(){let n={stdout:"",stderr:"",code:0};if(yield new Promise((a,r)=>{let p=I(s,e,t,i),c=f=>n.stdout+=String(f).trim(),u=f=>n.stderr+=String(f).trim(),m=f=>r(f instanceof Error?f:new Error(String(f))),v=f=>{n.code=f,p.stdout&&p.stdout.off("data",c),p.stderr&&p.stderr.off("data",u),p.off("error",m),p.off("close",v),a(void 0)};p.stdout&&p.stdout.on("data",c),p.stderr&&p.stderr.on("data",u),p.on("error",m),p.on("close",v)}),n.stderr.length>0){let a=`Unable to execute request ${s}: ${n.stderr}`;throw l(s,a,i),new Error(a)}if(e==="atvscript")try{return JSON.parse(n.stdout)}catch(a){let r=`Unable to parse result ${s} json: ${a}`;throw l(s,r,i),new Error(r)}return n.stdout})}function g(s={}){let e=[];return s.hosts?e.push("-s",s.hosts.join(",")):s.host&&e.push("-s",s.host),s.id&&e.push("-i",s.id),s.protocol&&e.push("--protocol",s.protocol),s.dmapCredentials&&e.push("--dmap-credentials",s.dmapCredentials),s.mrpCredentials&&e.push("--mrp-credentials",s.mrpCredentials),s.airplayCredentials&&e.push("--airplay-credentials",s.airplayCredentials),s.companionCredentials&&e.push("--companion-credentials",s.companionCredentials),s.raopCredentials&&e.push("--raop-credentials",s.raopCredentials),e}function P(s,e,t,i,n){if(typeof s[t]=="string"){e[i]=s[t];return}n(`No ${i} value found in input (${JSON.stringify(s)})`)}function V(s,e,t){let i=a=>l(e,a,t),n={dateTime:null,hash:null,mediaType:null,deviceState:null,title:null,artist:null,album:null,genre:null,totalTime:null,position:null,shuffle:null,repeat:null,app:null,appId:null,powerState:null,volume:null,focusState:null};if(!s||typeof s!="object")return n;if(s.exception){let a="Got pyatv Error: "+s.exception;throw s.stacktrace&&(a+=`
2
-
3
- pyatv Stacktrace:
4
- `+s.stacktrace),new Error(a)}if(typeof s.datetime=="string"){let a=new Date(s.datetime);isNaN(a.getTime())?i(`Invalid datetime value ${s.datetime}, ignore attribute`):n.dateTime=a}else i(`No datetime value found in input (${JSON.stringify(s)})`);return P(s,n,"hash","hash",i),typeof s.media_type=="string"?Object.keys(k).map(r=>String(r)).includes(s.media_type)?n.mediaType=k[s.media_type]:i(`Unsupported mediaType value ${s.media_type}, ignore attribute`):i(`No mediaType value found in input (${JSON.stringify(s)})`),typeof s.device_state=="string"?Object.keys(x).map(r=>String(r)).includes(s.device_state)?n.deviceState=x[s.device_state]:i(`Unsupported deviceState value ${s.device_state}, ignore attribute`):i(`No deviceState value found in input (${JSON.stringify(s)})`),P(s,n,"title","title",i),P(s,n,"artist","artist",i),P(s,n,"album","album",i),P(s,n,"genre","genre",i),typeof s.total_time=="number"?n.totalTime=s.total_time:i(`No totalTime value found in input (${JSON.stringify(s)})`),typeof s.position=="number"?n.position=s.position:i(`No position value found in input (${JSON.stringify(s)})`),typeof s.shuffle=="string"?Object.keys(_).map(r=>String(r)).includes(s.shuffle)?n.shuffle=_[s.shuffle]:i(`Unsupported shuffle value ${s.shuffle}, ignore attribute`):i(`No shuffle value found in input (${JSON.stringify(s)})`),typeof s.repeat=="string"?Object.keys(E).map(r=>String(r)).includes(s.repeat)?n.repeat=E[s.repeat]:i(`Unsupported repeat value ${s.repeat}, ignore attribute`):i(`No repeat value found in input (${JSON.stringify(s)})`),P(s,n,"app","app",i),P(s,n,"app_id","appId",i),typeof s.power_state=="string"?Object.keys(D).map(r=>String(r)).includes(s.power_state)?n.powerState=D[s.power_state]:i(`Unsupported powerState value ${s.power_state}, ignore attribute`):i(`No powerState value found in input (${JSON.stringify(s)})`),typeof s.volume=="number"&&(n.volume=s.volume),typeof s.focus_state=="string"?Object.keys(L).map(r=>String(r)).includes(s.focus_state)?n.focusState=L[s.power_state]:i(`Unsupported focusState value ${s.focus_state}, ignore attribute`):i(`No focusState value found in input (${JSON.stringify(s)})`),n}var b=class extends B{constructor(t,i,n){super();this.state=t,this.device=i,this.options=Object.assign({},n),this.listenerState=0}applyStateAndEmitEvents(t){Object.keys(this.state).forEach(i=>{let n=this.state[i],a=t[i];if(n===void 0||a===void 0||n===a)return;let r=new A({key:i,old:n,new:a,device:this.device});this.state[i]=t[i];try{this.emit("update:"+i,r),this.emit("update",r)}catch(p){this.emit("error",p)}})}parsePushUpdate(t,i){let n;try{n=JSON.parse(i)}catch(a){let r=`Unable to parse stdout json: ${a}`;l(t,r,this.options),this.emit("error",new Error(r));return}this.applyPushUpdate(n,t),this.listenerState===1&&(this.listenerState=2,this.checkListener())}applyPushUpdate(t,i){try{let n=V(t,i,this.options);this.applyStateAndEmitEvents(n)}catch(n){this.emit("error",n)}}checkListener(){if(this.listenerState===0&&this.listenerCount()===0&&this.timeout)clearTimeout(this.timeout),this.timeout=void 0;else if(this.listenerState===0&&this.listenerCount()>0){let t=y();l(t,`Start listeing to events from device ${this.options.name}`,this.options),this.startListening(t),h(t)}else if([1,2].includes(this.listenerState)&&this.listenerCount()===0){let t=y();l(t,`Stop listening to events from device ${this.options.name}`,this.options),this.stopListening(t).catch(i=>l(t,`Unable to stop listeing: ${i}`,this.options)).finally(()=>h(t))}}startListening(t){if(this.listenerState!==0)return;this.listenerState=1;let i=new Date().getTime(),n=g(this.options);if(this.pyatv=I(t,"atvscript",[...n,"push_updates"],this.options),!this.pyatv)throw new Error("Unable to start listener: Unable to start atvscript");let a=u=>{l(t,`Got error from child process: ${u}`,this.options),this.emit("error",u)},r=u=>{let m=new Error(`Got stderr output from pyatv: ${u}`);l(t,u.toString(),this.options),this.emit("error",m)},p=u=>{String(u).split(`
5
- `).map(m=>m.trim()).filter(Boolean).forEach(m=>{l(t,`> ${m}`,this.options),this.parsePushUpdate(t,m)})},c=u=>{this.pyatv!==void 0&&(this.listenerState=0,l(t,`Listening with atvscript exited with code ${u}`,this.options),this.timeout!==void 0&&(clearTimeout(this.timeout),this.timeout=void 0),this.pyatv.stdout&&this.pyatv.stdout.off("data",p),this.pyatv.stderr&&this.pyatv.stderr.off("data",r),this.pyatv.off("error",a),this.pyatv.off("close",c),this.listenerCount()>0&&new Date().getTime()-i<3e4?(l(t,`Wait 15s and restart listeing to events from device ${this.options.name}`,this.options),this.timeout=setTimeout(()=>{this.checkListener()},15e3)):this.listenerCount()>0&&(l(t,`Restart listeing to events from device ${this.options.name}`,this.options),this.checkListener()),h(t))};this.pyatv.on("error",a),this.pyatv.on("close",c),this.pyatv.stdout&&this.pyatv.stdout.on("data",p),this.pyatv.stderr&&this.pyatv.stderr.on("data",r)}stopListening(t){return o(this,null,function*(){if(!(this.listenerState!==1&&this.listenerState!==2)){if(this.listenerState=3,this.pyatv===void 0)throw new Error("Unable to stop listening due to internal error: state is stopping, but there's no child process. This should never happen, please report this.");this.pyatv.stdin&&(l(t,"Pressing enter to close atvscript\u2026",this.options),this.pyatv.stdin.write(`
6
- `),yield new Promise(i=>this.timeout=setTimeout(i,250))),this.listenerState===3&&this.pyatv&&this.pyatv.kill(),this.listenerState=0}})}addListener(t,i){return super.addListener(t,i),this.checkListener(),this}on(t,i){return super.on(t,i),this.checkListener(),this}once(t,i){return super.once(t,n=>{i(n),setTimeout(()=>this.checkListener(),0)}),this.checkListener(),this}prependListener(t,i){return super.prependListener(t,i),this.checkListener(),this}off(t,i){return super.off(t,i),this.checkListener(),this}removeAllListeners(t){return super.removeAllListeners(t),this.checkListener(),this}removeListener(t,i){return super.removeListener(t,i),this.checkListener(),this}listenerCount(t){return t!==void 0?super.listenerCount(t):this.eventNames().map(i=>this.listenerCount(i)).reduce((i,n)=>i+n,0)}};var O=class{constructor(e){this.options=Object.assign({},e),this.state=V({},"",{}),this.events=new b(this.state,this,this.options)}get name(){return this.options.name}get host(){return this.options.host}get id(){return this.options.id}get allIDs(){return this.options.allIDs}get protocol(){return this.options.protocol}get mac(){return this.options.mac}get model(){return this.options.model}get modelName(){return this.options.modelName}get os(){return this.options.os}get version(){return this.options.version}get services(){return this.options.services}get debug(){return this.options.debug}set debug(e){typeof e=="function"?this.options.debug=e:this.options.debug=!!e||void 0}toJSON(){return{name:this.name,host:this.host,id:this.id,protocol:this.protocol}}toString(){return`NodePyATVDevice(${this.name}, ${this.host})`}getState(){return o(this,arguments,function*(e={}){var i;if((i=this.state)!=null&&i.dateTime&&new Date().getTime()-this.state.dateTime.getTime()<(e.maxAge||5e3)){let n=null;return this.state.position&&this.state.dateTime&&(n=Math.round(this.state.position+(new Date().getTime()-this.state.dateTime.getTime())/1e3)),Object.assign({},this.state,{position:n})}let t=y();try{let n=g(this.options),a=yield T(t,"atvscript",[...n,"playing"],this.options),r=V(a,t,this.options);return this.applyState(r),r}finally{h(t)}})}clearState(){this.applyState(V({},"",{}))}applyState(e){this.events.applyStateAndEmitEvents(e)}getDateTime(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).dateTime})}getHash(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).hash})}getMediaType(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).mediaType})}getDeviceState(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).deviceState})}getTitle(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).title})}getArtist(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).artist})}getAlbum(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).album})}getGenre(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).genre})}getTotalTime(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).totalTime})}getPosition(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).position})}getShuffle(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).shuffle})}getRepeat(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).repeat})}getApp(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).app})}getAppId(){return o(this,arguments,function*(e={}){return(yield this.getState(e)).appId})}listApps(){return o(this,null,function*(){let e=y(),t=g(this.options),i=yield T(e,"atvremote",[...t,"app_list"],this.options);if(typeof i!="string"||!i.startsWith("App: "))throw new Error("Unexpected atvremote response: "+i);h(e);let n=/(.+) \(([^\)]+)\)$/i;return i.substring(5).split(", App: ").map(r=>{let p=r.match(n);if(p!==null)return{id:p[2],name:p[1],launch:()=>this.launchApp(p[2])}}).filter(Boolean)})}_pressKey(e,t){return o(this,null,function*(){let i=y(),n=g(this.options),a=yield T(i,t,[...n,e],this.options);if(t==="atvscript"&&(typeof a!="object"||a.result!=="success"))throw new Error(`Unable to parse pyatv response: ${JSON.stringify(a,null," ")}`);h(i)})}pressKey(e){return o(this,null,function*(){let t=Object.entries(j).find(([a])=>e===a);if(!t)throw new Error(`Unsupported key value ${e}!`);let i=t[1],n=["turnOn","turnOff"].includes(e)?"atvremote":"atvscript";yield this._pressKey(i,n)})}down(){return o(this,null,function*(){yield this._pressKey("down","atvscript")})}home(){return o(this,null,function*(){yield this._pressKey("home","atvscript")})}homeHold(){return o(this,null,function*(){yield this._pressKey("home_hold","atvscript")})}left(){return o(this,null,function*(){yield this._pressKey("left","atvscript")})}menu(){return o(this,null,function*(){yield this._pressKey("menu","atvscript")})}next(){return o(this,null,function*(){yield this._pressKey("next","atvscript")})}pause(){return o(this,null,function*(){yield this._pressKey("pause","atvscript")})}play(){return o(this,null,function*(){yield this._pressKey("play","atvscript")})}playPause(){return o(this,null,function*(){yield this._pressKey("play_pause","atvscript")})}previous(){return o(this,null,function*(){yield this._pressKey("previous","atvscript")})}right(){return o(this,null,function*(){yield this._pressKey("right","atvscript")})}select(){return o(this,null,function*(){yield this._pressKey("select","atvscript")})}skipBackward(){return o(this,null,function*(){yield this._pressKey("skip_backward","atvscript")})}skipForward(){return o(this,null,function*(){yield this._pressKey("skip_forward","atvscript")})}stop(){return o(this,null,function*(){yield this._pressKey("stop","atvscript")})}suspend(){return o(this,null,function*(){yield this._pressKey("suspend","atvscript")})}topMenu(){return o(this,null,function*(){yield this._pressKey("top_menu","atvscript")})}up(){return o(this,null,function*(){yield this._pressKey("up","atvscript")})}volumeDown(){return o(this,null,function*(){yield this._pressKey("volume_down","atvscript")})}volumeUp(){return o(this,null,function*(){yield this._pressKey("volume_up","atvscript")})}wakeup(){return o(this,null,function*(){yield this._pressKey("wakeup","atvscript")})}turnOff(){return o(this,null,function*(){yield this._pressKey("turn_off","atvremote")})}turnOn(){return o(this,null,function*(){yield this._pressKey("turn_on","atvremote")})}launchApp(e){return o(this,null,function*(){yield this._pressKey("launch_app="+e,"atvremote")})}addListener(e,t){return this.events.addListener(e,t),this}emit(e,t){return this.events.emit(e,t)}eventNames(){return this.events.eventNames()}getMaxListeners(){return this.events.getMaxListeners()}listenerCount(e){return this.events.listenerCount(e)}listeners(e){return this.events.listeners(e)}off(e,t){return this.events.off(e,t),this}on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}prependListener(e,t){return this.events.prependListener(e,t),this}prependOnceListener(e,t){return this.events.prependOnceListener(e,t),this}rawListeners(e){return this.events.rawListeners(e)}removeAllListeners(e){return this.events.removeAllListeners(e),this}removeListener(e,t){return this.events.removeListener(e,t),this}setMaxListeners(e){return this.events.setMaxListeners(e),this}};import G from"semver";import{join as H,dirname as W}from"path";import{fileURLToPath as z}from"url";import{promises as Q}from"fs";var X={};var C=class s{constructor(e={}){this.options={};this.options=Object.assign({},e)}static check(){return o(this,arguments,function*(e={}){let t=yield this.version(e);if(!t.pyatv)throw new Error("Unable to find pyatv. Is it installed?");if(G.lt(t.pyatv,"0.6.0"))throw new Error("Found pyatv, but unforunately it's too old. Please update pyatv.");try{yield this.find(e)}catch(i){throw new Error(`Unable to scan for devices: ${String(i).replace("Error: ","")}`)}})}static version(){return o(this,arguments,function*(e={}){let t=y(),i=null,n=null;try{i=yield T(t,"atvremote",["--version"],e)}catch(a){l(t,`Unable to get pyatv version due to ${a}`,e)}i&&i.substr(0,10)==="atvremote "&&(i=i.substr(10)),G.valid(i)||(l(t,`String "${i}" is not a valid pyatv version, set it to null`,e),i=null);try{let a=H(W(z(X.url)),"..","..","package.json"),r=JSON.parse(yield Q.readFile(a,"utf8"));n=(r==null?void 0:r.version)||null}catch(a){l(t,`Unable to get module version due to ${a}`,e)}return n&&!G.valid(n)&&(l(t,`String "${n}" is not a valid module version, set it to null`,e),n=null),h(t),{pyatv:i,module:n}})}static find(){return o(this,arguments,function*(e={}){let t=y(),i=g(e),n=yield T(t,"atvscript",[...i,"scan"],e);if(typeof n!="object"||n.result!=="success"||!Array.isArray(n.devices))throw new Error(`Unable to parse pyatv response: ${JSON.stringify(n,null," ")}`);let a=n.devices.map(r=>{var p,c,u,m,v;return this.device(Object.assign({},e,{host:r.address,id:r.identifier,allIDs:r.all_identifiers,name:r.name,mac:(p=r.device_info)==null?void 0:p.mac,model:(c=r.device_info)==null?void 0:c.model,modelName:(u=r.device_info)==null?void 0:u.model_str,os:(m=r.device_info)==null?void 0:m.operating_system,version:(v=r.device_info)==null?void 0:v.version,services:r.services}))});return h(t),a})}static device(e){return new O(e)}check(){return o(this,arguments,function*(e={}){return s.check(Object.assign({},this.options,e))})}version(){return o(this,arguments,function*(e={}){return s.version(Object.assign({},this.options,e))})}find(){return o(this,arguments,function*(e={}){return s.find(Object.assign({},this.options,e))})}device(e){return s.device(Object.assign({},this.options,e))}};export{o as a,N as b,R as c,k as d,x as e,E as f,_ as g,D as h,U as i,F as j,A as k,b as l,O as m,C as n};
7
- //# sourceMappingURL=chunk-D57T7NS2.js.map