UNPKG

@ledgerhq/live-common

Version:
34 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = openTransportAsSubject; const rxjs_1 = require("rxjs"); const deviceAccess_1 = require("./deviceAccess"); function openTransportAsSubject({ deviceId, }) { const subject = new rxjs_1.Subject(); (0, deviceAccess_1.withDevice)(deviceId)(transport => { // The input part of the bidirectional communication subject.subscribe({ next: e => { /** * Receiving an event from the ipc bridge allows us to pass a msg * into an ongoing withDevice job. Allowing to exchange messages with the * transport exposed from the job. */ if (e?.type === "input-frame") { subject.next({ type: "device-request", data: e.apduHex }); // TODO important avoiding collisions, also types will be broken transport .exchange(Buffer.from(e.apduHex, "hex")) .then(response => subject.next({ type: "device-response", data: response.toString("hex"), })) .catch(error => subject.next({ type: "error", error })); } }, }); return subject; }).subscribe(); return subject; } //# sourceMappingURL=openTransportAsSubject.js.map