Skip to content

Message Port

oRPC offers built-in support for common Message Port implementations, enabling easy internal communication between different processes.

EnvironmentDocumentation
Electron Message PortIntegration Guide
Browser (extension background to popup/content, window to window, etc.)Integration Guide
Node.js Worker Threads PortIntegration Guide

Basic Usage

Message Ports work by establishing two endpoints that can communicate with each other:

bridge
ts
const channel = new MessageChannel()
const serverPort = channel.port1
const clientPort = channel.port2
server
ts
import { experimental_RPCHandler as RPCHandler } from '@orpc/server/message-port'

const handler = new RPCHandler(router)

handler.upgrade(serverPort, {
  context: {}, // Optionally provide an initial context
})

serverPort.start()
client
ts
import { experimental_RPCLink as RPCLink } from '@orpc/client/message-port'

const link = new RPCLink({
  port: clientPort,
})

clientPort.start()

INFO

This only shows how to configure the link. For full client examples, see Client-Side Clients.

Released under the MIT License.