├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── libs │ └── socket.io-client.java-master │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── History.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── nkzawa │ │ │ ├── backo │ │ │ └── Backoff.java │ │ │ ├── hasbinary │ │ │ └── HasBinary.java │ │ │ └── socketio │ │ │ ├── client │ │ │ ├── Ack.java │ │ │ ├── IO.java │ │ │ ├── Manager.java │ │ │ ├── On.java │ │ │ ├── Socket.java │ │ │ ├── SocketIOException.java │ │ │ └── Url.java │ │ │ └── parser │ │ │ ├── Binary.java │ │ │ ├── Packet.java │ │ │ └── Parser.java │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── nkzawa │ │ │ ├── backo │ │ │ └── BackoffTest.java │ │ │ ├── hasbinary │ │ │ └── HasBinaryTest.java │ │ │ ├── socketio │ │ │ ├── client │ │ │ │ ├── Connection.java │ │ │ │ ├── ConnectionTest.java │ │ │ │ ├── ExecutionTest.java │ │ │ │ ├── SSLConnectionTest.java │ │ │ │ ├── ServerConnectionNamespaceTest.java │ │ │ │ ├── ServerConnectionTest.java │ │ │ │ ├── SocketTest.java │ │ │ │ ├── UrlTest.java │ │ │ │ └── executions │ │ │ │ │ ├── Connection.java │ │ │ │ │ ├── ConnectionFailure.java │ │ │ │ │ └── ImmediateClose.java │ │ │ └── parser │ │ │ │ ├── ByteArrayTest.java │ │ │ │ ├── Helpers.java │ │ │ │ └── ParserTest.java │ │ │ └── util │ │ │ └── Optional.java │ │ └── resources │ │ ├── cert.pem │ │ ├── key.pem │ │ ├── keystore.jks │ │ ├── logging.properties │ │ ├── package.json │ │ └── server.js ├── proguard-rules.pro ├── src.zip └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kriyatma │ │ └── nodesocket │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── kriyatma │ │ └── nodesocket │ │ ├── ChatFragment.java │ │ ├── Message.java │ │ ├── MessageAdapter.java │ │ └── SocketActivity.java │ └── res │ ├── drawable-hdpi │ ├── ic_action_attachment.png │ └── ic_action_camera.png │ ├── drawable-mdpi │ ├── ic_action_attachment.png │ └── ic_action_camera.png │ ├── drawable-xhdpi │ ├── ic_action_attachment.png │ └── ic_action_camera.png │ ├── drawable-xxhdpi │ ├── ic_action_attachment.png │ └── ic_action_camera.png │ ├── layout │ ├── activity_socket.xml │ ├── fragment_chat.xml │ └── layout_message.xml │ ├── menu │ ├── menu_socket.xml │ └── socket_activity_actions.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── build └── intermediates │ ├── dex-cache │ └── cache.xml │ └── gradle_project_sync_data.bin ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # android-socket.io-demo 2 | A demo realtime chat application with Node and socket.io on server side and native android as client. This demo includes sending text message as well as images files at realtime. 3 | server folder contains all the back end code i.e nodejs and socket.io. 4 | client folder contains all the android java client side code. 5 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.kriyatma.nodesocket" 9 | minSdkVersion 14 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:22.0.0' 25 | compile "com.android.support:recyclerview-v7:21.0.0" 26 | compile "com.github.nkzawa:socket.io-client:0.5.0" 27 | } 28 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | # Intellij project files 9 | *.iml 10 | *.ipr 11 | *.iws 12 | .idea/ 13 | 14 | .DS_Store 15 | target/ 16 | node_modules/ 17 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | install: mvn install -DskipTests=true -Dgpg.skip=true 3 | jdk: 4 | - openjdk7 5 | - oraclejdk8 6 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/History.md: -------------------------------------------------------------------------------- 1 | 0.5.0 / 2015-05-02 2 | ================== 3 | 4 | * bump `engine.io-client`. 5 | * enhance parser decode [niqo01] 6 | * add a wrong event name check 7 | * add setDefaultHostnameVerifier method 8 | 9 | 0.4.2 / 2015-03-07 10 | ================== 11 | 12 | * fix error on reconnection attemps 13 | 14 | 0.4.1 / 2015-02-08 15 | ================== 16 | 17 | * bump `engine.io-client`. 18 | * fix program doesn't terminate when closing socket before eatablishing connection. 19 | 20 | 0.4.0 / 2015-01-26 21 | ================== 22 | 23 | * compatible with socket.io 1.3.2 24 | * bump `engine.io-client`. 25 | * added `Socket#id()` pointing to session id 26 | * add exponential backoff with randomization 27 | * reset reconnection attempts state after a successul connection 28 | * fix binary arguments in emit with ack [AlfioEmanueleFresta] 29 | 30 | 0.3.0 / 2014-11-04 31 | ================== 32 | 33 | * compatible with socket.io 1.2.0 34 | * bump `engine.io-client`. 35 | * fix reconnection after reconnecting manually 36 | * enable to stop reconnecting 37 | * enable to reconnect manually 38 | * add `Socket#connected()` 39 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2013 Naoyuki Kanezawa 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | 10 | 11 | (The MIT License) 12 | 13 | Copyright (c) 2011 Guillermo Rauch 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining 16 | a copy of this software and associated documentation files (the 17 | 'Software'), to deal in the Software without restriction, including 18 | without limitation the rights to use, copy, modify, merge, publish, 19 | distribute, sublicense, and/or sell copies of the Software, and to 20 | permit persons to whom the Software is furnished to do so, subject to 21 | the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be 24 | included in all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 27 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 29 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 30 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 31 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 32 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/README.md: -------------------------------------------------------------------------------- 1 | # Socket.IO-client.java 2 | [![Build Status](https://travis-ci.org/nkzawa/socket.io-client.java.png?branch=master)](https://travis-ci.org/nkzawa/socket.io-client.java) 3 | 4 | This is the Socket.IO v1.x Client Library for Java, which is simply ported from the [JavaScript client](https://github.com/Automattic/socket.io-client). 5 | 6 | See also: 7 | 8 | - [Android chat demo](https://github.com/nkzawa/socket.io-android-chat) 9 | - [engine.io-client.java](https://github.com/nkzawa/engine.io-client.java) 10 | 11 | ## Installation 12 | The latest artifact is available on Maven Central. To install manually, please refer dependencies to [pom.xml](https://github.com/nkzawa/socket.io-client.java/blob/master/pom.xml). 13 | 14 | ### Maven 15 | Add the following dependency to your `pom.xml`. 16 | 17 | ```xml 18 | 19 | 20 | com.github.nkzawa 21 | socket.io-client 22 | 0.5.0 23 | 24 | 25 | ``` 26 | 27 | ### Gradle 28 | Add it as a gradle dependency for Android Studio, in `build.gradle`: 29 | 30 | ```groovy 31 | compile 'com.github.nkzawa:socket.io-client:0.5.0' 32 | ``` 33 | 34 | ## Usage 35 | Socket.IO-client.java has almost the same api and features with the original JS client. You use `IO#socket` to initialize `Socket`: 36 | 37 | ```java 38 | socket = IO.socket("http://localhost"); 39 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 40 | 41 | @Override 42 | public void call(Object... args) { 43 | socket.emit("foo", "hi"); 44 | socket.disconnect(); 45 | } 46 | 47 | }).on("event", new Emitter.Listener() { 48 | 49 | @Override 50 | public void call(Object... args) {} 51 | 52 | }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 53 | 54 | @Override 55 | public void call(Object... args) {} 56 | 57 | }); 58 | socket.connect(); 59 | ``` 60 | 61 | This Library uses [org.json](http://www.json.org/java/) to parse and compose JSON strings: 62 | 63 | ```java 64 | // Sending an object 65 | JSONObject obj = new JSONObject(); 66 | obj.put("hello", "server"); 67 | obj.put("binary", new byte[42]); 68 | socket.emit("foo", obj); 69 | 70 | // Receiving an object 71 | socket.on("foo", new Emitter.Listener() { 72 | @Override 73 | public void call(Object... args) { 74 | JSONObject obj = (JSONObject)args[0]; 75 | } 76 | }); 77 | ``` 78 | 79 | Options are supplied as follows: 80 | 81 | ```java 82 | IO.Options opts = new IO.Options(); 83 | opts.forceNew = true; 84 | opts.reconnection = false; 85 | 86 | socket = IO.socket("http://localhost", opts); 87 | ``` 88 | 89 | You can supply query parameters with the `query` option. NB: if you don't want to reuse a cached socket instance when the query parameter changes, you should use the `forceNew` option, the use case might be if your app allows for a user to logout, and a new user to login again: 90 | 91 | ```java 92 | IO.Options opts = new IO.Options(); 93 | opts.forceNew = true; 94 | opts.query = "auth_token=" + authToken; 95 | Socket socket = IO.socket("http://localhost", opts); 96 | ``` 97 | 98 | You can get a callback with `Ack` when the server received a message: 99 | 100 | ```java 101 | socket.emit("foo", "woot", new Ack() { 102 | @Override 103 | public void call(Object... args) {} 104 | }); 105 | ``` 106 | 107 | And vice versa: 108 | 109 | ```java 110 | // ack from client to server 111 | socket.on("foo", new Emitter.Listener() { 112 | @Override 113 | public void call(Object... args) { 114 | Ack ack = (Ack) args[args.length - 1]; 115 | ack.call(); 116 | } 117 | }); 118 | ``` 119 | 120 | Use custom SSL settings: 121 | 122 | ```java 123 | // default SSLContext for all sockets 124 | IO.setDefaultSSLContext(mySSLContext); 125 | 126 | // set as an option 127 | opts = new IO.Options(); 128 | opts.sslContext = mySSLContext; 129 | socket = IO.socket("https://localhost", opts); 130 | ``` 131 | 132 | See the Javadoc for more details. 133 | 134 | http://nkzawa.github.io/socket.io-client.java/apidocs/ 135 | 136 | ## Features 137 | This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported. 138 | 139 | ## License 140 | 141 | MIT 142 | 143 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.github.nkzawa 4 | socket.io-client 5 | 0.5.1-SNAPSHOT 6 | jar 7 | socket.io-client 8 | Socket.IO Client Library for Java 9 | https://github.com/nkzawa/socket.io-client.java 10 | 11 | 12 | org.sonatype.oss 13 | oss-parent 14 | 7 15 | 16 | 17 | 18 | github 19 | 20 | 21 | 22 | 23 | The MIT License (MIT) 24 | http://opensource.org/licenses/mit-license 25 | repo 26 | 27 | 28 | 29 | 30 | https://github.com/nkzawa/socket.io-client.java 31 | scm:git:git://github.com/nkzawa/socket.io-client.java.git 32 | scm:git:git@github.com:nkzawa/socket.io-client.java.git 33 | HEAD 34 | 35 | 36 | 37 | 38 | nkzawa 39 | Naoyuki Kanezawa 40 | naoyuki.kanezawa@gmail.com 41 | 42 | 43 | 44 | 45 | 46 | sonatype-oss-public 47 | https://oss.sonatype.org/content/groups/public/ 48 | 49 | true 50 | 51 | 52 | true 53 | 54 | 55 | 56 | 57 | 58 | 59 | com.github.nkzawa 60 | engine.io-client 61 | 0.5.0 62 | 63 | 64 | org.json 65 | json 66 | 20090211 67 | 68 | 69 | junit 70 | junit 71 | 4.11 72 | test 73 | 74 | 75 | org.hamcrest 76 | hamcrest-library 77 | 1.3 78 | test 79 | 80 | 81 | org.skyscreamer 82 | jsonassert 83 | 1.2.3 84 | test 85 | 86 | 87 | com.github.nkzawa 88 | socket.io-client 89 | 0.5.0 90 | 91 | 92 | 93 | 94 | 95 | ossrh 96 | https://oss.sonatype.org/content/repositories/snapshots 97 | 98 | 99 | ossrh 100 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 101 | 102 | 103 | 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-compiler-plugin 109 | 3.0 110 | 111 | 1.6 112 | 1.6 113 | 114 | 115 | 116 | org.apache.maven.plugins 117 | maven-surefire-plugin 118 | 2.14.1 119 | 120 | -Dfile.encoding=UTF-8 121 | 122 | 123 | java.util.logging.config.file 124 | ./src/test/resources/logging.properties 125 | 126 | 127 | 128 | 129 | 130 | org.apache.maven.plugins 131 | maven-gpg-plugin 132 | 1.5 133 | 134 | 135 | sign-artifacts 136 | verify 137 | 138 | sign 139 | 140 | 141 | 142 | 143 | 144 | org.apache.maven.plugins 145 | maven-source-plugin 146 | 2.2.1 147 | 148 | 149 | attach-sources 150 | 151 | jar-no-fork 152 | 153 | 154 | 155 | 156 | 157 | org.apache.maven.plugins 158 | maven-javadoc-plugin 159 | 2.9.1 160 | 161 | 162 | attach-javadocs 163 | 164 | jar 165 | 166 | 167 | 168 | 169 | 170 | org.apache.maven.plugins 171 | maven-release-plugin 172 | 2.5 173 | 174 | true 175 | false 176 | release 177 | deploy 178 | 179 | 180 | 181 | org.sonatype.plugins 182 | nexus-staging-maven-plugin 183 | 1.6.2 184 | true 185 | 186 | ossrh 187 | https://oss.sonatype.org/ 188 | true 189 | 190 | 191 | 192 | org.codehaus.mojo 193 | exec-maven-plugin 194 | 1.2.1 195 | 196 | 197 | npm-install 198 | process-test-resources 199 | 200 | exec 201 | 202 | 203 | ./src/test/resources 204 | npm 205 | 206 | install 207 | 208 | 209 | 210 | 211 | 212 | 213 | com.github.github 214 | site-maven-plugin 215 | 0.10 216 | 217 | Creating site for ${project.version} 218 | 219 | 220 | 221 | 222 | site 223 | 224 | site 225 | 226 | 227 | 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/backo/Backoff.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.backo; 2 | 3 | public class Backoff { 4 | 5 | private long ms = 100; 6 | private long max = 10000; 7 | private int factor = 2; 8 | private double jitter = 0.0; 9 | private int attempts = 0; 10 | 11 | public Backoff() {} 12 | 13 | public long duration() { 14 | long ms = this.ms * (long) Math.pow(this.factor, this.attempts++); 15 | if (jitter != 0.0) { 16 | double rand = Math.random(); 17 | int deviation = (int) Math.floor(rand * this.jitter * ms); 18 | ms = (((int) Math.floor(rand * 10)) & 1) == 0 ? ms - deviation : ms + deviation; 19 | } 20 | if (ms < this.ms) { 21 | // overflow happened 22 | ms = Long.MAX_VALUE; 23 | } 24 | return Math.min(ms, this.max); 25 | } 26 | 27 | public void reset() { 28 | this.attempts = 0; 29 | } 30 | 31 | public Backoff setMin(long min) { 32 | this.ms = min; 33 | return this; 34 | } 35 | 36 | public Backoff setMax(long max) { 37 | this.max = max; 38 | return this; 39 | } 40 | 41 | public Backoff setFactor(int factor) { 42 | this.factor = factor; 43 | return this; 44 | } 45 | 46 | public Backoff setJitter(double jitter) { 47 | this.jitter = jitter; 48 | return this; 49 | } 50 | 51 | public int getAttempts() { 52 | return this.attempts; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/hasbinary/HasBinary.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.hasbinary; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | 7 | import java.util.Iterator; 8 | 9 | public class HasBinary { 10 | 11 | private HasBinary() {} 12 | 13 | public static boolean hasBinary(Object data) { 14 | return _hasBinary(data); 15 | } 16 | 17 | private static boolean _hasBinary(Object obj) { 18 | if (obj == null) return false; 19 | 20 | if (obj instanceof byte[]) { 21 | return true; 22 | } 23 | 24 | if (obj instanceof JSONArray) { 25 | JSONArray _obj = (JSONArray)obj; 26 | int length = _obj.length(); 27 | for (int i = 0; i < length; i++) { 28 | Object v; 29 | try { 30 | v = _obj.isNull(i) ? null : _obj.get(i); 31 | } catch (JSONException e) { 32 | return false; 33 | } 34 | if (_hasBinary(v)) { 35 | return true; 36 | } 37 | } 38 | } else if (obj instanceof JSONObject) { 39 | JSONObject _obj = (JSONObject)obj; 40 | Iterator keys = _obj.keys(); 41 | while (keys.hasNext()) { 42 | String key = (String)keys.next(); 43 | Object v; 44 | try { 45 | v = _obj.get(key); 46 | } catch (JSONException e) { 47 | return false; 48 | } 49 | if (_hasBinary(v)) { 50 | return true; 51 | } 52 | } 53 | } 54 | 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/Ack.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | /** 4 | * Acknowledgement. 5 | */ 6 | public interface Ack { 7 | 8 | public void call(Object... args); 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/IO.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | 4 | import com.github.nkzawa.socketio.parser.Parser; 5 | 6 | import javax.net.ssl.HostnameVerifier; 7 | import javax.net.ssl.SSLContext; 8 | import java.net.MalformedURLException; 9 | import java.net.URI; 10 | import java.net.URISyntaxException; 11 | import java.net.URL; 12 | import java.util.concurrent.ConcurrentHashMap; 13 | import java.util.logging.Logger; 14 | 15 | 16 | public class IO { 17 | 18 | private static final Logger logger = Logger.getLogger(IO.class.getName()); 19 | 20 | private static final ConcurrentHashMap managers = new ConcurrentHashMap(); 21 | 22 | /** 23 | * Protocol version. 24 | */ 25 | public static int protocol = Parser.protocol; 26 | 27 | public static void setDefaultSSLContext(SSLContext sslContext) { 28 | Manager.defaultSSLContext = sslContext; 29 | } 30 | 31 | public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier) { 32 | Manager.defaultHostnameVerifier = hostnameVerifier; 33 | } 34 | 35 | private IO() {} 36 | 37 | public static Socket socket(String uri) throws URISyntaxException { 38 | return socket(uri, null); 39 | } 40 | 41 | public static Socket socket(String uri, Options opts) throws URISyntaxException { 42 | return socket(new URI(uri), opts); 43 | } 44 | 45 | public static Socket socket(URI uri) throws URISyntaxException { 46 | return socket(uri, null); 47 | } 48 | 49 | /** 50 | * Initializes a {@link Socket} from an existing {@link Manager} for multiplexing. 51 | * 52 | * @param uri uri to connect. 53 | * @param opts options for socket. 54 | * @return {@link Socket} instance. 55 | * @throws URISyntaxException 56 | */ 57 | public static Socket socket(URI uri, Options opts) throws URISyntaxException { 58 | if (opts == null) { 59 | opts = new Options(); 60 | } 61 | 62 | URL parsed; 63 | try { 64 | parsed = Url.parse(uri); 65 | } catch (MalformedURLException e) { 66 | throw new URISyntaxException(uri.toString(), e.getMessage()); 67 | } 68 | URI source = parsed.toURI(); 69 | Manager io; 70 | 71 | if (opts.forceNew || !opts.multiplex) { 72 | logger.fine(String.format("ignoring socket cache for %s", source)); 73 | io = new Manager(source, opts); 74 | } else { 75 | String id = Url.extractId(parsed); 76 | if (!managers.containsKey(id)) { 77 | logger.fine(String.format("new io instance for %s", source)); 78 | managers.putIfAbsent(id, new Manager(source, opts)); 79 | } 80 | io = managers.get(id); 81 | } 82 | 83 | return io.socket(parsed.getPath()); 84 | } 85 | 86 | 87 | public static class Options extends Manager.Options { 88 | 89 | public boolean forceNew; 90 | 91 | /** 92 | * Whether to enable multiplexing. Default is true. 93 | */ 94 | public boolean multiplex = true; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/Manager.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.backo.Backoff; 4 | import com.github.nkzawa.emitter.Emitter; 5 | import com.github.nkzawa.socketio.parser.Packet; 6 | import com.github.nkzawa.socketio.parser.Parser; 7 | import com.github.nkzawa.thread.EventThread; 8 | 9 | import javax.net.ssl.HostnameVerifier; 10 | import javax.net.ssl.SSLContext; 11 | import java.net.URI; 12 | import java.util.*; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | 17 | 18 | /** 19 | * Manager class represents a connection to a given Socket.IO server. 20 | */ 21 | public class Manager extends Emitter { 22 | 23 | private static final Logger logger = Logger.getLogger(Manager.class.getName()); 24 | 25 | /*package*/ enum ReadyState { 26 | CLOSED, OPENING, OPEN 27 | } 28 | 29 | /** 30 | * Called on a successful connection. 31 | */ 32 | public static final String EVENT_OPEN = "open"; 33 | 34 | /** 35 | * Called on a disconnection. 36 | */ 37 | public static final String EVENT_CLOSE = "close"; 38 | 39 | public static final String EVENT_PACKET = "packet"; 40 | public static final String EVENT_ERROR = "error"; 41 | 42 | /** 43 | * Called on a connection error. 44 | */ 45 | public static final String EVENT_CONNECT_ERROR = "connect_error"; 46 | 47 | /** 48 | * Called on a connection timeout. 49 | */ 50 | public static final String EVENT_CONNECT_TIMEOUT = "connect_timeout"; 51 | 52 | /** 53 | * Called on a successful reconnection. 54 | */ 55 | public static final String EVENT_RECONNECT = "reconnect"; 56 | 57 | /** 58 | * Called on a reconnection attempt error. 59 | */ 60 | public static final String EVENT_RECONNECT_ERROR = "reconnect_error"; 61 | 62 | public static final String EVENT_RECONNECT_FAILED = "reconnect_failed"; 63 | 64 | public static final String EVENT_RECONNECT_ATTEMPT = "reconnect_attempt"; 65 | 66 | public static final String EVENT_RECONNECTING = "reconnecting"; 67 | 68 | /** 69 | * Called when a new transport is created. (experimental) 70 | */ 71 | public static final String EVENT_TRANSPORT = Engine.EVENT_TRANSPORT; 72 | 73 | /*package*/ static SSLContext defaultSSLContext; 74 | /*package*/ static HostnameVerifier defaultHostnameVerifier; 75 | 76 | /*package*/ ReadyState readyState = null; 77 | 78 | private boolean _reconnection; 79 | private boolean skipReconnect; 80 | private boolean reconnecting; 81 | private boolean encoding; 82 | private int _reconnectionAttempts; 83 | private long _reconnectionDelay; 84 | private long _reconnectionDelayMax; 85 | private double _randomizationFactor; 86 | private Backoff backoff; 87 | private long _timeout; 88 | private Set connected; 89 | private URI uri; 90 | private List packetBuffer; 91 | private Queue subs; 92 | private Options opts; 93 | /*package*/ com.github.nkzawa.engineio.client.Socket engine; 94 | private Parser.Encoder encoder; 95 | private Parser.Decoder decoder; 96 | 97 | /** 98 | * This HashMap can be accessed from outside of EventThread. 99 | */ 100 | private ConcurrentHashMap nsps; 101 | 102 | 103 | public Manager() { 104 | this(null, null); 105 | } 106 | 107 | public Manager(URI uri) { 108 | this(uri, null); 109 | } 110 | 111 | public Manager(Options opts) { 112 | this(null, opts); 113 | } 114 | 115 | public Manager(URI uri, Options opts) { 116 | if (opts == null) { 117 | opts = new Options(); 118 | } 119 | if (opts.path == null) { 120 | opts.path = "/socket.io"; 121 | } 122 | if (opts.sslContext == null) { 123 | opts.sslContext = defaultSSLContext; 124 | } 125 | if (opts.hostnameVerifier == null) { 126 | opts.hostnameVerifier = defaultHostnameVerifier; 127 | } 128 | this.opts = opts; 129 | this.nsps = new ConcurrentHashMap(); 130 | this.subs = new LinkedList(); 131 | this.reconnection(opts.reconnection); 132 | this.reconnectionAttempts(opts.reconnectionAttempts != 0 ? opts.reconnectionAttempts : Integer.MAX_VALUE); 133 | this.reconnectionDelay(opts.reconnectionDelay != 0 ? opts.reconnectionDelay : 1000); 134 | this.reconnectionDelayMax(opts.reconnectionDelayMax != 0 ? opts.reconnectionDelayMax : 5000); 135 | this.randomizationFactor(opts.randomizationFactor != 0.0 ? opts.randomizationFactor : 0.5); 136 | this.backoff = new Backoff() 137 | .setMin(this.reconnectionDelay()) 138 | .setMax(this.reconnectionDelayMax()) 139 | .setJitter(this.randomizationFactor()); 140 | this.timeout(opts.timeout); 141 | this.readyState = ReadyState.CLOSED; 142 | this.uri = uri; 143 | this.connected = new HashSet(); 144 | this.encoding = false; 145 | this.packetBuffer = new ArrayList(); 146 | this.encoder = new Parser.Encoder(); 147 | this.decoder = new Parser.Decoder(); 148 | } 149 | 150 | private void emitAll(String event, Object... args) { 151 | this.emit(event, args); 152 | for (Socket socket : this.nsps.values()) { 153 | socket.emit(event, args); 154 | } 155 | } 156 | 157 | /** 158 | * Update `socket.id` of all sockets 159 | */ 160 | private void updateSocketIds() { 161 | for (Socket socket : this.nsps.values()) { 162 | socket.id = this.engine.id(); 163 | } 164 | } 165 | 166 | public boolean reconnection() { 167 | return this._reconnection; 168 | } 169 | 170 | public Manager reconnection(boolean v) { 171 | this._reconnection = v; 172 | return this; 173 | } 174 | 175 | public int reconnectionAttempts() { 176 | return this._reconnectionAttempts; 177 | } 178 | 179 | public Manager reconnectionAttempts(int v) { 180 | this._reconnectionAttempts = v; 181 | return this; 182 | } 183 | 184 | public long reconnectionDelay() { 185 | return this._reconnectionDelay; 186 | } 187 | 188 | public Manager reconnectionDelay(long v) { 189 | this._reconnectionDelay = v; 190 | if (this.backoff != null) { 191 | this.backoff.setMin(v); 192 | } 193 | return this; 194 | } 195 | 196 | public double randomizationFactor() { 197 | return this._randomizationFactor; 198 | } 199 | 200 | public Manager randomizationFactor(double v) { 201 | this._randomizationFactor = v; 202 | if (this.backoff != null) { 203 | this.backoff.setJitter(v); 204 | } 205 | return this; 206 | } 207 | 208 | public long reconnectionDelayMax() { 209 | return this._reconnectionDelayMax; 210 | } 211 | 212 | public Manager reconnectionDelayMax(long v) { 213 | this._reconnectionDelayMax = v; 214 | if (this.backoff != null) { 215 | this.backoff.setMax(v); 216 | } 217 | return this; 218 | } 219 | 220 | public long timeout() { 221 | return this._timeout; 222 | } 223 | 224 | public Manager timeout(long v) { 225 | this._timeout = v; 226 | return this; 227 | } 228 | 229 | private void maybeReconnectOnOpen() { 230 | // Only try to reconnect if it's the first time we're connecting 231 | if (!this.reconnecting && this._reconnection && this.backoff.getAttempts() == 0) { 232 | this.reconnect(); 233 | } 234 | } 235 | 236 | public Manager open(){ 237 | return open(null); 238 | } 239 | 240 | /** 241 | * Connects the client. 242 | * 243 | * @param fn callback. 244 | * @return a reference to this object. 245 | */ 246 | public Manager open(final OpenCallback fn) { 247 | EventThread.exec(new Runnable() { 248 | @Override 249 | public void run() { 250 | logger.fine(String.format("readyState %s", Manager.this.readyState)); 251 | if (Manager.this.readyState == ReadyState.OPEN) return; 252 | 253 | logger.fine(String.format("opening %s", Manager.this.uri)); 254 | Manager.this.engine = new Engine(Manager.this.uri, Manager.this.opts); 255 | final com.github.nkzawa.engineio.client.Socket socket = Manager.this.engine; 256 | final Manager self = Manager.this; 257 | Manager.this.readyState = ReadyState.OPENING; 258 | Manager.this.skipReconnect = false; 259 | 260 | // propagate transport event. 261 | socket.on(Engine.EVENT_TRANSPORT, new Listener() { 262 | @Override 263 | public void call(Object... args) { 264 | self.emit(Manager.EVENT_TRANSPORT, args); 265 | } 266 | }); 267 | 268 | final On.Handle openSub = On.on(socket, Engine.EVENT_OPEN, new Listener() { 269 | @Override 270 | public void call(Object... objects) { 271 | self.onopen(); 272 | if (fn != null) fn.call(null); 273 | } 274 | }); 275 | 276 | On.Handle errorSub = On.on(socket, Engine.EVENT_ERROR, new Listener() { 277 | @Override 278 | public void call(Object... objects) { 279 | Object data = objects.length > 0 ? objects[0] : null; 280 | logger.fine("connect_error"); 281 | self.cleanup(); 282 | self.readyState = ReadyState.CLOSED; 283 | self.emitAll(EVENT_CONNECT_ERROR, data); 284 | if (fn != null) { 285 | Exception err = new SocketIOException("Connection error", 286 | data instanceof Exception ? (Exception) data : null); 287 | fn.call(err); 288 | } else { 289 | // Only do this if there is no fn to handle the error 290 | self.maybeReconnectOnOpen(); 291 | } 292 | } 293 | }); 294 | 295 | if (Manager.this._timeout >= 0) { 296 | final long timeout = Manager.this._timeout; 297 | logger.fine(String.format("connection attempt will timeout after %d", timeout)); 298 | 299 | final Timer timer = new Timer(); 300 | timer.schedule(new TimerTask() { 301 | @Override 302 | public void run() { 303 | EventThread.exec(new Runnable() { 304 | @Override 305 | public void run() { 306 | logger.fine(String.format("connect attempt timed out after %d", timeout)); 307 | openSub.destroy(); 308 | socket.close(); 309 | socket.emit(Engine.EVENT_ERROR, new SocketIOException("timeout")); 310 | self.emitAll(EVENT_CONNECT_TIMEOUT, timeout); 311 | } 312 | }); 313 | } 314 | }, timeout); 315 | 316 | Manager.this.subs.add(new On.Handle() { 317 | @Override 318 | public void destroy() { 319 | timer.cancel(); 320 | } 321 | }); 322 | } 323 | 324 | Manager.this.subs.add(openSub); 325 | Manager.this.subs.add(errorSub); 326 | 327 | Manager.this.engine.open(); 328 | } 329 | }); 330 | return this; 331 | } 332 | 333 | private void onopen() { 334 | logger.fine("open"); 335 | 336 | this.cleanup(); 337 | 338 | this.readyState = ReadyState.OPEN; 339 | this.emit(EVENT_OPEN); 340 | 341 | final com.github.nkzawa.engineio.client.Socket socket = this.engine; 342 | this.subs.add(On.on(socket, Engine.EVENT_DATA, new Listener() { 343 | @Override 344 | public void call(Object... objects) { 345 | Object data = objects[0]; 346 | if (data instanceof String) { 347 | Manager.this.ondata((String)data); 348 | } else if (data instanceof byte[]) { 349 | Manager.this.ondata((byte[])data); 350 | } 351 | } 352 | })); 353 | this.subs.add(On.on(this.decoder, Parser.Decoder.EVENT_DECODED, new Listener() { 354 | @Override 355 | public void call(Object... objects) { 356 | Manager.this.ondecoded((Packet) objects[0]); 357 | } 358 | })); 359 | this.subs.add(On.on(socket, Engine.EVENT_ERROR, new Listener() { 360 | @Override 361 | public void call(Object... objects) { 362 | Manager.this.onerror((Exception)objects[0]); 363 | } 364 | })); 365 | this.subs.add(On.on(socket, Engine.EVENT_CLOSE, new Listener() { 366 | @Override 367 | public void call(Object... objects) { 368 | Manager.this.onclose((String)objects[0]); 369 | } 370 | })); 371 | } 372 | 373 | private void ondata(String data) { 374 | this.decoder.add(data); 375 | } 376 | 377 | private void ondata(byte[] data) { 378 | this.decoder.add(data); 379 | } 380 | 381 | private void ondecoded(Packet packet) { 382 | this.emit(EVENT_PACKET, packet); 383 | } 384 | 385 | private void onerror(Exception err) { 386 | logger.log(Level.FINE, "error", err); 387 | this.emitAll(EVENT_ERROR, err); 388 | } 389 | 390 | /** 391 | * Initializes {@link Socket} instances for each namespaces. 392 | * 393 | * @param nsp namespace. 394 | * @return a socket instance for the namespace. 395 | */ 396 | public Socket socket(String nsp) { 397 | Socket socket = this.nsps.get(nsp); 398 | if (socket == null) { 399 | socket = new Socket(this, nsp); 400 | Socket _socket = this.nsps.putIfAbsent(nsp, socket); 401 | if (_socket != null) { 402 | socket = _socket; 403 | } else { 404 | final Manager self = this; 405 | final Socket s = socket; 406 | socket.on(Socket.EVENT_CONNECT, new Listener() { 407 | @Override 408 | public void call(Object... objects) { 409 | s.id = self.engine.id(); 410 | self.connected.add(s); 411 | } 412 | }); 413 | } 414 | } 415 | return socket; 416 | } 417 | 418 | /*package*/ void destroy(Socket socket) { 419 | this.connected.remove(socket); 420 | if (this.connected.size() > 0) return; 421 | 422 | this.close(); 423 | } 424 | 425 | /*package*/ void packet(Packet packet) { 426 | logger.fine(String.format("writing packet %s", packet)); 427 | final Manager self = this; 428 | 429 | if (!self.encoding) { 430 | self.encoding = true; 431 | this.encoder.encode(packet, new Parser.Encoder.Callback() { 432 | @Override 433 | public void call(Object[] encodedPackets) { 434 | for (Object packet : encodedPackets) { 435 | if (packet instanceof String) { 436 | self.engine.write((String)packet); 437 | } else if (packet instanceof byte[]) { 438 | self.engine.write((byte[])packet); 439 | } 440 | } 441 | self.encoding = false; 442 | self.processPacketQueue(); 443 | } 444 | }); 445 | } else { 446 | self.packetBuffer.add(packet); 447 | } 448 | } 449 | 450 | private void processPacketQueue() { 451 | if (this.packetBuffer.size() > 0 && !this.encoding) { 452 | Packet pack = this.packetBuffer.remove(0); 453 | this.packet(pack); 454 | } 455 | } 456 | 457 | private void cleanup() { 458 | On.Handle sub; 459 | while ((sub = this.subs.poll()) != null) sub.destroy(); 460 | } 461 | 462 | /*package*/ void close() { 463 | if (this.readyState != ReadyState.OPEN) { 464 | this.cleanup(); 465 | } 466 | this.skipReconnect = true; 467 | this.backoff.reset(); 468 | this.readyState = ReadyState.CLOSED; 469 | if (this.engine != null) { 470 | this.engine.close(); 471 | } 472 | } 473 | 474 | private void onclose(String reason) { 475 | logger.fine("close"); 476 | this.cleanup(); 477 | this.backoff.reset(); 478 | this.readyState = ReadyState.CLOSED; 479 | this.emit(EVENT_CLOSE, reason); 480 | 481 | if (this._reconnection && !this.skipReconnect) { 482 | this.reconnect(); 483 | } 484 | } 485 | 486 | private void reconnect() { 487 | if (this.reconnecting || this.skipReconnect) return; 488 | 489 | final Manager self = this; 490 | 491 | if (this.backoff.getAttempts() >= this._reconnectionAttempts) { 492 | logger.fine("reconnect failed"); 493 | this.backoff.reset(); 494 | this.emitAll(EVENT_RECONNECT_FAILED); 495 | this.reconnecting = false; 496 | } else { 497 | long delay = this.backoff.duration(); 498 | logger.fine(String.format("will wait %dms before reconnect attempt", delay)); 499 | 500 | this.reconnecting = true; 501 | final Timer timer = new Timer(); 502 | timer.schedule(new TimerTask() { 503 | @Override 504 | public void run() { 505 | EventThread.exec(new Runnable() { 506 | @Override 507 | public void run() { 508 | if (self.skipReconnect) return; 509 | 510 | logger.fine("attempting reconnect"); 511 | int attempts = self.backoff.getAttempts(); 512 | self.emitAll(EVENT_RECONNECT_ATTEMPT, attempts); 513 | self.emitAll(EVENT_RECONNECTING, attempts); 514 | 515 | // check again for the case socket closed in above events 516 | if (self.skipReconnect) return; 517 | 518 | self.open(new OpenCallback() { 519 | @Override 520 | public void call(Exception err) { 521 | if (err != null) { 522 | logger.fine("reconnect attempt error"); 523 | self.reconnecting = false; 524 | self.reconnect(); 525 | self.emitAll(EVENT_RECONNECT_ERROR, err); 526 | } else { 527 | logger.fine("reconnect success"); 528 | self.onreconnect(); 529 | } 530 | } 531 | }); 532 | } 533 | }); 534 | } 535 | }, delay); 536 | 537 | this.subs.add(new On.Handle() { 538 | @Override 539 | public void destroy() { 540 | timer.cancel(); 541 | } 542 | }); 543 | } 544 | } 545 | 546 | private void onreconnect() { 547 | int attempts = this.backoff.getAttempts(); 548 | this.reconnecting = false; 549 | this.backoff.reset(); 550 | this.updateSocketIds(); 551 | this.emitAll(EVENT_RECONNECT, attempts); 552 | } 553 | 554 | 555 | public static interface OpenCallback { 556 | 557 | public void call(Exception err); 558 | } 559 | 560 | 561 | private static class Engine extends com.github.nkzawa.engineio.client.Socket { 562 | 563 | Engine(URI uri, Options opts) { 564 | super(uri, opts); 565 | } 566 | } 567 | 568 | public static class Options extends com.github.nkzawa.engineio.client.Socket.Options { 569 | 570 | public boolean reconnection = true; 571 | public int reconnectionAttempts; 572 | public long reconnectionDelay; 573 | public long reconnectionDelayMax; 574 | public double randomizationFactor; 575 | 576 | /** 577 | * Connection timeout (ms). Set -1 to disable. 578 | */ 579 | public long timeout = 20000; 580 | } 581 | } 582 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/On.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | 5 | public class On { 6 | 7 | private On() {} 8 | 9 | public static Handle on(final Emitter obj, final String ev, final Emitter.Listener fn) { 10 | obj.on(ev, fn); 11 | return new Handle() { 12 | @Override 13 | public void destroy() { 14 | obj.off(ev, fn); 15 | } 16 | }; 17 | } 18 | 19 | public static interface Handle { 20 | 21 | public void destroy(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/Socket.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import com.github.nkzawa.hasbinary.HasBinary; 5 | import com.github.nkzawa.socketio.parser.Packet; 6 | import com.github.nkzawa.socketio.parser.Parser; 7 | import com.github.nkzawa.thread.EventThread; 8 | import org.json.JSONArray; 9 | import org.json.JSONException; 10 | import org.json.JSONObject; 11 | 12 | import java.util.*; 13 | import java.util.logging.Logger; 14 | 15 | /** 16 | * The socket class for Socket.IO Client. 17 | */ 18 | public class Socket extends Emitter { 19 | 20 | private static final Logger logger = Logger.getLogger(Socket.class.getName()); 21 | 22 | /** 23 | * Called on a connection. 24 | */ 25 | public static final String EVENT_CONNECT = "connect"; 26 | 27 | /** 28 | * Called on a disconnection. 29 | */ 30 | public static final String EVENT_DISCONNECT = "disconnect"; 31 | 32 | /** 33 | * Called on a connection error. 34 | * 35 | *

