XuqmGroup-RNSDK/packages/common/src/sdk.ts
XuqmGroup 67d54bf1f2 docs(sdk): 添加 Android SDK 文档和 API 设计规范
- 新增 Android SDK 使用文档,包含模块结构、集成方式和快速开始指南
- 添加 SDK API 重设计规范,统一初始化和登录接口设计
- 补充安全设计规范,完善 UserSig 鉴权和敏感数据处理方案
- 创建平台 REST API 规范,定义服务端到服务端的调用接口
- 添加离线推送架构设计,集成各大厂商推送服务与 IM 联动方案
2026-04-29 15:46:40 +08:00

53 行
1.8 KiB
TypeScript

import { initConfigFromRemote, isInitialized, type XuqmInitOptions, setUserId as setCommonUserId, getUserId as getCommonUserId } from './config'
import { DEFAULT_IM_WS_URL, DEFAULT_TENANT_PLATFORM_URL } from './constants'
export const XuqmSDK = {
/**
* @param options.appKey - Your application key (from the tenant platform)
* @param options.debug - Enable verbose logging
*/
async initialize(options: XuqmInitOptions): Promise<void> {
if (isInitialized()) return
const configUrl = `${DEFAULT_TENANT_PLATFORM_URL}/api/sdk/config?appId=${options.appKey}`
try {
const res = await fetch(configUrl)
const json = await res.json()
const remote = json.data ?? json
initConfigFromRemote(options, {
imWsUrl: remote.imWsUrl,
fileServiceUrl: remote.fileServiceUrl,
apiUrl: remote.imApiUrl ?? DEFAULT_TENANT_PLATFORM_URL,
})
} catch (e) {
// Fallback: construct URLs from the built-in platform endpoint
initConfigFromRemote(options, {
imWsUrl: DEFAULT_IM_WS_URL,
fileServiceUrl: DEFAULT_TENANT_PLATFORM_URL,
apiUrl: DEFAULT_TENANT_PLATFORM_URL,
})
if (options.debug) console.warn('[XuqmSDK] Config fetch failed, using fallback URLs', e)
}
},
/**
* @param options.appKey - Your application key (from the tenant platform)
* @param options.debug - Enable verbose logging
*/
init(options: XuqmInitOptions): void {
if (isInitialized()) return
initConfigFromRemote(options, {
imWsUrl: DEFAULT_IM_WS_URL,
fileServiceUrl: DEFAULT_TENANT_PLATFORM_URL,
apiUrl: DEFAULT_TENANT_PLATFORM_URL,
})
},
setUserId(userId: string | null): void {
setCommonUserId(userId)
},
getUserId(): string | null {
return getCommonUserId()
},
}