@mentra/crust 3.3.0-dev.515 → 3.3.0-dev.517
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -170,13 +170,23 @@ class CrustModule : Module() {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
AsyncFunction("nativeHttpRequest") {
|
|
173
|
-
method: String, url: String, headers: Map<String, String>, body: String
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
method: String, url: String, headers: Map<String, String>, body: String?, promise: expo.modules.kotlin.Promise ->
|
|
174
|
+
JSCPolyfillBridge.enqueueHttp(
|
|
175
|
+
method,
|
|
176
|
+
url,
|
|
177
|
+
headers,
|
|
178
|
+
body,
|
|
179
|
+
onResult = { result ->
|
|
180
|
+
promise.resolve(
|
|
181
|
+
mapOf(
|
|
182
|
+
"status" to result.status,
|
|
183
|
+
"statusText" to result.statusText,
|
|
184
|
+
"headers" to result.headers,
|
|
185
|
+
"body" to result.body,
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
},
|
|
189
|
+
onError = { error -> promise.reject("E_NATIVE_HTTP", error.message ?: "Native HTTP request failed", error) },
|
|
180
190
|
)
|
|
181
191
|
}
|
|
182
192
|
|
|
@@ -52,21 +52,49 @@ object JSCPolyfillBridge {
|
|
|
52
52
|
val body: String,
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Shared OkHttp path for host cloud-client requests. Asynchronous because Expo runs every
|
|
57
|
+
* module's AsyncFunction on one shared thread: a blocking call here stalls miniapp delivery
|
|
58
|
+
* and every other native module for the length of the request, up to [callTimeout].
|
|
59
|
+
*/
|
|
60
|
+
fun enqueueHttp(
|
|
61
|
+
method: String,
|
|
62
|
+
url: String,
|
|
63
|
+
headers: Map<String, String>,
|
|
64
|
+
bodyString: String?,
|
|
65
|
+
onResult: (HttpResult) -> Unit,
|
|
66
|
+
onError: (Throwable) -> Unit,
|
|
67
|
+
) {
|
|
68
|
+
val request = try {
|
|
69
|
+
buildHttpRequest(method, url, headers, bodyString)
|
|
70
|
+
} catch (e: Throwable) {
|
|
71
|
+
onError(e)
|
|
72
|
+
return
|
|
69
73
|
}
|
|
74
|
+
httpClient.newCall(request).enqueue(object : Callback {
|
|
75
|
+
override fun onFailure(call: Call, e: IOException) = onError(e)
|
|
76
|
+
|
|
77
|
+
override fun onResponse(call: Call, response: Response) {
|
|
78
|
+
try {
|
|
79
|
+
response.use { r ->
|
|
80
|
+
val responseHeaders = mutableMapOf<String, String>()
|
|
81
|
+
for (name in r.headers.names()) {
|
|
82
|
+
responseHeaders[name.lowercase()] = r.headers.values(name).joinToString(", ")
|
|
83
|
+
}
|
|
84
|
+
onResult(
|
|
85
|
+
HttpResult(
|
|
86
|
+
status = r.code,
|
|
87
|
+
statusText = r.message,
|
|
88
|
+
headers = responseHeaders,
|
|
89
|
+
body = r.body?.string() ?: "",
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
} catch (e: Throwable) {
|
|
94
|
+
onError(e)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
})
|
|
70
98
|
}
|
|
71
99
|
|
|
72
100
|
/** Keep host HTTP and miniapp fetch body semantics identical, including empty POSTs. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/crust",
|
|
3
|
-
"version": "3.3.0-dev.
|
|
3
|
+
"version": "3.3.0-dev.517",
|
|
4
4
|
"description": "Mentra Native Module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"license": "Apache-2.0",
|
|
36
36
|
"homepage": "https://github.com/Mentra-Community/MentraOS/tree/dev/mobile/modules/crust#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@mentra/jspolyfill": "3.3.0-dev.
|
|
38
|
+
"@mentra/jspolyfill": "3.3.0-dev.517"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@expo/config-plugins": ">=8.0.0",
|