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