Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
47 lines
1.5 KiB
Markdown
47 lines
1.5 KiB
Markdown
# @univerjs/rpc
|
|
|
|
[](https://npmjs.com/package/@univerjs/rpc)
|
|
[](https://npmjs.com/package/@univerjs/rpc)
|
|
[](https://npmjs.com/package/@univerjs/rpc)
|
|
|
|
`@univerjs/rpc` provides a browser-friendly RPC layer for communicating between the main thread and workers or other message-based runtimes.
|
|
|
|
## Package Overview
|
|
|
|
| Package | UMD global | CSS | Locales | Facade entry |
|
|
| --- | --- | :---: | :---: | :---: |
|
|
| `@univerjs/rpc` | `UniverRpc` | No | No | No |
|
|
|
|
## Installation
|
|
|
|
```sh
|
|
pnpm add @univerjs/rpc
|
|
# or
|
|
npm install @univerjs/rpc
|
|
```
|
|
|
|
Keep all `@univerjs/*` packages on the same version.
|
|
|
|
## Usage
|
|
|
|
```ts
|
|
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
|
|
|
|
const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
|
|
univer.registerPlugin(UniverRPCMainThreadPlugin, { workerURL: worker });
|
|
univer.onDispose(() => worker.terminate());
|
|
```
|
|
|
|
The referenced worker module must create its own Univer instance and register `UniverRPCWorkerThreadPlugin`; see the [browser worker example](../../examples/src/sheets-mobile/worker.ts).
|
|
|
|
Exported plugin classes:
|
|
|
|
- `UniverRPCMainThreadPlugin`
|
|
- `UniverRPCWorkerThreadPlugin`
|
|
|
|
## Resources
|
|
|
|
- [Documentation](https://docs.univer.ai)
|
|
- [NPM package](https://npmjs.com/package/@univerjs/rpc)
|
|
- [GitHub repository](https://github.com/dream-num/univer)
|