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.
Run it
Section titled “Run it”cd example-connectornpm installCreate a .env file:
INARI_URL=ws://localhost:3030/wsINARI_API_KEY=MySuperApiKeyINARI_CHANNEL=defaultStart Inari with the same API_KEY, then:
npm startYou 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.
Simulate players
Section titled “Simulate players”Players come from src/data.json, re-read at each sync, so you can edit it while the connector runs:
[ { "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] }]- Open
http://localhost:3030/?channel=default&code=user11in a browser. - Open
http://localhost:3030/?channel=default&code=user22in another one (or a private window). - Move
positionof one player indata.jsonand watch the voice get quieter, then disappear beyondMAX_DISTANCE. - Set
is_force_mutedtotrue, or give them a differentgroup, to see them silenced.
How it works
Section titled “How it works”src/main.ts is about 70 lines:
call(kind, data)sends a message with a freshtransaction_uuidand returns a promise resolved when the response with the same UUID arrives.- On
open, it sendsauthwithis_connector: true. Anerrorresponse closes the connection. - Once authenticated,
setIntervalcallssync_connector_stateevery 300 ms with the players, and logs the returnedconnections. - 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.
Port it to your game
Section titled “Port it to your game”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.