homebridge-xbox-tv 2.8.21 → 2.8.22-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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "2.8.21",
4
+ "version": "2.8.22-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",
@@ -47,15 +47,15 @@ class XBOXWEBAPI extends EventEmitter {
47
47
  this.emit('stateChanged', false);
48
48
  });
49
49
 
50
- this.getAuthorizationState();
50
+ this.checkAuthorization();
51
51
  }
52
52
 
53
53
  async updateAuthorization() {
54
54
  await new Promise(resolve => setTimeout(resolve, 900000));
55
- this.getAuthorizationState();
55
+ this.checkAuthorization();
56
56
  };
57
57
 
58
- async getAuthorizationState() {
58
+ async checkAuthorization() {
59
59
  try {
60
60
  const tokens = this.userToken && this.userHash ? false : await this.authentication.checkAuthorization();
61
61
  const debug = this.debugLog ? this.emit('debug', `authorization tokens: ${JSON.stringify(tokens, null, 2)}`) : false;
@@ -72,6 +72,21 @@ class XBOXWEBAPI extends EventEmitter {
72
72
  this.tokens = tokens;
73
73
  this.authorized = true;
74
74
 
75
+ try {
76
+ await this.xboxLiveData();
77
+ } catch (error) {
78
+ this.emit('error', `xbox live data error: ${JSON.stringify(error, null, 2)}.`);
79
+ };
80
+
81
+ this.updateAuthorization();
82
+ } catch (error) {
83
+ this.emit('error', `check authorization state error: ${JSON.stringify(error, null, 2)}, recheck in 15min.`);
84
+ this.updateAuthorization();
85
+ };
86
+ };
87
+
88
+ xboxLiveData() {
89
+ return new Promise(async (resolve, reject) => {
75
90
  try {
76
91
  const rmEnabled = await this.consoleStatus();
77
92
  const debug1 = !rmEnabled ? this.emit('message', `remote management not enabled, please check your console settings.`) : false;
@@ -79,15 +94,11 @@ class XBOXWEBAPI extends EventEmitter {
79
94
  await this.installedApps();
80
95
  //await this.storageDevices();
81
96
  //await this.userProfile();
82
- this.updateAuthorization();
97
+ resolve();
83
98
  } catch (error) {
84
- this.emit('error', `web Api data error: ${JSON.stringify(error, null, 2)}, recheck in 15min.`)
85
- this.updateAuthorization();
99
+ reject(`Console: ${this.xboxLiveId}, get data error: ${JSON.stringify(error, null, 2)}`);
86
100
  };
87
- } catch (error) {
88
- this.emit('error', `check authorization state error: ${JSON.stringify(error, null, 2)}, recheck in 15min.`);
89
- this.updateAuthorization();
90
- };
101
+ });
91
102
  };
92
103
 
93
104
  consoleStatus() {