homebridge-xbox-tv 2.9.9-beta.21 → 2.9.9-beta.23

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "2.9.9-beta.21",
4
+ "version": "2.9.9-beta.23",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -5,10 +5,7 @@ const CHANNELID = Buffer.from('\x00\x00\x00\x00\x00\x00\x00\x00');
5
5
  const CONSTANS = require('../constans.json');
6
6
 
7
7
  class MESSAGE {
8
- constructor(type, packetData = false) {
9
- this.packetType = type;
10
- this.packetData = packetData;
11
-
8
+ constructor() {
12
9
  const Type = {
13
10
  uInt32(value) {
14
11
  const packet = {
@@ -380,7 +377,7 @@ class MESSAGE {
380
377
  }
381
378
  }
382
379
 
383
- pack(xboxlocalapi) {
380
+ pack(xboxlocalapi, type, value) {
384
381
  const packetStructure = new PacketStructure();
385
382
  let packet = '';
386
383
 
@@ -394,7 +391,7 @@ class MESSAGE {
394
391
  header.writeUInt32(xboxlocalapi.getRequestNum());
395
392
  header.writeUInt32(xboxlocalapi.targetParticipantId);
396
393
  header.writeUInt32(xboxlocalapi.sourceParticipantId);
397
- header.writeBytes(this.setFlags(this.packetType));
394
+ header.writeBytes(this.setFlags(type));
398
395
  header.writeBytes(CHANNELID);
399
396
 
400
397
  if (packetStructure.toBuffer().length % 16 > 0) {
@@ -424,8 +421,8 @@ class MESSAGE {
424
421
  return packet;
425
422
  };
426
423
 
427
- unpack(xboxlocalapi = undefined) {
428
- const packetStructure = new PacketStructure(this.packetData);
424
+ unpack(xboxlocalapi = undefined, type, value = false) {
425
+ const packetStructure = new PacketStructure(type);
429
426
 
430
427
  let packet = {
431
428
  type: packetStructure.readBytes(2).toString('hex'),
@@ -444,7 +441,7 @@ class MESSAGE {
444
441
  // Lets decrypt the data when the payload is encrypted
445
442
  if (packet.protectedPayload) {
446
443
  const iv = xboxlocalapi.crypto.getIv();
447
- const key = xboxlocalapi.crypto.encrypt(this.packetData.slice(0, 16), iv);
444
+ const key = xboxlocalapi.crypto.encrypt(value.slice(0, 16), iv);
448
445
  let decryptedPayload = xboxlocalapi.crypto.decrypt(packet.protectedPayload, key);
449
446
  packet.decryptedPayload = new PacketStructure(decryptedPayload).toBuffer();
450
447
  decryptedPayload = new PacketStructure(decryptedPayload);
@@ -9,19 +9,23 @@ class PACKER {
9
9
  this.packetStructure = '';
10
10
 
11
11
  if (packetType in CONSTANS.Types) {
12
- const packetValue = type;
13
12
  type = CONSTANS.Types[packetType];
14
- this.packetStructure = this.loadPacketStructure(type, packetValue);
13
+ const value = type;
14
+ this.loadPacketStructure(type, value);
15
15
  } else {
16
- this.packetStructure = this.loadPacketStructure(type);
16
+ this.loadPacketStructure(type);
17
17
  };
18
18
  };
19
19
 
20
20
  loadPacketStructure(type, value = false) {
21
21
  if (type.slice(0, 6) == 'simple') {
22
- return new SimplePacket(type.slice(7), value);
22
+ this.type = type.slice(7);
23
+ this.value = value;
24
+ this.packetStructure = new SimplePacket();
23
25
  } else if (type.slice(0, 7) == 'message') {
24
- return new MessagePacket(type.slice(8), value);
26
+ this.type = type.slice(8);
27
+ this.value = value;
28
+ this.packetStructure = new MessagePacket();
25
29
  } else {
26
30
  return false;
27
31
  };
@@ -31,12 +35,12 @@ class PACKER {
31
35
  this.packetStructure.set(key, value, protectedPayload);
32
36
  };
33
37
 
34
- pack(xboxlocalapi = undefined) {
35
- return this.packetStructure.pack(xboxlocalapi);
38
+ pack(xboxlocalapi = undefined,) {
39
+ return this.packetStructure.pack(xboxlocalapi, this.type, this.value);
36
40
  };
37
41
 
38
- unpack(xboxlocalapi = undefined) {
39
- return this.packetStructure.unpack(xboxlocalapi);
42
+ unpack(xboxlocalapi = undefined,) {
43
+ return this.packetStructure.unpack(xboxlocalapi, this.type, this.value);
40
44
  };
41
45
  };
42
46
  module.exports = PACKER;
@@ -2,9 +2,8 @@
2
2
  const PacketStructure = require('./structure.js');
3
3
 
4
4
  class SIMPLE {
5
- constructor(type, packetData = false) {
5
+ constructor(type) {
6
6
  this.packetType = type;
7
- this.packetData = packetData;
8
7
  this.structureProtected = false;
9
8
 
10
9
  const Type = {
@@ -126,7 +125,7 @@ class SIMPLE {
126
125
  }
127
126
  }
128
127
 
129
- pack(xboxlocalapi = false) {
128
+ pack(xboxlocalapi = false, type, value = false) {
130
129
  const packetStructure = new PacketStructure();
131
130
  let packet = '';
132
131
 
@@ -160,7 +159,7 @@ class SIMPLE {
160
159
  }
161
160
  }
162
161
 
163
- switch (this.packetType) {
162
+ switch (type) {
164
163
  case 'powerOn':
165
164
  packet = this.pack1(Buffer.from('dd02', 'hex'), packetStructure.toBuffer(), '');
166
165
  break;
@@ -237,9 +236,9 @@ class SIMPLE {
237
236
  return packet;
238
237
  };
239
238
 
240
- unpack(xboxlocalapi = undefined) {
241
- const packetStructure = new PacketStructure(this.packetData);
242
- const packetType = packetStructure.readBytes(2).toString('hex') === 'dd02' ? 'powerOn' : this.packetType;
239
+ unpack(xboxlocalapi = undefined, type, value = false) {
240
+ const packetStructure = new PacketStructure(value);
241
+ const packetType = packetStructure.readBytes(2).toString('hex') === 'dd02' ? 'powerOn' : type;
243
242
 
244
243
  let packet = {
245
244
  type: packetType,
@@ -268,7 +267,7 @@ class SIMPLE {
268
267
  decryptedPayload = decryptedPayload.slice(0, protectedPayloadLength);
269
268
  decryptedPayload = new PacketStructure(decryptedPayload);
270
269
 
271
- const protectedStructure = this.packet[`${this.packetType}Protected`];
270
+ const protectedStructure = this.packet[`${type}Protected`];
272
271
  packet.protectedPayload = {};
273
272
 
274
273
  for (const name in protectedStructure) {