diff --git a/README.md b/README.md index 260ab8e..3222f8f 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ yarn add @xuqm/rn-common @xuqm/rn-im @xuqm/rn-push @xuqm/rn-update ## 入口 -- `XuqmSDK.initialize({ appKey, debug })` -- `XuqmSDK.login({ userId, userSig, profile, expiresAt, refreshUserSig })` +- `XuqmSDK.initialize({ appKey, logLevel })` +- `XuqmSDK.login({ userId, userSig })` - `XuqmSDK.logout()` - `ImSDK` - `PushSDK` diff --git a/packages/im/src/ImSDK.ts b/packages/im/src/ImSDK.ts index 80caf9d..cefae04 100644 --- a/packages/im/src/ImSDK.ts +++ b/packages/im/src/ImSDK.ts @@ -283,33 +283,18 @@ function resolveMimeTypeFromUri(uri: string, fallback: string): string { export const ImSDK = { /** - * Login to IM service. Fetches a token internally and opens the WebSocket connection. - * Pass dbName to enable local SQLite message caching (requires @nozbe/watermelondb). + * Login to IM service with a pre-obtained userSig and open the WebSocket connection. */ - async login(userId: string, dbName?: string): Promise { + async login(userId: string, userSig: string): Promise { const config = getConfig() - const device = await getDeviceInfo() client?.disconnect() - const res = await apiRequest<{ token: string }>('/api/im/auth/login', { - method: 'POST', - skipAuth: true, - params: { - appId: config.appId, - userId, - deviceId: device.deviceId, - platform: device.platform, - brand: device.brand, - model: device.model, - osVersion: device.osVersion, - }, - }) - await _saveToken(res.token) + await _saveToken(userSig) _currentUserId = userId setCommonUserId(userId) - ImDatabase.init(dbName ?? buildDbName(config.appKey, userId)) + ImDatabase.init(buildDbName(config.appKey, userId)) - client = new ImClient(config.imWsUrl, res.token, config.appId) + client = new ImClient(config.imWsUrl, userSig, config.appId) client.addListener({ onConnected: () => { _syncHistoryForAllConversations().catch(() => {}) @@ -318,32 +303,6 @@ export const ImSDK = { void client.connect() }, - /** - * Login with a pre-obtained IM token (e.g. from demo-service). - * Sets up the IM connection without calling the auth endpoint. - */ - async loginWithToken(userId: string, token: string, dbName?: string): Promise { - const config = getConfig() - client?.disconnect() - await _saveToken(token) - _currentUserId = userId - setCommonUserId(userId) - - ImDatabase.init(dbName ?? buildDbName(config.appKey, userId)) - - client = new ImClient(config.imWsUrl, token, config.appId) - client.addListener({ - onConnected: () => { - _syncHistoryForAllConversations().catch(() => {}) - }, - }) - void client.connect() - }, - - async loginWithUserSig(userId: string, userSig: string, dbName?: string): Promise { - return ImSDK.loginWithToken(userId, userSig, dbName) - }, - async reconnect(): Promise { const config = getConfig() const token = await _getToken() diff --git a/packages/im/src/upload.ts b/packages/im/src/upload.ts index f59a85c..8160644 100644 --- a/packages/im/src/upload.ts +++ b/packages/im/src/upload.ts @@ -24,7 +24,7 @@ export async function uploadFile( const config = getConfig() const token = await _getToken() if (!token) { - throw new Error('[uploadFile] No active session — call ImSDK.loginWithToken() first.') + throw new Error('[uploadFile] No active session — call XuqmSDK.login() first.') } const form = new FormData() diff --git a/src/sdk.ts b/src/sdk.ts index dad5230..b341d07 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -12,7 +12,7 @@ let currentSession: UnifiedLoginOptions | null = null async function applyLoginSession(session: UnifiedLoginOptions): Promise { setCommonUserId(session.userId) try { - await ImSDK.loginWithUserSig(session.userId, session.userSig) + await ImSDK.login(session.userId, session.userSig) } catch (error) { setCommonUserId(null) currentSession = null