diff --git a/client/src/components/common/BaseButton.vue b/client/src/components/common/BaseButton.vue index 2a70233..bf51d33 100644 --- a/client/src/components/common/BaseButton.vue +++ b/client/src/components/common/BaseButton.vue @@ -49,6 +49,8 @@ const variantClass = computed(() => { return 'bg-accent-400 text-bg-700 ' case 'light': return 'bg-accent-500 text-bg-900 hover:bg-accent-600' + case 'red': + return 'bg-error text-white-100' default: return 'bg-accent-600 text-white-100' } diff --git a/client/src/components/flow/FlowHeader.vue b/client/src/components/flow/FlowHeader.vue index 86c8e08..474e78a 100644 --- a/client/src/components/flow/FlowHeader.vue +++ b/client/src/components/flow/FlowHeader.vue @@ -5,9 +5,10 @@ import ExitIcon from '@/icons/ExitIcon.vue' import NodesList from '@/components/flow/NodesList.vue' import ExportIcon from '@/icons/ExportIcon.vue' -defineEmits(['update:displayLog']) +defineEmits(['toggle-log', 'toggle-web-socket']) defineProps({ displayLog: Boolean, + isRunning: Boolean, nodes: Array }) @@ -24,10 +25,16 @@ defineProps({
- Run + + {{ isRunning ? 'Stop' : 'Run' }} + Logs diff --git a/client/src/components/flow/FlowLogList.vue b/client/src/components/flow/FlowLogList.vue index 969efb0..4c50a37 100644 --- a/client/src/components/flow/FlowLogList.vue +++ b/client/src/components/flow/FlowLogList.vue @@ -71,7 +71,11 @@ watch( {{ logItems.find((item) => item.id === deviceId)?.name || 'All Devices' }} diff --git a/client/src/interfaces/IWebSocketService.ts b/client/src/interfaces/IWebSocketService.ts index 7a5c364..8c28cc7 100644 --- a/client/src/interfaces/IWebSocketService.ts +++ b/client/src/interfaces/IWebSocketService.ts @@ -2,6 +2,7 @@ import type { Log } from '@/types/WebSocketServiceTypes' export interface IWebSocketService { connect(port: number): void + disconnect(): void subscribe(listener: (log: Log) => void): void unsubscribe(listener: (log: Log) => void): void notifyListeners(log: Log): void diff --git a/client/src/services/WebSocketService.ts b/client/src/services/WebSocketService.ts index b8172fa..4d3bdee 100644 --- a/client/src/services/WebSocketService.ts +++ b/client/src/services/WebSocketService.ts @@ -43,6 +43,16 @@ class WebSocketService implements IWebSocketService { public notifyListeners(log: Log) { this.eventListeners.forEach((listener) => listener(log)) } + + public disconnect() { + if (this.socket) { + console.log('this.socket:', this.socket) + this.socket.close() + console.log('WebSocket disconnected') + } else { + console.log('WebSocket already disconnected') + } + } } export const webSocketService = new WebSocketService() diff --git a/client/src/views/FlowDetailedView.vue b/client/src/views/FlowDetailedView.vue index 9c37008..59635c9 100644 --- a/client/src/views/FlowDetailedView.vue +++ b/client/src/views/FlowDetailedView.vue @@ -15,6 +15,8 @@ import FlowEdge from '@/components/flow/FlowEdge.vue' import { ref, type Ref } from 'vue' import { inject, computed } from 'vue' import { useRoute } from 'vue-router' +import { webSocketService } from '@/services/WebSocketService' +import type { Log } from '@/types/WebSocketServiceTypes' const flows = inject>('flows', ref([])) @@ -41,14 +43,39 @@ function onEdgeChange({ edge, connection }: { edge: GraphEdge; connection: Conne } const displayLog = ref(false) +const isRunning = ref(false) + +const handleNewLog = (log: Log) => { + console.log('new log', log) +} + +// toggle log display const toggleLog = () => { displayLog.value = !displayLog.value } + +// toggle websocket connection +const toggleWebSocket = () => { + isRunning.value = !isRunning.value + + if (isRunning.value) { + webSocketService.connect(8765) + webSocketService.subscribe(handleNewLog) + } else { + webSocketService.unsubscribe(handleNewLog) + webSocketService.disconnect() + } +}