@@ -1403,6 +1403,72 @@ public void leavePool(String poolID, Promise promise) {
14031403 });
14041404 }
14051405
1406+ @ ReactMethod
1407+ public void joinPoolWithChain (String poolID , String chainName , Promise promise ) {
1408+ ThreadUtils .runOnExecutor (() -> {
1409+ Log .d ("ReactNative" , "joinPoolWithChain: poolID = " + poolID + ", chainName = " + chainName );
1410+ try {
1411+ // Validate inputs
1412+ if (poolID == null || poolID .trim ().isEmpty ()) {
1413+ promise .reject ("INVALID_POOL_ID" , "Pool ID cannot be null or empty" );
1414+ return ;
1415+ }
1416+ if (chainName == null || chainName .trim ().isEmpty ()) {
1417+ promise .reject ("INVALID_CHAIN_NAME" , "Chain name cannot be null or empty" );
1418+ return ;
1419+ }
1420+ if (this .fula == null ) {
1421+ promise .reject ("FULA_NOT_INITIALIZED" , "Fula client is not initialized" );
1422+ return ;
1423+ }
1424+
1425+ long poolIdLong = Long .parseLong (poolID );
1426+ byte [] result = this .fula .poolJoinWithChain (poolIdLong , chainName );
1427+ String resultString = toString (result );
1428+ promise .resolve (resultString );
1429+ } catch (NumberFormatException e ) {
1430+ Log .d ("ReactNative" , "ERROR: Invalid poolID format: " + e .getMessage ());
1431+ promise .reject ("INVALID_POOL_ID_FORMAT" , "Pool ID must be a valid number: " + poolID , e );
1432+ } catch (Exception e ) {
1433+ Log .d ("ReactNative" , "ERROR:" + e .getMessage ());
1434+ promise .reject ("JOIN_POOL_WITH_CHAIN_ERROR" , "Failed to join pool with chain: " + e .getMessage (), e );
1435+ }
1436+ });
1437+ }
1438+
1439+ @ ReactMethod
1440+ public void leavePoolWithChain (String poolID , String chainName , Promise promise ) {
1441+ ThreadUtils .runOnExecutor (() -> {
1442+ Log .d ("ReactNative" , "leavePoolWithChain: poolID = " + poolID + ", chainName = " + chainName );
1443+ try {
1444+ // Validate inputs
1445+ if (poolID == null || poolID .trim ().isEmpty ()) {
1446+ promise .reject ("INVALID_POOL_ID" , "Pool ID cannot be null or empty" );
1447+ return ;
1448+ }
1449+ if (chainName == null || chainName .trim ().isEmpty ()) {
1450+ promise .reject ("INVALID_CHAIN_NAME" , "Chain name cannot be null or empty" );
1451+ return ;
1452+ }
1453+ if (this .fula == null ) {
1454+ promise .reject ("FULA_NOT_INITIALIZED" , "Fula client is not initialized" );
1455+ return ;
1456+ }
1457+
1458+ long poolIdLong = Long .parseLong (poolID );
1459+ byte [] result = this .fula .poolLeaveWithChain (poolIdLong , chainName );
1460+ String resultString = toString (result );
1461+ promise .resolve (resultString );
1462+ } catch (NumberFormatException e ) {
1463+ Log .d ("ReactNative" , "ERROR: Invalid poolID format: " + e .getMessage ());
1464+ promise .reject ("INVALID_POOL_ID_FORMAT" , "Pool ID must be a valid number: " + poolID , e );
1465+ } catch (Exception e ) {
1466+ Log .d ("ReactNative" , "ERROR:" + e .getMessage ());
1467+ promise .reject ("LEAVE_POOL_WITH_CHAIN_ERROR" , "Failed to leave pool with chain: " + e .getMessage (), e );
1468+ }
1469+ });
1470+ }
1471+
14061472 @ ReactMethod
14071473 public void listAvailableReplicationRequests (String poolIDStr , Promise promise ) {
14081474 ThreadUtils .runOnExecutor (() -> {
@@ -1930,14 +1996,14 @@ public void streamChunks(String streamID, Promise promise) {
19301996 ThreadUtils .runOnExecutor (() -> {
19311997 try {
19321998 fulamobile .StreamIterator iterator = this .fula .getStreamIterator (streamID );
1933-
1999+
19342000 if (iterator == null ) {
19352001 promise .reject ("STREAM_ITERATOR_ERROR" , "Failed to create StreamIterator" );
19362002 return ;
19372003 }
19382004
19392005 // Start listening for chunks
1940- new Handler (Looper .getMainLooper ()).post (() ->
2006+ new Handler (Looper .getMainLooper ()).post (() ->
19412007 pollIterator (iterator , promise )
19422008 );
19432009 } catch (Exception e ) {
@@ -1957,7 +2023,7 @@ private void pollIterator(fulamobile.StreamIterator iterator, Promise promise) {
19572023 emitEvent ("onStreamingCompleted" , null );
19582024 promise .resolve (null );
19592025 } else {
1960- new Handler (Looper .getMainLooper ()).postDelayed (() ->
2026+ new Handler (Looper .getMainLooper ()).postDelayed (() ->
19612027 pollIterator (iterator , promise )
19622028 , 50 ); // Reduced delay for better responsiveness
19632029 }
@@ -1967,7 +2033,7 @@ private void pollIterator(fulamobile.StreamIterator iterator, Promise promise) {
19672033 promise .resolve (null );
19682034 } else if (e .getMessage () != null && e .getMessage ().contains ("timeout" )) {
19692035 // Retry on timeout
1970- new Handler (Looper .getMainLooper ()).post (() ->
2036+ new Handler (Looper .getMainLooper ()).post (() ->
19712037 pollIterator (iterator , promise )
19722038 );
19732039 } else {
@@ -1976,7 +2042,7 @@ private void pollIterator(fulamobile.StreamIterator iterator, Promise promise) {
19762042 }
19772043 }
19782044}
1979-
2045+
19802046 private void emitEvent (String eventName , String data ) {
19812047 try {
19822048 getReactApplicationContext ()
0 commit comments