@ubio/intercomm
v0.1.0
Published
Bi-directional type-safe RPC and events for Node.js and Browser
Downloads
2
Readme
ProtoComm — bi-directional RPC + events microframework
Status: work-in-progress, use at your own risk.
Facilitates transparent bi-directional communication between services. Works in Node.js and Browser (over WebSocket).
Features
- shared message and service definitions in JSON Schema format
- transparent access: clients just invoke methods and subscribe to events as if the service was a class within the same process/runtime
- transport is abstracted away from business logic
- no reliance on code generation (unlike Protobuf toolset)
- transport-agnostic; built for WebSockets in mind, but can work with IPC, TCP (albeit custom framing required)
How to use
Let's use Chat Service from tests as a motivational example.
- ChatServiceDef is a service definition which is shared across Server and Client
- On server side, ChatSession implements
ChatServiceDef
interface per connected client. - On client side, ServiceClient creates a stub using the shared service def. Conceptually, each client "talks" to its session.
- Finally, on server side ChatServer sets up the WebSocket server, hooks it up with the transport and creates a service registry.
- The tests demonstrate how messages are delivered both in RPC style (response delivered to the client who sent the request) and in Event-driven style.