-
Notifications
You must be signed in to change notification settings - Fork 376
/
CoreModule.java
46 lines (39 loc) · 1.39 KB
/
CoreModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package chat.berty.core;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactMethod;
import core.Core;
public class CoreModule extends ReactContextBaseJavaModule {
private Logger logger = new Logger("chat.berty.io");
private String filesDir = "";
private ReactApplicationContext reactContext;
public CoreModule(ReactApplicationContext reactContext) {
super(reactContext);
this.filesDir = reactContext.getFilesDir().getAbsolutePath();
this.reactContext = reactContext;
}
public String getName() {
return "CoreModule";
}
@ReactMethod
public void start(Promise promise) throws Exception {
try {
Core.start(this.filesDir, this.logger);
promise.resolve(null);
} catch (Exception err) {
this.logger.format(Level.ERROR, this.getName(), "Unable to start core: %s", err);
promise.reject(err);
}
}
@ReactMethod
public void getPort(Promise promise) {
try {
Long port = Core.getPort();
promise.resolve(port.toString());
} catch (Exception err) {
this.logger.format(Level.ERROR, this.getName(), "Unable to get port", err);
promise.reject(err);
}
}
}