Parameters:

36 | *
    37 | *
  • (Exception) error data.
  • 38 | *
39 | */ 40 | public static final String EVENT_ERROR = "error"; 41 | 42 | public static final String EVENT_MESSAGE = "message"; 43 | 44 | public static final String EVENT_CONNECT_ERROR = Manager.EVENT_CONNECT_ERROR; 45 | 46 | public static final String EVENT_CONNECT_TIMEOUT = Manager.EVENT_CONNECT_TIMEOUT; 47 | 48 | public static final String EVENT_RECONNECT = Manager.EVENT_RECONNECT; 49 | 50 | public static final String EVENT_RECONNECT_ERROR = Manager.EVENT_RECONNECT_ERROR; 51 | 52 | public static final String EVENT_RECONNECT_FAILED = Manager.EVENT_RECONNECT_FAILED; 53 | 54 | public static final String EVENT_RECONNECT_ATTEMPT = Manager.EVENT_RECONNECT_ATTEMPT; 55 | 56 | public static final String EVENT_RECONNECTING = Manager.EVENT_RECONNECTING; 57 | 58 | private static Map events = new HashMap() {{ 59 | put(EVENT_CONNECT, 1); 60 | put(EVENT_CONNECT_ERROR, 1); 61 | put(EVENT_CONNECT_TIMEOUT, 1); 62 | put(EVENT_DISCONNECT, 1); 63 | put(EVENT_ERROR, 1); 64 | put(EVENT_RECONNECT, 1); 65 | put(EVENT_RECONNECT_ATTEMPT, 1); 66 | put(EVENT_RECONNECT_FAILED, 1); 67 | put(EVENT_RECONNECT_ERROR, 1); 68 | put(EVENT_RECONNECTING, 1); 69 | }}; 70 | 71 | /*package*/ String id; 72 | 73 | private volatile boolean connected; 74 | private int ids; 75 | private String nsp; 76 | private Manager io; 77 | private Map acks = new HashMap(); 78 | private Queue subs; 79 | private final Queue> receiveBuffer = new LinkedList>(); 80 | private final Queue> sendBuffer = new LinkedList>(); 81 | 82 | public Socket(Manager io, String nsp) { 83 | this.io = io; 84 | this.nsp = nsp; 85 | } 86 | 87 | private void subEvents() { 88 | if (this.subs != null) return; 89 | 90 | final Manager io = Socket.this.io; 91 | Socket.this.subs = new LinkedList() {{ 92 | add(On.on(io, Manager.EVENT_OPEN, new Listener() { 93 | @Override 94 | public void call(Object... args) { 95 | Socket.this.onopen(); 96 | } 97 | })); 98 | add(On.on(io, Manager.EVENT_PACKET, new Listener() { 99 | @Override 100 | public void call(Object... args) { 101 | Socket.this.onpacket((Packet) args[0]); 102 | } 103 | })); 104 | add(On.on(io, Manager.EVENT_CLOSE, new Listener() { 105 | @Override 106 | public void call(Object... args) { 107 | Socket.this.onclose(args.length > 0 ? (String) args[0] : null); 108 | } 109 | })); 110 | }}; 111 | } 112 | 113 | /** 114 | * Connects the socket. 115 | */ 116 | public Socket open() { 117 | EventThread.exec(new Runnable() { 118 | @Override 119 | public void run() { 120 | if (Socket.this.connected) return; 121 | 122 | Socket.this.subEvents(); 123 | Socket.this.io.open(); // ensure open 124 | if (Manager.ReadyState.OPEN == Socket.this.io.readyState) Socket.this.onopen(); 125 | } 126 | }); 127 | return this; 128 | } 129 | 130 | /** 131 | * Connects the socket. 132 | */ 133 | public Socket connect() { 134 | return this.open(); 135 | } 136 | 137 | /** 138 | * Send messages. 139 | * 140 | * @param args data to send. 141 | * @return a reference to this object. 142 | */ 143 | public Socket send(final Object... args) { 144 | EventThread.exec(new Runnable() { 145 | @Override 146 | public void run() { 147 | Socket.this.emit(EVENT_MESSAGE, args); 148 | } 149 | }); 150 | return this; 151 | } 152 | 153 | /** 154 | * Emits an event. When you pass {@link Ack} at the last argument, then the acknowledge is done. 155 | * 156 | * @param event an event name. 157 | * @param args data to send. 158 | * @return a reference to this object. 159 | */ 160 | @Override 161 | public Emitter emit(final String event, final Object... args) { 162 | EventThread.exec(new Runnable() { 163 | @Override 164 | public void run() { 165 | if (events.containsKey(event)) { 166 | Socket.super.emit(event, args); 167 | return; 168 | } 169 | 170 | List _args = new ArrayList(args.length + 1); 171 | _args.add(event); 172 | _args.addAll(Arrays.asList(args)); 173 | 174 | JSONArray jsonArgs = new JSONArray(); 175 | for (Object arg : _args) { 176 | jsonArgs.put(arg); 177 | } 178 | int parserType = HasBinary.hasBinary(jsonArgs) ? Parser.BINARY_EVENT : Parser.EVENT; 179 | Packet packet = new Packet(parserType, jsonArgs); 180 | 181 | if (_args.get(_args.size() - 1) instanceof Ack) { 182 | logger.fine(String.format("emitting packet with ack id %d", Socket.this.ids)); 183 | Socket.this.acks.put(Socket.this.ids, (Ack)_args.remove(_args.size() - 1)); 184 | jsonArgs = remove(jsonArgs, jsonArgs.length() - 1); 185 | packet.data = jsonArgs; 186 | packet.id = Socket.this.ids++; 187 | } 188 | 189 | if (Socket.this.connected) { 190 | Socket.this.packet(packet); 191 | } else { 192 | Socket.this.sendBuffer.add(packet); 193 | } 194 | } 195 | }); 196 | return this; 197 | } 198 | 199 | private static JSONArray remove(JSONArray a, int pos) { 200 | JSONArray na = new JSONArray(); 201 | for (int i = 0; i < a.length(); i++){ 202 | if (i != pos) { 203 | Object v; 204 | try { 205 | v = a.get(i); 206 | } catch (JSONException e) { 207 | v = null; 208 | } 209 | na.put(v); 210 | } 211 | } 212 | return na; 213 | } 214 | 215 | /** 216 | * Emits an event with an acknowledge. 217 | * 218 | * @param event an event name 219 | * @param args data to send. 220 | * @param ack the acknowledgement to be called 221 | * @return a reference to this object. 222 | */ 223 | public Emitter emit(final String event, final Object[] args, final Ack ack) { 224 | EventThread.exec(new Runnable() { 225 | @Override 226 | public void run() { 227 | List _args = new ArrayList() {{ 228 | add(event); 229 | if (args != null) { 230 | addAll(Arrays.asList(args)); 231 | } 232 | }}; 233 | 234 | JSONArray jsonArgs = new JSONArray(); 235 | for (Object _arg : _args) { 236 | jsonArgs.put(_arg); 237 | } 238 | int parserType = HasBinary.hasBinary(jsonArgs) ? Parser.BINARY_EVENT : Parser.EVENT; 239 | Packet packet = new Packet(parserType, jsonArgs); 240 | 241 | logger.fine(String.format("emitting packet with ack id %d", ids)); 242 | Socket.this.acks.put(ids, ack); 243 | packet.id = ids++; 244 | 245 | Socket.this.packet(packet); 246 | } 247 | }); 248 | return this; 249 | } 250 | 251 | private void packet(Packet packet) { 252 | packet.nsp = this.nsp; 253 | this.io.packet(packet); 254 | } 255 | 256 | private void onopen() { 257 | logger.fine("transport is open - connecting"); 258 | 259 | if (!"/".equals(this.nsp)) { 260 | this.packet(new Packet(Parser.CONNECT)); 261 | } 262 | } 263 | 264 | private void onclose(String reason) { 265 | logger.fine(String.format("close (%s)", reason)); 266 | this.connected = false; 267 | this.id = null; 268 | this.emit(EVENT_DISCONNECT, reason); 269 | } 270 | 271 | private void onpacket(Packet packet) { 272 | if (!this.nsp.equals(packet.nsp)) return; 273 | 274 | switch (packet.type) { 275 | case Parser.CONNECT: 276 | this.onconnect(); 277 | break; 278 | 279 | case Parser.EVENT: 280 | this.onevent(packet); 281 | break; 282 | 283 | case Parser.BINARY_EVENT: 284 | this.onevent(packet); 285 | break; 286 | 287 | case Parser.ACK: 288 | this.onack(packet); 289 | break; 290 | 291 | case Parser.BINARY_ACK: 292 | this.onack(packet); 293 | break; 294 | 295 | case Parser.DISCONNECT: 296 | this.ondisconnect(); 297 | break; 298 | 299 | case Parser.ERROR: 300 | this.emit(EVENT_ERROR, packet.data); 301 | break; 302 | } 303 | } 304 | 305 | private void onevent(Packet packet) { 306 | List args = new ArrayList(Arrays.asList(toArray(packet.data))); 307 | logger.fine(String.format("emitting event %s", args)); 308 | 309 | if (packet.id >= 0) { 310 | logger.fine("attaching ack callback to event"); 311 | args.add(this.ack(packet.id)); 312 | } 313 | 314 | if (this.connected) { 315 | if (args.size() == 0) return; 316 | String event = args.remove(0).toString(); 317 | super.emit(event, args.toArray()); 318 | } else { 319 | this.receiveBuffer.add(args); 320 | } 321 | } 322 | 323 | private Ack ack(final int id) { 324 | final Socket self = this; 325 | final boolean[] sent = new boolean[] {false}; 326 | return new Ack() { 327 | @Override 328 | public void call(final Object... args) { 329 | EventThread.exec(new Runnable() { 330 | @Override 331 | public void run() { 332 | if (sent[0]) return; 333 | sent[0] = true; 334 | logger.fine(String.format("sending ack %s", args.length != 0 ? args : null)); 335 | 336 | int type = HasBinary.hasBinary(args) ? Parser.BINARY_ACK : Parser.ACK; 337 | Packet packet = new Packet(type, new JSONArray(Arrays.asList(args))); 338 | packet.id = id; 339 | self.packet(packet); 340 | } 341 | }); 342 | } 343 | }; 344 | } 345 | 346 | private void onack(Packet packet) { 347 | logger.fine(String.format("calling ack %s with %s", packet.id, packet.data)); 348 | Ack fn = this.acks.remove(packet.id); 349 | fn.call(toArray(packet.data)); 350 | } 351 | 352 | private void onconnect() { 353 | this.connected = true; 354 | this.emit(EVENT_CONNECT); 355 | this.emitBuffered(); 356 | } 357 | 358 | private void emitBuffered() { 359 | List data; 360 | while ((data = this.receiveBuffer.poll()) != null) { 361 | String event = (String)data.get(0); 362 | super.emit(event, data.toArray()); 363 | } 364 | this.receiveBuffer.clear(); 365 | 366 | Packet packet; 367 | while ((packet = this.sendBuffer.poll()) != null) { 368 | this.packet(packet); 369 | } 370 | this.sendBuffer.clear(); 371 | } 372 | 373 | private void ondisconnect() { 374 | logger.fine(String.format("server disconnect (%s)", this.nsp)); 375 | this.destroy(); 376 | this.onclose("io server disconnect"); 377 | } 378 | 379 | private void destroy() { 380 | if (this.subs != null) { 381 | // clean subscriptions to avoid reconnection 382 | for (On.Handle sub : this.subs) { 383 | sub.destroy(); 384 | } 385 | this.subs = null; 386 | } 387 | 388 | this.io.destroy(this); 389 | } 390 | 391 | /** 392 | * Disconnects the socket. 393 | * 394 | * @return a reference to this object. 395 | */ 396 | public Socket close() { 397 | EventThread.exec(new Runnable() { 398 | @Override 399 | public void run() { 400 | if (Socket.this.connected) { 401 | logger.fine(String.format("performing disconnect (%s)", Socket.this.nsp)); 402 | Socket.this.packet(new Packet(Parser.DISCONNECT)); 403 | } 404 | 405 | Socket.this.destroy(); 406 | 407 | if (Socket.this.connected) { 408 | Socket.this.onclose("io client disconnect"); 409 | } 410 | } 411 | }); 412 | return this; 413 | } 414 | 415 | /** 416 | * Disconnects the socket. 417 | * 418 | * @return a reference to this object. 419 | */ 420 | public Socket disconnect() { 421 | return this.close(); 422 | } 423 | 424 | public Manager io() { 425 | return this.io; 426 | } 427 | 428 | public boolean connected() { 429 | return this.connected; 430 | } 431 | 432 | /** 433 | * A property on the socket instance that is equal to the underlying engine.io socket id. 434 | * 435 | * The value is present once the socket has connected, is removed when the socket disconnects and is updated if the socket reconnects. 436 | * 437 | * @return a socket id 438 | */ 439 | public String id() { 440 | return this.id; 441 | } 442 | 443 | private static Object[] toArray(JSONArray array) { 444 | int length = array.length(); 445 | Object[] data = new Object[length]; 446 | for (int i = 0; i < length; i++) { 447 | Object v; 448 | try { 449 | v = array.get(i); 450 | } catch (JSONException e) { 451 | v = null; 452 | } 453 | data[i] = v == JSONObject.NULL ? null : v; 454 | } 455 | return data; 456 | } 457 | } 458 | 459 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/SocketIOException.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | public class SocketIOException extends Exception { 4 | 5 | public SocketIOException() { 6 | super(); 7 | } 8 | 9 | public SocketIOException(String message) { 10 | super(message); 11 | } 12 | 13 | public SocketIOException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public SocketIOException(Throwable cause) { 18 | super(cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/client/Url.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URI; 5 | import java.net.URISyntaxException; 6 | import java.net.URL; 7 | import java.util.regex.Pattern; 8 | 9 | public class Url { 10 | 11 | private static Pattern PATTERN_HTTP = Pattern.compile("^http|ws$"); 12 | private static Pattern PATTERN_HTTPS = Pattern.compile("^(http|ws)s$"); 13 | 14 | private Url() {} 15 | 16 | public static URL parse(String uri) throws URISyntaxException, MalformedURLException { 17 | return parse(new URI(uri)); 18 | } 19 | 20 | public static URL parse(URI uri) throws MalformedURLException { 21 | String protocol = uri.getScheme(); 22 | if (protocol == null || !protocol.matches("^https?|wss?$")) { 23 | protocol = "https"; 24 | } 25 | 26 | int port = uri.getPort(); 27 | if (port == -1) { 28 | if (PATTERN_HTTP.matcher(protocol).matches()) { 29 | port = 80; 30 | } else if (PATTERN_HTTPS.matcher(protocol).matches()) { 31 | port = 443; 32 | } 33 | } 34 | 35 | String path = uri.getRawPath(); 36 | if (path == null || path.length() == 0) { 37 | path = "/"; 38 | } 39 | 40 | String userInfo = uri.getRawUserInfo(); 41 | String query = uri.getRawQuery(); 42 | String fragment = uri.getRawFragment(); 43 | return new URL(protocol + "://" 44 | + (userInfo != null ? userInfo + "@" : "") 45 | + uri.getHost() 46 | + (port != -1 ? ":" + port : "") 47 | + path 48 | + (query != null ? "?" + query : "") 49 | + (fragment != null ? "#" + fragment : "")); 50 | } 51 | 52 | public static String extractId(String url) throws MalformedURLException { 53 | return extractId(new URL(url)); 54 | } 55 | 56 | public static String extractId(URL url) { 57 | String protocol = url.getProtocol(); 58 | int port = url.getPort(); 59 | if (port == -1) { 60 | if (PATTERN_HTTP.matcher(protocol).matches()) { 61 | port = 80; 62 | } else if (PATTERN_HTTPS.matcher(protocol).matches()) { 63 | port = 443; 64 | } 65 | } 66 | return protocol + "://" + url.getHost() + ":" + port; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/parser/Binary.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.parser; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | 11 | public class Binary { 12 | 13 | private static final String KEY_PLACEHOLDER = "_placeholder"; 14 | 15 | private static final String KEY_NUM = "num"; 16 | 17 | 18 | public static DeconstructedPacket deconstructPacket(Packet packet) { 19 | List buffers = new ArrayList(); 20 | 21 | packet.data = _deconstructPacket(packet.data, buffers); 22 | packet.attachments = buffers.size(); 23 | 24 | DeconstructedPacket result = new DeconstructedPacket(); 25 | result.packet = packet; 26 | result.buffers = buffers.toArray(new byte[buffers.size()][]); 27 | return result; 28 | } 29 | 30 | private static Object _deconstructPacket(Object data, List buffers) { 31 | if (data == null) return null; 32 | 33 | if (data instanceof byte[]) { 34 | JSONObject placeholder = new JSONObject(); 35 | try { 36 | placeholder.put(KEY_PLACEHOLDER, true); 37 | placeholder.put(KEY_NUM, buffers.size()); 38 | } catch (JSONException e) { 39 | return null; 40 | } 41 | buffers.add((byte[])data); 42 | return placeholder; 43 | } else if (data instanceof JSONArray) { 44 | JSONArray newData = new JSONArray(); 45 | JSONArray _data = (JSONArray)data; 46 | int len = _data.length(); 47 | for (int i = 0; i < len; i ++) { 48 | try { 49 | newData.put(i, _deconstructPacket(_data.get(i), buffers)); 50 | } catch (JSONException e) { 51 | return null; 52 | } 53 | } 54 | return newData; 55 | } else if (data instanceof JSONObject) { 56 | JSONObject newData = new JSONObject(); 57 | JSONObject _data = (JSONObject)data; 58 | Iterator iterator = _data.keys(); 59 | while (iterator.hasNext()) { 60 | String key = (String)iterator.next(); 61 | try { 62 | newData.put(key, _deconstructPacket(_data.get(key), buffers)); 63 | } catch (JSONException e) { 64 | return null; 65 | } 66 | } 67 | return newData; 68 | } 69 | return data; 70 | } 71 | 72 | public static Packet reconstructPacket(Packet packet, byte[][] buffers) { 73 | packet.data = _reconstructPacket(packet.data, buffers); 74 | packet.attachments = -1; 75 | return packet; 76 | } 77 | 78 | private static Object _reconstructPacket(Object data, byte[][] buffers) { 79 | if (data instanceof JSONArray) { 80 | JSONArray _data = (JSONArray)data; 81 | int len = _data.length(); 82 | for (int i = 0; i < len; i ++) { 83 | try { 84 | _data.put(i, _reconstructPacket(_data.get(i), buffers)); 85 | } catch (JSONException e) { 86 | return null; 87 | } 88 | } 89 | return _data; 90 | } else if (data instanceof JSONObject) { 91 | JSONObject _data = (JSONObject)data; 92 | if (_data.optBoolean(KEY_PLACEHOLDER)) { 93 | int num = _data.optInt(KEY_NUM, -1); 94 | return num >= 0 && num < buffers.length ? buffers[num] : null; 95 | } 96 | Iterator iterator = _data.keys(); 97 | while (iterator.hasNext()) { 98 | String key = (String)iterator.next(); 99 | try { 100 | _data.put(key, _reconstructPacket(_data.get(key), buffers)); 101 | } catch (JSONException e) { 102 | return null; 103 | } 104 | } 105 | return _data; 106 | } 107 | return data; 108 | } 109 | 110 | public static class DeconstructedPacket { 111 | 112 | public Packet packet; 113 | public byte[][] buffers; 114 | } 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/parser/Packet.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.parser; 2 | 3 | 4 | public class Packet { 5 | 6 | public int type = -1; 7 | public int id = -1; 8 | public String nsp; 9 | public T data; 10 | public int attachments; 11 | 12 | public Packet() {} 13 | 14 | public Packet(int type) { 15 | this.type = type; 16 | } 17 | 18 | public Packet(int type, T data) { 19 | this.type = type; 20 | this.data = data; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/main/java/com/github/nkzawa/socketio/parser/Parser.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.parser; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import org.json.JSONException; 5 | import org.json.JSONTokener; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | import java.util.logging.Logger; 11 | 12 | public class Parser { 13 | 14 | private static final Logger logger = Logger.getLogger(Parser.class.getName()); 15 | 16 | /** 17 | * Packet type `connect`. 18 | */ 19 | public static final int CONNECT = 0; 20 | 21 | /** 22 | * Packet type `disconnect`. 23 | */ 24 | public static final int DISCONNECT = 1; 25 | 26 | /** 27 | * Packet type `event`. 28 | */ 29 | public static final int EVENT = 2; 30 | 31 | /** 32 | * Packet type `ack`. 33 | */ 34 | public static final int ACK = 3; 35 | 36 | /** 37 | * Packet type `error`. 38 | */ 39 | public static final int ERROR = 4; 40 | 41 | /** 42 | * Packet type `binary event`. 43 | */ 44 | public static final int BINARY_EVENT = 5; 45 | 46 | /** 47 | * Packet type `binary ack`. 48 | */ 49 | public static final int BINARY_ACK = 6; 50 | 51 | public static int protocol = 4; 52 | 53 | /** 54 | * Packet types. 55 | */ 56 | public static String[] types = new String[] { 57 | "CONNECT", 58 | "DISCONNECT", 59 | "EVENT", 60 | "ACK", 61 | "ERROR", 62 | "BINARY_EVENT", 63 | "BINARY_ACK" 64 | }; 65 | 66 | 67 | private Parser() {} 68 | 69 | private static Packet error() { 70 | return new Packet(ERROR, "parser error"); 71 | } 72 | 73 | 74 | public static class Encoder { 75 | 76 | public Encoder() {} 77 | 78 | public void encode(Packet obj, Callback callback) { 79 | logger.fine(String.format("encoding packet %s", obj)); 80 | 81 | if (BINARY_EVENT == obj.type || BINARY_ACK == obj.type) { 82 | encodeAsBinary(obj, callback); 83 | } else { 84 | String encoding = encodeAsString(obj); 85 | callback.call(new String[] {encoding}); 86 | } 87 | } 88 | 89 | private String encodeAsString(Packet obj) { 90 | StringBuilder str = new StringBuilder(); 91 | boolean nsp = false; 92 | 93 | str.append(obj.type); 94 | 95 | if (BINARY_EVENT == obj.type || BINARY_ACK == obj.type) { 96 | str.append(obj.attachments); 97 | str.append("-"); 98 | } 99 | 100 | if (obj.nsp != null && obj.nsp.length() != 0 && !"/".equals(obj.nsp)) { 101 | nsp = true; 102 | str.append(obj.nsp); 103 | } 104 | 105 | if (obj.id >= 0) { 106 | if (nsp) { 107 | str.append(","); 108 | nsp = false; 109 | } 110 | str.append(obj.id); 111 | } 112 | 113 | if (obj.data != null) { 114 | if (nsp) str.append(","); 115 | str.append(obj.data); 116 | } 117 | 118 | logger.fine(String.format("encoded %s as %s", obj, str)); 119 | return str.toString(); 120 | } 121 | 122 | private void encodeAsBinary(Packet obj, Callback callback) { 123 | Binary.DeconstructedPacket deconstruction = Binary.deconstructPacket(obj); 124 | String pack = encodeAsString(deconstruction.packet); 125 | List buffers = new ArrayList(Arrays.asList(deconstruction.buffers)); 126 | 127 | buffers.add(0, pack); 128 | callback.call(buffers.toArray()); 129 | } 130 | 131 | public interface Callback { 132 | 133 | public void call(Object[] data); 134 | } 135 | } 136 | 137 | public static class Decoder extends Emitter { 138 | 139 | public static String EVENT_DECODED = "decoded"; 140 | 141 | /*package*/ BinaryReconstructor reconstructor; 142 | 143 | public Decoder() { 144 | this.reconstructor = null; 145 | } 146 | 147 | public void add(String obj) { 148 | Packet packet = decodeString(obj); 149 | if (BINARY_EVENT == packet.type || BINARY_ACK == packet.type) { 150 | this.reconstructor = new BinaryReconstructor(packet); 151 | 152 | if (this.reconstructor.reconPack.attachments == 0) { 153 | this.emit(EVENT_DECODED, packet); 154 | } 155 | } else { 156 | this.emit(EVENT_DECODED, packet); 157 | } 158 | } 159 | 160 | public void add(byte[] obj) { 161 | if (this.reconstructor == null) { 162 | throw new RuntimeException("got binary data when not reconstructing a packet"); 163 | } else { 164 | Packet packet = this.reconstructor.takeBinaryData(obj); 165 | if (packet != null) { 166 | this.reconstructor = null; 167 | this.emit(EVENT_DECODED, packet); 168 | } 169 | } 170 | } 171 | 172 | private static Packet decodeString(String str) { 173 | Packet p = new Packet(); 174 | int i = 0; 175 | int length = str.length(); 176 | 177 | p.type = Character.getNumericValue(str.charAt(0)); 178 | if (p.type < 0 || p.type > types.length - 1) return error(); 179 | 180 | if (BINARY_EVENT == p.type || BINARY_ACK == p.type) { 181 | if (!str.contains("-") || length <= i + 1) return error(); 182 | StringBuilder attachments = new StringBuilder(); 183 | while (str.charAt(++i) != '-') { 184 | attachments.append(str.charAt(i)); 185 | } 186 | p.attachments = Integer.parseInt(attachments.toString()); 187 | } 188 | 189 | if (length > i + 1 && '/' == str.charAt(i + 1)) { 190 | StringBuilder nsp = new StringBuilder(); 191 | while (true) { 192 | ++i; 193 | char c = str.charAt(i); 194 | if (',' == c) break; 195 | nsp.append(c); 196 | if (i + 1 == length) break; 197 | } 198 | p.nsp = nsp.toString(); 199 | } else { 200 | p.nsp = "/"; 201 | } 202 | 203 | if (length > i + 1){ 204 | Character next = str.charAt(i + 1); 205 | if (Character.getNumericValue(next) > -1) { 206 | StringBuilder id = new StringBuilder(); 207 | while (true) { 208 | ++i; 209 | char c = str.charAt(i); 210 | if (Character.getNumericValue(c) < 0) { 211 | --i; 212 | break; 213 | } 214 | id.append(c); 215 | if (i + 1 == length) break; 216 | } 217 | try { 218 | p.id = Integer.parseInt(id.toString()); 219 | } catch (NumberFormatException e){ 220 | return error(); 221 | } 222 | } 223 | } 224 | 225 | if (length > i + 1){ 226 | try { 227 | str.charAt(++i); 228 | p.data = new JSONTokener(str.substring(i)).nextValue(); 229 | } catch (JSONException e) { 230 | return error(); 231 | } 232 | } 233 | 234 | logger.fine(String.format("decoded %s as %s", str, p)); 235 | return p; 236 | } 237 | 238 | public void destroy() { 239 | if (this.reconstructor != null) { 240 | this.reconstructor.finishReconstruction(); 241 | } 242 | } 243 | } 244 | 245 | 246 | /*package*/ static class BinaryReconstructor { 247 | 248 | public Packet reconPack; 249 | 250 | /*package*/ List buffers; 251 | 252 | BinaryReconstructor(Packet packet) { 253 | this.reconPack = packet; 254 | this.buffers = new ArrayList(); 255 | } 256 | 257 | public Packet takeBinaryData(byte[] binData) { 258 | this.buffers.add(binData); 259 | if (this.buffers.size() == this.reconPack.attachments) { 260 | Packet packet = Binary.reconstructPacket(this.reconPack, 261 | this.buffers.toArray(new byte[this.buffers.size()][])); 262 | this.finishReconstruction(); 263 | return packet; 264 | } 265 | return null; 266 | } 267 | 268 | public void finishReconstruction () { 269 | this.reconPack = null; 270 | this.buffers = new ArrayList(); 271 | } 272 | } 273 | } 274 | 275 | 276 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/backo/BackoffTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.backo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertTrue; 6 | 7 | public class BackoffTest { 8 | 9 | @Test 10 | public void durationShouldIncreaseTheBackoff() { 11 | Backoff b = new Backoff(); 12 | 13 | assertTrue(100 == b.duration()); 14 | assertTrue(200 == b.duration()); 15 | assertTrue(400 == b.duration()); 16 | assertTrue(800 == b.duration()); 17 | 18 | b.reset(); 19 | assertTrue(100 == b.duration()); 20 | assertTrue(200 == b.duration()); 21 | } 22 | 23 | @Test 24 | public void durationOverflow() { 25 | Backoff b = new Backoff(); 26 | b.setMin(100); 27 | b.setMax(10000); 28 | b.setJitter(1.0); 29 | 30 | for (int i = 0; i < 100; i++) { 31 | long duration = b.duration(); 32 | assertTrue(100 <= duration && duration <= 10000); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/hasbinary/HasBinaryTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.hasbinary; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.JUnit4; 9 | 10 | import java.nio.charset.Charset; 11 | 12 | import static org.junit.Assert.assertTrue; 13 | 14 | @RunWith(JUnit4.class) 15 | public class HasBinaryTest { 16 | 17 | @Test 18 | public void byteArray() { 19 | assertTrue(HasBinary.hasBinary(new byte[0])); 20 | } 21 | 22 | @Test 23 | public void anArrayThatDoesNotContainByteArray() throws JSONException { 24 | JSONArray arr = new JSONArray("[1, \"cool\", 2]"); 25 | assertTrue(!HasBinary.hasBinary(arr)); 26 | } 27 | 28 | @Test 29 | public void anArrayContainsByteArray() throws JSONException { 30 | JSONArray arr = new JSONArray("[1, null, 2]"); 31 | arr.put(1, "asdfasdf".getBytes(Charset.forName("UTF-8"))); 32 | assertTrue(HasBinary.hasBinary(arr)); 33 | } 34 | 35 | @Test 36 | public void anObjectThatDoesNotContainByteArray() throws JSONException { 37 | JSONObject ob = new JSONObject("{\"a\": \"a\", \"b\": [], \"c\": 1234}"); 38 | assertTrue(!HasBinary.hasBinary(ob)); 39 | } 40 | 41 | @Test 42 | public void anObjectThatContainsByteArray() throws JSONException { 43 | JSONObject ob = new JSONObject("{\"a\": \"a\", \"b\": null, \"c\": 1234}"); 44 | ob.put("b", "abc".getBytes(Charset.forName("UTF-8"))); 45 | assertTrue(HasBinary.hasBinary(ob)); 46 | } 47 | 48 | @Test 49 | public void testNull() { 50 | assertTrue(!HasBinary.hasBinary(null)); 51 | } 52 | 53 | @Test 54 | public void aComplexObjectThatContainsNoBinary() throws JSONException { 55 | JSONObject ob = new JSONObject(); 56 | ob.put("x", new JSONArray("[\"a\", \"b\", 123]")); 57 | ob.put("y", JSONObject.NULL); 58 | ob.put("z", new JSONObject("{\"a\": \"x\", \"b\": \"y\", \"c\": 3, \"d\": null}")); 59 | ob.put("w", new JSONArray()); 60 | assertTrue(!HasBinary.hasBinary(ob)); 61 | } 62 | 63 | @Test 64 | public void aComplexObjectThatContainsBinary() throws JSONException { 65 | JSONObject ob = new JSONObject(); 66 | ob.put("x", new JSONArray("[\"a\", \"b\", 123]")); 67 | ob.put("y", JSONObject.NULL); 68 | ob.put("z", new JSONObject("{\"a\": \"x\", \"b\": \"y\", \"c\": 3, \"d\": null}")); 69 | ob.put("w", new JSONArray()); 70 | ob.put("bin", "xxx".getBytes(Charset.forName("UTF-8"))); 71 | assertTrue(HasBinary.hasBinary(ob)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/Connection.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.net.URISyntaxException; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.concurrent.*; 13 | import java.util.logging.Logger; 14 | 15 | public abstract class Connection { 16 | 17 | private static final Logger logger = Logger.getLogger(Connection.class.getName()); 18 | 19 | final static int TIMEOUT = 7000; 20 | final static int PORT = 3000; 21 | 22 | private Process serverProcess; 23 | private ExecutorService serverService; 24 | private Future serverOutput; 25 | private Future serverError; 26 | 27 | @Before 28 | public void startServer() throws IOException, InterruptedException { 29 | logger.fine("Starting server ..."); 30 | 31 | final CountDownLatch latch = new CountDownLatch(1); 32 | serverProcess = Runtime.getRuntime().exec( 33 | String.format("node src/test/resources/server.js %s", nsp()), createEnv()); 34 | serverService = Executors.newCachedThreadPool(); 35 | serverOutput = serverService.submit(new Runnable() { 36 | @Override 37 | public void run() { 38 | BufferedReader reader = new BufferedReader( 39 | new InputStreamReader(serverProcess.getInputStream())); 40 | String line; 41 | try { 42 | line = reader.readLine(); 43 | latch.countDown(); 44 | do { 45 | logger.fine("SERVER OUT: " + line); 46 | } while ((line = reader.readLine()) != null); 47 | } catch (IOException e) { 48 | logger.warning(e.getMessage()); 49 | } 50 | } 51 | }); 52 | serverError = serverService.submit(new Runnable() { 53 | @Override 54 | public void run() { 55 | BufferedReader reader = new BufferedReader( 56 | new InputStreamReader(serverProcess.getErrorStream())); 57 | String line; 58 | try { 59 | while ((line = reader.readLine()) != null) { 60 | logger.fine("SERVER ERR: " + line); 61 | } 62 | } catch (IOException e) { 63 | logger.warning(e.getMessage()); 64 | } 65 | } 66 | }); 67 | latch.await(3000, TimeUnit.MILLISECONDS); 68 | } 69 | 70 | @After 71 | public void stopServer() throws InterruptedException { 72 | logger.fine("Stopping server ..."); 73 | serverProcess.destroy(); 74 | serverOutput.cancel(false); 75 | serverError.cancel(false); 76 | serverService.shutdown(); 77 | serverService.awaitTermination(3000, TimeUnit.MILLISECONDS); 78 | } 79 | 80 | Socket client() throws URISyntaxException { 81 | return client(createOptions()); 82 | } 83 | 84 | Socket client(IO.Options opts) throws URISyntaxException { 85 | return IO.socket(uri() + nsp(), opts); 86 | } 87 | 88 | String uri() { 89 | return "http://localhost:" + PORT; 90 | } 91 | 92 | String nsp() { 93 | return "/"; 94 | } 95 | 96 | IO.Options createOptions() { 97 | IO.Options opts = new IO.Options(); 98 | opts.forceNew = true; 99 | return opts; 100 | } 101 | 102 | String[] createEnv() { 103 | Map env = new HashMap(System.getenv()); 104 | env.put("DEBUG", "socket.io:*"); 105 | env.put("PORT", String.valueOf(PORT)); 106 | String[] _env = new String[env.size()]; 107 | int i = 0; 108 | for (String key : env.keySet()) { 109 | _env[i] = key + "=" + env.get(key); 110 | i++; 111 | } 112 | return _env; 113 | 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/ConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.JUnit4; 9 | 10 | import java.net.URI; 11 | import java.net.URISyntaxException; 12 | import java.nio.charset.Charset; 13 | import java.util.Date; 14 | import java.util.Timer; 15 | import java.util.TimerTask; 16 | import java.util.concurrent.BlockingQueue; 17 | import java.util.concurrent.LinkedBlockingQueue; 18 | 19 | import static org.hamcrest.CoreMatchers.instanceOf; 20 | import static org.hamcrest.CoreMatchers.is; 21 | import static org.junit.Assert.assertThat; 22 | 23 | @RunWith(JUnit4.class) 24 | public class ConnectionTest extends Connection { 25 | 26 | private Socket socket; 27 | 28 | @Test(timeout = TIMEOUT) 29 | public void connectToLocalhost() throws URISyntaxException, InterruptedException { 30 | final BlockingQueue values = new LinkedBlockingQueue(); 31 | socket = client(); 32 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 33 | @Override 34 | public void call(Object... objects) { 35 | socket.emit("echo"); 36 | socket.on("echoBack", new Emitter.Listener() { 37 | @Override 38 | public void call(Object... args) { 39 | values.offer("done"); 40 | } 41 | }); 42 | } 43 | }); 44 | socket.connect(); 45 | values.take(); 46 | socket.close(); 47 | } 48 | 49 | @Test(timeout = TIMEOUT) 50 | public void workWithAcks() throws URISyntaxException, InterruptedException { 51 | final BlockingQueue values = new LinkedBlockingQueue(); 52 | socket = client(); 53 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 54 | @Override 55 | public void call(Object... objects) { 56 | socket.emit("callAck"); 57 | socket.on("ack", new Emitter.Listener() { 58 | @Override 59 | public void call(Object... args) { 60 | Ack fn = (Ack) args[0]; 61 | JSONObject data = new JSONObject(); 62 | try { 63 | data.put("test", true); 64 | } catch (JSONException e) { 65 | throw new AssertionError(e); 66 | } 67 | fn.call(5, data); 68 | } 69 | }); 70 | socket.on("ackBack", new Emitter.Listener() { 71 | @Override 72 | public void call(Object... args) { 73 | JSONObject data = (JSONObject)args[1]; 74 | try { 75 | if ((Integer)args[0] == 5 && data.getBoolean("test")) { 76 | values.offer("done"); 77 | } 78 | } catch (JSONException e) { 79 | throw new AssertionError(e); 80 | } 81 | } 82 | }); 83 | } 84 | }); 85 | socket.connect(); 86 | values.take(); 87 | socket.close(); 88 | } 89 | 90 | @Test(timeout = TIMEOUT) 91 | public void receiveDateWithAck() throws URISyntaxException, InterruptedException { 92 | final BlockingQueue values = new LinkedBlockingQueue(); 93 | socket = client(); 94 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 95 | @Override 96 | public void call(Object... objects) { 97 | try { 98 | socket.emit("getAckDate", new JSONObject("{test: true}"), new Ack() { 99 | @Override 100 | public void call(Object... args) { 101 | values.offer(args[0]); 102 | } 103 | }); 104 | } catch (JSONException e) { 105 | throw new AssertionError(e); 106 | } 107 | } 108 | }); 109 | socket.connect(); 110 | assertThat(values.take(), instanceOf(String.class)); 111 | socket.close(); 112 | } 113 | 114 | @Test(timeout = TIMEOUT) 115 | public void workWithFalse() throws URISyntaxException, InterruptedException { 116 | final BlockingQueue values = new LinkedBlockingQueue(); 117 | socket = client(); 118 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 119 | @Override 120 | public void call(Object... objects) { 121 | socket.emit("echo", false); 122 | socket.on("echoBack", new Emitter.Listener() { 123 | @Override 124 | public void call(Object... args) { 125 | values.offer(args[0]); 126 | } 127 | }); 128 | } 129 | }); 130 | socket.connect(); 131 | assertThat((Boolean)values.take(), is(false)); 132 | socket.close(); 133 | } 134 | 135 | @Test(timeout = TIMEOUT) 136 | public void receiveUTF8MultibyteCharacters() throws URISyntaxException, InterruptedException { 137 | final BlockingQueue values = new LinkedBlockingQueue(); 138 | final String[] correct = new String[] { 139 | "てすと", 140 | "Я Б Г Д Ж Й", 141 | "Ä ä Ü ü ß", 142 | "utf8 — string", 143 | "utf8 — string" 144 | }; 145 | 146 | socket = client(); 147 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 148 | @Override 149 | public void call(Object... objects) { 150 | socket.on("echoBack", new Emitter.Listener() { 151 | @Override 152 | public void call(Object... args) { 153 | values.offer(args[0]); 154 | } 155 | }); 156 | for (String data : correct) { 157 | socket.emit("echo", data); 158 | } 159 | } 160 | }); 161 | socket.connect(); 162 | for (String expected : correct) { 163 | assertThat((String)values.take(), is(expected)); 164 | } 165 | socket.close(); 166 | } 167 | 168 | @Test(timeout = TIMEOUT) 169 | public void connectToNamespaceAfterConnectionEstablished() throws URISyntaxException, InterruptedException { 170 | final BlockingQueue values = new LinkedBlockingQueue(); 171 | final Manager manager = new Manager(new URI(uri())); 172 | socket = manager.socket("/"); 173 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 174 | @Override 175 | public void call(Object... objects) { 176 | final Socket foo = manager.socket("/foo"); 177 | foo.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 178 | @Override 179 | public void call(Object... args) { 180 | foo.close(); 181 | socket.close(); 182 | manager.close(); 183 | values.offer("done"); 184 | } 185 | }); 186 | foo.open(); 187 | } 188 | }); 189 | socket.open(); 190 | values.take(); 191 | } 192 | 193 | @Test(timeout = TIMEOUT) 194 | public void connectToNamespaceAfterConnectionGetsClosed() throws URISyntaxException, InterruptedException { 195 | final BlockingQueue values = new LinkedBlockingQueue(); 196 | final Manager manager = new Manager(new URI(uri())); 197 | socket = manager.socket("/"); 198 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 199 | @Override 200 | public void call(Object... objects) { 201 | socket.close(); 202 | } 203 | }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 204 | @Override 205 | public void call(Object... objects) { 206 | final Socket foo = manager.socket("/foo"); 207 | foo.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 208 | @Override 209 | public void call(Object... args) { 210 | foo.close(); 211 | manager.close(); 212 | values.offer("done"); 213 | } 214 | }); 215 | foo.open(); 216 | } 217 | }); 218 | socket.open(); 219 | values.take(); 220 | } 221 | 222 | @Test(timeout = TIMEOUT) 223 | public void reconnectByDefault() throws URISyntaxException, InterruptedException { 224 | final BlockingQueue values = new LinkedBlockingQueue(); 225 | socket = client(); 226 | socket.io().on(Manager.EVENT_RECONNECT, new Emitter.Listener() { 227 | @Override 228 | public void call(Object... objects) { 229 | socket.close(); 230 | values.offer("done"); 231 | } 232 | }); 233 | socket.open(); 234 | new Timer().schedule(new TimerTask() { 235 | @Override 236 | public void run() { 237 | socket.io().engine.close(); 238 | } 239 | }, 500); 240 | values.take(); 241 | } 242 | 243 | @Test(timeout = TIMEOUT) 244 | public void reconnectManually() throws URISyntaxException, InterruptedException { 245 | final BlockingQueue values = new LinkedBlockingQueue(); 246 | socket = client(); 247 | socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() { 248 | @Override 249 | public void call(Object... args) { 250 | socket.disconnect(); 251 | } 252 | }).once(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 253 | @Override 254 | public void call(Object... args) { 255 | socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() { 256 | @Override 257 | public void call(Object... args) { 258 | socket.disconnect(); 259 | values.offer("done"); 260 | } 261 | }); 262 | socket.connect(); 263 | } 264 | }); 265 | socket.connect(); 266 | values.take(); 267 | } 268 | 269 | @Test(timeout = TIMEOUT) 270 | public void reconnectAutomaticallyAfterReconnectingManually() throws URISyntaxException, InterruptedException { 271 | final BlockingQueue values = new LinkedBlockingQueue(); 272 | socket = client(); 273 | socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() { 274 | @Override 275 | public void call(Object... args) { 276 | socket.disconnect(); 277 | } 278 | }).once(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 279 | @Override 280 | public void call(Object... args) { 281 | socket.on(Socket.EVENT_RECONNECT, new Emitter.Listener() { 282 | @Override 283 | public void call(Object... args) { 284 | socket.disconnect(); 285 | values.offer("done"); 286 | } 287 | }); 288 | socket.connect(); 289 | new Timer().schedule(new TimerTask() { 290 | @Override 291 | public void run() { 292 | socket.io().engine.close(); 293 | } 294 | }, 500); 295 | } 296 | }); 297 | socket.connect(); 298 | values.take(); 299 | } 300 | 301 | @Test(timeout = TIMEOUT) 302 | public void attemptReconnectsAfterAFailedReconnect() throws URISyntaxException, InterruptedException { 303 | final BlockingQueue values = new LinkedBlockingQueue(); 304 | IO.Options opts = createOptions(); 305 | opts.reconnection = true; 306 | opts.timeout = 0; 307 | opts.reconnectionAttempts = 2; 308 | opts.reconnectionDelay = 10; 309 | final Manager manager = new Manager(new URI(uri()), opts); 310 | socket = manager.socket("/timeout"); 311 | socket.once(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 312 | @Override 313 | public void call(Object... args) { 314 | final int[] reconnects = new int[] {0}; 315 | Emitter.Listener reconnectCb = new Emitter.Listener() { 316 | @Override 317 | public void call(Object... args) { 318 | reconnects[0]++; 319 | } 320 | }; 321 | 322 | manager.on(Manager.EVENT_RECONNECT_ATTEMPT, reconnectCb); 323 | manager.on(Manager.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 324 | @Override 325 | public void call(Object... args) { 326 | values.offer(reconnects[0]); 327 | } 328 | }); 329 | socket.connect(); 330 | } 331 | }); 332 | socket.connect(); 333 | assertThat((Integer)values.take(), is(2)); 334 | socket.close(); 335 | manager.close(); 336 | } 337 | 338 | @Test(timeout = TIMEOUT) 339 | public void reconnectDelayShouldIncreaseEveryTime() throws URISyntaxException, InterruptedException { 340 | final BlockingQueue values = new LinkedBlockingQueue(); 341 | IO.Options opts = createOptions(); 342 | opts.reconnection = true; 343 | opts.timeout = 0; 344 | opts.reconnectionAttempts = 5; 345 | opts.reconnectionDelay = 10; 346 | opts.randomizationFactor = 0.2; 347 | final Manager manager = new Manager(new URI(uri()), opts); 348 | socket = manager.socket("/timeout"); 349 | 350 | final int[] reconnects = new int[] {0}; 351 | final boolean[] increasingDelay = new boolean[] {true}; 352 | final long[] startTime = new long[] {0}; 353 | final long[] prevDelay = new long[] {0}; 354 | 355 | socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() { 356 | @Override 357 | public void call(Object... args) { 358 | startTime[0] = new Date().getTime(); 359 | } 360 | }); 361 | socket.on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() { 362 | @Override 363 | public void call(Object... args) { 364 | reconnects[0]++; 365 | long currentTime = new Date().getTime(); 366 | long delay = currentTime - startTime[0]; 367 | if (delay <= prevDelay[0]) { 368 | increasingDelay[0] = false; 369 | } 370 | prevDelay[0] = delay; 371 | } 372 | }); 373 | socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 374 | @Override 375 | public void call(Object... args) { 376 | values.offer(true); 377 | } 378 | }); 379 | 380 | socket.connect(); 381 | values.take(); 382 | assertThat(reconnects[0], is(5)); 383 | // this fails sometimes 384 | //assertThat(increasingDelay[0], is(true)); 385 | socket.close(); 386 | manager.close(); 387 | } 388 | 389 | @Test(timeout = TIMEOUT) 390 | public void reconnectEventFireInSocket() throws URISyntaxException, InterruptedException { 391 | final BlockingQueue values = new LinkedBlockingQueue(); 392 | socket = client(); 393 | socket.on(Socket.EVENT_RECONNECT, new Emitter.Listener() { 394 | @Override 395 | public void call(Object... objects) { 396 | values.offer("done"); 397 | } 398 | }); 399 | socket.open(); 400 | new Timer().schedule(new TimerTask() { 401 | @Override 402 | public void run() { 403 | socket.io().engine.close(); 404 | } 405 | }, 500); 406 | values.take(); 407 | socket.close(); 408 | } 409 | 410 | @Test(timeout = TIMEOUT) 411 | public void notReconnectWhenForceClosed() throws URISyntaxException, InterruptedException { 412 | final BlockingQueue values = new LinkedBlockingQueue(); 413 | IO.Options opts = createOptions(); 414 | opts.timeout = 0; 415 | opts.reconnectionDelay = 10; 416 | socket = IO.socket(uri() + "/invalid", opts); 417 | socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() { 418 | @Override 419 | public void call(Object... args) { 420 | socket.on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() { 421 | @Override 422 | public void call(Object... args) { 423 | values.offer(false); 424 | } 425 | }); 426 | socket.disconnect(); 427 | new Timer().schedule(new TimerTask() { 428 | @Override 429 | public void run() { 430 | values.offer(true); 431 | } 432 | }, 500); 433 | } 434 | }); 435 | socket.connect(); 436 | assertThat((Boolean)values.take(), is(true)); 437 | } 438 | 439 | @Test(timeout = TIMEOUT) 440 | public void stopReconnectingWhenForceClosed() throws URISyntaxException, InterruptedException { 441 | final BlockingQueue values = new LinkedBlockingQueue(); 442 | IO.Options opts = createOptions(); 443 | opts.timeout = 0; 444 | opts.reconnectionDelay = 10; 445 | socket = IO.socket(uri() + "/invalid", opts); 446 | socket.once(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() { 447 | @Override 448 | public void call(Object... args) { 449 | socket.on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() { 450 | @Override 451 | public void call(Object... args) { 452 | values.offer(false); 453 | } 454 | }); 455 | socket.disconnect(); 456 | // set a timer to let reconnection possibly fire 457 | new Timer().schedule(new TimerTask() { 458 | @Override 459 | public void run() { 460 | values.offer(true); 461 | } 462 | }, 500); 463 | } 464 | }); 465 | socket.connect(); 466 | assertThat((Boolean) values.take(), is(true)); 467 | } 468 | 469 | @Test(timeout = TIMEOUT) 470 | public void stopReconnectingOnASocketAndKeepToReconnectOnAnother() throws URISyntaxException, InterruptedException { 471 | final BlockingQueue values = new LinkedBlockingQueue(); 472 | final Manager manager = new Manager(new URI(uri())); 473 | final Socket socket1 = manager.socket("/"); 474 | final Socket socket2 = manager.socket("/asd"); 475 | 476 | manager.on(Manager.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() { 477 | @Override 478 | public void call(Object... args) { 479 | socket1.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 480 | @Override 481 | public void call(Object... args) { 482 | values.offer(false); 483 | } 484 | }); 485 | socket2.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 486 | @Override 487 | public void call(Object... args) { 488 | new Timer().schedule(new TimerTask() { 489 | @Override 490 | public void run() { 491 | socket2.disconnect(); 492 | manager.close(); 493 | values.offer(true); 494 | } 495 | }, 500); 496 | } 497 | }); 498 | socket1.disconnect(); 499 | } 500 | }); 501 | 502 | socket1.connect(); 503 | socket2.connect(); 504 | 505 | new Timer().schedule(new TimerTask() { 506 | @Override 507 | public void run() { 508 | manager.engine.close(); 509 | } 510 | }, 1000); 511 | 512 | assertThat((Boolean) values.take(), is(true)); 513 | } 514 | 515 | @Test(timeout = TIMEOUT) 516 | public void tryToReconnectTwiceAndFailWithIncorrectAddress() throws URISyntaxException, InterruptedException { 517 | final BlockingQueue values = new LinkedBlockingQueue(); 518 | IO.Options opts = new IO.Options(); 519 | opts.reconnection = true; 520 | opts.reconnectionAttempts = 2; 521 | opts.reconnectionDelay = 10; 522 | final Manager manager = new Manager(new URI("http://localhost:3940"), opts); 523 | socket = manager.socket("/asd"); 524 | final int[] reconnects = new int[] {0}; 525 | Emitter.Listener cb = new Emitter.Listener() { 526 | @Override 527 | public void call(Object... objects) { 528 | reconnects[0]++; 529 | } 530 | }; 531 | 532 | manager.on(Manager.EVENT_RECONNECT_ATTEMPT, cb); 533 | 534 | manager.on(Manager.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 535 | @Override 536 | public void call(Object... objects) { 537 | values.offer(reconnects[0]); 538 | } 539 | }); 540 | 541 | socket.open(); 542 | assertThat((Integer)values.take(), is(2)); 543 | socket.close(); 544 | manager.close(); 545 | } 546 | 547 | @Test(timeout = TIMEOUT) 548 | public void tryToReconnectTwiceAndFailWithImmediateTimeout() throws URISyntaxException, InterruptedException { 549 | final BlockingQueue values = new LinkedBlockingQueue(); 550 | IO.Options opts = new IO.Options(); 551 | opts.reconnection = true; 552 | opts.timeout = 0; 553 | opts.reconnectionAttempts = 2; 554 | opts.reconnectionDelay = 10; 555 | final Manager manager = new Manager(new URI(uri()), opts); 556 | 557 | final int[] reconnects = new int[] {0}; 558 | Emitter.Listener reconnectCb = new Emitter.Listener() { 559 | @Override 560 | public void call(Object... objects) { 561 | reconnects[0]++; 562 | } 563 | }; 564 | 565 | manager.on(Manager.EVENT_RECONNECT_ATTEMPT, reconnectCb); 566 | manager.on(Manager.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 567 | @Override 568 | public void call(Object... objects) { 569 | socket.close(); 570 | manager.close(); 571 | values.offer(reconnects[0]); 572 | } 573 | }); 574 | 575 | socket = manager.socket("/timeout"); 576 | socket.open(); 577 | assertThat((Integer)values.take(), is(2)); 578 | } 579 | 580 | @Test(timeout = TIMEOUT) 581 | public void notTryToReconnectWithIncorrectPortWhenReconnectionDisabled() throws URISyntaxException, InterruptedException { 582 | final BlockingQueue values = new LinkedBlockingQueue(); 583 | IO.Options opts = new IO.Options(); 584 | opts.reconnection = false; 585 | final Manager manager = new Manager(new URI("http://localhost:9823"), opts); 586 | Emitter.Listener cb = new Emitter.Listener() { 587 | @Override 588 | public void call(Object... objects) { 589 | socket.close(); 590 | throw new RuntimeException(); 591 | } 592 | }; 593 | manager.on(Manager.EVENT_RECONNECT_ATTEMPT, cb); 594 | manager.on(Manager.EVENT_CONNECT_ERROR, new Emitter.Listener() { 595 | @Override 596 | public void call(Object... objects) { 597 | Timer timer = new Timer(); 598 | timer.schedule(new TimerTask() { 599 | @Override 600 | public void run() { 601 | socket.close(); 602 | manager.close(); 603 | values.offer("done"); 604 | } 605 | }, 1000); 606 | } 607 | }); 608 | 609 | socket = manager.socket("/invalid"); 610 | socket.open(); 611 | values.take(); 612 | } 613 | 614 | @Test(timeout = TIMEOUT) 615 | public void fireReconnectEventsOnSocket() throws URISyntaxException, InterruptedException { 616 | final BlockingQueue values = new LinkedBlockingQueue(); 617 | 618 | Manager.Options opts = new Manager.Options(); 619 | opts.reconnection = true; 620 | opts.timeout = 0; 621 | opts.reconnectionAttempts = 2; 622 | opts.reconnectionDelay = 10; 623 | final Manager manager = new Manager(new URI(uri()), opts); 624 | socket = manager.socket("/timeout_socket"); 625 | 626 | final int[] reconnects = new int[] {0}; 627 | Emitter.Listener reconnectCb = new Emitter.Listener() { 628 | @Override 629 | public void call(Object... args) { 630 | reconnects[0]++; 631 | values.offer(args[0]); 632 | } 633 | }; 634 | 635 | socket.on(Socket.EVENT_RECONNECT_ATTEMPT, reconnectCb); 636 | socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 637 | @Override 638 | public void call(Object... objects) { 639 | socket.close(); 640 | manager.close(); 641 | values.offer(reconnects[0]); 642 | } 643 | }); 644 | socket.open(); 645 | assertThat((Integer)values.take(), is(reconnects[0])); 646 | assertThat((Integer)values.take(), is(2)); 647 | } 648 | 649 | @Test(timeout = TIMEOUT) 650 | public void fireReconnectingWithAttemptsNumberWhenReconnectingTwice() throws URISyntaxException, InterruptedException { 651 | final BlockingQueue values = new LinkedBlockingQueue(); 652 | 653 | Manager.Options opts = new Manager.Options(); 654 | opts.reconnection = true; 655 | opts.timeout = 0; 656 | opts.reconnectionAttempts = 2; 657 | opts.reconnectionDelay = 10; 658 | final Manager manager = new Manager(new URI(uri()), opts); 659 | socket = manager.socket("/timeout_socket"); 660 | 661 | final int[] reconnects = new int[] {0}; 662 | Emitter.Listener reconnectCb = new Emitter.Listener() { 663 | @Override 664 | public void call(Object... args) { 665 | reconnects[0]++; 666 | values.offer(args[0]); 667 | } 668 | }; 669 | 670 | socket.on(Socket.EVENT_RECONNECTING, reconnectCb); 671 | socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() { 672 | @Override 673 | public void call(Object... objects) { 674 | socket.close(); 675 | manager.close(); 676 | values.offer(reconnects[0]); 677 | } 678 | }); 679 | socket.open(); 680 | assertThat((Integer)values.take(), is(reconnects[0])); 681 | assertThat((Integer)values.take(), is(2)); 682 | } 683 | 684 | @Test(timeout = TIMEOUT) 685 | public void emitDateAsString() throws URISyntaxException, InterruptedException { 686 | final BlockingQueue values = new LinkedBlockingQueue(); 687 | socket = client(); 688 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 689 | @Override 690 | public void call(Object... objects) { 691 | socket.emit("echo", new Date()); 692 | socket.on("echoBack", new Emitter.Listener() { 693 | @Override 694 | public void call(Object... args) { 695 | socket.close(); 696 | values.offer(args[0]); 697 | } 698 | }); 699 | } 700 | }); 701 | socket.connect(); 702 | assertThat(values.take(), instanceOf(String.class)); 703 | } 704 | 705 | @Test(timeout = TIMEOUT) 706 | public void emitDateInObject() throws URISyntaxException, InterruptedException, JSONException { 707 | final BlockingQueue values = new LinkedBlockingQueue(); 708 | socket = client(); 709 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 710 | @Override 711 | public void call(Object... objects) { 712 | JSONObject data = new JSONObject(); 713 | try { 714 | data.put("date", new Date()); 715 | } catch (JSONException e) { 716 | throw new AssertionError(e); 717 | } 718 | socket.emit("echo", data); 719 | socket.on("echoBack", new Emitter.Listener() { 720 | @Override 721 | public void call(Object... args) { 722 | values.offer(args[0]); 723 | } 724 | }); 725 | } 726 | }); 727 | socket.connect(); 728 | Object data = values.take(); 729 | assertThat(data, instanceOf(JSONObject.class)); 730 | assertThat(((JSONObject)data).get("date"), instanceOf(String.class)); 731 | socket.close(); 732 | } 733 | 734 | @Test(timeout = TIMEOUT) 735 | public void sendAndGetBinaryData() throws URISyntaxException, InterruptedException { 736 | final BlockingQueue values = new LinkedBlockingQueue(); 737 | final byte[] buf = "asdfasdf".getBytes(Charset.forName("UTF-8")); 738 | socket = client(); 739 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 740 | @Override 741 | public void call(Object... args) { 742 | socket.emit("echo", buf); 743 | socket.on("echoBack", new Emitter.Listener() { 744 | @Override 745 | public void call(Object... args) { 746 | values.offer(args[0]); 747 | } 748 | }); 749 | } 750 | }); 751 | socket.open(); 752 | assertThat((byte[])values.take(), is(buf)); 753 | socket.close(); 754 | } 755 | 756 | @Test(timeout = TIMEOUT) 757 | public void sendBinaryDataMixedWithJson() throws URISyntaxException, InterruptedException, JSONException { 758 | final BlockingQueue values = new LinkedBlockingQueue(); 759 | final byte[] buf = "howdy".getBytes(Charset.forName("UTF-8")); 760 | socket = client(); 761 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 762 | @Override 763 | public void call(Object... args) { 764 | JSONObject data = new JSONObject(); 765 | try { 766 | data.put("hello", "lol"); 767 | data.put("message", buf); 768 | data.put("goodbye", "gotcha"); 769 | } catch (JSONException e) { 770 | throw new AssertionError(e); 771 | } 772 | socket.emit("echo", data); 773 | socket.on("echoBack", new Emitter.Listener() { 774 | @Override 775 | public void call(Object... args) { 776 | values.offer(args[0]); 777 | } 778 | }); 779 | } 780 | }); 781 | socket.open(); 782 | JSONObject a = (JSONObject)values.take(); 783 | assertThat(a.getString("hello"), is("lol")); 784 | assertThat((byte[])a.get("message"), is(buf)); 785 | assertThat(a.getString("goodbye"), is("gotcha")); 786 | socket.close(); 787 | } 788 | 789 | @Test(timeout = TIMEOUT) 790 | public void sendEventsWithByteArraysInTheCorrectOrder() throws Exception { 791 | final BlockingQueue values = new LinkedBlockingQueue(); 792 | final byte[] buf = "abuff1".getBytes(Charset.forName("UTF-8")); 793 | socket = client(); 794 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 795 | @Override 796 | public void call(Object... args) { 797 | socket.emit("echo", buf); 798 | socket.emit("echo", "please arrive second"); 799 | 800 | socket.on("echoBack", new Emitter.Listener() { 801 | @Override 802 | public void call(Object... args) { 803 | values.offer(args[0]); 804 | } 805 | }); 806 | } 807 | }); 808 | socket.open(); 809 | assertThat((byte[])values.take(), is(buf)); 810 | assertThat((String)values.take(), is("please arrive second")); 811 | socket.close(); 812 | } 813 | } 814 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/ExecutionTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.junit.runners.JUnit4; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStreamReader; 10 | import java.util.logging.Logger; 11 | 12 | import static org.hamcrest.CoreMatchers.is; 13 | import static org.junit.Assert.assertThat; 14 | 15 | @RunWith(JUnit4.class) 16 | public class ExecutionTest extends Connection { 17 | 18 | private static final Logger logger = Logger.getLogger(ExecutionTest.class.getName()); 19 | 20 | final static int TIMEOUT = 30 * 1000; 21 | 22 | @Test(timeout = TIMEOUT) 23 | public void execConnection() throws InterruptedException, IOException { 24 | exec("com.github.nkzawa.socketio.client.executions.Connection"); 25 | } 26 | 27 | @Test(timeout = TIMEOUT) 28 | public void execConnectionFailure() throws InterruptedException, IOException { 29 | exec("com.github.nkzawa.socketio.client.executions.ConnectionFailure"); 30 | } 31 | 32 | @Test(timeout = TIMEOUT) 33 | public void execImmediateClose() throws InterruptedException, IOException { 34 | exec("com.github.nkzawa.socketio.client.executions.ImmediateClose"); 35 | } 36 | 37 | private void exec(String mainClass) throws InterruptedException, IOException { 38 | Process process = Runtime.getRuntime().exec(String.format("mvn --quiet exec:java" + 39 | " -Dexec.mainClass=%s -Dexec.classpathScope=test", mainClass), createEnv()); 40 | BufferedReader input = new BufferedReader( 41 | new InputStreamReader(process.getInputStream())); 42 | String line; 43 | while ((line = input.readLine()) != null) { 44 | logger.fine("EXEC OUT: " + line); 45 | } 46 | process.waitFor(); 47 | assertThat(process.exitValue(), is(0)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/SSLConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import org.junit.After; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.JUnit4; 8 | 9 | import javax.net.ssl.HostnameVerifier; 10 | import javax.net.ssl.KeyManagerFactory; 11 | import javax.net.ssl.SSLContext; 12 | import javax.net.ssl.TrustManagerFactory; 13 | import java.io.File; 14 | import java.io.FileInputStream; 15 | import java.io.IOException; 16 | import java.security.GeneralSecurityException; 17 | import java.security.KeyStore; 18 | import java.util.concurrent.BlockingQueue; 19 | import java.util.concurrent.LinkedBlockingQueue; 20 | 21 | @RunWith(JUnit4.class) 22 | public class SSLConnectionTest extends Connection { 23 | 24 | // for test on localhost 25 | static HostnameVerifier hostnameVerifier = new HostnameVerifier(){ 26 | public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { 27 | return hostname.equals("localhost"); 28 | } 29 | }; 30 | 31 | private Socket socket; 32 | 33 | @Override 34 | String uri() { 35 | return "https://localhost:" + PORT; 36 | } 37 | 38 | @Override 39 | IO.Options createOptions() { 40 | IO.Options opts = super.createOptions(); 41 | opts.secure = true; 42 | return opts; 43 | } 44 | 45 | @Override 46 | String[] createEnv() { 47 | return new String[] {"DEBUG=socket.io:*", "PORT=" + PORT, "SSL=1"}; 48 | } 49 | 50 | SSLContext createSSLContext() throws GeneralSecurityException, IOException { 51 | KeyStore ks = KeyStore.getInstance("JKS"); 52 | File file = new File("src/test/resources/keystore.jks"); 53 | ks.load(new FileInputStream(file), "password".toCharArray()); 54 | 55 | KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 56 | kmf.init(ks, "password".toCharArray()); 57 | 58 | TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); 59 | tmf.init(ks); 60 | 61 | SSLContext sslContext = SSLContext.getInstance("TLS"); 62 | sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); 63 | return sslContext; 64 | } 65 | 66 | @After 67 | public void tearDown() { 68 | IO.setDefaultSSLContext(null); 69 | IO.setDefaultHostnameVerifier(null); 70 | } 71 | 72 | @Test(timeout = TIMEOUT) 73 | public void connect() throws Exception { 74 | final BlockingQueue values = new LinkedBlockingQueue(); 75 | IO.Options opts = createOptions(); 76 | opts.sslContext = createSSLContext(); 77 | opts.hostnameVerifier = hostnameVerifier; 78 | socket = client(opts); 79 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 80 | @Override 81 | public void call(Object... objects) { 82 | socket.emit("echo"); 83 | socket.on("echoBack", new Emitter.Listener() { 84 | @Override 85 | public void call(Object... args) { 86 | values.offer("done"); 87 | } 88 | }); 89 | } 90 | }); 91 | socket.connect(); 92 | values.take(); 93 | socket.close(); 94 | } 95 | 96 | @Test(timeout = TIMEOUT) 97 | public void defaultSSLContext() throws Exception { 98 | final BlockingQueue values = new LinkedBlockingQueue(); 99 | IO.setDefaultSSLContext(createSSLContext()); 100 | IO.setDefaultHostnameVerifier(hostnameVerifier); 101 | socket = client(); 102 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 103 | @Override 104 | public void call(Object... objects) { 105 | socket.emit("echo"); 106 | socket.on("echoBack", new Emitter.Listener() { 107 | @Override 108 | public void call(Object... args) { 109 | values.offer("done"); 110 | } 111 | }); 112 | } 113 | }); 114 | socket.connect(); 115 | values.take(); 116 | socket.close(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/ServerConnectionNamespaceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.junit.runners.JUnit4; 5 | 6 | @RunWith(JUnit4.class) 7 | public class ServerConnectionNamespaceTest extends ServerConnectionTest { 8 | 9 | protected String nsp() { 10 | return "/foo"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/ServerConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import com.github.nkzawa.engineio.client.Transport; 5 | import com.github.nkzawa.engineio.client.transports.Polling; 6 | import com.github.nkzawa.engineio.client.transports.WebSocket; 7 | import org.json.JSONObject; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.junit.runners.JUnit4; 11 | 12 | import java.net.URISyntaxException; 13 | import java.util.Map; 14 | import java.util.concurrent.BlockingQueue; 15 | import java.util.concurrent.LinkedBlockingQueue; 16 | 17 | import static org.hamcrest.CoreMatchers.*; 18 | import static org.junit.Assert.assertThat; 19 | 20 | @RunWith(JUnit4.class) 21 | public class ServerConnectionTest extends Connection { 22 | 23 | private Socket socket; 24 | private Socket socket2; 25 | 26 | @Test(timeout = TIMEOUT) 27 | public void openAndClose() throws URISyntaxException, InterruptedException { 28 | final BlockingQueue values = new LinkedBlockingQueue(); 29 | 30 | socket = client(); 31 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 32 | @Override 33 | public void call(Object... args) { 34 | values.offer(args); 35 | socket.disconnect(); 36 | } 37 | }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 38 | @Override 39 | public void call(Object... args) { 40 | values.offer(args); 41 | } 42 | }); 43 | socket.connect(); 44 | 45 | assertThat(((Object[])values.take()).length, is(0)); 46 | Object[] args = (Object[] )values.take(); 47 | assertThat(args.length, is(1)); 48 | assertThat(args[0], is(instanceOf(String.class))); 49 | } 50 | 51 | @Test(timeout = TIMEOUT) 52 | public void message() throws URISyntaxException, InterruptedException { 53 | final BlockingQueue values = new LinkedBlockingQueue(); 54 | 55 | socket = client(); 56 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 57 | @Override 58 | public void call(Object... objects) { 59 | socket.send("foo", "bar"); 60 | } 61 | }).on(Socket.EVENT_MESSAGE, new Emitter.Listener() { 62 | @Override 63 | public void call(Object... args) { 64 | values.offer(args); 65 | } 66 | }); 67 | socket.connect(); 68 | 69 | assertThat((Object[])values.take(), is(new Object[] {"hello client"})); 70 | assertThat((Object[])values.take(), is(new Object[] {"foo", "bar"})); 71 | socket.disconnect(); 72 | } 73 | 74 | @Test(timeout = TIMEOUT) 75 | public void event() throws Exception { 76 | final BlockingQueue values = new LinkedBlockingQueue(); 77 | 78 | final JSONObject obj = new JSONObject(); 79 | obj.put("foo", 1); 80 | 81 | socket = client(); 82 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 83 | @Override 84 | public void call(Object... objects) { 85 | socket.emit("echo", obj, null, "bar"); 86 | } 87 | }).on("echoBack", new Emitter.Listener() { 88 | @Override 89 | public void call(Object... args) { 90 | values.offer(args); 91 | } 92 | }); 93 | socket.connect(); 94 | 95 | Object[] args = (Object[])values.take(); 96 | assertThat(args.length, is(3)); 97 | assertThat(args[0].toString(), is(obj.toString())); 98 | assertThat(args[1], is(nullValue())); 99 | assertThat((String)args[2], is("bar")); 100 | socket.disconnect(); 101 | } 102 | 103 | @Test(timeout = TIMEOUT) 104 | public void ack() throws Exception { 105 | final BlockingQueue values = new LinkedBlockingQueue(); 106 | 107 | final JSONObject obj = new JSONObject(); 108 | obj.put("foo", 1); 109 | 110 | socket = client(); 111 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 112 | @Override 113 | public void call(Object... objects) { 114 | socket.emit("ack", new Object[] {obj, "bar"}, new Ack() { 115 | @Override 116 | public void call(Object... args) { 117 | values.offer(args); 118 | } 119 | }); 120 | } 121 | }); 122 | socket.connect(); 123 | 124 | Object[] args = (Object[])values.take(); 125 | assertThat(args.length, is(2)); 126 | assertThat(args[0].toString(), is(obj.toString())); 127 | assertThat((String)args[1], is("bar")); 128 | socket.disconnect(); 129 | } 130 | 131 | @Test(timeout = TIMEOUT) 132 | public void ackWithoutArgs() throws URISyntaxException, InterruptedException { 133 | final BlockingQueue values = new LinkedBlockingQueue(); 134 | 135 | socket = client(); 136 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 137 | @Override 138 | public void call(Object... objects) { 139 | socket.emit("ack", null, new Ack() { 140 | @Override 141 | public void call(Object... args) { 142 | values.offer(args.length); 143 | } 144 | }); 145 | } 146 | }); 147 | socket.connect(); 148 | 149 | assertThat((Integer)values.take(), is(0)); 150 | socket.disconnect(); 151 | } 152 | 153 | @Test(timeout = TIMEOUT) 154 | public void ackWithoutArgsFromClient() throws URISyntaxException, InterruptedException { 155 | final BlockingQueue values = new LinkedBlockingQueue(); 156 | 157 | socket = client(); 158 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 159 | @Override 160 | public void call(Object... objects) { 161 | socket.on("ack", new Emitter.Listener() { 162 | @Override 163 | public void call(Object... args) { 164 | values.offer(args); 165 | Ack ack = (Ack)args[0]; 166 | ack.call(); 167 | } 168 | }).on("ackBack", new Emitter.Listener() { 169 | @Override 170 | public void call(Object... args) { 171 | values.offer(args); 172 | socket.disconnect(); 173 | } 174 | }); 175 | socket.emit("callAck"); 176 | } 177 | }); 178 | socket.connect(); 179 | 180 | Object[] args = (Object[])values.take(); 181 | assertThat(args.length, is(1)); 182 | assertThat(args[0], is(instanceOf(Ack.class))); 183 | args = (Object[])values.take(); 184 | assertThat(args.length, is(0)); 185 | socket.disconnect(); 186 | } 187 | 188 | @Test(timeout = TIMEOUT) 189 | public void closeEngineConnection() throws URISyntaxException, InterruptedException { 190 | final BlockingQueue values = new LinkedBlockingQueue(); 191 | 192 | socket = client(); 193 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 194 | @Override 195 | public void call(Object... args) { 196 | socket.io().engine.on(com.github.nkzawa.engineio.client.Socket.EVENT_CLOSE, new Emitter.Listener() { 197 | @Override 198 | public void call(Object... objects) { 199 | values.offer("done"); 200 | } 201 | }); 202 | socket.disconnect(); 203 | } 204 | }); 205 | socket.connect(); 206 | values.take(); 207 | } 208 | 209 | @Test(timeout = TIMEOUT) 210 | public void broadcast() throws URISyntaxException, InterruptedException { 211 | final BlockingQueue values = new LinkedBlockingQueue(); 212 | 213 | socket = client(); 214 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 215 | @Override 216 | public void call(Object... objects) { 217 | try { 218 | socket2 = client(); 219 | } catch (URISyntaxException e) { 220 | throw new RuntimeException(e); 221 | } 222 | 223 | socket2.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 224 | @Override 225 | public void call(Object... objects) { 226 | socket2.emit("broadcast", "hi"); 227 | } 228 | }); 229 | socket2.connect(); 230 | } 231 | }).on("broadcastBack", new Emitter.Listener() { 232 | @Override 233 | public void call(Object... args) { 234 | values.offer(args); 235 | } 236 | }); 237 | socket.connect(); 238 | 239 | Object[] args = (Object[])values.take(); 240 | assertThat(args.length, is(1)); 241 | assertThat((String)args[0], is("hi")); 242 | socket.disconnect(); 243 | socket2.disconnect(); 244 | } 245 | 246 | @Test(timeout = TIMEOUT) 247 | public void room() throws URISyntaxException, InterruptedException { 248 | final BlockingQueue values = new LinkedBlockingQueue(); 249 | 250 | socket = client(); 251 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 252 | @Override 253 | public void call(Object... objects) { 254 | socket.emit("room", "hi"); 255 | } 256 | }).on("roomBack", new Emitter.Listener() { 257 | @Override 258 | public void call(Object... args) { 259 | values.offer(args); 260 | } 261 | }); 262 | socket.connect(); 263 | 264 | Object[] args = (Object[])values.take(); 265 | assertThat(args.length, is(1)); 266 | assertThat((String)args[0], is("hi")); 267 | socket.disconnect(); 268 | } 269 | 270 | @Test(timeout = TIMEOUT) 271 | public void pollingHeaders() throws URISyntaxException, InterruptedException { 272 | final BlockingQueue values = new LinkedBlockingQueue(); 273 | 274 | IO.Options opts = createOptions(); 275 | opts.transports = new String[] {Polling.NAME}; 276 | socket = client(opts); 277 | socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() { 278 | @Override 279 | public void call(Object... args) { 280 | Transport transport = (Transport)args[0]; 281 | transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() { 282 | @Override 283 | public void call(Object... args) { 284 | @SuppressWarnings("unchecked") 285 | Map headers = (Map)args[0]; 286 | headers.put("X-SocketIO", "hi"); 287 | } 288 | }).on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() { 289 | @Override 290 | public void call(Object... args) { 291 | @SuppressWarnings("unchecked") 292 | Map headers = (Map)args[0]; 293 | String value = headers.get("X-SocketIO"); 294 | values.offer(value != null ? value : ""); 295 | } 296 | }); 297 | } 298 | }); 299 | socket.open(); 300 | 301 | assertThat((String)values.take(), is("hi")); 302 | socket.close(); 303 | } 304 | 305 | @Test(timeout = TIMEOUT) 306 | public void websocketHandshakeHeaders() throws URISyntaxException, InterruptedException { 307 | final BlockingQueue values = new LinkedBlockingQueue(); 308 | 309 | IO.Options opts = createOptions(); 310 | opts.transports = new String[] {WebSocket.NAME}; 311 | socket = client(opts); 312 | socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() { 313 | @Override 314 | public void call(Object... args) { 315 | Transport transport = (Transport)args[0]; 316 | transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() { 317 | @Override 318 | public void call(Object... args) { 319 | @SuppressWarnings("unchecked") 320 | Map headers = (Map)args[0]; 321 | headers.put("X-SocketIO", "hi"); 322 | } 323 | }).on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() { 324 | @Override 325 | public void call(Object... args) { 326 | @SuppressWarnings("unchecked") 327 | Map headers = (Map)args[0]; 328 | String value = headers.get("X-SocketIO"); 329 | values.offer(value != null ? value : ""); 330 | } 331 | }); 332 | } 333 | }); 334 | socket.open(); 335 | 336 | assertThat((String)values.take(), is("hi")); 337 | socket.close(); 338 | } 339 | 340 | @Test(timeout = TIMEOUT) 341 | public void disconnectFromServer() throws URISyntaxException, InterruptedException { 342 | final BlockingQueue values = new LinkedBlockingQueue(); 343 | 344 | socket = client(); 345 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 346 | @Override 347 | public void call(Object... args) { 348 | socket.emit("requestDisconnect"); 349 | } 350 | }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 351 | @Override 352 | public void call(Object... args) { 353 | values.offer("disconnected"); 354 | } 355 | }); 356 | socket.connect(); 357 | assertThat((String)values.take(), is("disconnected")); 358 | } 359 | } 360 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/SocketTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import com.github.nkzawa.util.Optional; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.JUnit4; 8 | 9 | import java.net.URISyntaxException; 10 | import java.util.concurrent.BlockingQueue; 11 | import java.util.concurrent.LinkedBlockingQueue; 12 | 13 | import static org.hamcrest.CoreMatchers.*; 14 | import static org.junit.Assert.assertThat; 15 | 16 | @RunWith(JUnit4.class) 17 | public class SocketTest extends Connection { 18 | 19 | private Socket socket; 20 | 21 | @Test(timeout = TIMEOUT) 22 | public void shouldHaveAnAccessibleSocketIdEqualToTheEngineIOSocketId() throws URISyntaxException, InterruptedException { 23 | final BlockingQueue values = new LinkedBlockingQueue(); 24 | socket = client(); 25 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 26 | @Override 27 | public void call(Object... objects) { 28 | values.offer(Optional.ofNullable(socket.id())); 29 | } 30 | }); 31 | socket.connect(); 32 | 33 | @SuppressWarnings("unchecked") 34 | Optional id = values.take(); 35 | assertThat(id.isPresent(), is(true)); 36 | assertThat(id.get(), is(socket.io().engine.id())); 37 | socket.disconnect(); 38 | } 39 | 40 | @Test(timeout = TIMEOUT) 41 | public void clearsSocketIdUponDisconnection() throws URISyntaxException, InterruptedException { 42 | final BlockingQueue values = new LinkedBlockingQueue(); 43 | socket = client(); 44 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 45 | @Override 46 | public void call(Object... objects) { 47 | socket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 48 | @Override 49 | public void call(Object... args) { 50 | values.offer(Optional.ofNullable(socket.id())); 51 | } 52 | }); 53 | 54 | socket.disconnect(); 55 | } 56 | }); 57 | socket.connect(); 58 | @SuppressWarnings("unchecked") 59 | Optional id = values.take(); 60 | assertThat(id.isPresent(), is(false)); 61 | } 62 | 63 | @Test(timeout = TIMEOUT) 64 | public void shouldChangeSocketIdUponReconnection() throws URISyntaxException, InterruptedException { 65 | final BlockingQueue values = new LinkedBlockingQueue(); 66 | socket = client(); 67 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 68 | @Override 69 | public void call(Object... objects) { 70 | values.offer(Optional.ofNullable(socket.id())); 71 | 72 | socket.on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() { 73 | @Override 74 | public void call(Object... objects) { 75 | values.offer(Optional.ofNullable(socket.id())); 76 | } 77 | }); 78 | 79 | socket.on(Socket.EVENT_RECONNECT, new Emitter.Listener() { 80 | @Override 81 | public void call(Object... objects) { 82 | values.offer(Optional.ofNullable(socket.id())); 83 | } 84 | }); 85 | 86 | socket.io().engine.close(); 87 | } 88 | }); 89 | socket.connect(); 90 | @SuppressWarnings("unchecked") 91 | Optional id1 = values.take(); 92 | 93 | @SuppressWarnings("unchecked") 94 | Optional id2 = values.take(); 95 | assertThat(id2.isPresent(), is(false)); 96 | 97 | @SuppressWarnings("unchecked") 98 | Optional id3 = values.take(); 99 | assertThat(id3.get(), is(not(id1.get()))); 100 | 101 | socket.disconnect(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/UrlTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.junit.runners.JUnit4; 6 | 7 | import java.net.MalformedURLException; 8 | import java.net.URISyntaxException; 9 | import java.net.URL; 10 | 11 | import static org.hamcrest.CoreMatchers.is; 12 | import static org.hamcrest.CoreMatchers.not; 13 | import static org.junit.Assert.assertThat; 14 | 15 | @RunWith(JUnit4.class) 16 | public class UrlTest { 17 | 18 | @Test 19 | public void parse() throws MalformedURLException, URISyntaxException { 20 | assertThat(Url.parse("http://username:password@host:8080/directory/file?query#ref").toString(), 21 | is("http://username:password@host:8080/directory/file?query#ref")); 22 | } 23 | 24 | @Test 25 | public void parseRelativePath() throws MalformedURLException, URISyntaxException { 26 | URL url = Url.parse("https://woot.com/test"); 27 | assertThat(url.getProtocol(), is("https")); 28 | assertThat(url.getHost(), is("woot.com")); 29 | assertThat(url.getPath(), is("/test")); 30 | } 31 | 32 | @Test 33 | public void parseNoProtocol() throws MalformedURLException, URISyntaxException { 34 | URL url = Url.parse("//localhost:3000"); 35 | assertThat(url.getProtocol(), is("https")); 36 | assertThat(url.getHost(), is("localhost")); 37 | assertThat(url.getPort(), is(3000)); 38 | } 39 | 40 | @Test 41 | public void parseNamespace() throws MalformedURLException, URISyntaxException { 42 | assertThat(Url.parse("http://woot.com/woot").getPath(), is("/woot")); 43 | assertThat(Url.parse("http://google.com").getPath(), is("/")); 44 | assertThat(Url.parse("http://google.com/").getPath(), is("/")); 45 | } 46 | 47 | @Test 48 | public void parseDefaultPort() throws MalformedURLException, URISyntaxException { 49 | assertThat(Url.parse("http://google.com/").toString(), is("http://google.com:80/")); 50 | assertThat(Url.parse("https://google.com/").toString(), is("https://google.com:443/")); 51 | } 52 | 53 | @Test 54 | public void extractId() throws MalformedURLException { 55 | String id1 = Url.extractId("http://google.com:80/"); 56 | String id2 = Url.extractId("http://google.com/"); 57 | String id3 = Url.extractId("https://google.com/"); 58 | assertThat(id1, is(id2)); 59 | assertThat(id1, is(not(id3))); 60 | assertThat(id2, is(not(id3))); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/executions/Connection.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client.executions; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import com.github.nkzawa.socketio.client.IO; 5 | import com.github.nkzawa.socketio.client.Socket; 6 | 7 | import java.net.URISyntaxException; 8 | 9 | public class Connection { 10 | 11 | public static void main(String[] args) throws URISyntaxException { 12 | IO.Options options = new IO.Options(); 13 | options.forceNew = true; 14 | final Socket socket = IO.socket("http://localhost:" + System.getenv("PORT"), options); 15 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 16 | @Override 17 | public void call(Object... args) { 18 | System.out.println("connect"); 19 | socket.close(); 20 | } 21 | }); 22 | socket.open(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/executions/ConnectionFailure.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client.executions; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import com.github.nkzawa.socketio.client.IO; 5 | import com.github.nkzawa.socketio.client.Socket; 6 | 7 | import java.net.URISyntaxException; 8 | 9 | public class ConnectionFailure { 10 | 11 | public static void main(String[] args) throws URISyntaxException { 12 | int port = Integer.parseInt(System.getenv("PORT")); 13 | port++; 14 | IO.Options options = new IO.Options(); 15 | options.forceNew = true; 16 | options.reconnection = false; 17 | final Socket socket = IO.socket("http://localhost:" + port, options); 18 | socket.on(Socket.EVENT_CONNECT_TIMEOUT, new Emitter.Listener() { 19 | @Override 20 | public void call(Object... args) { 21 | System.out.println("connect timeout"); 22 | } 23 | }).on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() { 24 | @Override 25 | public void call(Object... args) { 26 | System.out.println("connect error"); 27 | } 28 | }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 29 | @Override 30 | public void call(Object... args) { 31 | System.out.println("disconnect"); 32 | } 33 | }); 34 | socket.open(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/client/executions/ImmediateClose.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.client.executions; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import com.github.nkzawa.socketio.client.IO; 5 | import com.github.nkzawa.socketio.client.Socket; 6 | 7 | import java.net.URISyntaxException; 8 | 9 | public class ImmediateClose { 10 | 11 | public static void main(String[] args) throws URISyntaxException { 12 | IO.Options options = new IO.Options(); 13 | options.forceNew = true; 14 | final Socket socket = IO.socket("http://localhost:" + System.getenv("PORT"), options); 15 | socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { 16 | @Override 17 | public void call(Object... args) { 18 | System.out.println("connect"); 19 | } 20 | }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { 21 | @Override 22 | public void call(Object... args) { 23 | System.out.println("disconnect"); 24 | } 25 | }); 26 | socket.connect(); 27 | socket.disconnect(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/parser/ByteArrayTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.parser; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import org.json.JSONArray; 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.JUnit4; 10 | 11 | import java.nio.charset.Charset; 12 | 13 | import static org.hamcrest.CoreMatchers.is; 14 | import static org.junit.Assert.assertThat; 15 | 16 | @RunWith(JUnit4.class) 17 | public class ByteArrayTest { 18 | 19 | private static Parser.Encoder encoder = new Parser.Encoder(); 20 | 21 | @Test 22 | public void encodeByteArray() { 23 | Packet packet = new Packet(Parser.BINARY_EVENT); 24 | packet.data = "abc".getBytes(Charset.forName("UTF-8")); 25 | packet.id = 23; 26 | packet.nsp = "/cool"; 27 | Helpers.testBin(packet); 28 | } 29 | 30 | @Test 31 | public void encodeByteArray2() { 32 | Packet packet = new Packet(Parser.BINARY_EVENT); 33 | packet.data = new byte[2]; 34 | packet.id = 0; 35 | packet.nsp = "/"; 36 | Helpers.testBin(packet); 37 | } 38 | 39 | @Test 40 | public void encodeByteArrayDeepInJson() throws JSONException { 41 | JSONObject data = new JSONObject("{a: \"hi\", b: {}, c: {a: \"bye\", b: {}}}"); 42 | data.getJSONObject("b").put("why", new byte[3]); 43 | data.getJSONObject("c").getJSONObject("b").put("a", new byte[6]); 44 | 45 | Packet packet = new Packet(Parser.BINARY_EVENT); 46 | packet.data = data; 47 | packet.id = 999; 48 | packet.nsp = "/deep"; 49 | Helpers.testBin(packet); 50 | } 51 | 52 | @Test 53 | public void encodeDeepBinaryJSONWithNullValue() throws JSONException { 54 | JSONObject data = new JSONObject("{a: \"b\", c: 4, e: {g: null}, h: null}"); 55 | data.put("h", new byte[9]); 56 | 57 | Packet packet = new Packet(Parser.BINARY_EVENT); 58 | packet.data = data; 59 | packet.nsp = "/"; 60 | packet.id = 600; 61 | Helpers.testBin(packet); 62 | } 63 | 64 | @Test 65 | public void encodeBinaryAckWithByteArray() throws JSONException { 66 | JSONArray data = new JSONArray("[a, null, {}]"); 67 | data.put(1, "xxx".getBytes(Charset.forName("UTF-8"))); 68 | 69 | Packet packet = new Packet(Parser.BINARY_ACK); 70 | packet.data = data; 71 | packet.id = 127; 72 | packet.nsp = "/back"; 73 | Helpers.testBin(packet); 74 | } 75 | 76 | @Test 77 | public void cleanItselfUpOnClose() { 78 | JSONArray data = new JSONArray(); 79 | data.put(new byte[2]); 80 | data.put(new byte[3]); 81 | 82 | Packet packet = new Packet(Parser.BINARY_EVENT); 83 | packet.data = data; 84 | packet.id = 0; 85 | packet.nsp = "/"; 86 | 87 | encoder.encode(packet, new Parser.Encoder.Callback() { 88 | @Override 89 | public void call(final Object[] encodedPackets) { 90 | final Parser.Decoder decoder = new Parser.Decoder(); 91 | decoder.on(Parser.Decoder.EVENT_DECODED, new Emitter.Listener() { 92 | @Override 93 | public void call(Object... args) { 94 | throw new RuntimeException("received a packet when not all binary data was sent."); 95 | } 96 | }); 97 | 98 | decoder.add((String)encodedPackets[0]); 99 | decoder.add((byte[]) encodedPackets[1]); 100 | decoder.destroy(); 101 | assertThat(decoder.reconstructor.buffers.size(), is(0)); 102 | } 103 | }); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/parser/Helpers.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.parser; 2 | 3 | import com.github.nkzawa.emitter.Emitter; 4 | import org.json.JSONArray; 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.JUnit4; 9 | import org.skyscreamer.jsonassert.JSONAssert; 10 | 11 | import static org.hamcrest.CoreMatchers.is; 12 | import static org.junit.Assert.assertThat; 13 | 14 | @RunWith(JUnit4.class) 15 | public class Helpers { 16 | 17 | private static Parser.Encoder encoder = new Parser.Encoder(); 18 | private static Packet errorPacket = new Packet(Parser.ERROR, "parser error"); 19 | 20 | public static void test(final Packet obj) { 21 | encoder.encode(obj, new Parser.Encoder.Callback() { 22 | @Override 23 | public void call(Object[] encodedPackets) { 24 | Parser.Decoder decoder = new Parser.Decoder(); 25 | decoder.on(Parser.Decoder.EVENT_DECODED, new Emitter.Listener() { 26 | @Override 27 | public void call(Object... args) { 28 | Packet packet = (Packet)args[0]; 29 | assertPacket(packet, obj); 30 | } 31 | }); 32 | decoder.add((String)encodedPackets[0]); 33 | } 34 | }); 35 | } 36 | 37 | public static void testDecodeError(final String errorMessage) { 38 | Parser.Decoder decoder = new Parser.Decoder(); 39 | decoder.on(Parser.Decoder.EVENT_DECODED, new Emitter.Listener() { 40 | @Override 41 | public void call(Object... args) { 42 | Packet packet = (Packet)args[0]; 43 | assertPacket(errorPacket, packet); 44 | } 45 | }); 46 | decoder.add(errorMessage); 47 | } 48 | 49 | public static void testBin(final Packet obj) { 50 | final Object originalData = obj.data; 51 | encoder.encode(obj, new Parser.Encoder.Callback() { 52 | @Override 53 | public void call(Object[] encodedPackets) { 54 | Parser.Decoder decoder = new Parser.Decoder(); 55 | decoder.on(Parser.Decoder.EVENT_DECODED, new Emitter.Listener() { 56 | @Override 57 | public void call(Object... args) { 58 | Packet packet = (Packet)args[0]; 59 | obj.data = originalData; 60 | obj.attachments = -1; 61 | assertPacket(packet, obj); 62 | } 63 | }); 64 | 65 | for (Object packet : encodedPackets) { 66 | if (packet instanceof String) { 67 | decoder.add((String)packet); 68 | } else if (packet instanceof byte[]) { 69 | decoder.add((byte[])packet); 70 | } 71 | } 72 | } 73 | }); 74 | } 75 | 76 | public static void assertPacket(Packet expected, Packet actual) { 77 | assertThat(actual.type, is(expected.type)); 78 | assertThat(actual.id, is(expected.id)); 79 | assertThat(actual.nsp, is(expected.nsp)); 80 | assertThat(actual.attachments, is(expected.attachments)); 81 | 82 | if (expected.data instanceof JSONArray) { 83 | try { 84 | JSONAssert.assertEquals((JSONArray)expected.data, (JSONArray)actual.data, true); 85 | } catch (JSONException e) { 86 | throw new AssertionError(e); 87 | } 88 | } else if (expected.data instanceof JSONObject) { 89 | try { 90 | JSONAssert.assertEquals((JSONObject)expected.data, (JSONObject)actual.data, true); 91 | } catch (JSONException e) { 92 | throw new AssertionError(e); 93 | } 94 | } else { 95 | assertThat(actual.data, is(expected.data)); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/socketio/parser/ParserTest.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.socketio.parser; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONException; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.JUnit4; 8 | 9 | @RunWith(JUnit4.class) 10 | public class ParserTest { 11 | 12 | private static Parser.Encoder encoder = new Parser.Encoder(); 13 | 14 | @Test 15 | public void encodeConnection() { 16 | Packet packet = new Packet(Parser.CONNECT); 17 | packet.nsp = "/woot"; 18 | Helpers.test(packet); 19 | } 20 | 21 | @Test 22 | public void encodeDisconnection() { 23 | Packet packet = new Packet(Parser.DISCONNECT); 24 | packet.nsp = "/woot"; 25 | Helpers.test(packet); 26 | } 27 | 28 | @Test 29 | public void encodeEvent() throws JSONException { 30 | Packet packet1 = new Packet(Parser.EVENT); 31 | packet1.data = new JSONArray("[\"a\", 1, {}]"); 32 | packet1.nsp = "/"; 33 | Helpers.test(packet1); 34 | 35 | Packet packet2 = new Packet(Parser.EVENT); 36 | packet2.data = new JSONArray("[\"a\", 1, {}]"); 37 | packet2.nsp = "/test"; 38 | Helpers.test(packet2); 39 | } 40 | 41 | @Test 42 | public void encodeAck() throws JSONException { 43 | Packet packet = new Packet(Parser.ACK); 44 | packet.data = new JSONArray("[\"a\", 1, {}]"); 45 | packet.id = 123; 46 | packet.nsp = "/"; 47 | Helpers.test(packet); 48 | } 49 | 50 | @Test 51 | public void decodeInError() throws JSONException { 52 | // Random string 53 | Helpers.testDecodeError("asdf"); 54 | // Unknown type 55 | Helpers.testDecodeError(Parser.types.length + "asdf"); 56 | // Binary event with no `-` 57 | Helpers.testDecodeError(Parser.BINARY_EVENT + "asdf"); 58 | // Binary ack with no `-` 59 | Helpers.testDecodeError(Parser.BINARY_ACK + "asdf"); 60 | // Binary event with no attachment 61 | Helpers.testDecodeError(String.valueOf(Parser.BINARY_EVENT)); 62 | // event non numeric id 63 | Helpers.testDecodeError(Parser.EVENT + "2sd"); 64 | // event with invalid json data 65 | Helpers.testDecodeError(Parser.EVENT + "2[\"a\",1,{asdf}]"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/java/com/github/nkzawa/util/Optional.java: -------------------------------------------------------------------------------- 1 | package com.github.nkzawa.util; 2 | 3 | import java.util.NoSuchElementException; 4 | 5 | public class Optional { 6 | 7 | static final Optional EMPTY = Optional.ofNullable(null); 8 | 9 | private T value; 10 | 11 | public static Optional of(T value) { 12 | if (value == null) { 13 | throw new NullPointerException(); 14 | } 15 | return new Optional(value); 16 | } 17 | 18 | public static Optional ofNullable(T value) { 19 | return new Optional(value); 20 | } 21 | 22 | public static Optional empty() { 23 | return EMPTY; 24 | } 25 | 26 | private Optional(T value) { 27 | this.value = value; 28 | } 29 | 30 | public boolean isPresent() { 31 | return this.value != null; 32 | } 33 | 34 | public T get() { 35 | if (this.value == null) { 36 | throw new NoSuchElementException(); 37 | } 38 | return this.value; 39 | } 40 | 41 | public T orElse(T other) { 42 | return this.value != null ? this.value : other; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/resources/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBfDCCASYCCQDTnGd/oOyF1DANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB 3 | VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 4 | cyBQdHkgTHRkMB4XDTE0MDcwNzEzMTUzN1oXDTQxMTEyMTEzMTUzN1owRTELMAkG 5 | A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0 6 | IFdpZGdpdHMgUHR5IEx0ZDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC6sdeFPlqk 7 | 5Pap9woFx1RO05gLidw4MNcL+ZRSxy/sNeE4PhT/RLFcEvnXiHc92wT8YB5Z+WCM 8 | k/jRQ0q19PNPAgMBAAEwDQYJKoZIhvcNAQEFBQADQQCnmm1N/yZiMBZw2JDfbsx3 9 | ecc0BGQ2BwWQuGHzP07TMi1AuOyNZSczl907OphYb9iRC8shZ4O+oXjQAuGTQ1Hp 10 | -----END CERTIFICATE----- 11 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/resources/key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIBOwIBAAJBALqx14U+WqTk9qn3CgXHVE7TmAuJ3Dgw1wv5lFLHL+w14Tg+FP9E 3 | sVwS+deIdz3bBPxgHln5YIyT+NFDSrX0808CAwEAAQJAIdwLSIEsk2drTRwe1zl1 4 | ku5RTxZruE0zU1qqifDSQjab1StAK1tapxBVRlRlyLCfD704UClsU8sjGtq0Nh6n 5 | kQIhAO2YJM1g0w9bWYet3zC2UdEASPzaQ7llpZmc51NRBx2NAiEAyShICAaclEuy 6 | wwuD4hibV+b6I8CLYoyPBo32EaceN0sCIQCUed6NxfM/houlgV+Xtmfcnzv9X3yx 7 | EDdzjpz08Q7sRQIgZFv1fBOYYSBXQppnJRFzx2pUmCvDHtrTrMh84RfIqnsCIQCf 8 | JjNXXxOaHn1PNZpi6EHReiFQmy1Swt+AxpTsKixsfA== 9 | -----END RSA PRIVATE KEY----- 10 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/libs/socket.io-client.java-master/src/test/resources/keystore.jks -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler 2 | .level = ALL 3 | 4 | java.util.logging.ConsoleHandler.level = INFO 5 | 6 | java.util.logging.FileHandler.level = ALL 7 | java.util.logging.FileHandler.pattern = ./target/test.log 8 | java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter 9 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/resources/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "socket.io-client.java-test", 3 | "version": "0.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "socket.io": "1.3.2" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /app/libs/socket.io-client.java-master/src/test/resources/server.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | var server; 4 | if (process.env.SSL) { 5 | server = require('https').createServer({ 6 | key: fs.readFileSync(__dirname + '/key.pem'), 7 | cert: fs.readFileSync(__dirname + '/cert.pem') 8 | }); 9 | } else { 10 | server = require('http').createServer(); 11 | } 12 | 13 | var io = require('socket.io')(server); 14 | var port = process.env.PORT || 3000; 15 | var nsp = process.argv[2] || '/'; 16 | var slice = Array.prototype.slice; 17 | 18 | io.of('/foo').on('connection', function() { 19 | // register namespace 20 | }); 21 | 22 | io.of('/timeout_socket').on('connection', function() { 23 | // register namespace 24 | }); 25 | 26 | io.of('/valid').on('connection', function() { 27 | // register namespace 28 | }); 29 | 30 | io.of('/asd').on('connection', function() { 31 | // register namespace 32 | }); 33 | 34 | io.of(nsp).on('connection', function(socket) { 35 | socket.send('hello client'); 36 | 37 | socket.on('message', function() { 38 | var args = slice.call(arguments); 39 | socket.send.apply(socket, args); 40 | }); 41 | 42 | socket.on('echo', function() { 43 | var args = slice.call(arguments); 44 | socket.emit.apply(socket, ['echoBack'].concat(args)); 45 | }); 46 | 47 | socket.on('ack', function() { 48 | var args = slice.call(arguments); 49 | var callback = args.pop(); 50 | callback.apply(null, args); 51 | }); 52 | 53 | socket.on('callAck', function() { 54 | socket.emit('ack', function() { 55 | var args = slice.call(arguments); 56 | socket.emit.apply(socket, ['ackBack'].concat(args)); 57 | }); 58 | }); 59 | 60 | socket.on('getAckDate', function(data, callback) { 61 | callback(new Date()); 62 | }); 63 | 64 | socket.on('broadcast', function(data) { 65 | var args = slice.call(arguments); 66 | socket.broadcast.emit.apply(socket, ['broadcastBack'].concat(args)); 67 | }); 68 | 69 | socket.on('room', function() { 70 | var args = slice.call(arguments); 71 | io.to(socket.id).emit.apply(socket, ['roomBack'].concat(args)); 72 | }); 73 | 74 | socket.on('requestDisconnect', function() { 75 | socket.disconnect(); 76 | }); 77 | 78 | socket.on('disconnect', function() { 79 | console.log('disconnect'); 80 | }); 81 | 82 | socket.on('error', function() { 83 | console.log('error: ', arguments); 84 | }); 85 | }); 86 | 87 | 88 | function before(context, name, fn) { 89 | var method = context[name]; 90 | context[name] = function() { 91 | fn.apply(this, arguments); 92 | return method.apply(this, arguments); 93 | }; 94 | } 95 | 96 | before(io.engine, 'handleRequest', function(req, res) { 97 | // echo a header value 98 | var value = req.headers['x-socketio']; 99 | if (!value) return; 100 | res.setHeader('X-SocketIO', value); 101 | }); 102 | 103 | before(io.engine, 'handleUpgrade', function(req, socket, head) { 104 | // echo a header value for websocket handshake 105 | var value = req.headers['x-socketio']; 106 | if (!value) return; 107 | this.ws.once('headers', function(headers) { 108 | headers.push('X-SocketIO: ' + value); 109 | }); 110 | }); 111 | 112 | 113 | server.listen(port, function() { 114 | console.log('Socket.IO server listening on port', port); 115 | }); 116 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sreejeshpillai/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src.zip -------------------------------------------------------------------------------- /app/src/androidTest/java/com/kriyatma/nodesocket/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.kriyatma.nodesocket; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriyatma/nodesocket/ChatFragment.java: -------------------------------------------------------------------------------- 1 | package com.kriyatma.nodesocket; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.app.Fragment; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.util.Base64; 12 | import android.util.Log; 13 | import android.view.LayoutInflater; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.widget.EditText; 17 | import android.widget.ImageButton; 18 | 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileNotFoundException; 23 | import java.net.URISyntaxException; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Objects; 27 | 28 | import com.github.nkzawa.emitter.Emitter; 29 | import com.github.nkzawa.socketio.client.IO; 30 | import com.github.nkzawa.socketio.client.Socket; 31 | 32 | import org.json.JSONException; 33 | import org.json.JSONObject; 34 | 35 | 36 | /** 37 | * A simple {@link Fragment} subclass. 38 | * Activities that contain this fragment must implement the 39 | * {@link ChatFragment.OnFragmentInteractionListener} interface 40 | * to handle interaction events. 41 | * Use the {@link ChatFragment#newInstance} factory method to 42 | * create an instance of this fragment. 43 | */ 44 | public class ChatFragment extends Fragment { 45 | // TODO: Rename parameter arguments, choose names that match 46 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER 47 | private static final String ARG_PARAM1 = "param1"; 48 | private static final String ARG_PARAM2 = "param2"; 49 | 50 | // TODO: Rename and change types of parameters 51 | private String mParam1; 52 | private String mParam2; 53 | private EditText mInputMessageView; 54 | private RecyclerView mMessagesView; 55 | private OnFragmentInteractionListener mListener; 56 | private List mMessages = new ArrayList(); 57 | private RecyclerView.Adapter mAdapter; 58 | 59 | private Socket socket; 60 | { 61 | try{ 62 | socket = IO.socket("http://192.168.0.101:3000"); 63 | }catch(URISyntaxException e){ 64 | throw new RuntimeException(e); 65 | } 66 | } 67 | /** 68 | * Use this factory method to create a new instance of 69 | * this fragment using the provided parameters. 70 | * 71 | * @param param1 Parameter 1. 72 | * @param param2 Parameter 2. 73 | * @return A new instance of fragment ChatFragment. 74 | */ 75 | // TODO: Rename and change types and number of parameters 76 | public static ChatFragment newInstance(String param1, String param2) { 77 | ChatFragment fragment = new ChatFragment(); 78 | Bundle args = new Bundle(); 79 | args.putString(ARG_PARAM1, param1); 80 | args.putString(ARG_PARAM2, param2); 81 | fragment.setArguments(args); 82 | return fragment; 83 | } 84 | 85 | public ChatFragment() { 86 | // Required empty public constructor 87 | } 88 | 89 | @Override 90 | public void onCreate(Bundle savedInstanceState) { 91 | super.onCreate(savedInstanceState); 92 | setHasOptionsMenu(true); 93 | socket.connect(); 94 | socket.on("message", handleIncomingMessages); 95 | } 96 | 97 | 98 | 99 | @Override 100 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 101 | Bundle savedInstanceState) { 102 | // Inflate the layout for this fragment 103 | return inflater.inflate(R.layout.fragment_chat, container, false); 104 | } 105 | 106 | // TODO: Rename method, update argument and hook method into UI event 107 | public void onButtonPressed(Uri uri) { 108 | if (mListener != null) { 109 | mListener.onFragmentInteraction(uri); 110 | } 111 | } 112 | 113 | @Override 114 | public void onAttach(Activity activity) { 115 | super.onAttach(activity); 116 | mAdapter = new MessageAdapter( mMessages); 117 | /*try { 118 | mListener = (OnFragmentInteractionListener) activity; 119 | } catch (ClassCastException e) { 120 | throw new ClassCastException(activity.toString() 121 | + " must implement OnFragmentInteractionListener"); 122 | }*/ 123 | 124 | } 125 | 126 | @Override 127 | public void onViewCreated(View view, Bundle savedInstanceState) { 128 | super.onViewCreated(view, savedInstanceState); 129 | 130 | mMessagesView = (RecyclerView) view.findViewById(R.id.messages); 131 | mMessagesView.setLayoutManager(new LinearLayoutManager(getActivity())); 132 | mMessagesView.setAdapter(mAdapter); 133 | 134 | ImageButton sendButton = (ImageButton) view.findViewById(R.id.send_button); 135 | mInputMessageView = (EditText) view.findViewById(R.id.message_input); 136 | 137 | sendButton.setOnClickListener(new View.OnClickListener() { 138 | @Override 139 | public void onClick(View v) { 140 | sendMessage(); 141 | } 142 | }); 143 | 144 | 145 | } 146 | 147 | private void sendMessage(){ 148 | String message = mInputMessageView.getText().toString().trim(); 149 | mInputMessageView.setText(""); 150 | addMessage(message); 151 | JSONObject sendText = new JSONObject(); 152 | try{ 153 | sendText.put("text",message); 154 | socket.emit("message", sendText); 155 | }catch(JSONException e){ 156 | 157 | } 158 | 159 | } 160 | 161 | public void sendImage(String path) 162 | { 163 | JSONObject sendData = new JSONObject(); 164 | try{ 165 | sendData.put("image", encodeImage(path)); 166 | Bitmap bmp = decodeImage(sendData.getString("image")); 167 | addImage(bmp); 168 | socket.emit("message",sendData); 169 | }catch(JSONException e){ 170 | 171 | } 172 | } 173 | 174 | private void addMessage(String message) { 175 | 176 | mMessages.add(new Message.Builder(Message.TYPE_MESSAGE) 177 | .message(message).build()); 178 | // mAdapter = new MessageAdapter(mMessages); 179 | mAdapter = new MessageAdapter( mMessages); 180 | mAdapter.notifyItemInserted(0); 181 | scrollToBottom(); 182 | } 183 | 184 | private void addImage(Bitmap bmp){ 185 | mMessages.add(new Message.Builder(Message.TYPE_MESSAGE) 186 | .image(bmp).build()); 187 | mAdapter = new MessageAdapter( mMessages); 188 | mAdapter.notifyItemInserted(0); 189 | scrollToBottom(); 190 | } 191 | private void scrollToBottom() { 192 | mMessagesView.scrollToPosition(mAdapter.getItemCount() - 1); 193 | } 194 | 195 | private String encodeImage(String path) 196 | { 197 | File imagefile = new File(path); 198 | FileInputStream fis = null; 199 | try{ 200 | fis = new FileInputStream(imagefile); 201 | }catch(FileNotFoundException e){ 202 | e.printStackTrace(); 203 | } 204 | Bitmap bm = BitmapFactory.decodeStream(fis); 205 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 206 | bm.compress(Bitmap.CompressFormat.JPEG,100,baos); 207 | byte[] b = baos.toByteArray(); 208 | String encImage = Base64.encodeToString(b, Base64.DEFAULT); 209 | //Base64.de 210 | return encImage; 211 | 212 | } 213 | 214 | private Bitmap decodeImage(String data) 215 | { 216 | byte[] b = Base64.decode(data,Base64.DEFAULT); 217 | Bitmap bmp = BitmapFactory.decodeByteArray(b,0,b.length); 218 | return bmp; 219 | } 220 | private Emitter.Listener handleIncomingMessages = new Emitter.Listener(){ 221 | @Override 222 | public void call(final Object... args){ 223 | getActivity().runOnUiThread(new Runnable() { 224 | @Override 225 | public void run() { 226 | JSONObject data = (JSONObject) args[0]; 227 | String message; 228 | String imageText; 229 | try { 230 | message = data.getString("text").toString(); 231 | addMessage(message); 232 | 233 | } catch (JSONException e) { 234 | // return; 235 | } 236 | try { 237 | imageText = data.getString("image"); 238 | addImage(decodeImage(imageText)); 239 | } catch (JSONException e) { 240 | //retur 241 | } 242 | 243 | } 244 | }); 245 | } 246 | }; 247 | 248 | @Override 249 | public void onDetach() { 250 | super.onDetach(); 251 | mListener = null; 252 | } 253 | 254 | /** 255 | * This interface must be implemented by activities that contain this 256 | * fragment to allow an interaction in this fragment to be communicated 257 | * to the activity and potentially other fragments contained in that 258 | * activity. 259 | *

260 | * See the Android Training lesson Communicating with Other Fragments for more information. 263 | */ 264 | public interface OnFragmentInteractionListener { 265 | // TODO: Update argument type and name 266 | public void onFragmentInteraction(Uri uri); 267 | } 268 | 269 | @Override 270 | public void onDestroy() { 271 | super.onDestroy(); 272 | socket.disconnect(); 273 | } 274 | 275 | } 276 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriyatma/nodesocket/Message.java: -------------------------------------------------------------------------------- 1 | package com.kriyatma.nodesocket; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | /** 6 | * Created by sreejeshpillai on 10/05/15. 7 | */ 8 | public class Message { 9 | 10 | public static final int TYPE_MESSAGE = 0; 11 | public static final int TYPE_LOG = 1; 12 | public static final int TYPE_ACTION = 2; 13 | 14 | private int mType; 15 | private String mMessage; 16 | private Bitmap mImage; 17 | 18 | private Message() {} 19 | 20 | public int getType() { 21 | return mType; 22 | }; 23 | 24 | public String getMessage() { 25 | return mMessage; 26 | }; 27 | 28 | public Bitmap getImage() { 29 | return mImage; 30 | }; 31 | 32 | 33 | public static class Builder { 34 | private final int mType; 35 | private Bitmap mImage; 36 | private String mMessage; 37 | 38 | public Builder(int type) { 39 | mType = type; 40 | } 41 | 42 | public Builder image(Bitmap image) { 43 | mImage = image; 44 | return this; 45 | } 46 | 47 | public Builder message(String message) { 48 | mMessage = message; 49 | return this; 50 | } 51 | 52 | public Message build() { 53 | Message message = new Message(); 54 | message.mType = mType; 55 | message.mImage = mImage; 56 | message.mMessage = mMessage; 57 | return message; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriyatma/nodesocket/MessageAdapter.java: -------------------------------------------------------------------------------- 1 | package com.kriyatma.nodesocket; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import java.util.List; 13 | 14 | 15 | public class MessageAdapter extends RecyclerView.Adapter { 16 | 17 | private List mMessages; 18 | private int[] mUsernameColors; 19 | 20 | public MessageAdapter(List messages) { 21 | mMessages = messages; 22 | // mUsernameColors = context.getResources().getIntArray(R.array.username_colors); 23 | } 24 | 25 | @Override 26 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 27 | int layout = -1; 28 | /*switch (viewType) { 29 | case Message.TYPE_MESSAGE: 30 | layout = R.layout.item_message; 31 | break; 32 | case Message.TYPE_LOG: 33 | layout = R.layout.item_log; 34 | break; 35 | case Message.TYPE_ACTION: 36 | layout = R.layout.item_action; 37 | break; 38 | }*/ 39 | View v = LayoutInflater 40 | .from(parent.getContext()) 41 | .inflate(R.layout.layout_message, parent, false); 42 | return new ViewHolder(v); 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(ViewHolder viewHolder, int position) { 47 | Message message = mMessages.get(position); 48 | viewHolder.setMessage(message.getMessage()); 49 | viewHolder.setImage(message.getImage()); 50 | } 51 | 52 | @Override 53 | public int getItemCount() { 54 | return mMessages.size(); 55 | } 56 | 57 | @Override 58 | public int getItemViewType(int position) { 59 | return mMessages.get(position).getType(); 60 | } 61 | 62 | public class ViewHolder extends RecyclerView.ViewHolder { 63 | private ImageView mImageView; 64 | private TextView mMessageView; 65 | public ViewHolder(View itemView) { 66 | super(itemView); 67 | mImageView = (ImageView) itemView.findViewById(R.id.image); 68 | mMessageView = (TextView) itemView.findViewById(R.id.message); 69 | } 70 | 71 | public void setMessage(String message) { 72 | if (null == mMessageView) return; 73 | if(null == message) return; 74 | mMessageView.setText(message); 75 | } 76 | 77 | public void setImage(Bitmap bmp){ 78 | if(null == mImageView) return; 79 | if(null == bmp) return; 80 | mImageView.setImageBitmap(bmp); 81 | } 82 | private int getUsernameColor(String username) { 83 | int hash = 7; 84 | for (int i = 0, len = username.length(); i < len; i++) { 85 | hash = username.codePointAt(i) + (hash << 5) - hash; 86 | } 87 | int index = Math.abs(hash % mUsernameColors.length); 88 | return mUsernameColors[index]; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriyatma/nodesocket/SocketActivity.java: -------------------------------------------------------------------------------- 1 | package com.kriyatma.nodesocket; 2 | 3 | import android.content.Intent; 4 | import android.database.Cursor; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.net.Uri; 8 | import android.provider.MediaStore; 9 | import android.support.v7.app.ActionBarActivity; 10 | import android.os.Bundle; 11 | import android.util.Base64; 12 | import android.util.Log; 13 | import android.view.Menu; 14 | import android.view.MenuInflater; 15 | import android.view.MenuItem; 16 | 17 | import java.io.ByteArrayInputStream; 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.FileNotFoundException; 22 | import java.net.URI; 23 | 24 | 25 | public class SocketActivity extends ActionBarActivity { 26 | 27 | String imgDecodableString; 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | 32 | setContentView(R.layout.activity_socket); 33 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 34 | getSupportActionBar().setHomeButtonEnabled(true); 35 | 36 | } 37 | 38 | @Override 39 | public boolean onCreateOptionsMenu(Menu menu) { 40 | // Inflate the menu; this adds items to the action bar if it is present. 41 | Log.d("onCreateOptionsMenu", "create menu"); 42 | MenuInflater inflater = getMenuInflater(); 43 | inflater.inflate(R.menu.socket_activity_actions, menu); 44 | return super.onCreateOptionsMenu(menu); 45 | } 46 | 47 | @Override 48 | public boolean onOptionsItemSelected(MenuItem item) { 49 | // Handle action bar item clicks here. The action bar will 50 | // automatically handle clicks on the Home/Up button, so long 51 | // as you specify a parent activity in AndroidManifest.xml. 52 | switch (item.getItemId()) { 53 | case R.id.action_attach: 54 | Log.d("onOptionsItemSelected","action_attach"); 55 | openGallery(); 56 | return true; 57 | case R.id.action_capture: 58 | Log.d("onOptionsItemSelected","action_capture"); 59 | // openSettings(); 60 | return true; 61 | default: 62 | return super.onOptionsItemSelected(item); 63 | } 64 | } 65 | 66 | private void openGallery() 67 | { 68 | Intent galleryintent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 69 | startActivityForResult(galleryintent, 1); 70 | } 71 | 72 | @Override 73 | protected void onActivityResult(int requestCode,int resultCode,Intent data) 74 | { 75 | super.onActivityResult(requestCode, resultCode, data); 76 | if (requestCode == 1 && resultCode == RESULT_OK 77 | && null != data) { 78 | Uri selectedImage = data.getData(); 79 | String[] filePathColumn = {MediaStore.Images.Media.DATA}; 80 | 81 | Cursor cursor = getContentResolver().query(selectedImage, 82 | filePathColumn, null, null, null); 83 | // Move to first row 84 | cursor.moveToFirst(); 85 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 86 | imgDecodableString = cursor.getString(columnIndex); 87 | cursor.close(); 88 | //Log.d("onActivityResult",imgDecodableString); 89 | ChatFragment fragment = (ChatFragment) getFragmentManager().findFragmentById(R.id.chat); 90 | fragment.sendImage(imgDecodableString); 91 | } 92 | } 93 | 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_attachment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-hdpi/ic_action_attachment.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-hdpi/ic_action_camera.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_attachment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-mdpi/ic_action_attachment.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-mdpi/ic_action_camera.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_attachment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-xhdpi/ic_action_attachment.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-xhdpi/ic_action_camera.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_attachment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-xxhdpi/ic_action_attachment.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/drawable-xxhdpi/ic_action_camera.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_socket.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_chat.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 18 | 25 | 26 | 38 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_message.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_socket.xml: -------------------------------------------------------------------------------- 1 |

4 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/socket_activity_actions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 8dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NodeSocket 3 | 4 | Hello world! 5 | Settings 6 | SEND 7 | Send 8 | Message 9 | ATTACH 10 | CAPTURE IMAGE 11 | 12 | 13 | Hello blank fragment 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.2.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /build/intermediates/dex-cache/cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 23 | 24 | 25 | 30 | 31 | 32 | 37 | 38 | 39 | 44 | 45 | 46 | 51 | 52 | 53 | 58 | 59 | 60 | 65 | 66 | 67 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /build/intermediates/gradle_project_sync_data.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/build/intermediates/gradle_project_sync_data.bin -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sreejesh79/android-socket.io-demo/f3f1f4c34d06345346dede54682ec15d52501c41/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file should *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | sdk.dir=/Users/sreejeshpillai/Library/Android/sdk -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------