homebridge-xbox-tv 2.8.2-beta.2 → 2.8.2-beta.20
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/homebridge-ui/public/index.html +73 -95
- package/homebridge-ui/server.js +32 -14
- package/package.json +1 -1
|
@@ -1,38 +1,35 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<div class="text-center">
|
|
12
|
-
<div class="text-center">
|
|
13
|
-
<label id="info" style="text-align: center; font-size: 17px; color: white;">Authorization
|
|
14
|
-
Manager</label><br><br>
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
<div class="form-group">
|
|
18
|
-
<label for="deviceHostInput">Host</label>
|
|
19
|
-
<input type="text" class="form-control" id="deviceHostInput"><br>
|
|
20
|
-
<label for="deviceLiveId">Xbox Live ID</label>
|
|
21
|
-
<input type="text" class="form-control" id="deviceLiveId"><br>
|
|
22
|
-
<label for="deviceTokenInput">Web Api Token</label>
|
|
23
|
-
<input type="text" class="form-control" id="deviceTokenInput"><br>
|
|
24
|
-
<label for="deviceWebApiControl">Web Api Control</label>
|
|
25
|
-
<input type="checkbox" class="form-control" id="deviceWebApiControl">
|
|
26
|
-
</div>
|
|
1
|
+
<div>
|
|
2
|
+
<img src="homebridge-xbox-tv.png" style="text-align: center;" height="150" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<div id="authorizationManager" style="display: none;" class="card card-body">
|
|
6
|
+
<form id="configForm">
|
|
7
|
+
<div class="text-center">
|
|
8
|
+
<label id="deviceNameInput" style="font-size: 23px">Xbox</label><br>
|
|
9
|
+
</div>
|
|
10
|
+
<div class="text-center">
|
|
27
11
|
<div class="text-center">
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
<button id="clearTokenButton" type="button" class="btn btn-primary">Clear Web Api Token</button>
|
|
31
|
-
<button id="configButton" type="button" class="btn btn-primary"><i class="fas fa-gear"></i></button>
|
|
12
|
+
<label id="info" style="text-align: center; font-size: 17px; color: white;">Authorization
|
|
13
|
+
Manager</label><br><br>
|
|
32
14
|
</div>
|
|
33
|
-
</
|
|
34
|
-
|
|
35
|
-
</
|
|
15
|
+
</div>
|
|
16
|
+
<div class="form-group">
|
|
17
|
+
<label for="deviceHostInput">Host</label>
|
|
18
|
+
<input type="text" class="form-control" id="deviceHostInput"><br>
|
|
19
|
+
<label for="deviceLiveId">Xbox Live ID</label>
|
|
20
|
+
<input type="text" class="form-control" id="deviceLiveId"><br>
|
|
21
|
+
<label for="deviceTokenInput">Web Api Token</label>
|
|
22
|
+
<input type="text" class="form-control" id="deviceTokenInput"><br>
|
|
23
|
+
<label for="deviceWebApiControl">Web Api Control</label>
|
|
24
|
+
<input type="checkbox" class="form-control" id="deviceWebApiControl">
|
|
25
|
+
</div>
|
|
26
|
+
<div class="text-center">
|
|
27
|
+
<button id="startAuthorizationButton" type="button" class="btn btn-primary">Start authorization</button>
|
|
28
|
+
<button id="clearTokenButton" type="button" class="btn btn-primary">Clear Web Api Token</button>
|
|
29
|
+
<button id="configButton" type="button" class="btn btn-primary"><i class="fas fa-gear"></i></button>
|
|
30
|
+
</div>
|
|
31
|
+
</form>
|
|
32
|
+
</div>
|
|
36
33
|
|
|
37
34
|
<script>
|
|
38
35
|
(async () => {
|
|
@@ -55,13 +52,12 @@
|
|
|
55
52
|
//get devices count
|
|
56
53
|
const devicesCount = pluginConfig[0].devices.length;
|
|
57
54
|
|
|
58
|
-
//
|
|
59
|
-
this.deviceIndex = 0;
|
|
55
|
+
//get the intial from the config and add it to the form
|
|
60
56
|
for (let i = 0; i < devicesCount; i++) {
|
|
61
57
|
//create consoles buttons
|
|
62
58
|
const button = document.createElement("button");
|
|
63
59
|
button.setAttribute("type", "button");
|
|
64
|
-
button.setAttribute("id",
|
|
60
|
+
button.setAttribute("id", `button${i}`);
|
|
65
61
|
button.setAttribute("class", "btn btn-secondary");
|
|
66
62
|
button.innerText = pluginConfig[0].devices[i].name || 'Not set';
|
|
67
63
|
button.style.width = '160px';
|
|
@@ -69,7 +65,7 @@
|
|
|
69
65
|
document.body.appendChild(button);
|
|
70
66
|
|
|
71
67
|
//get actuall value on console select
|
|
72
|
-
document.getElementById(
|
|
68
|
+
document.getElementById(`button${i}`).addEventListener('click', async () => {
|
|
73
69
|
document.querySelector('#deviceNameInput').innerHTML = pluginConfig[0].devices[i].name || '';
|
|
74
70
|
document.querySelector('#deviceHostInput').value = pluginConfig[0].devices[i].host || '';
|
|
75
71
|
document.querySelector('#deviceLiveId').value = pluginConfig[0].devices[i].xboxLiveId || '';
|
|
@@ -77,20 +73,9 @@
|
|
|
77
73
|
document.querySelector('#deviceWebApiControl').checked = pluginConfig[0].devices[i].webApiControl || false;
|
|
78
74
|
this.deviceIndex = i;
|
|
79
75
|
});
|
|
76
|
+
this.deviceIndex = 0;
|
|
80
77
|
};
|
|
81
78
|
|
|
82
|
-
//add button show/hide config
|
|
83
|
-
document.getElementById('configButton').addEventListener('click', async () => {
|
|
84
|
-
const configButton = document.getElementById('configButton');
|
|
85
|
-
if (this.configButtonState) {
|
|
86
|
-
await homebridge.hideSchemaForm();
|
|
87
|
-
this.configButtonState = false;
|
|
88
|
-
} else {
|
|
89
|
-
await homebridge.showSchemaForm();
|
|
90
|
-
this.configButtonState = true;
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
|
|
94
79
|
//load values on first run
|
|
95
80
|
document.querySelector('#deviceNameInput').innerHTML = pluginConfig[0].devices[0].name || '';
|
|
96
81
|
document.querySelector('#deviceHostInput').value = pluginConfig[0].devices[0].host || '';
|
|
@@ -98,27 +83,28 @@
|
|
|
98
83
|
document.querySelector('#deviceTokenInput').value = pluginConfig[0].devices[0].xboxWebApiToken || '';
|
|
99
84
|
document.querySelector('#deviceWebApiControl').checked = pluginConfig[0].devices[0].webApiControl || false;
|
|
100
85
|
|
|
101
|
-
//check token length and
|
|
102
|
-
const tokenLength = (
|
|
103
|
-
document.getElementById('authorizeConsoleButton').setAttribute('disabled', 'disabled');
|
|
86
|
+
//check token length and set buttons name and checkbock state after open
|
|
87
|
+
const tokenLength = (document.querySelector('#deviceTokenInput').value).length || 0;
|
|
104
88
|
const setButtonMode = tokenLength <= 10 ? document.getElementById('startAuthorizationButton').innerText = "Start authorization" : document.getElementById('startAuthorizationButton').innerText = "Check state";
|
|
105
89
|
const setCheckboxState = tokenLength <= 10 ? document.getElementById('deviceWebApiControl').checked = false : false;
|
|
106
90
|
const setCheckboxMode = tokenLength <= 10 ? document.getElementById('deviceWebApiControl').disabled = true : false;
|
|
107
91
|
|
|
108
|
-
//watch for changes to the
|
|
92
|
+
//watch for changes to the config button
|
|
93
|
+
document.getElementById('configButton').addEventListener('click', async () => {
|
|
94
|
+
const showHideSettings = this.configButtonState ? await homebridge.hideSchemaForm() : await homebridge.showSchemaForm();
|
|
95
|
+
this.configButtonState = !this.configButtonState;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
//watch for changes to the form
|
|
109
99
|
document.getElementById('configForm').addEventListener('input', async () => {
|
|
110
100
|
pluginConfig[0].devices[this.deviceIndex].host = document.querySelector('#deviceHostInput').value;
|
|
111
101
|
pluginConfig[0].devices[this.deviceIndex].xboxLiveId = document.querySelector('#deviceLiveId').value;
|
|
112
102
|
pluginConfig[0].devices[this.deviceIndex].xboxWebApiToken = document.querySelector('#deviceTokenInput').value;
|
|
113
103
|
pluginConfig[0].devices[this.deviceIndex].webApiControl = document.querySelector('#deviceWebApiControl').checked;
|
|
114
104
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
document.getElementById('startAuthorizationButton').removeAttribute('disabled');
|
|
119
|
-
} else {
|
|
120
|
-
document.getElementById('authorizeConsoleButton').setAttribute('disabled', 'disabled');
|
|
121
|
-
}
|
|
105
|
+
const tokenLength1 = (document.querySelector('#deviceTokenInput').value).length || 0;
|
|
106
|
+
const setButtonName = tokenLength1 <= 10 ? document.getElementById('startAuthorizationButton').innerText = "Start authorization" : false;
|
|
107
|
+
const setButtonMode = tokenLength1 <= 10 ? document.getElementById('startAuthorizationButton').removeAttribute('disabled') : false;
|
|
122
108
|
|
|
123
109
|
await homebridge.savePluginConfig(pluginConfig);
|
|
124
110
|
await homebridge.updatePluginConfig(pluginConfig);
|
|
@@ -126,9 +112,8 @@
|
|
|
126
112
|
|
|
127
113
|
//clear token file
|
|
128
114
|
document.getElementById('clearTokenButton').addEventListener('click', async () => {
|
|
129
|
-
homebridge.showSpinner();
|
|
130
|
-
|
|
131
115
|
try {
|
|
116
|
+
homebridge.showSpinner();
|
|
132
117
|
const host = pluginConfig[0].devices[this.deviceIndex].host || '';
|
|
133
118
|
const payload = {
|
|
134
119
|
host: host
|
|
@@ -152,17 +137,18 @@
|
|
|
152
137
|
|
|
153
138
|
homebridge.hideSpinner();
|
|
154
139
|
} catch (e) {
|
|
155
|
-
|
|
140
|
+
document.getElementById('info').innerHTML = `Clear Web Api Token error: ${JSON.stringify(e, null, 2)}`;
|
|
141
|
+
document.getElementById('info').style.color = 'red';
|
|
156
142
|
homebridge.hideSpinner();
|
|
157
143
|
};
|
|
158
144
|
});
|
|
159
145
|
|
|
160
146
|
//watch for click on the Start authorization button
|
|
161
147
|
document.getElementById('startAuthorizationButton').addEventListener('click', async () => {
|
|
162
|
-
await homebridge.updatePluginConfig(pluginConfig);
|
|
163
|
-
homebridge.showSpinner();
|
|
164
|
-
|
|
165
148
|
try {
|
|
149
|
+
homebridge.showSpinner();
|
|
150
|
+
await homebridge.updatePluginConfig(pluginConfig);
|
|
151
|
+
|
|
166
152
|
const host = pluginConfig[0].devices[this.deviceIndex].host || '';
|
|
167
153
|
this.clientId = pluginConfig[0].devices[this.deviceIndex].clientId || '5e5ead27-ed60-482d-b3fc-702b28a97404';
|
|
168
154
|
this.clientSecret = pluginConfig[0].devices[this.deviceIndex].clientSecret || '';
|
|
@@ -186,40 +172,33 @@
|
|
|
186
172
|
case 0:
|
|
187
173
|
document.getElementById('info').innerHTML = 'Console authorized and activated. To start new process please clear Web API Token first.';
|
|
188
174
|
document.getElementById('info').style.color = 'green';
|
|
189
|
-
document.getElementById('
|
|
190
|
-
document.getElementById('authorizeConsoleButton').innerText = "Authorize console";
|
|
175
|
+
document.getElementById('startAuthorizationButton').innerText = "Check state";
|
|
191
176
|
document.getElementById('deviceWebApiControl').disabled = false;
|
|
192
177
|
break;
|
|
193
178
|
case 1:
|
|
194
|
-
document.getElementById('info').innerHTML = '
|
|
179
|
+
document.getElementById('info').innerHTML = 'Now go to the pop-up window, login to Your Xbox Live account and allow this plugin. Next from the response URI copy the part after *?code=* and paste it to the *Web Api Token*, next press *Activate Console*.';
|
|
195
180
|
document.getElementById('info').style.color = 'yellow';
|
|
196
|
-
document.getElementById('startAuthorizationButton').
|
|
197
|
-
document.getElementById('authorizeConsoleButton').removeAttribute('disabled');
|
|
198
|
-
document.getElementById('authorizeConsoleButton').innerText = "Authorize console";
|
|
181
|
+
document.getElementById('startAuthorizationButton').innerText = "Activate console";
|
|
199
182
|
document.getElementById('deviceWebApiControl').checked = false;
|
|
200
183
|
document.getElementById('deviceWebApiControl').disabled = true;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
};
|
|
184
|
+
|
|
185
|
+
// open the oauth2 URI for authentication
|
|
186
|
+
const authWindow = await window.open(info, "_blank");
|
|
187
|
+
document.getElementById('info').innerHTML = authWindow;
|
|
188
|
+
// get the authorization code from the URL
|
|
189
|
+
authWindow.addEventListener('load', async () => {
|
|
190
|
+
const locationHash = this.location.hash.substring(1);
|
|
191
|
+
const urlParams = await homebridge.request('/queryString', locationHash);
|
|
192
|
+
const code = urlParams.code;
|
|
193
|
+
if (code !== null) {
|
|
194
|
+
document.querySelector('#deviceTokenInput').value = code;
|
|
195
|
+
}
|
|
214
196
|
});
|
|
215
197
|
break;
|
|
216
198
|
case 2:
|
|
217
199
|
document.getElementById('info').innerHTML = 'Activation done, now enable *Web Api Control*, restart plugin and have fun!!!';
|
|
218
200
|
document.getElementById('info').style.color = 'green';
|
|
219
|
-
document.getElementById('startAuthorizationButton').
|
|
220
|
-
document.getElementById('startAuthorizationButton').innerText = "Start authorization";
|
|
221
|
-
document.getElementById('authorizeConsoleButton').setAttribute('disabled', 'disabled');
|
|
222
|
-
document.getElementById('authorizeConsoleButton').innerText = "Authorize console";
|
|
201
|
+
document.getElementById('startAuthorizationButton').innerText = "Check state";
|
|
223
202
|
document.getElementById('deviceWebApiControl').disabled = false;
|
|
224
203
|
|
|
225
204
|
await homebridge.savePluginConfig(pluginConfig);
|
|
@@ -228,18 +207,17 @@
|
|
|
228
207
|
case 3:
|
|
229
208
|
document.getElementById('info').innerHTML = 'Authorization or Token save error!!!.';
|
|
230
209
|
document.getElementById('info').style.color = 'red';
|
|
231
|
-
|
|
232
|
-
startAuthorizationButton.innerText = "Start authorization";
|
|
233
|
-
document.getElementById('authorizeConsoleButton').setAttribute('disabled', 'disabled');
|
|
234
|
-
document.getElementById('authorizeConsoleButton').innerText = "Authorize console";
|
|
210
|
+
document.getElementById('startAuthorizationButton').innerText = "Start authorization";
|
|
235
211
|
document.getElementById('deviceWebApiControl').checked = false;
|
|
236
212
|
document.getElementById('deviceWebApiControl').disabled = true;
|
|
237
|
-
|
|
213
|
+
document.getElementById('info').innerHTML = `Authorization error: ${JSON.stringify(info, null, 2)}`;
|
|
238
214
|
break;
|
|
239
215
|
};
|
|
240
216
|
|
|
241
217
|
} catch (e) {
|
|
242
|
-
|
|
218
|
+
document.getElementById('info').innerHTML = `Data error: ${JSON.stringify(e, null, 2)}`;
|
|
219
|
+
document.getElementById('deviceWebApiControl').checked = false;
|
|
220
|
+
document.getElementById('deviceWebApiControl').disabled = true;
|
|
243
221
|
} finally {
|
|
244
222
|
homebridge.hideSpinner();
|
|
245
223
|
};
|
package/homebridge-ui/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { HomebridgePluginUiServer, RequestError } = require('@homebridge/plugin-ui-utils');
|
|
4
|
+
const QueryString = require('querystring');
|
|
4
5
|
const Authentication = require('../src/webApi/authentication.js')
|
|
5
6
|
const fs = require('fs');
|
|
6
7
|
const fsPromises = fs.promises;
|
|
@@ -14,6 +15,9 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
14
15
|
// clear token
|
|
15
16
|
this.onRequest('/clearToken', this.clearToken.bind(this));
|
|
16
17
|
|
|
18
|
+
// clear token
|
|
19
|
+
this.onRequest('/queryString', this.queryString.bind(this));
|
|
20
|
+
|
|
17
21
|
// start console authorization
|
|
18
22
|
this.onRequest('/startAuthorization', this.getWebApiToken.bind(this));
|
|
19
23
|
|
|
@@ -22,14 +26,10 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
async clearToken(payload) {
|
|
25
|
-
const host = payload.host;
|
|
26
|
-
const authTokenFile = `${this.homebridgeStoragePath}/xboxTv/authToken_${host.split('.').join('')}`;
|
|
27
|
-
|
|
28
29
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
30
|
+
const host = payload.host;
|
|
31
|
+
const authTokenFile = `${this.homebridgeStoragePath}/xboxTv/authToken_${host.split('.').join('')}`;
|
|
32
|
+
await fsPromises.writeFile(authTokenFile, JSON.stringify({}));
|
|
33
33
|
return true;
|
|
34
34
|
} catch (e) {
|
|
35
35
|
throw new RequestError('Clear token file failed.', {
|
|
@@ -38,6 +38,17 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
async queryString(locationHash) {
|
|
42
|
+
try {
|
|
43
|
+
const urlParams = QueryString.parse(locationHash);
|
|
44
|
+
return urlParams;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw new RequestError('Query string failed.', {
|
|
47
|
+
message: e.message
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
41
52
|
async getWebApiToken(payload) {
|
|
42
53
|
|
|
43
54
|
try {
|
|
@@ -45,14 +56,14 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
45
56
|
const webApiToken = payload.webApiToken;
|
|
46
57
|
const authTokenFile = `${this.homebridgeStoragePath}/xboxTv/authToken_${host.split('.').join('')}`;
|
|
47
58
|
|
|
48
|
-
const
|
|
59
|
+
const authConfig = {
|
|
49
60
|
clientId: payload.clientId,
|
|
50
61
|
clientSecret: payload.clientSecret,
|
|
51
62
|
userToken: payload.userToken,
|
|
52
63
|
uhs: payload.uhs,
|
|
53
64
|
tokensFile: authTokenFile
|
|
54
65
|
}
|
|
55
|
-
const authentication = new Authentication(
|
|
66
|
+
const authentication = new Authentication(authConfig);
|
|
56
67
|
|
|
57
68
|
try {
|
|
58
69
|
await authentication.isAuthenticated();
|
|
@@ -70,15 +81,22 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
70
81
|
};
|
|
71
82
|
} catch (error) {
|
|
72
83
|
this.data = {
|
|
73
|
-
info:
|
|
84
|
+
info: error,
|
|
74
85
|
status: 3
|
|
75
86
|
};
|
|
76
87
|
};
|
|
77
88
|
} else {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
try {
|
|
90
|
+
const oauth2URI = await authentication.generateAuthorizationUrl();
|
|
91
|
+
this.data = {
|
|
92
|
+
info: oauth2URI,
|
|
93
|
+
status: 1
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
this.data = {
|
|
97
|
+
info: error,
|
|
98
|
+
status: 3
|
|
99
|
+
};
|
|
82
100
|
};
|
|
83
101
|
};
|
|
84
102
|
};
|
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.2-beta.
|
|
4
|
+
"version": "2.8.2-beta.20",
|
|
5
5
|
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|