Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add node logger code generation #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/gen_kotlin/templates/module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ class BreezSDKModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
}

@ReactMethod
fun connect(config: ReadableMap, seed: ReadableArray, promise: Promise) {
fun connect(
config: ReadableMap,
seed: ReadableArray,
logFilePath: String,
promise: Promise,
) {
if (breezServices != null) {
promise.reject(TAG, "BreezServices already initialized")
return
Expand All @@ -71,8 +76,9 @@ class BreezSDKModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
try {
val configTmp = asConfig(config) ?: run { throw SdkException.Generic("Missing mandatory field config of type Config") }
val emitter = reactApplicationContext.getJSModule(RCTDeviceEventEmitter::class.java)

breezServices = connect(configTmp, asUByteList(seed), BreezSDKListener(emitter))
val logFilePathTmp = logFilePath.takeUnless { it.isEmpty() }

breezServices = connect(configTmp, asUByteList(seed), BreezSDKListener(emitter), BreezSDKNodeLogger(emitter), logFilePathTmp)
promise.resolve(readableMapOf("status" to "ok"))
} catch (e: SdkException) {
e.printStackTrace()
Expand Down
1 change: 1 addition & 0 deletions src/gen_swift/templates/extern.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface RCT_EXTERN_MODULE(RNBreezSDK, RCTEventEmitter)
RCT_EXTERN_METHOD(
connect: (NSDictionary*)config
seed: (NSArray*)seed
logFilePath: (NSString*)logFilePath
resolve: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)
Expand Down
9 changes: 5 additions & 4 deletions src/gen_swift/templates/module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RNBreezSDK: RCTEventEmitter {
}

override func supportedEvents() -> [String]! {
return [BreezSDKListener.emitterName, BreezSDKLogStream.emitterName]
return [BreezSDKListener.emitterName, BreezSDKLogStream.emitterName, BreezSDKNodeLogger.emitterName]
}

@objc
Expand Down Expand Up @@ -56,16 +56,17 @@ class RNBreezSDK: RCTEventEmitter {
}
}

@objc(connect:seed:resolve:reject:)
func connect(_ config:[String: Any], seed:[UInt8], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
@objc(connect:seed:logFilePath:resolve:reject:)
func connect(_ config: [String: Any], seed: [UInt8], logFilePath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
if self.breezServices != nil {
reject(RNBreezSDK.TAG, "BreezServices already initialized", nil)
return
}

do {
let configTmp = try BreezSDKMapper.asConfig(data: config)
self.breezServices = try BreezSDK.connect(config: configTmp, seed: seed, listener: BreezSDKListener(emitter: self))
let logFilePathTmp = logFilePath.isEmpty ? nil : logFilePath
breezServices = try BreezSDK.connect(config: configTmp, seed: seed, listener: BreezSDKListener(emitter: self), nodeLogger: BreezSDKNodeLogger(emitter: self), logFilePath: logFilePathTmp)
resolve(["status": "ok"])
} catch let err {
rejectErr(err: err, reject: reject)
Expand Down
8 changes: 6 additions & 2 deletions src/gen_typescript/templates/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ export type EventListener = (breezEvent: BreezEvent) => void

export type LogStream = (logEntry: LogEntry) => void

export const connect = async (config: Config, seed: number[], listener: EventListener): Promise<EmitterSubscription> => {
export type Logger = (logMessage: LogMessage) => void

export const connect = async (config: Config, seed: number[], listener: EventListener, nodeLogger: Logger, logFilePath?: string ): Promise<EmitterSubscription> => {
const subscription = BreezSDKEmitter.addListener("breezSdkEvent", listener)

await BreezSDK.connect(config, seed)
BreezSDKEmitter.addListener("breezSdkNodeLog", nodeLogger)

await BreezSDK.connect(config, seed, logFilePath)

return subscription
}
Expand Down