@sebbo2002/node-pyatv 6.0.0-develop.1 → 6.0.0-develop.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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} +351 -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 +23 -14
- 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 -288
- 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 -756
- 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 -199
- 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 -2829
- 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 -2401
- 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 -757
- 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 -1228
- 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 -4745
- 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 -772
- 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 -224
- package/test/device-event.ts +0 -88
- package/test/device-events.ts +0 -502
- package/test/device.ts +0 -784
- package/test/instance.ts +0 -428
- package/test/tools.ts +0 -301
- package/tsconfig.json +0 -19
- package/typedoc.json +0 -15
package/release.config.cjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const configuration = {
|
|
2
|
-
'branches': [
|
|
3
|
-
'main',
|
|
4
|
-
{
|
|
5
|
-
'name': 'develop',
|
|
6
|
-
'channel': 'next',
|
|
7
|
-
'prerelease': true
|
|
8
|
-
}
|
|
9
|
-
],
|
|
10
|
-
'plugins': []
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
configuration.plugins.push(['@semantic-release/commit-analyzer', {
|
|
14
|
-
'releaseRules': [
|
|
15
|
-
{'type': 'chore', 'scope': 'deps', 'release': 'patch'},
|
|
16
|
-
{'type': 'chore', 'scope': 'package', 'release': 'patch'},
|
|
17
|
-
{'type': 'build', 'scope': 'deps', 'release': 'patch'},
|
|
18
|
-
{'type': 'docs', 'release': 'patch'}
|
|
19
|
-
]
|
|
20
|
-
}]);
|
|
21
|
-
|
|
22
|
-
configuration.plugins.push('@semantic-release/release-notes-generator');
|
|
23
|
-
|
|
24
|
-
configuration.plugins.push('@semantic-release/changelog');
|
|
25
|
-
|
|
26
|
-
configuration.plugins.push('semantic-release-license');
|
|
27
|
-
|
|
28
|
-
configuration.plugins.push('@semantic-release/npm');
|
|
29
|
-
|
|
30
|
-
configuration.plugins.push(['@semantic-release/exec', {
|
|
31
|
-
'prepareCmd': './.github/workflows/build.sh'
|
|
32
|
-
}]);
|
|
33
|
-
|
|
34
|
-
configuration.plugins.push(['@semantic-release/github', {
|
|
35
|
-
'labels': false,
|
|
36
|
-
'assignees': process.env.GH_OWNER
|
|
37
|
-
}]);
|
|
38
|
-
|
|
39
|
-
configuration.plugins.push(['@semantic-release/git', {
|
|
40
|
-
'assets': ['CHANGELOG.md', 'LICENSE'],
|
|
41
|
-
'message': 'chore(release): :bookmark: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
|
|
42
|
-
}]);
|
|
43
|
-
|
|
44
|
-
configuration.plugins.push(['@qiwi/semantic-release-gh-pages-plugin', {
|
|
45
|
-
'msg': 'docs: Updated for <%= nextRelease.gitTag %>',
|
|
46
|
-
'src': './docs',
|
|
47
|
-
'dst': `./${process.env.BRANCH}`,
|
|
48
|
-
'pullTagsBranch': 'main'
|
|
49
|
-
}]);
|
|
50
|
-
|
|
51
|
-
module.exports = configuration;
|
package/src/bin/check.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import NodePyATVInstance from '../lib/instance.js';
|
|
4
|
-
|
|
5
|
-
(async () => {
|
|
6
|
-
try {
|
|
7
|
-
await NodePyATVInstance.check();
|
|
8
|
-
|
|
9
|
-
console.log('');
|
|
10
|
-
console.log('✔ node-pyatv seems to be ready to use!');
|
|
11
|
-
console.log(' Thank you and have a great day. Or night. Whatever.');
|
|
12
|
-
console.log('');
|
|
13
|
-
}
|
|
14
|
-
catch(error) {
|
|
15
|
-
console.log('');
|
|
16
|
-
console.log('#'.repeat(60));
|
|
17
|
-
console.log('#' + ' '.repeat(58) + '#');
|
|
18
|
-
console.log('# ⚠ Warning: node-pyatv is not ready to be used!' + ' '.repeat(10) + '#');
|
|
19
|
-
console.log('#' + ' '.repeat(58) + '#');
|
|
20
|
-
console.log('# To use the JavaScript module, pyatv >= 0.6.0 must be #');
|
|
21
|
-
console.log('# installed. Unfortunately this could not be found. During #');
|
|
22
|
-
console.log('# the check following error message was reported: #');
|
|
23
|
-
console.log('#' + ' '.repeat(58) + '#');
|
|
24
|
-
console.log(
|
|
25
|
-
String(error)
|
|
26
|
-
.replace('Error: ', '')
|
|
27
|
-
.replace(/(.{1,54})/g, '$1\n')
|
|
28
|
-
.split('\n')
|
|
29
|
-
.map(l => l.trim())
|
|
30
|
-
.filter(l => Boolean(l))
|
|
31
|
-
.map(l => `# > ${l}${' '.repeat(55 - l.length)}#`)
|
|
32
|
-
.join('\n')
|
|
33
|
-
);
|
|
34
|
-
console.log('#' + ' '.repeat(58) + '#');
|
|
35
|
-
console.log('# You can probably find more information here: #');
|
|
36
|
-
console.log('# https://github.com/sebbo2002/node-pyatv #');
|
|
37
|
-
console.log('#' + ' '.repeat(58) + '#');
|
|
38
|
-
console.log('#'.repeat(60));
|
|
39
|
-
console.log('');
|
|
40
|
-
}
|
|
41
|
-
})();
|
package/src/examples/push.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// import pyatv, {NodePyATVDeviceEvent} from '@sebbo2002/node-pyatv';
|
|
4
|
-
import pyatv, {NodePyATVDeviceEvent} from '../lib/index.js';
|
|
5
|
-
|
|
6
|
-
(async () => {
|
|
7
|
-
const devices = await pyatv.find(/*{debug: true}*/);
|
|
8
|
-
if (!devices.length) {
|
|
9
|
-
throw new Error('Oh no. Unable to find any devices. If you find devices with atvremote, please enable the debug log.');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
console.log(`🔍 Found ${devices.length} device${devices.length > 1 ? 's' : ''}:`);
|
|
13
|
-
if(devices.length > 1) {
|
|
14
|
-
for (const i in devices) {
|
|
15
|
-
const device = devices[i];
|
|
16
|
-
console.log(` - ${device.name} (${device.host})`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const device = devices.find(d => d.name === 'Wohnzimmer') || devices[0];
|
|
21
|
-
console.log(`\n⚡️ Subscribe to live events on ${device.name} (press any key to stop)`);
|
|
22
|
-
await new Promise((resolve, reject) => {
|
|
23
|
-
const errorListener = (error: NodePyATVDeviceEvent | Error) => reject(error);
|
|
24
|
-
const updateListener = (event: NodePyATVDeviceEvent | Error) => {
|
|
25
|
-
if(event instanceof Error || event.key === 'dateTime') return;
|
|
26
|
-
console.log(` ${event.key}: ${event?.value} (was ${event?.oldValue})`);
|
|
27
|
-
};
|
|
28
|
-
const keyPressListener = () => {
|
|
29
|
-
console.log('\n⏳ Remove event listeners…');
|
|
30
|
-
device.off('update', updateListener);
|
|
31
|
-
device.off('error', errorListener);
|
|
32
|
-
process.stdin.off('data', keyPressListener);
|
|
33
|
-
resolve(undefined);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
device.on('update', updateListener);
|
|
37
|
-
device.on('error', errorListener);
|
|
38
|
-
process.stdin.on('data', keyPressListener);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
console.log('🎉 Thank you');
|
|
42
|
-
process.exit(0);
|
|
43
|
-
})().catch(error => {
|
|
44
|
-
console.log(`🚨 Error: ${error.stack || error}`);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
});
|
package/src/lib/device-event.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import {NodePyATVDevice} from '../lib/index.js';
|
|
4
|
-
import type {NodePyATVEventValueType, NodePyATVStateIndex} from './types.js';
|
|
5
|
-
|
|
6
|
-
export default class NodePyATVDeviceEvent {
|
|
7
|
-
protected readonly values: {key: NodePyATVStateIndex, old: NodePyATVEventValueType, new: NodePyATVEventValueType, device: NodePyATVDevice};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param values
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
constructor(values: {key: NodePyATVStateIndex, old: NodePyATVEventValueType, new: NodePyATVEventValueType, device: NodePyATVDevice}) {
|
|
15
|
-
this.values = Object.assign({}, values, {
|
|
16
|
-
key: values.key as NodePyATVStateIndex
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* References the attribute name which was changed. So if the
|
|
22
|
-
* title has been updated, this would be `title`.
|
|
23
|
-
*/
|
|
24
|
-
get key(): NodePyATVStateIndex {
|
|
25
|
-
return this.values.key;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Holds the old value which was there
|
|
30
|
-
* before the value was changed.
|
|
31
|
-
*/
|
|
32
|
-
get oldValue(): NodePyATVEventValueType {
|
|
33
|
-
return this.values.old;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @alias value
|
|
38
|
-
*/
|
|
39
|
-
get newValue(): NodePyATVEventValueType {
|
|
40
|
-
return this.values.new;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* New, current value for `key`
|
|
45
|
-
*/
|
|
46
|
-
get value(): NodePyATVEventValueType {
|
|
47
|
-
return this.values.new;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* References the device instance this
|
|
52
|
-
* event originates from
|
|
53
|
-
*/
|
|
54
|
-
get device(): NodePyATVDevice {
|
|
55
|
-
return this.values.device;
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/lib/device-events.ts
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
NodePyATVDeviceOptions,
|
|
5
|
-
NodePyATVExecutableType,
|
|
6
|
-
NodePyATVInternalState,
|
|
7
|
-
NodePyATVListenerState,
|
|
8
|
-
NodePyATVState,
|
|
9
|
-
NodePyATVStateIndex
|
|
10
|
-
} from './types.js';
|
|
11
|
-
import {ChildProcess} from 'child_process';
|
|
12
|
-
|
|
13
|
-
import {EventEmitter} from 'events';
|
|
14
|
-
import {NodePyATVDevice, NodePyATVDeviceEvent} from '../lib/index.js';
|
|
15
|
-
import {addRequestId, debug, execute, getParamters, parseState, removeRequestId} from './tools.js';
|
|
16
|
-
import {FakeChildProcess} from './fake-spawn.js';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
export default class NodePyATVDeviceEvents extends EventEmitter {
|
|
22
|
-
private readonly options: NodePyATVDeviceOptions;
|
|
23
|
-
private readonly state: NodePyATVState;
|
|
24
|
-
private readonly device: NodePyATVDevice;
|
|
25
|
-
private pyatv: ChildProcess | FakeChildProcess | undefined;
|
|
26
|
-
private timeout: NodeJS.Timeout | undefined;
|
|
27
|
-
private listenerState: NodePyATVListenerState;
|
|
28
|
-
|
|
29
|
-
constructor(state: NodePyATVState, device: NodePyATVDevice, options: NodePyATVDeviceOptions) {
|
|
30
|
-
super();
|
|
31
|
-
|
|
32
|
-
this.state = state;
|
|
33
|
-
this.device = device;
|
|
34
|
-
this.options = Object.assign({}, options);
|
|
35
|
-
this.listenerState = NodePyATVListenerState.stopped;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
applyStateAndEmitEvents(newState: NodePyATVState): void {
|
|
39
|
-
Object.keys(this.state).forEach((key: string) => {
|
|
40
|
-
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
const oldValue = this.state[key];
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
const newValue = newState[key];
|
|
46
|
-
|
|
47
|
-
if(oldValue === undefined || newValue === undefined || oldValue === newValue) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const event = new NodePyATVDeviceEvent({
|
|
52
|
-
key: key as NodePyATVStateIndex,
|
|
53
|
-
old: oldValue,
|
|
54
|
-
new: newValue,
|
|
55
|
-
device: this.device
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
this.state[key] = newState[key];
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
this.emit('update:' + key, event);
|
|
63
|
-
this.emit('update', event);
|
|
64
|
-
}
|
|
65
|
-
catch(error) {
|
|
66
|
-
this.emit('error', error);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private parsePushUpdate(reqId: string, data: string): void {
|
|
72
|
-
let json: NodePyATVInternalState;
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
json = JSON.parse(data);
|
|
76
|
-
}
|
|
77
|
-
catch(error) {
|
|
78
|
-
const msg = `Unable to parse stdout json: ${error}`;
|
|
79
|
-
debug(reqId, msg, this.options);
|
|
80
|
-
this.emit('error', new Error(msg));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.applyPushUpdate(json, reqId);
|
|
85
|
-
|
|
86
|
-
if(this.listenerState === NodePyATVListenerState.starting) {
|
|
87
|
-
this.listenerState = NodePyATVListenerState.started;
|
|
88
|
-
this.checkListener();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private applyPushUpdate(update: NodePyATVInternalState, reqId: string): void {
|
|
93
|
-
try {
|
|
94
|
-
const newState = parseState(update, reqId, this.options);
|
|
95
|
-
this.applyStateAndEmitEvents(newState);
|
|
96
|
-
}
|
|
97
|
-
catch(error) {
|
|
98
|
-
this.emit('error', error);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private checkListener(): void {
|
|
103
|
-
if(this.listenerState === NodePyATVListenerState.stopped && this.listenerCount() === 0 && this.timeout) {
|
|
104
|
-
clearTimeout(this.timeout);
|
|
105
|
-
this.timeout = undefined;
|
|
106
|
-
}
|
|
107
|
-
else if(this.listenerState === NodePyATVListenerState.stopped && this.listenerCount() > 0) {
|
|
108
|
-
const id = addRequestId();
|
|
109
|
-
debug(id, `Start listeing to events from device ${this.options.name}`, this.options);
|
|
110
|
-
|
|
111
|
-
this.startListening(id);
|
|
112
|
-
removeRequestId(id);
|
|
113
|
-
}
|
|
114
|
-
else if(
|
|
115
|
-
[NodePyATVListenerState.starting, NodePyATVListenerState.started].includes(this.listenerState) &&
|
|
116
|
-
this.listenerCount() === 0
|
|
117
|
-
) {
|
|
118
|
-
const id = addRequestId();
|
|
119
|
-
debug(id, `Stop listening to events from device ${this.options.name}`, this.options);
|
|
120
|
-
|
|
121
|
-
this.stopListening(id)
|
|
122
|
-
.catch(error => debug(id, `Unable to stop listeing: ${error}`, this.options))
|
|
123
|
-
.finally(() => removeRequestId(id));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private startListening(reqId: string): void {
|
|
128
|
-
if(this.listenerState !== NodePyATVListenerState.stopped) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.listenerState = NodePyATVListenerState.starting;
|
|
133
|
-
|
|
134
|
-
const listenStart = new Date().getTime();
|
|
135
|
-
const parameters = getParamters(this.options);
|
|
136
|
-
this.pyatv = execute(reqId, NodePyATVExecutableType.atvscript, [...parameters, 'push_updates'], this.options);
|
|
137
|
-
if(!this.pyatv) {
|
|
138
|
-
throw new Error('Unable to start listener: Unable to start atvscript');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const onError = (error: Error) => {
|
|
142
|
-
debug(reqId, `Got error from child process: ${error}`, this.options);
|
|
143
|
-
this.emit('error', error);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
147
|
-
const onStdErr = (data: any) => {
|
|
148
|
-
const error = new Error(`Got stderr output from pyatv: ${data}`);
|
|
149
|
-
debug(reqId, data.toString(), this.options);
|
|
150
|
-
this.emit('error', error);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
-
const onStdOut = (data: any) => {
|
|
155
|
-
String(data)
|
|
156
|
-
.split('\n')
|
|
157
|
-
.map(s => s.trim())
|
|
158
|
-
.filter(Boolean)
|
|
159
|
-
.forEach(s => this.parsePushUpdate(reqId, s));
|
|
160
|
-
};
|
|
161
|
-
const onClose = (code: number) => {
|
|
162
|
-
if(this.pyatv === undefined) {
|
|
163
|
-
// this should never happen… :/
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this.listenerState = NodePyATVListenerState.stopped;
|
|
168
|
-
debug(reqId, `Listening with atvscript exited with code ${code}`, this.options);
|
|
169
|
-
if(this.timeout !== undefined) {
|
|
170
|
-
clearTimeout(this.timeout);
|
|
171
|
-
this.timeout = undefined;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (this.pyatv.stdout) {
|
|
175
|
-
this.pyatv.stdout.off('data', onStdOut);
|
|
176
|
-
}
|
|
177
|
-
if (this.pyatv.stderr) {
|
|
178
|
-
this.pyatv.stderr.off('data', onStdErr);
|
|
179
|
-
}
|
|
180
|
-
this.pyatv.off('error', onError);
|
|
181
|
-
this.pyatv.off('close', onClose);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if(this.listenerCount() > 0 && new Date().getTime() - listenStart < 30000) {
|
|
185
|
-
debug(reqId, `Wait 15s and restart listeing to events from device ${this.options.name}`, this.options);
|
|
186
|
-
|
|
187
|
-
this.timeout = setTimeout(() => {
|
|
188
|
-
this.checkListener();
|
|
189
|
-
}, 15000);
|
|
190
|
-
}
|
|
191
|
-
else if(this.listenerCount() > 0) {
|
|
192
|
-
debug(reqId, `Restart listeing to events from device ${this.options.name}`, this.options);
|
|
193
|
-
this.checkListener();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
removeRequestId(reqId);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
this.pyatv.on('error', onError);
|
|
200
|
-
this.pyatv.on('close', onClose);
|
|
201
|
-
|
|
202
|
-
if (this.pyatv.stdout) {
|
|
203
|
-
this.pyatv.stdout.on('data', onStdOut);
|
|
204
|
-
}
|
|
205
|
-
if (this.pyatv.stderr) {
|
|
206
|
-
this.pyatv.stderr.on('data', onStdErr);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
protected async stopListening(reqId: string): Promise<void> {
|
|
211
|
-
if(
|
|
212
|
-
this.listenerState !== NodePyATVListenerState.starting &&
|
|
213
|
-
this.listenerState !== NodePyATVListenerState.started
|
|
214
|
-
) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
this.listenerState = NodePyATVListenerState.stopping;
|
|
219
|
-
if(this.pyatv === undefined) {
|
|
220
|
-
throw new Error(
|
|
221
|
-
'Unable to stop listening due to internal error: state is stopping, but there\'s no child process. ' +
|
|
222
|
-
'This should never happen, please report this.'
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if(this.pyatv.stdin) {
|
|
227
|
-
debug(reqId, 'Pressing enter to close atvscript…', this.options);
|
|
228
|
-
this.pyatv.stdin.write('\n');
|
|
229
|
-
|
|
230
|
-
await new Promise(cb => this.timeout = setTimeout(cb, 250));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if(this.listenerState === NodePyATVListenerState.stopping && this.pyatv) {
|
|
234
|
-
this.pyatv.kill();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
this.listenerState = NodePyATVListenerState.stopped;
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
|
|
242
|
-
super.addListener(event, listener);
|
|
243
|
-
this.checkListener();
|
|
244
|
-
return this;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
on(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
|
|
248
|
-
super.on(event, listener);
|
|
249
|
-
this.checkListener();
|
|
250
|
-
return this;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
once(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
|
|
254
|
-
super.once(event, (event: NodePyATVDeviceEvent) => {
|
|
255
|
-
listener(event);
|
|
256
|
-
setTimeout(() => this.checkListener(), 0);
|
|
257
|
-
});
|
|
258
|
-
this.checkListener();
|
|
259
|
-
return this;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
prependListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
|
|
263
|
-
super.prependListener(event, listener);
|
|
264
|
-
this.checkListener();
|
|
265
|
-
return this;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
off(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
|
|
269
|
-
super.off(event, listener);
|
|
270
|
-
this.checkListener();
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
removeAllListeners(event?: string | symbol): this {
|
|
275
|
-
super.removeAllListeners(event);
|
|
276
|
-
this.checkListener();
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this {
|
|
281
|
-
super.removeListener(event, listener);
|
|
282
|
-
this.checkListener();
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
listenerCount(event?: string | symbol): number {
|
|
287
|
-
if(event !== undefined) {
|
|
288
|
-
return super.listenerCount(event);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return this.eventNames()
|
|
292
|
-
.map(event => this.listenerCount(event))
|
|
293
|
-
.reduce((a, b) => a + b, 0);
|
|
294
|
-
}
|
|
295
|
-
}
|