Developers
Get started

Get started

Installation

npm install @nymproject/mix-websocket

ESM only, with the worker and WASM inlined via mix-tunnel; no bundler config needed.

Quick start

Echo against wss://echo.websocket.org, the same endpoint the smolmix dev tool uses:

import { setupMixTunnel, MixWebSocket } from '@nymproject/mix-websocket';
 
await setupMixTunnel();
 
const ws = new MixWebSocket('wss://echo.websocket.org');
 
ws.addEventListener('open', () => {
  console.log('connected');
  ws.send('hello mixnet');
});
 
ws.addEventListener('message', (e) => {
  console.log('received:', e.data);
  ws.close();
});
 
ws.addEventListener('close', () => console.log('closed'));
ws.addEventListener('error', (e) => console.error('error:', e));

Or await on the upgrade instead of subscribing to the open event:

const ws = new MixWebSocket('wss://echo.websocket.org');
await ws.opened();
ws.send('hello mixnet');

Open a MixWebSocket live in the mixnet playground, which echoes messages and runs an echo burst over the live mixnet.