@functionland/react-native-fula 1.55.16 → 1.55.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/ios/Fula.swift +19 -11
  2. package/package.json +1 -1
package/ios/Fula.swift CHANGED
@@ -1508,7 +1508,7 @@ class FulaModule: RCTEventEmitter {
1508
1508
  return
1509
1509
  }
1510
1510
 
1511
- let result = try fula.poolJoinWithChain(poolIdInt, chainName: chainName)
1511
+ let result = try fula.poolJoin(withChain: poolIdInt, chainName: chainName)
1512
1512
  let resultString = String(data: result, encoding: .utf8)
1513
1513
  resolve(resultString)
1514
1514
  } catch let error {
@@ -1545,7 +1545,7 @@ class FulaModule: RCTEventEmitter {
1545
1545
  return
1546
1546
  }
1547
1547
 
1548
- let result = try fula.poolLeaveWithChain(poolIdInt, chainName: chainName)
1548
+ let result = try fula.poolLeave(withChain: poolIdInt, chainName: chainName)
1549
1549
  let resultString = String(data: result, encoding: .utf8)
1550
1550
  resolve(resultString)
1551
1551
  } catch let error {
@@ -2145,7 +2145,7 @@ func chatWithAI(aiModel: String, userMessage: String, resolve: @escaping RCTProm
2145
2145
  }
2146
2146
 
2147
2147
  // Call the Go Mobile method, which returns Data
2148
- let streamIDData = try fula.chatWithAI(aiModel, userMessage: userMessage)
2148
+ let streamIDData = try fula.chat(withAI: aiModel, userMessage: userMessage)
2149
2149
 
2150
2150
  // Convert Data to String (assuming UTF-8 encoding)
2151
2151
  guard let streamID = String(data: streamIDData, encoding: .utf8) else {
@@ -2175,7 +2175,12 @@ func getChatChunk(streamID: String, resolve: @escaping RCTPromiseResolveBlock, r
2175
2175
  }
2176
2176
 
2177
2177
  // Call the Go Mobile method, which returns a String
2178
- let chunk = fula.getChatChunk(streamID)
2178
+ var error: NSError?
2179
+ let chunk = fula.getChatChunk(streamID, error: &error)
2180
+
2181
+ if let error = error {
2182
+ throw error
2183
+ }
2179
2184
 
2180
2185
  // Handle null or empty response
2181
2186
  if chunk.isEmpty {
@@ -2214,10 +2219,8 @@ func streamChunks(streamID: String, resolve: @escaping RCTPromiseResolveBlock, r
2214
2219
  throw MyError.runtimeError("ReactNative Fula client is not initialized")
2215
2220
  }
2216
2221
 
2217
- let iterator = fula.getStreamIterator(streamID)
2218
- guard iterator != nil else {
2219
- throw MyError.runtimeError("Failed to create StreamIterator")
2220
- }
2222
+ let iterator = try fula.getStreamIterator(streamID)
2223
+ // Iterator is now non-optional, no need for nil check
2221
2224
 
2222
2225
  // Start listening for chunks on the main thread
2223
2226
  DispatchQueue.main.async {
@@ -2234,8 +2237,13 @@ func streamChunks(streamID: String, resolve: @escaping RCTPromiseResolveBlock, r
2234
2237
 
2235
2238
  private func pollIterator(iterator: FulamobileStreamIterator, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
2236
2239
  do {
2237
- let chunk = iterator.next()
2238
- if !chunk.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
2240
+ var error: NSError?
2241
+ let chunk = iterator.next(&error)
2242
+
2243
+ if let error = error {
2244
+ throw error
2245
+ }
2246
+ if !chunk.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty {
2239
2247
  self.emitEvent(eventName: "onChunkReceived", data: chunk)
2240
2248
  }
2241
2249
 
@@ -2256,7 +2264,7 @@ private func pollIterator(iterator: FulamobileStreamIterator, resolve: @escaping
2256
2264
  } else if errorMessage.contains("timeout") {
2257
2265
  // Retry on timeout
2258
2266
  DispatchQueue.main.async {
2259
- self.pollIterator(iterator: iterator!, resolve: resolve, reject: reject)
2267
+ self.pollIterator(iterator: iterator, resolve: resolve, reject: reject)
2260
2268
  }
2261
2269
  } else {
2262
2270
  self.emitEvent(eventName: "onStreamError", data: errorMessage)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionland/react-native-fula",
3
- "version": "1.55.16",
3
+ "version": "1.55.18",
4
4
  "description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
5
5
  "type": "module",
6
6
  "main": "lib/commonjs/index",