homebridge-xbox-tv 3.7.2 → 3.7.3-beta.1

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.
@@ -9,271 +9,266 @@
9
9
  <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/js/all.min.js"></script>
10
10
  </head>
11
11
 
12
- <body>
13
-
14
- <div class="container mt-4">
15
- <div class="text-center">
16
- <img src="homebridge-xbox-tv.png" alt="Image" height="120" />
17
- </div>
18
-
19
- <div id="authorizationManager" class="card card-body mt-3">
20
- <form id="configForm">
21
- <div class="text-center">
22
- <label id="deviceName" class="fw-bold" style="font-size: 23px;">Xbox</label><br>
23
- <label id="info" class="d-block" style="font-size: 17px;"></label>
24
- <label id="info1" class="d-block" style="font-size: 15px;"></label>
25
- </div>
26
-
27
- <div class="mb-3">
28
- <label for="deviceHost" class="form-label">Host</label>
29
- <input id="deviceHost" type="text" class="form-control" required>
30
- </div>
12
+ <div class="container mt-4">
13
+ <div class="text-center">
14
+ <img src="homebridge-xbox-tv.png" alt="Image" height="120" />
15
+ </div>
31
16
 
32
- <div class="mb-3">
33
- <label for="deviceLiveId" class="form-label">Xbox Live ID</label>
34
- <input id="deviceLiveId" type="password" class="form-control" autocomplete="off" required>
17
+ <div id="authorizationManager" class="card card-body mt-3">
18
+ <form id="configForm">
19
+ <div class="text-center">
20
+ <label id="deviceName" class="fw-bold" style="font-size: 23px;">Xbox</label><br>
21
+ <label id="info" class="d-block" style="font-size: 17px;"></label>
22
+ <label id="info1" class="d-block" style="font-size: 15px;"></label>
23
+ </div>
24
+
25
+ <div class="mb-3">
26
+ <label for="deviceHost" class="form-label">Host</label>
27
+ <input id="deviceHost" type="text" class="form-control" required>
28
+ </div>
29
+
30
+ <div class="mb-3">
31
+ <label for="deviceLiveId" class="form-label">Xbox Live ID</label>
32
+ <input id="deviceLiveId" type="password" class="form-control" autocomplete="off" required>
33
+ </div>
34
+
35
+ <div class="mb-3 position-relative">
36
+ <label for="deviceToken" class="form-label">Web API Token</label>
37
+ <div class="input-group">
38
+ <input id="deviceToken" type="password" class="form-control" autocomplete="new-password" required>
39
+ <button type="button" id="toggleToken" class="btn btn-outline-secondary">
40
+ <i class="fas fa-eye"></i>
41
+ </button>
35
42
  </div>
43
+ </div>
44
+
45
+ <div class="form-check mb-3">
46
+ <input id="deviceWebApiControl" type="checkbox" class="form-check-input">
47
+ <label for="deviceWebApiControl" class="form-check-label">Web API Control</label>
48
+ </div>
49
+
50
+ <div class="text-center">
51
+ <button id="startAuthorizationButton" type="button" class="btn btn-primary">Start Authorization</button>
52
+ <button id="clearTokenButton" type="button" class="btn btn-secondary">Clear Web API Token</button>
53
+ <button id="configButton" type="button" class="btn btn-secondary"><i class="fas fa-gear"></i></button>
54
+ </div>
55
+ </form>
56
+ </div>
36
57
 
37
- <div class="mb-3 position-relative">
38
- <label for="deviceToken" class="form-label">Web API Token</label>
39
- <div class="input-group">
40
- <input id="deviceToken" type="password" class="form-control" autocomplete="new-password" required>
41
- <button type="button" id="toggleToken" class="btn btn-outline-secondary">
42
- <i class="fas fa-eye"></i>
43
- </button>
44
- </div>
45
- </div>
58
+ <div id="consoleButton" class="text-center mt-3"></div>
59
+ </div>
46
60
 
