From e183747b7204c498e929fff273a07960175d1939 Mon Sep 17 00:00:00 2001 From: hyrious Date: Thu, 28 Dec 2023 16:53:15 +0800 Subject: [PATCH] docs: add app event guide --- README-zh.md | 34 ++++++++++++++++++++++++++++++++++ README.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/README-zh.md b/README-zh.md index e283de5..14487f0 100644 --- a/README-zh.md +++ b/README-zh.md @@ -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 diff --git a/README.md b/README.md index f1e67ba..8bb969e 100644 --- a/README.md +++ b/README.md @@ -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