feat(sdk-core): XuqmSDK.initialize() 新增 serverUrl 参数支持私有化部署
传入 serverUrl 后 SDK 自动完成: - 配置所有服务端点(controlBaseUrl/fileBaseUrl/imApiBaseUrl/imWsUrl/pushBaseUrl/updateBaseUrl) - 通过反射调用 LicenseSDK.initialize() 注入私有化 appKey 和 baseUrl - wss/ws scheme 自动根据 https/http 推导 App 侧只需: XuqmSDK.initialize(context, appKey, serverUrl = "https://your-server.com", logLevel = WARN) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
5481ffa57a
当前提交
d7fe714e69
@ -30,6 +30,7 @@ object XuqmSDK {
|
|||||||
fun initialize(
|
fun initialize(
|
||||||
context: Context,
|
context: Context,
|
||||||
appKey: String,
|
appKey: String,
|
||||||
|
serverUrl: String? = null,
|
||||||
logLevel: LogLevel = LogLevel.WARN,
|
logLevel: LogLevel = LogLevel.WARN,
|
||||||
) {
|
) {
|
||||||
val applicationContext = context.applicationContext
|
val applicationContext = context.applicationContext
|
||||||
@ -48,6 +49,35 @@ object XuqmSDK {
|
|||||||
initializedAppKey = appKey
|
initializedAppKey = appKey
|
||||||
initialized = true
|
initialized = true
|
||||||
}
|
}
|
||||||
|
serverUrl?.takeIf { it.isNotBlank() }?.let { configurePrivateServer(context, appKey, it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun configurePrivateServer(context: Context, appKey: String, serverUrl: String) {
|
||||||
|
val base = serverUrl.trimEnd('/') + "/"
|
||||||
|
val wsBase = serverUrl.trimEnd('/')
|
||||||
|
.replace("https://", "wss://")
|
||||||
|
.replace("http://", "ws://")
|
||||||
|
configureServiceEndpoints(
|
||||||
|
ServiceEndpoints(
|
||||||
|
controlBaseUrl = base,
|
||||||
|
fileBaseUrl = base,
|
||||||
|
imApiBaseUrl = base,
|
||||||
|
imWsUrl = "$wsBase/ws/im",
|
||||||
|
pushBaseUrl = base,
|
||||||
|
updateBaseUrl = base,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
// Initialize LicenseSDK via reflection — sdk-core cannot depend on sdk-license
|
||||||
|
runCatching {
|
||||||
|
val clazz = Class.forName("com.xuqm.sdk.license.LicenseSDK")
|
||||||
|
val instance = clazz.getField("INSTANCE").get(null)
|
||||||
|
val method = clazz.methods.firstOrNull { m ->
|
||||||
|
m.name == "initialize" &&
|
||||||
|
m.parameterTypes.size == 4 &&
|
||||||
|
m.parameterTypes[3] == String::class.java
|
||||||
|
}
|
||||||
|
method?.invoke(instance, context.applicationContext, appKey, null, base)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun configureServiceEndpoints(endpoints: ServiceEndpoints) {
|
fun configureServiceEndpoints(endpoints: ServiceEndpoints) {
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户