homebridge-xbox-tv 3.7.9-beta.21 → 3.7.9-beta.22
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 +1 -1
- package/src/localApi/xboxlocalapi.js +4 -88
- package/src/xboxdevice.js +1 -4
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ class XboxLocalApi extends EventEmitter {
|
|
|
30
30
|
this.channels = [];
|
|
31
31
|
this.channelRequestId = 0;
|
|
32
32
|
this.mediaRequestId = 0;
|
|
33
|
+
this.fragments = {};
|
|
33
34
|
|
|
34
35
|
//create impulse generator
|
|
35
36
|
this.impulseGenerator = new ImpulseGenerator();
|
|
@@ -205,8 +206,8 @@ class XboxLocalApi extends EventEmitter {
|
|
|
205
206
|
};
|
|
206
207
|
|
|
207
208
|
const channelRequestId = LocalApi.Channels.System[channelName].Id
|
|
208
|
-
const channelCommunicationId = this.channels[
|
|
209
|
-
const channelOpen = this.channels[
|
|
209
|
+
const channelCommunicationId = this.channels[channelRequestId]?.id ?? -1;
|
|
210
|
+
const channelOpen = this.channels[channelRequestId]?.open ?? false;
|
|
210
211
|
|
|
211
212
|
if (channelCommunicationId === -1 || !channelOpen) {
|
|
212
213
|
this.emit('warn', `Channel Id: ${channelCommunicationId}, state: ${channelOpen ? 'Open' : 'Closed'}, trying to open it`);
|
|
@@ -278,91 +279,6 @@ class XboxLocalApi extends EventEmitter {
|
|
|
278
279
|
return true;
|
|
279
280
|
};
|
|
280
281
|
|
|
281
|
-
// Dodaj do klasy XboxLocalApi:
|
|
282
|
-
|
|
283
|
-
async sendSystemButton(channelName, command) {
|
|
284
|
-
if (!this.isConnected) {
|
|
285
|
-
this.emit('warn', `Cannot send command, console not connected`);
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const channelInfo = LocalApi.Channels.System[channelName];
|
|
290
|
-
if (!channelInfo) {
|
|
291
|
-
this.emit('warn', `Unknown channel: ${channelName}`);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
let channel = this.channels.find(c => c.id !== -1);
|
|
296
|
-
if (!channel) {
|
|
297
|
-
// Otwórz kanał jeśli nie istnieje
|
|
298
|
-
await this.channelOpen(channelInfo.Id, channelInfo.Uuid);
|
|
299
|
-
channel = this.channels.find(c => c.id !== -1);
|
|
300
|
-
if (!channel) {
|
|
301
|
-
this.emit('warn', `Failed to open channel: ${channelName}`);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const channelId = channel.id;
|
|
307
|
-
|
|
308
|
-
switch (channelInfo.Id) {
|
|
309
|
-
case 0: // Gamepad
|
|
310
|
-
await this._sendGamepadCommand(command, channelId);
|
|
311
|
-
break;
|
|
312
|
-
case 1: // TvRemote
|
|
313
|
-
await this._sendTvRemoteCommand(command, channelId);
|
|
314
|
-
break;
|
|
315
|
-
case 2: // Media
|
|
316
|
-
await this._sendMediaCommand(command, channelId);
|
|
317
|
-
break;
|
|
318
|
-
default:
|
|
319
|
-
this.emit('warn', `Unhandled channel type: ${channelName}`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Prywatne metody do wysyłania komend
|
|
324
|
-
async _sendGamepadCommand(buttons, channelId) {
|
|
325
|
-
const timestamp = Buffer.from(`000${Date.now()}`, 'hex');
|
|
326
|
-
const press = new MessagePacket('gamepad');
|
|
327
|
-
press.set('timestamp', timestamp);
|
|
328
|
-
press.set('buttons', buttons);
|
|
329
|
-
let seq = await this.getSequenceNumber();
|
|
330
|
-
await this.sendSocketMessage(press.pack(this.crypto, seq, this.sourceParticipantId, channelId), 'gamepad');
|
|
331
|
-
|
|
332
|
-
// Release buttons
|
|
333
|
-
setTimeout(async () => {
|
|
334
|
-
const release = new MessagePacket('gamepad');
|
|
335
|
-
release.set('timestamp', timestamp);
|
|
336
|
-
release.set('buttons', LocalApi.Channels.System.Input.Commands.unpress);
|
|
337
|
-
seq = await this.getSequenceNumber();
|
|
338
|
-
await this.sendSocketMessage(release.pack(this.crypto, seq, this.sourceParticipantId, channelId), 'gamepadUnpress');
|
|
339
|
-
}, 150);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
async _sendTvRemoteCommand(command, channelId) {
|
|
343
|
-
const seq = await this.getSequenceNumber();
|
|
344
|
-
const jsonReq = JSON.stringify({
|
|
345
|
-
msgid: `2ed6c0fd.${seq}`,
|
|
346
|
-
request: LocalApi.Channels.System.TvRemote.MessageType.SendKey,
|
|
347
|
-
params: { button_id: command, device_id: null }
|
|
348
|
-
});
|
|
349
|
-
const json = new MessagePacket('json');
|
|
350
|
-
json.set('json', jsonReq);
|
|
351
|
-
await this.sendSocketMessage(json.pack(this.crypto, seq, this.sourceParticipantId, channelId), 'json');
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
async _sendMediaCommand(command, channelId) {
|
|
355
|
-
const requestIdHex = (`0000000000000000${this.mediaRequestId}`).slice(-16);
|
|
356
|
-
const media = new MessagePacket('mediaCommand');
|
|
357
|
-
media.set('requestId', Buffer.from(requestIdHex, 'hex'));
|
|
358
|
-
media.set('titleId', 0);
|
|
359
|
-
media.set('command', command);
|
|
360
|
-
const seq = await this.getSequenceNumber();
|
|
361
|
-
await this.sendSocketMessage(media.pack(this.crypto, seq, this.sourceParticipantId, channelId), 'mediaCommand');
|
|
362
|
-
this.mediaRequestId++;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
282
|
async disconnect() {
|
|
367
283
|
if (this.enableDebugMode) this.emit('debug', 'Disconnecting...');
|
|
368
284
|
|
|
@@ -475,7 +391,7 @@ class XboxLocalApi extends EventEmitter {
|
|
|
475
391
|
switch (type) {
|
|
476
392
|
case 'json':
|
|
477
393
|
// Object to hold fragments
|
|
478
|
-
const fragments =
|
|
394
|
+
const fragments = this.fragments;
|
|
479
395
|
const jsonMessage = JSON.parse(packet.payloadProtected.json);
|
|
480
396
|
const datagramId = jsonMessage.datagramId;
|
|
481
397
|
|
package/src/xboxdevice.js
CHANGED
|
@@ -658,10 +658,7 @@ class XboxDevice extends EventEmitter {
|
|
|
658
658
|
break;
|
|
659
659
|
}
|
|
660
660
|
|
|
661
|
-
|
|
662
|
-
await this.xboxLocalApi.sendSystemButton('Input', LocalApi.Channels.System.Input.Commands[command]);
|
|
663
|
-
//await xboxLocalApi.sendSystemButton('TvRemote', LocalApi.Channels.System.TvRemote.Buttons.Power);
|
|
664
|
-
//await xboxLocalApi.sendSystemButton('Media', LocalApi.Channels.System.Media.Commands[command]);
|
|
661
|
+
await this.xboxWebApi.send(channelName, 'InjectKey', [{ 'keyType': command }]);
|
|
665
662
|
if (!this.disableLogInfo) this.emit('info', `Remote Key: ${command}`);
|
|
666
663
|
} catch (error) {
|
|
667
664
|
this.emit('warn', `set Remote Key error: ${JSON.stringify(error, null, 2)}`);
|