2026-05-11 12:06:17 +08:00
|
|
|
|
function trimTrailingSlashes(value: string): string {
|
|
|
|
|
|
return value.replace(/\/+$/, '');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-19 15:43:16 +08:00
|
|
|
|
export type AppVariant = 'development' | 'staging' | 'production';
|
|
|
|
|
|
|
|
|
|
|
|
function resolveAppVariant(): AppVariant {
|
|
|
|
|
|
const raw = process.env.EXPO_PUBLIC_APP_VARIANT;
|
|
|
|
|
|
if (raw === 'development' || raw === 'staging' || raw === 'production') {
|
|
|
|
|
|
return raw;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
|
return 'development';
|
|
|
|
|
|
}
|
|
|
|
|
|
return 'production';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Shown on About screen for dev/staging builds only. */
|
|
|
|
|
|
export function shouldShowAboutBackendUrl(variant: AppVariant = appVariant): boolean {
|
|
|
|
|
|
return variant === 'development' || variant === 'staging';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const appVariant = resolveAppVariant();
|
|
|
|
|
|
|
2026-03-19 01:12:17 +08:00
|
|
|
|
export const config = {
|
2026-05-11 12:06:17 +08:00
|
|
|
|
apiBaseUrl: trimTrailingSlashes(
|
|
|
|
|
|
process.env.EXPO_PUBLIC_API_URL ?? 'http://192.168.10.151:8000',
|
|
|
|
|
|
),
|
|
|
|
|
|
wsBaseUrl: trimTrailingSlashes(
|
|
|
|
|
|
process.env.EXPO_PUBLIC_WS_URL ?? 'ws://192.168.10.151:8000',
|
|
|
|
|
|
),
|
2026-03-19 01:12:17 +08:00
|
|
|
|
isDebugMode: __DEV__,
|
2026-05-19 15:43:16 +08:00
|
|
|
|
appVariant,
|
|
|
|
|
|
showAboutBackendUrl: shouldShowAboutBackendUrl(),
|
2026-03-19 01:12:17 +08:00
|
|
|
|
|
|
|
|
|
|
api: {
|
|
|
|
|
|
timeoutMs: 30_000,
|
|
|
|
|
|
refreshPath: '/api/auth/refresh',
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
ws: {
|
|
|
|
|
|
reconnectMaxRetries: 10,
|
|
|
|
|
|
reconnectBaseDelayMs: 1_000,
|
|
|
|
|
|
reconnectMaxDelayMs: 30_000,
|
|
|
|
|
|
heartbeatIntervalMs: 30_000,
|
2026-05-13 17:12:08 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 仅当 App 处于 `background` 连续超过该毫秒数才释放当前会话 WebSocket。
|
|
|
|
|
|
* 短暂切到其它应用再返回时保持连接,避免反复重连。
|
|
|
|
|
|
*/
|
|
|
|
|
|
backgroundDisconnectAfterMs: 300_000,
|
2026-03-19 01:12:17 +08:00
|
|
|
|
},
|
|
|
|
|
|
} as const;
|