Przejdź do treści
Biblioteka skilli
Programowanie · Integracja z narzędziem

driving-surface-mapper-over-websocket

/driving-surface-mapper-over-websocket

Czyta i zmienia źródło Surface Mapper spoza docku przez obs-websocket i CallVendorRequest, także przy zdarzeniach zmian i błędach SetMapping.

Repozytorium
surface-mapper ↗
Licencja
LGPL
Ostatnia zmiana repozytorium
10.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 10.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

LGPL, otwarta.

Co robi i kiedy

Czyta i zmienia źródło Surface Mapper spoza docku przez obs-websocket i CallVendorRequest, także przy zdarzeniach zmian i błędach SetMapping.

Wyzwalacze z opisu

surface-mapper
Oryginalny opis (EN)

Use when a script, agent or app needs to read or change a Surface Mapper Mapping source from outside the dock — calling CallVendorRequest with vendor "surface-mapper", creating a Mapping source over obs-websocket, listening for MappingChanged / OverlayChanged, a SetMapping that returns ok:false, a mapping that was sent but the output looks unchanged, or Program showing only part (e.g. a quarter) of a mapping that looks correct in a source screenshot.

Jak działa

  1. Overview
  2. Connecting
  3. Vendor requests
  4. Events
  5. Creating a Mapping source
  6. Checking the result
  7. Safety around a live setup
  8. Common mistakes
Sekcje z nagłówków SKILL.md, w oryginale · 141 linii, 1 142 słów
Podgląd SKILL.md
---
name: driving-surface-mapper-over-websocket
description: Use when a script, agent or app needs to read or change a Surface Mapper Mapping source from outside the dock — calling CallVendorRequest with vendor "surface-mapper", creating a Mapping source over obs-websocket, listening for MappingChanged / OverlayChanged, a SetMapping that returns ok:false, a mapping that was sent but the output looks unchanged, or Program showing only part (e.g. a quarter) of a mapping that looks correct in a source screenshot.
---

# Driving Surface Mapper over obs-websocket

## Overview

Surface Mapper exposes one obs-websocket **vendor** named `surface-mapper`. Everything the dock does — list Mapping sources, read a mapping, replace it, toggle the editing overlay — goes through four vendor requests. Payloads that are JSON documents travel as **strings** (`mappingJson`, `selectionJson`), not objects.

For the content of `mappingJson` see `writing-mapping-json`. For building a mapping from an LED chart see `mapping-led-pixel-maps`.

## Connecting

- URL and password come from OBS: **Tools > WebSocket Server Settings** (enable the server; default port `4455`). The dock's default URL is `ws://127.0.0.1:4455`. Ask the user for the password — never guess or brute-force it.
- obs-websocket close code `4009` = authentication failed (the dock treats it as non-retryable).
- With `obs-websocket-js` loaded via dynamic `import()` in some Node/ESM setups, the class can end up nested: use `const OBSWebSocket = mod.default?.default ?? mod.default;`.

```typescript
const obs = new OBSWebSocket();
await obs.connect("ws://127.0.0.1:4455", password || undefined);

const call = async (requestType: string, requestData: Record<string, unknown>) => {
  const res = await obs.call("CallVendorRequest", {
    vendorName: "surface-mapper",
    requestType,
    requestData,
  });
  return res.responseData; // { ok: true, ... } | { ok: false, error: string }
};
```

The plugin's reply is in `responseData`. Always check `ok` — a failed vendor request is still a successful obs-websocket call.

## Vendor requests

| Request | `requestData` | `responseData` on success |
|---|---|---|
| `ListMappingSources` | `{}` | `{ ok: true, sources: [{ name, width, height }] }` |
| `GetMapping` | `{ sourceName }` | `{ ok: true, mappingJson, overlayEnabled }` |
| `SetMapping` | `{ sourceName, mappingJson, requestId? }` | `{ ok: true }` |
| `SetOverlay` | `{ sourceName, enabled?, selectionJson? }` | `{ ok: true }` |

Failures are `{ ok: false, error }` with `error` one of:

| `error` | Cause |
|---|---|
| `source not found: <name>` | No OBS source with that name |
| `not a mapping source: <name>` | Source exists but is not a Mapping source |
| `mappingJson: missing` | `SetMapping` without `mappingJson` |
| `<json path>: <reason>` | Mapping validation failed, e.g. `surfaces[2].corners: expected 4 points` |
| `json: <parser message>` | `mappingJson` is not valid JSON |
| `selectionJson: <reason>` | `SetOverlay` selection could not be parsed |

`width` / `height` in `ListMappingSources` are the mapping's `canvas` size — the Mapping source's output size **is** its canvas.

### SetMapping replaces everything

`SetMapping` swaps in the whole document; there is no patch. The safe edit loop is:

1. `GetMapping` → `JSON.parse(mappingJson)` (the plugin returns canonical v2).
2. Change what you need.
3. `SetMapping` with `JSON.stringify(...)`.
4. On `ok: false`, nothing was applied — fix the path named in `error` and resend.

A successful `SetMapping` is persisted into the source's settings (and so into the scene collection).

### SetOverlay

- `enabled` omitted → the current on/off flag is kept; only the selection changes.
- `selectionJson` omitted → empty selection. Shape: `{"selectedSurfaceIds": string[], "selectedCorner": {"surfaceId": string, "index": 0..3} | null}` (both keys optional).
- **The overlay is drawn into the Mapping source's output, so it appears on stream/recording.** Turn it off (`enabled: false`) before going live. It is always off after OBS starts.

## Events

