diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..2bd5a0a --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/App.tsx b/App.tsx index ced334c..d2cb639 100644 --- a/App.tsx +++ b/App.tsx @@ -10,18 +10,21 @@ import { View, } from 'react-native' import {SafeAreaProvider, SafeAreaView} from 'react-native-safe-area-context' -import {ImSDK, type ImEventListener, type ImMessage, type MsgType, XuqmSDK} from '@xuqm/rn-sdk' +import {ImSDK, type ImEventListener, type ImMessage, type MsgType, UpdateSDK, XuqmSDK} from '@xuqm/rn-sdk' import {MessageBubble} from './src/components/MessageBubble' import {DEMO_CONTENT, MessageComposer} from './src/components/MessageComposer' import {GroupChatPanel} from './src/components/GroupChatPanel' import {UpdatePanel} from './src/components/UpdatePanel' +import pluginMeta from './plugin.json' + +// Register this bundle as a plugin so UpdateSDK.checkRnUpdate() knows the current version. +UpdateSDK.registerPlugin(pluginMeta) + +// Dev fallback: set app versionCode for simulators where native module is not linked. +UpdateSDK._devSetAppVersion(1, '1.0.0') const APP_ID = 'ak_demo_chat' -const MODULE_ID = 'chat-home' -const CURRENT_APP_VERSION_CODE = 1 -const CURRENT_RN_VERSION = '1.0.0' -const API_BASE_URL = 'https://sentry.xuqinmin.com' -const IM_WS_URL = 'wss://sentry.xuqinmin.com/ws/im' +const MODULE_ID = pluginMeta.moduleId type DemoUser = {id: string; nickname: string} @@ -88,11 +91,7 @@ function DemoConsole() { useEffect(() => { XuqmSDK.init({ appId: APP_ID, - appKey: APP_ID, - appSecret: 'demo-secret-not-used-by-current-services', - apiBaseUrl: API_BASE_URL, - imWsUrl: IM_WS_URL, - debug: true, + debug: __DEV__, }) }, []) @@ -210,7 +209,7 @@ function DemoConsole() { XuqmGroup RN SDK Demo IM · 全消息类型 · 群聊 · App 更新 · 热更新 - 连接 {API_BASE_URL},演示单聊/群聊全消息类型、整包更新和 RN 插件热更新完整流程。 + 演示单聊/群聊全消息类型、整包更新和 RN 插件热更新完整流程。 {/* Section 1: 当前会话 */} @@ -297,9 +296,7 @@ function DemoConsole() { {/* Section 4: 更新演示 */} diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..8d28dec --- /dev/null +++ b/plugin.json @@ -0,0 +1,4 @@ +{ + "moduleId": "chat-home", + "version": "1.0.0" +} diff --git a/src/components/UpdatePanel.tsx b/src/components/UpdatePanel.tsx index 0b13df6..8102db6 100644 --- a/src/components/UpdatePanel.tsx +++ b/src/components/UpdatePanel.tsx @@ -3,9 +3,7 @@ import {Linking, Platform, Pressable, StyleSheet, Text, View} from 'react-native import {UpdateSDK} from '@xuqm/rn-sdk' interface Props { - appVersionCode: number rnModuleId: string - rnCurrentVersion: string onLog: (msg: string) => void } @@ -17,7 +15,7 @@ interface CheckResult { detail: string } -export function UpdatePanel({appVersionCode, rnModuleId, rnCurrentVersion, onLog}: Props) { +export function UpdatePanel({rnModuleId, onLog}: Props) { const [appStep, setAppStep] = useState('idle') const [rnCheckStep, setRnCheckStep] = useState('idle') const [rnDownloadStep, setRnDownloadStep] = useState('idle') @@ -43,12 +41,12 @@ export function UpdatePanel({appVersionCode, rnModuleId, rnCurrentVersion, onLog reset() setAppStep('loading') try { - const res = await UpdateSDK.checkAppUpdate(appVersionCode) + const res = await UpdateSDK.checkAppUpdate() if (!res.needsUpdate) { setAppResult({ needsUpdate: false, label: '✓ App 已是最新版本', - detail: `当前版本码:${appVersionCode},服务端无更高版本`, + detail: `当前版本码:${UpdateSDK.getAppVersionCode()},服务端无更高版本`, }) setAppStep('ok') onLog('App 更新检查:当前最新') @@ -84,7 +82,7 @@ export function UpdatePanel({appVersionCode, rnModuleId, rnCurrentVersion, onLog let checkInfo: Awaited> try { - checkInfo = await UpdateSDK.checkRnUpdate(rnModuleId, rnCurrentVersion) + checkInfo = await UpdateSDK.checkRnUpdate(rnModuleId) if (!checkInfo.needsUpdate) { setRnResult({ needsUpdate: false, @@ -97,7 +95,7 @@ export function UpdatePanel({appVersionCode, rnModuleId, rnCurrentVersion, onLog } setRnResult({ needsUpdate: true, - label: `↑ 发现插件版本 ${checkInfo.latestVersion}(当前 ${rnCurrentVersion})`, + label: `↑ 发现插件版本 ${checkInfo.latestVersion}(当前 ${UpdateSDK.getRegisteredPluginVersion(rnModuleId)})`, detail: [ `模块:${rnModuleId}`, `平台:${Platform.OS}`, @@ -169,7 +167,7 @@ export function UpdatePanel({appVersionCode, rnModuleId, rnCurrentVersion, onLog App 整包更新(APK / IPA) Android 返回 APK 下载链接,iOS 返回 App Store 跳转。 - 本地版本码写死为 {appVersionCode}。 + 当前版本码由 SDK 自动读取(versionCode={UpdateSDK.getAppVersionCode()})。 RN 插件热更新(JS Bundle) - 模块 {rnModuleId},本地版本 {rnCurrentVersion}。 + 模块 {rnModuleId},本地版本{' '} + {UpdateSDK.getRegisteredPluginVersion(rnModuleId) ?? '未注册'}。 热更新全流程:检查 → 下载 → 缓存至 AsyncStorage。