From a750644c2020dc281ea7764d3fe694c445d3c6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 9 Nov 2023 13:52:00 +0100 Subject: [PATCH] updates socket.ts (renames and add method) --- frontend/src/socket.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/socket.ts b/frontend/src/socket.ts index 22f1486..9e9de6f 100644 --- a/frontend/src/socket.ts +++ b/frontend/src/socket.ts @@ -9,15 +9,28 @@ console.debug('Websocket: ', URL); export const socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] }); -export const emit_update = ( +export const setAttribute = ( name: string, parentPath: string, value: unknown, callback?: (ack: unknown) => void ) => { if (callback) { - socket.emit('frontend_update', { name, parent_path: parentPath, value }, callback); + socket.emit('set_attribute', { name, parent_path: parentPath, value }, callback); } else { - socket.emit('frontend_update', { name, parent_path: parentPath, value }); + socket.emit('set_attribute', { name, parent_path: parentPath, value }); + } +}; + +export const runMethod = ( + name: string, + parentPath: string, + kwargs: Record, + callback?: (ack: unknown) => void +) => { + if (callback) { + socket.emit('run_method', { name, parent_path: parentPath, kwargs }, callback); + } else { + socket.emit('run_method', { name, parent_path: parentPath, kwargs }); } };