diff --git a/core/src/ws/index.ts b/core/src/ws/index.ts index e54ea92bd..c12535404 100644 --- a/core/src/ws/index.ts +++ b/core/src/ws/index.ts @@ -3,10 +3,11 @@ import fp from "fastify-plugin"; import fastifyWebsocket from "fastify-websocket"; import { createObservable } from "@monitor/util"; import handleMessage from "./messages"; +import { Action } from "@monitor/types"; declare module "fastify" { interface FastifyInstance { - broadcast: (message: object) => void; + broadcast: (type: string, message: MessageType) => void; } } @@ -15,7 +16,13 @@ const ws = fp((app: FastifyInstance, _: {}, done: () => void) => { const messages = createObservable(); - app.decorate("broadcast", (msg: object) => messages.publish(msg)); + app.decorate( + "broadcast", + (type: string, msg: Action & MessageType) => { + msg.type = type; + messages.publish(msg); + } + ); app.get("/ws", { websocket: true, onRequest: [app.auth] }, (connection) => { const unsub = messages.subscribe((msg) => connection.socket.send(msg)); diff --git a/types/types.d.ts b/types/types.d.ts index e753b807a..b349bdb3a 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -17,6 +17,10 @@ export type User = { avatar?: string; }; +export type Action = { + type: string; +}; + export type Log = { stdout?: string; stderr?: string; @@ -93,7 +97,7 @@ export type Conversion = { export interface Volume extends Conversion { useSystemRoot?: boolean; -}; +} export type EnvironmentVar = { variable: string;