refactor: adopt new SDK API (no URLs/token in init, auto version)

- XuqmSDK.init now takes only { appId, debug } — no URLs or appSecret
- Add plugin.json for plugin self-registration
- UpdateSDK._devSetAppVersion(1) as simulator fallback
- UpdatePanel: remove appVersionCode/rnCurrentVersion props,
  use UpdateSDK.getAppVersionCode() and getRegisteredPluginVersion()
- Add .nvmrc (node 22)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
徐勤民 2026-04-24 16:16:50 +08:00
父节点 e2bd914dd3
当前提交 734aaf256b
共有 4 个文件被更改,包括 24 次插入23 次删除

1
.nvmrc 普通文件
查看文件

@ -0,0 +1 @@
22

25
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() {
<Text style={styles.eyebrow}>XuqmGroup RN SDK Demo</Text>
<Text style={styles.title}>IM · · · App · </Text>
<Text style={styles.subtitle}>
{API_BASE_URL}/ RN
/ RN
</Text>
{/* Section 1: 当前会话 */}
@ -297,9 +296,7 @@ function DemoConsole() {
{/* Section 4: 更新演示 */}
<SectionCard title="4. 更新演示">
<UpdatePanel
appVersionCode={CURRENT_APP_VERSION_CODE}
rnModuleId={MODULE_ID}
rnCurrentVersion={CURRENT_RN_VERSION}
onLog={appendLog}
/>
</SectionCard>

4
plugin.json 普通文件
查看文件

@ -0,0 +1,4 @@
{
"moduleId": "chat-home",
"version": "1.0.0"
}

查看文件

@ -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<StepStatus>('idle')
const [rnCheckStep, setRnCheckStep] = useState<StepStatus>('idle')
const [rnDownloadStep, setRnDownloadStep] = useState<StepStatus>('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<ReturnType<typeof UpdateSDK.checkRnUpdate>>
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
<Text style={styles.blockTitle}>App APK / IPA</Text>
<Text style={styles.blockHint}>
Android APK iOS App Store
{appVersionCode}
SDK versionCode={UpdateSDK.getAppVersionCode()}
</Text>
<StepRow
step={1}
@ -192,7 +190,8 @@ export function UpdatePanel({appVersionCode, rnModuleId, rnCurrentVersion, onLog
<View style={styles.block}>
<Text style={styles.blockTitle}>RN JS Bundle</Text>
<Text style={styles.blockHint}>
<Text style={styles.mono}>{rnModuleId}</Text> <Text style={styles.mono}>{rnCurrentVersion}</Text>
<Text style={styles.mono}>{rnModuleId}</Text>{' '}
<Text style={styles.mono}>{UpdateSDK.getRegisteredPluginVersion(rnModuleId) ?? '未注册'}</Text>
AsyncStorage
</Text>