Commit c00e1b05 by giaogiao

修改文档

parent 3459d0aa
This source diff could not be displayed because it is too large. You can view the blob instead.
# wecloud-im 前端Websocket对接文档 # wecloud-im 前端Websocket对接文档
...@@ -65,38 +65,51 @@ clientId:由后端生成 ...@@ -65,38 +65,51 @@ clientId:由后端生成
**已读**为客户端已经查看该消息 **已读**为客户端已经查看该消息
## ping / pong心跳机制
1. 客户端接收到服务端下发"ping"字符串时, 必须立即回应"pong"字符串;
2. 客户端可完善定时向服务端发起"ping"字符串,来保持websocket连接状态, 服务端会立即回应"pong"字符串,如果连续3次未及时响应"pong",即可认定websocket已经断开,进入重新连接流程;
3. 建议客户端发"ping"间隔时间为5秒
## 客户端登陆 ## 客户端登陆
![wc_im_client连接流程-Page-1](https://tva1.sinaimg.cn/large/008i3skNgy1guv1su6a35j60d80gzaan02.jpg) ![wc_im_client连接流程-Page-1](https://tva1.sinaimg.cn/large/008i3skNly1gvbhmdzg3kj60zt0u0juf02.jpg)
1. appKey, appSecret为蔚可云下发给客户方安全保护密钥,不建议保存在前端客户端; 1. appKey, appSecret为蔚可云下发给客户方安全保护密钥,不建议保存在前端客户端;
2. 第三方应用服务端需提供获取sign的接口, sign 由MD5{timestamp + clientId + appKey + appSecret},其中clientId由后端生成; 2. 第三方应用服务端需提供获取sign的接口, sign 由MD5{timestamp + clientId + appKey + appSecret},其中clientId由后端生成;
3. 前端拿到sign后,调用验证sign接口进行获取token; 3. 前端拿到sign后,调用验证sign接口进行获取token;
4. websocket连接初始化需要带上token即可连接成功; 4. websocket连接初始化需要带上token即可连接成功;
5. sign 需要在你的应用服务端生成;
### 第三方应用后端生成sign接口示例 ### 第三方应用后端生成sign接口示例
本文展示如何在服务端部署一个 sign 生成器。
**java**示例代码 ,供客户应用后端参考 **java**示例代码 ,供客户应用后端参考
```java ```java
private void getSign(String timestemp, String clientId, String appKey, String appSecret) { import org.springframework.util.DigestUtils;
String sign = new MD5().digestHex(timestemp + clientId + appKey + appSecret); private void getSign(String timestamp, String clientId, String appKey, String appSecret) {
String data = timestamp + clientId + appKey + appSecret;
String sign = DigestUtils.md5DigestAsHex(data.getBytes());
} }
public static void main(String[] args) { public static void main(String[] args) {
String clientId = "client_123123"; String clientId = "client_123123";
String appKey = "elLwpel1gWCHDqZy"; String appKey = "elLwpel1gWCHDqZy";
String appSecret = "68809bb5a9077a83631aeb0b17b5965d6b2302faf2ab3737"; String appSecret = "68809bb5a9077a83631aeb0b17b5965d6b2302faf2ab3737";
String timestemp = String.valueOf(new Date().getTime()); String timestamp = String.valueOf(new Date().getTime());
getSign(timestemp, clientId, appKey, appSecret); getSign(timestamp, clientId, appKey, appSecret);
} }
``` ```
后端必须需要响应参数: 第三方应用后端需要响应的参数:
``` ```json
{ {
"timestamp": "1628838135066", "timestamp": "1628838135066",
"clientId": "client_3334444", "clientId": "client_3334444",
...@@ -111,7 +124,7 @@ ws://localhost:8899/ws?token=xxxxxx&platform=1 ...@@ -111,7 +124,7 @@ ws://localhost:8899/ws?token=xxxxxx&platform=1
示例: 示例:
``` ```text
ws://localhost:8899/ws?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWIiLCJjbGllbnRJZCI6ImhhaGFoXzMwIiwiaXNzIjoid2VjbG91ZF9pbSIsImFwcEtleSI6ImVsTHdwZWwxZ1dDSERxWnkiLCJleHAiOjE2MjkwOTY0MzksImlhdCI6MTYyMDQ1NjQzOSwianRpIjoiNDA1YzE3MWM2Njc5NGJmMDllNGRjZDdhNzA0ZjY3YTgifQ.7g2J_0q9UnuWszpuapSJUXJEwVevvI8Rm2Srg3594Lk&platform=1 ws://localhost:8899/ws?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWIiLCJjbGllbnRJZCI6ImhhaGFoXzMwIiwiaXNzIjoid2VjbG91ZF9pbSIsImFwcEtleSI6ImVsTHdwZWwxZ1dDSERxWnkiLCJleHAiOjE2MjkwOTY0MzksImlhdCI6MTYyMDQ1NjQzOSwianRpIjoiNDA1YzE3MWM2Njc5NGJmMDllNGRjZDdhNzA0ZjY3YTgifQ.7g2J_0q9UnuWszpuapSJUXJEwVevvI8Rm2Srg3594Lk&platform=1
``` ```
...@@ -155,7 +168,6 @@ wss://ws.im199.com/ws?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWI ...@@ -155,7 +168,6 @@ wss://ws.im199.com/ws?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWI
## 请求CMD指令说明 ## 请求CMD指令说明
- 1: 发送IM消息请求 - 1: 发送IM消息请求
- 3: 单人WebRTC请求 - 3: 单人WebRTC请求
## 响应CMD指令说明 ## 响应CMD指令说明
...@@ -237,7 +249,7 @@ websocket是异步的 有可能你很快速的发送了几条消息,服务器响 ...@@ -237,7 +249,7 @@ websocket是异步的 有可能你很快速的发送了几条消息,服务器响
**示例一: 必传参数:** **示例一: 必传参数:**
``` ```json
{ {
"reqId":"123123123", "reqId":"123123123",
"cmd":1, "cmd":1,
......
# wecloud-RTC音视频客户端对接文档 # wecloud-RTC音视频客户端信令对接文档
# wecloud-RTC音视频客户端对接文档 # wecloud-RTC音视频客户端信令对接文档
## 文档描述 ## 文档描述
...@@ -27,17 +27,21 @@ client需要监听频道内 状态更新(房间断开,挂断)、用户状态更 ...@@ -27,17 +27,21 @@ client需要监听频道内 状态更新(房间断开,挂断)、用户状态更
## 指令说明 ## 指令说明
**subCmd**子类型 #### **subCmd**子类型
##### 客户端**请求**指令列表:
客户端**请求**指令列表:
**create**:创建频道 **create**:创建频道
**join**: 加入频道 **join**: 加入频道
服务端**响应**指令列表: ##### 服务端**响应**指令列表:
**rtcCall**:接收到RTC邀请 **rtcCall**:接收到RTC邀请
**userEvent** : 用户状态更新事件(用户加入, 用户退出) **clientEvent** : 用户状态更新事件(用户加入,用户退出,用户拒接邀请)
**typeChangeEvent**:流状态更新(切换音频 切换视频) **typeEvent**:流状态更新(切换音频 切换视频)
**statusEvent**:状态更新(网络断开,挂断) **statusEvent**:状态更新(网络断开,挂断)
**SDP**:SDP数据转发
**busy**:忙线
## 创建频道 发起RTC音视频通话 ## 创建频道 发起RTC音视频通话
...@@ -126,14 +130,16 @@ client需要监听频道内 状态更新(房间断开,挂断)、用户状态更 ...@@ -126,14 +130,16 @@ client需要监听频道内 状态更新(房间断开,挂断)、用户状态更
```json ```json
{ {
"reqId":"",
"cmd":4, "cmd":4,
"data":{ "data":{
"diyParam自定义字段":"aaaa自已定义字段的值",
"toConversation":null,
"channelId":1234263457652,
"subCmd":"rtcCall", "subCmd":"rtcCall",
"sender":"client_1010", "subData":{
"type":"video",
"toConversation":null,
"channelId":1234263457652,
"sender":"client_1010"
},
"diyParam自定义字段":"aaaa自已定义字段的值",
"attrs":{ "attrs":{
"a":"示例: 用户自定义的一些键值对", "a":"示例: 用户自定义的一些键值对",
"b":"存储用户自定义的一些键值对" "b":"存储用户自定义的一些键值对"
...@@ -153,11 +159,11 @@ client需要监听频道内 状态更新(房间断开,挂断)、用户状态更 ...@@ -153,11 +159,11 @@ client需要监听频道内 状态更新(房间断开,挂断)、用户状态更
| subCmd | String | 否 | 子类型指令 | | subCmd | String | 否 | 子类型指令 |
| sender | String | 否 | 发起通话的客户端ID | | sender | String | 否 | 发起通话的客户端ID |
| channelId | Long | 否 | 由服务端创建的频道id | | channelId | Long | 否 | 由服务端创建的频道id |
| type | String | 否 | 类型: "video" 或 "voice" |
## 同意加入频道
## 接收方同意加入频道 client接收方向服务端请求数据:
client接收方向服务端发送数据:
```json ```json
{ {
...@@ -179,34 +185,35 @@ client接收方向服务端发送数据: ...@@ -179,34 +185,35 @@ client接收方向服务端发送数据:
| diyParam自定义字段 | Object | 是 | 自定义拓展字段 | | diyParam自定义字段 | Object | 是 | 自定义拓展字段 |
| subCmd | String | 否 | 子类型指令 | | subCmd | String | 否 | 子类型指令 |
### 通知发起方: 接收方同意加入频道 ## 通知:有client加入频道
服务端向发送方下发数据: 服务端向频道内其他client响应数据:
```json ```json
{ {
"reqId":"123",
"cmd":4, "cmd":4,
"data":{ "data":{
"channelId":1234263457652, "subCmd":"clientEvent",
"clientId":"adsfadf", "subData":{
"diyParam自定义字段":"aaaa自已定义字段的值", "channelId":1234263457652,
"subCmd":"agree" "type":"join",
"clientId":7657567,
}
} }
} }
``` ```
## 接收方拒绝加入频道 ## 拒绝加入频道
client接收方向服务端发送数据: client接收方向服务端请求数据:
```json ```json
{ {
"reqId":"123", "reqId":"123",
"cmd":3, "cmd":3,
"data":{ "data":{
"subCmd":"reject",
"diyParam自定义字段":"aaaa自已定义字段的值", "diyParam自定义字段":"aaaa自已定义字段的值",
"channelId":1234263457652, "channelId":1234263457652,
"subCmd":"reject",
"attrs":{} "attrs":{}
} }
} }
...@@ -224,43 +231,123 @@ client接收方向服务端发送数据: ...@@ -224,43 +231,123 @@ client接收方向服务端发送数据:
| diyParam自定义字段 | Object | 是 | 自定义拓展字段 | | diyParam自定义字段 | Object | 是 | 自定义拓展字段 |
| subCmd | String | 否 | 子类型 | | subCmd | String | 否 | 子类型 |
### 通知发送方: 接收方拒绝加入频道 ## 通知:有Client拒绝加入频道
服务端向发送方下发数据: 服务端向频道内其他client响应数据:
```json ```json
{ {
"reqId":"123",
"cmd":4, "cmd":4,
"data":{ "data":{
"diyParam自定义字段":"aaaa自已定义字段的值", "subCmd":"clientEvent",
"toConversation":1402147846261706752, "subData":{
"subCmd":"reject" "channelId":1234263457652,
"type":"reject",
"clientId":7657567,
}
} }
} }
``` ```
## 流媒体描述信息SDP转发 ## 流媒体描述信息SDP转发
(服务端仅负责转发)(ice_candidate,anser,offer) (服务端仅负责转发)(ice_candidate,anser,offer)
## 视频/音频切换 ### client发送SDP
## 有用户离开频道 ```json
{
"reqId":"123",
"cmd":3,
"data":{
"subCmd":"sdp",
"channelId":1234263457652,
"sdpData":"xxxxxxxxxxxxxxxx",
"diyParam自定义字段":"aaaa自已定义字段的值",
"attrs":{}
}
}
```
## 系统电话繁忙
## 断线重连 ### client接收SDP
## 发送心跳 ```json
{
"cmd":4,
"data":{
"subCmd":"sdp",
"subData":{
"channelId":1234263457652,
"clientId":7657567,
"sdpData":"xxxxxxxxxxxxxxxx",
"diyParam自定义字段":"aaaa自已定义字段的值",
"attrs":{}
}
}
}
```
## 对方是否还挂起 ## 主动挂断(离开频道)
client主动离开频道
向服务端请求:
```json
{
"reqId":"123",
"cmd":3,
"data":{
"subCmd":"leave",
"channelId":1234263457652
}
}
```
## 通知:有client离开频道
服务端向频道内其他client响应数据:
```json
{
"cmd":4,
"data":{
"subCmd":"clientEvent",
"subData":{
"channelId":1234263457652,
"type":"leave",
"clientId":7657567,
}
}
}
```
## 对方忙线(对方正在通话中)
服务端响应给发起方
```json
{
"reqId":"555111-ad-afd12",
"cmd":5,
"data":{
"subCmd":"busy",
"subData":{
"channelId":1234263457652,
"clientId":7657567
}
}
}
```
## 挂断 ## 断线重连
## 确认离开 重新join进频道即可重连
## 确认是否离开 ## 对方是否还挂起
## 视频/音频切换
## 查询对方是否离开 ## 查询对方是否离开
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment