homebridge-xbox-tv 2.7.6 → 2.7.7-beta.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.
- package/index.js +81 -93
- 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,7 +129,6 @@ 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
|
|
|
@@ -315,35 +313,24 @@ class XBOXDEVICE {
|
|
|
315
313
|
debugLog: this.enableDebugMode
|
|
316
314
|
});
|
|
317
315
|
|
|
318
|
-
this.xboxWebApi.on('
|
|
319
|
-
this.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
this.informationService
|
|
324
|
-
.setCharacteristic(Characteristic.Model, consoleType)
|
|
325
|
-
};
|
|
316
|
+
this.xboxWebApi.on('consoleStatus', (consoleStatusData, consoleType) => {
|
|
317
|
+
if (this.informationService) {
|
|
318
|
+
this.informationService
|
|
319
|
+
.setCharacteristic(Characteristic.Model, consoleType)
|
|
320
|
+
};
|
|
326
321
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
322
|
+
//this.serialNumber = id;
|
|
323
|
+
this.modelName = consoleType;
|
|
324
|
+
//this.power = powerState;
|
|
325
|
+
//this.mediaState = playbackState;
|
|
331
326
|
|
|
332
|
-
|
|
333
|
-
|
|
327
|
+
const mqtt = this.mqttEnabled ? this.mqtt.send('Status', JSON.stringify(consoleStatusData, null, 2)) : false;
|
|
328
|
+
})
|
|
334
329
|
.on('consolesList', (consolesList) => {
|
|
335
330
|
const mqtt = this.mqttEnabled ? this.mqtt.send('Consoles List', JSON.stringify(consolesList, null, 2)) : false;
|
|
336
331
|
})
|
|
337
332
|
.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
|
-
};
|
|
333
|
+
this.inputs = [...CONSTANS.DefaultInputs, ...appsArray];
|
|
347
334
|
})
|
|
348
335
|
.on('storageDevices', (storageDevices) => {
|
|
349
336
|
const mqtt = this.mqttEnabled ? this.mqtt.send('Storages', JSON.stringify(storageDevices, null, 2)) : false;
|
|
@@ -430,7 +417,7 @@ class XBOXDEVICE {
|
|
|
430
417
|
const inputReference = this.inputsReference[inputIdentifier];
|
|
431
418
|
const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
|
|
432
419
|
|
|
433
|
-
switch (
|
|
420
|
+
switch (inputOneStoreProductId) {
|
|
434
421
|
case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
|
|
435
422
|
await this.xboxWebApi.launchDashboard();
|
|
436
423
|
break;
|
|
@@ -495,7 +482,7 @@ class XBOXDEVICE {
|
|
|
495
482
|
break;
|
|
496
483
|
};
|
|
497
484
|
|
|
498
|
-
|
|
485
|
+
await this.xboxWebApi.sendButtonPress(command);
|
|
499
486
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, Remote Key command successful: ${command}`);
|
|
500
487
|
} catch (error) {
|
|
501
488
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Remote Key command error: ${JSON.stringify(error, null, 2)}`);
|
|
@@ -541,7 +528,7 @@ class XBOXDEVICE {
|
|
|
541
528
|
};
|
|
542
529
|
|
|
543
530
|
const channelName = 'systemInput';
|
|
544
|
-
|
|
531
|
+
await this.xboxWebApi.sendButtonPress(command);
|
|
545
532
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command successful: ${command}`);
|
|
546
533
|
} catch (error) {
|
|
547
534
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command error: ${error}`);
|
|
@@ -568,7 +555,7 @@ class XBOXDEVICE {
|
|
|
568
555
|
break;
|
|
569
556
|
};
|
|
570
557
|
|
|
571
|
-
|
|
558
|
+
await this.xboxWebApi.sendButtonPress(command);
|
|
572
559
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Volume command successful: ${command}`);
|
|
573
560
|
} catch (error) {
|
|
574
561
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Volume command error: ${error}`);
|
|
@@ -596,7 +583,7 @@ class XBOXDEVICE {
|
|
|
596
583
|
})
|
|
597
584
|
.onSet(async (state) => {
|
|
598
585
|
try {
|
|
599
|
-
const toggleMute =
|
|
586
|
+
const toggleMute = state ? await this.xboxWebApi.mute() : await this.xboxWebApi.unmute();
|
|
600
587
|
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Mute successful: ${state ? 'ON' : 'OFF'}`);
|
|
601
588
|
} catch (error) {
|
|
602
589
|
this.log.error(`Device: ${this.host} ${accessoryName}, set Mute error: ${error}`);
|
|
@@ -616,7 +603,7 @@ class XBOXDEVICE {
|
|
|
616
603
|
return volume;
|
|
617
604
|
})
|
|
618
605
|
.onSet(async (volume) => {
|
|
619
|
-
|
|
606
|
+
this.speakerService.setCharacteristic(Characteristic.Volume, volume);
|
|
620
607
|
});
|
|
621
608
|
this.volumeService.getCharacteristic(Characteristic.On)
|
|
622
609
|
.onGet(async () => {
|
|
@@ -624,7 +611,7 @@ class XBOXDEVICE {
|
|
|
624
611
|
return state;
|
|
625
612
|
})
|
|
626
613
|
.onSet(async (state) => {
|
|
627
|
-
|
|
614
|
+
this.speakerService.setCharacteristic(Characteristic.Mute, !state);
|
|
628
615
|
});
|
|
629
616
|
|
|
630
617
|
accessory.addService(this.volumeService);
|
|
@@ -638,7 +625,7 @@ class XBOXDEVICE {
|
|
|
638
625
|
return volume;
|
|
639
626
|
})
|
|
640
627
|
.onSet(async (volume) => {
|
|
641
|
-
|
|
628
|
+
this.speakerService.setCharacteristic(Characteristic.Volume, volume);
|
|
642
629
|
});
|
|
643
630
|
this.volumeServiceFan.getCharacteristic(Characteristic.On)
|
|
644
631
|
.onGet(async () => {
|
|
@@ -646,7 +633,7 @@ class XBOXDEVICE {
|
|
|
646
633
|
return state;
|
|
647
634
|
})
|
|
648
635
|
.onSet(async (state) => {
|
|
649
|
-
|
|
636
|
+
this.speakerService.setCharacteristic(Characteristic.Mute, !state);
|
|
650
637
|
});
|
|
651
638
|
|
|
652
639
|
accessory.addService(this.volumeServiceFan);
|
|
@@ -689,10 +676,6 @@ class XBOXDEVICE {
|
|
|
689
676
|
|
|
690
677
|
//Prepare inputs services
|
|
691
678
|
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
679
|
const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
|
|
697
680
|
const debug1 = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, read saved Inputs names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
|
|
698
681
|
|
|
@@ -701,7 +684,7 @@ class XBOXDEVICE {
|
|
|
701
684
|
|
|
702
685
|
//check possible inputs and filter custom unnecessary inputs
|
|
703
686
|
const filteredInputsArr = [];
|
|
704
|
-
for (const input of
|
|
687
|
+
for (const input of this.inputs) {
|
|
705
688
|
const contentType = input.contentType;
|
|
706
689
|
const filterGames = this.filterGames ? (contentType === 'Game') : false;
|
|
707
690
|
const filterApps = this.filterApps ? (contentType === 'App') : false;
|
|
@@ -719,13 +702,13 @@ class XBOXDEVICE {
|
|
|
719
702
|
const input = inputs[i];
|
|
720
703
|
|
|
721
704
|
//get title Id
|
|
722
|
-
const inputTitleId = input.titleId
|
|
705
|
+
const inputTitleId = input.titleId;
|
|
723
706
|
|
|
724
707
|
//get input reference
|
|
725
|
-
const inputReference = input.reference
|
|
708
|
+
const inputReference = input.reference;
|
|
726
709
|
|
|
727
710
|
//get input oneStoreProductId
|
|
728
|
-
const inputOneStoreProductId =
|
|
711
|
+
const inputOneStoreProductId = input.oneStoreProductId;
|
|
729
712
|
|
|
730
713
|
//get input name
|
|
731
714
|
const inputName = savedInputsNames[inputTitleId] ? savedInputsNames[inputTitleId] : savedInputsNames[inputReference] ? savedInputsNames[inputReference] : savedInputsNames[inputOneStoreProductId] ? savedInputsNames[inputOneStoreProductId] : input.name;
|
|
@@ -740,58 +723,63 @@ class XBOXDEVICE {
|
|
|
740
723
|
const currentVisibility = savedInputsTargetVisibility[inputTitleId] ? savedInputsTargetVisibility[inputTitleId] : savedInputsTargetVisibility[inputReference] ? savedInputsTargetVisibility[inputReference] : savedInputsTargetVisibility[inputOneStoreProductId] ? savedInputsTargetVisibility[inputOneStoreProductId] : 0;
|
|
741
724
|
const targetVisibility = currentVisibility;
|
|
742
725
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
726
|
+
if (inputReference && inputName) {
|
|
727
|
+
const inputService = new Service.InputSource(inputName, `Input ${i}`);
|
|
728
|
+
inputService
|
|
729
|
+
.setCharacteristic(Characteristic.Identifier, i)
|
|
730
|
+
.setCharacteristic(Characteristic.Name, inputName)
|
|
731
|
+
.setCharacteristic(Characteristic.IsConfigured, isConfigured)
|
|
732
|
+
.setCharacteristic(Characteristic.InputSourceType, inputType)
|
|
733
|
+
.setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
|
|
750
734
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
735
|
+
inputService.getCharacteristic(Characteristic.ConfiguredName)
|
|
736
|
+
.onGet(async () => {
|
|
737
|
+
return inputName;
|
|
738
|
+
})
|
|
739
|
+
.onSet(async (name) => {
|
|
740
|
+
try {
|
|
741
|
+
const nameIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
|
|
742
|
+
savedInputsNames[nameIdentifier] = name;
|
|
743
|
+
|
|
744
|
+
const newCustomName = JSON.stringify(savedInputsNames, null, 2);
|
|
745
|
+
await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
|
|
746
|
+
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved new Input name: ${name}, one store product id: ${inputOneStoreProductId}`) : false;
|
|
747
|
+
inputService.setCharacteristic(Characteristic.Name, inputName);
|
|
748
|
+
} catch (error) {
|
|
749
|
+
this.log.error(`Device: ${this.host} ${accessoryName}, new Input name save error: ${error}`);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
768
752
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
753
|
+
inputService
|
|
754
|
+
.getCharacteristic(Characteristic.TargetVisibilityState)
|
|
755
|
+
.onGet(async () => {
|
|
756
|
+
return targetVisibility;
|
|
757
|
+
})
|
|
758
|
+
.onSet(async (state) => {
|
|
759
|
+
try {
|
|
760
|
+
const targetVisibilityIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
|
|
761
|
+
savedInputsTargetVisibility[targetVisibilityIdentifier] = state;
|
|
762
|
+
|
|
763
|
+
const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
|
|
764
|
+
await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
|
|
765
|
+
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved new Input: ${inputName} target visibility state: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
|
|
766
|
+
inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
|
|
767
|
+
} catch (error) {
|
|
768
|
+
this.log.error(`Device: ${this.host} ${accessoryName}, new target visibility state save error: ${error}`);
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
this.inputsTitleId.push(inputTitleId);
|
|
773
|
+
this.inputsReference.push(inputReference);
|
|
774
|
+
this.inputsOneStoreProductId.push(inputOneStoreProductId);
|
|
775
|
+
this.inputsName.push(inputName);
|
|
787
776
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
777
|
+
this.televisionService.addLinkedService(inputService);
|
|
778
|
+
accessory.addService(inputService);
|
|
779
|
+
} else {
|
|
780
|
+
this.log(`Device: ${this.host} ${accessoryName}, ${!inputName ? 'name: Missing' : 'name: OK'}, ${!inputReference ? 'reference: Missing' : 'reference: OK'}, check your Inputs config!!!`);
|
|
792
781
|
|
|
793
|
-
|
|
794
|
-
accessory.addService(inputService);
|
|
782
|
+
};
|
|
795
783
|
}
|
|
796
784
|
|
|
797
785
|
//prepare sonsor service
|
|
@@ -852,7 +840,7 @@ class XBOXDEVICE {
|
|
|
852
840
|
const buttonCommand = button.command || 'Not set';
|
|
853
841
|
|
|
854
842
|
//get button inputOneStoreProductId
|
|
855
|
-
const buttonOneStoreProductId =
|
|
843
|
+
const buttonOneStoreProductId = button.oneStoreProductId || 'Not set';
|
|
856
844
|
|
|
857
845
|
//get button display type
|
|
858
846
|
const buttonDisplayType = button.displayType >= 0 ? button.displayType : -1;
|
|
@@ -868,7 +856,7 @@ class XBOXDEVICE {
|
|
|
868
856
|
})
|
|
869
857
|
.onSet(async (state) => {
|
|
870
858
|
try {
|
|
871
|
-
if (
|
|
859
|
+
if (state) {
|
|
872
860
|
//get button mode
|
|
873
861
|
let buttonMode = -1;
|
|
874
862
|
if (buttonCommand in CONSTANS.SystemMediaCommands) {
|
|
@@ -918,7 +906,7 @@ class XBOXDEVICE {
|
|
|
918
906
|
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, set button successful, name: ${buttonName}, command: ${buttonCommand}`) : false;
|
|
919
907
|
}
|
|
920
908
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
921
|
-
const setChar =
|
|
909
|
+
const setChar = state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
|
|
922
910
|
} catch (error) {
|
|
923
911
|
this.log.error(`Device: ${this.host} ${accessoryName}, set button error, name: ${buttonName}, error: ${error}`);
|
|
924
912
|
};
|
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.0",
|
|
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",
|