-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
665 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Callback.h | ||
// LncRn | ||
// | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface Callback : NSObject | ||
-(void)setCallback:(RCTPromiseResolveBlock)callback; | ||
-(void)sendResult:(NSString *)data; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Callback.m | ||
#import "Callback.h" | ||
#import <React/RCTEventEmitter.h> | ||
|
||
@implementation Callback | ||
|
||
RCTPromiseResolveBlock rnCallback; | ||
|
||
-(void)setCallback:(RCTPromiseResolveBlock)callback { | ||
rnCallback = callback; | ||
} | ||
|
||
-(void)sendResult:(NSString *)data { | ||
rnCallback(data); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <React/RCTEventEmitter.h> | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface LncRn : RCTEventEmitter <RCTBridgeModule> | ||
|
||
-(void)sendEvent: (NSString *)event data:(NSString *)data; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#import "LncRn.h" | ||
#import "Callback.h" | ||
#import "StreamingCallback.h" | ||
#import "Lndmobile.xcframework/ios-arm64_x86_64-simulator/Lndmobile.framework/Headers/Lndmobile.h" | ||
|
||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "RNLncRnSpec.h" | ||
#endif | ||
|
||
@implementation LncRn | ||
RCT_EXPORT_MODULE() | ||
|
||
RCT_EXPORT_METHOD(registerLocalPrivCreateCallback:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)onLocalPrivCreate) | ||
{ | ||
Callback *lpccb = [[Callback alloc] init]; | ||
// id<Callback> lpccb; | ||
// lpccb.setCallback(onLocalPrivCreate); | ||
[lpccb setCallback:onLocalPrivCreate]; | ||
MobileRegisterLocalPrivCreateCallback(lpccb); | ||
} | ||
|
||
RCT_EXPORT_METHOD(registerRemoteKeyReceiveCallback:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)onRemoteKeyReceive) | ||
{ | ||
Callback * rkrcb = [[Callback alloc] init]; | ||
[rkrcb setCallback:onRemoteKeyReceive]; | ||
MobileRegisterAuthDataCallback(rkrcb); | ||
} | ||
|
||
RCT_EXPORT_METHOD(registerAuthDataCallback:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)onAuthData) | ||
{ | ||
Callback * oacb = [[Callback alloc] init]; | ||
[oacb setCallback:onAuthData]; | ||
MobileRegisterAuthDataCallback(oacb); | ||
} | ||
|
||
RCT_EXPORT_METHOD(isConnected:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
BOOL isConnected = MobileIsConnected(); | ||
resolve(@(isConnected)); | ||
} | ||
|
||
RCT_EXPORT_METHOD(status:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
NSString *status = MobileStatus(); | ||
resolve(status); | ||
} | ||
|
||
struct Data { | ||
NSString* expiry; | ||
NSError* error; | ||
}; | ||
|
||
RCT_EXPORT_METHOD(expiry:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
NSString * response = MobileGetExpiry(nil); | ||
resolve(response); | ||
} | ||
|
||
RCT_EXPORT_METHOD(isReadOnly:(NSString *)title | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
BOOL readOnly = MobileIsReadOnly(); | ||
resolve(@(readOnly)); | ||
} | ||
|
||
RCT_EXPORT_METHOD(hasPerms:(NSString *)title | ||
permission:(NSString *)permission | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
BOOL hasPermissions = MobileHasPermissions(permission); | ||
resolve(@(hasPermissions)); | ||
} | ||
|
||
RCT_EXPORT_METHOD(connectServer:(NSString *)title | ||
mailboxServerAddr:(NSString *)mailboxServerAddr | ||
isDevServer:(BOOL *)isDevServer | ||
connectPhrase:(NSString *)connectPhrase | ||
localStatic:(NSString *)localStatic | ||
remoteStatic:(NSString *)remoteStatic) | ||
{ | ||
MobileConnectServer(mailboxServerAddr, isDevServer, connectPhrase, localStatic, remoteStatic); | ||
} | ||
|
||
RCT_EXPORT_METHOD(disconnect:(NSString *)title) | ||
{ | ||
MobileDisconnect(); | ||
} | ||
|
||
RCT_EXPORT_METHOD(invokeRPC:(NSString *)title | ||
route:(NSString *)route | ||
requestData:(NSString *)requestData | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
Callback * gocb = [[Callback alloc] init]; | ||
[gocb setCallback:resolve]; | ||
MobileInvokeRPC(route, requestData, gocb, nil); | ||
} | ||
|
||
- (NSArray<NSString *> *)supportedEvents { | ||
// TODO add all streaming events names to list | ||
return @[@"Accelerometer"]; | ||
} | ||
|
||
- (void)sendEvent: (NSString *)event data:(NSString *)data { | ||
[self sendEventWithName:event body:@{@"result": data}]; | ||
} | ||
|
||
- (void)startObserving: (NSString *)eventName request:(NSString *)request | ||
{ | ||
StreamingCallback * gocb = [[StreamingCallback alloc] init]; | ||
[gocb setEventName:eventName]; | ||
// TODO set callback properly | ||
// [gocb setCallback:[self sendEvent]]; | ||
MobileInvokeRPC(eventName, request, gocb, nil); | ||
} | ||
|
||
// TO DO | ||
// ~registerLocalPrivCreateCallback | ||
// ~registerRemoteKeyReceiveCallback | ||
// ~registerAuthDataCallback | ||
// +isConnected | ||
// +status | ||
// +expiry | ||
// +isReadOnly | ||
// +hasPerms | ||
// +connectServer | ||
// +disconnect | ||
// ~invokeRPC | ||
// ~sendEvent | ||
// ~initListener | ||
|
||
// Don't compile this code when we build for the old architecture. | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
{ | ||
return std::make_shared<facebook::react::NativeLncRnSpecJSI>(params); | ||
} | ||
#endif | ||
|
||
@end |
Oops, something went wrong.