From 8e99afeb31f7bba36264347ad11aed0ce48100f0 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sat, 10 Aug 2024 14:36:08 -0400 Subject: [PATCH] Controller --- lib/controller/ws.dart | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/controller/ws.dart diff --git a/lib/controller/ws.dart b/lib/controller/ws.dart new file mode 100644 index 0000000..1f708f0 --- /dev/null +++ b/lib/controller/ws.dart @@ -0,0 +1,24 @@ +import 'package:web_socket_channel/web_socket_channel.dart'; + +class LiveFeeder { + late WebSocketChannel channel; + + LiveFeeder(); + + void init() { + String socketUrl = 'ws://xenon:3050/ws'; + Uri baseUri = Uri.base; + if (baseUri.scheme == 'http' || baseUri.scheme == 'https') { + String port = (baseUri.hasPort ? ':' + baseUri.port.toString() : ''); + socketUrl = 'ws://${baseUri.host}$port/ws'; + } + final wsUri = Uri.parse(socketUrl); + + channel = WebSocketChannel.connect(wsUri); + channel.stream.listen((event) => _handleData(event)); + } + + void _handleData(dynamic event) { + print(event); + } +}