2026-04-24 16:16:31 +08:00
|
|
|
|
export interface XuqmInitOptions {
|
2026-04-29 15:46:40 +08:00
|
|
|
|
appKey: string
|
2026-06-15 10:37:57 +08:00
|
|
|
|
platformUrl?: string // 不传则使用内置默认公有平台地址
|
2026-04-24 16:16:31 +08:00
|
|
|
|
debug?: boolean
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface XuqmConfig {
|
|
|
|
|
|
appKey: string
|
2026-04-29 15:46:40 +08:00
|
|
|
|
apiUrl: string
|
|
|
|
|
|
imWsUrl: string
|
2026-06-15 10:57:55 +08:00
|
|
|
|
fileServiceUrl: string
|
|
|
|
|
|
licenseUrl: string
|
2026-04-24 16:16:31 +08:00
|
|
|
|
debug: boolean
|
2026-06-15 10:57:55 +08:00
|
|
|
|
// 服务开通状态(由平台远程配置决定)
|
|
|
|
|
|
imEnabled: boolean
|
|
|
|
|
|
pushEnabled: boolean
|
|
|
|
|
|
licenseEnabled: boolean
|
2026-06-16 17:39:18 +08:00
|
|
|
|
// 崩溃采集服务(rn-bugcollect 使用)
|
|
|
|
|
|
bugCollectApiUrl: string
|
|
|
|
|
|
bugCollectEnabled: boolean
|
2026-04-24 16:16:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-15 01:44:20 +08:00
|
|
|
|
export interface XuqmUserInfo {
|
2026-06-15 10:57:55 +08:00
|
|
|
|
userId: string
|
|
|
|
|
|
userSig?: string // IM 登录凭证;未开通 IM 时可不传
|
2026-06-15 01:44:20 +08:00
|
|
|
|
name?: string
|
|
|
|
|
|
email?: string
|
|
|
|
|
|
phone?: string
|
2026-06-15 10:57:55 +08:00
|
|
|
|
avatar?: string
|
2026-06-15 01:44:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-15 10:57:55 +08:00
|
|
|
|
// ─── Internal state ────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
let _config: XuqmConfig | null = null
|
|
|
|
|
|
let _userId: string | null = null
|
2026-06-15 01:44:20 +08:00
|
|
|
|
let _userInfo: XuqmUserInfo | null = null
|
2026-06-15 10:57:55 +08:00
|
|
|
|
const _userInfoHandlers: Array<(info: XuqmUserInfo | null) => void> = []
|
|
|
|
|
|
|
|
|
|
|
|
// ─── Config ────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
export interface XuqmRemoteConfig {
|
|
|
|
|
|
imApiUrl?: string
|
|
|
|
|
|
apiUrl?: string
|
|
|
|
|
|
imWsUrl?: string
|
|
|
|
|
|
fileServiceUrl?: string
|
|
|
|
|
|
licenseUrl?: string
|
|
|
|
|
|
imEnabled?: boolean
|
|
|
|
|
|
pushEnabled?: boolean
|
|
|
|
|
|
licenseEnabled?: boolean
|
2026-06-16 17:39:18 +08:00
|
|
|
|
bugCollectApiUrl?: string
|
|
|
|
|
|
bugCollectEnabled?: boolean
|
2026-06-15 10:57:55 +08:00
|
|
|
|
}
|
2026-06-15 01:44:20 +08:00
|
|
|
|
|
2026-04-25 16:41:19 +08:00
|
|
|
|
export function initConfigFromRemote(
|
|
|
|
|
|
options: XuqmInitOptions,
|
2026-06-15 10:57:55 +08:00
|
|
|
|
remote: XuqmRemoteConfig,
|
2026-04-25 16:41:19 +08:00
|
|
|
|
): void {
|
2026-06-15 10:57:55 +08:00
|
|
|
|
const apiUrl = remote.imApiUrl ?? remote.apiUrl ?? ''
|
2026-04-24 16:16:31 +08:00
|
|
|
|
_config = {
|
2026-06-15 10:57:55 +08:00
|
|
|
|
appKey: options.appKey,
|
|
|
|
|
|
apiUrl,
|
|
|
|
|
|
imWsUrl: remote.imWsUrl ?? '',
|
|
|
|
|
|
fileServiceUrl: remote.fileServiceUrl ?? apiUrl,
|
|
|
|
|
|
licenseUrl: remote.licenseUrl ?? apiUrl,
|
|
|
|
|
|
debug: options.debug ?? false,
|
|
|
|
|
|
imEnabled: remote.imEnabled ?? !!remote.imWsUrl,
|
|
|
|
|
|
pushEnabled: remote.pushEnabled ?? true,
|
|
|
|
|
|
licenseEnabled: remote.licenseEnabled ?? false,
|
2026-06-16 17:39:18 +08:00
|
|
|
|
bugCollectApiUrl: remote.bugCollectApiUrl ?? '',
|
|
|
|
|
|
bugCollectEnabled: remote.bugCollectEnabled ?? 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-06-15 10:57:55 +08:00
|
|
|
|
export function isInitialized(): boolean {
|
|
|
|
|
|
return _config !== null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ─── UserId ────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
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-06-15 10:57:55 +08:00
|
|
|
|
// ─── UserInfo + subscribers ────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
export function _registerUserInfoHandler(handler: (info: XuqmUserInfo | null) => void): void {
|
|
|
|
|
|
_userInfoHandlers.push(handler)
|
2026-04-24 16:16:31 +08:00
|
|
|
|
}
|
2026-06-15 01:44:20 +08:00
|
|
|
|
|
|
|
|
|
|
export function setUserInfo(info: XuqmUserInfo | null): void {
|
|
|
|
|
|
_userInfo = info
|
2026-06-15 10:57:55 +08:00
|
|
|
|
_userId = info?.userId ?? null
|
|
|
|
|
|
for (const handler of _userInfoHandlers) {
|
|
|
|
|
|
try { handler(info) } catch { /* sub-SDK errors must not break the chain */ }
|
2026-06-15 01:44:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getUserInfo(): XuqmUserInfo | null {
|
|
|
|
|
|
return _userInfo
|
|
|
|
|
|
}
|