Controller

This commit is contained in:
Daniel 2024-08-10 14:36:08 -04:00
parent e64948bef5
commit 8e99afeb31

24
lib/controller/ws.dart Normal file
View file

@ -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);
}
}