Skip to content

Commit 5928aa7

Browse files
committed
This project now supports both iOS and Android using the same JS calls.
* Exceptions: * The Android version does not support manual reconnects, joinNamespace, or leaveNamespace * The wrapped libraries can be found here: * [Socket.IO-Client-Swift](https://github.com/socketio/socket.io-client-swift). * [Socket.IO-Client-Java](https://github.com/socketio/socket.io-client-java). Notes: * You will see a whole lot of pain involved in taking JSONObjects/JSONArrays from the SocketIO-Client and bridging that data to RN bridge types (which use JSON) and then into Javascript objects. Any tips on making that a lot more efficient would be appreciated. * Not all socket configuration options have been migrated over to the Android version. This needs to be done. * We need unit tests.
1 parent da9e819 commit 5928aa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+889
-17
lines changed

README.md

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
This project was forked from Kirkness' React Native Swift Socket.Io project
44
[found here](https://github.com/kirkness/react-native-swift-socketio)
55

6-
Going forward, I will split from Kirkness' project so that it will
7-
include the Java Swift Socket.Io project as well. The point is to have one entry point into
8-
Socket.Io for both platforms.
6+
This project now supports both iOS and Android using the same JS calls.
7+
* Exceptions:
8+
* The Android version does not support manual reconnects, joinNamespace, or leaveNamespace
99

10-
* The wrapped 'Socket.IO-Client-Swift' can be [found here](https://github.com/socketio/socket.io-client-swift).
11-
12-
* The wrapped 'Socket.IO-Client-Java' can be [found here](https://github.com/socketio/socket.io-client-java).
10+
* The wrapped libraries can be found here:
11+
* [Socket.IO-Client-Swift](https://github.com/socketio/socket.io-client-swift).
12+
* [Socket.IO-Client-Java](https://github.com/socketio/socket.io-client-java).
1313

1414
### Example
15-
I've also added a super simple example app to /examples, copy and paste to your index.ios.js.
15+
Kirkness added a super simple example app to /examples, copy and paste to your index.ios.js.
1616
``` js
1717
/**
1818
* Pass in an optional config obj, this can include most of the
@@ -65,6 +65,7 @@ Optional:
6565

6666

6767
### Config
68+
* Please note that the Android version does not support all of these options yet. It's very much a work in progress.
6869

6970
- `connectParams: Any Object` - Any data to be sent with the connection.
7071
- `reconnects: Boolean` Default is `true`
@@ -92,15 +93,17 @@ Optional:
9293
- `emit` - Emit an event to server
9394
- `@param` - String - Event name
9495
- `@param` - Anything - Data to be sent
95-
- `close` - Close the connection
96-
- `@param` - Boolean - should close fast?
96+
- `disconnect` - Close the connection
9797
- `reconnect` - Reconnect to a closed connection
9898
- `joinNamespace` - Manually join namespace
99+
- `@param` - String - Namespace
99100
- `leaveNamespace` - Leave namespace, back to '/'
100101

101102
### Known issues
102103

103104
- Would rather this in an xcode framework but run into non-modular header issue.
105+
- Android needs more configuration option support.
106+
- Both implementations need unit testing.
104107

105108
### Install
106109

@@ -109,16 +112,59 @@ Optional:
109112
$ npm install react-native-socketio
110113
```
111114

115+
#### iOS
116+
* Note as of May 19, 2016 that the path to the ios components has been moved from root to the /ios folder.
112117
- Open up your project in xcode and right click the package.
113118
- Click **Add files to 'Your project name'**
114-
- Navigate to **/node_modules/react-native-socketio/RNSwiftSocketIO**
119+
- Navigate to **/node_modules/react-native-socketio/ios/RNSwiftSocketIO**
115120
- Click 'Add'
116121
- Click your project in the navigator on the left and go to **build settings**
117122
- Search for **Objective-C Bridging Header**
118123
- Double click on the empty column
119-
- Enter **../node_modules/react-native-socketio/RNSwiftSocketIO/SocketBridge.h**
124+
- Enter **../node_modules/react-native-socketio/ios/RNSwiftSocketIO/SocketBridge.h**
120125
- Search for **Header Search Paths**
121126
- Double Click on the column (likely has other search paths in it already)
122-
- Enter this text at the bottom of the column $(SRCROOT)/../node_modules/react-native-socketio/RNSwiftSocketIO
127+
- Enter this text at the bottom of the column $(SRCROOT)/../node_modules/react-native-socketio/ios/RNSwiftSocketIO
128+
129+
#### Android
130+
131+
1. In `android/setting.gradle`
132+
133+
```
134+
...
135+
include ':SocketIo'
136+
project(':SocketIo').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-socketio/android')
137+
```
138+
139+
2. In `android/app/build.gradle`
140+
141+
```
142+
...
143+
dependencies {
144+
...
145+
compile project(':SocketIo')
146+
}
147+
```
148+
149+
3. Register module (in MainActivity.java)
150+
151+
```
152+
import com.github.gcrabtree.rctsocketio.SocketIoPackage; // <--- import
153+
154+
public class MainActivity extends ReactActivity {
155+
......
156+
157+
@Override
158+
protected List<ReactPackage> getPackages() {
159+
return Arrays.<ReactPackage>asList(
160+
new MainReactPackage(),
161+
new VectorIconsPackage(),
162+
new OrientationPackage(this),
163+
new SocketIoPackage() // <--- Add here!
164+
);
165+
}
166+
167+
......
123168
124-
... That should do it! Please let me know of any issues ...
169+
}
170+
```

android/.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

android/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:2.1.0'
8+
}
9+
}
10+
11+
apply plugin: 'com.android.library'
12+
13+
android {
14+
compileSdkVersion 23
15+
buildToolsVersion "23.0.3"
16+
17+
defaultConfig {
18+
minSdkVersion 16
19+
targetSdkVersion 23
20+
versionCode 1
21+
versionName "1.0"
22+
}
23+
}
24+
25+
repositories {
26+
mavenCentral()
27+
}
28+
29+
dependencies {
30+
compile "com.facebook.react:react-native:+"
31+
compile ('io.socket:socket.io-client:0.7.0') {
32+
// excluding org.json which is provided by Android
33+
exclude group: 'org.json', module: 'json'
34+
}
35+
}
52.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Thu May 19 12:32:16 CDT 2016
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

android/gradlew

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/usr/bin/env bash
2+
3+
##############################################################################
4+
##
5+
## Gradle start up script for UN*X
6+
##
7+
##############################################################################
8+
9+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10+
DEFAULT_JVM_OPTS=""
11+
12+
APP_NAME="Gradle"
13+
APP_BASE_NAME=`basename "$0"`
14+
15+
# Use the maximum available, or set MAX_FD != -1 to use that value.
16+
MAX_FD="maximum"
17+
18+
warn ( ) {
19+
echo "$*"
20+
}
21+
22+
die ( ) {
23+
echo
24+
echo "$*"
25+
echo
26+
exit 1
27+
}
28+
29+
# OS specific support (must be 'true' or 'false').
30+
cygwin=false
31+
msys=false
32+
darwin=false
33+
case "`uname`" in
34+
CYGWIN* )
35+
cygwin=true
36+
;;
37+
Darwin* )
38+
darwin=true
39+
;;
40+
MINGW* )
41+
msys=true
42+
;;
43+
esac
44+
45+
# Attempt to set APP_HOME
46+
# Resolve links: $0 may be a link
47+
PRG="$0"
48+
# Need this for relative symlinks.
49+
while [ -h "$PRG" ] ; do
50+
ls=`ls -ld "$PRG"`
51+
link=`expr "$ls" : '.*-> \(.*\)$'`
52+
if expr "$link" : '/.*' > /dev/null; then
53+
PRG="$link"
54+
else
55+
PRG=`dirname "$PRG"`"/$link"
56+
fi
57+
done
58+
SAVED="`pwd`"
59+
cd "`dirname \"$PRG\"`/" >/dev/null
60+
APP_HOME="`pwd -P`"
61+
cd "$SAVED" >/dev/null
62+
63+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64+
65+
# Determine the Java command to use to start the JVM.
66+
if [ -n "$JAVA_HOME" ] ; then
67+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68+
# IBM's JDK on AIX uses strange locations for the executables
69+
JAVACMD="$JAVA_HOME/jre/sh/java"
70+
else
71+
JAVACMD="$JAVA_HOME/bin/java"
72+
fi
73+
if [ ! -x "$JAVACMD" ] ; then
74+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75+
76+
Please set the JAVA_HOME variable in your environment to match the
77+
location of your Java installation."
78+
fi
79+
else
80+
JAVACMD="java"
81+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82+
83+
Please set the JAVA_HOME variable in your environment to match the
84+
location of your Java installation."
85+
fi
86+
87+
# Increase the maximum file descriptors if we can.
88+
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89+
MAX_FD_LIMIT=`ulimit -H -n`
90+
if [ $? -eq 0 ] ; then
91+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92+
MAX_FD="$MAX_FD_LIMIT"
93+
fi
94+
ulimit -n $MAX_FD
95+
if [ $? -ne 0 ] ; then
96+
warn "Could not set maximum file descriptor limit: $MAX_FD"
97+
fi
98+
else
99+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100+
fi
101+
fi
102+
103+
# For Darwin, add options to specify how the application appears in the dock
104+
if $darwin; then
105+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106+
fi
107+
108+
# For Cygwin, switch paths to Windows format before running java
109+
if $cygwin ; then
110+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112+
JAVACMD=`cygpath --unix "$JAVACMD"`
113+
114+
# We build the pattern for arguments to be converted via cygpath
115+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116+
SEP=""
117+
for dir in $ROOTDIRSRAW ; do
118+
ROOTDIRS="$ROOTDIRS$SEP$dir"
119+
SEP="|"
120+
done
121+
OURCYGPATTERN="(^($ROOTDIRS))"
122+
# Add a user-defined pattern to the cygpath arguments
123+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125+
fi
126+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
127+
i=0
128+
for arg in "$@" ; do
129+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131+
132+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134+
else
135+
eval `echo args$i`="\"$arg\""
136+
fi
137+
i=$((i+1))
138+
done
139+
case $i in
140+
(0) set -- ;;
141+
(1) set -- "$args0" ;;
142+
(2) set -- "$args0" "$args1" ;;
143+
(3) set -- "$args0" "$args1" "$args2" ;;
144+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150+
esac
151+
fi
152+
153+
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154+
function splitJvmOpts() {
155+
JVM_OPTS=("$@")
156+
}
157+
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158+
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159+
160+
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

0 commit comments

Comments
 (0)