From 2ca58aa458e1ca5837e18a513e53448041be8b3d Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Tue, 28 Apr 2026 16:08:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(sample):=20=E6=B7=BB=E5=8A=A0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E5=BA=94=E7=94=A8=E7=9A=84=E6=A0=B8=E5=BF=83=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现环境配置管理,支持外部和本地主机模式切换 - 集成Demo API接口,包含登录、注册、文件上传等功能 - 构建附件处理仓库,支持图片、视频、音频和文件发送 - 开发认证仓库,管理用户会话和IM令牌刷新机制 - 添加语音录制功能,支持实时音频消息录制 - 创建依赖注入容器,统一管理应用组件实例 - 实现登录界面,提供用户认证交互功能 - 开发聊天界面,集成消息收发和媒体处理功能 --- package.json | 2 +- packages/common/package.json | 1 + packages/common/src/config.ts | 2 +- packages/common/src/constants.ts | 4 ++-- packages/common/src/http.ts | 23 +++++++++++++++++++++++ packages/common/src/sdk.ts | 4 ++-- packages/im/package.json | 1 + packages/im/src/upload.ts | 22 ++++++++++++++++++++++ packages/push/package.json | 1 + packages/update/package.json | 1 + 10 files changed, 55 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 5849a2a..6802bba 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "src/index.ts", "react-native": "src/index.ts", "types": "src/index.ts", - "private": false, + "private": true, "workspaces": ["packages/*"], "publishConfig": { "registry": "https://nexus.xuqinmin.com/repository/npm-hosted/" diff --git a/packages/common/package.json b/packages/common/package.json index 208806a..7033303 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -2,6 +2,7 @@ "name": "@xuqm/rn-common", "version": "0.2.0", "description": "XuqmGroup RN SDK — core: init, network, token management", + "license": "UNLICENSED", "main": "src/index.ts", "react-native": "src/index.ts", "types": "src/index.ts", diff --git a/packages/common/src/config.ts b/packages/common/src/config.ts index 93cf133..174e966 100644 --- a/packages/common/src/config.ts +++ b/packages/common/src/config.ts @@ -1,6 +1,6 @@ export interface XuqmInitOptions { appId: string - serverUrl: string // e.g. "https://dev.xuqinmin.com" — SDK fetches config from here + serverUrl: string // e.g. "http://192.168.116.9:8081" — SDK fetches config from here appKey?: string debug?: boolean } diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts index ddd770b..0d02e60 100644 --- a/packages/common/src/constants.ts +++ b/packages/common/src/constants.ts @@ -4,9 +4,9 @@ * XuqmSDK.initialize(). These constants are kept only as fallback * references and for backward compatibility. */ -export const API_BASE_URL = 'https://dev.xuqinmin.com' +export const API_BASE_URL = 'http://192.168.116.9:8081' /** * @deprecated See API_BASE_URL. */ -export const IM_WS_URL = 'wss://dev.xuqinmin.com/ws/im' +export const IM_WS_URL = 'ws://192.168.116.9:8082/ws/im' diff --git a/packages/common/src/http.ts b/packages/common/src/http.ts index e4e83bf..8b1982c 100644 --- a/packages/common/src/http.ts +++ b/packages/common/src/http.ts @@ -42,6 +42,14 @@ export async function apiRequest( if (token) headers['Authorization'] = `Bearer ${token}` } + if (config.debug) { + console.debug('[XuqmSDK][HTTP] request', { + method: options.method ?? 'GET', + url, + hasBody: Boolean(options.body), + }) + } + const res = await fetch(url, { method: options.method ?? 'GET', headers, @@ -50,9 +58,24 @@ export async function apiRequest( if (!res.ok) { const err = await res.json().catch(() => ({ message: res.statusText })) + if (config.debug) { + console.debug('[XuqmSDK][HTTP] response', { + url, + status: res.status, + ok: false, + message: (err as { message?: string }).message ?? res.statusText, + }) + } throw new Error((err as { message?: string }).message ?? `HTTP ${res.status}`) } const json = await res.json() + if (config.debug) { + console.debug('[XuqmSDK][HTTP] response', { + url, + status: res.status, + ok: true, + }) + } return (json.data ?? json) as T } diff --git a/packages/common/src/sdk.ts b/packages/common/src/sdk.ts index 714dd0a..a79fce8 100644 --- a/packages/common/src/sdk.ts +++ b/packages/common/src/sdk.ts @@ -6,7 +6,7 @@ export const XuqmSDK = { * Recommended for production use. * * @param options.appId - Your application ID (from the tenant platform) - * @param options.serverUrl - Base URL of the tenant platform, e.g. "https://dev.xuqinmin.com" + * @param options.serverUrl - Base URL of the tenant platform, e.g. "http://192.168.116.9:8081" * @param options.appKey - Optional; defaults to appId * @param options.debug - Enable verbose logging */ @@ -38,7 +38,7 @@ export const XuqmSDK = { * Kept for backward compatibility; prefer initialize() for production use. * * @param options.appId - Your application ID (from the tenant platform) - * @param options.serverUrl - Base URL of the tenant platform, e.g. "https://dev.xuqinmin.com" + * @param options.serverUrl - Base URL of the tenant platform, e.g. "http://192.168.116.9:8081" * @param options.appKey - Optional; defaults to appId * @param options.debug - Enable verbose logging */ diff --git a/packages/im/package.json b/packages/im/package.json index 4cbbffa..85b82e0 100644 --- a/packages/im/package.json +++ b/packages/im/package.json @@ -2,6 +2,7 @@ "name": "@xuqm/rn-im", "version": "0.2.0", "description": "XuqmGroup RN SDK — IM module (single chat, group chat, 13 message types)", + "license": "UNLICENSED", "main": "src/index.ts", "react-native": "src/index.ts", "types": "src/index.ts", diff --git a/packages/im/src/upload.ts b/packages/im/src/upload.ts index aad1892..0e711f9 100644 --- a/packages/im/src/upload.ts +++ b/packages/im/src/upload.ts @@ -44,6 +44,15 @@ export async function uploadFile( } as unknown as Blob) } + if (config.debug) { + console.debug('[XuqmSDK][Upload] request', { + url: `${config.fileServiceUrl}/api/file/upload`, + filename, + mimeType, + hasThumbnail: Boolean(thumbnailUri), + }) + } + const response = await fetch(`${config.fileServiceUrl}/api/file/upload`, { method: 'POST', headers: { @@ -55,10 +64,23 @@ export async function uploadFile( if (!response.ok) { const text = await response.text().catch(() => '') + if (config.debug) { + console.debug('[XuqmSDK][Upload] response', { + status: response.status, + ok: false, + body: text, + }) + } throw new Error(`[uploadFile] Upload failed (${response.status}): ${text}`) } const json = await response.json() + if (config.debug) { + console.debug('[XuqmSDK][Upload] response', { + status: response.status, + ok: true, + }) + } // Server wraps result in ApiResponse { code, data, message } const data = json?.data ?? json diff --git a/packages/push/package.json b/packages/push/package.json index 82c56fa..6f1e940 100644 --- a/packages/push/package.json +++ b/packages/push/package.json @@ -2,6 +2,7 @@ "name": "@xuqm/rn-push", "version": "0.2.0", "description": "XuqmGroup RN SDK — Push module (device token registration)", + "license": "UNLICENSED", "main": "src/index.ts", "react-native": "src/index.ts", "types": "src/index.ts", diff --git a/packages/update/package.json b/packages/update/package.json index 9ab95c6..95445c4 100644 --- a/packages/update/package.json +++ b/packages/update/package.json @@ -2,6 +2,7 @@ "name": "@xuqm/rn-update", "version": "0.2.0", "description": "XuqmGroup RN SDK — Update module (App update, RN plugin hot-update)", + "license": "UNLICENSED", "main": "src/index.ts", "react-native": "src/index.ts", "types": "src/index.ts",