|
1 | 1 | package com.opengineering.opserver |
2 | 2 |
|
| 3 | +import androidx.annotation.Keep |
| 4 | +import com.facebook.proguard.annotations.DoNotStrip |
3 | 5 | import com.facebook.react.bridge.ReactApplicationContext |
4 | | -import com.facebook.react.module.annotations.ReactModule |
| 6 | +import com.facebook.react.bridge.ReactMethod |
| 7 | +import com.facebook.react.common.annotations.FrameworkAPI |
| 8 | +import com.facebook.react.turbomodule.core.CallInvokerHolderImpl |
| 9 | +import android.util.Log; |
5 | 10 |
|
6 | | -@ReactModule(name = OpServerModule.NAME) |
7 | | -class OpServerModule(reactContext: ReactApplicationContext) : |
8 | | - NativeOpServerSpec(reactContext) { |
| 11 | +@DoNotStrip |
| 12 | +@Keep |
| 13 | +@OptIn(FrameworkAPI::class) |
| 14 | +@Suppress("KotlinJniMissingFunction") |
| 15 | +class OpServerModule(val context: ReactApplicationContext) : |
| 16 | + NativeOpServerSpec(context) { |
9 | 17 |
|
10 | 18 | override fun getName(): String { |
11 | 19 | return NAME |
12 | 20 | } |
13 | 21 |
|
14 | | - // Example method |
15 | | - // See https://reactnative.dev/docs/native-modules-android |
16 | | - override fun multiply(a: Double, b: Double): Double { |
17 | | - return a * b |
| 22 | + @ReactMethod(isBlockingSynchronousMethod = true) |
| 23 | + override fun install(): Boolean { |
| 24 | + try { |
| 25 | + val jsContext = |
| 26 | + context.javaScriptContextHolder |
| 27 | + ?: return false |
| 28 | + |
| 29 | + val callInvokerHolder = |
| 30 | + context.jsCallInvokerHolder as? CallInvokerHolderImpl |
| 31 | + ?: return false |
| 32 | + |
| 33 | + install(jsContext.get(), callInvokerHolder) |
| 34 | + |
| 35 | + return true |
| 36 | + } catch (e: Throwable) { |
| 37 | + return false |
| 38 | + } |
18 | 39 | } |
19 | 40 |
|
| 41 | + private external fun install( |
| 42 | + jsRuntimePointer: Long, |
| 43 | + callInvokerHolder: CallInvokerHolderImpl, |
| 44 | + ) |
| 45 | + |
20 | 46 | companion object { |
21 | 47 | const val NAME = "OpServer" |
| 48 | + |
| 49 | + @JvmStatic |
| 50 | + var applicationContext: ReactApplicationContext? = null |
| 51 | + |
| 52 | + init { |
| 53 | + System.loadLibrary("op-server"); |
| 54 | + Log.i("OPServer", "Successfully loaded C++ library!"); |
| 55 | + } |
22 | 56 | } |
23 | 57 | } |
0 commit comments