XuqmGroup-RNSDK/packages/common/src/config.ts

52 行
1.3 KiB
TypeScript

export interface XuqmInitOptions {
appId: string
serverUrl: string // e.g. "http://192.168.116.9:8081" — SDK fetches config from here
appKey?: string
debug?: boolean
}
export interface XuqmConfig {
appId: string
appKey: string
serverUrl: string
apiBaseUrl: string // im-service base URL
imWsUrl: string // fetched from remote config
fileServiceUrl: string // fetched from remote config
debug: boolean
}
let _config: XuqmConfig | null = null
let _userId: string | null = null
export function initConfigFromRemote(
options: XuqmInitOptions,
remote: { imWsUrl: string; fileServiceUrl: string; apiBaseUrl: string },
): void {
_config = {
appId: options.appId,
appKey: options.appKey ?? options.appId,
serverUrl: options.serverUrl,
apiBaseUrl: remote.apiBaseUrl,
imWsUrl: remote.imWsUrl,
fileServiceUrl: remote.fileServiceUrl,
debug: options.debug ?? false,
}
}
export function getConfig(): XuqmConfig {
if (!_config) throw new Error('[XuqmSDK] Not initialized — call XuqmSDK.initialize() first.')
return _config
}
export function setUserId(userId: string | null): void {
_userId = userId
}
export function getUserId(): string | null {
return _userId
}
export function isInitialized(): boolean {
return _config !== null
}