homebridge-xbox-tv 2.7.6 → 2.7.7-beta.1
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/index.js +81 -97
- package/package.json +1 -1
- package/src/webApi/xboxwebapi.js +8 -2
package/index.js
CHANGED
|
@@ -107,7 +107,6 @@ class XBOXDEVICE {
|
|
|
107
107
|
this.firmwareRevision = 'Firmware Revision';
|
|
108
108
|
|
|
109
109
|
//setup variables
|
|
110
|
-
this.webApiEnabled = false;
|
|
111
110
|
this.firstRun = true;
|
|
112
111
|
|
|
113
112
|
this.inputsReference = [];
|
|
@@ -130,12 +129,10 @@ class XBOXDEVICE {
|
|
|
130
129
|
|
|
131
130
|
this.prefDir = path.join(api.user.storagePath(), 'xboxTv');
|
|
132
131
|
this.authTokenFile = `${this.prefDir}/authToken_${this.host.split('.').join('')}`;
|
|
133
|
-
this.inputsFile = `${this.prefDir}/inputs_${this.host.split('.').join('')}`;
|
|
134
132
|
this.inputsNamesFile = `${this.prefDir}/inputsNames_${this.host.split('.').join('')}`;
|
|
135
133
|
this.inputsTargetVisibilityFile = `${this.prefDir}/inputsTargetVisibility_${this.host.split('.').join('')}`;
|
|
136
134
|
|
|
137
135
|
const object = JSON.stringify({});
|
|
138
|
-
const array = JSON.stringify([]);
|
|
139
136
|
//check if the directory exists, if not then create it
|
|
140
137
|
if (!fs.existsSync(this.prefDir)) {
|
|
141
138
|
fs.mkdirSync(this.prefDir);
|
|
@@ -143,9 +140,6 @@ class XBOXDEVICE {
|
|
|
143
140
|
if (!fs.existsSync(this.authTokenFile)) {
|
|
144
141
|
fs.writeFileSync(this.authTokenFile, object);
|
|
145
142
|
}
|
|
146
|
-
if (!fs.existsSync(this.inputsFile)) {
|
|
147
|
-
fs.writeFileSync(this.inputsFile, array);
|
|
148
|
-
}
|
|
149
143
|
if (!fs.existsSync(this.inputsNamesFile)) {
|
|
150
144
|
fs.writeFileSync(this.inputsNamesFile, object);
|
|
151
145
|
}
|
|
@@ -315,35 +309,24 @@ class XBOXDEVICE {
|
|
|
315
309
|
debugLog: this.enableDebugMode
|
|
316
310
|
});
|
|
317
311
|
|
|
318
|
-
this.xboxWebApi.on('
|
|
319
|
-
this.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
this.informationService
|
|
324
|
-
.setCharacteristic(Characteristic.Model, consoleType)
|
|
325
|
-
};
|
|
312
|
+
this.xboxWebApi.on('consoleStatus', (consoleStatusData, consoleType) => {
|
|
313
|
+
if (this.informationService) {
|
|
314
|
+
this.informationService
|
|
315
|
+
.setCharacteristic(Characteristic.Model, consoleType)
|
|
316
|
+
};
|
|
326
317
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
318
|
+
//this.serialNumber = id;
|
|
319
|
+
this.modelName = consoleType;
|
|
320
|
+
//this.power = powerState;
|
|
321
|
+
//this.mediaState = playbackState;
|
|
331
322
|
|
|
332
|
-
|
|
333
|
-
|
|
323
|
+
const mqtt = this.mqttEnabled ? this.mqtt.send('Status', JSON.stringify(consoleStatusData, null, 2)) : false;
|
|
324
|
+
})
|
|
334
325
|
.on('consolesList', (consolesList) => {
|
|
335
326
|
const mqtt = this.mqttEnabled ? this.mqtt.send('Consoles List', JSON.stringify(consolesList, null, 2)) : false;
|
|
336
327
|
})
|
|
337
328
|
.on('appsList', async (appsArray) => {
|
|
338
|
-
|
|
339
|
-
const apps = JSON.stringify([...CONSTANS.DefaultInputs, ...appsArray], null, 2);
|
|
340
|
-
await fsPromises.writeFile(this.inputsFile, apps);
|
|
341
|
-
const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, saved apps: ${apps}`) : false;
|
|
342
|
-
|
|
343
|
-
const mqtt = this.mqttEnabled ? this.mqtt.send('Apps', JSON.stringify(apps, null, 2)) : false;
|
|
344
|
-
} catch (error) {
|
|
345
|
-
this.log.error(`Device: ${this.host} ${this.name}, save apps error: ${error}`);
|
|
346
|
-
};
|
|
329
|
+
this.inputs = [...CONSTANS.DefaultInputs, ...appsArray];
|
|
347
330
|
})
|
|
348
331
|
.on('storageDevices', (storageDevices) => {
|
|
349
332
|
const mqtt = this.mqttEnabled ? this.mqtt.send('Storages', JSON.stringify(storageDevices, null, 2)) : false;
|
|
@@ -430,7 +413,7 @@ class XBOXDEVICE {
|
|
|
430
413
|
const inputReference = this.inputsReference[inputIdentifier];
|
|
431
414
|
const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
|
|
432
415
|
|
|
433
|
-
switch (
|
|
416
|
+
switch (inputOneStoreProductId) {
|
|
434
417
|
case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
|
|
435
418
|
await this.xboxWebApi.launchDashboard();
|
|
436
419
|
break;
|
|
@@ -495,7 +478,7 @@ class XBOXDEVICE {
|
|
|
495
478
|
break;
|
|
496
479
|
};
|
|
497
480
|
|
|
498
|
-
|
|
481
|
+
await this.xboxWebApi.sendButtonPress(command);
|
|
499
482
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, Remote Key command successful: ${command}`);
|
|
500
483
|
} catch (error) {
|
|
501
484
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Remote Key command error: ${JSON.stringify(error, null, 2)}`);
|
|
@@ -541,7 +524,7 @@ class XBOXDEVICE {
|
|
|
541
524
|
};
|
|
542
525
|
|
|
543
526
|
const channelName = 'systemInput';
|
|
544
|
-
|
|
527
|
+
await this.xboxWebApi.sendButtonPress(command);
|
|
545
528
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command successful: ${command}`);
|
|
546
529
|
} catch (error) {
|
|
547
530
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command error: ${error}`);
|
|
@@ -568,7 +551,7 @@ class XBOXDEVICE {
|
|
|
568
551
|
break;
|
|
569
552
|
};
|
|
570
553
|
|
|
571
|
-
|
|
554
|
+
await this.xboxWebApi.sendButtonPress(command);
|
|
572
555
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Volume command successful: ${command}`);
|
|
573
556
|
} catch (error) {
|
|
574
557
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Volume command error: ${error}`);
|
|
@@ -596,7 +579,7 @@ class XBOXDEVICE {
|
|
|
596
579
|
})
|
|
597
580
|
.onSet(async (state) => {
|
|
598
581
|
try {
|
|
599
|
-
const toggleMute =
|
|
582
|
+
const toggleMute = state ? await this.xboxWebApi.mute() : await this.xboxWebApi.unmute();
|
|
600
583
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Mute successful: ${state ? 'ON' : 'OFF'}`);
|
|
601
584
|
} catch (error) {
|
|
602
585
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Mute error: ${error}`);
|
|
@@ -616,7 +599,7 @@ class XBOXDEVICE {
|
|
|
616
599
|
return volume;
|
|
617
600
|
})
|
|
618
601
|
.onSet(async (volume) => {
|
|
619
|
-
|
|
602
|
+
this.speakerService.setCharacteristic(Characteristic.Volume, volume);
|
|
620
603
|
});
|
|
621
604
|
this.volumeService.getCharacteristic(Characteristic.On)
|
|
622
605
|
.onGet(async () => {
|
|
@@ -624,7 +607,7 @@ class XBOXDEVICE {
|
|
|
624
607
|
return state;
|
|
625
608
|
})
|
|
626
609
|
.onSet(async (state) => {
|
|
627
|
-
|
|
610
|
+
this.speakerService.setCharacteristic(Characteristic.Mute, !state);
|
|
628
611
|
});
|
|
629
612
|
|
|
630
613
|
accessory.addService(this.volumeService);
|
|
@@ -638,7 +621,7 @@ class XBOXDEVICE {
|
|
|
638
621
|
return volume;
|
|
639
622
|
})
|
|
640
623
|
.onSet(async (volume) => {
|
|
641
|
-
|
|
624
|
+
this.speakerService.setCharacteristic(Characteristic.Volume, volume);
|
|
642
625
|
});
|
|
643
626
|
this.volumeServiceFan.getCharacteristic(Characteristic.On)
|
|
644
627
|
.onGet(async () => {
|
|
@@ -646,7 +629,7 @@ class XBOXDEVICE {
|
|
|
646
629
|
return state;
|
|
647
630
|
})
|
|
648
631
|
.onSet(async (state) => {
|
|
649
|
-
|
|
632
|
+
this.speakerService.setCharacteristic(Characteristic.Mute, !state);
|
|
650
633
|
});
|
|
651
634
|
|
|
652
635
|
accessory.addService(this.volumeServiceFan);
|
|
@@ -689,10 +672,6 @@ class XBOXDEVICE {
|
|
|
689
672
|
|
|
690
673
|
//Prepare inputs services
|
|
691
674
|
this.log.debug('prepareInputServices');
|
|
692
|
-
|
|
693
|
-
const savedInputs = this.getInputsFromDevice ? fs.readFileSync(this.inputsFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsFile)) : this.inputs : this.inputs;
|
|
694
|
-
const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, read saved Inputs: ${JSON.stringify(savedInputs, null, 2)}`) : false;
|
|
695
|
-
|
|
696
675
|
const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
|
|
697
676
|
const debug1 = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, read saved Inputs names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
|
|
698
677
|
|
|
@@ -701,7 +680,7 @@ class XBOXDEVICE {
|
|
|
701
680
|
|
|
702
681
|
//check possible inputs and filter custom unnecessary inputs
|
|
703
682
|
const filteredInputsArr = [];
|
|
704
|
-
for (const input of
|
|
683
|
+
for (const input of this.inputs) {
|
|
705
684
|
const contentType = input.contentType;
|
|
706
685
|
const filterGames = this.filterGames ? (contentType === 'Game') : false;
|
|
707
686
|
const filterApps = this.filterApps ? (contentType === 'App') : false;
|
|
@@ -719,13 +698,13 @@ class XBOXDEVICE {
|
|
|
719
698
|
const input = inputs[i];
|
|
720
699
|
|
|
721
700
|
//get title Id
|
|
722
|
-
const inputTitleId = input.titleId
|
|
701
|
+
const inputTitleId = input.titleId;
|
|
723
702
|
|
|
724
703
|
//get input reference
|
|
725
|
-
const inputReference = input.reference
|
|
704
|
+
const inputReference = input.reference;
|
|
726
705
|
|
|
727
706
|
//get input oneStoreProductId
|
|
728
|
-
const inputOneStoreProductId =
|
|
707
|
+
const inputOneStoreProductId = input.oneStoreProductId;
|
|
729
708
|
|
|
730
709
|
//get input name
|
|
731
710
|
const inputName = savedInputsNames[inputTitleId] ? savedInputsNames[inputTitleId] : savedInputsNames[inputReference] ? savedInputsNames[inputReference] : savedInputsNames[inputOneStoreProductId] ? savedInputsNames[inputOneStoreProductId] : input.name;
|
|
@@ -740,58 +719,63 @@ class XBOXDEVICE {
|
|
|
740
719
|
const currentVisibility = savedInputsTargetVisibility[inputTitleId] ? savedInputsTargetVisibility[inputTitleId] : savedInputsTargetVisibility[inputReference] ? savedInputsTargetVisibility[inputReference] : savedInputsTargetVisibility[inputOneStoreProductId] ? savedInputsTargetVisibility[inputOneStoreProductId] : 0;
|
|
741
720
|
const targetVisibility = currentVisibility;
|
|
742
721
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
722
|
+
if (inputReference && inputName) {
|
|
723
|
+
const inputService = new Service.InputSource(inputName, `Input ${i}`);
|
|
724
|
+
inputService
|
|
725
|
+
.setCharacteristic(Characteristic.Identifier, i)
|
|
726
|
+
.setCharacteristic(Characteristic.Name, inputName)
|
|
727
|
+
.setCharacteristic(Characteristic.IsConfigured, isConfigured)
|
|
728
|
+
.setCharacteristic(Characteristic.InputSourceType, inputType)
|
|
729
|
+
.setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
|
|
750
730
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
731
|
+
inputService.getCharacteristic(Characteristic.ConfiguredName)
|
|
732
|
+
.onGet(async () => {
|
|
733
|
+
return inputName;
|
|
734
|
+
})
|
|
735
|
+
.onSet(async (name) => {
|
|
736
|
+
try {
|
|
737
|
+
const nameIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
|
|
738
|
+
savedInputsNames[nameIdentifier] = name;
|
|
739
|
+
|
|
740
|
+
const newCustomName = JSON.stringify(savedInputsNames, null, 2);
|
|
741
|
+
await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
|
|
742
|
+
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved new Input name: ${name}, one store product id: ${inputOneStoreProductId}`) : false;
|
|
743
|
+
inputService.setCharacteristic(Characteristic.Name, inputName);
|
|
744
|
+
} catch (error) {
|
|
745
|
+
this.log.error(`Device: ${this.host} ${accessoryName}, new Input name save error: ${error}`);
|
|
746
|
+
}
|
|
747
|
+
});
|
|
768
748
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
749
|
+
inputService
|
|
750
|
+
.getCharacteristic(Characteristic.TargetVisibilityState)
|
|
751
|
+
.onGet(async () => {
|
|
752
|
+
return targetVisibility;
|
|
753
|
+
})
|
|
754
|
+
.onSet(async (state) => {
|
|
755
|
+
try {
|
|
756
|
+
const targetVisibilityIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
|
|
757
|
+
savedInputsTargetVisibility[targetVisibilityIdentifier] = state;
|
|
758
|
+
|
|
759
|
+
const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
|
|
760
|
+
await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
|
|
761
|
+
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved new Input: ${inputName} target visibility state: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
|
|
762
|
+
inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
|
|
763
|
+
} catch (error) {
|
|
764
|
+
this.log.error(`Device: ${this.host} ${accessoryName}, new target visibility state save error: ${error}`);
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
this.inputsTitleId.push(inputTitleId);
|
|
769
|
+
this.inputsReference.push(inputReference);
|
|
770
|
+
this.inputsOneStoreProductId.push(inputOneStoreProductId);
|
|
771
|
+
this.inputsName.push(inputName);
|
|
787
772
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
773
|
+
this.televisionService.addLinkedService(inputService);
|
|
774
|
+
accessory.addService(inputService);
|
|
775
|
+
} else {
|
|
776
|
+
this.log(`Device: ${this.host} ${accessoryName}, ${!inputName ? 'name: Missing' : 'name: OK'}, ${!inputReference ? 'reference: Missing' : 'reference: OK'}, check your Inputs config!!!`);
|
|
792
777
|
|
|
793
|
-
|
|
794
|
-
accessory.addService(inputService);
|
|
778
|
+
};
|
|
795
779
|
}
|
|
796
780
|
|
|
797
781
|
//prepare sonsor service
|
|
@@ -852,7 +836,7 @@ class XBOXDEVICE {
|
|
|
852
836
|
const buttonCommand = button.command || 'Not set';
|
|
853
837
|
|
|
854
838
|
//get button inputOneStoreProductId
|
|
855
|
-
const buttonOneStoreProductId =
|
|
839
|
+
const buttonOneStoreProductId = button.oneStoreProductId || 'Not set';
|
|
856
840
|
|
|
857
841
|
//get button display type
|
|
858
842
|
const buttonDisplayType = button.displayType >= 0 ? button.displayType : -1;
|
|
@@ -868,7 +852,7 @@ class XBOXDEVICE {
|
|
|
868
852
|
})
|
|
869
853
|
.onSet(async (state) => {
|
|
870
854
|
try {
|
|
871
|
-
if (
|
|
855
|
+
if (state) {
|
|
872
856
|
//get button mode
|
|
873
857
|
let buttonMode = -1;
|
|
874
858
|
if (buttonCommand in CONSTANS.SystemMediaCommands) {
|
|
@@ -918,7 +902,7 @@ class XBOXDEVICE {
|
|
|
918
902
|
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, set button successful, name: ${buttonName}, command: ${buttonCommand}`) : false;
|
|
919
903
|
}
|
|
920
904
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
921
|
-
const setChar =
|
|
905
|
+
const setChar = state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
|
|
922
906
|
} catch (error) {
|
|
923
907
|
this.log.error(`Device: ${this.host} ${accessoryName}, set button error, name: ${buttonName}, error: ${error}`);
|
|
924
908
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Xbox TV",
|
|
3
3
|
"name": "homebridge-xbox-tv",
|
|
4
|
-
"version": "2.7.
|
|
4
|
+
"version": "2.7.7-beta.1",
|
|
5
5
|
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
package/src/webApi/xboxwebapi.js
CHANGED
|
@@ -50,12 +50,13 @@ class XBOXWEBAPI extends EventEmitter {
|
|
|
50
50
|
try {
|
|
51
51
|
const authorized = await this.authentication.isAuthenticated();
|
|
52
52
|
if (!authorized) {
|
|
53
|
-
this.emit(`message', 'not authorized, please use authorization manager first
|
|
53
|
+
this.emit(`message', 'not authorized, please use authorization manager first.`)
|
|
54
|
+
this.auhorized = false;
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
try {
|
|
58
|
-
this.
|
|
59
|
+
this.auhorized = true;
|
|
59
60
|
this.headers = {
|
|
60
61
|
'Authorization': (this.userToken !== '' && this.uhs !== '') ? `XBL3.0 x=${this.uhs};${this.userToken}` : `XBL3.0 x=${this.authentication.user.uhs};${this.authentication.tokens.xsts.Token}`,
|
|
61
62
|
'Accept-Language': 'en-US',
|
|
@@ -478,6 +479,11 @@ class XBOXWEBAPI extends EventEmitter {
|
|
|
478
479
|
send(commandType, command, params) {
|
|
479
480
|
return new Promise(async (resolve, reject) => {
|
|
480
481
|
try {
|
|
482
|
+
if (!this.auhorized) {
|
|
483
|
+
reject('not authorized.');
|
|
484
|
+
return;
|
|
485
|
+
};
|
|
486
|
+
|
|
481
487
|
const sessionid = Uuid4();
|
|
482
488
|
const postParams = {
|
|
483
489
|
"destination": "Xbox",
|