mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
updates frontend socket to use new sio events
This commit is contained in:
parent
8addcd26aa
commit
2eb996b382
@ -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 });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user