Skip to content

Commit

Permalink
docs: add app event guide
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Dec 28, 2023
1 parent d67c770 commit e183747
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,40 @@ const appId = await fastboard.insertDocs("文件名.pptx", conversionResponse);
> });
> ```
#### 监听 PDF、PPTX 文档跳页事件
> **注意:** 该功能需要你把以下依赖升级到对应版本以上
>
> - `@netless/app-slide` ≥ 0.2.50
> - `@netless/window-manager` ≥ 0.4.66
```js
// PDF / 静态转码的文档
const dispose = fastboard.manager.onAppEvent("DocsViewer", event => {
if (event.type === "pageStateChange") console.log(event.value);
});
// PPTX / 动态转码的文档
const dispose = fastboard.manager.onAppEvent("Slide", console.log);
onExitRoom(() => dispose());
```
上面的 `event` 对象结构如下:

```json
{
"kind": "Slide",
"appId": "Slide-aa1840ba",
"type": "pageStateChange",
"value": {
"index": 0,
"length": 12
}
}
```

该方法返回一个取消监听的函数。

#### 操作 PDF、PPTX 文档

```js
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,40 @@ The `conversionResponse` is the result of [this api](https://developer.netless.l
> });
> ```
#### Listen PDF/PPTX Page Change Event
> **Note:** This feature requires the following versions of dependencies:
>
> - `@netless/app-slide` ≥ 0.2.50
> - `@netless/window-manager` ≥ 0.4.66
```js
// For static documents i.e. PDF files
const dispose = fastboard.manager.onAppEvent("DocsViewer", event => {
if (event.type === "pageStateChange") console.log(event.value);
});
// For dynamic documents i.e. PPTX files
const dispose = fastboard.manager.onAppEvent("Slide", console.log);
onExitRoom(() => dispose());
```
The `event` above will be like:

```json
{
"kind": "Slide",
"appId": "Slide-aa1840ba",
"type": "pageStateChange",
"value": {
"index": 0,
"length": 12
}
}
```

The `dispose` above is a function to stop listening.

#### Control the PDF/PPTX Apps

```js
Expand Down

0 comments on commit e183747

Please sign in to comment.