#typescript
Cap'n Web is a lightweight JavaScript RPC system that lets you call functions and pass objects between client and server easily, using familiar JavaScript APIs and JSON for data. It supports bidirectional calls, passing functions and objects by reference, and promise pipelining, which means you can chain calls efficiently in one network round trip. It works in browsers, Node.js, Cloudflare Workers, and supports HTTP, WebSocket, and MessagePort transports. Cap'n Web is small (under 10kB), integrates with TypeScript, and helps build fast, secure, and flexible web APIs with less boilerplate and better performance than many other RPC systems. This makes your web app communication simpler and faster.
https://github.com/cloudflare/capnweb
🚀 Вышел стабильный JavaScript движок от Google для Android
Новая стабильная библиотека Jetpack JavaScript Engine позволит разработчикам выполнять JS код в изолированной и ограниченной среде.
class MainActivity : ComponentActivity() {
// Теперь nullable, без lateinit
private var jsSandbox: JavaScriptSandbox? = null
private var jsIsolate: JavaScriptIsolate? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!JavaScriptSandbox.isSupported()) {
Log.e("JS", "JavaScriptSandbox не поддерживается")
return
}
lifecycleScope.launch {
// Создаём и сохраняем в nullable-поле
jsSandbox = JavaScriptSandbox
.createConnectedInstanceAsync(applicationContext)
.await()
jsIsolate = jsSandbox?.createIsolate()
// При выполнении гарантируем, что jsIsolate != null
val result: String = jsIsolate
?.evaluateJavaScriptAsync(JS_SCRIPT_SCRING)
?.await()
?: "Ошибка: isolate не инициализирован"
Log.d("JS", "Результат выполнения: $result")
}
}
override fun onDestroy() {
super.onDestroy()
// Закрываем только если не null
jsIsolate?.close()
jsSandbox?.close()
}
}
#jetpack#js