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>
这个提交包含在:
父节点
e2bd914dd3
当前提交
734aaf256b
25
App.tsx
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
普通文件
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>
|
||||
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户