diff --git a/docs/README.md b/docs/README.md index 6af8641..242b28b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,6 +16,7 @@ | 配置项 | 值 | |--------|-----| | API 域名 | `https://dev.xuqinmin.com` | +| 登录服务 | `demo-service`(`/api/demo/auth/*`) | | IM WebSocket | `wss://dev.xuqinmin.com/ws/im` | | 演示 AppId | `ak_demo_chat` | | 演示用户 | `demo_alice`(Alice)、`demo_bob`(Bob) | @@ -136,6 +137,7 @@ cd XuqmGroup-RNChatDemo | 路径前缀 | 对应服务 | 端口 | |----------|---------|-----| +| `/api/demo/` | demo-service | 8085 | | `/api/im/` | im-service | 8082 | | `/ws/im` | im-service (WebSocket) | 8082 | | `/api/v1/updates/` | update-service | 8084 | @@ -144,6 +146,8 @@ cd XuqmGroup-RNChatDemo 所有接口通过 Nginx 反代至 `https://dev.xuqinmin.com`。 +`demo-service` 负责 demo 账号体系的注册、登录、找回密码和资料更新;登录成功后会返回 `demoToken`、`imToken` 和 `profile`。其中 `profile.appId` 用于后续初始化 IM 和更新能力,不走租户服务登录链路。 + --- ## 注意事项 diff --git a/scripts/publish-demo-assets.sh b/scripts/publish-demo-assets.sh index d9359df..e39d0b9 100755 --- a/scripts/publish-demo-assets.sh +++ b/scripts/publish-demo-assets.sh @@ -2,7 +2,7 @@ set -euo pipefail -BASE_URL="${BASE_URL:-https://sentry.xuqinmin.com}" +BASE_URL="${BASE_URL:-https://dev.xuqinmin.com}" APP_ID="${APP_ID:-ak_demo_chat}" MODULE_ID="${MODULE_ID:-chat-home}" diff --git a/src/api/demo.ts b/src/api/demo.ts index 50edd4f..f60bf8c 100644 --- a/src/api/demo.ts +++ b/src/api/demo.ts @@ -33,6 +33,7 @@ async function request( } export interface UserProfile { + appId: string userId: string nickname: string avatar: string diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index 025be3a..804bacd 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -8,6 +8,10 @@ import pluginMeta from '../../plugin.json' const APP_ID = 'ak_demo_chat' const SERVER_URL = 'https://dev.xuqinmin.com' +function buildImDbName(appId: string, userId: string): string { + return `xuqm_im_${appId}_${userId}` +} + interface AuthState { ready: boolean userId: string | null @@ -27,10 +31,11 @@ const AuthContext = createContext(null) export function AuthProvider({ children }: { children: React.ReactNode }) { const [state, setState] = useState({ ready: false, userId: null, profile: null }) - const initSDK = useCallback(async (userId: string, imToken: string, profile: UserProfile) => { - await XuqmSDK.initialize({ appId: APP_ID, serverUrl: SERVER_URL }) - await ImSDK.loginWithToken(userId, imToken, 'xuqm_im') - setState({ ready: true, userId, profile }) + const initSDK = useCallback(async (profile: UserProfile, imToken: string) => { + const appId = profile.appId || APP_ID + await XuqmSDK.initialize({ appId, serverUrl: SERVER_URL }) + await ImSDK.loginWithToken(profile.userId, imToken, buildImDbName(appId, profile.userId)) + setState({ ready: true, userId: profile.userId, profile }) UpdateSDK.checkAppUpdate() .then(update => { @@ -57,7 +62,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { const imToken = await load(K.IM_TOKEN) const profile = await load(K.PROFILE) if (demoToken && imToken && profile) { - await initSDK(profile.userId, imToken, profile) + await initSDK(profile, imToken) return } } catch { @@ -72,7 +77,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { await save(K.DEMO_TOKEN, result.demoToken) await save(K.IM_TOKEN, result.imToken) await save(K.PROFILE, result.profile) - await initSDK(result.profile.userId, result.imToken, result.profile) + await initSDK(result.profile, result.imToken) }, [initSDK]) const login = useCallback(async (userId: string, password: string) => { diff --git a/src/screens/conversation/ConversationListScreen.tsx b/src/screens/conversation/ConversationListScreen.tsx index 974aafa..4b72a15 100644 --- a/src/screens/conversation/ConversationListScreen.tsx +++ b/src/screens/conversation/ConversationListScreen.tsx @@ -18,6 +18,7 @@ interface ConvWithMeta extends ConversationData { } export default function ConversationListScreen() { + const appId = 'ak_demo_chat' const navigation = useNavigation