@sebbo2002/node-pyatv 6.0.0-develop.2 → 6.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.
- 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/src/lib/tools.ts
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
NodePyATVDeviceState,
|
|
5
|
-
NodePyATVExecutableType,
|
|
6
|
-
NodePyATVFindAndInstanceOptions,
|
|
7
|
-
NodePyATVInstanceOptions,
|
|
8
|
-
NodePyATVInternalState,
|
|
9
|
-
NodePyATVMediaType, NodePyATVPowerState, NodePyATVRepeatState, NodePyATVShuffleState,
|
|
10
|
-
NodePyATVState
|
|
11
|
-
} from './types.js';
|
|
12
|
-
|
|
13
|
-
import {ChildProcess, spawn, SpawnOptions} from 'child_process';
|
|
14
|
-
import {FakeChildProcess} from './fake-spawn.js';
|
|
15
|
-
|
|
16
|
-
const requestIds: string[] = [];
|
|
17
|
-
|
|
18
|
-
export function addRequestId(): string {
|
|
19
|
-
let id = '?';
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < 1000; i += 1) {
|
|
22
|
-
id = Math.round(Math.random() * (i + 6) * 36).toString(36).toUpperCase();
|
|
23
|
-
if (!requestIds.includes(id)) {
|
|
24
|
-
requestIds.push(id);
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return id;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function removeRequestId(id: string | undefined): void {
|
|
33
|
-
if (id && requestIds.includes(id)) {
|
|
34
|
-
requestIds.splice(requestIds.indexOf(id), 1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function debug(id: string, message: string, options: NodePyATVInstanceOptions): void {
|
|
39
|
-
if (options.debug) {
|
|
40
|
-
const log = typeof options.debug === 'function' ? options.debug : console.log;
|
|
41
|
-
const enableColors = !process.env.NO_COLOR && !options.noColors;
|
|
42
|
-
|
|
43
|
-
const parts = [
|
|
44
|
-
enableColors ? '\x1b[0m' : '', // Color Reset
|
|
45
|
-
enableColors ? '\x1b[90m' : '', // Grey
|
|
46
|
-
'[node-pyatv][',
|
|
47
|
-
enableColors ? '\x1b[37m' : '', // Light Grey
|
|
48
|
-
id,
|
|
49
|
-
enableColors ? '\x1b[90m' : '', // Grey
|
|
50
|
-
'] ',
|
|
51
|
-
enableColors ? '\x1b[0m' : '', // Color Reset
|
|
52
|
-
message
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
log.apply(null, [parts.join('')]);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function getExecutable(executable: NodePyATVExecutableType, options: NodePyATVInstanceOptions): string {
|
|
60
|
-
if (executable === NodePyATVExecutableType.atvremote && typeof options.atvremotePath === 'string') {
|
|
61
|
-
return options.atvremotePath;
|
|
62
|
-
}
|
|
63
|
-
else if (executable === NodePyATVExecutableType.atvscript && typeof options.atvscriptPath === 'string') {
|
|
64
|
-
return options.atvscriptPath;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return executable;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function execute(
|
|
72
|
-
requestId: string,
|
|
73
|
-
executableType: NodePyATVExecutableType,
|
|
74
|
-
parameters: string[],
|
|
75
|
-
options: NodePyATVInstanceOptions
|
|
76
|
-
): ChildProcess | FakeChildProcess {
|
|
77
|
-
const executable = getExecutable(executableType, options);
|
|
78
|
-
const mySpawn: ((command: string, args: Array<string>, options: SpawnOptions) => (ChildProcess | FakeChildProcess)) = typeof options.spawn === 'function' ? options.spawn : spawn;
|
|
79
|
-
|
|
80
|
-
debug(requestId, `${executable} ${parameters.join(' ')}`, options);
|
|
81
|
-
const child = mySpawn(executable, parameters, {
|
|
82
|
-
env: process.env
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
/* eslint-disable @typescript-eslint/no-explicit-any*/
|
|
86
|
-
const onStdOut = (data: any) => debug(requestId, `stdout: ${String(data).trim()}`, options);
|
|
87
|
-
const onStdErr = (data: any) => debug(requestId, `stderr: ${String(data).trim()}`, options);
|
|
88
|
-
const onError = (data: any) => debug(requestId, `error: ${String(data).trim()}`, options);
|
|
89
|
-
/* eslint-enable @typescript-eslint/no-explicit-any*/
|
|
90
|
-
|
|
91
|
-
const onClose = (code: number) => {
|
|
92
|
-
debug(requestId, `${executable} exited with code: ${code}`, options);
|
|
93
|
-
|
|
94
|
-
if (child.stdout) {
|
|
95
|
-
child.stdout.off('data', onStdOut);
|
|
96
|
-
}
|
|
97
|
-
if (child.stderr) {
|
|
98
|
-
child.stderr.off('data', onStdErr);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
child.off('error', onError);
|
|
102
|
-
child.off('close', onClose);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (child.stdout) {
|
|
106
|
-
child.stdout.on('data', onStdOut);
|
|
107
|
-
}
|
|
108
|
-
if (child.stderr) {
|
|
109
|
-
child.stderr.on('data', onStdErr);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
child.on('error', onError);
|
|
113
|
-
child.on('close', onClose);
|
|
114
|
-
|
|
115
|
-
return child;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export async function request(
|
|
119
|
-
requestId: string,
|
|
120
|
-
executableType: NodePyATVExecutableType,
|
|
121
|
-
parameters: string[],
|
|
122
|
-
options: NodePyATVInstanceOptions
|
|
123
|
-
): Promise<string|Record<string,unknown>> {
|
|
124
|
-
const result = {
|
|
125
|
-
stdout: '',
|
|
126
|
-
stderr: '',
|
|
127
|
-
code: 0
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
await new Promise((resolve, reject) => {
|
|
131
|
-
const pyatv = execute(requestId, executableType, parameters, options);
|
|
132
|
-
|
|
133
|
-
/* eslint-disable @typescript-eslint/no-explicit-any*/
|
|
134
|
-
const onStdOut = (data: any) => result.stdout += String(data).trim();
|
|
135
|
-
const onStdErr = (data: any) => result.stderr += String(data).trim();
|
|
136
|
-
const onError = (data: any) => reject(data instanceof Error ? data : new Error(String(data)));
|
|
137
|
-
/* eslint-enable @typescript-eslint/no-explicit-any*/
|
|
138
|
-
|
|
139
|
-
const onClose: (code: number) => void = (code: number) => {
|
|
140
|
-
result.code = code;
|
|
141
|
-
|
|
142
|
-
if (pyatv.stdout) {
|
|
143
|
-
pyatv.stdout.off('data', onStdOut);
|
|
144
|
-
}
|
|
145
|
-
if (pyatv.stderr) {
|
|
146
|
-
pyatv.stderr.off('data', onStdErr);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
pyatv.off('error', onError);
|
|
150
|
-
pyatv.off('close', onClose);
|
|
151
|
-
resolve(undefined);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
if (pyatv.stdout) {
|
|
155
|
-
pyatv.stdout.on('data', onStdOut);
|
|
156
|
-
}
|
|
157
|
-
if (pyatv.stderr) {
|
|
158
|
-
pyatv.stderr.on('data', onStdErr);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
pyatv.on('error', onError);
|
|
162
|
-
pyatv.on('close', onClose);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
if (result.stderr.length > 0) {
|
|
166
|
-
const msg = `Unable to execute request ${requestId}: ${result.stderr}`;
|
|
167
|
-
debug(requestId, msg, options);
|
|
168
|
-
throw new Error(msg);
|
|
169
|
-
}
|
|
170
|
-
if (executableType === NodePyATVExecutableType.atvscript) {
|
|
171
|
-
try {
|
|
172
|
-
return JSON.parse(result.stdout);
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
const msg = `Unable to parse result ${requestId} json: ${error}`;
|
|
176
|
-
debug(requestId, msg, options);
|
|
177
|
-
throw new Error(msg);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return result.stdout;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function getParamters(options: NodePyATVFindAndInstanceOptions = {}): string[] {
|
|
185
|
-
const parameters: string[] = [];
|
|
186
|
-
|
|
187
|
-
if (options.hosts) {
|
|
188
|
-
parameters.push('-s', options.hosts.join(','));
|
|
189
|
-
}
|
|
190
|
-
else if (options.host) {
|
|
191
|
-
parameters.push('-s', options.host);
|
|
192
|
-
}
|
|
193
|
-
if (options.id) {
|
|
194
|
-
parameters.push('-i', options.id);
|
|
195
|
-
}
|
|
196
|
-
if (options.protocol) {
|
|
197
|
-
parameters.push('--protocol', options.protocol);
|
|
198
|
-
}
|
|
199
|
-
if (options.dmapCredentials) {
|
|
200
|
-
parameters.push('--dmap-credentials', options.dmapCredentials);
|
|
201
|
-
}
|
|
202
|
-
if (options.mrpCredentials) {
|
|
203
|
-
parameters.push('--mrp-credentials', options.mrpCredentials);
|
|
204
|
-
}
|
|
205
|
-
if (options.airplayCredentials) {
|
|
206
|
-
parameters.push('--airplay-credentials', options.airplayCredentials);
|
|
207
|
-
}
|
|
208
|
-
if (options.companionCredentials) {
|
|
209
|
-
parameters.push('--companion-credentials', options.companionCredentials);
|
|
210
|
-
}
|
|
211
|
-
if (options.raopCredentials) {
|
|
212
|
-
parameters.push('--raop-credentials', options.raopCredentials);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return parameters;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function parseStateStringAttr(
|
|
219
|
-
input: NodePyATVInternalState,
|
|
220
|
-
output: NodePyATVState,
|
|
221
|
-
inputAttr: ('hash' | 'title' | 'album' | 'artist' | 'genre' | 'app' | 'app_id'),
|
|
222
|
-
outputAttr: ('hash' | 'title' | 'album' | 'artist' | 'genre' | 'app' | 'appId'),
|
|
223
|
-
d: (msg: string) => void
|
|
224
|
-
): void {
|
|
225
|
-
if (typeof input[inputAttr] === 'string') {
|
|
226
|
-
output[outputAttr] = input[inputAttr] as string;
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
d(`No ${outputAttr} value found in input (${JSON.stringify(input)})`);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function parseState(input: NodePyATVInternalState, id: string, options: NodePyATVInstanceOptions): NodePyATVState {
|
|
234
|
-
const d = (msg: string) => debug(id, msg, options);
|
|
235
|
-
const result: NodePyATVState = {
|
|
236
|
-
dateTime: null,
|
|
237
|
-
hash: null,
|
|
238
|
-
mediaType: null,
|
|
239
|
-
deviceState: null,
|
|
240
|
-
title: null,
|
|
241
|
-
artist: null,
|
|
242
|
-
album: null,
|
|
243
|
-
genre: null,
|
|
244
|
-
totalTime: null,
|
|
245
|
-
position: null,
|
|
246
|
-
shuffle: null,
|
|
247
|
-
repeat: null,
|
|
248
|
-
app: null,
|
|
249
|
-
appId: null,
|
|
250
|
-
powerState: null
|
|
251
|
-
};
|
|
252
|
-
if (!input || typeof input !== 'object') {
|
|
253
|
-
return result;
|
|
254
|
-
}
|
|
255
|
-
if(input.exception) {
|
|
256
|
-
let errorStr = 'Got pyatv Error: ' + input.exception;
|
|
257
|
-
if(input.stacktrace) {
|
|
258
|
-
errorStr += '\n\npyatv Stacktrace:\n' + input.stacktrace;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
throw new Error(errorStr);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// datetime
|
|
265
|
-
if (typeof input.datetime === 'string') {
|
|
266
|
-
const date = new Date(input.datetime);
|
|
267
|
-
if (!isNaN(date.getTime())) {
|
|
268
|
-
result.dateTime = date;
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
d(`Invalid datetime value ${input.datetime}, ignore attribute`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
d(`No datetime value found in input (${JSON.stringify(input)})`);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// hash
|
|
279
|
-
parseStateStringAttr(input, result, 'hash', 'hash', d);
|
|
280
|
-
|
|
281
|
-
// mediaType
|
|
282
|
-
if(typeof input.media_type === 'string') {
|
|
283
|
-
const validValues = Object.keys(NodePyATVMediaType).map(o => String(o));
|
|
284
|
-
if (validValues.includes(input.media_type)) {
|
|
285
|
-
result.mediaType = NodePyATVMediaType[input.media_type as NodePyATVMediaType];
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
d(`Unsupported mediaType value ${input.media_type}, ignore attribute`);
|
|
289
|
-
}
|
|
290
|
-
} else {
|
|
291
|
-
d(`No mediaType value found in input (${JSON.stringify(input)})`);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// deviceState
|
|
295
|
-
if(typeof input.device_state === 'string') {
|
|
296
|
-
const validValues = Object.keys(NodePyATVDeviceState).map(o => String(o));
|
|
297
|
-
if (validValues.includes(input.device_state)) {
|
|
298
|
-
result.deviceState = NodePyATVDeviceState[input.device_state as NodePyATVDeviceState];
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
d(`Unsupported deviceState value ${input.device_state}, ignore attribute`);
|
|
302
|
-
}
|
|
303
|
-
} else {
|
|
304
|
-
d(`No deviceState value found in input (${JSON.stringify(input)})`);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// title
|
|
308
|
-
parseStateStringAttr(input, result, 'title', 'title', d);
|
|
309
|
-
|
|
310
|
-
// artist
|
|
311
|
-
parseStateStringAttr(input, result, 'artist', 'artist', d);
|
|
312
|
-
|
|
313
|
-
// album
|
|
314
|
-
parseStateStringAttr(input, result, 'album', 'album', d);
|
|
315
|
-
|
|
316
|
-
// genre
|
|
317
|
-
parseStateStringAttr(input, result, 'genre', 'genre', d);
|
|
318
|
-
|
|
319
|
-
// totalTime
|
|
320
|
-
if (typeof input.total_time === 'number') {
|
|
321
|
-
result.totalTime = input.total_time;
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
d(`No totalTime value found in input (${JSON.stringify(input)})`);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// position
|
|
328
|
-
if (typeof input.position === 'number') {
|
|
329
|
-
result.position = input.position;
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
d(`No position value found in input (${JSON.stringify(input)})`);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// shuffle
|
|
336
|
-
if(typeof input.shuffle === 'string') {
|
|
337
|
-
const validValues = Object.keys(NodePyATVShuffleState).map(o => String(o));
|
|
338
|
-
if (validValues.includes(input.shuffle)) {
|
|
339
|
-
result.shuffle = NodePyATVShuffleState[input.shuffle as NodePyATVShuffleState];
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
d(`Unsupported shuffle value ${input.shuffle}, ignore attribute`);
|
|
343
|
-
}
|
|
344
|
-
} else {
|
|
345
|
-
d(`No shuffle value found in input (${JSON.stringify(input)})`);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// repeat
|
|
349
|
-
if(typeof input.repeat === 'string') {
|
|
350
|
-
const validValues = Object.keys(NodePyATVRepeatState).map(o => String(o));
|
|
351
|
-
if (validValues.includes(input.repeat)) {
|
|
352
|
-
result.repeat = NodePyATVRepeatState[input.repeat as NodePyATVRepeatState];
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
d(`Unsupported repeat value ${input.repeat}, ignore attribute`);
|
|
356
|
-
}
|
|
357
|
-
} else {
|
|
358
|
-
d(`No repeat value found in input (${JSON.stringify(input)})`);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// app
|
|
362
|
-
parseStateStringAttr(input, result, 'app', 'app', d);
|
|
363
|
-
parseStateStringAttr(input, result, 'app_id', 'appId', d);
|
|
364
|
-
|
|
365
|
-
// powerState
|
|
366
|
-
if(typeof input.power_state === 'string') {
|
|
367
|
-
const validValues = Object.keys(NodePyATVPowerState).map(o => String(o));
|
|
368
|
-
if (validValues.includes(input.power_state)) {
|
|
369
|
-
result.powerState = NodePyATVPowerState[input.power_state as NodePyATVPowerState];
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
d(`Unsupported powerState value ${input.power_state}, ignore attribute`);
|
|
373
|
-
}
|
|
374
|
-
} else {
|
|
375
|
-
d(`No powerState value found in input (${JSON.stringify(input)})`);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return result;
|
|
379
|
-
}
|
package/src/lib/types.ts
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import {ChildProcess, SpawnOptions} from 'child_process';
|
|
2
|
-
import {FakeChildProcess} from './fake-spawn.js';
|
|
3
|
-
|
|
4
|
-
export enum NodePyATVExecutableType {
|
|
5
|
-
atvremote = 'atvremote',
|
|
6
|
-
atvscript = 'atvscript',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export enum NodePyATVProtocol {
|
|
10
|
-
dmap = 'dmap',
|
|
11
|
-
mrp = 'mrp',
|
|
12
|
-
airplay = 'airplay',
|
|
13
|
-
mdns = 'mdns',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export enum NodePyATVMediaType {
|
|
17
|
-
music = 'music',
|
|
18
|
-
tv = 'tv',
|
|
19
|
-
video = 'video',
|
|
20
|
-
unknown = 'unknown'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export enum NodePyATVDeviceState {
|
|
24
|
-
idle = 'idle',
|
|
25
|
-
loading = 'loading',
|
|
26
|
-
paused = 'paused',
|
|
27
|
-
playing = 'playing',
|
|
28
|
-
seeking = 'seeking',
|
|
29
|
-
stopped = 'stopped'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export enum NodePyATVRepeatState {
|
|
33
|
-
all = 'all',
|
|
34
|
-
track = 'track',
|
|
35
|
-
off = 'off'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum NodePyATVShuffleState {
|
|
39
|
-
albums = 'albums',
|
|
40
|
-
songs = 'songs',
|
|
41
|
-
off = 'off'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export enum NodePyATVPowerState {
|
|
45
|
-
on = 'on',
|
|
46
|
-
off = 'off'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export enum NodePyATVKeys {
|
|
50
|
-
down = 'down',
|
|
51
|
-
home = 'home',
|
|
52
|
-
homeHold = 'homeHold',
|
|
53
|
-
left = 'left',
|
|
54
|
-
menu = 'menu',
|
|
55
|
-
next = 'next',
|
|
56
|
-
pause = 'pause',
|
|
57
|
-
play = 'play',
|
|
58
|
-
playPause = 'playPause',
|
|
59
|
-
previous = 'previous',
|
|
60
|
-
right = 'right',
|
|
61
|
-
select = 'select',
|
|
62
|
-
skipBackward = 'skipBackward',
|
|
63
|
-
skipForward = 'skipForward',
|
|
64
|
-
stop = 'stop',
|
|
65
|
-
suspend = 'suspend',
|
|
66
|
-
topMenu = 'topMenu',
|
|
67
|
-
up = 'up',
|
|
68
|
-
volumeDown = 'volumeDown',
|
|
69
|
-
volumeUp = 'volumeUp',
|
|
70
|
-
wakeup = 'wakeup',
|
|
71
|
-
turnOff = 'turnOff',
|
|
72
|
-
turnOn = 'turnOn'
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
export enum NodePyATVInternalKeys {
|
|
79
|
-
down = 'down',
|
|
80
|
-
home = 'home',
|
|
81
|
-
homeHold = 'home_hold',
|
|
82
|
-
left = 'left',
|
|
83
|
-
menu = 'menu',
|
|
84
|
-
next = 'next',
|
|
85
|
-
pause = 'pause',
|
|
86
|
-
play = 'play',
|
|
87
|
-
playPause = 'play_pause',
|
|
88
|
-
previous = 'previous',
|
|
89
|
-
right = 'right',
|
|
90
|
-
select = 'select',
|
|
91
|
-
skipBackward = 'skip_backward',
|
|
92
|
-
skipForward = 'skip_forward',
|
|
93
|
-
stop = 'stop',
|
|
94
|
-
suspend = 'suspend',
|
|
95
|
-
topMenu = 'top_menu',
|
|
96
|
-
up = 'up',
|
|
97
|
-
volumeDown = 'volume_down',
|
|
98
|
-
volumeUp = 'volume_up',
|
|
99
|
-
wakeup = 'wakeup',
|
|
100
|
-
turnOff = 'turn_off',
|
|
101
|
-
turnOn = 'turn_on'
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export enum NodePyATVListenerState {
|
|
105
|
-
stopped,
|
|
106
|
-
starting,
|
|
107
|
-
started,
|
|
108
|
-
stopping
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
export type NodePyATVStateIndex = keyof NodePyATVState;
|
|
113
|
-
|
|
114
|
-
export type NodePyATVEventValueType = (string | number | NodePyATVMediaType | NodePyATVDeviceState |
|
|
115
|
-
NodePyATVShuffleState | NodePyATVRepeatState);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
export interface NodePyATVInstanceOptions {
|
|
119
|
-
atvremotePath?: string;
|
|
120
|
-
atvscriptPath?: string;
|
|
121
|
-
debug?: true | ((msg: string) => void);
|
|
122
|
-
noColors?: true;
|
|
123
|
-
spawn?: (command: string, args: Array<string>, options: SpawnOptions) => (ChildProcess | FakeChildProcess);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface NodePyATVVersionResponse {
|
|
127
|
-
pyatv: string | null;
|
|
128
|
-
module: string | null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface NodePyATVFindOptions {
|
|
132
|
-
host?: string;
|
|
133
|
-
hosts?: string[];
|
|
134
|
-
id?: string;
|
|
135
|
-
protocol?: NodePyATVProtocol;
|
|
136
|
-
dmapCredentials?: string;
|
|
137
|
-
mrpCredentials?: string;
|
|
138
|
-
airplayCredentials?: string;
|
|
139
|
-
companionCredentials?: string;
|
|
140
|
-
raopCredentials?: string;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface NodePyATVFindAndInstanceOptions extends NodePyATVInstanceOptions, NodePyATVFindOptions {
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
|
|
148
|
-
host: string;
|
|
149
|
-
name: string;
|
|
150
|
-
model?: string;
|
|
151
|
-
modelName?: string;
|
|
152
|
-
os?: string;
|
|
153
|
-
version?: string;
|
|
154
|
-
services?: NodePyATVService[];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface NodePyATVGetStateOptions {
|
|
158
|
-
maxAge?: number;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export interface NodePyATVService {
|
|
162
|
-
protocol: NodePyATVProtocol;
|
|
163
|
-
port: number;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @internal
|
|
168
|
-
*/
|
|
169
|
-
export interface NodePyATVInternalScanDevice {
|
|
170
|
-
name: string;
|
|
171
|
-
address: string;
|
|
172
|
-
identifier: string;
|
|
173
|
-
device_info?: {
|
|
174
|
-
model: string;
|
|
175
|
-
model_str: string;
|
|
176
|
-
operating_system: string;
|
|
177
|
-
version: string;
|
|
178
|
-
};
|
|
179
|
-
services?: NodePyATVService[];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @internal
|
|
184
|
-
*/
|
|
185
|
-
export interface NodePyATVInternalState {
|
|
186
|
-
result?: string | unknown,
|
|
187
|
-
datetime?: string | unknown,
|
|
188
|
-
hash?: string | unknown,
|
|
189
|
-
media_type?: string | unknown,
|
|
190
|
-
device_state?: string | unknown,
|
|
191
|
-
title?: string | unknown,
|
|
192
|
-
artist?: string | unknown,
|
|
193
|
-
album?: string | unknown,
|
|
194
|
-
genre?: string | unknown,
|
|
195
|
-
total_time?: number | unknown,
|
|
196
|
-
position?: 1 | unknown,
|
|
197
|
-
shuffle?: string | unknown,
|
|
198
|
-
repeat?: string | unknown,
|
|
199
|
-
app?: string | unknown,
|
|
200
|
-
app_id?: string | unknown,
|
|
201
|
-
power_state?: string | unknown,
|
|
202
|
-
push_updates?: string | unknown,
|
|
203
|
-
exception?: string | unknown,
|
|
204
|
-
stacktrace?: string | unknown,
|
|
205
|
-
connection?: string | unknown
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export interface NodePyATVState {
|
|
209
|
-
dateTime: Date | null;
|
|
210
|
-
hash: string | null;
|
|
211
|
-
mediaType: NodePyATVMediaType | null,
|
|
212
|
-
deviceState: NodePyATVDeviceState | null,
|
|
213
|
-
title: string | null,
|
|
214
|
-
artist: string | null,
|
|
215
|
-
album: string | null,
|
|
216
|
-
genre: string | null,
|
|
217
|
-
totalTime: number | null,
|
|
218
|
-
position: number | null,
|
|
219
|
-
shuffle: NodePyATVShuffleState | null,
|
|
220
|
-
repeat: NodePyATVRepeatState | null,
|
|
221
|
-
app: string | null,
|
|
222
|
-
appId: string | null,
|
|
223
|
-
powerState: NodePyATVPowerState | null
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export interface NodePyATVApp {
|
|
227
|
-
id: string;
|
|
228
|
-
name: string;
|
|
229
|
-
launch: () => Promise<void>;
|
|
230
|
-
}
|
package/test/device-event.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
import NodePyATVDevice from '../src/lib/device.js';
|
|
5
|
-
import NodePyATVDeviceEvent from '../src/lib/device-event.js';
|
|
6
|
-
|
|
7
|
-
describe('NodePyATVDeviceEvent', function () {
|
|
8
|
-
describe('get key()', function () {
|
|
9
|
-
it('should work', function () {
|
|
10
|
-
const event = new NodePyATVDeviceEvent({
|
|
11
|
-
key: 'genre',
|
|
12
|
-
old: 'Jazz',
|
|
13
|
-
new: 'Rock',
|
|
14
|
-
device: new NodePyATVDevice({
|
|
15
|
-
host: '192.168.178.2',
|
|
16
|
-
name: 'My Testinstance'
|
|
17
|
-
})
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
assert.strictEqual(event.key, 'genre');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('get oldValue()', function () {
|
|
25
|
-
it('should work', function () {
|
|
26
|
-
const event = new NodePyATVDeviceEvent({
|
|
27
|
-
key: 'genre',
|
|
28
|
-
old: 'Jazz',
|
|
29
|
-
new: 'Rock',
|
|
30
|
-
device: new NodePyATVDevice({
|
|
31
|
-
host: '192.168.178.2',
|
|
32
|
-
name: 'My Testinstance'
|
|
33
|
-
})
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
assert.strictEqual(event.oldValue, 'Jazz');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('get newValue()', function () {
|
|
41
|
-
it('should work', function () {
|
|
42
|
-
const event = new NodePyATVDeviceEvent({
|
|
43
|
-
key: 'genre',
|
|
44
|
-
old: 'Jazz',
|
|
45
|
-
new: 'Rock',
|
|
46
|
-
device: new NodePyATVDevice({
|
|
47
|
-
host: '192.168.178.2',
|
|
48
|
-
name: 'My Testinstance'
|
|
49
|
-
})
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
assert.strictEqual(event.newValue, 'Rock');
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('get value()', function () {
|
|
57
|
-
it('should work', function () {
|
|
58
|
-
const event = new NodePyATVDeviceEvent({
|
|
59
|
-
key: 'genre',
|
|
60
|
-
old: 'Jazz',
|
|
61
|
-
new: 'Rock',
|
|
62
|
-
device: new NodePyATVDevice({
|
|
63
|
-
host: '192.168.178.2',
|
|
64
|
-
name: 'My Testinstance'
|
|
65
|
-
})
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
assert.strictEqual(event.value, 'Rock');
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('get device()', function () {
|
|
73
|
-
it('should work', function () {
|
|
74
|
-
const device = new NodePyATVDevice({
|
|
75
|
-
host: '192.168.178.2',
|
|
76
|
-
name: 'My Testinstance'
|
|
77
|
-
});
|
|
78
|
-
const event = new NodePyATVDeviceEvent({
|
|
79
|
-
key: 'genre',
|
|
80
|
-
old: 'Jazz',
|
|
81
|
-
new: 'Rock',
|
|
82
|
-
device
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
assert.deepEqual(event.device, device);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|