Developer
On this page

Relay API

Send peer-to-peer messages between applet instances over the RightPlace relay channel.

ctx.sdk.relay sends peer-to-peer messages over the RightPlace relay infrastructure. Use it to coordinate between applet instances across devices: presence, cursors, live sync hints, and other real-time signals.

Scope required: relay:channel

Usage

Inside a method run, reach the surface via ctx.sdk.relay. Send a JSON-serializable payload to a named channel.

import { defineMethod } from "@rightplace/applet-sdk/v2";

export const ping = defineMethod({
  name: "@wiredwp/collab.ping",
  async run(_params, ctx) {
    await ctx.sdk.relay.send("channel-name", { type: "ping", data: {} });
  },
});

The first argument is the channel name. The second is any JSON-serializable value, sent to peers connected on that channel through the relay infrastructure.

Notes

  • Declare relay:channel in applet.json::scopes[].
  • The relay is for peer-to-peer, pub/sub style signals between applet instances, not request and response. For external request and response traffic use the HTTP API, and for a single long-lived external stream use the WebSocket API.