Skip to content

Commit 667366c

Browse files
committed
docs: update doc
1 parent 551d0d6 commit 667366c

File tree

5 files changed

+287
-2
lines changed

5 files changed

+287
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.settings
55

66
# dist
7-
target/
7+
target/
8+
.vuepress

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ DFocus wanted ssp solution - java-client.
1414

1515
## Depdencies
1616

17+
Currently, you can only use `socket.io.java.client.biz` from the [source](https://github.com/DFocusFE/socket.io.java.client.biz).
18+
19+
```bash
20+
# clone source code
21+
git clone https://github.com/DFocusFE/socket.io.java.client.biz.git
22+
cd socket.io.java.client.biz.git
23+
24+
# install the library into your local maven repo
25+
mvn clean install
26+
```
27+
1728
### maven
1829

1930
```xml
@@ -24,7 +35,27 @@ DFocus wanted ssp solution - java-client.
2435
</dependency>
2536
```
2637

27-
> Currently, you have to install the library to your local repo, with `mvn clean install`
38+
### gradle
39+
40+
Add `mavenLocal()` to `build.gradle`
41+
42+
```
43+
allprojects {
44+
repositories {
45+
google()
46+
jcenter()
47+
mavenLocal()
48+
}
49+
}
50+
```
51+
52+
Add dependency
53+
54+
```
55+
dependencies {
56+
implementation 'com.dfocus:socket.io.java.client.biz:1.0-SNAPSHOT'
57+
}
58+
```
2859

2960
## Usage
3061

docs/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
home: true
3+
actionText: More Information
4+
actionLink: /api/
5+
---
6+
7+
[![NPM version][npm-image]][npm-url]
8+
![][david-url]
9+
![][dt-url]
10+
![][license-url]
11+
12+
DFocus wanted ssp solution - java-client. It is a porting version of [socket.io.client.biz](https://github.com/DFocusFE/socket.io.client.biz).
13+
14+
It must be work with the specific Backend(TBD)
15+
16+
`socket.io.java.client.biz` is made for domain specific business scenarios. It consists of following features:
17+
18+
- re-connect
19+
- authentication via token
20+
- project based, let's say you are working on a SaaS platform, several projects may subscribe topics individually
21+
- easy to distinguish events from topics
22+
- no need to worry about re-subscribe process whenever re-connect triggered
23+
24+
## Install
25+
26+
Currently, you can only use `socket.io.java.client.biz` from the [source](https://github.com/DFocusFE/socket.io.java.client.biz).
27+
28+
```bash
29+
# clone source code
30+
git clone https://github.com/DFocusFE/socket.io.java.client.biz.git
31+
cd socket.io.java.client.biz.git
32+
33+
# install the library into your local maven repo
34+
mvn clean install
35+
```
36+
37+
**maven**
38+
39+
```xml
40+
<dependency>
41+
<groupId>com.dfocus</groupId>
42+
<artifactId>socket.io.java.client.biz</artifactId>
43+
<version>1.0-SNAPSHOT</version>
44+
</dependency>
45+
```
46+
47+
**gradle**
48+
49+
Add `mavenLocal()` to `build.gradle`
50+
51+
```
52+
allprojects {
53+
repositories {
54+
google()
55+
jcenter()
56+
mavenLocal()
57+
}
58+
}
59+
```
60+
61+
```
62+
dependencies {
63+
implementation 'com.dfocus:socket.io.java.client.biz:1.0-SNAPSHOT'
64+
}
65+
```
66+
67+
## Usage
68+
69+
```java
70+
public class SocketIoClientBizTest {
71+
public static void main(String[] args) {
72+
SocketOpts opts = new SocketOpts("http://hi.dfocus.com", "your projectId", "your token");
73+
SocketIoClientBiz biz = new SocketIoClientBiz(opts);
74+
75+
try{
76+
biz.connect(new Finish() {
77+
@Override
78+
public void onFinished(String msg) {
79+
if ("".equals(msg)) {
80+
System.out.println("Connection established");
81+
} else {
82+
System.out.println("Failed to connect to server: " + msg);
83+
}
84+
85+
}
86+
});
87+
88+
biz.subscribe("your topic", "your event", new EventCallback() {
89+
@Override
90+
public void onFire(final EventMessage message) {
91+
@Override
92+
public void run() {
93+
System.out.println("Message from server: " + message.getPayload());
94+
}
95+
}
96+
});
97+
98+
biz.onStateChange(new StateChangeCallback() {
99+
@Override
100+
public void onChange(final ClientState s) {
101+
System.out.println("State Changed: " + s);
102+
}
103+
});
104+
}
105+
catch(InvalidArgumentException e) {
106+
e.printStackTrace();
107+
}
108+
catch(LifecycleException e) {
109+
e.printStackTrace();
110+
}
111+
}
112+
}
113+
```
114+
115+
> If you are going to use it with Android, all callbacks has to be called in `runOnUiThread`
116+
117+
## LICENSE
118+
119+
[MIT License](https://raw.githubusercontent.com/DFocusFE/socket.io.client.biz/master/LICENSE)
120+
121+
[npm-url]: https://npmjs.org/package/socket.io.client.biz
122+
[npm-image]: https://badge.fury.io/js/socket.io.client.biz.png
123+
[david-url]: https://david-dm.org/DFocusFE/socket.io.client.biz.png
124+
[dt-url]: https://img.shields.io/npm/dt/socket.io.client.biz.svg
125+
[license-url]: https://img.shields.io/npm/l/socket.io.client.biz.svg

docs/api/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
sidebarDepth: 4
3+
---
4+
5+
# API
6+
7+
## SocketIoClientBiz
8+
9+
`(SocketOpts opts) => SocketIoClientBiz`
10+
11+
- construct a client instance
12+
13+
**Usage**
14+
15+
```java
16+
SocketOpts opts = new SocketOpts("http://hi.dfocus.com", "your projectId", "your token");
17+
SocketIoClientBiz biz = new SocketIoClientBiz(opts);
18+
```
19+
20+
## Methods
21+
22+
### connect
23+
24+
`(Finish callback) => void`
25+
26+
- open the connection with server
27+
28+
**Usage**
29+
30+
```java
31+
bizClient.connect(new Finish() {
32+
@Override
33+
public void onFinished(final String errorMessage) {
34+
@Override
35+
public void run() {
36+
if ("".equals(errorMessage)) {
37+
System.out.println("connected");
38+
} else {
39+
System.out.println("failed to connect");
40+
}
41+
}
42+
}
43+
});
44+
```
45+
46+
### onStateChange
47+
48+
`(ClientState state) => Subscription`
49+
50+
- listen for client state change
51+
52+
**Usage**
53+
54+
```java
55+
// watch every connection state change
56+
const stateChangeSub = bizClient.onStateChange(new StateChangeCallback() {
57+
@Override
58+
public void onChange(ClientState s) {
59+
@Override
60+
public void run() {
61+
System.out.println("state changed to " + s);
62+
}
63+
}
64+
});
65+
66+
// you can dispose this subscription later
67+
stateChangeSub.dispose();
68+
```
69+
70+
### subscribe
71+
72+
`(String topic, String event, EventCallback cb)=> Subscription`
73+
74+
- subscribe event for specific topic
75+
76+
**Usage**
77+
78+
```java
79+
// watch for specific event along with its topic
80+
const eventSub = bizClient.subscribe("spaces", "SPACE_ADDED", new EventCallback() {
81+
@Override
82+
public void onFire(EventMessage message) {
83+
@Override
84+
public void run() {
85+
System.out.println("event = " + message.getPayload());
86+
}
87+
}
88+
});
89+
90+
// you can dispose this subscription later
91+
eventSub.dispose();
92+
```
93+
94+
### disconnect
95+
96+
`(): void`
97+
98+
- manually close the connection with server side
99+
100+
**Usage**
101+
102+
```java
103+
bizClient.disconnect();
104+
```

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "socket.io.java.client.biz",
3+
"version": "1.0.0",
4+
"description": "DFocus wanted ssp java client",
5+
"scripts": {
6+
"docs:dev": "vuepress dev docs",
7+
"docs:deploy": "vuepress build docs && gh-pages -d docs/.vuepress/dist"
8+
},
9+
"sideEffects": false,
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/DFocusFE/socket.io.java.client.biz.git"
13+
},
14+
"author": "Howard.Zuo",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/DFocusFE/socket.io.java.client.biz/issues"
18+
},
19+
"homepage": "https://github.com/DFocusFE/socket.io.java.client.biz#readme",
20+
"devDependencies": {
21+
"gh-pages": "^2.1.1",
22+
"vuepress": "^1.0.4"
23+
}
24+
}

0 commit comments

Comments
 (0)