Skip to content

tryRoleMap

tryRoleMap(devices): RoleMapResult

Defined in: console-sdk/src/roleMap.ts:75

Builds a modality-keyed RoleAssignment from a device list, returning a RoleMapResult value instead of throwing (SDK_PLAN.md §3.6.5) — the shape a pre-flight UI wants: it can render the conflict and gate start() without exception handling. roleMap is the throwing companion for the ergonomic happy path.

Only metrics-producing consoles with a modality participate: any device whose modality is null is ignored, so a full useDevices() list can be passed through unfiltered. A session cannot contain two devices of the same modality, so a second console of an already-claimed modality yields { ok: false, conflict }.

readonly Device[]

Devices to assign — typically the fleet list; non-consoles are skipped.

RoleMapResult

{ ok: true, assignment }, or { ok: false, conflict } on a same-modality collision.

const result = tryRoleMap(useDevices({ connected: true }));
const canStart = result.ok;