37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { requireOptionalNativeModule } from 'expo-modules-core'
|
|
|
|
export type EasyTierConfigInput = {
|
|
networkName: string
|
|
networkSecret: string
|
|
peerUrls: string[]
|
|
}
|
|
|
|
type NativeModule = {
|
|
isAvailable: () => boolean
|
|
saveAndPrepareTunnel: (configJson: string) => Promise<Record<string, unknown>>
|
|
checkVpnPermissionGranted: () => Promise<Record<string, unknown>>
|
|
}
|
|
|
|
const Native = requireOptionalNativeModule<NativeModule>('ExpoEasyTierVpn')
|
|
|
|
export function isExpoEasyTierVpnAvailable(): boolean {
|
|
try {
|
|
return Native?.isAvailable?.() === true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export async function saveAndPrepareTunnel(config: EasyTierConfigInput): Promise<Record<string, unknown>> {
|
|
if (!Native?.saveAndPrepareTunnel) {
|
|
return { ok: false, reason: 'native_module_missing' }
|
|
}
|
|
return Native.saveAndPrepareTunnel(JSON.stringify(config))
|
|
}
|
|
|
|
export async function checkVpnPermissionGranted(): Promise<boolean> {
|
|
if (!Native?.checkVpnPermissionGranted) return false
|
|
const r = await Native.checkVpnPermissionGranted()
|
|
return r?.granted === true
|
|
}
|