Setup
Workex is a solution to RPC in the JS world. You define interfaces in TypeScript, and Workex generates code so that calling a remote context uses the same interface you define.
Workex provides support for these bidirectional RPCs:
- Between
Window
andWorker
- Between 2
Window
s, for both same- and cross-origin- For example, the main window and iframes, or popouts
- WebSocket support might be added in the future
The library works as follows:
- You define the messaging protocol as TypeScript interfaces
- Run the
workex
CLI to generate code in your project - Use the generated code and the
@pistonite/workex
SDK library to have seamless RPC - Handshake, protocol agreement, error handling, same- and cross-origin… all handled internally
To get started, install the CLI tool with
cargo install --git https://github.com/Pistonite/workex
After installing, you can run workex --help
to see the available options.
See the tutorials for a full end-to-end walk-through
of running some basic RPC stuff.
TypeScript SDK
The code generated by the workex
CLI depends on the @pistonite/workex
TypeScript SDK.
You can install it with your favorite package manager. For example, for pnpm
:
pnpm i @pistonite/workex
The tutorials shows basic examples for using the SDK. You can also refer to the SDK reference when needed.
Note that:
- The SDK version and CLI version should have the same minor version (the major version will always be
0
)- i.e.
0.1.1
and0.1.0
are compatible with each other, but not0.1.1
and0.2.0
- i.e.
- The SDK is TypeScript-only, so a bundler is needed to consume it.