From 2eb996b3827bfbe1696b0aeb7d9afc4319556795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 27 Mar 2024 09:31:06 +0100 Subject: [PATCH] updates frontend socket to use new sio events --- frontend/src/socket.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/src/socket.ts b/frontend/src/socket.ts index 9e9de6f..2e3fafb 100644 --- a/frontend/src/socket.ts +++ b/frontend/src/socket.ts @@ -1,4 +1,5 @@ import { io } from 'socket.io-client'; +import { SerializedValue } from './components/GenericComponent'; export const hostname = process.env.NODE_ENV === 'development' ? `localhost` : window.location.hostname; @@ -9,28 +10,27 @@ console.debug('Websocket: ', URL); export const socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] }); -export const setAttribute = ( - name: string, - parentPath: string, - value: unknown, +export const updateValue = ( + serializedObject: SerializedValue, callback?: (ack: unknown) => void ) => { if (callback) { - socket.emit('set_attribute', { name, parent_path: parentPath, value }, callback); + socket.emit('update_value', { value: serializedObject }, callback); } else { - socket.emit('set_attribute', { name, parent_path: parentPath, value }); + socket.emit('update_value', { value: serializedObject }); } }; export const runMethod = ( - name: string, - parentPath: string, - kwargs: Record, + accessPath: string, + args: unknown[] = [], + kwargs: Record = {}, callback?: (ack: unknown) => void ) => { + // TODO: serialize args and kwargs before passing to trigger_method if (callback) { - socket.emit('run_method', { name, parent_path: parentPath, kwargs }, callback); + socket.emit('trigger_method', { access_path: accessPath, args, kwargs }, callback); } else { - socket.emit('run_method', { name, parent_path: parentPath, kwargs }); + socket.emit('trigger_method', { access_path: accessPath, args, kwargs }); } };