Skip to content

Commit 4f43dcb

Browse files
authored
Allow LOCAL with a custom string. (#170)
* update with IP address ability * fix lint issue * the default should be dev
1 parent 8a019c7 commit 4f43dcb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class Client() {
324324

325325
createClient(
326326
logger = logger,
327-
host = "http://10.0.2.2:5556",
327+
host = "http://${options.api.env.getValue()}:5556",
328328
isSecure = false,
329329
db = dbPath,
330330
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)