diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..447d675 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 22 + versionCode 1 + versionName "0.2.0" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + // needed for https://github.com/square/okio/issues/58 + lintOptions { + warning 'InvalidPackage' + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.facebook.react:react-native:0.11.+' +} diff --git a/android/proguard-rules.pro b/android/proguard-rules.pro new file mode 100644 index 0000000..a92fa17 --- /dev/null +++ b/android/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0892cb6 --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/android/src/main/java/com/peel/react/TcpSockets.java b/android/src/main/java/com/peel/react/TcpSockets.java new file mode 100644 index 0000000..d6a1ff3 --- /dev/null +++ b/android/src/main/java/com/peel/react/TcpSockets.java @@ -0,0 +1,132 @@ +/** + * TcpSockets.java + * react-native-tcp + * + * Created by Andy Prock on 12/21/15. + */ + +package com.peel.react; + +import android.content.Context; +import android.net.wifi.WifiManager; +import android.support.annotation.Nullable; +import android.util.SparseArray; + +import com.facebook.common.logging.FLog; +import com.facebook.react.bridge.Arguments; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.GuardedAsyncTask; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.WritableMap; +import com.facebook.react.modules.core.DeviceEventManagerModule; + +import java.io.IOException; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.concurrent.ExecutionException; + +/** + * The NativeModule in charge of storing active {@link TcpSocketClient}s, and acting as an api layer. + */ +public final class TcpSockets extends ReactContextBaseJavaModule { + private static final String TAG = "TcpSockets"; + + private boolean mShuttingDown = false; + + public TcpSockets(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public String getName() { + return TAG; + } + + @Override + public void initialize() { + mShuttingDown = false; + } + + @Override + public void onCatalystInstanceDestroy() { + mShuttingDown = true; + } + + /** + * Creates a {@link TcpSocketClient} with the given ID + */ + @ReactMethod + public void createSocket(final Integer cId) { + new GuardedAsyncTask(getReactApplicationContext()) { + @Override + protected void doInBackgroundGuarded(Void... params) { + FLog.e(TAG, "TcpSockets.createSocket unimplemented."); + + WritableMap eventParams = Arguments.createMap(); + eventParams.putString("event", "error"); + eventParams.putString("data", "TcpSockets.createSocket unimplemented"); + + ReactContext reactContext = TcpSockets.this.getReactApplicationContext(); + reactContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit("tcp-" + cId + "-event", eventParams); + } + }.execute(); + } + + @ReactMethod + public void connect(final Integer cId, final @Nullable String host, final Integer port, final ReadableMap options) { + new GuardedAsyncTask(getReactApplicationContext()) { + @Override + protected void doInBackgroundGuarded(Void... params) { + FLog.e(TAG, "TcpSockets.connect unimplemented."); + + WritableMap eventParams = Arguments.createMap(); + eventParams.putString("event", "error"); + eventParams.putString("data", "TcpSockets.connect unimplemented"); + + ReactContext reactContext = TcpSockets.this.getReactApplicationContext(); + reactContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit("tcp-" + cId + "-event", eventParams); + } + }.execute(); + } + + @ReactMethod + public void write(final Integer cId, final String base64String, final boolean encoded, final Callback callback) { + new GuardedAsyncTask(getReactApplicationContext()) { + @Override + protected void doInBackgroundGuarded(Void... params) { + FLog.e(TAG, "TcpSockets.write unimplemented."); + callback.invoke("unimplemented." + cId); + } + }.execute(); + } + + @ReactMethod + public void end(final Integer cId, final Callback callback) { + new GuardedAsyncTask(getReactApplicationContext()) { + @Override + protected void doInBackgroundGuarded(Void... params) { + FLog.e(TAG, "TcpSockets.end unimplemented."); + callback.invoke("unimplemented." + cId); + } + }.execute(); + } + + @ReactMethod + public void destroy(final Integer cId, final Callback callback) { + new GuardedAsyncTask(getReactApplicationContext()) { + @Override + protected void doInBackgroundGuarded(Void... params) { + FLog.e(TAG, "TcpSockets.destroy unimplemented."); + callback.invoke("unimplemented." + cId); + } + }.execute(); + } +} diff --git a/android/src/main/java/com/peel/react/TcpSocketsModule.java b/android/src/main/java/com/peel/react/TcpSocketsModule.java new file mode 100644 index 0000000..89b913f --- /dev/null +++ b/android/src/main/java/com/peel/react/TcpSocketsModule.java @@ -0,0 +1,43 @@ +/** + * TcpSocketsModule.java + * react-native-tcp + * + * Created by Andy Prock on 12/21/15. + */ + +package com.peel.react; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +public final class TcpSocketsModule implements ReactPackage { + + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList(); + + modules.add(new TcpSockets(reactContext)); + + return modules; + } + + @Override + public List> createJSModules() { + return Collections.emptyList(); + } + + @Override + public List createViewManagers( + ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +} diff --git a/ios/TcpSockets.xcodeproj/project.pbxproj b/ios/TcpSockets.xcodeproj/project.pbxproj index bf7110a..1ad874d 100644 --- a/ios/TcpSockets.xcodeproj/project.pbxproj +++ b/ios/TcpSockets.xcodeproj/project.pbxproj @@ -106,7 +106,7 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0720; - ORGANIZATIONNAME = "Tradle, Inc."; + ORGANIZATIONNAME = "Peel, Inc."; TargetAttributes = { 58B511DA1A9E6C8500147676 = { CreatedOnToolsVersion = 6.1.1;