homebridge-xbox-tv 2.8.4-beta.8 → 2.8.4
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 +23 -23
- package/config.schema.json +6 -6
- package/homebridge-ui/public/index.html +31 -36
- package/homebridge-ui/server.js +9 -26
- package/index.js +9 -9
- package/package.json +1 -1
- package/src/localApi/xboxlocalapi.js +3 -3
- package/src/webApi/authentication.js +11 -11
- package/src/webApi/xboxwebapi.js +5 -6
package/README.md
CHANGED
|
@@ -71,17 +71,7 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
|
|
|
71
71
|
| `name` | Here set the accessory *Name* to be displayed in *Homebridge/HomeKit*. |
|
|
72
72
|
| `host` | Here set the *Hsostname or Address IP* of Console.|
|
|
73
73
|
| `xboxLiveId` | On your console select Profile > Settings > System > Console info, listed as **Xbox network device ID**. *You can only find the Xbox network device ID in Settings on your console, this is different from your console serial number*. |
|
|
74
|
-
| `clientId` | If You create app on Azure AD then You can use your own Client Id. |
|
|
75
|
-
| `clientSecret` | If You create app on Azure AD then You can use own Client Secret. |
|
|
76
|
-
| `userToken` | Alternate authorization method. |
|
|
77
|
-
| `userUhs` | Alternate authorization method. |
|
|
78
74
|
| `webApiControl` | If enabled, the console can be controlled using Web Api and additional functions are available in `Advanced Settings` section. |
|
|
79
|
-
| `xboxWebApiToken` | Required if `webApiControl` enabled. |
|
|
80
|
-
| `disableLogInfo` | If enabled, disable log info, all values and state will not be displayed in Homebridge log console. |
|
|
81
|
-
| `disableLogDeviceInfo` | If enabled, add ability to disable log device info by every connections device to the network. |
|
|
82
|
-
| `enableDebugMode` | If enabled, deep log will be present in homebridge console. |
|
|
83
|
-
| `volumeControl` | Here choice what a additional volume control mode You want to use (`None/Disabled`, `Lightbulb`, `Fan`), not working yet. |
|
|
84
|
-
| `infoButtonCommand` | Here select the function of `I` button in RC app. |
|
|
85
75
|
| `getInputsFromDevice`| If enabled, apps will be loaded from device, only available if `webApiControl` enabled. |
|
|
86
76
|
| `filterGames` | If enabled, Games will be hidden and not displayed in the inputs list, only available if `webApiControl` enabled. |
|
|
87
77
|
| `filterApps` | If enabled, Apps will be hidden and not displayed in the inputs list, only available if `webApiControl` enabled. |
|
|
@@ -93,26 +83,36 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
|
|
|
93
83
|
| `inputs.contentType` | Here select from available content types. |
|
|
94
84
|
| `buttons.name` | Here set *Button Name* which You want expose to the *Homebridge/HomeKit*. |
|
|
95
85
|
| `buttons.command` | Here select button control mode or command, `Reboot` and `Switch App/Game`- only possible if `webApiControl` enabled. |
|
|
96
|
-
| `buttons.oneStoreProductId` | Here set *Input oneStoreProductId*, only possible if `webApiControl` enabled
|
|
97
|
-
| `buttons.displayType` | Here select display type in HomeKit app, possible `None/Disabled`, `Outlet`, `Switch
|
|
86
|
+
| `buttons.oneStoreProductId` | Here set *Input oneStoreProductId*, only possible if `webApiControl` enabled. |
|
|
87
|
+
| `buttons.displayType` | Here select display type in HomeKit app, possible `None/Disabled`, `Outlet`, `Switch`. |
|
|
98
88
|
| `sensorPower`| If enabled, then the Power will be exposed as a `Motion Sensor` (active on Power ON) to use with automations. |
|
|
99
89
|
| `sensorInput`| If enabled, then the Input will be exposed as a `Motion Sensor` (active on every Input change) to use with automations. |
|
|
100
90
|
| `sensorScreenSaver`| If enabled, then the Screen Saver will be exposed as a `Motion Sensor` (active on change to Screen Saver) to use with automations. |
|
|
101
91
|
| `sensorInputs.name` | Here set own *Name* which You want expose to the *Homebridge/HomeKit* for this sensor. |
|
|
102
92
|
| `sensorInputs.reference` | Here set *Reference* like `Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application` to be exposed as sensor (active on switch to this Input). |
|
|
103
93
|
| `sensorInputs.displayType` | Here select sensor type to be exposed in HomeKit app, possible `None/Disabled`, `Motion Sensor`, `Occupancy Sensor`, `Contact Sensor`. |
|
|
94
|
+
| `xboxWebApiToken` | Required if `webApiControl` enabled. |
|
|
95
|
+
| `clientId` | If You create app on Azure AD then You can use your own Client Id. |
|
|
96
|
+
| `clientSecret` | If You create app on Azure AD then You can use own Client Secret. |
|
|
97
|
+
| `userToken` | Alternate authorization method. |
|
|
98
|
+
| `userHash` | Alternate authorization method. |
|
|
99
|
+
| `enableDebugMode` | If enabled, deep log will be present in homebridge console. |
|
|
100
|
+
| `disableLogInfo` | If enabled, disable log info, all values and state will not be displayed in Homebridge log console. |
|
|
101
|
+
| `disableLogDeviceInfo` | If enabled, add ability to disable log device info by every connections device to the network. |
|
|
102
|
+
| `infoButtonCommand` | Here select the function of `I` button in RC app. |
|
|
103
|
+
| `volumeControl` | Here choice what a additional volume control mode You want to use (`None/Disabled`, `Lightbulb`, `Fan`), not working yet. |
|
|
104
104
|
| `enableMqtt` | If enabled, MQTT Broker will start automatically and publish all awailable PV installation data. |
|
|
105
|
-
| `mqttHost` | Here set the *IP Address* or *Hostname* for MQTT Broker.
|
|
106
|
-
| `mqttPort` | Here set the *Port* for MQTT Broker, default 1883.
|
|
107
|
-
| `mqttPrefix` | Here set the *Prefix* for *Topic* or leave empty.
|
|
105
|
+
| `mqttHost` | Here set the *IP Address* or *Hostname* for MQTT Broker. |
|
|
106
|
+
| `mqttPort` | Here set the *Port* for MQTT Broker, default 1883. |
|
|
107
|
+
| `mqttPrefix` | Here set the *Prefix* for *Topic* or leave empty. |
|
|
108
108
|
| `mqttAuth` | If enabled, MQTT Broker will use authorization credentials. |
|
|
109
109
|
| `mqttUser` | Here set the MQTT Broker user. |
|
|
110
110
|
| `mqttPasswd` | Here set the MQTT Broker password. |
|
|
111
111
|
| `mqttDebug` | If enabled, deep log will be present in homebridge console for MQTT. |
|
|
112
112
|
| `reference`, `oneStoreProductId` | If web Api enabled then all available in `./homebridge/xboxTv/inputs_xxxxxx` file. |
|
|
113
|
-
| `Volume Control` | -1 - `None/Disabled`, 0 - `Slider`, 1 - `Fan
|
|
114
|
-
| `Display Type Inputs/Buttons` | -1 - `None/Disabled`, 0 - `Outlet`, 1 - `Switch
|
|
115
|
-
| `Display Type Sensors` | -1 - `None/Disabled`, 0 - `Motion Sensor`, 1 - `Occupancy Sensor`, 2 - `Contact Sensor
|
|
113
|
+
| `Volume Control` | -1 - `None/Disabled`, 0 - `Slider`, 1 - `Fan`. |
|
|
114
|
+
| `Display Type Inputs/Buttons` | -1 - `None/Disabled`, 0 - `Outlet`, 1 - `Switch`. |
|
|
115
|
+
| `Display Type Sensors` | -1 - `None/Disabled`, 0 - `Motion Sensor`, 1 - `Occupancy Sensor`, 2 - `Contact Sensor`. |
|
|
116
116
|
|
|
117
117
|
*Example Config:
|
|
118
118
|
|
|
@@ -125,11 +125,6 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
|
|
|
125
125
|
"host": "192.168.1.6",
|
|
126
126
|
"xboxLiveId": "FD0000000000",
|
|
127
127
|
"webApiControl": false,
|
|
128
|
-
"clientId": "",
|
|
129
|
-
"clientSecret": "",
|
|
130
|
-
"userToken": "",
|
|
131
|
-
"userUhs": "",
|
|
132
|
-
"xboxWebApiToken": "",
|
|
133
128
|
"getInputsFromDevice": false,
|
|
134
129
|
"filterGames": false,
|
|
135
130
|
"filterApps": false,
|
|
@@ -182,6 +177,11 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
|
|
|
182
177
|
"displayType": -1
|
|
183
178
|
}
|
|
184
179
|
],
|
|
180
|
+
"xboxWebApiToken": "",
|
|
181
|
+
"clientId": "",
|
|
182
|
+
"clientSecret": "",
|
|
183
|
+
"userToken": "",
|
|
184
|
+
"userHash": "",
|
|
185
185
|
"enableDebugMode": false,
|
|
186
186
|
"disableLogInfo": false,
|
|
187
187
|
"disableLogDeviceInfo": false,
|
package/config.schema.json
CHANGED
|
@@ -484,7 +484,7 @@
|
|
|
484
484
|
"title": "Xbox Live User",
|
|
485
485
|
"type": "string",
|
|
486
486
|
"placeholder": "abcdefg@hotmail.com",
|
|
487
|
-
"description": "Here set user for your Xbox Live account.",
|
|
487
|
+
"description": "Here set user for your Xbox Live account, not used at this time.",
|
|
488
488
|
"required": true,
|
|
489
489
|
"condition": {
|
|
490
490
|
"functionBody": "return model.devices[arrayIndices].webApiControl === true;"
|
|
@@ -494,7 +494,7 @@
|
|
|
494
494
|
"title": "Xbox Live Password",
|
|
495
495
|
"type": "string",
|
|
496
496
|
"placeholder": "abcdefg@hotmail.com",
|
|
497
|
-
"description": "Here set password
|
|
497
|
+
"description": "Here set password for your Xbox Live account, not used at this time.",
|
|
498
498
|
"required": true,
|
|
499
499
|
"condition": {
|
|
500
500
|
"functionBody": "return model.devices[arrayIndices].webApiControl === true;"
|
|
@@ -514,7 +514,7 @@
|
|
|
514
514
|
"title": "Client ID",
|
|
515
515
|
"type": "string",
|
|
516
516
|
"placeholder": "a34ac209-edab-4b08-91e7-a4558d8da1bd",
|
|
517
|
-
"description": "Here set your own Client ID
|
|
517
|
+
"description": "Here set your own Client ID from Azure AD, leave empty if you do not have own account.",
|
|
518
518
|
"required": false,
|
|
519
519
|
"condition": {
|
|
520
520
|
"functionBody": "return model.devices[arrayIndices].webApiControl === true;"
|
|
@@ -524,7 +524,7 @@
|
|
|
524
524
|
"title": "Client Secret",
|
|
525
525
|
"type": "string",
|
|
526
526
|
"placeholder": "Client Secret",
|
|
527
|
-
"description": "
|
|
527
|
+
"description": "Here set your Client Secret from Azure AD to use with API uthorization, leave empty if you do not have own account.",
|
|
528
528
|
"required": false,
|
|
529
529
|
"condition": {
|
|
530
530
|
"functionBody": "return model.devices[arrayIndices].webApiControl === true;"
|
|
@@ -540,7 +540,7 @@
|
|
|
540
540
|
"functionBody": "return model.devices[arrayIndices].webApiControl === true;"
|
|
541
541
|
}
|
|
542
542
|
},
|
|
543
|
-
"
|
|
543
|
+
"userHash": {
|
|
544
544
|
"title": "User Hash",
|
|
545
545
|
"type": "string",
|
|
546
546
|
"placeholder": "User Hash",
|
|
@@ -832,7 +832,7 @@
|
|
|
832
832
|
"devices[].clientId",
|
|
833
833
|
"devices[].clientSecret",
|
|
834
834
|
"devices[].userToken",
|
|
835
|
-
"devices[].
|
|
835
|
+
"devices[].userHash"
|
|
836
836
|
]
|
|
837
837
|
},
|
|
838
838
|
{
|
|
@@ -5,22 +5,17 @@
|
|
|
5
5
|
<form id="configForm">
|
|
6
6
|
<div class="text-center">
|
|
7
7
|
<label id="deviceName" style="font-size: 23px">Xbox</label><br>
|
|
8
|
-
|
|
9
|
-
<div class="text-center">
|
|
10
|
-
<div class="text-center">
|
|
11
|
-
<label id="info" style="text-align: center; font-size: 17px; color: white;">Authorization
|
|
12
|
-
Manager</label><br><br>
|
|
13
|
-
</div>
|
|
8
|
+
<label id="info" style="text-align: center; font-size: 17px; color: white;">Authorization Manager</label><br><br>
|
|
14
9
|
</div>
|
|
15
10
|
<div class="form-group">
|
|
16
11
|
<label for="deviceHost">Host</label>
|
|
17
|
-
<input type="text" class="form-control"
|
|
12
|
+
<input id="deviceHost" type="text" class="form-control"><br>
|
|
18
13
|
<label for="deviceLiveId">Xbox Live ID</label>
|
|
19
|
-
<input type="text" class="form-control"
|
|
14
|
+
<input id="deviceLiveId" type="text" class="form-control"><br>
|
|
20
15
|
<label for="deviceToken">Web Api Token</label>
|
|
21
|
-
<input type="text" class="form-control"
|
|
16
|
+
<input id="deviceToken" type="text" class="form-control"><br>
|
|
22
17
|
<label for="deviceWebApiControl">Web Api Control</label>
|
|
23
|
-
<input type="checkbox" class="form-control"
|
|
18
|
+
<input id="deviceWebApiControl" type="checkbox" class="form-control">
|
|
24
19
|
</div>
|
|
25
20
|
<div class="text-center">
|
|
26
21
|
<button id="startAuthorizationButton" type="button" class="btn btn-primary">Start authorization</button>
|
|
@@ -42,15 +37,10 @@
|
|
|
42
37
|
return;
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
//load form
|
|
46
|
-
document.getElementById('authorizationManager').style.display = 'block';
|
|
47
|
-
|
|
48
40
|
//get devices count
|
|
49
41
|
const devicesCount = pluginConfig[0].devices.length;
|
|
50
|
-
|
|
51
|
-
//get the intial from the config and add it to the form
|
|
52
42
|
for (let i = 0; i < devicesCount; i++) {
|
|
53
|
-
//create
|
|
43
|
+
//create buttons
|
|
54
44
|
const button = document.createElement("button");
|
|
55
45
|
button.setAttribute("type", "button");
|
|
56
46
|
button.setAttribute("id", `button${i}`);
|
|
@@ -62,11 +52,11 @@
|
|
|
62
52
|
|
|
63
53
|
//get actuall value on console select
|
|
64
54
|
document.getElementById(`button${i}`).addEventListener('click', async () => {
|
|
65
|
-
document.
|
|
66
|
-
document.
|
|
67
|
-
document.
|
|
68
|
-
document.
|
|
69
|
-
document.
|
|
55
|
+
document.getElementById('deviceName').innerHTML = pluginConfig[0].devices[i].name || '';
|
|
56
|
+
document.getElementById('deviceHost').value = pluginConfig[0].devices[i].host || '';
|
|
57
|
+
document.getElementById('deviceLiveId').value = pluginConfig[0].devices[i].xboxLiveId || '';
|
|
58
|
+
document.getElementById('deviceToken').value = pluginConfig[0].devices[i].xboxWebApiToken || '';
|
|
59
|
+
document.getElementById('deviceWebApiControl').checked = pluginConfig[0].devices[i].webApiControl || false;
|
|
70
60
|
|
|
71
61
|
const tokenLength = (pluginConfig[0].devices[i].xboxWebApiToken).length || 0;
|
|
72
62
|
const setButtonName = tokenLength <= 10 ? document.getElementById('startAuthorizationButton').innerText = "Start authorization" : document.getElementById('startAuthorizationButton').innerText = "Check state";
|
|
@@ -79,6 +69,9 @@
|
|
|
79
69
|
const update = i === devicesCount - 1 ? await homebridge.updatePluginConfig(pluginConfig) : false;
|
|
80
70
|
};
|
|
81
71
|
|
|
72
|
+
//load authorizationManager form
|
|
73
|
+
document.getElementById('authorizationManager').style.display = 'block';
|
|
74
|
+
|
|
82
75
|
//watch for changes to the config button
|
|
83
76
|
document.getElementById('configButton').addEventListener('click', async () => {
|
|
84
77
|
const showHideSettings = this.configButtonState ? homebridge.hideSchemaForm() : homebridge.showSchemaForm();
|
|
@@ -104,10 +97,10 @@
|
|
|
104
97
|
document.getElementById('clearTokenButton').addEventListener('click', async () => {
|
|
105
98
|
try {
|
|
106
99
|
homebridge.showSpinner();
|
|
107
|
-
const host = pluginConfig[0].devices[this.deviceIndex].host
|
|
100
|
+
const host = pluginConfig[0].devices[this.deviceIndex].host;
|
|
108
101
|
const response = await homebridge.request('/clearToken', { host: host });
|
|
109
102
|
|
|
110
|
-
document.
|
|
103
|
+
document.getElementById('deviceToken').value = '';
|
|
111
104
|
document.getElementById('startAuthorizationButton').removeAttribute("disabled");
|
|
112
105
|
document.getElementById('startAuthorizationButton').innerText = "Start authorization";
|
|
113
106
|
document.getElementById('deviceWebApiControl').checked = false;
|
|
@@ -121,7 +114,7 @@
|
|
|
121
114
|
await homebridge.savePluginConfig(pluginConfig);
|
|
122
115
|
homebridge.hideSpinner();
|
|
123
116
|
} catch (e) {
|
|
124
|
-
homebridge.toast.error(`Clear Web Api Token error: ${
|
|
117
|
+
homebridge.toast.error(`Clear Web Api Token error: ${e.message}`);
|
|
125
118
|
} finally {
|
|
126
119
|
homebridge.hideSpinner();
|
|
127
120
|
};
|
|
@@ -133,14 +126,14 @@
|
|
|
133
126
|
homebridge.showSpinner();
|
|
134
127
|
await homebridge.updatePluginConfig(pluginConfig)
|
|
135
128
|
|
|
136
|
-
const host = pluginConfig[0].devices[this.deviceIndex].host
|
|
137
|
-
const xboxLiveUser = pluginConfig[0].devices[this.deviceIndex].xboxLiveUser
|
|
138
|
-
const xboxLivePasswd = pluginConfig[0].devices[this.deviceIndex].xboxLivePasswd
|
|
139
|
-
const clientId = pluginConfig[0].devices[this.deviceIndex].clientId
|
|
140
|
-
const clientSecret = pluginConfig[0].devices[this.deviceIndex].clientSecret
|
|
141
|
-
const userToken = pluginConfig[0].devices[this.deviceIndex].userToken
|
|
142
|
-
const
|
|
143
|
-
const xboxWebApiToken = pluginConfig[0].devices[this.deviceIndex].xboxWebApiToken
|
|
129
|
+
const host = pluginConfig[0].devices[this.deviceIndex].host;
|
|
130
|
+
const xboxLiveUser = pluginConfig[0].devices[this.deviceIndex].xboxLiveUser;
|
|
131
|
+
const xboxLivePasswd = pluginConfig[0].devices[this.deviceIndex].xboxLivePasswd;
|
|
132
|
+
const clientId = pluginConfig[0].devices[this.deviceIndex].clientId;
|
|
133
|
+
const clientSecret = pluginConfig[0].devices[this.deviceIndex].clientSecret;
|
|
134
|
+
const userToken = pluginConfig[0].devices[this.deviceIndex].userToken;
|
|
135
|
+
const userHash = pluginConfig[0].devices[this.deviceIndex].userHash;
|
|
136
|
+
const xboxWebApiToken = pluginConfig[0].devices[this.deviceIndex].xboxWebApiToken;
|
|
144
137
|
|
|
145
138
|
const payload = {
|
|
146
139
|
host: host,
|
|
@@ -149,12 +142,13 @@
|
|
|
149
142
|
clientId: clientId,
|
|
150
143
|
clientSecret: clientSecret,
|
|
151
144
|
userToken: userToken,
|
|
152
|
-
|
|
145
|
+
userHash: userHash,
|
|
153
146
|
webApiToken: xboxWebApiToken
|
|
154
147
|
};
|
|
155
148
|
const response = await homebridge.request('/startAuthorization', payload);
|
|
156
149
|
const info = response.info;
|
|
157
150
|
const status = response.status;
|
|
151
|
+
const error = response.error;
|
|
158
152
|
|
|
159
153
|
switch (status) {
|
|
160
154
|
case 0:
|
|
@@ -173,7 +167,7 @@
|
|
|
173
167
|
open(info);
|
|
174
168
|
|
|
175
169
|
homebridge.addEventListener('webApiToken', async (webApiToken) => {
|
|
176
|
-
document.
|
|
170
|
+
document.getElementById('deviceToken').value = webApiToken;
|
|
177
171
|
await homebridge.updatePluginConfig(pluginConfig)
|
|
178
172
|
await homebridge.savePluginConfig(pluginConfig);
|
|
179
173
|
});
|
|
@@ -190,7 +184,7 @@
|
|
|
190
184
|
await homebridge.savePluginConfig(pluginConfig);
|
|
191
185
|
break;
|
|
192
186
|
case 3:
|
|
193
|
-
document.getElementById('info').innerHTML = `Authorization error: ${JSON.stringify(
|
|
187
|
+
document.getElementById('info').innerHTML = `Authorization error: ${JSON.stringify(error, null, 2)}`;
|
|
194
188
|
document.getElementById('info').style.color = 'red';
|
|
195
189
|
document.getElementById('startAuthorizationButton').innerText = "Start authorization";
|
|
196
190
|
document.getElementById('deviceWebApiControl').checked = false;
|
|
@@ -203,10 +197,11 @@
|
|
|
203
197
|
};
|
|
204
198
|
|
|
205
199
|
} catch (e) {
|
|
206
|
-
homebridge.toast.error(`Data error: ${
|
|
200
|
+
homebridge.toast.error(`Data error: ${e.message}`);
|
|
207
201
|
} finally {
|
|
208
202
|
homebridge.hideSpinner();
|
|
209
203
|
};
|
|
210
204
|
});
|
|
205
|
+
|
|
211
206
|
})();
|
|
212
207
|
</script>
|
package/homebridge-ui/server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { HomebridgePluginUiServer, RequestError } = require('@homebridge/plugin-ui-utils');
|
|
4
|
-
const QueryString = require('querystring');
|
|
5
4
|
const Authentication = require('../src/webApi/authentication.js')
|
|
6
5
|
const fs = require('fs');
|
|
7
6
|
const fsPromises = fs.promises;
|
|
@@ -13,9 +12,6 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
13
12
|
//clear web api token
|
|
14
13
|
this.onRequest('/clearToken', this.clearToken.bind(this));
|
|
15
14
|
|
|
16
|
-
//query string
|
|
17
|
-
this.onRequest('/queryString', this.queryString.bind(this));
|
|
18
|
-
|
|
19
15
|
//start console authorization
|
|
20
16
|
this.onRequest('/startAuthorization', this.startAuthorization.bind(this));
|
|
21
17
|
|
|
@@ -30,20 +26,7 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
30
26
|
await fsPromises.writeFile(authTokenFile, JSON.stringify({}));
|
|
31
27
|
return true;
|
|
32
28
|
} catch (e) {
|
|
33
|
-
throw new RequestError(
|
|
34
|
-
message: e.message
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
async queryString(locationHash) {
|
|
40
|
-
try {
|
|
41
|
-
const urlParams = QueryString.parse(locationHash);
|
|
42
|
-
return urlParams;
|
|
43
|
-
} catch (e) {
|
|
44
|
-
throw new RequestError('Query string failed.', {
|
|
45
|
-
message: e.message
|
|
46
|
-
});
|
|
29
|
+
throw new RequestError(`Clear token error: ${e.message}`);
|
|
47
30
|
};
|
|
48
31
|
};
|
|
49
32
|
|
|
@@ -60,7 +43,7 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
60
43
|
clientId: payload.clientId,
|
|
61
44
|
clientSecret: payload.clientSecret,
|
|
62
45
|
userToken: payload.userToken,
|
|
63
|
-
|
|
46
|
+
userHash: payload.userHash,
|
|
64
47
|
tokensFile: authTokenFile
|
|
65
48
|
}
|
|
66
49
|
const authentication = new Authentication(authConfig);
|
|
@@ -81,8 +64,9 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
81
64
|
};
|
|
82
65
|
} catch (error) {
|
|
83
66
|
this.data = {
|
|
84
|
-
info:
|
|
85
|
-
status: 3
|
|
67
|
+
info: 'Error',
|
|
68
|
+
status: 3,
|
|
69
|
+
error: error
|
|
86
70
|
};
|
|
87
71
|
};
|
|
88
72
|
} else {
|
|
@@ -95,8 +79,9 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
95
79
|
};
|
|
96
80
|
} catch (error) {
|
|
97
81
|
this.data = {
|
|
98
|
-
info:
|
|
99
|
-
status: 3
|
|
82
|
+
info: 'Error',
|
|
83
|
+
status: 3,
|
|
84
|
+
error: error
|
|
100
85
|
};
|
|
101
86
|
};
|
|
102
87
|
};
|
|
@@ -104,9 +89,7 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
104
89
|
|
|
105
90
|
return this.data;
|
|
106
91
|
} catch (e) {
|
|
107
|
-
throw new RequestError(
|
|
108
|
-
message: e.message
|
|
109
|
-
});
|
|
92
|
+
throw new RequestError(`Authorization data error: ${e.message}`);
|
|
110
93
|
};
|
|
111
94
|
};
|
|
112
95
|
};
|
package/index.js
CHANGED
|
@@ -78,13 +78,13 @@ class XBOXDEVICE {
|
|
|
78
78
|
this.sensorInput = config.sensorInput || false;
|
|
79
79
|
this.sensorScreenSaver = config.sensorScreenSaver || false;
|
|
80
80
|
this.sensorInputs = config.sensorInputs || [];
|
|
81
|
-
this.xboxLiveUser = config.xboxLiveUser
|
|
82
|
-
this.xboxLivePasswd = config.xboxLivePasswd
|
|
83
|
-
this.xboxWebApiToken = config.xboxWebApiToken
|
|
84
|
-
this.clientId = config.clientId
|
|
85
|
-
this.clientSecret = config.clientSecret
|
|
86
|
-
this.userToken = config.userToken
|
|
87
|
-
this.
|
|
81
|
+
this.xboxLiveUser = config.xboxLiveUser;
|
|
82
|
+
this.xboxLivePasswd = config.xboxLivePasswd;
|
|
83
|
+
this.xboxWebApiToken = config.xboxWebApiToken;
|
|
84
|
+
this.clientId = config.clientId;
|
|
85
|
+
this.clientSecret = config.clientSecret;
|
|
86
|
+
this.userToken = config.userToken;
|
|
87
|
+
this.userHash = config.userHash;
|
|
88
88
|
this.enableDebugMode = config.enableDebugMode || false;
|
|
89
89
|
this.disableLogInfo = config.disableLogInfo || false;
|
|
90
90
|
this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
|
|
@@ -193,7 +193,7 @@ class XBOXDEVICE {
|
|
|
193
193
|
host: this.host,
|
|
194
194
|
xboxLiveId: this.xboxLiveId,
|
|
195
195
|
userToken: this.userToken,
|
|
196
|
-
|
|
196
|
+
userHash: this.userHash,
|
|
197
197
|
infoLog: this.disableLogInfo,
|
|
198
198
|
debugLog: this.enableDebugMode
|
|
199
199
|
});
|
|
@@ -317,7 +317,7 @@ class XBOXDEVICE {
|
|
|
317
317
|
clientId: this.clientId,
|
|
318
318
|
clientSecret: this.clientSecret,
|
|
319
319
|
userToken: this.userToken,
|
|
320
|
-
|
|
320
|
+
userHash: this.userHash,
|
|
321
321
|
tokensFile: this.authTokenFile,
|
|
322
322
|
debugLog: this.enableDebugMode
|
|
323
323
|
});
|
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.4
|
|
4
|
+
"version": "2.8.4",
|
|
5
5
|
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -17,7 +17,7 @@ class XBOXLOCALAPI extends EventEmitter {
|
|
|
17
17
|
this.port = config.dgramPort;
|
|
18
18
|
this.xboxLiveId = config.xboxLiveId;
|
|
19
19
|
this.userToken = config.userToken;
|
|
20
|
-
this.
|
|
20
|
+
this.userHash = config.userHash;
|
|
21
21
|
this.infoLog = config.infoLog;
|
|
22
22
|
this.debugLog = config.debugLog;
|
|
23
23
|
|
|
@@ -156,8 +156,8 @@ class XBOXLOCALAPI extends EventEmitter {
|
|
|
156
156
|
connectRequest.set('publicKey', this.crypto.getPublicKey());
|
|
157
157
|
connectRequest.set('iv', this.crypto.getIv());
|
|
158
158
|
|
|
159
|
-
if (this.
|
|
160
|
-
connectRequest.set('userHash', this.
|
|
159
|
+
if (this.userHash && this.userToken) {
|
|
160
|
+
connectRequest.set('userHash', this.userHash, true);
|
|
161
161
|
connectRequest.set('jwt', this.userToken, true);
|
|
162
162
|
this.isAuthorized = true;
|
|
163
163
|
}
|
|
@@ -14,7 +14,7 @@ class AUTHENTICATION {
|
|
|
14
14
|
this.clientId = config.clientId || 'a34ac209-edab-4b08-91e7-a4558d8da1bd';
|
|
15
15
|
this.clientSecret = config.clientSecret;
|
|
16
16
|
this.userToken = config.userToken;
|
|
17
|
-
this.
|
|
17
|
+
this.userHash = config.userHash;
|
|
18
18
|
this.tokensFile = config.tokensFile;
|
|
19
19
|
|
|
20
20
|
this.user = {
|
|
@@ -60,7 +60,7 @@ class AUTHENTICATION {
|
|
|
60
60
|
this.tokens.oauth = refreshToken;
|
|
61
61
|
await this.saveTokens(this.tokens);
|
|
62
62
|
|
|
63
|
-
const accessToken = await this.
|
|
63
|
+
const accessToken = await this.getUserToken(this.tokens.oauth.access_token);
|
|
64
64
|
this.tokens.user = accessToken;
|
|
65
65
|
this.tokens.xsts = {};
|
|
66
66
|
await this.saveTokens(this.tokens);
|
|
@@ -79,7 +79,7 @@ class AUTHENTICATION {
|
|
|
79
79
|
};
|
|
80
80
|
} else {
|
|
81
81
|
try {
|
|
82
|
-
const accessToken = await this.
|
|
82
|
+
const accessToken = await this.getUserToken(this.tokens.oauth.access_token);
|
|
83
83
|
this.tokens.user = accessToken;
|
|
84
84
|
this.tokens.xsts = {};
|
|
85
85
|
await this.saveTokens(this.tokens);
|
|
@@ -98,7 +98,7 @@ class AUTHENTICATION {
|
|
|
98
98
|
this.tokens.xsts = {};
|
|
99
99
|
await this.saveTokens(this.tokens);
|
|
100
100
|
|
|
101
|
-
const userToken = await this.
|
|
101
|
+
const userToken = await this.getXstsToken(this.tokens.user.Token);
|
|
102
102
|
this.tokens.xsts = userToken;
|
|
103
103
|
await this.saveTokens(this.tokens);
|
|
104
104
|
await this.refreshTokens('xsts');
|
|
@@ -118,7 +118,7 @@ class AUTHENTICATION {
|
|
|
118
118
|
};
|
|
119
119
|
} else {
|
|
120
120
|
try {
|
|
121
|
-
const userToken = await this.
|
|
121
|
+
const userToken = await this.getXstsToken(this.tokens.user.Token);
|
|
122
122
|
this.tokens.xsts = userToken;
|
|
123
123
|
await this.saveTokens(this.tokens);
|
|
124
124
|
|
|
@@ -149,7 +149,7 @@ class AUTHENTICATION {
|
|
|
149
149
|
"code": webApiToken,
|
|
150
150
|
"redirect_uri": 'http://localhost:8888/auth/callback'
|
|
151
151
|
}
|
|
152
|
-
const addClientSecret = this.clientSecret
|
|
152
|
+
const addClientSecret = this.clientSecret ? payload.client_secret = this.clientSecret : false;
|
|
153
153
|
|
|
154
154
|
const postData = QueryString.stringify(payload);
|
|
155
155
|
const url = 'https://login.live.com/oauth20_token.srf';
|
|
@@ -175,7 +175,7 @@ class AUTHENTICATION {
|
|
|
175
175
|
"scope": CONSTANS.Scopes.join(' '),
|
|
176
176
|
"refresh_token": refreshToken,
|
|
177
177
|
}
|
|
178
|
-
const addClientSecret = this.clientSecret
|
|
178
|
+
const addClientSecret = this.clientSecret ? payload.client_secret = this.clientSecret : false;
|
|
179
179
|
|
|
180
180
|
const postData = QueryString.stringify(payload);
|
|
181
181
|
const url = 'https://login.live.com/oauth20_token.srf';
|
|
@@ -190,7 +190,7 @@ class AUTHENTICATION {
|
|
|
190
190
|
})
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
getUserToken(accessToken) {
|
|
194
194
|
return new Promise(async (resolve, reject) => {
|
|
195
195
|
try {
|
|
196
196
|
const payload = {
|
|
@@ -215,7 +215,7 @@ class AUTHENTICATION {
|
|
|
215
215
|
})
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
getXstsToken(userToken) {
|
|
219
219
|
return new Promise(async (resolve, reject) => {
|
|
220
220
|
try {
|
|
221
221
|
const payload = {
|
|
@@ -247,10 +247,10 @@ class AUTHENTICATION {
|
|
|
247
247
|
this.tokens = JSON.parse(tokens);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
if (this.clientId
|
|
250
|
+
if (this.clientId) {
|
|
251
251
|
await this.refreshTokens();
|
|
252
252
|
resolve();
|
|
253
|
-
} else if (this.userToken
|
|
253
|
+
} else if (this.userToken && this.userHash) {
|
|
254
254
|
resolve();
|
|
255
255
|
} else {
|
|
256
256
|
reject(error);
|
package/src/webApi/xboxwebapi.js
CHANGED
|
@@ -16,7 +16,6 @@ const Titlehub = require('./providers/titlehub.js');
|
|
|
16
16
|
const UserPresence = require('./providers/userpresence.js');
|
|
17
17
|
const UserStats = require('./providers/userstats.js');
|
|
18
18
|
const CONSTANS = require('../constans.json');
|
|
19
|
-
|
|
20
19
|
class XBOXWEBAPI extends EventEmitter {
|
|
21
20
|
constructor(config) {
|
|
22
21
|
super();
|
|
@@ -24,16 +23,16 @@ class XBOXWEBAPI extends EventEmitter {
|
|
|
24
23
|
this.clientId = config.clientId;
|
|
25
24
|
this.clientSecret = config.clientSecret;
|
|
26
25
|
this.userToken = config.userToken;
|
|
27
|
-
this.
|
|
26
|
+
this.userHash = config.userHash;
|
|
28
27
|
this.debugLog = config.debugLog;
|
|
29
28
|
|
|
30
29
|
const authConfig = {
|
|
31
|
-
xboxLiveUser: xboxLiveUser,
|
|
32
|
-
xboxLivePasswd: xboxLivePasswd,
|
|
30
|
+
xboxLiveUser: config.xboxLiveUser,
|
|
31
|
+
xboxLivePasswd: config.xboxLivePasswd,
|
|
33
32
|
clientId: config.clientId,
|
|
34
33
|
clientSecret: config.clientSecret,
|
|
35
34
|
userToken: config.userToken,
|
|
36
|
-
|
|
35
|
+
userHash: config.userHash,
|
|
37
36
|
tokensFile: config.tokensFile
|
|
38
37
|
}
|
|
39
38
|
this.authentication = new Authentication(authConfig);
|
|
@@ -59,7 +58,7 @@ class XBOXWEBAPI extends EventEmitter {
|
|
|
59
58
|
try {
|
|
60
59
|
this.auhorized = true;
|
|
61
60
|
this.headers = {
|
|
62
|
-
'Authorization': (this.userToken
|
|
61
|
+
'Authorization': (this.userToken && this.userHash) ? `XBL3.0 x=${this.userHash};${this.userToken}` : `XBL3.0 x=${this.authentication.user.uhs};${this.authentication.tokens.xsts}`,
|
|
63
62
|
'Accept-Language': 'en-US',
|
|
64
63
|
'x-xbl-contract-version': '4',
|
|
65
64
|
'x-xbl-client-name': 'XboxApp',
|