Skip to content

Commit

Permalink
Merge pull request #186 from grzegorz914/2.10.0-beta
Browse files Browse the repository at this point in the history
2.10.0
  • Loading branch information
grzegorz914 authored Dec 26, 2023
2 parents bbb9651 + 380dab9 commit 351ef13
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 310 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### NOTE!!!
## After update to 2.x.x the plugin settings (xboxLiveId) need to be updated.

## [2.10.0] - (xx.09.2023)
## [2.10.0] - (26.12.2023)
## After update to this version the plugin properties are changed and console must be authorized and settings need to be corrected.
## Changes
- full code refactor
- added possibility toggle Power control between local/web api
- added possibility toggle RC control between local/web api
- added possibility toggle Volume control between local/web api
- fixed laggy remote control [#140](https://github.com/grzegorz914/homebridge-xbox-tv/issues/140)
- fixed disconnect problem on first run
- performance and stability improvements
- config.schema updated
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
| `sensorInputs.displayType` | Here select sensor type to be exposed in HomeKit app, possible `None/Disabled`, `Motion Sensor`, `Occupancy Sensor`, `Contact Sensor`. |
| `webApiControl` | This enable console control over Web Api. Additional functions are available in `Advanced Settings` section. |
| `webApiPowerOnOff` | This enable `Power` control over Web Api. |
| `webApiRcControl` | This enable `Remote` control over Web Api. |
| `webApiVolumeControl` | This enable `Volume/Mute` control over Web Api. |
| `webApiToken` | Required if `webApiControl` enabled, use Authorization Manager to get it. |
| `webApiClientId` | If You are created App on Azure AD then You can use your own Client Id. |
| `webApiClientSecret` | If You are created App on Azure AD then You can use own Client Secret. |
Expand Down
4 changes: 1 addition & 3 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"singular": true,
"fixArrays": true,
"customUi": true,
"headerDisplay": "This plugin works with Xbox game Consoles. Devices are exposed to HomeKit as separate accessories and each needs to be manually paired.\n\n1. Open the Home <img src='https://user-images.githubusercontent.com/3979615/78010622-4ea1d380-738e-11ea-8a17-e6a465eeec35.png' height='16.42px'> app on your device.\n2. Tap the <img src='https://user-images.githubusercontent.com/3979615/78010869-9aed1380-738e-11ea-9644-9f46b3633026.png' height='16.42px'>.\n3. Tap *Add Accessory*, and select *I Don't Have a Code or Cannot Scan* or *More Options*.\n4. Select Your accessory and press add anyway.\n5. Enter the PIN or scan the QR code, this can be found in Homebridge UI or Homebridge logs.\n6. Complete the accessory setup.",
"headerDisplay": "This plugin works with Xbox Game Consoles. Devices are exposed to HomeKit as separate accessories and each needs to be manually paired.",
"footerDisplay": "For documentation please see [GitHub repository](https://github.com/grzegorz914/homebridge-xbox-tv).",
"schema": {
"type": "object",
Expand Down Expand Up @@ -861,8 +861,6 @@
"items": [
"devices[].webApiControl",
"devices[].webApiPowerOnOff",
"devices[].webApiRcControl",
"devices[].webApiVolumeControl",
"devices[].webApiToken",
"devices[].webApiClientId",
"devices[].webApiClientSecret"
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class XboxPlatform {
api.on('didFinishLaunching', () => {
for (const device of config.devices) {
if (!device.name || !device.host || !device.xboxLiveId) {
log.warn(`Device Name: ${device.name ? device.name : 'Missing'}, Host: ${device.host ? device.host : 'Missing'} or Xbox Live ID: ${device.xboxLiveId ? device.xboxLiveId : 'Missing'}.`);
log.warn(`Name: ${device.name ? 'OK' : device.name}, Host: ${device.host ? 'OK' : device.host}, Xbox Live ID: ${device.xboxLiveId ? 'OK' : device.xboxLiveId}, wromg or missing.`);
return;
}
const debug = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, did finish launching.`) : false;
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"displayName": "Xbox TV",
"name": "homebridge-xbox-tv",
"version": "2.10.0-beta.198",
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
"version": "2.10.0",
"description": "Homebridge plugin to control Xbox game consoles.",
"license": "MIT",
"author": "grzegorz914",
"homepage": "https://github.com/grzegorz914/homebridge-xbox-tv#readme",
Expand All @@ -25,19 +25,19 @@
"LICENSE"
],
"engines": {
"node": ">=16.0.0",
"homebridge": ">=1.5.0"
"node": ">=18.0.0",
"homebridge": ">=1.6.0"
},
"dependencies": {
"@homebridge/plugin-ui-utils": "^0.1.0",
"@homebridge/plugin-ui-utils": "^1.0.0",
"async-mqtt": "^2.6.3",
"elliptic": "^6.5.4",
"hex-to-binary": "^1.0.1",
"jsrsasign": "^10.8.6",
"jsrsasign": "^10.9.0",
"uuid": "^9.0.1",
"ping": "^0.4.4",
"express": "^4.18.2",
"axios": "^1.5.1"
"axios": "^1.6.2"
},
"keywords": [
"homebridge",
Expand Down
2 changes: 0 additions & 2 deletions sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
],
"webApiControl": false,
"webApiPowerOnOff": false,
"webApiRcControl": false,
"webApiVolumeControl": false,
"webApiToken": "",
"webApiClientId": "",
"webApiClientSecret": "",
Expand Down
45 changes: 27 additions & 18 deletions src/constans.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,75 @@
"PluginName": "homebridge-xbox-tv",
"DefaultInputs": [
{
"name": "Screensaver",
"oneStoreProductId": "Screensaver",
"titleId": "851275400",
"reference": "Xbox.IdleScreen_8wekyb3d8bbwe!Xbox.IdleScreen.Application",
"oneStoreProductId": "Screensaver",
"isGame": false,
"name": "Screensaver",
"contentType": "Dashboard"
},
{
"name": "Dashboard",
"oneStoreProductId": "Dashboard",
"titleId": "750323071",
"reference": "Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application",
"oneStoreProductId": "Dashboard",
"isGame": false,
"name": "Dashboard",
"contentType": "Dashboard"
},
{
"name": "Settings",
"oneStoreProductId": "Settings",
"titleId": "1837352387",
"reference": "Microsoft.Xbox.Settings_8wekyb3d8bbwe!Xbox.Settings.Application",
"oneStoreProductId": "Settings",
"isGame": false,
"name": "Settings",
"contentType": "Dashboard"
},
{
"name": "Television",
"oneStoreProductId": "Television",
"titleId": "371594669",
"reference": "Microsoft.Xbox.LiveTV_8wekyb3d8bbwe!Microsoft.Xbox.LiveTV.Application",
"oneStoreProductId": "Television",
"isGame": false,
"name": "Television",
"contentType": "systemApp"
},
{
"name": "Settings TV",
"oneStoreProductId": "SettingsTv",
"titleId": "2019308066",
"reference": "Microsoft.Xbox.TvSettings_8wekyb3d8bbwe!Microsoft.Xbox.TvSettings.Application",
"oneStoreProductId": "SettingsTv",
"isGame": false,
"name": "Settings TV",
"contentType": "Dashboard"
},
{
"name": "Accessory",
"oneStoreProductId": "Accessory",
"titleId": "758407307",
"reference": "Microsoft.XboxDevices_8wekyb3d8bbwe!App",
"oneStoreProductId": "Accessory",
"isGame": false,
"name": "Accessory",
"contentType": "systemApp"
},
{
"name": "Network Troubleshooter",
"oneStoreProductId": "NetworkTroubleshooter",
"titleId": "1614319806",
"reference": "Xbox.NetworkTroubleshooter_8wekyb3d8bbwe!Xbox.NetworkTroubleshooter.Application",
"oneStoreProductId": "NetworkTroubleshooter",
"isGame": false,
"name": "Network Troubleshooter",
"contentType": "systemApp"
},
{
"name": "Microsoft Store",
"oneStoreProductId": "MicrosoftStore",
"titleId": "1864271209",
"reference": "Microsoft.storify_8wekyb3d8bbwe!App",
"oneStoreProductId": "MicrosoftStore",
"isGame": false,
"name": "Microsoft Store",
"contentType": "Dashboard"
},
{
"name": "Xbox Guide",
"oneStoreProductId": "XboxGuide",
"titleId": "1052052983",
"reference": "Xbox.Guide_8wekyb3d8bbwe!Xbox.Guide.Application",
"oneStoreProductId": "XboxGuide",
"isGame": false,
"name": "Xbox Guide",
"contentType": "systemApp"
}
],
Expand Down
24 changes: 14 additions & 10 deletions src/localApi/xboxlocalapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs');
const fsPromises = fs.promises;
const Dgram = require('dgram');
const Net = require('net');
const { parse: UuIdParse, v4: UuIdv4 } = require('uuid');
const EventEmitter = require('events');
const Ping = require('ping');
Expand Down Expand Up @@ -33,10 +34,15 @@ class XBOXLOCALAPI extends EventEmitter {

//dgram socket
this.connect = () => {
this.client = new Dgram.createSocket('udp4');
this.client.on('error', (error) => {
const udpType = Net.isIPv6(this.host) ? 'udp6' : 'udp4';
const socket = Dgram.createSocket(udpType);
socket.on('error', (error) => {
this.emit('error', `Socket error: ${error}`);
this.client.close();
socket.close();
}).on('close', () => {
const debug = this.debugLog ? this.emit('debug', 'Socket closed.') : false;
this.isConnected = false;
this.reconnect();
}).on('message', async (message, remote) => {
const debug = this.debugLog ? this.emit('debug', `Received message from: ${remote.address}:${remote.port}`) : false;
this.heartBeatStartTime = Date.now();
Expand Down Expand Up @@ -237,7 +243,7 @@ class XBOXLOCALAPI extends EventEmitter {

//Start prepare accessory
const prepareAccessory = this.startPrepareAccessory ? this.emit('prepareAccessory') : false;
const awaitToPrepareAccesory = this.startPrepareAccessory ? await new Promise(resolve => setTimeout(resolve, 1500)) : false;
const awaitToPrepareAccesory = this.startPrepareAccessory ? await new Promise(resolve => setTimeout(resolve, 1000)) : false;
this.startPrepareAccessory = false;

const appsCount = Array.isArray(packet.payloadProtected.activeTitles) ? packet.payloadProtected.activeTitles.length : 0;
Expand Down Expand Up @@ -285,8 +291,10 @@ class XBOXLOCALAPI extends EventEmitter {
break;
};
}).on('listening', async () => {
const address = this.client.address();
//socket.setBroadcast(true);
const address = socket.address();
const debug = this.debugLog ? this.emit('debug', `Server start listening: ${address.address}:${address.port}.`) : false;
this.socket = socket;

//ping console
setInterval(async () => {
Expand Down Expand Up @@ -325,10 +333,6 @@ class XBOXLOCALAPI extends EventEmitter {
await new Promise(resolve => setTimeout(resolve, 5000));
const prepareAccessory = this.startPrepareAccessory ? this.emit('prepareAccessory') : false;
this.startPrepareAccessory = false;
}).on('close', () => {
const debug = this.debugLog ? this.emit('debug', 'Socket closed.') : false;
this.isConnected = false;
this.reconnect();
}).bind();
};

Expand Down Expand Up @@ -581,7 +585,7 @@ class XBOXLOCALAPI extends EventEmitter {
const offset = 0;
const length = message.byteLength;

this.client.send(message, offset, length, 5050, this.host, (error, bytes) => {
this.socket.send(message, offset, length, 5050, this.host, (error, bytes) => {
if (error) {
reject(error);
return;
Expand Down
Loading

0 comments on commit 351ef13

Please sign in to comment.