Skip to content

Commit a857b9b

Browse files
docs: update website
1 parent 49068d3 commit a857b9b

File tree

6 files changed

+222
-15
lines changed

6 files changed

+222
-15
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
help: ## print this message
2+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
3+
4+
build-site: ## build the site
5+
mvn javadoc:javadoc site -DskipTests
6+
7+
.PHONY: build-site

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Add the following dependency to your `pom.xml`.
4040
<dependency>
4141
<groupId>io.socket</groupId>
4242
<artifactId>socket.io-client</artifactId>
43-
<version>1.0.1/version>
43+
<version>1.0.1</version>
4444
</dependency>
4545
</dependencies>
4646
```

pom.xml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,9 @@
219219
<version>2.3</version>
220220
</plugin>
221221
<plugin>
222-
<groupId>com.github.github</groupId>
223-
<artifactId>site-maven-plugin</artifactId>
224-
<version>0.12</version>
225-
<configuration>
226-
<message>Creating site for ${project.version}</message>
227-
</configuration>
228-
<executions>
229-
<execution>
230-
<goals>
231-
<goal>site</goal>
232-
</goals>
233-
<phase>site</phase>
234-
</execution>
235-
</executions>
222+
<groupId>org.apache.maven.plugins</groupId>
223+
<artifactId>maven-site-plugin</artifactId>
224+
<version>3.9.1</version>
236225
</plugin>
237226
</plugins>
238227
</build>

src/site/markdown/installation.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Compatibility
2+
3+
| Client version | Socket.IO server |
4+
| -------------- | ---------------- |
5+
| 0.9.x | 1.x |
6+
| 1.x | 2.x |
7+
| WIP | 3.x |
8+
9+
## Installation
10+
The latest artifact is available on Maven Central.
11+
12+
### Maven
13+
Add the following dependency to your `pom.xml`.
14+
15+
```xml
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.socket</groupId>
19+
<artifactId>socket.io-client</artifactId>
20+
<version>1.0.1</version>
21+
</dependency>
22+
</dependencies>
23+
```
24+
25+
### Gradle
26+
Add it as a gradle dependency for Android Studio, in `build.gradle`:
27+
28+
```groovy
29+
compile ('io.socket:socket.io-client:1.0.1') {
30+
// excluding org.json which is provided by Android
31+
exclude group: 'org.json', module: 'json'
32+
}
33+
```

src/site/markdown/usage.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
## Usage
2+
Socket.IO-client Java has almost the same api and features with the original JS client. You use `IO#socket` to initialize `Socket`:
3+
4+
```java
5+
import io.socket.client.IO;
6+
import io.socket.client.Socket;
7+
...
8+
9+
Socket socket = IO.socket("http://localhost");
10+
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
11+
12+
@Override
13+
public void call(Object... args) {
14+
socket.emit("foo", "hi");
15+
socket.disconnect();
16+
}
17+
18+
}).on("event", new Emitter.Listener() {
19+
20+
@Override
21+
public void call(Object... args) {}
22+
23+
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
24+
25+
@Override
26+
public void call(Object... args) {}
27+
28+
});
29+
socket.connect();
30+
```
31+
32+
This Library uses [org.json](https://github.com/stleary/JSON-java) to parse and compose JSON strings:
33+
34+
```java
35+
// Sending an object
36+
JSONObject obj = new JSONObject();
37+
obj.put("hello", "server");
38+
obj.put("binary", new byte[42]);
39+
socket.emit("foo", obj);
40+
41+
// Receiving an object
42+
socket.on("foo", new Emitter.Listener() {
43+
@Override
44+
public void call(Object... args) {
45+
JSONObject obj = (JSONObject)args[0];
46+
}
47+
});
48+
```
49+
50+
Options are supplied as follows:
51+
52+
```java
53+
IO.Options opts = new IO.Options();
54+
opts.forceNew = true;
55+
opts.reconnection = false;
56+
57+
socket = IO.socket("http://localhost", opts);
58+
```
59+
60+
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:
61+
62+
```java
63+
IO.Options opts = new IO.Options();
64+
opts.forceNew = true;
65+
opts.query = "auth_token=" + authToken;
66+
Socket socket = IO.socket("http://localhost", opts);
67+
```
68+
69+
You can get a callback with `Ack` when the server received a message:
70+
71+
```java
72+
socket.emit("foo", "woot", new Ack() {
73+
@Override
74+
public void call(Object... args) {}
75+
});
76+
```
77+
78+
And vice versa:
79+
80+
```java
81+
// ack from client to server
82+
socket.on("foo", new Emitter.Listener() {
83+
@Override
84+
public void call(Object... args) {
85+
Ack ack = (Ack) args[args.length - 1];
86+
ack.call();
87+
}
88+
});
89+
```
90+
91+
SSL (HTTPS, WSS) settings:
92+
93+
```java
94+
OkHttpClient okHttpClient = new OkHttpClient.Builder()
95+
.hostnameVerifier(myHostnameVerifier)
96+
.sslSocketFactory(mySSLContext.getSocketFactory(), myX509TrustManager)
97+
.build();
98+
99+
// default settings for all sockets
100+
IO.setDefaultOkHttpWebSocketFactory(okHttpClient);
101+
IO.setDefaultOkHttpCallFactory(okHttpClient);
102+
103+
// set as an option
104+
opts = new IO.Options();
105+
opts.callFactory = okHttpClient;
106+
opts.webSocketFactory = okHttpClient;
107+
socket = IO.socket("https://localhost", opts);
108+
```
109+
110+
See the Javadoc for more details.
111+
112+
http://socketio.github.io/socket.io-client-java/apidocs/
113+
114+
### Transports and HTTP Headers
115+
You can access transports and their HTTP headers as follows.
116+
117+
```java
118+
// Called upon transport creation.
119+
socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() {
120+
@Override
121+
public void call(Object... args) {
122+
Transport transport = (Transport)args[0];
123+
124+
transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
125+
@Override
126+
public void call(Object... args) {
127+
@SuppressWarnings("unchecked")
128+
Map<String, List<String>> headers = (Map<String, List<String>>)args[0];
129+
// modify request headers
130+
headers.put("Cookie", Arrays.asList("foo=1;"));
131+
}
132+
});
133+
134+
transport.on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() {
135+
@Override
136+
public void call(Object... args) {
137+
@SuppressWarnings("unchecked")
138+
Map<String, List<String>> headers = (Map<String, List<String>>)args[0];
139+
// access response headers
140+
String cookie = headers.get("Set-Cookie").get(0);
141+
}
142+
});
143+
}
144+
});
145+
```
146+
147+
## Features
148+
This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported.

src/site/site.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
4+
5+
<skin>
6+
<groupId>org.apache.maven.skins</groupId>
7+
<artifactId>maven-fluido-skin</artifactId>
8+
<version>1.9</version>
9+
</skin>
10+
11+
<custom>
12+
<fluidoSkin>
13+
<gitHub>
14+
<projectId>socketio/socket.io-client-java</projectId>
15+
<ribbonOrientation>right</ribbonOrientation>
16+
<ribbonColor>gray</ribbonColor>
17+
</gitHub>
18+
</fluidoSkin>
19+
</custom>
20+
21+
<body>
22+
<menu name="Overview">
23+
<item name="Installation" href="./installation.html"/>
24+
<item name="Usage" href="./usage.html"/>
25+
<item name="Javadoc" href="./apidocs/index.html"/>
26+
</menu>
27+
28+
<menu ref="reports"/>
29+
</body>
30+
</project>

0 commit comments

Comments
 (0)