Skip to content

Commit

Permalink
Allow LOCAL with a custom string. (#170)
Browse files Browse the repository at this point in the history
* update with IP address ability

* fix lint issue

* the default should be dev
  • Loading branch information
nplasterer authored Feb 5, 2024
1 parent 8a019c7 commit 4f43dcb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ data class GRPCApiClient(

private val channel: ManagedChannel =
Grpc.newChannelBuilderForAddress(
environment.rawValue,
environment.getValue(),
5556,
if (secure) {
TlsChannelCredentials.create()
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class Client() {

createClient(
logger = logger,
host = "http://10.0.2.2:5556",
host = "http://${options.api.env.getValue()}:5556",
isSecure = false,
db = dbPath,
encryptionKey = retrievedKey.encoded,
Expand Down
24 changes: 20 additions & 4 deletions library/src/main/java/org/xmtp/android/library/XMTPEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@ package org.xmtp.android.library
enum class XMTPEnvironment(val rawValue: String) {
DEV("dev.xmtp.network"),
PRODUCTION("production.xmtp.network"),
LOCAL("10.0.2.2"),
;
LOCAL("10.0.2.2") {
override fun withValue(value: String): XMTPEnvironment {
return LOCAL.apply { customValue = value }
}
};

private var customValue: String = ""

open fun withValue(value: String): XMTPEnvironment {
return this
}

companion object {
operator fun invoke(rawValue: String) =
XMTPEnvironment.values().firstOrNull { it.rawValue == rawValue }
operator fun invoke(rawValue: String): XMTPEnvironment {
return XMTPEnvironment.values().firstOrNull { it.rawValue == rawValue }
?: LOCAL.withValue(rawValue)
}
}

// This function returns the actual raw value for the enum, handling the CUSTOM case.
fun getValue(): String {
return if (this == LOCAL && customValue.isNotEmpty()) customValue else rawValue
}
}

0 comments on commit 4f43dcb

Please sign in to comment.