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