Import apps/android/src/services/network-route.ts

This commit is contained in:
QQ 2026-11-14 14:18:18 +08:00
parent 0d908bea57
commit 321c6eec3e
1 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import NetInfo from '@react-native-community/netinfo'
import { automaticPreferredTransports, networkRouteForNativeType, type PreferredTransport } from '../lib/network-route'
/**
* Reads the native network type before opening the encrypted transport. An
* unknown result keeps LAN enabled: ICE host candidates remain safe and will
* fall back to P2P, TURN, then Relay if no local route is available.
*/
export async function resolveAutomaticPreferredTransports(): Promise<PreferredTransport[]> {
try {
const state = await NetInfo.fetch()
return automaticPreferredTransports(networkRouteForNativeType(state.type))
} catch {
return automaticPreferredTransports('unknown')
}
}