Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ To use this library you need to ensure you are using the correct version of Reac

| `react-native-tcp-socket` version | Required React Native Version |
| ----------------------------------------- | --------------------------------------------------------------------------------- |
| `4.X.X`, `3.X.X` | `>= 0.61` |
| `1.2.2` | `>= 0.??` |
| `4.X.X`, `3.X.X` | `>= 0.60.0` |
| `1.2.2` | `>= Unknown` |

## Usage
Import the library:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.Callback;
import com.facebook.react.modules.core.DeviceEventManagerModule;

Expand Down Expand Up @@ -71,9 +70,9 @@ private void sendEvent(String eventName, WritableMap params) {
@SuppressWarnings("unused")
@ReactMethod
public void connect(@NonNull final Integer cId, @NonNull final String host, @NonNull final Integer port, @NonNull final ReadableMap options) {
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
executorService.execute(new Thread(new Runnable() {
@Override
protected void doInBackgroundGuarded(Void... params) {
public void run() {
TcpSocketClient client = socketClients.get(cId);
if (client != null) {
onError(cId, TAG + "createSocket called twice with the same id.");
Expand All @@ -92,16 +91,16 @@ protected void doInBackgroundGuarded(Void... params) {
onError(cId, e.getMessage());
}
}
}.executeOnExecutor(executorService);
}));
}

@SuppressLint("StaticFieldLeak")
@SuppressWarnings("unused")
@ReactMethod
public void write(@NonNull final Integer cId, @NonNull final String base64String, @Nullable final Callback callback) {
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
executorService.execute(new Thread(new Runnable() {
@Override
protected void doInBackgroundGuarded(Void... params) {
public void run() {
TcpSocketClient socketClient = socketClients.get(cId);
if (socketClient == null) {
return;
Expand All @@ -118,24 +117,24 @@ protected void doInBackgroundGuarded(Void... params) {
onError(cId, e.toString());
}
}
}.executeOnExecutor(executorService);
}));
}

@SuppressLint("StaticFieldLeak")
@SuppressWarnings("unused")
@ReactMethod
public void end(final Integer cId) {
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
executorService.execute(new Thread(new Runnable() {
@Override
protected void doInBackgroundGuarded(Void... params) {
public void run() {
TcpSocketClient socketClient = socketClients.get(cId);
if (socketClient == null) {
return;
}
socketClient.close();
socketClients.remove(cId);
}
}.executeOnExecutor(executorService);
}));
}

@SuppressWarnings("unused")
Expand All @@ -148,9 +147,9 @@ public void destroy(final Integer cId) {
@SuppressWarnings("unused")
@ReactMethod
public void listen(final Integer cId, final ReadableMap options) {
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
executorService.execute(new Thread(new Runnable() {
@Override
protected void doInBackgroundGuarded(Void... params) {
public void run() {
try {
TcpSocketServer server = new TcpSocketServer(socketClients, TcpSocketModule.this, cId, options);
socketClients.put(cId, server);
Expand All @@ -161,7 +160,7 @@ protected void doInBackgroundGuarded(Void... params) {
onError(cId, uhe.getMessage());
}
}
}.executeOnExecutor(executorService);
}));
}

@SuppressWarnings("unused")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"metro-react-native-babel-preset": "^0.58.0",
"prettier": "^1.18.2",
"react": "16.9.0",
"react-native": "^0.61.4",
"react-native": "0.60.0",
"semantic-release": "^17.0.1",
"typescript": "^3.8.2"
},
Expand Down
Loading