docs: update website

This commit is contained in:
Damien Arrachequesne
2020-12-11 15:16:25 +01:00
parent 2b5dfb99f8
commit cbd341c2c9
6 changed files with 156 additions and 52 deletions

View File

@@ -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
<dependencies>
<dependency>
<groupId>io.socket</groupId>
<artifactId>engine.io-client</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
```
### 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'
}
```

View File

@@ -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.

30
src/site/site.xml Normal file
View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.9</version>
</skin>
<custom>
<fluidoSkin>
<gitHub>
<projectId>socketio/engine.io-client-java</projectId>
<ribbonOrientation>right</ribbonOrientation>
<ribbonColor>gray</ribbonColor>
</gitHub>
</fluidoSkin>
</custom>
<body>
<menu name="Overview">
<item name="Installation" href="./installation.html"/>
<item name="Usage" href="./usage.html"/>
<item name="Javadoc" href="./apidocs/index.html"/>
</menu>
<menu ref="reports"/>
</body>
</project>