diff --git a/CHANGELOG.md b/CHANGELOG.md index cdc1f7b..80ec525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ 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.4.0] - (24.01.2023) +## Changes +- added Power Sensor for use with automations (active if power is ON) +- added Input Sensor for use with automations (activ on every Input change) +- added Screen Saver Sensor for use with automations (active on change to Screen Saver) +- added custom Inputs Sensor based on reference for use with automations (active on change to Input) +- config.schema updated +- cleanup + ## [2.3.16] - (04.01.2023) ## Changes - fix wrong state after power Off diff --git a/README.md b/README.md index 838a081..baee368 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,12 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox | `buttons.command` | Here select button control mode or command, `Reboot` and `Switch App/Game`- only possible if `webApiControl` enabled. | | `buttons.oneStoreProductId` | Here set *Input oneStoreProductId*, only possible if `webApiControl` enabled.| | `buttons.displayType` | Here select display type in HomeKit app, possible `Switch`, `Button` - selectable in HomeKit app as Light, Fan, Outlet.| +| `sensorPower`| If enabled, then the Power will be exposed as a `Motion Sensor` to use with automations (active if power is ON). | +| `sensorInput`| If enabled, then the Input will be exposed as a `Motion Sensor` to use with automations (activ on every Input change). | +| `sensorScreenSaver`| If enabled, then the Screen Saver will be exposed as a `Motion Sensor` to use with automations (active on change to Screen Saver). | +| `sensorInputs.name` | Here set own *Name* which You want expose to the *Homebridge/HomeKit* for this sensor. | +| `sensorInputs.reference` | Here set *Reference* like `Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application`, `Microsoft.XboxDevices_8wekyb3d8bbwe!App` to be exposed as sensor. | +| `sensorInputs.displayType` | Here select sensor type to be exposed in HomeKit app, possible `None`, `Motion Sensor`, `Occupancy Sensor`, `Contact Sensor`. | | `enableMqtt` | If enabled, MQTT Broker will start automatically and publish all awailable PV installation data. | | `mqttHost` | Here set the *IP Address* or *Hostname* for MQTT Broker.) | | `mqttPort` | Here set the *Port* for MQTT Broker, default 1883.) | @@ -168,6 +174,16 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox "displayType": 0 }, ], + "sensorPower": false, + "sensorInput": false, + "sensorScreenSaver": false, + "sensorInputs": [ + { + "name": "Dashboard", + "reference": "Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application", + "displayType": 0 + } + ], "enableMqtt": false, "mqttHost": "192.168.1.33", "mqttPort": 1883, diff --git a/config.schema.json b/config.schema.json index cbe7f4f..860221b 100644 --- a/config.schema.json +++ b/config.schema.json @@ -102,9 +102,9 @@ "type": "integer", "minimum": 0, "maximum": 2, - "default": 0, "description": "Here select what a volume control mode You want to use. If select *None* only hardware buttons in RC app can be used to control volume.", - "oneOf": [{ + "oneOf": [ + { "title": "None", "enum": [ 0 @@ -128,7 +128,8 @@ "infoButtonCommand": { "title": "Info Button", "type": "string", - "oneOf": [{ + "oneOf": [ + { "title": "View", "enum": [ "view" @@ -232,7 +233,8 @@ "title": "Type", "type": "string", "description": "Here select source input type.", - "oneOf": [{ + "oneOf": [ + { "title": "Other", "enum": [ "OTHER" @@ -305,7 +307,8 @@ "title": "Content Type", "type": "string", "description": "Here select source input type.", - "oneOf": [{ + "oneOf": [ + { "title": "Game", "enum": [ "Game" @@ -351,7 +354,8 @@ "command": { "title": "Command / Mode", "type": "string", - "oneOf": [{ + "oneOf": [ + { "title": "Media Play", "enum": [ "play" @@ -557,7 +561,8 @@ "displayType": { "title": "Display Type", "type": "integer", - "oneOf": [{ + "oneOf": [ + { "title": "Button", "enum": [ 0 @@ -576,6 +581,83 @@ } } }, + "sensorPower": { + "title": "Power", + "type": "boolean", + "default": false, + "description": "This expose Power as a Motion Sensor to use with automations.", + "required": false + }, + "sensorInput": { + "title": "Input", + "type": "boolean", + "default": false, + "description": "This expose Input as a Motion Sensor to use with automations.", + "required": false + }, + "sensorScreenSaver": { + "title": "Screen Saver", + "type": "boolean", + "default": false, + "description": "This expose Screen Saver as a Motion Sensor to use with automations.", + "required": false + }, + "sensorInputs": { + "type": "array", + "items": { + "title": "Inputs", + "type": "object", + "description": "Here create Input/App Sensors based on reference, sensor will active if switch to it.", + "properties": { + "name": { + "title": "Name", + "type": "string", + "placeholder": "Name", + "description": "Here set Your own name.", + "required": true + }, + "reference": { + "title": "Reference", + "type": "string", + "placeholder": "Input/App reference", + "description": "Here set the Input/App reference.", + "required": true + }, + "displayType": { + "title": "Type", + "type": "integer", + "oneOf": [ + { + "title": "None", + "enum": [ + -1 + ] + }, + { + "title": "Motion Sensor", + "enum": [ + 0 + ] + }, + { + "title": "Occupancy Sensor", + "enum": [ + 1 + ] + }, + { + "title": "Contact Sensor", + "enum": [ + 2 + ] + } + ], + "description": "Here select sensor type to be exposed in HomeKit app.", + "required": true + } + } + } + }, "enableMqtt": { "title": "Enable", "type": "boolean", @@ -659,110 +741,145 @@ } } }, - "layout": [{ - "key": "devices", - "type": "tabarray", - "title": "{{ value.name || 'new device' }}", - "items": [ - "devices[].name", - "devices[].host", - "devices[].xboxLiveId", - "devices[].webApiControl", - { - "key": "devices[]", - "type": "section", - "title": "Inputs", - "expandable": true, - "expanded": false, - "items": [ - "devices[].getInputsFromDevice", - "devices[].filterGames", - "devices[].filterApps", - "devices[].filterSystemApps", - "devices[].filterDlc", - { - "key": "devices[].inputs", - "type": "tabarray", - "title": "{{ value.name || 'new input' }}", - "items": [ - "devices[].inputs[].name", - "devices[].inputs[].reference", - "devices[].inputs[].oneStoreProductId", - "devices[].inputs[].type", - "devices[].inputs[].contentType" - ], - "condition": { - "functionBody": "return model.devices && model.devices[arrayIndices].getInputsFromDevice === false || model.devices[arrayIndices].webApiControl === false;" + "layout": [ + { + "key": "devices", + "type": "tabarray", + "title": "{{ value.name || 'new device' }}", + "items": [ + "devices[].name", + "devices[].host", + "devices[].xboxLiveId", + "devices[].webApiControl", + { + "key": "devices[]", + "type": "section", + "title": "Inputs", + "expandable": true, + "expanded": false, + "items": [ + "devices[].getInputsFromDevice", + "devices[].filterGames", + "devices[].filterApps", + "devices[].filterSystemApps", + "devices[].filterDlc", + { + "key": "devices[].inputs", + "type": "tabarray", + "title": "{{ value.name || 'new input' }}", + "items": [ + "devices[].inputs[].name", + "devices[].inputs[].reference", + "devices[].inputs[].oneStoreProductId", + "devices[].inputs[].type", + "devices[].inputs[].contentType" + ], + "condition": { + "functionBody": "return model.devices && model.devices[arrayIndices].getInputsFromDevice === false || model.devices[arrayIndices].webApiControl === false;" + } + } + ] + }, + { + "key": "devices[]", + "type": "section", + "title": "Buttons", + "expandable": true, + "expanded": false, + "items": [ + { + "key": "devices[].buttons", + "type": "tabarray", + "title": "{{ value.name || 'new button' }}", + "items": [ + "devices[].buttons[].name", + "devices[].buttons[].command", + "devices[].buttons[].oneStoreProductId", + "devices[].buttons[].displayType" + ] } + ] + }, + { + "key": "devices[]", + "type": "section", + "title": "Sensors", + "expandable": true, + "expanded": false, + "items": [ + "devices[].sensorPower", + "devices[].sensorScreenSaver", + { + "key": "devices[]", + "type": "section", + "title": "Inputs", + "expandable": true, + "expanded": false, + "items": [ + "devices[].sensorInput", + { + "key": "devices[].sensorInputs", + "type": "tabarray", + "title": "{{ value.name || 'new input sensor' }}", + "items": [ + "devices[].sensorInputs[].name", + "devices[].sensorInputs[].reference", + "devices[].sensorInputs[].displayType" + ] + } + ] + } + ] + }, + { + "key": "devices[]", + "type": "section", + "title": "Web Api", + "expandable": true, + "expanded": false, + "items": [ + "devices[].clientId", + "devices[].clientSecret", + "devices[].xboxWebApiToken", + "devices[].userToken", + "devices[].userHash" + ], + "condition": { + "functionBody": "return model.devices[arrayIndices].webApiControl === true;" } - ] - }, - { - "key": "devices[]", - "type": "section", - "title": "Buttons", - "expandable": true, - "expanded": false, - "items": [{ - "key": "devices[].buttons", - "type": "tabarray", - "title": "{{ value.name || 'new button' }}", + }, + { + "key": "devices[]", + "type": "section", + "title": "Advanced Settings", + "expandable": true, + "expanded": false, "items": [ - "devices[].buttons[].name", - "devices[].buttons[].command", - "devices[].buttons[].oneStoreProductId", - "devices[].buttons[].displayType" + "devices[].enableDebugMode", + "devices[].disableLogInfo", + "devices[].disableLogDeviceInfo", + "devices[].infoButtonCommand", + "devices[].volumeControl" + ] + }, + { + "key": "devices[]", + "type": "section", + "title": "MQTT", + "expandable": true, + "expanded": false, + "items": [ + "devices[].enableMqtt", + "devices[].mqttHost", + "devices[].mqttPort", + "devices[].mqttPrefix", + "devices[].mqttAuth", + "devices[].mqttUser", + "devices[].mqttPasswd", + "devices[].mqttDebug" ] - }] - }, - { - "key": "devices[]", - "type": "section", - "title": "Web Api Settings", - "expandable": true, - "expanded": false, - "items": [ - "devices[].clientId", - "devices[].clientSecret", - "devices[].xboxWebApiToken", - "devices[].userToken", - "devices[].userHash" - ], - "condition": { - "functionBody": "return model.devices[arrayIndices].webApiControl === true;" } - }, - { - "key": "devices[]", - "type": "section", - "title": "Advanced Settings", - "expandable": true, - "expanded": false, - "items": [ - "devices[].enableDebugMode", - "devices[].disableLogInfo", - "devices[].disableLogDeviceInfo", - "devices[].infoButtonCommand", - "devices[].volumeControl" - ] - }, - { - "key": "devices[]", - "type": "section", - "title": "MQTT", - "expandable": true, - "expanded": false, - "items": [ - "devices[].enableMqtt", - "devices[].mqttHost", - "devices[].mqttPort", - "devices[].mqttPrefix", - "devices[].mqttAuth", - "devices[].mqttUser", - "devices[].mqttPasswd", - "devices[].mqttDebug" - ] - } - ] - }] + ] + } + ] } \ No newline at end of file diff --git a/index.js b/index.js index 2735f13..0fd0ff9 100644 --- a/index.js +++ b/index.js @@ -84,6 +84,10 @@ class XBOXDEVICE { this.filterDlc = config.filterDlc || false; this.inputs = config.inputs || []; this.buttons = config.buttons || []; + this.sensorPower = config.sensorPower || false; + this.sensorInput = config.sensorInput || false; + this.sensorScreenSaver = config.sensorScreenSaver || false; + this.sensorInputs = config.sensorInputs || []; this.mqttEnabled = config.enableMqtt || false; this.mqttHost = config.mqttHost; this.mqttPort = config.mqttPort || 1883; @@ -112,12 +116,18 @@ class XBOXDEVICE { this.inputsName = []; this.inputsTitleId = []; this.inputsType = []; + this.inputsSensorsReference = []; + this.inputsSensorsDisplayType = []; this.power = false; this.volume = 0; this.mute = true; this.mediaState = 0; this.inputIdentifier = 0; + this.reference = ''; + + this.sensorScreenSaverState = false; + this.sensorInputState = false; this.prefDir = path.join(api.user.storagePath(), 'xboxTv'); this.authTokenFile = `${this.prefDir}/authToken_${this.host.split('.').join('')}`; @@ -219,13 +229,13 @@ class XBOXDEVICE { this.firmwareRevision = firmwareRevision; }) - .on('stateChanged', (power, titleId, inputReference, volume, mute, mediaState) => { - const inputIdentifier = this.inputsReference.indexOf(inputReference) >= 0 ? this.inputsReference.indexOf(inputReference) : this.inputsTitleId.indexOf(titleId) >= 0 ? this.inputsTitleId.indexOf(titleId) : this.inputIdentifier; + .on('stateChanged', (power, titleId, reference, volume, mute, mediaState) => { + const inputIdentifier = this.inputsReference.indexOf(reference) >= 0 ? this.inputsReference.indexOf(reference) : this.inputsTitleId.indexOf(titleId) >= 0 ? this.inputsTitleId.indexOf(titleId) : this.inputIdentifier; const obj = JSON.stringify({ 'power': power, 'titleId': titleId, - 'app': inputReference, + 'app': reference, 'volume': volume, 'mute': mute, 'mediaState': mediaState, @@ -254,11 +264,42 @@ class XBOXDEVICE { }; }; + if (this.sensorPowerService) { + this.sensorPowerService + .updateCharacteristic(Characteristic.MotionDetected, power) + } + + if (this.sensorInputService) { + const state = power ? (this.inputIdentifier !== inputIdentifier) : false; + this.sensorInputService + .updateCharacteristic(Characteristic.MotionDetected, state) + this.sensorInputState = state; + } + + if (this.sensorScreenSaverService) { + const state = power ? (reference === 'Xbox.IdleScreen_8wekyb3d8bbwe!Xbox.IdleScreen.Application') : false; + this.sensorScreenSaverService + .updateCharacteristic(Characteristic.MotionDetected, state) + this.sensorScreenSaverState = state; + } + + if (this.inputSensorServices) { + const servicesCount = this.inputSensorServices.length; + for (let i = 0; i < servicesCount; i++) { + const state = power ? (this.inputsSensorsReference[i] === reference) : false; + const displayType = this.inputsSensorsDisplayType[i]; + const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType]; + this.inputSensorServices[i] + .updateCharacteristic(characteristicType, state); + } + } + this.firstRun = false; this.power = power; this.volume = volume; this.mute = mute; this.mediaState = mediaState; + this.reference = reference; this.inputIdentifier = inputIdentifier; const mqtt = this.mqttEnabled ? this.mqtt.send('State', obj) : false; }) @@ -838,6 +879,40 @@ class XBOXDEVICE { } } + //prepare sensor service + if (this.sensorPower) { + this.log.debug('prepareSensorPowerService') + this.sensorPowerService = new Service.MotionSensor(`${accessoryName} Power Sensor`, `Power Sensor`); + this.sensorPowerService.getCharacteristic(Characteristic.MotionDetected) + .onGet(async () => { + const state = this.power; + return state; + }); + accessory.addService(this.sensorPowerService); + }; + + if (this.sensorInput) { + this.log.debug('prepareSensorInputService') + this.sensorInputService = new Service.MotionSensor(`${accessoryName} Input Sensor`, `Input Sensor`); + this.sensorInputService.getCharacteristic(Characteristic.MotionDetected) + .onGet(async () => { + const state = this.sensorInputState; + return state; + }); + accessory.addService(this.sensorInputService); + }; + + if (this.sensorScreenSaver) { + this.log.debug('prepareSensorScreenSaverService') + this.sensorScreenSaverService = new Service.MotionSensor(`${accessoryName} Screen Saver Sensor`, `Screen Saver Sensor`); + this.sensorScreenSaverService.getCharacteristic(Characteristic.MotionDetected) + .onGet(async () => { + const state = this.power ? this.sensorScreenSaverState : false; + return state; + }); + accessory.addService(this.sensorScreenSaverService); + }; + //Prepare inputs services this.log.debug('prepareInputServices'); @@ -939,12 +1014,52 @@ class XBOXDEVICE { accessory.addService(inputService); } + //prepare sonsor service + const inputsSensors = this.sensorInputs; + const inputsSensorsCount = inputsSensors.length; + const availableInputsSensorsCount = 94 - maxInputsCount; + const maxInputsSensorsCount = (availableInputsSensorsCount > 0) ? (availableInputsSensorsCount > inputsSensorsCount) ? inputsSensorsCount : availableInputsSensorsCount : 0; + if (maxInputsSensorsCount > 0) { + this.log.debug('prepareInputSensorServices'); + this.inputSensorServices = []; + for (let i = 0; i < maxInputsSensorsCount; i++) { + //get sensor + const inputSensor = inputsSensors[i]; + + //get sensor name + const inputSensorName = inputSensor.name; + + //get sensor reference + const inputSensorReference = inputSensor.reference; + + //get sensor display type + const inputSensorDisplayType = inputSensor.displayType || -1; + + if (inputSensorDisplayType === -1) { + return; + } + + const serviceType = [Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][inputSensorDisplayType]; + const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][inputSensorDisplayType]; + const inputSensorService = new serviceType(`${accessoryName} ${inputSensorName}`, `Sensor ${inputSensorName}`); + inputSensorService.getCharacteristic(characteristicType) + .onGet(async () => { + const state = this.power ? (this.reference === inputSensorReference) : false; + return state; + }); + + this.inputsSensorsReference.push(inputSensorReference); + this.inputSensorServices.push(inputSensorService); + accessory.addService(this.inputSensorServices[i]); + } + } + //Prepare buttons services //check available buttons and possible buttons count (max 94) const buttons = this.buttons; const buttonsCount = buttons.length; - const availableButtonshCount = 94 - maxInputsCount; - const maxButtonsCount = (availableButtonshCount > 0) ? (availableButtonshCount >= buttonsCount) ? buttonsCount : availableButtonshCount : 0; + const availableButtonsCount = (94 - (maxInputsCount + maxInputsSensorsCount)); + const maxButtonsCount = (availableButtonsCount > 0) ? (availableButtonsCount >= buttonsCount) ? buttonsCount : availableButtonsCount : 0; if (maxButtonsCount > 0) { this.log.debug('prepareButtonServices'); for (let i = 0; i < maxButtonsCount; i++) { diff --git a/package.json b/package.json index 33dff34..5759f42 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Xbox TV", "name": "homebridge-xbox-tv", - "version": "2.3.27", + "version": "2.4.0", "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.", "license": "MIT", "author": "grzegorz914", diff --git a/sample-config.json b/sample-config.json index 9561d1f..9dbbb65 100644 --- a/sample-config.json +++ b/sample-config.json @@ -14,83 +14,99 @@ "comment": "In this section set the port for Homebridge accessories." }, "accessories": [], - "platforms": [{ - "platform": "XboxTv", - "devices": [{ - "name": "Game Console", - "host": "192.168.1.6", - "xboxLiveId": "FD0000000000", - "clientId": "", - "clientSecret": "", - "userToken": "", - "userUhs": "", - "xboxWebApiToken": "", - "webApiControl": false, - "disableLogInfo": false, - "disableLogDeviceInfo": false, - "enableDebugMode": false, - "volumeControl": 0, - "infoButtonCommand": "nexus", - "getInputsFromDevice": false, - "filterGames": false, - "filterApps": false, - "filterSystemApps": false, - "filterDlc": false, - "inputs": [{ - "name": "A Way Out", - "reference": "AWayOut_zwks512sysnyr!AppAWayOut", - "oneStoreProductId": "", - "type": "APPLICATION" - }, + "platforms": [ + { + "platform": "XboxTv", + "devices": [ { - "name": "Apple TV", - "reference": "AppleInc.AppleTV_nzyj5cx40ttqa!App", - "oneStoreProductId": "", - "type": "APPLICATION" - }, - { - "name": "Battlefield 4", - "reference": "BFX_8s70symrha4j2!BF.App", - "oneStoreProductId": "", - "type": "APPLICATION" - }, - { - "name": "Cities: Skylines", - "reference": "ColossalOrder.CitiesSkylines_9dej7x9zwzxzc!App", - "oneStoreProductId": "C4GH8N6ZXG5L", - "type": "APPLICATION" - } - ], - "buttons": [{ - "name": "Play", - "command": "play", - "displayType": 0 - }, - { - "name": "Record Game DVR", - "command": "recordGameDvr", - "displayType": 0 - }, - { - "name": "Reboot", - "command": "reboot", - "displayType": 0 - }, - { - "name": "A Way Out", - "command": "switchAppGame", - "oneStoreProductId": "oneStoreProductId", - "displayType": 0 + "name": "Game Console", + "host": "192.168.1.6", + "xboxLiveId": "FD0000000000", + "clientId": "", + "clientSecret": "", + "userToken": "", + "userUhs": "", + "xboxWebApiToken": "", + "webApiControl": false, + "disableLogInfo": false, + "disableLogDeviceInfo": false, + "enableDebugMode": false, + "volumeControl": 0, + "infoButtonCommand": "nexus", + "getInputsFromDevice": false, + "filterGames": false, + "filterApps": false, + "filterSystemApps": false, + "filterDlc": false, + "inputs": [ + { + "name": "A Way Out", + "reference": "AWayOut_zwks512sysnyr!AppAWayOut", + "oneStoreProductId": "", + "type": "APPLICATION" + }, + { + "name": "Apple TV", + "reference": "AppleInc.AppleTV_nzyj5cx40ttqa!App", + "oneStoreProductId": "", + "type": "APPLICATION" + }, + { + "name": "Battlefield 4", + "reference": "BFX_8s70symrha4j2!BF.App", + "oneStoreProductId": "", + "type": "APPLICATION" + }, + { + "name": "Cities: Skylines", + "reference": "ColossalOrder.CitiesSkylines_9dej7x9zwzxzc!App", + "oneStoreProductId": "C4GH8N6ZXG5L", + "type": "APPLICATION" + } + ], + "buttons": [ + { + "name": "Play", + "command": "play", + "displayType": 0 + }, + { + "name": "Record Game DVR", + "command": "recordGameDvr", + "displayType": 0 + }, + { + "name": "Reboot", + "command": "reboot", + "displayType": 0 + }, + { + "name": "A Way Out", + "command": "switchAppGame", + "oneStoreProductId": "oneStoreProductId", + "displayType": 0 + } + ], + "sensorPower": false, + "sensorInput": false, + "sensorScreenSaver": false, + "sensorInputs": [ + { + "name": "Dashboard", + "reference": "Xbox.Dashboard_8wekyb3d8bbwe!Xbox.Dashboard.Application", + "displayType": 0 + } + ], + "enableMqtt": false, + "mqttHost": "192.168.1.33", + "mqttPort": 1883, + "mqttPrefix": "home/denon", + "mqttAuth": false, + "mqttUser": "user", + "mqttPass": "password", + "mqttDebug": false } - ], - "enableMqtt": false, - "mqttHost": "192.168.1.33", - "mqttPort": 1883, - "mqttPrefix": "home/denon", - "mqttAuth": false, - "mqttUser": "user", - "mqttPass": "password", - "mqttDebug": false - }] - }] + ] + } + ] } \ No newline at end of file diff --git a/src/packet/packer.js b/src/packet/packer.js index 16bb5a1..8e01ebb 100644 --- a/src/packet/packer.js +++ b/src/packet/packer.js @@ -7,6 +7,7 @@ class PACKER { constructor(type) { const packetType = type.slice(0, 2).toString('hex'); this.packetStructure = ''; + if (packetType in CONSTANS.Types) { const packetValue = type; type = CONSTANS.Types[packetType]; @@ -31,6 +32,10 @@ class PACKER { this.structure.set(key, value, protectedPayload); }; + setChannel(channelId) { + this.structure.setChannel(channelId); + }; + pack(xboxlocalapi = undefined) { return this.packetStructure.pack(xboxlocalapi); }; @@ -38,9 +43,5 @@ class PACKER { unpack(xboxlocalapi = undefined) { return this.packetStructure.unpack(xboxlocalapi); }; - - setChannel(channelId) { - this.structure.setChannel(channelId); - }; }; module.exports = PACKER; \ No newline at end of file diff --git a/src/packet/simple.js b/src/packet/simple.js index 94513ea..eb0fcde 100644 --- a/src/packet/simple.js +++ b/src/packet/simple.js @@ -8,6 +8,7 @@ class SIMPLE { this.packetFormat = packetFormat; this.packetData = packetData; this.packetDecoded = false; + this.structureProtected = false; const Type = { uInt32(value) { @@ -105,15 +106,13 @@ class SIMPLE { }, }; this.packet = Packet; - this.structure = Packet[packetFormat]; + // Load protected payload PacketStructure if (this.structure.protectedPayload !== undefined) { this.protectedPayload = new PacketStructure(); - const protectedStructure = Packet[`${packetFormat}Protected`]; - this.structureProtected = protectedStructure; + this.structureProtected = Packet[`${packetFormat}Protected`]; }; - this.structureProtected = this.structureProtected || false; }; set(key, value, isProtected = false) {