Skip to content

Commit d356095

Browse files
committed
First Upload
1 parent 10bfe79 commit d356095

12 files changed

+378
-37
lines changed

.babelrc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"retainLines": true,
3+
"compact": true,
4+
"comments": false,
5+
"plugins": [
6+
"syntax-async-functions",
7+
"syntax-class-properties",
8+
"syntax-trailing-function-commas",
9+
"transform-class-properties",
10+
"transform-es2015-arrow-functions",
11+
"transform-es2015-block-scoping",
12+
"transform-es2015-classes",
13+
"transform-es2015-computed-properties",
14+
"transform-es2015-constants",
15+
"transform-es2015-destructuring",
16+
["transform-es2015-modules-commonjs", {"strict": false, "allowTopLevelThis": true}],
17+
"transform-es2015-parameters",
18+
"transform-es2015-shorthand-properties",
19+
"transform-es2015-spread",
20+
"transform-es2015-template-literals",
21+
"transform-flow-strip-types",
22+
"transform-object-assign",
23+
"transform-object-rest-spread",
24+
"transform-react-display-name",
25+
"transform-react-jsx",
26+
"transform-regenerator",
27+
"transform-es2015-for-of"
28+
],
29+
"sourceMaps": false,
30+
"presets": ["react-native"]
31+
}

.eslintrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": ["zavatta"],
3+
"plugins": [
4+
"react",
5+
"react-native"
6+
],
7+
"ecmaFeatures": {
8+
"jsx": true
9+
},
10+
"rules": {
11+
"react-native/no-unused-styles": 2,
12+
"react-native/split-platform-components": 2,
13+
"react-native/no-inline-styles": 2,
14+
"react-native/no-color-literals": 2,
15+
}
16+
}

.gitignore

+41-37
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# nyc test coverage
18-
.nyc_output
19-
20-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21-
.grunt
22-
23-
# node-waf configuration
24-
.lock-wscript
25-
26-
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
28-
29-
# Dependency directories
30-
node_modules
31-
jspm_packages
32-
33-
# Optional npm cache directory
34-
.npm
35-
36-
# Optional REPL history
37-
.node_repl_history
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IJ
26+
#
27+
.idea
28+
.gradle
29+
local.properties
30+
31+
# node.js
32+
#
33+
node_modules/
34+
npm-debug.log
35+
36+
# BUCK
37+
buck-out/
38+
\.buckd/
39+
android/app/libs
40+
android/build
41+
android/keystores/debug.keystore

.npmignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
node_modules/
2+
3+
build/
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
*.xcworkspace
13+
!default.xcworkspace
14+
xcuserdata
15+
profile
16+
*.moved-aside
17+
DerivedData
18+
19+
local.properties

