@elgato-stream-deck/tcp
Version:
An npm module for interfacing with select Elgato Stream Deck devices in node over tcp
44 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamDeckTcpWrapper = void 0;
const events_1 = require("events");
const core_1 = require("@elgato-stream-deck/core");
class StreamDeckTcpWrapper extends core_1.StreamDeckProxy {
#socket;
#device;
#tcpEvents = new events_1.EventEmitter();
get remoteAddress() {
return this.#socket.address;
}
get remotePort() {
return this.#socket.port;
}
get tcpEvents() {
return this.#tcpEvents;
}
constructor(socket, device, streamdeck) {
super(streamdeck);
this.#socket = socket;
this.#device = device;
this.#socket.on('disconnected', () => {
setImmediate(() => this.#tcpEvents.emit('disconnected'));
});
// Forward child info changes
if (this.#device.isPrimary) {
this.#device.onChildInfoChange = (info) => {
this.#tcpEvents.emit('childChange', info);
};
}
}
async getMacAddress() {
if (!this.#device.isPrimary)
throw new Error('Not supported on secondary devices');
const data = await this.#device.getFeatureReport(0x85, -1);
// This would be nice to do with a TextDecoder, but that doesn't support hex and we are in nodejs so don't need to
return Array.from(data.subarray(4, 10))
.map((v) => v.toString(16).padStart(2, '0'))
.join(':');
}
}
exports.StreamDeckTcpWrapper = StreamDeckTcpWrapper;
//# sourceMappingURL=tcpWrapper.js.map