Skip to content

Latest commit

 

History

History
96 lines (74 loc) · 2.45 KB

README.md

File metadata and controls

96 lines (74 loc) · 2.45 KB

MCC.js Guide

Public API

The package exports two client layers:

  • MccClient
    • typed high-level command methods
    • typed event subscriptions
    • reconnect policy
    • plain-text chat and serialized MCC slash-command support
  • MccProtocolClient
    • raw WebSocket transport lifecycle
    • raw frame and envelope events
    • explicit sendCommand() and sendPlainText() primitives

Key helpers and types:

  • createMccUrl(host = "127.0.0.1", port = 8043, secure = false)
  • commandDefinitions
  • KNOWN_PROTOCOL_EVENT_NAMES
  • protocol/event payload types from the package root

Basic Connection

import { MccClient, createMccUrl } from "mcc.js";

const client = new MccClient({
  url: createMccUrl(),
  password: "CHANGE_THIS_PASSWORD",
  reconnect: { attempts: 3, delayMs: 1_000 },
});

client.on("ready", () => {
  console.log("ready");
});

client.on("OnChatRaw", ({ text }) => {
  console.log(text);
});

await client.connect();

Event Model

Use on(), once(), or waitFor() with typed event names:

const [payload] = await client.waitFor("OnMccCommandResponse", {
  timeoutMs: 5_000,
});

Forward-compatible hooks are available on the low-level client:

  • rawFrameSent
  • rawFrameReceived
  • rawEnvelope
  • rawProtocolEvent
  • unknownProtocolEvent
  • parsingError

Plain Text vs Protocol Commands

  • client.sendChat("hello")
    • sends plain text over the socket
    • MCC forwards it to in-game chat
  • client.sendMccCommand("help")
    • sends /help
    • waits for OnMccCommandResponse
    • serialized internally because the protocol does not include a request ID for plain-text MCC commands
  • client.protocolClient.sendCommand("GetUsername")
    • raw protocol command path
    • resolves from OnWsCommandResponse

Runtime Caveats

  • The WebSocket endpoint is the root path, not /mcc.
  • OnWsCommandResponse returns message, not result.
  • The workspace copy of WebSocketBot.cs includes a session-routing fix for ChangeSessionId, and MccClient.connect() applies sessionId after authentication when provided.
  • If you connect this SDK to an older unpatched WebSocketBot.cs, session renaming may still fail there.
  • Browser packaging is present, but browser execution testing is intentionally deferred in this pass.

Validation Commands

npm run lint
npm test
npm run build
npm run test:runtime:node
npm run test:runtime:bun
npm run test:runtime:deno
MCC_WS_PASSWORD=CHANGE_THIS_PASSWORD npm run integration:local