@@ -303,52 +303,53 @@ class BitwindowRPCLive extends BitwindowRPC {
303303 if (stoppingBinary) return ;
304304
305305 try {
306- _healthStreamSubscription = health.watch ().listen (
307- (response) {
308- // Broadcast to health stream listeners
309- _healthStreamController.add (response);
310-
311- // Only notify if the health status has changed
312- if (_previousHealthResponse == null ) {
313- _previousHealthResponse = response;
314- notifyListeners ();
315- } else if (! _areHealthResponsesEqual (_previousHealthResponse! , response)) {
316- _previousHealthResponse = response;
306+ _healthStreamSubscription =
307+ health.watch ().listen (
308+ (response) {
309+ // Broadcast to health stream listeners
310+ _healthStreamController.add (response);
311+
312+ // Only notify if the health status has changed
313+ if (_previousHealthResponse == null ) {
314+ _previousHealthResponse = response;
315+ notifyListeners ();
316+ } else if (! _areHealthResponsesEqual (_previousHealthResponse! , response)) {
317+ _previousHealthResponse = response;
318+ notifyListeners ();
319+ }
320+ },
321+ onError: (error) {
322+ log.e ('Health stream error: $error ' );
323+ if (error is Exception ) {
324+ log.e ('Error details: ${error .toString ()}' );
325+ }
326+ // Reset previous response on error since state is uncertain
327+ _previousHealthResponse = null ;
317328 notifyListeners ();
318- }
319- },
320- onError: (error) {
321- log.e ('Health stream error: $error ' );
322- if (error is Exception ) {
323- log.e ('Error details: ${error .toString ()}' );
324- }
325- // Reset previous response on error since state is uncertain
326- _previousHealthResponse = null ;
327- notifyListeners ();
328329
329- // If we're still connected and not stopping, try to restart the stream after a delay
330+ // If we're still connected and not stopping, try to restart the stream after a delay
331+ if (connected && ! stoppingBinary) {
332+ log.i ('Health stream dropped, but still connected, restarting health stream in 5 seconds...' );
333+ Future .delayed (const Duration (seconds: 5 ), () {
334+ if (connected && ! stoppingBinary) {
335+ startHealthStream ();
336+ }
337+ });
338+ }
339+ },
340+ cancelOnError: false ,
341+ )..onDone (() {
342+ log.i ('Health stream completed' );
343+ // If we're still connected and not stopping, restart the stream
330344 if (connected && ! stoppingBinary) {
331- log.i ('Health stream dropped, but still connected, restarting health stream in 5 seconds...' );
345+ log.i ('Stream completed but still connected, restarting health stream in 5 seconds...' );
332346 Future .delayed (const Duration (seconds: 5 ), () {
333347 if (connected && ! stoppingBinary) {
334348 startHealthStream ();
335349 }
336350 });
337351 }
338- },
339- cancelOnError: false ,
340- )..onDone (() {
341- log.i ('Health stream completed' );
342- // If we're still connected and not stopping, restart the stream
343- if (connected && ! stoppingBinary) {
344- log.i ('Stream completed but still connected, restarting health stream in 5 seconds...' );
345- Future .delayed (const Duration (seconds: 5 ), () {
346- if (connected && ! stoppingBinary) {
347- startHealthStream ();
348- }
349- });
350- }
351- });
352+ });
352353 } catch (e) {
353354 log.e ('Failed to start health stream: $e ' );
354355 // Connection is probably dead, don't crash - just log it
@@ -363,40 +364,41 @@ class BitwindowRPCLive extends BitwindowRPC {
363364 if (stoppingBinary) return ;
364365
365366 try {
366- _notificationStreamSubscription = notifications.watch ().listen (
367- (event) {
368- // Broadcast to notification stream listeners
369- _notificationStreamController.add (event);
370- },
371- onError: (error) {
372- log.e ('Notification stream error: $error ' );
373- if (error is Exception ) {
374- log.e ('Error details: ${error .toString ()}' );
375- }
367+ _notificationStreamSubscription =
368+ notifications.watch ().listen (
369+ (event) {
370+ // Broadcast to notification stream listeners
371+ _notificationStreamController.add (event);
372+ },
373+ onError: (error) {
374+ log.e ('Notification stream error: $error ' );
375+ if (error is Exception ) {
376+ log.e ('Error details: ${error .toString ()}' );
377+ }
376378
377- // If we're still connected and not stopping, try to restart the stream after a delay
379+ // If we're still connected and not stopping, try to restart the stream after a delay
380+ if (connected && ! stoppingBinary) {
381+ log.i ('Notification stream dropped, but still connected, restarting in 5 seconds...' );
382+ Future .delayed (const Duration (seconds: 5 ), () {
383+ if (connected && ! stoppingBinary) {
384+ startNotificationStream ();
385+ }
386+ });
387+ }
388+ },
389+ cancelOnError: false ,
390+ )..onDone (() {
391+ log.i ('Notification stream completed' );
392+ // If we're still connected and not stopping, restart the stream
378393 if (connected && ! stoppingBinary) {
379- log.i ('Notification stream dropped, but still connected, restarting in 5 seconds...' );
394+ log.i ('Stream completed but still connected, restarting notification stream in 5 seconds...' );
380395 Future .delayed (const Duration (seconds: 5 ), () {
381396 if (connected && ! stoppingBinary) {
382397 startNotificationStream ();
383398 }
384399 });
385400 }
386- },
387- cancelOnError: false ,
388- )..onDone (() {
389- log.i ('Notification stream completed' );
390- // If we're still connected and not stopping, restart the stream
391- if (connected && ! stoppingBinary) {
392- log.i ('Stream completed but still connected, restarting notification stream in 5 seconds...' );
393- Future .delayed (const Duration (seconds: 5 ), () {
394- if (connected && ! stoppingBinary) {
395- startNotificationStream ();
396- }
397- });
398- }
399- });
401+ });
400402 } catch (e) {
401403 log.e ('Failed to start notification stream: $e ' );
402404 // Connection is probably dead, don't crash - just log it
0 commit comments