Skip to content

Commit

Permalink
fix: do not rely on private methods internally
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
Berend Sliedrecht committed Nov 7, 2024
1 parent 6235f35 commit 6a9a80d
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/MdocDataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,23 @@ class MdocDataTransfer {
return await mDocNativeModule.startQrEngagement()
}

private onDeviceRequest(cb: (payload: OnRequestReceivedEventPayload<Uint8Array>) => Promise<void> | void) {
return mDocNativeModuleEventEmitter.addListener<OnRequestReceivedEventPayload>(
MdocDataTransferEvent.OnRequestReceived,
(payload) =>
cb({
deviceRequest: new Uint8Array(payload.deviceRequest),
sessionTranscript: new Uint8Array(payload.sessionTranscript),
})
)
}

private onResponseSent(cb: (payload: OnResponseSendPayload) => Promise<void> | void) {
return mDocNativeModuleEventEmitter.addListener<OnResponseSendPayload>(MdocDataTransferEvent.OnRequestReceived, cb)
}

public async waitForDeviceRequest() {
return await new Promise<OnRequestReceivedEventPayload<Uint8Array>>((resolve) => this.onDeviceRequest(resolve))
return await new Promise<OnRequestReceivedEventPayload<Uint8Array>>((resolve) =>
mDocNativeModuleEventEmitter.addListener<OnRequestReceivedEventPayload>(
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<OnResponseSendPayload>(MdocDataTransferEvent.OnResponseSent, resolve)
)
mDocNativeModule.sendDeviceResponse(deviceResponse.join(':'))
await p
}
Expand Down

0 comments on commit 6a9a80d

Please sign in to comment.