updates frontend socket to use new sio events

This commit is contained in:
Mose Müller 2024-03-27 09:31:06 +01:00
parent 8addcd26aa
commit 2eb996b382

View File

@ -1,4 +1,5 @@
import { io } from 'socket.io-client'; import { io } from 'socket.io-client';
import { SerializedValue } from './components/GenericComponent';
export const hostname = export const hostname =
process.env.NODE_ENV === 'development' ? `localhost` : window.location.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 socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] });
export const setAttribute = ( export const updateValue = (
name: string, serializedObject: SerializedValue,
parentPath: string,
value: unknown,
callback?: (ack: unknown) => void callback?: (ack: unknown) => void
) => { ) => {
if (callback) { if (callback) {
socket.emit('set_attribute', { name, parent_path: parentPath, value }, callback); socket.emit('update_value', { value: serializedObject }, callback);
} else { } else {
socket.emit('set_attribute', { name, parent_path: parentPath, value }); socket.emit('update_value', { value: serializedObject });
} }
}; };
export const runMethod = ( export const runMethod = (
name: string, accessPath: string,
parentPath: string, args: unknown[] = [],
kwargs: Record<string, unknown>, kwargs: Record<string, unknown> = {},
callback?: (ack: unknown) => void callback?: (ack: unknown) => void
) => { ) => {
// TODO: serialize args and kwargs before passing to trigger_method
if (callback) { if (callback) {
socket.emit('run_method', { name, parent_path: parentPath, kwargs }, callback); socket.emit('trigger_method', { access_path: accessPath, args, kwargs }, callback);
} else { } else {
socket.emit('run_method', { name, parent_path: parentPath, kwargs }); socket.emit('trigger_method', { access_path: accessPath, args, kwargs });
} }
}; };