47
- <div class="form-check mb-3">
48
- <input id="deviceWebApiControl" type="checkbox" class="form-check-input">
49
- <label for="deviceWebApiControl" class="form-check-label">Web API Control</label>
50
- </div>
61
+ <script>
62
+ (async () => {
63
+ const pluginConfig = await homebridge.getPluginConfig();
51
64
 
52
- <div class="text-center">
53
- <button id="startAuthorizationButton" type="button" class="btn btn-primary">Start Authorization</button>
54
- <button id="clearTokenButton" type="button" class="btn btn-secondary">Clear Web API Token</button>
55
- <button id="configButton" type="button" class="btn btn-secondary"><i class="fas fa-gear"></i></button>
56
- </div>
57
- </form>
58
- </div>
65
+ if (!pluginConfig.length) {
66
+ pluginConfig.push({});
67
+ await homebridge.updatePluginConfig(pluginConfig);
68
+ homebridge.showSchemaForm();
69
+ return;
70
+ }
59
71
 
60
- <div id="consoleButton" class="text-center mt-3"></div>
61
- </div>
72
+ this.configButtonState = false;
73
+ this.deviceIndex = 0;
74
+ const devices = pluginConfig[0].devices || [];
75
+ const devicesCount = devices.length;
62
76
 
63
- <script>
64
- (async () => {
65
- const pluginConfig = await homebridge.getPluginConfig();
77
+ // Helper to get DOM elements
78
+ const $ = id => document.getElementById(id);
66
79
 
67
- if (!pluginConfig.length) {
68
- pluginConfig.push({});
69
- await homebridge.updatePluginConfig(pluginConfig);
70
- homebridge.showSchemaForm();
71
- return;
80
+ // Helper to set button classes
81
+ const setButtonClass = (activeIndex) => {
82
+ for (let j = 0; j < devicesCount; j++) {
83
+ $(`button${j}`).className = j === activeIndex ? "btn btn-primary" : "btn btn-secondary";
72
84
  }
85
+ };
86
+
87
+ // Helper to update the device form
88
+ const updateDeviceForm = (device) => {
89
+ $('deviceName').innerHTML = device.name || '';
90
+ $('deviceHost').value = device.host || '';
91
+ $('deviceLiveId').value = device.xboxLiveId || '';
92
+ $('deviceToken').value = device.webApiToken || '';
93
+ $('deviceWebApiControl').checked = device.webApiControl || false;
94
+
95
+ const tokenLength = device.webApiToken?.length || 0;
96
+ $('startAuthorizationButton').innerText = tokenLength <= 10 ? "Start Authorization" : "Check State";
97
+ $('deviceWebApiControl').disabled = tokenLength <= 10;
98
+
99
+ if (tokenLength <= 10) {
100
+ $('deviceWebApiControl').checked = false;
101
+ device.webApiControl = false;
102
+ }
103
+ };
104
+
105
+ // Create buttons for each device
106
+ devices.forEach((device, i) => {
107
+ const button = document.createElement("button");
108
+ button.type = "button";
109
+ button.id = `button${i}`;
110
+ button.className = "btn btn-secondary m-1";
111
+ button.style.textTransform = "none";
112
+ button.innerText = device.name || `Device ${i + 1}`;
113
+
114
+ $("consoleButton").appendChild(button);
115
+
116
+ button.addEventListener("click", async () => {
117
+ setButtonClass(i);
118
+ updateDeviceForm(devices[i]);
119
+ this.deviceIndex = i;
120
+ await homebridge.updatePluginConfig(pluginConfig);
121
+ });
73
122
 
74
- this.configButtonState = false;
75
- this.deviceIndex = 0;
76
- const devices = pluginConfig[0].devices || [];
77
- const devicesCount = devices.length;
123
+ // Auto-select the first device
124
+ if (i === devicesCount - 1) {
125
+ $("button0").click();
126
+ }
127
+ });
128
+
129
+ // Show the authorization form
130
+ $("authorizationManager").style.display = "block";
131
+
132
+ // Config button toggle
133
+ $("configButton").addEventListener("click", () => {
134
+ this.configButtonState ? homebridge.hideSchemaForm() : homebridge.showSchemaForm();
135
+ $("configButton").className = this.configButtonState ? "btn btn-secondary" : "btn btn-primary";
136
+ this.configButtonState = !this.configButtonState;
137
+ });
138
+
139
+ // Token toggle
140
+ $("toggleToken").addEventListener("click", () => {
141
+ const tokenInput = $("deviceToken");
142
+ const icon = document.querySelector('#toggleToken i');
143
+
144
+ if (tokenInput.type === 'password') {
145
+ tokenInput.type = 'text';
146
+ icon.classList.replace('fa-eye', 'fa-eye-slash');
147
+ } else {
148
+ tokenInput.type = 'password';
149
+ icon.classList.replace('fa-eye-slash', 'fa-eye');
150
+ }
151
+ });
78
152
 
79
- // Helper to get DOM elements
80
- const $ = id => document.getElementById(id);
153
+ // Update config on form input
154
+ $("configForm").addEventListener("input", async () => {
155
+ const currentDevice = devices[this.deviceIndex];
81
156
 
82
- // Helper to set button classes
83
- const setButtonClass = (activeIndex) => {
84
- for (let j = 0; j < devicesCount; j++) {
85
- $(`button${j}`).className = j === activeIndex ? "btn btn-primary" : "btn btn-secondary";
86
- }
87
- };
88
-
89
- // Helper to update the device form
90
- const updateDeviceForm = (device) => {
91
- $('deviceName').innerHTML = device.name || '';
92
- $('deviceHost').value = device.host || '';
93
- $('deviceLiveId').value = device.xboxLiveId || '';
94
- $('deviceToken').value = device.webApiToken || '';
95
- $('deviceWebApiControl').checked = device.webApiControl || false;
96
-
97
- const tokenLength = device.webApiToken?.length || 0;
98
- $('startAuthorizationButton').innerText = tokenLength <= 10 ? "Start Authorization" : "Check State";
99
- $('deviceWebApiControl').disabled = tokenLength <= 10;
100
-
101
- if (tokenLength <= 10) {
102
- $('deviceWebApiControl').checked = false;
103
- device.webApiControl = false;
104
- }
105
- };
106
-
107
- // Create buttons for each device
108
- devices.forEach((device, i) => {
109
- const button = document.createElement("button");
110
- button.type = "button";
111
- button.id = `button${i}`;
112
- button.className = "btn btn-secondary m-1";
113
- button.style.textTransform = "none";
114
- button.innerText = device.name || `Device ${i + 1}`;
115
-
116
- $("consoleButton").appendChild(button);
117
-
118
- button.addEventListener("click", async () => {
119
- setButtonClass(i);
120
- updateDeviceForm(devices[i]);
121
- this.deviceIndex = i;
122
- await homebridge.updatePluginConfig(pluginConfig);
123
- });
157
+ currentDevice.host = $('deviceHost').value;
158
+ currentDevice.xboxLiveId = $('deviceLiveId').value;
159
+ currentDevice.webApiToken = $('deviceToken').value;
160
+ currentDevice.webApiControl = $('deviceWebApiControl').checked;
124
161
 
125
- // Auto-select the first device
126
- if (i === devicesCount - 1) {
127
- $("button0").click();
128
- }
129
- });
162
+ const tokenLength = currentDevice.webApiToken?.length || 0;
163
+ $('startAuthorizationButton').innerText = tokenLength <= 10 ? "Start Authorization" : "Check State";
130
164
 
131
- // Show the authorization form
132
- $("authorizationManager").style.display = "block";
165
+ if (tokenLength <= 10) {
166
+ $('startAuthorizationButton').removeAttribute('disabled');
167
+ }
133
168
 
134
- // Config button toggle
135
- $("configButton").addEventListener("click", () => {
136
- this.configButtonState ? homebridge.hideSchemaForm() : homebridge.showSchemaForm();
137
- $("configButton").className = this.configButtonState ? "btn btn-secondary" : "btn btn-primary";
138
- this.configButtonState = !this.configButtonState;
139
- });
169
+ await homebridge.updatePluginConfig(pluginConfig);
170
+ await homebridge.savePluginConfig(pluginConfig);
171
+ });
140
172
 
141
- // Token toggle
142
- $("toggleToken").addEventListener("click", () => {
143
- const tokenInput = $("deviceToken");
144
- const icon = document.querySelector('#toggleToken i');
145
-
146
- if (tokenInput.type === 'password') {
147
- tokenInput.type = 'text';
148
- icon.classList.replace('fa-eye', 'fa-eye-slash');
149
- } else {
150
- tokenInput.type = 'password';
151
- icon.classList.replace('fa-eye-slash', 'fa-eye');
152
- }
153
- });
173
+ // Clear token button logic
174
+ $("clearTokenButton").addEventListener("click", async () => {
175
+ homebridge.showSpinner();
176
+ $("info").textContent = "Start clearing token...";
177
+ $("info").style.color = "yellow";
154
178
 
155
- // Update config on form input
156
- $("configForm").addEventListener("input", async () => {
157
- const currentDevice = devices[this.deviceIndex];
179
+ try {
180
+ const host = devices[this.deviceIndex].host;
181
+ await homebridge.request('/clearToken', { host });
158
182
 
159
- currentDevice.host = $('deviceHost').value;
160
- currentDevice.xboxLiveId = $('deviceLiveId').value;
161
- currentDevice.webApiToken = $('deviceToken').value;
162
- currentDevice.webApiControl = $('deviceWebApiControl').checked;
183
+ Object.assign(devices[this.deviceIndex], {
184
+ webApiToken: '',
185
+ webApiControl: false
186
+ });
163
187
 
164
- const tokenLength = currentDevice.webApiToken?.length || 0;
165
- $('startAuthorizationButton').innerText = tokenLength <= 10 ? "Start Authorization" : "Check State";
188
+ updateDeviceForm(devices[this.deviceIndex]);
166
189
 
167
- if (tokenLength <= 10) {
168
- $('startAuthorizationButton').removeAttribute('disabled');
169
- }
190
+ $("info").textContent = "Web API token cleared, now you can start a new authorization process.";
191
+ $("info").style.color = "green";
192
+ $("startAuthorizationButton").removeAttribute("disabled");
170
193
 
171
194
  await homebridge.updatePluginConfig(pluginConfig);
172
195
  await homebridge.savePluginConfig(pluginConfig);
173
- });
174
-
175
- // Clear token button logic
176
- $("clearTokenButton").addEventListener("click", async () => {
177
- homebridge.showSpinner();
178
- $("info").textContent = "Start clearing token...";
196
+ } catch (error) {
197
+ $("info").textContent = "Clear Web API token error.";
179
198
  $("info").style.color = "yellow";
199
+ $("info1").textContent = `Error: ${error}`;
200
+ $("info1").style.color = "red";
201
+ } finally {
202
+ homebridge.hideSpinner();
203
+ }
204
+ });
180
205
 
181
- try {
182
- const host = devices[this.deviceIndex].host;
183
- await homebridge.request('/clearToken', { host });
184
-
185
- Object.assign(devices[this.deviceIndex], {
186
- webApiToken: '',
187
- webApiControl: false
188
- });
189
-
190
- updateDeviceForm(devices[this.deviceIndex]);
191
-
192
- $("info").textContent = "Web API token cleared, now you can start a new authorization process.";
193
- $("info").style.color = "green";
194
- $("startAuthorizationButton").removeAttribute("disabled");
195
-
196
- await homebridge.updatePluginConfig(pluginConfig);
197
- await homebridge.savePluginConfig(pluginConfig);
198
- } catch (error) {
199
- $("info").textContent = "Clear Web API token error.";
200
- $("info").style.color = "yellow";
201
- $("info1").textContent = `Error: ${error}`;
202
- $("info1").style.color = "red";
203
- } finally {
204
- homebridge.hideSpinner();
205
- }
206
- });
206
+ // Start authorization logic
207
+ $("startAuthorizationButton").addEventListener("click", async () => {
208
+ homebridge.showSpinner();
209
+ $("startAuthorizationButton").setAttribute("disabled", "true"); // blokada wielokliku
210
+ $("info").textContent = "Starting authorization...";
211
+ $("info").style.color = "yellow";
207
212
 
208
- // Start authorization logic
209
- $("startAuthorizationButton").addEventListener("click", async () => {
210
- homebridge.showSpinner();
211
- $("startAuthorizationButton").setAttribute("disabled", "true"); // blokada wielokliku
212
- $("info").textContent = "Starting authorization...";
213
- $("info").style.color = "yellow";
213
+ try {
214
+ const device = devices[this.deviceIndex];
215
+ const { host, webApiClientId, webApiClientSecret, webApiToken } = device;
214
216
 
215
- try {
216
- const device = devices[this.deviceIndex];
217
- const { host, webApiClientId, webApiClientSecret, webApiToken } = device;
218
-
219
- const response = await homebridge.request('/startAuthorization', {
220
- host, webApiClientId, webApiClientSecret, webApiToken
221
- });
222
-
223
- const { info, status } = response;
224
-
225
- switch (status) {
226
- case 0: // Authorized
227
- $("info").textContent = info;
228
- $("info").style.color = "green";
229
- $("startAuthorizationButton").innerText = "Check State";
230
- $("deviceWebApiControl").disabled = false;
231
- break;
232
- case 1: // Needs user interaction
233
- $("startAuthorizationButton").innerText = "Activate Console";
234
- $("deviceWebApiControl").checked = false;
235
- $("deviceWebApiControl").disabled = true;
236
- device.webApiControl = false;
237
-
238
- let timeLeft = 10;
239
- const timerId = setInterval(() => {
240
- if (timeLeft <= 0) {
241
- open(info);
242
- clearInterval(timerId);
243
- $("info").innerText = "Now paste the *code* into *Web API Token* and press *Activate Console*.";
244
- $("info").style.color = "yellow";
245
- } else {
246
- $("info").innerText = `After ${timeLeft} sec, sign in to Xbox Live and authorize. Then copy the code after ?code= and return here.`;
247
- $("info").style.color = "yellow";
248
- timeLeft--;
249
- }
250
- }, 1000);
251
- break;
252
- case 2: // Successfully authorized
253
- $("info").textContent = info;
254
- $("info").style.color = "green";
255
- $("startAuthorizationButton").innerText = "Check State";
256
- $("deviceWebApiControl").disabled = false;
257
- $("deviceWebApiControl").checked = true;
258
- device.webApiControl = true;
259
-
260
- await homebridge.updatePluginConfig(pluginConfig);
261
- await homebridge.savePluginConfig(pluginConfig);
262
- break;
263
- }
264
- } catch (error) {
265
- $("info").textContent = "Check your credential data and try again.";
266
- $("info").style.color = "yellow";
267
- $("info1").textContent = `Error: ${error}`;
268
- $("info1").style.color = "red";
269
- } finally {
270
- $("startAuthorizationButton").removeAttribute("disabled"); // odblokowanie przycisku
271
- homebridge.hideSpinner();
272
- }
273
- });
217
+ const response = await homebridge.request('/startAuthorization', {
218
+ host, webApiClientId, webApiClientSecret, webApiToken
219
+ });
274
220
 
275
- })();
276
- </script>
277
- </body>
221
+ const { info, status } = response;
222
+
223
+ switch (status) {
224
+ case 0: // Authorized
225
+ $("info").textContent = info;
226
+ $("info").style.color = "green";
227
+ $("startAuthorizationButton").innerText = "Check State";
228
+ $("deviceWebApiControl").disabled = false;
229
+ break;
230
+ case 1: // Needs user interaction
231
+ $("startAuthorizationButton").innerText = "Activate Console";
232
+ $("deviceWebApiControl").checked = false;
233
+ $("deviceWebApiControl").disabled = true;
234
+ device.webApiControl = false;
235
+
236
+ let timeLeft = 10;
237
+ const timerId = setInterval(() => {
238
+ if (timeLeft <= 0) {
239
+ open(info);
240
+ clearInterval(timerId);
241
+ $("info").innerText = "Now paste the *code* into *Web API Token* and press *Activate Console*.";
242
+ $("info").style.color = "yellow";
243
+ } else {
244
+ $("info").innerText = `After ${timeLeft} sec, sign in to Xbox Live and authorize. Then copy the code after ?code= and return here.`;
245
+ $("info").style.color = "yellow";
246
+ timeLeft--;
247
+ }
248
+ }, 1000);
249
+ break;
250
+ case 2: // Successfully authorized
251
+ $("info").textContent = info;
252
+ $("info").style.color = "green";
253
+ $("startAuthorizationButton").innerText = "Check State";
254
+ $("deviceWebApiControl").disabled = false;
255
+ $("deviceWebApiControl").checked = true;
256
+ device.webApiControl = true;
257
+
258
+ await homebridge.updatePluginConfig(pluginConfig);
259
+ await homebridge.savePluginConfig(pluginConfig);
260
+ break;
261
+ }
262
+ } catch (error) {
263
+ $("info").textContent = "Check your credential data and try again.";
264
+ $("info").style.color = "yellow";
265
+ $("info1").textContent = `Error: ${error}`;
266
+ $("info1").style.color = "red";
267
+ } finally {
268
+ $("startAuthorizationButton").removeAttribute("disabled"); // odblokowanie przycisku
269
+ homebridge.hideSpinner();
270
+ }
271
+ });
278
272
 
279
- </html>
273
+ })();
274
+ </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "3.7.2",
4
+ "version": "3.7.3-beta.1",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",