action types

This commit is contained in:
mbecker20
2022-03-13 22:37:22 -07:00
parent 0a80f83cc8
commit 37c2f6a203
2 changed files with 14 additions and 3 deletions
+9 -2
View File
@@ -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: <MessageType>(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",
<MessageType>(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));
+5 -1
View File
@@ -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;