Links the Tor okhttpclient with nests
This commit is contained in:
+2
-1
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.nests.room.lifecycle
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.vitorpamplona.amethyst.Amethyst
|
||||
import com.vitorpamplona.amethyst.commons.viewmodels.NestViewModel
|
||||
import com.vitorpamplona.nestsclient.NestsRoomConfig
|
||||
import com.vitorpamplona.nestsclient.OkHttpNestsClient
|
||||
@@ -46,7 +47,7 @@ internal class NestViewModelFactory(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T =
|
||||
NestViewModel(
|
||||
httpClient = OkHttpNestsClient(),
|
||||
httpClient = OkHttpNestsClient(Amethyst.instance.roleBasedHttpClientBuilder::okHttpClientForVideo),
|
||||
transport = QuicWebTransportFactory(),
|
||||
decoderFactory = { MediaCodecOpusDecoder() },
|
||||
playerFactory = { AudioTrackPlayer() },
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ import kotlin.math.min
|
||||
* the process; the default constructor creates a dedicated client.
|
||||
*/
|
||||
class OkHttpNestsClient(
|
||||
private val http: OkHttpClient = OkHttpClient(),
|
||||
private val httpClient: (String) -> OkHttpClient,
|
||||
) : NestsClient {
|
||||
override suspend fun mintToken(
|
||||
room: NestsRoomConfig,
|
||||
@@ -142,7 +142,7 @@ class OkHttpNestsClient(
|
||||
val request = buildRequest()
|
||||
val response: Response =
|
||||
try {
|
||||
http.newCall(request).execute()
|
||||
httpClient(url).newCall(request).execute()
|
||||
} catch (e: SocketException) {
|
||||
transportError = e
|
||||
if (++transportAttempts >= MAX_TRANSPORT_RETRIES) throw NestsException("Failed to reach $url", e)
|
||||
|
||||
+3
-3
@@ -99,7 +99,7 @@ class OkHttpNestsClientRateLimitTest {
|
||||
server.enqueue(success(token = "T1"))
|
||||
|
||||
try {
|
||||
val client = OkHttpNestsClient(http = OkHttpClient())
|
||||
val client = OkHttpNestsClient(httpClient = { OkHttpClient() })
|
||||
val token =
|
||||
client.mintToken(
|
||||
room = roomConfig(server.baseUrl),
|
||||
@@ -122,7 +122,7 @@ class OkHttpNestsClientRateLimitTest {
|
||||
repeat(MAX_RATE_LIMIT_RETRIES + 2) { server.enqueue(rateLimited(retryAfterSeconds = 0)) }
|
||||
|
||||
try {
|
||||
val client = OkHttpNestsClient(http = OkHttpClient())
|
||||
val client = OkHttpNestsClient(httpClient = { OkHttpClient() })
|
||||
val ex =
|
||||
assertFailsWith<NestsException> {
|
||||
client.mintToken(
|
||||
@@ -149,7 +149,7 @@ class OkHttpNestsClientRateLimitTest {
|
||||
server.enqueue(StubResponse(401, "Unauthorized", body = "{\"error\":\"bad sig\"}"))
|
||||
|
||||
try {
|
||||
val client = OkHttpNestsClient(http = OkHttpClient())
|
||||
val client = OkHttpNestsClient(httpClient = { OkHttpClient() })
|
||||
val ex =
|
||||
assertFailsWith<NestsException> {
|
||||
client.mintToken(
|
||||
|
||||
+2
-2
@@ -140,7 +140,7 @@ class NostrNestsAuthFailureInteropTest {
|
||||
// Per moq-auth's regex /^nests\/\d+:[0-9a-f]{64}:[a-zA-Z0-9._-]+$/
|
||||
// — uppercase pubkey hex doesn't match the `[0-9a-f]` class.
|
||||
val signer = NostrSignerInternal(KeyPair())
|
||||
val client = OkHttpNestsClient(http = http)
|
||||
val client = OkHttpNestsClient(httpClient = { http })
|
||||
val room =
|
||||
NestsRoomConfig(
|
||||
authBaseUrl = harness.authBaseUrl,
|
||||
@@ -171,7 +171,7 @@ class NostrNestsAuthFailureInteropTest {
|
||||
// with `put: [<their-pubkey>]`. Lock that in so a future
|
||||
// hostlist gate doesn't sneak in unnoticed.
|
||||
val signer = NostrSignerInternal(KeyPair())
|
||||
val client = OkHttpNestsClient(http = http)
|
||||
val client = OkHttpNestsClient(httpClient = { http })
|
||||
val room =
|
||||
NestsRoomConfig(
|
||||
authBaseUrl = harness.authBaseUrl,
|
||||
|
||||
Reference in New Issue
Block a user