removing broadcastStream
Some checks failed
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Has been cancelled
Some checks failed
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Has been cancelled
This commit is contained in:
parent
3cb6efe5bd
commit
d18b576d7e
@ -1,4 +1,3 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -12,17 +11,13 @@ import 'custom_menu.dart';
|
||||
|
||||
class StatusPage extends StatefulWidget {
|
||||
final VoidCallback toggleProfile;
|
||||
|
||||
const StatusPage({super.key, required this.toggleProfile});
|
||||
|
||||
@override
|
||||
StatusPageState createState() => StatusPageState();
|
||||
}
|
||||
|
||||
class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
WebSocketChannel? channel;
|
||||
late final Stream<dynamic> broadcastStream;
|
||||
late StreamController<dynamic> controller;
|
||||
late final WebSocketChannel channel;
|
||||
List<Map<String, dynamic>> messages = [];
|
||||
final Map<String, ImageProvider> _imageCache = {};
|
||||
static const wsBaseUrl = String.fromEnvironment('WS_BASE_URL',
|
||||
@ -41,17 +36,14 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
channel = WebSocketChannel.connect(
|
||||
Uri.parse('$wsBaseUrl/ws'),
|
||||
);
|
||||
|
||||
controller = StreamController<dynamic>.broadcast();
|
||||
controller.addStream(channel!.stream);
|
||||
broadcastStream = channel!.stream.asBroadcastStream();
|
||||
debugPrint("WebSocket initialized at: $wsBaseUrl/ws");
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
channel?.sink.close();
|
||||
controller.close();
|
||||
channel.sink.close();
|
||||
debugPrint("WebSocket connection closed.");
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -63,8 +55,8 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
void _reconnectWebSocket() {
|
||||
if (channel == null || channel!.closeCode != null) {
|
||||
// Check if channel is null or already closed
|
||||
if (channel.closeCode != null) {
|
||||
debugPrint("Reinitializing WebSocket connection...");
|
||||
_initializeWebSocket();
|
||||
}
|
||||
}
|
||||
@ -310,7 +302,7 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
),
|
||||
),
|
||||
body: StreamBuilder(
|
||||
stream: controller.stream,
|
||||
stream: channel.stream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final newMessage =
|
||||
|
Loading…
Reference in New Issue
Block a user