109 行
3.5 KiB
Markdown
109 行
3.5 KiB
Markdown
# XuqmGroup RN SDK 架构总览
|
||
|
||
## 整体架构
|
||
|
||
```
|
||
宿主 App(YiwangxinApp4 等)
|
||
└── 初始化(方式A: 配置文件自动 / 方式B: 手动 initialize)
|
||
↓
|
||
@xuqm/rn-common (核心层 v0.4.0)
|
||
├── XuqmSDK.initialize() → 拉取 /api/sdk/config
|
||
├── XuqmSDK.setUserInfo() → 通知所有子 SDK(订阅者模式)
|
||
├── api/(useApi / usePageApi / apiRequest)
|
||
├── device(设备信息 / 厂商检测)
|
||
├── xwebview(JSBridge 桥接控制)
|
||
├── ui/(toast / alert / confirm)
|
||
└── logApiUrl / logEnabled(从平台配置获取)
|
||
↓ peerDep / 依赖
|
||
子 SDK(各自独立)
|
||
├── @xuqm/rn-update → OTA 热更新 / APK 更新
|
||
├── @xuqm/rn-push → 厂商推送(peerDep: rn-common)
|
||
├── @xuqm/rn-im → IM 会话 / 消息(peerDep: rn-common)
|
||
├── @xuqm/rn-xwebview → WebView UI 组件(peerDep: rn-common)
|
||
├── @xuqm/rn-license → 证书授权(peerDep: rn-common)
|
||
└── @xuqm/rn-bugcollect → 错误采集 / Crash 捕获 / 漏斗分析(peerDep: rn-common)
|
||
```
|
||
|
||
## 依赖关系
|
||
|
||
```
|
||
rn-common (核心,无 SDK 内部依赖)
|
||
↑ peerDep
|
||
├── rn-update (直接依赖 rn-common)
|
||
├── rn-push (peerDep rn-common)
|
||
├── rn-im (peerDep rn-common + watermelondb)
|
||
├── rn-xwebview (peerDep rn-common + webview + navigation)
|
||
├── rn-license (peerDep rn-common + quick-crypto)
|
||
└── rn-bugcollect(peerDep rn-common)
|
||
```
|
||
|
||
## 用户状态分发机制
|
||
|
||
```
|
||
XuqmSDK.setUserInfo(info)
|
||
├── PushSDK: 检测厂商 → 获取厂商配置 → 注册 token
|
||
├── ImSDK: 若 userSig 存在且 imEnabled → 自动登录 WebSocket
|
||
├── UpdateSDK: 更新 userId(用于定向更新)
|
||
└── LicenseSDK: 更新用户上下文
|
||
|
||
XuqmSDK.setUserInfo(null)
|
||
├── PushSDK: 解绑 token
|
||
├── ImSDK: 断开 WebSocket
|
||
└── 其他子 SDK: 清理用户状态
|
||
```
|
||
|
||
各子 SDK 在模块加载时通过 `_registerUserInfoHandler()` 注册处理器,无需 App 手动协调。
|
||
|
||
## 初始化流程
|
||
|
||
### 方式 A(自动,推荐)
|
||
|
||
```
|
||
withXuqmConfig(metroConfig) 自动发现 src/assets/config/*.xuqmconfig
|
||
↓ 生成虚拟模块 @xuqm/autoinit-config
|
||
import '@xuqm/rn-common' 时触发
|
||
↓ autoInit.ts → require('@xuqm/autoinit-config')
|
||
↓ 解密(PBKDF2 + AES-256-GCM)
|
||
initWithConfigFile() → initialize({ appKey, platformUrl })
|
||
↓ HTTP GET
|
||
/api/sdk/config → 返回 { apiUrl, imWsUrl, fileServiceUrl, bugCollectApiUrl, ... }
|
||
```
|
||
|
||
兼容方式:手动配置 Babel/Metro alias `@xuqm/autoinit-config` → `.ts` 包装文件。
|
||
|
||
### 方式 B(手动)
|
||
|
||
```
|
||
App 代码调用 XuqmSDK.initialize({ appKey })
|
||
↓ HTTP GET
|
||
/api/sdk/config → 解析平台配置
|
||
↓
|
||
各子 SDK 就绪(等待 setUserInfo 触发具体功能)
|
||
```
|
||
|
||
## 数据流
|
||
|
||
```
|
||
App 代码
|
||
↓ 调用 API
|
||
子 SDK(update/push/im/license/bugcollect)
|
||
↓ 使用 apiRequest()
|
||
rn-common http.ts
|
||
↓ 附加 Bearer Token + 处理响应
|
||
平台服务(tenant-service / im-service / push-service / update-service / bugcollect-service)
|
||
```
|
||
|
||
## 包发布
|
||
|
||
所有包发布到 Nexus npm 私有仓库:`https://nexus.xuqinmin.com/repository/npm-hosted/`
|
||
|
||
```bash
|
||
# 发布单个包
|
||
cd packages/common && npm publish
|
||
|
||
# 发布所有包
|
||
for pkg in common update push im xwebview license bugcollect; do
|
||
cd packages/$pkg && npm publish && cd ../..
|
||
done
|
||
```
|