Skip to content
File

Blob: worker/src/server/routes/device.ts

typescript25 lines
1import { Hono } from 'hono';
2import {
3 deviceHeartbeatSchema,
4 deviceStartSchema,
5 generationSchema,
6} from '@/shared/contracts/signaling.ts';
7import type { HttpApp } from '@/server/http.ts';
8import { input, result, room } from './context.ts';
9 
10const app = new Hono<HttpApp>();
11app.post('/start', async (c) =>
12 result(c, await room(c).startDevice(await input(c, deviceStartSchema))),
13);
14app.post('/channels', async (c) =>
15 result(c, await room(c).createDeviceChannels((await input(c, generationSchema)).generation)),
16);
17app.post('/ready', async (c) =>
18 result(c, await room(c).deviceReady((await input(c, generationSchema)).generation)),
19);
20app.post('/heartbeat', async (c) =>
21 result(c, await room(c).deviceHeartbeat(await input(c, deviceHeartbeatSchema))),
22);
23 
24export default app;