@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.
Files changed (120) hide show
  1. package/dist/bin/check.cjs +10 -0
  2. package/dist/bin/check.cjs.map +1 -0
  3. package/dist/bin/check.d.ts +2 -1
  4. package/dist/bin/check.js +4 -45
  5. package/dist/bin/check.js.map +1 -1
  6. package/dist/chunk-TZSWUAOB.js +7 -0
  7. package/dist/chunk-TZSWUAOB.js.map +1 -0
  8. package/dist/lib/index.cjs +7 -0
  9. package/dist/lib/index.cjs.map +1 -0
  10. package/dist/lib/{device.d.ts → index.d.cts} +340 -4
  11. package/dist/lib/index.d.ts +806 -6
  12. package/dist/lib/index.js +1 -7
  13. package/dist/lib/index.js.map +1 -1
  14. package/package.json +18 -9
  15. package/.editorconfig +0 -12
  16. package/.eslintignore +0 -4
  17. package/.eslintrc +0 -60
  18. package/.mocharc.yml +0 -7
  19. package/.nycrc +0 -32
  20. package/CHANGELOG.md +0 -295
  21. package/check.sh +0 -5
  22. package/dist/examples/push.d.ts +0 -1
  23. package/dist/examples/push.js +0 -51
  24. package/dist/examples/push.js.map +0 -1
  25. package/dist/lib/device-event.d.ts +0 -44
  26. package/dist/lib/device-event.js +0 -47
  27. package/dist/lib/device-event.js.map +0 -1
  28. package/dist/lib/device-events.d.ts +0 -30
  29. package/dist/lib/device-events.js +0 -237
  30. package/dist/lib/device-events.js.map +0 -1
  31. package/dist/lib/device.js +0 -793
  32. package/dist/lib/device.js.map +0 -1
  33. package/dist/lib/fake-spawn.d.ts +0 -43
  34. package/dist/lib/fake-spawn.js +0 -85
  35. package/dist/lib/fake-spawn.js.map +0 -1
  36. package/dist/lib/instance.d.ts +0 -97
  37. package/dist/lib/instance.js +0 -208
  38. package/dist/lib/instance.js.map +0 -1
  39. package/dist/lib/tools.d.ts +0 -12
  40. package/dist/lib/tools.js +0 -319
  41. package/dist/lib/tools.js.map +0 -1
  42. package/dist/lib/types.d.ts +0 -204
  43. package/dist/lib/types.js +0 -108
  44. package/dist/lib/types.js.map +0 -1
  45. package/docs/coverage/base.css +0 -224
  46. package/docs/coverage/block-navigation.js +0 -87
  47. package/docs/coverage/cobertura-coverage.xml +0 -2889
  48. package/docs/coverage/device-event.ts.html +0 -256
  49. package/docs/coverage/device-events.ts.html +0 -970
  50. package/docs/coverage/device.ts.html +0 -2518
  51. package/docs/coverage/fake-spawn.ts.html +0 -448
  52. package/docs/coverage/favicon.png +0 -0
  53. package/docs/coverage/index.html +0 -221
  54. package/docs/coverage/index.ts.html +0 -172
  55. package/docs/coverage/instance.ts.html +0 -718
  56. package/docs/coverage/prettify.css +0 -1
  57. package/docs/coverage/prettify.js +0 -2
  58. package/docs/coverage/sort-arrow-sprite.png +0 -0
  59. package/docs/coverage/sorter.js +0 -196
  60. package/docs/coverage/tools.ts.html +0 -1222
  61. package/docs/coverage/types.ts.html +0 -775
  62. package/docs/reference/.nojekyll +0 -1
  63. package/docs/reference/assets/highlight.css +0 -99
  64. package/docs/reference/assets/main.js +0 -58
  65. package/docs/reference/assets/search.js +0 -1
  66. package/docs/reference/assets/style.css +0 -1280
  67. package/docs/reference/classes/NodePyATVDevice.html +0 -1266
  68. package/docs/reference/classes/NodePyATVDeviceEvent.html +0 -123
  69. package/docs/reference/classes/NodePyATVInstance.html +0 -240
  70. package/docs/reference/enums/NodePyATVDeviceState.html +0 -97
  71. package/docs/reference/enums/NodePyATVExecutableType.html +0 -69
  72. package/docs/reference/enums/NodePyATVKeys.html +0 -216
  73. package/docs/reference/enums/NodePyATVListenerState.html +0 -83
  74. package/docs/reference/enums/NodePyATVMediaType.html +0 -83
  75. package/docs/reference/enums/NodePyATVPowerState.html +0 -69
  76. package/docs/reference/enums/NodePyATVProtocol.html +0 -83
  77. package/docs/reference/enums/NodePyATVRepeatState.html +0 -76
  78. package/docs/reference/enums/NodePyATVShuffleState.html +0 -76
  79. package/docs/reference/index.html +0 -139
  80. package/docs/reference/interfaces/NodePyATVDeviceOptions.html +0 -232
  81. package/docs/reference/interfaces/NodePyATVFindAndInstanceOptions.html +0 -193
  82. package/docs/reference/interfaces/NodePyATVFindOptions.html +0 -124
  83. package/docs/reference/interfaces/NodePyATVGetStateOptions.html +0 -66
  84. package/docs/reference/interfaces/NodePyATVInstanceOptions.html +0 -113
  85. package/docs/reference/interfaces/NodePyATVService.html +0 -73
  86. package/docs/reference/interfaces/NodePyATVState.html +0 -164
  87. package/docs/reference/interfaces/NodePyATVVersionResponse.html +0 -73
  88. package/docs/reference/modules.html +0 -106
  89. package/docs/reference/types/NodePyATVEventValueType.html +0 -66
  90. package/docs/tests/assets/MaterialIcons-Regular.woff +0 -0
  91. package/docs/tests/assets/MaterialIcons-Regular.woff2 +0 -0
  92. package/docs/tests/assets/app.css +0 -14
  93. package/docs/tests/assets/app.js +0 -2
  94. package/docs/tests/assets/app.js.LICENSE.txt +0 -55
  95. package/docs/tests/assets/roboto-light-webfont.woff +0 -0
  96. package/docs/tests/assets/roboto-light-webfont.woff2 +0 -0
  97. package/docs/tests/assets/roboto-medium-webfont.woff +0 -0
  98. package/docs/tests/assets/roboto-medium-webfont.woff2 +0 -0
  99. package/docs/tests/assets/roboto-regular-webfont.woff +0 -0
  100. package/docs/tests/assets/roboto-regular-webfont.woff2 +0 -0
  101. package/docs/tests/index.html +0 -2
  102. package/docs/tests/mochawesome.json +0 -4823
  103. package/release.config.cjs +0 -51
  104. package/src/bin/check.ts +0 -41
  105. package/src/examples/push.ts +0 -46
  106. package/src/lib/device-event.ts +0 -57
  107. package/src/lib/device-events.ts +0 -295
  108. package/src/lib/device.ts +0 -811
  109. package/src/lib/fake-spawn.ts +0 -121
  110. package/src/lib/index.ts +0 -29
  111. package/src/lib/instance.ts +0 -211
  112. package/src/lib/tools.ts +0 -379
  113. package/src/lib/types.ts +0 -230
  114. package/test/device-event.ts +0 -88
  115. package/test/device-events.ts +0 -502
  116. package/test/device.ts +0 -826
  117. package/test/instance.ts +0 -428
  118. package/test/tools.ts +0 -301
  119. package/tsconfig.json +0 -19
  120. package/typedoc.json +0 -15