android/build.gradle

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.3"
6+
7+
defaultConfig {
8+
minSdkVersion 16
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
}
14+
15+
dependencies {
16+
compile fileTree(dir: 'libs', include: ['*.jar'])
17+
testCompile 'junit:junit:4.12'
18+
compile 'com.android.support:appcompat-v7:23.4.0'
19+
compile 'com.facebook.react:react-native:+'
20+
}
+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":react-native-portavailable" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../../../android" external.system.id="GRADLE" external.system.module.group="RemoteBox" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":react-native-portavailable" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
13+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
14+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15+
<afterSyncTasks>
16+
<task>generateDebugSources</task>
17+
</afterSyncTasks>
18+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
19+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
20+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
21+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
22+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
23+
<option name="LIBRARY_PROJECT" value="true" />
24+
</configuration>
25+
</facet>
26+
</component>
27+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
28+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
29+
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
30+
<exclude-output />
31+
<content url="file://$MODULE_DIR$">
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
43+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
67+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
68+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
69+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
70+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.react/react-native/0.20.1/jars" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/mockable-android-23.jar" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
90+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
91+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
92+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
93+
</content>
94+
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
95+
<orderEntry type="sourceFolder" forTests="false" />
96+
<orderEntry type="library" exported="" name="okhttp-ws-2.5.0" level="project" />
97+
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
98+
<orderEntry type="library" exported="" name="okio-1.6.0" level="project" />
99+
<orderEntry type="library" exported="" name="okhttp-2.5.0" level="project" />
100+
<orderEntry type="library" exported="" name="stetho-1.2.0" level="project" />
101+
<orderEntry type="library" exported="" name="jsr305-3.0.0" level="project" />
102+
<orderEntry type="library" exported="" name="fbcore-0.8.1" level="project" />
103+
<orderEntry type="library" exported="" name="commons-cli-1.2" level="project" />
104+
<orderEntry type="library" exported="" name="animated-vector-drawable-23.4.0" level="project" />
105+
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
106+
<orderEntry type="library" exported="" name="imagepipeline-0.8.1" level="project" />
107+
<orderEntry type="library" exported="" name="android-jsc-r174650" level="project" />
108+
<orderEntry type="library" exported="" name="fresco-0.8.1" level="project" />
109+
<orderEntry type="library" exported="" name="imagepipeline-okhttp-0.8.1" level="project" />
110+
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
111+
<orderEntry type="library" exported="" name="bolts-android-1.1.4" level="project" />
112+
<orderEntry type="library" exported="" name="support-vector-drawable-23.4.0" level="project" />
113+
<orderEntry type="library" exported="" name="drawee-0.8.1" level="project" />
114+
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
115+
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
116+
<orderEntry type="library" exported="" name="stetho-okhttp-1.2.0" level="project" />
117+
<orderEntry type="library" exported="" name="jackson-core-2.2.3" level="project" />
118+
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
119+
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
120+
<orderEntry type="library" exported="" name="react-native-0.20.1" level="project" />
121+
</component>
122+
</module>

android/src/main/AndroidManifest.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.odinvt.portavailable">
3+
4+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.odinvt.portavailable;
2+
3+
import com.facebook.react.bridge.Promise;
4+
import com.facebook.react.bridge.ReactApplicationContext;
5+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
6+
import com.facebook.react.bridge.ReactMethod;
7+
8+
import java.io.IOException;
9+
import java.net.DatagramSocket;
10+
import java.net.ServerSocket;
11+
12+
public class PortAvailableModule extends ReactContextBaseJavaModule {
13+
private static final int MIN_PORT_NUMBER = 0;
14+
private static final int MAX_PORT_NUMBER = 0xFFFF;
15+
16+
public PortAvailableModule(ReactApplicationContext reactContext) {
17+
super(reactContext);
18+
}
19+
20+
@Override
21+
public String getName() {
22+
return "RNPortAvailable";
23+
}
24+
25+
@ReactMethod
26+
public void available(int port, Promise promise) {
27+
boolean available;
28+
try {
29+
available = check(port);
30+
31+
promise.resolve(available);
32+
} catch (Exception e) {
33+
promise.reject(e);
34+
}
35+
}
36+
37+
public boolean check(int port) throws IllegalArgumentException, IOException {
38+
if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
39+
throw new IllegalArgumentException("Invalid start port: " + port);
40+
}
41+
42+
ServerSocket ss = null;
43+
DatagramSocket ds = null;
44+
boolean result = false;
45+
try {
46+
ss = new ServerSocket(port);
47+
ss.setReuseAddress(true);
48+
ds = new DatagramSocket(port);
49+
ds.setReuseAddress(true);
50+
result = true;
51+
} catch (IOException e) {
52+
throw new IOException(e);
53+
} finally {
54+
if (ds != null) {
55+
ds.close();
56+
}
57+
58+
if (ss != null) {
59+
try {
60+
ss.close();
61+
} catch (IOException e) {
62+
/* should not be thrown */
63+
throw new IOException(e);
64+
}
65+
}
66+
}
67+
68+
return result;
69+
}
70+
}

0 commit comments

Comments
 (0)