Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.6 kB · 69 lines
TSX
at mistress
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import RTNbleServer, { type NativeDIDRecord } from './NativeRTNbleServer';import type { Datetime, Did, DIDRecord } from './record';
export type { Datetime, Did, DIDRecord };
function toRecord(record: NativeDIDRecord): DIDRecord { return { did: record.did as Did, createdAt: record.createdAt };}
export function setOTP(otp: string): void { RTNbleServer.setOTP(otp);}
export function setDID(did: string): void { RTNbleServer.setDID(did);}
export function startGatt(): void { RTNbleServer.startGatt();}
export function stopGatt(): void { RTNbleServer.stopGatt();}
export function hasServerPermissions(): boolean { return RTNbleServer.hasServerPermissions();}
export function getRecord(): DIDRecord | null { const raw = RTNbleServer.getRecord(); if (!raw) { return null; }
try { const parsed = JSON.parse(raw) as Partial<NativeDIDRecord>; if ( typeof parsed.did === 'string' && typeof parsed.createdAt === 'string' ) { return { did: parsed.did as Did, createdAt: parsed.createdAt }; } } catch { // Fall through to "no record". }
return null;}
export function handleDID(handler: (record: DIDRecord) => void): void { RTNbleServer.setDIDHandler((record) => handler(toRecord(record)));}
export function startClient(otp: string): void { RTNbleServer.startClient(otp);}
export function stopClient(): void { RTNbleServer.stopClient();}
export function hasClientPermissions(): boolean { return RTNbleServer.hasClientPermissions();}
export function handleClientError(handler: (message: string) => void): void { RTNbleServer.setClientErrorHandler(handler);}