homebridge-xbox-tv 3.1.13 → 3.1.15
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/package.json +1 -1
- package/src/xboxdevice.js +57 -53
package/package.json
CHANGED
package/src/xboxdevice.js
CHANGED
|
@@ -170,10 +170,10 @@ class XboxDevice extends EventEmitter {
|
|
|
170
170
|
this.emit('error', error);
|
|
171
171
|
})
|
|
172
172
|
.on('restFul', (path, data) => {
|
|
173
|
-
this.
|
|
173
|
+
const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
|
|
174
174
|
})
|
|
175
175
|
.on('mqtt', (topic, message) => {
|
|
176
|
-
this.emit('
|
|
176
|
+
const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
//check authorization
|
|
@@ -312,64 +312,68 @@ class XboxDevice extends EventEmitter {
|
|
|
312
312
|
try {
|
|
313
313
|
//RESTFul server
|
|
314
314
|
const restFulEnabled = this.restFul.enable || false;
|
|
315
|
-
if (restFulEnabled
|
|
316
|
-
this.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
this.restFul1.on('connected', (message) => {
|
|
322
|
-
this.restFulConnected = true;
|
|
323
|
-
this.emit('success', message);
|
|
324
|
-
})
|
|
325
|
-
.on('set', async (key, value) => {
|
|
326
|
-
try {
|
|
327
|
-
await this.setOverExternalIntegration('RESTFul', key, value);
|
|
328
|
-
} catch (error) {
|
|
329
|
-
this.emit('warn', `RESTFul set error: ${error}`);
|
|
330
|
-
};
|
|
331
|
-
})
|
|
332
|
-
.on('debug', (debug) => {
|
|
333
|
-
this.emit('debug', debug);
|
|
334
|
-
})
|
|
335
|
-
.on('error', (error) => {
|
|
336
|
-
this.emit('warn', error);
|
|
315
|
+
if (restFulEnabled) {
|
|
316
|
+
if (!this.restFulConnected) {
|
|
317
|
+
this.restFul1 = new RestFul({
|
|
318
|
+
port: this.restFul.port || 3000,
|
|
319
|
+
debug: this.restFul.debug || false
|
|
337
320
|
});
|
|
321
|
+
|
|
322
|
+
this.restFul1.on('connected', (message) => {
|
|
323
|
+
this.restFulConnected = true;
|
|
324
|
+
this.emit('success', message);
|
|
325
|
+
})
|
|
326
|
+
.on('set', async (key, value) => {
|
|
327
|
+
try {
|
|
328
|
+
await this.setOverExternalIntegration('RESTFul', key, value);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
this.emit('warn', `RESTFul set error: ${error}`);
|
|
331
|
+
};
|
|
332
|
+
})
|
|
333
|
+
.on('debug', (debug) => {
|
|
334
|
+
this.emit('debug', debug);
|
|
335
|
+
})
|
|
336
|
+
.on('error', (error) => {
|
|
337
|
+
this.emit('warn', error);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
338
340
|
}
|
|
339
341
|
|
|
340
342
|
//mqtt client
|
|
341
343
|
const mqttEnabled = this.mqtt.enable || false;
|
|
342
|
-
if (mqttEnabled
|
|
343
|
-
this.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
})
|
|
357
|
-
.on('subscribed', (message) => {
|
|
344
|
+
if (mqttEnabled) {
|
|
345
|
+
if (!this.mqttConnected) {
|
|
346
|
+
this.mqtt1 = new Mqtt({
|
|
347
|
+
host: this.mqtt.host,
|
|
348
|
+
port: this.mqtt.port || 1883,
|
|
349
|
+
clientId: this.mqtt.clientId || `xbox_${Math.random().toString(16).slice(3)}`,
|
|
350
|
+
prefix: `${this.mqtt.prefix}/${device.name}`,
|
|
351
|
+
user: this.mqtt.user,
|
|
352
|
+
passwd: this.mqtt.passwd,
|
|
353
|
+
debug: this.mqtt.debug || false
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
this.mqtt1.on('connected', (message) => {
|
|
357
|
+
this.mqttConnected = true;
|
|
358
358
|
this.emit('success', message);
|
|
359
359
|
})
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
360
|
+
.on('subscribed', (message) => {
|
|
361
|
+
this.emit('success', message);
|
|
362
|
+
})
|
|
363
|
+
.on('set', async (key, value) => {
|
|
364
|
+
try {
|
|
365
|
+
await this.setOverExternalIntegration('MQTT', key, value);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
this.emit('warn', `MQTT set error: ${error}.`);
|
|
368
|
+
};
|
|
369
|
+
})
|
|
370
|
+
.on('debug', (debug) => {
|
|
371
|
+
this.emit('debug', debug);
|
|
372
|
+
})
|
|
373
|
+
.on('error', (error) => {
|
|
374
|
+
this.emit('warn', error);
|
|
375
|
+
});
|
|
376
|
+
};
|
|
373
377
|
};
|
|
374
378
|
} catch (error) {
|
|
375
379
|
this.emit('warn', `External integration start error: ${error.message || error}.`);
|