Skip to content

Example connector

The repository contains example-connector/, a small Node.js and TypeScript program. It reads fake players from a JSON file and syncs them with Inari, which makes it a handy way to test an installation or to learn the protocol before writing a real connector.

Terminal window
cd example-connector
npm install

Create a .env file:

example-connector/.env
INARI_URL=ws://localhost:3030/ws
INARI_API_KEY=MySuperApiKey
INARI_CHANNEL=default

Start Inari with the same API_KEY, then:

Terminal window
npm start

You should see:

WS > Connection Open !
Welcome on Inari 1.0.0. Max Distance set to 20 !

If you get Authentification Error, the API key does not match.

Players come from src/data.json, re-read at each sync, so you can edit it while the connector runs:

example-connector/src/data.json
[
{
"code": "user11",
"display_name": "User 11",
"is_force_muted": false,
"position": [0, 0, 0],
"head": [1, 0, 0]
},
{
"code": "user22",
"display_name": "User 22",
"is_force_muted": false,
"position": [0, 0, 0],
"head": [1, 0, 0]
}
]
  1. Open http://localhost:3030/?channel=default&code=user11 in a browser.
  2. Open http://localhost:3030/?channel=default&code=user22 in another one (or a private window).
  3. Move position of one player in data.json and watch the voice get quieter, then disappear beyond MAX_DISTANCE.
  4. Set is_force_muted to true, or give them a different group, to see them silenced.

src/main.ts is about 70 lines:

  • call(kind, data) sends a message with a fresh transaction_uuid and returns a promise resolved when the response with the same UUID arrives.
  • On open, it sends auth with is_connector: true. An error response closes the connection.
  • Once authenticated, setInterval calls sync_connector_state every 300 ms with the players, and logs the returned connections.
  • When the socket closes, the process exits, so a supervisor (systemd, Docker, pm2) can restart it.

src/type.d.ts holds the TypeScript types of all messages. Copy it into your own project.

Replace the data.json read with your game’s player list. Keep the rest: authentication, a regular sync, and reconnection. The same protocol works from any language with a WebSocket client (Java for Minecraft plugins, Lua, C#…). See the protocol reference.