Subscribe to obs-websocket `VendorEvent` and filter `vendorName === "surface-mapper"`.

| `eventType` | `eventData` | Fires when |
|---|---|---|
| `MappingChanged` | `{ sourceName, mappingJson, overlayEnabled, requestId? }` | The mapping changed (any path), or a `SetMapping` carried a `requestId` even if nothing changed |
| `OverlayChanged` | `{ sourceName, enabled }` | Overlay on/off flipped, via `SetOverlay` or the properties checkbox |

`requestId`: pass any non-empty string to `SetMapping`; the `MappingChanged` it causes carries the same id, so a client can recognise its own echo. Empty strings and non-string values count as "no id". A rejected `SetMapping` emits nothing. `mappingJson` in the event is the value at emit time and can include another client's concurrent edit.

## Creating a Mapping source

The input kind is `surface_mapper_source`. A new source starts with a 1920×1080 canvas and no surfaces.

```typescript
await obs.call("CreateInput", {
  sceneName: "Mapping",           // the scene the user names
  inputName: "LED Wall",
  inputKind: "surface_mapper_source",
});
const r = await call("SetMapping", { sourceName: "LED Wall", mappingJson });
```

Find existing ones with `ListMappingSources`, or `GetInputList` filtered by `inputKind === "surface_mapper_source"`.

Do **not** write the mapping through `CreateInput`'s `inputSettings.mapping_json` or `SetInputSettings`: that path only logs a warning on invalid JSON and keeps the old mapping, so the client never sees the error. Create the source, then `SetMapping`.

## Checking the result

`GetSourceScreenshot` on the Mapping source shows what it renders:

```typescript
const { imageData } = await obs.call("GetSourceScreenshot", {
  sourceName: "LED Wall", imageFormat: "png", imageWidth: 1920,
});
```

A screenshot of the **source** says nothing about how its **scene item** is placed. Check that too.

### Pitfall: the scene item is scaled

A Mapping source's size follows its canvas. A scene item added (or left) with a transform from an earlier size can end up scaled — e.g. scale 2 on a canvas-sized source, so Program shows only the top-left quarter while the source screenshot looks perfect.

When the canvas equals OBS's base resolution (`GetVideoSettings` → `baseWidth` / `baseHeight`):

1. `GetSceneItemId { sceneName, sourceName }` → `sceneItemId`.
2. `GetSceneItemTransform` → expect `scaleX = scaleY = 1`, `positionX = positionY = 0`, no bounds, no crop.
3. If not, `SetSceneItemTransform { sceneItemTransform: { scaleX: 1, scaleY: 1, positionX: 0, positionY: 0 } }` (and reset bounds/crop if set).

Re-check after any `SetMapping` that changes `canvas`.

## Safety around a live setup

- Before anything disruptive (creating/removing inputs, changing canvas, switching scenes), check `GetStreamStatus` / `GetRecordStatus` → `outputActive`. If live, ask first.
- Switching scene collections replaces the user's whole live setup. Work in the collection the user names; do not switch to "a clean one" on your own.
- Do not rename sources the mapping references: a rename inside OBS is followed automatically, but an external delete is not, and that surface just stops drawing.

## Common mistakes

| Mistake | Reality |
|---|---|
| Sending `mappingJson` as an object | It must be a JSON **string** (`JSON.stringify`) |
| Reading the reply from the top level | The plugin's reply is `res.responseData` |
| Treating a resolved `call` as success | Check `responseData.ok`; validation errors come back as `ok: false` |
| Sending only the changed surface | `SetMapping` replaces the whole mapping — always send the full document |
| `SetInputSettings({ mapping_json })` to apply a mapping | Invalid JSON is silently ignored there; use `SetMapping` |
| Waiting for `MappingChanged` after a no-op `SetMapping` without `requestId` | No change and no id → no event |
| Verifying only with a source screenshot | Also check the scene item transform; scale ≠ 1 crops Program |
| Leaving the overlay on | It is burned into the output, including stream and recording |

Wersje

W bazie nie ma innych skilli o nazwie driving-surface-mapper-over-websocket.

Migawka bazy z 13.11.2026 · wersja paczki 583e5fece407 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 88upgrading-from-0-6
    Pomaga przejść z obs-mapping 0.6 na Surface Mapper 0.7 i naprawić źródła Mapping, które po aktualizacji pokazują błąd lub znikają.
  • 100writing-mapping-json
    Pisze, sprawdza i naprawia pliki mapowania JSON w wersji 2 dla Surface Mappera, z powierzchniami, przycinaniem i warstwami.
  • 100obs-docs
    Wyszukuje i pobiera oficjalną dokumentację OBS Studio (docs.obsproject.com, wiki instalacji, szablon wtyczki, protokół obs-websocket) przy pytaniach o API i tworzenie wtyczek.
  • 98obs-recording
    Zarządza sesjami nagrywania przez OBS i obs-mcp (OBS WebSocket): start i stop nagrania, przełączanie scen, poziomy audio i weryfikacja plików, przy sesjach wsadowych.
  • 100mapperly
    Prowadzi przez Mapperly, mapper obiektów generowany w czasie kompilacji: mapowanie wydajne i bez refleksji, walidacja mapowań przy kompilacji, zgodność z AOT oraz mapowanie enumów i kolekcji.
  • 100obs-plugins
    Pomaga tworzyć wtyczki OBS w C++ z obs-plugintemplate (CMake, CI na GitHub Actions), rejestrować źródła, wyjścia i enkodery oraz instalować popularne wtyczki społeczności.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.