diff --git a/sdk-core/src/main/java/com/xuqm/sdk/XuqmSDK.kt b/sdk-core/src/main/java/com/xuqm/sdk/XuqmSDK.kt index 655e94e..51f4c2a 100644 --- a/sdk-core/src/main/java/com/xuqm/sdk/XuqmSDK.kt +++ b/sdk-core/src/main/java/com/xuqm/sdk/XuqmSDK.kt @@ -30,6 +30,7 @@ object XuqmSDK { fun initialize( context: Context, appKey: String, + serverUrl: String? = null, logLevel: LogLevel = LogLevel.WARN, ) { val applicationContext = context.applicationContext @@ -48,6 +49,35 @@ object XuqmSDK { initializedAppKey = appKey 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) {