Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/mobile/src/ext/flows/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hub } from "../hardware/hub";
import { onLetGo, proxyRunning } from "../hardware/proxy";

/**
* A flow running on the phone itself (docs/features/flows.md, "Running on the phone"; #321): a client names a flow and
* A flow running on the phone itself (docs/features/flows.md, "Running on the device"; #321): a client names a flow and
* the revision it saved; the proxy phone fetches exactly that and plays it on its own clock through its own
* connections, with the same player as the Studio. It keeps playing when the Studio goes away; it stops when the
* proxy lets go of its connections (switched off, or a pairing takes the radio).
Expand Down Expand Up @@ -56,11 +56,11 @@ async function run(id: string, revision: string, fromMs: number) {
} catch (e) {
if (mine !== gen) return;
log("warn", "run: flow not fetched", { flow: id, error: e });
set({ phase: "error", error: `The phone could not fetch the flow: ${e instanceof Error ? e.message : String(e)}` });
set({ phase: "error", error: `The device could not fetch the flow: ${e instanceof Error ? e.message : String(e)}` });
return;
}
if (mine !== gen) return;
if (!got) { set({ phase: "error", error: "The phone got another version of the flow than was saved; try again." }); return; }
if (!got) { set({ phase: "error", error: "The device got another version of the flow than was saved; try again." }); return; }
flow = got;
const from = Math.min(Math.max(0, fromMs), got.durationMs);
log("info", "run: playing", { flow: got.id, revision, from });
Expand Down
10 changes: 5 additions & 5 deletions apps/mobile/src/ext/flows/ui/FlowsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const secs = (ms: number) => `${(ms / 1000).toFixed(1)} s`;
const bodyOf = (f: FileRec): FlowBody => ({ ...emptyFlow(), ...(f.body as Partial<FlowBody>) });

/**
* Flows on the phone and tablet (docs/features/flows.md, "On the phone"): the project's flows, run on the phone itself
* Flows on the phone and tablet (docs/features/flows.md, "On the device"): the project's flows, run on the phone itself
* as on set (through the phone that holds the connections), and the Studio's flow editor in a web view, the one editor
* for every client.
*/
Expand Down Expand Up @@ -45,7 +45,7 @@ export function FlowsApp({ active }: { active: boolean }) {
return (
<Screen header={<Header title="Flows" sub={project?.name} actions={[{ icon: "plus", label: "New flow", onPress: () => void make() }]} />}>
<RunBanner run={run} />
{!state?.proxy && <Block><Hint>Running a flow needs a phone that holds the connections: switch its proxy on in Hardware.</Hint></Block>}
{!state?.proxy && <Block><Hint>Running a flow needs a device that holds the connections: switch its proxy on in Hardware.</Hint></Block>}
{flows === null ? <ActivityIndicator style={{ marginTop: 24 }} />
: !flows.length ? <Block><Empty icon="timeline" title="No flows yet" body="Tracks of lights and cameras, keyframes on them, played from here or the Studio." /><Button icon="plus" label="New flow" onPress={() => void make()} /></Block>
: flows.map((f) => { const b = bodyOf(f); return <ListRow key={f.id} icon="timeline" title={f.name} meta={`${secs(b.durationMs)} · ${b.tracks.length} track${b.tracks.length === 1 ? "" : "s"}${b.loop ? " · loops" : ""}${run?.flow === f.id && run.phase === "playing" ? " · running" : ""}`} onPress={() => setOpen(f.id)} />; })}
Expand All @@ -66,7 +66,7 @@ function RunBanner({ run }: { run: RunState | null }) {
);
}

/** One flow: what it drives, run it on the phone, open it in the editor. */
/** One flow: what it drives, run it on the device, open it in the editor. */
function FlowPage({ f, run, proxy, back, onEdit }: { f: FileRec; run: RunState | null; proxy: boolean; back: () => void; onEdit: () => void }) {
const s = useStyles();
const b = bodyOf(f);
Expand All @@ -76,8 +76,8 @@ function FlowPage({ f, run, proxy, back, onEdit }: { f: FileRec; run: RunState |
<Screen header={<Header title={f.name} sub={`Flow · ${secs(b.durationMs)}${b.loop ? " · loops" : ""}`} onBack={back} actions={[{ icon: "edit", label: "Edit the flow", onPress: onEdit }]} />}>
<RunBanner run={run} />
<Block>
<Button icon="play" label={runsThis ? "Running" : "Run on the phone"} disabled={!proxy || busy || !canCall()} onPress={() => request({ type: "run", flow: f.id, revision: f.updated_at, fromMs: 0 })} />
<Hint>{proxy ? "The phone that holds the connections plays it on its own clock, as on set; it keeps playing when the Studio closes." : "No phone holds the connections: switch the proxy on in Hardware."}</Hint>
<Button icon="play" label={runsThis ? "Running" : "Run on the device"} disabled={!proxy || busy || !canCall()} onPress={() => request({ type: "run", flow: f.id, revision: f.updated_at, fromMs: 0 })} />
<Hint>{proxy ? "The device that holds the connections plays it on its own clock, as on set; it keeps playing when the Studio closes." : "No device holds the connections: switch the proxy on in Hardware."}</Hint>
</Block>
<Block>
<SectionLabel>{`${b.tracks.length} track${b.tracks.length === 1 ? "" : "s"}`}</SectionLabel>
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/ext/hardware/bt/drivers/sidusMesh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ test("a Lightning strike goes out once, with the running effect's options", asyn
test("without the network's keys on this phone the connection is refused", async () => {
const { node } = setup();
const driver = sidusMesh({ access: () => ({ keysFor: () => null }) });
await assert.rejects(driver.open(node.link(), [mc("MC 3", 3)], () => {}), /keys are not on this phone/);
await assert.rejects(driver.open(node.link(), [mc("MC 3", 3)], () => {}), /keys are not on this device/);
});
4 changes: 2 additions & 2 deletions apps/mobile/src/ext/hardware/bt/drivers/sidusMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function sidusMesh(o: SidusOptions): Driver {
async open(link: Link, fixtures: Fixture[], sink: (id: string, t: Telemetry) => void): Promise<Session> {
const networkId = fixtures.find((f) => f.mesh)?.mesh?.networkId;
const net = networkId ? o.access()?.keysFor(networkId) : null;
if (!networkId || !net) throw new Error("this light's network keys are not on this phone, or another phone controls it (Setup → Lights → Key backup)");
if (!networkId || !net) throw new Error("this light's network keys are not on this device, or another device controls it (Setup → Lights → Key backup)");
const session = new MeshSession(link, net.keys, net.seq, { log: o.log, onIvIndex: net.onIvIndex, setupWaitMs: o.setupWaitMs });
await session.start();
const byUnicast = new Map(fixtures.filter((f) => f.mesh).map((f) => [f.mesh!.unicast, f]));
Expand Down Expand Up @@ -88,7 +88,7 @@ export function sidusMesh(o: SidusOptions): Driver {
});

const toLight = async (f: Fixture, payload: Uint8Array, times = repeats) => {
if (!f.mesh) throw new Error("this light is not on the phone's mesh");
if (!f.mesh) throw new Error("this light is not on the device's mesh");
for (let i = 0; i < times; i++) {
if (i) await wait(o.repeatGapMs ?? 40);
await session.send({ dst: f.mesh.unicast, access: bytes([TELINK_OPCODE], payload), key: app });
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/ext/hardware/meshNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const holderFor = (n: MeshNetwork) => (hasKeys(n.id) ? deviceId() : null);
/** 409: another phone holds the network now. Take the server's record, which says so, and stop pushing. */
async function lostTo409(n: MeshNetwork, err: unknown): Promise<boolean> {
if (!(err instanceof ApiError) || err.status !== 409) return false;
log("warn", "mesh network is in use on another phone", { network: n.id });
log("warn", "mesh network is in use on another device", { network: n.id });
try {
const server = (await meshApi.list()).find((x) => x.id === n.id);
if (server) adoptMeshNetwork(server);
Expand Down Expand Up @@ -163,7 +163,7 @@ export async function ensureNetwork(): Promise<MeshNetwork> {
/** Keep a provisioned light's device key, before anything else happens with it. */
export function rememberNode(networkId: string, unicast: number, devKey: Uint8Array, configured = false, info?: NodeInfo) {
const s = readSecrets(networkId);
if (!s) throw new Error("the network's keys are not on this phone");
if (!s) throw new Error("the network's keys are not on this device");
writeSecrets(networkId, { ...s, nodes: { ...s.nodes, [String(unicast)]: { devKey: hexOf(devKey), configured, info } } });
}

Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/src/ext/hardware/provisionFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export async function provisionFixture(f: Fixture, onStage: (s: Stage) => void,
if (!resume) {
onStage("find");
const found = await lookFor(f.address, 10_000);
if (found === "missing") throw new Error("The light was not found. Is it on and close to the phone?");
if (found === "missing") throw new Error("The light was not found. Is it on and close to the device?");
if (found === "provisioned") throw new Error("This light is still in another mesh network (Sidus Link). Remove it there (light settings → remove) or reset it on the light, then try again.");

const netKey = netKeyOf(network.id);
if (!netKey) throw new Error("The network's keys are not on this phone.");
if (!netKey) throw new Error("The network's keys are not on this device.");
const unicast = network.nextUnicast;
const link = await connect(f.address);
const io = await bearer(link);
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function provisionFixture(f: Fixture, onStage: (s: Stage) => void,
const keys = networkKeys(network);
const appKey = appKeyOf(network.id);
const devKey = keys?.devKeyOf(mesh.unicast);
if (!keys || !appKey || !devKey) throw new Error("The network's keys are not on this phone.");
if (!keys || !appKey || !devKey) throw new Error("The network's keys are not on this device.");
const link = await connectWithRetry(fixture.address, 5);
const session = new MeshSession(link, keys, seqFor(network.id), { log, onIvIndex: (iv) => { network = { ...network, ivIndex: iv }; void saveMeshNetwork(network); } });
try {
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/src/ext/hardware/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ async function startScan() {
scanStop?.();
scanFound = [];
sendScan("scanning");
if (!(await askBluetooth())) { sendScan("error", "Bluetooth permission denied on the phone: allow “Nearby devices” for OpenClapper."); return; }
if (!(await askBluetooth())) { sendScan("error", "Bluetooth permission denied on the device: allow “Nearby devices” for OpenClapper."); return; }
const adapter = await adapterState().catch(() => "unknown" as const);
if (adapter !== "on") { sendScan("error", adapter === "off" ? "Bluetooth is off on the phone." : `Bluetooth is not available on the phone (${adapter}).`); return; }
if (adapter !== "on") { sendScan("error", adapter === "off" ? "Bluetooth is off on the device." : `Bluetooth is not available on the device (${adapter}).`); return; }
log("info", "proxy: scan started");
const end = setTimeout(() => stopScan("done"), SCAN_MS);
const halt = scan(
Expand Down Expand Up @@ -156,7 +156,7 @@ async function provision(deviceId: string, fresh: boolean) {
await syncDevices();
const f = getFixtures().find((x) => x.id === deviceId);
const resume = !!f?.mesh && !fresh;
if (!f) { provisioning = false; state({ phase: "error", stage: null, resume, error: "The phone does not know this light yet; try again." }); return; }
if (!f) { provisioning = false; state({ phase: "error", stage: null, resume, error: "The device does not know this light yet; try again." }); return; }
pause();
let stage: HardwareProvision["stage"] = null;
try {
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/ext/hardware/ui/AddDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export function AddDevice({ back, opened }: { back: () => void; opened: (id: str
return (
<Screen header={<Header title="Add a device" onBack={back} />}>
<Block>
{!proxy && <Banner kind="info" title="No proxy" meta="Scanning runs on the phone that holds the connections: switch the proxy on in Hardware." />}
{!proxy && <Banner kind="info" title="No proxy" meta="Scanning runs on the device that holds the connections: switch the proxy on in Hardware." />}
{scan?.phase === "error" && <Banner kind="danger" title={scan.message ?? "Scan failed"} />}
<SectionLabel>{scan?.phase === "scanning" ? "Looking for devices…" : "Found nearby"}</SectionLabel>
{!scan?.found.length && <Empty icon="bluetooth" title={scan?.phase === "scanning" ? "Looking…" : "Nothing found"} body="Switch the device on and keep it close to the phone." />}
{!scan?.found.length && <Empty icon="bluetooth" title={scan?.phase === "scanning" ? "Looking…" : "Nothing found"} body="Switch the device on and keep it close to the device." />}
{scan?.found.map((f) => (
<ListRow key={f.address} icon={f.kinds.length ? TYPE_LOOK[modelOf(f.kinds[0])!.type].icon : "bluetooth"} title={f.name ?? f.address}
meta={[f.kinds.length ? `Likely ${modelName(modelOf(f.kinds[0])!)}` : null, f.address, f.rssi !== null ? `${f.rssi} dBm` : null].filter(Boolean).join(" · ")} onPress={() => setPicked(f)} />
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/ext/hardware/ui/CameraSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function HardwareSheet({ onClose }: { onClose: () => void }) {
const d = open ? devices.find((x) => x.id === open) : undefined;
if (d) return <Sheet visible title={d.name} onClose={() => setOpen(null)} height={0.9} scroll={false}><DeviceScreen d={d} back={() => setOpen(null)} /></Sheet>;
return (
<Sheet visible title="Hardware" sub={started.current ? "This phone holds the connections while this is open" : state?.proxy ? `Through ${state.phone.name || "the proxy phone"}` : undefined} onClose={onClose} height={0.75}>
<Sheet visible title="Hardware" sub={started.current ? "This device holds the connections while this is open" : state?.proxy ? `Through ${state.phone.name || "the proxy device"}` : undefined} onClose={onClose} height={0.75}>
{!devices.length && <Empty icon="light-fixture" title="No devices yet" body="Add them in the Hardware app." />}
{devices.map((x) => <Card key={x.id} d={x} all={devices} live={live} proxy={!!state?.proxy} onOpen={() => setOpen(x.id)} />)}
<Hint>The full list, adding devices and the key backup are in the Hardware app.</Hint>
Expand Down
8 changes: 4 additions & 4 deletions apps/mobile/src/ext/hardware/ui/Device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function DeviceScreen({ d, back }: { d: HardwareDevice; back: () => void
const rename = () => { const to = name?.trim(); setName(null); if (to && to !== d.name) void renameDevice(d, to).then(() => request({ type: "sync" }), () => toast("Not renamed: the server is not reachable", "danger")); };
const remove = async () => {
const mesh = m.transport === "mesh" && d.body.mesh;
if (!(await confirm({ title: `Remove “${d.name}”?`, body: mesh ? "It goes to the recycle bin. The light keeps the phone's network keys until it is reset on the light itself." : "It goes to the recycle bin.", confirmLabel: "Remove", danger: true }))) return;
if (!(await confirm({ title: `Remove “${d.name}”?`, body: mesh ? "It goes to the recycle bin. The light keeps the device's network keys until it is reset on the light itself." : "It goes to the recycle bin.", confirmLabel: "Remove", danger: true }))) return;
try { await removeDevice(d); request({ type: "sync" }); back(); } catch { toast("Not removed: the server is not reachable", "danger"); }
};
const pickPower = (battery: string | null) => { setPowerOpen(false); void setPower(d.id, battery).then(() => request({ type: "sync" }), () => toast("Not changed: the server is not reachable", "danger")); };
Expand All @@ -48,8 +48,8 @@ export function DeviceScreen({ d, back }: { d: HardwareDevice; back: () => void
<Block>
<View style={{ flexDirection: "row", gap: 12, alignItems: "center" }}><TypeTag kind={m.type} /><LinkMark tone={link.tone} label={link.label} /></View>
{charge.charge !== undefined || charge.from ? <Row label={charge.from ? `Battery (${charge.from})` : "Battery"}><BatteryBar charge={charge.charge} minutes={charge.minutes} /></Row> : null}
{!state?.proxy && m.transport !== "wifi" && <Hint>No phone holds the connections: switch the proxy on in Hardware, on this phone or another.</Hint>}
{m.type === "camera" && !ready && <Hint>First connection: the camera shows a 6-digit PIN in its Bluetooth menu; type it into the pairing dialog on the proxy phone. Bluetooth must be on in the camera's Setup menu.</Hint>}
{!state?.proxy && m.transport !== "wifi" && <Hint>No device holds the connections: switch the proxy on in Hardware, on this device or another.</Hint>}
{m.type === "camera" && !ready && <Hint>First connection: the camera shows a 6-digit PIN in its Bluetooth menu; type it into the pairing dialog on the proxy device. Bluetooth must be on in the camera's Setup menu.</Hint>}
</Block>

{m.feeds.map((f) => <Block key={f.id}><SectionLabel>{f.label}</SectionLabel><PictureHost /></Block>)}
Expand All @@ -58,7 +58,7 @@ export function DeviceScreen({ d, back }: { d: HardwareDevice; back: () => void
<Block>
<SectionLabel>Pairing</SectionLabel>
{prov && <Banner kind={prov.phase === "error" ? "danger" : prov.phase === "done" ? "ok" : "info"} title={prov.phase === "error" ? prov.error ?? "Pairing failed" : prov.phase === "done" ? "Paired" : prov.stage ? PROVISION_STAGE_LABELS[prov.stage] : "Starting…"} />}
{!d.body.mesh && <Hint>Not paired with this phone's network yet. Remove the light from Sidus Link first, or reset it.</Hint>}
{!d.body.mesh && <Hint>Not paired with this device's network yet. Remove the light from Sidus Link first, or reset it.</Hint>}
<Button kind={d.body.mesh ? "secondary" : "primary"} icon="bluetooth" label={d.body.mesh ? "Run setup again" : "Pair with OpenClapper"} disabled={!state?.proxy || !online || prov?.phase === "running"} onPress={() => request({ type: "provision", device: d.id })} />
{d.body.mesh && <Button kind="secondary" icon="refresh" label="Pair again (after a reset)" disabled={!state?.proxy || !online || prov?.phase === "running"} onPress={() => request({ type: "provision", device: d.id, fresh: true })} />}
</Block>
Expand Down
Loading
Loading