From 6a9a80d9173682abeb10c5d497b119c6908b8b30 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht Date: Thu, 7 Nov 2024 12:30:26 +0100 Subject: [PATCH] fix: do not rely on private methods internally Signed-off-by: Berend Sliedrecht --- src/MdocDataTransfer.ts | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/MdocDataTransfer.ts b/src/MdocDataTransfer.ts index 961f0de..cf20ecc 100644 --- a/src/MdocDataTransfer.ts +++ b/src/MdocDataTransfer.ts @@ -24,27 +24,23 @@ class MdocDataTransfer { return await mDocNativeModule.startQrEngagement() } - private onDeviceRequest(cb: (payload: OnRequestReceivedEventPayload) => Promise | void) { - return mDocNativeModuleEventEmitter.addListener( - MdocDataTransferEvent.OnRequestReceived, - (payload) => - cb({ - deviceRequest: new Uint8Array(payload.deviceRequest), - sessionTranscript: new Uint8Array(payload.sessionTranscript), - }) - ) - } - - private onResponseSent(cb: (payload: OnResponseSendPayload) => Promise | void) { - return mDocNativeModuleEventEmitter.addListener(MdocDataTransferEvent.OnRequestReceived, cb) - } - public async waitForDeviceRequest() { - return await new Promise>((resolve) => this.onDeviceRequest(resolve)) + return await new Promise>((resolve) => + mDocNativeModuleEventEmitter.addListener( + MdocDataTransferEvent.OnRequestReceived, + (payload) => + resolve({ + deviceRequest: new Uint8Array(payload.deviceRequest), + sessionTranscript: new Uint8Array(payload.sessionTranscript), + }) + ) + ) } public async sendDeviceResponse(deviceResponse: Uint8Array) { - const p = new Promise((resolve) => this.onResponseSent(resolve)) + const p = new Promise((resolve) => + mDocNativeModuleEventEmitter.addListener(MdocDataTransferEvent.OnResponseSent, resolve) + ) mDocNativeModule.sendDeviceResponse(deviceResponse.join(':')) await p }