Skip to content

Commit 0f004f1

Browse files
committed
update with IP address ability
1 parent 5aab3d4 commit 0f004f1

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

library/src/main/java/org/xmtp/android/library/ApiClient.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ data class GRPCApiClient(
9090

9191
private val channel: ManagedChannel =
9292
Grpc.newChannelBuilderForAddress(
93-
environment.rawValue,
93+
environment.getValue(),
9494
5556,
9595
if (secure) {
9696
TlsChannelCredentials.create()

library/src/main/java/org/xmtp/android/library/Client.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.xmtp.android.library
22

33
import android.content.Context
44
import android.os.Build
5+
import android.os.Environment
56
import android.security.keystore.KeyGenParameterSpec
67
import android.security.keystore.KeyProperties
78
import android.util.Log
@@ -66,7 +67,7 @@ data class ClientOptions(
6667
val enableAlphaMls: Boolean = false,
6768
) {
6869
data class Api(
69-
val env: XMTPEnvironment = XMTPEnvironment.DEV,
70+
val env: XMTPEnvironment = XMTPEnvironment.LOCAL,
7071
val isSecure: Boolean = true,
7172
val appVersion: String? = null,
7273
)
@@ -323,7 +324,7 @@ class Client() {
323324

324325
createClient(
325326
logger = logger,
326-
host = "http://10.0.2.2:5556",
327+
host = "http://${options.api.env.getValue()}:5556",
327328
isSecure = false,
328329
db = dbPath,
329330
encryptionKey = retrievedKey.encoded,

library/src/main/java/org/xmtp/android/library/XMTPEnvironment.kt

+20-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@ package org.xmtp.android.library
33
enum class XMTPEnvironment(val rawValue: String) {
44
DEV("dev.xmtp.network"),
55
PRODUCTION("production.xmtp.network"),
6-
LOCAL("10.0.2.2"),
7-
;
6+
LOCAL("10.0.2.2") {
7+
override fun withValue(value: String): XMTPEnvironment {
8+
return LOCAL.apply { customValue = value }
9+
}
10+
};
11+
12+
private var customValue: String = ""
13+
14+
open fun withValue(value: String): XMTPEnvironment {
15+
return this
16+
}
817

918
companion object {
10-
operator fun invoke(rawValue: String) =
11-
XMTPEnvironment.values().firstOrNull { it.rawValue == rawValue }
19+
operator fun invoke(rawValue: String): XMTPEnvironment {
20+
return XMTPEnvironment.values().firstOrNull { it.rawValue == rawValue }
21+
?: LOCAL.withValue(rawValue)
22+
}
23+
}
24+
25+
// This function returns the actual raw value for the enum, handling the CUSTOM case.
26+
fun getValue(): String {
27+
return if (this == LOCAL && customValue.isNotEmpty()) customValue else rawValue
1228
}
1329
}

0 commit comments

Comments
 (0)