diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cc752f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +help: ## print this message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +build-site: ## build the site + mvn javadoc:javadoc site -DskipTests + +.PHONY: build-site diff --git a/README.md b/README.md index 39dd81e..27957ed 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ See also: [Socket.IO-client Java](https://github.com/socketio/socket.io-client-j | -------------- | ---------------- | ---------------- | | 0.9.x | 1.x | 1.x | | 1.x | 3.x | 2.x | -| - | 4.x | 3.x | +| WIP | 4.x | 3.x | ## Installation The latest artifact is available on Maven Central. @@ -132,43 +132,6 @@ socket = new Socket(opts); ## Features This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported. -### Extra features only for Java client - -#### Accessing HTTP Headers -You can access HTTP headers like the following. - -```java -socket.on(Socket.EVENT_TRANSPORT, new Emitter.listener() { - @Override - public void call(Object... args) { - // Called on a new transport created. - Transport transport = (Transport)args[0]; - - transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() { - @Override - public void call(Object... args) { - @SuppressWarnings("unchecked") - Map> headers = (Map>)args[0]; - // send cookie value to server. - headers.put("Cookie", Arrays.asList("foo=1;")); - } - }).on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() { - @Override - public void call(Object... args) { - @SuppressWarnings("unchecked") - Map> headers = (Map>)args[0]; - // receive cookie value from server. - String cookie = headers.get("Set-Cookie").get(0); - } - }); - } -}); -``` - -See the Javadoc for more details. - -http://socketio.github.io/engine.io-client-java/apidocs/ - ## License MIT diff --git a/pom.xml b/pom.xml index 240af40..863583b 100644 --- a/pom.xml +++ b/pom.xml @@ -200,20 +200,9 @@ 2.3 - com.github.github - site-maven-plugin - 0.12 - - Creating site for ${project.version} - - - - - site - - site - - + org.apache.maven.plugins + maven-site-plugin + 3.9.1 diff --git a/src/site/markdown/installation.md b/src/site/markdown/installation.md new file mode 100644 index 0000000..7b3cabb --- /dev/null +++ b/src/site/markdown/installation.md @@ -0,0 +1,33 @@ +## Compatibility + +| Client version | Engine.IO server | Socket.IO server | +| -------------- | ---------------- | ---------------- | +| 0.9.x | 1.x | 1.x | +| 1.x | 3.x | 2.x | +| WIP | 4.x | 3.x | + +## Installation +The latest artifact is available on Maven Central. + +### Maven +Add the following dependency to your `pom.xml`. + +```xml + + + io.socket + engine.io-client + 1.0.1 + + +``` + +### Gradle +Add it as a gradle dependency for Android Studio, in `build.gradle`: + +```groovy +compile ('io.socket:engine.io-client:1.0.1') { + // excluding org.json which is provided by Android + exclude group: 'org.json', module: 'json' +} +``` diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md new file mode 100644 index 0000000..4299cac --- /dev/null +++ b/src/site/markdown/usage.md @@ -0,0 +1,82 @@ +## Usage +Engine.IO-client Java has the similar api with the JS client. You can use `Socket` to connect: + +```java +socket = new Socket("ws://localhost"); +socket.on(Socket.EVENT_OPEN, new Emitter.Listener() { + @Override + public void call(Object... args) { + socket.send("hi"); + socket.close(); + } +}); +socket.open(); +``` + +You can listen events as follows: + +```java +socket.on(Socket.EVENT_MESSAGE, new Emitter.Listener() { + @Override + public void call(Object... args) { + String data = (String)args[0]; + } +}).on(Socket.EVENT_ERROR, new Emitter.Listener() { + @Override + public void call(Object... args) { + Exception err = (Exception)args[0]; + } +}); +``` + +How to set options: + +```java +opts = new Socket.Options(); +opts.transports = new String[] {WebSocket.NAME}; + +socket = new Socket(opts); +``` + +Sending and receiving binary data: + +```java +socket = new Socket(); +socket.on(Socket.EVENT_OPEN, new Emitter.Listener() { + @Override + public void call(Object... args) { + // send binary data + byte[] data = new byte[42]; + socket.send(data); + } +}).on(Socket.EVENT_MESSAGE, new Emitter.Listener() { + @Override + public void call(Object... args) { + // receive binary data + byte[] data = (byte[])args[0]; + } +}); +``` + +Use custom SSL settings: + +```java +OkHttpClient okHttpClient = new OkHttpClient.Builder() + .hostnameVerifier(myHostnameVerifier) + .sslSocketFactory(mySSLContext.getSocketFactory(), myX509TrustManager) + .build(); + +// default SSLContext for all sockets +Socket.setDefaultOkHttpWebSocketFactory(okHttpClient); +Socket.setDefaultOkHttpCallFactory(okHttpClient); + +// set as an option +opts = new Socket.Options(); +opts.callFactory = okHttpClient; +opts.webSocketFactory = okHttpClient; +socket = new Socket(opts); +``` + +## Features + +This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported. diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000..27b861d --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,30 @@ + + + + + org.apache.maven.skins + maven-fluido-skin + 1.9 + + + + + + socketio/engine.io-client-java + right + gray + + + + + + + + + + + + + + \ No newline at end of file