mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Delegate no-arg PackagerStatusCheck constructor to shared OkHttpClient (#55577)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55577 PackagerStatusCheck had two constructors: a no-arg one that created its own OkHttpClient, and one that accepted an external client. The no-arg constructor is used by callers in fbandroid/ (FbDevBottomSheetViewController, LocalJsPackagerManager, FbPackagerStatusCheck, FbDevModeNuxController). Instead of removing it, delegate it to `DevSupportHttpClient.httpClient` so that all callers share the same connection pool without needing code changes. Also removes the now-unused `HTTP_CONNECT_TIMEOUT_MS` constant since the timeout configuration is centralized in DevSupportHttpClient. Changelog: [Internal] [Changed] - Reviewed By: cipolleschi Differential Revision: D93480248 fbshipit-source-id: 07b3a6c01cec19a5de1604c560229622974e500e
This commit is contained in:
1 parent
ac57f644e7
commit
99ed9101ee
1 file changed
+3
-17
+3
-17
@@ -11,10 +11,10 @@ package com.facebook.react.devsupport
|
||||
|
||||
import com.facebook.common.logging.FLog
|
||||
import com.facebook.react.common.ReactConstants
|
||||
import com.facebook.react.devsupport.inspector.DevSupportHttpClient
|
||||
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback
|
||||
import java.io.IOException
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit
|
||||
import okhttp3.Call
|
||||
import okhttp3.Callback
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -22,22 +22,9 @@ import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
|
||||
/** Use this class to check if the JavaScript packager is running on the provided host. */
|
||||
internal class PackagerStatusCheck {
|
||||
internal class PackagerStatusCheck(private val client: OkHttpClient) {
|
||||
|
||||
private val client: OkHttpClient
|
||||
|
||||
constructor() {
|
||||
client =
|
||||
OkHttpClient.Builder()
|
||||
.connectTimeout(HTTP_CONNECT_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
|
||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.writeTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
}
|
||||
|
||||
constructor(client: OkHttpClient) {
|
||||
this.client = client
|
||||
}
|
||||
constructor() : this(DevSupportHttpClient.httpClient)
|
||||
|
||||
fun run(host: String, callback: PackagerStatusCallback) {
|
||||
val statusURL = createPackagerStatusURL(host)
|
||||
@@ -92,7 +79,6 @@ internal class PackagerStatusCheck {
|
||||
|
||||
private companion object {
|
||||
private const val PACKAGER_OK_STATUS = "packager-status:running"
|
||||
private const val HTTP_CONNECT_TIMEOUT_MS = 5_000
|
||||
private const val PACKAGER_STATUS_URL_TEMPLATE = "http://%s/status"
|
||||
|
||||
private fun createPackagerStatusURL(host: String): String =
|
||||
|
||||
Reference in new issue
Block a user