Skip to content

Quickstart

Package@consenger/[email protected]
Protocolcompanion.plugin.v1
RuntimeVifu Web iframe
StatusPublic alpha

This guide adds companion integration to a static browser game. The game still runs without Vifu, but companion features become active when the Vifu host initializes the bridge.

Install

bash
npm install @consenger/[email protected]

For static games without a bundler, copy the browser bundle from the package:

txt
node_modules/@consenger/companion-sdk/dist/browser/companion-sdk.js

Add the SDK

html
<script src="./companion-sdk.js"></script>
<script>
  const companion = window.Consenger.companion;
</script>

Bundled games can import the module:

ts
import { createCompanionSDK } from "@consenger/companion-sdk";

const companion = createCompanionSDK({ transport: "auto" });

Register game state

ts
companion.context("question.current", {
  description: "Current question shown to the player",
  read: () => ({
    id: "q-1",
    prompt: "Choose the Japanese word for water.",
    choices: ["みず", "ねこ", "そら"]
  })
});

Register a command

ts
companion.command("question.hint", {
  title: "Show a hint",
  inputSchema: { type: "object", properties: {}, additionalProperties: false },
  handler: () => {
    showHint();
    return { ok: true };
  }
});

Report observations

ts
companion.observe("answer.wrong", { questionId: "q-1" }, {
  context: "question.current"
});

Declare the capability

json
{
  "name": "water-quest",
  "entry": "index.html",
  "capabilities": ["companion.plugin.v1"]
}

Verify

ts
console.log(companion.status());

hostConnected should become true after the game is loaded by Vifu. In a plain local browser tab, it can remain false; the game should still be playable.