Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Dec 6, 2024
1 parent 3c30ebe commit 135e1bf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
52 changes: 52 additions & 0 deletions docs/native-to-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,58 @@ App暴露的Javascript方法,可以使用这些方法调用原生的组件!
| responseHeader | - | Object | 响应标头 |
| cookie | - | Object | Cookie |

## WebSocket

=== "示例"

```javascript linenums="1"
const ws = app.socket('wss://xxxxx');

// 连接socket成功
ws.open(() => {
// 发送消息
ws.send('hello');
})

// 获取文本信息
ws.text((text) => {
console.log(text);

// 消息接收完毕,主要用于自定义tts中
ws.finished();
})

// 获取二进制数据
ws.binary((data) => {
console.log(data);
// 消息推送给app,主要用于自定义tts中
ws.push(data);
})

// 关闭连接
ws.close();
```

=== "API"
- 请求

| 参数 | 名称 | 类型 | 默认值 | 说明 |
|:---|:---|:---|:---|:---|
| path | 地址 | String | - | - |
| protocols | 协议 | Array | [] | - |

- 方法

| 参数 | 名称 | 类型 | 说明 |
|:---|:---|:---|:---|
| open(() => {}) | 连接成功 | - | - |
| text((text) => {}) | 字符串消息回调 | String | - |
| binary((data) => {}) | 二进制消息回调 | Uint8Array | - |
| close(() => {}) | 关闭连接 | - | - |
| push | 数据推送 | - | - |
| finished | 数据接收完成推送 | - | - |

## 简易存储

将一个或多个参数本地化保存,获取和删除.
Expand Down
3 changes: 2 additions & 1 deletion docs/rules-tts.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WebSocket和post的最大区别在于WebSocket的返回值是字符串 socket

```javascript
const ws = app.socket('wss://xxxxx');

// socket连接
ws.open(() => {
console.log('连接socket成功');
Expand All @@ -80,7 +81,7 @@ ws.text((text) => {
// 获取二进制消息信息
ws.binary((data) => {
console.log('返回的二进制数据:', data.length);
// 将获取到的数据处理后重新推送给app,如果不做处理,直接pushdata数据即可
// 将获取到的数据处理后重新推送给app,如果不做处理,直接push data数据即可
ws.push(data)
});

Expand Down

0 comments on commit 135e1bf

Please sign in to comment.