Skip to content

Latest commit

 

History

History

rpc

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@univerjs/rpc

npm version license downloads

@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 Worker entry
@univerjs/rpc UniverRpc No No No Yes

Installation

pnpm add @univerjs/rpc
# or
npm install @univerjs/rpc

Usage

Start with the integration setup for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.

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());

Main-thread plugin classes:

  • UniverRPCMainThreadPlugin

Worker usage

On the main thread, import UniverRPCMainThreadPlugin from @univerjs/rpc. Set workerURL to the worker URL or instance.

In the worker entry, import UniverRPCWorkerThreadPlugin from @univerjs/rpc/worker:

import { UniverRPCWorkerThreadPlugin } from '@univerjs/rpc/worker';

univer.registerPlugin(UniverRPCWorkerThreadPlugin);

Resources