@@ -1,121 +0,0 @@
1
- import {SpawnOptions} from 'child_process';
2
- import {EventEmitter} from 'events';
3
-
4
- /**
5
- * @internal
6
- */
7
- export function createFakeSpawn(callback: ((cp: FakeChildProcessController) => void)): (
8
- command: string,
9
- args: ReadonlyArray<string>,
10
- options: SpawnOptions
11
- ) => FakeChildProcess {
12
- return (command: string, args: ReadonlyArray<string>, options: SpawnOptions) => new FakeChildProcess(
13
- command,
14
- args,
15
- options,
16
- callback
17
- );
18
- }
19
-
20
- /**
21
- * @internal
22
- */
23
- export class FakeChildProcessStdIn extends EventEmitter {
24
- write (data: string): void {
25
- this.emit('data', Buffer.from(data));
26
- }
27
- }
28
-
29
- /**
30
- * @internal
31
- */
32
- export class FakeChildProcess extends EventEmitter {
33
- cmd: string;
34
- args: ReadonlyArray<string>;
35
- timeout: NodeJS.Timeout | undefined;
36
- stdout: EventEmitter;
37
- stderr: EventEmitter;
38
- stdin: FakeChildProcessStdIn;
39
-
40
- constructor(command: string, args: ReadonlyArray<string>, options: SpawnOptions, callback: (cp: FakeChildProcessController) => void) {
41
- super();
42
-
43
- this.cmd = command;
44
- this.args = args;
45
- this.timeout = setTimeout(() => {
46
- console.error(new Error(`FakeSpawn: Timeout for ${this.cmd} ${this.args.join(' ')}!`));
47
- }, 5000);
48
-
49
- this.stdout = new EventEmitter();
50
- this.stderr = new EventEmitter();
51
- this.stdin = new FakeChildProcessStdIn();
52
-
53
- const controller = new FakeChildProcessController(this);
54
- setTimeout(() => callback(controller), 0);
55
- }
56
-
57
- kill(): void {
58
- this.emit('close', 0);
59
- if(this.timeout !== undefined) {
60
- clearTimeout(this.timeout);
61
- this.timeout = undefined;
62
- }
63
- }
64
- }
65
-
66
- /**
67
- * @internal
68
- */
69
- export class FakeChildProcessController {
70
- _cp: FakeChildProcess;
71
- _code: number | null;
72
-
73
- constructor(cp: FakeChildProcess) {
74
- this._cp = cp;
75
- this._code = null;
76
- }
77
-
78
- cmd(): string {
79
- return this._cp.cmd;
80
- }
81
-
82
- stdout(content: string | Record<string, unknown>): this {
83
- this._cp.stdout.emit('data', typeof content === 'string' ? content : JSON.stringify(content));
84
- return this;
85
- }
86
-
87
- stderr(content: string): this {
88
- this._cp.stderr.emit('data', content);
89
- return this;
90
- }
91
-
92
- // eslint-disable-next-line
93
- onStdIn(listener: (...args: any[]) => void): this {
94
- this._cp.stdin.on('data', listener);
95
- return this;
96
- }
97
-
98
- error(error: Error): this {
99
- this._cp.emit('error', error);
100
- return this;
101
- }
102
-
103
- code(exitCode: number): this {
104
- this._code = exitCode;
105
- return this;
106
- }
107
-
108
- end(content?: string | Record<string, unknown>): this {
109
- if (content !== undefined) {
110
- this.stdout(content);
111
- }
112
-
113
- this._cp.emit('close', this._code || 0);
114
- if(this._cp.timeout !== undefined) {
115
- clearTimeout(this._cp.timeout);
116
- this._cp.timeout = undefined;
117
- }
118
-
119
- return this;
120
- }
121
- }
package/src/lib/index.ts DELETED
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- export {
4
- NodePyATVDeviceOptions,
5
- NodePyATVDeviceState,
6
- NodePyATVEventValueType,
7
- NodePyATVExecutableType,
8
- NodePyATVFindAndInstanceOptions,
9
- NodePyATVFindOptions,
10
- NodePyATVGetStateOptions,
11
- NodePyATVInstanceOptions,
12
- NodePyATVKeys,
13
- NodePyATVListenerState,
14
- NodePyATVMediaType,
15
- NodePyATVPowerState,
16
- NodePyATVProtocol,
17
- NodePyATVRepeatState,
18
- NodePyATVService,
19
- NodePyATVShuffleState,
20
- NodePyATVState,
21
- NodePyATVVersionResponse
22
- } from './types.js';
23
-
24
- export {default as NodePyATVDeviceEvent} from './device-event.js';
25
- export {default as NodePyATVDeviceEvents} from './device-events.js';
26
- export {default as NodePyATVDevice} from './device.js';
27
- export {default as NodePyATVInstance} from './instance.js';
28
-
29
- export {default} from './instance.js';
@@ -1,211 +0,0 @@
1
- 'use strict';
2
-
3
- import semver from 'semver';
4
- import { dirname } from 'path';
5
- import { fileURLToPath } from 'url';
6
- import { promises as fsPromises } from 'fs';
7
-
8
- import {
9
- NodePyATVDeviceOptions,
10
- NodePyATVExecutableType,
11
- NodePyATVFindAndInstanceOptions,
12
- NodePyATVInstanceOptions,
13
- NodePyATVInternalScanDevice,
14
- NodePyATVVersionResponse
15
- } from './types.js';
16
-
17
- import { addRequestId, debug, getParamters, removeRequestId, request } from './tools.js';
18
- import { NodePyATVDevice } from '../lib/index.js';
19
-
20
- const __filename = fileURLToPath(import.meta.url);
21
- const __dirname = dirname(__filename);
22
-
23
- /**
24
- * Default class exported by `@sebbo2002/node-pyatv`. Use [[find]] to scan for devices in your local network. Use
25
- * [[device]] to connect to a known device by passing (at least) it's name and IP.
26
- *
27
- * ```typescript
28
- * import pyatv from '@sebbo2002/node-pyatv';
29
- * ```
30
- */
31
- export default class NodePyATVInstance {
32
- private readonly options: NodePyATVInstanceOptions = {};
33
-
34
- /**
35
- * Checks if pyatv is installed and ready to be used.
36
- * Will throw an error if not.
37
- *
38
- * @param options
39
- */
40
- public static async check (options: NodePyATVInstanceOptions = {}): Promise<void> {
41
- const versions = await this.version(options);
42
- if (!versions.pyatv) {
43
- throw new Error('Unable to find pyatv. Is it installed?');
44
- }
45
- if (semver.lt(versions.pyatv, '0.6.0')) {
46
- throw new Error('Found pyatv, but unforunately it\'s too old. Please update pyatv.');
47
- }
48
-
49
- try {
50
- await this.find(options);
51
- } catch (error) {
52
- throw new Error(`Unable to scan for devices: ${String(error).replace('Error: ', '')}`);
53
- }
54
- }
55
-
56
- /**
57
- * Resolves with the version of pyatv and of the module itself.
58
- * If a value can't be found, null is returned instead.
59
- *
60
- * @param options
61
- */
62
- public static async version (options: NodePyATVInstanceOptions = {}): Promise<NodePyATVVersionResponse> {
63
- const id = addRequestId();
64
- let pyatv = null;
65
- let module = null;
66
-
67
- try {
68
- pyatv = await request(id, NodePyATVExecutableType.atvremote, ['--version'], options) as string;
69
- } catch (error) {
70
- debug(id, `Unable to get pyatv version due to ${error}`, options);
71
- }
72
-
73
- if (pyatv && pyatv.substr(0, 10) === 'atvremote ') {
74
- pyatv = pyatv.substr(10);
75
- }
76
- if (!semver.valid(pyatv)) {
77
- debug(id, `String "${pyatv}" is not a valid pyatv version, set it to null`, options);
78
- pyatv = null;
79
- }
80
-
81
- try {
82
- const json = JSON.parse(await fsPromises.readFile(__dirname + '/../../package.json', 'utf8'));
83
- module = json?.version || null;
84
- } catch (error) {
85
- debug(id, `Unable to get module version due to ${error}`, options);
86
- }
87
- if (module && !semver.valid(module)) {
88
- debug(id, `String "${module}" is not a valid module version, set it to null`, options);
89
- module = null;
90
- }
91
-
92
- removeRequestId(id);
93
- return {
94
- pyatv,
95
- module
96
- };
97
- }
98
-
99
- /**
100
- * Scan the network for Apple TVs by using pyatv's atvscript. See [[NodePyATVFindAndInstanceOptions]]
101
- * for the options allowed. Use the `host` / `hosts` attribute to filter by IP addresses. Resolves with
102
- * an array of [[NodePyATVDevice]].
103
- *
104
- * ```typescript
105
- * import pyatv from '@sebbo2002/node-pyatv';
106
- * const devices = await pyatv.find();
107
- * console.log(devices);
108
- * ```
109
- *
110
- * @param options
111
- */
112
- public static async find (options: NodePyATVFindAndInstanceOptions = {}): Promise<NodePyATVDevice[]> {
113
- const id = addRequestId();
114
- const parameters = getParamters(options);
115
-
116
- const result = await request(id, NodePyATVExecutableType.atvscript, [...parameters, 'scan'], options);
117
- if (typeof result !== 'object' || result.result !== 'success' || !Array.isArray(result.devices)) {
118
- throw new Error(`Unable to parse pyatv response: ${JSON.stringify(result, null, ' ')}`);
119
- }
120
-
121
- const objects = result.devices.map((device: NodePyATVInternalScanDevice) =>
122
- this.device(Object.assign({}, options, {
123
- host: device.address,
124
- id: device.identifier,
125
- name: device.name,
126
- model: device.device_info?.model,
127
- modelName: device.device_info?.model_str,
128
- os: device.device_info?.operating_system,
129
- version: device.device_info?.version,
130
- services: device.services
131
- }))
132
- );
133
-
134
- removeRequestId(id);
135
- return objects;
136
- }
137
-
138
- /**
139
- * Create a [[NodePyATVDevice]] to query the state and control it.
140
- * At least `host` and `name` are required.
141
- *
142
- * @param options
143
- */
144
- public static device (options: NodePyATVDeviceOptions): NodePyATVDevice {
145
- return new NodePyATVDevice(options);
146
- }
147
-
148
- /**
149
- * Use this to apply [[NodePyATVInstanceOptions]]
150
- * (e.g. debug log method) to all further requests
151
- *
152
- * ```typescript
153
- * import pyatv from '@sebbo2002/node-pyatv';
154
- * const myPyatv = new pyatv({debug: true});
155
- * const devices = myPyatv.find();
156
- * console.log(devices);
157
- * ```
158
- * @param options
159
- */
160
- public constructor (options: NodePyATVInstanceOptions = {}) {
161
- this.options = Object.assign({}, options);
162
- }
163
-
164
- /**
165
- * Checks if pyatv is installed and ready to be used.
166
- * Will throw an error if not.
167
- *
168
- * @param options
169
- */
170
- public async check (options: NodePyATVInstanceOptions = {}): Promise<void> {
171
- return NodePyATVInstance.check(Object.assign({}, this.options, options));
172
- }
173
-
174
- /**
175
- * Resolves with the version of pyatv and of the module itself.
176
- * If a value can't be found, null is returned instead.
177
- *
178
- * @param options
179
- */
180
- public async version (options: NodePyATVInstanceOptions = {}): Promise<NodePyATVVersionResponse> {
181
- return NodePyATVInstance.version(Object.assign({}, this.options, options));
182
- }
183
-
184
- /**
185
- * Scan the network for Apple TVs by using pyatv's atvscript. See [[NodePyATVFindAndInstanceOptions]]
186
- * for the options allowed. Use the `host` / `hosts` attribute to filter by IP addresses. Resolves with
187
- * an array of [[NodePyATVDevice]].
188
- *
189
- * ```typescript
190
- * import pyatv from '@sebbo2002/node-pyatv';
191
- * const myPyATV = new pyatv({debug: true});
192
- * const devices = await myPyATV.find();
193
- * console.log(devices);
194
- * ```
195
- *
196
- * @param options
197
- */
198
- public async find (options: NodePyATVFindAndInstanceOptions = {}): Promise<NodePyATVDevice[]> {
199
- return NodePyATVInstance.find(Object.assign({}, this.options, options));
200
- }
201
-
202
- /**
203
- * Create a [[NodePyATVDevice]] to query the state and control it.
204
- * At least `host` and `name` are required.
205
- *
206
- * @param options
207
- */
208
- public device (options: NodePyATVDeviceOptions): NodePyATVDevice {
209
- return NodePyATVInstance.device(Object.assign({}, this.options, options));
210
- }
211
- }