Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow LOCAL with a custom string. #170

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
}
}
Loading