Skip to content

Commit

Permalink
update with IP address ability
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 5, 2024
1 parent 5aab3d4 commit 0f004f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 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
5 changes: 3 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.xmtp.android.library

import android.content.Context
import android.os.Build
import android.os.Environment
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.Log
Expand Down Expand Up @@ -66,7 +67,7 @@ data class ClientOptions(
val enableAlphaMls: Boolean = false,
) {
data class Api(
val env: XMTPEnvironment = XMTPEnvironment.DEV,
val env: XMTPEnvironment = XMTPEnvironment.LOCAL,
val isSecure: Boolean = true,
val appVersion: String? = null,
)
Expand Down Expand Up @@ -323,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 0f004f1

Please sign in to comment.