zRuvixDiscord presence API

WebSocket

Subscribe to realtime presence updates over a WebSocket gateway.

WSS /socket

Append ?compression=zlib_json to receive zlib-compressed frames.

Handshake

On connect you receive Opcode 1: Hello with a heartbeat_interval. Send Opcode 2: Initialize immediately, then Opcode 3: Heartbeat on the interval.

OpcodeNameDirection
0Event (INIT_STATE, PRESENCE_UPDATE)Receive
1HelloReceive
2InitializeSend
3HeartbeatSend
4UnsubscribeSend

Subscribing

// Opcode 2 — subscribe to one, many, or all
{ "op": 2, "d": { "subscribe_to_id": "94490510688792576" } }
{ "op": 2, "d": { "subscribe_to_ids": ["id1", "id2"] } }
{ "op": 2, "d": { "subscribe_to_all": true } }

Minimal client

const ws = new WebSocket('wss://api.zruvix.com/socket');

ws.onmessage = ({ data }) => {
  const { op, d } = JSON.parse(data);

  if (op === 1) {
    // Hello — subscribe, then start heartbeating.
    ws.send(JSON.stringify({ op: 2, d: { subscribe_to_id: '94490510688792576' } }));
    setInterval(() => ws.send(JSON.stringify({ op: 3 })), d.heartbeat_interval);
  }

  if (op === 0) {
    // INIT_STATE or PRESENCE_UPDATE
    console.log(d);
  }
};

On this page