2026-04-24 16:16:31 +08:00
|
|
|
export interface XuqmInitOptions {
|
2026-04-29 15:46:40 +08:00
|
|
|
appKey: string
|
2026-04-24 16:16:31 +08:00
|
|
|
debug?: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface XuqmConfig {
|
|
|
|
|
appId: string
|
|
|
|
|
appKey: string
|
2026-04-29 15:46:40 +08:00
|
|
|
apiUrl: string
|
|
|
|
|
imWsUrl: string
|
2026-04-25 16:41:19 +08:00
|
|
|
fileServiceUrl: string // fetched from remote config
|
2026-04-24 16:16:31 +08:00
|
|
|
debug: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let _config: XuqmConfig | null = null
|
2026-04-28 16:55:12 +08:00
|
|
|
let _userId: string | null = null
|
2026-04-24 16:16:31 +08:00
|
|
|
|
2026-04-25 16:41:19 +08:00
|
|
|
export function initConfigFromRemote(
|
|
|
|
|
options: XuqmInitOptions,
|
2026-04-29 15:46:40 +08:00
|
|
|
remote: { imWsUrl: string; fileServiceUrl: string; apiUrl: string },
|
2026-04-25 16:41:19 +08:00
|
|
|
): void {
|
2026-04-24 16:16:31 +08:00
|
|
|
_config = {
|
2026-04-29 15:46:40 +08:00
|
|
|
appId: options.appKey,
|
|
|
|
|
appKey: options.appKey,
|
|
|
|
|
apiUrl: remote.apiUrl,
|
2026-04-25 16:41:19 +08:00
|
|
|
imWsUrl: remote.imWsUrl,
|
|
|
|
|
fileServiceUrl: remote.fileServiceUrl,
|
|
|
|
|
debug: options.debug ?? false,
|
2026-04-24 16:16:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getConfig(): XuqmConfig {
|
2026-04-25 16:41:19 +08:00
|
|
|
if (!_config) throw new Error('[XuqmSDK] Not initialized — call XuqmSDK.initialize() first.')
|
2026-04-24 16:16:31 +08:00
|
|
|
return _config
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 16:55:12 +08:00
|
|
|
export function setUserId(userId: string | null): void {
|
|
|
|
|
_userId = userId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getUserId(): string | null {
|
|
|
|
|
return _userId
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 16:16:31 +08:00
|
|
|
export function isInitialized(): boolean {
|
|
|
|
|
return _config !== null
|
|
|
|
|
}
|