Loading Patchies...

P2P Messaging

Use netsend and netrecv to send and receive messages over peer-to-peer WebRTC connections.

Room Configuration

When you create a netsend or netrecv object, Patchies adds a room parameter to the URL. Users need the same ?room= parameter to connect.

  • Remove the room parameter from the URL to create a different room.
  • Set a room manually with Ctrl/Cmd + K > Set room for netsend/netrecv.
  • Share a room with "Share Link" or Ctrl/Cmd + K > Share Patch Link. Patchies adds the room to the shared link.

How It Works

Patchies uses Trystero and WebRTC. Public relay servers help peers find each other. No central server stores messages.

Node.js and Bun Integration

Use Trystero to send and receive messages from Node.js or Bun scripts. Use an RTC polyfill such as node-datachannel/polyfill or werift.

OSC Bridge Example

Route messages from netsend osc to a local OSC server:

import { joinRoom } from "trystero";
import { Client } from "node-osc";
import { RTCPeerConnection } from "node-datachannel/polyfill";

const appId = "patchies";
const roomId = "f84df292-3811-4d9b-be54-ce024d4ae1c0"; // your room id!

const room = joinRoom({ appId, rtcPolyfill: RTCPeerConnection }, roomId);
const [netsend, netrecv] = room.makeAction("osc");
const osc = new Client("127.0.0.1", 3333);

room.onPeerJoin((peerId) => console.log("peer joined:", peerId));
room.onPeerLeave((peerId) => console.log("peer left:", peerId));

netrecv((data) => {
  const { address, args } = data;

  osc.send(address, ...args, (err) => {
    if (err) console.error(err);
    netsend("osc sent!");
    osc.close();
  });
});

ArtNet DMX Bridge Example

Control DMX-enabled equipment with netsend dmx:

import { joinRoom } from "trystero";
import { RTCPeerConnection } from "node-datachannel/polyfill";
import dmxlib from "dmxnet";

const appId = "patchies";
const roomId = "f84df292-3811-4d9b-be54-ce024d4ae1c0"; // your room id!

const room = joinRoom({ appId, rtcPolyfill: RTCPeerConnection }, roomId);

room.onPeerJoin((peerId) => console.log("peer joined:", peerId));
room.onPeerLeave((peerId) => console.log("peer left:", peerId));

const [netsend, netrecv] = room.makeAction("dmx");

const dmxnet = new dmxlib.dmxnet({});
const sender = dmxnet.newSender({
  ip: "127.0.0.1",
  subnet: 0,
  universe: 0,
  port: 6454,
});

netrecv((data, peerId) => {
  if (Array.isArray(data)) {
    for (let frame of data) {
      sender.prepChannel(frame.channel, frame.value);
    }

    sender.transmit();
  }
});

See Also

  • netsend — Send network messages.
  • netrecv — Receive network messages.
  • mqtt — Send and receive MQTT messages.