homebridge-xbox-tv 2.13.1 → 2.13.2
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/README.md +2 -2
- package/package.json +1 -1
- package/src/mqtt.js +45 -63
- package/src/xboxdevice.js +4 -4
package/README.md
CHANGED
|
@@ -144,8 +144,8 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
|
|
|
144
144
|
|
|
145
145
|
| Direction | Topic | Message | Payload Data |
|
|
146
146
|
| --- | --- | --- | --- |
|
|
147
|
-
| Publish | `Info`, `State`, `Consoles List`, `Profile`, `Apps`, `Storages`, `Status` | `{power: true, app: Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application}` | JSON object. |
|
|
148
|
-
| Subscribe | `Set` | `{Power: true}` | JSON object. |
|
|
147
|
+
| Publish | `Info`, `State`, `Consoles List`, `Profile`, `Apps`, `Storages`, `Status` | `{"power": true, "app": Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application}` | JSON object. |
|
|
148
|
+
| Subscribe | `Set` | `{"Power": true}` | JSON object. |
|
|
149
149
|
|
|
150
150
|
| Subscribe | Key | Value | Type | Description |
|
|
151
151
|
| --- | --- | --- | --- | --- |
|
package/package.json
CHANGED
package/src/mqtt.js
CHANGED
|
@@ -2,70 +2,52 @@
|
|
|
2
2
|
const AsyncMqtt = require("async-mqtt");
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class Mqtt extends EventEmitter {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
this.emit('
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.emit('error', `MQTT Subscribe error: ${error}`);
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
async send(topic, message) {
|
|
56
|
-
if (!this.isConnected) {
|
|
57
|
-
const debug = this.mqttDebug ? this.emit('debug', `MQTT client not connected.`) : false;
|
|
58
|
-
return
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const fullTopic = `${this.mqttPrefix}/${topic}`;
|
|
63
|
-
const publishMessage = JSON.stringify(message, null, 2);
|
|
64
|
-
await this.mqttClient.publish(fullTopic, publishMessage);
|
|
65
|
-
const debug = this.mqttDebug ? this.emit('debug', `MQTT publish: ${fullTopic}: ${publishMessage}`) : false;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
this.emit('error', `MQTT Publish error: ${error}`);
|
|
68
|
-
};
|
|
8
|
+
const options = {
|
|
9
|
+
clientId: config.clientId,
|
|
10
|
+
username: config.user,
|
|
11
|
+
password: config.passwd
|
|
12
|
+
}
|
|
13
|
+
const url = `mqtt://${config.host}:${config.port}`;
|
|
14
|
+
const subscribeTopic = `${config.prefix}/Set`;
|
|
15
|
+
|
|
16
|
+
this.on('connect', async () => {
|
|
17
|
+
try {
|
|
18
|
+
//connect
|
|
19
|
+
this.mqttClient = await AsyncMqtt.connectAsync(url, options);
|
|
20
|
+
this.emit('connected', 'MQTT Connected.');
|
|
21
|
+
|
|
22
|
+
//subscribe
|
|
23
|
+
await this.mqttClient.subscribe(subscribeTopic);
|
|
24
|
+
this.emit('subscribed', `MQTT Subscribe topic: ${subscribeTopic}.`);
|
|
25
|
+
|
|
26
|
+
//subscribed message
|
|
27
|
+
this.mqttClient.on('message', (topic, message) => {
|
|
28
|
+
try {
|
|
29
|
+
const subscribedMessage = JSON.parse(message.toString());
|
|
30
|
+
const emitDebug = config.debug ? this.emit('debug', `MQTT Received topic: ${topic}, message: ${JSON.stringify(subscribedMessage, null, 2)}`) : false;
|
|
31
|
+
this.emit('subscribedMessage', subscribedMessage);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
this.emit('error', `MQTT Parse message error: ${error}`);
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.emit('error', `MQTT Connect error: ${error}`);
|
|
38
|
+
};
|
|
39
|
+
}).on('publish', async (topic, message) => {
|
|
40
|
+
try {
|
|
41
|
+
const fullTopic = `${config.prefix}/${topic}`;
|
|
42
|
+
const publishMessage = JSON.stringify(message, null, 2);
|
|
43
|
+
await this.mqttClient.publish(fullTopic, publishMessage);
|
|
44
|
+
const emitDebug = config.debug ? this.emit('debug', `MQTT Publish topic: ${fullTopic}, message: ${publishMessage}`) : false;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
this.emit('error', `MQTT Publish error: ${error}`);
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
this.emit('connect');
|
|
69
51
|
};
|
|
70
52
|
};
|
|
71
|
-
module.exports =
|
|
53
|
+
module.exports = Mqtt;
|
package/src/xboxdevice.js
CHANGED
|
@@ -280,8 +280,8 @@ class XboxDevice extends EventEmitter {
|
|
|
280
280
|
});
|
|
281
281
|
|
|
282
282
|
this.restFul.on('connected', (message) => {
|
|
283
|
-
this.emit('message', message);
|
|
284
283
|
this.restFulConnected = true;
|
|
284
|
+
this.emit('message', message);
|
|
285
285
|
})
|
|
286
286
|
.on('error', (error) => {
|
|
287
287
|
this.emit('error', error);
|
|
@@ -305,8 +305,8 @@ class XboxDevice extends EventEmitter {
|
|
|
305
305
|
});
|
|
306
306
|
|
|
307
307
|
this.mqtt.on('connected', (message) => {
|
|
308
|
-
this.emit('message', message);
|
|
309
308
|
this.mqttConnected = true;
|
|
309
|
+
this.emit('message', message);
|
|
310
310
|
})
|
|
311
311
|
.on('changeState', async (data) => {
|
|
312
312
|
const key = Object.keys(data)[0];
|
|
@@ -368,7 +368,7 @@ class XboxDevice extends EventEmitter {
|
|
|
368
368
|
break;
|
|
369
369
|
};
|
|
370
370
|
} catch (error) {
|
|
371
|
-
this.emit('error', `
|
|
371
|
+
this.emit('error', `MQTT send error: ${error}.`);
|
|
372
372
|
};
|
|
373
373
|
})
|
|
374
374
|
.on('debug', (debug) => {
|
|
@@ -427,7 +427,7 @@ class XboxDevice extends EventEmitter {
|
|
|
427
427
|
const restFul = this.restFulConnected ? this.restFul.update(path, data) : false;
|
|
428
428
|
})
|
|
429
429
|
.on('mqtt', (topic, message) => {
|
|
430
|
-
const mqtt = this.mqttConnected ? this.mqtt.
|
|
430
|
+
const mqtt = this.mqttConnected ? this.mqtt.emit('publish', topic, message) : false;
|
|
431
431
|
});
|
|
432
432
|
}
|
|
433
433
|
|