centrifugal / centrifuge-dart

Dart (Flutter) client SDK for bidirectional communication with Centrifugo and Centrifuge-based server over WebSocket
https://pub.dartlang.org/packages/centrifuge
MIT License
102 stars 29 forks source link

Bad state: StreamSink is closed #75

Closed furkanKotic closed 1 year ago

furkanKotic commented 1 year ago

The Firebase log record, which is usually seen on Oppo devices, is as follows:

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Bad state: StreamSink is closed
       at _WebSocketImpl.add(_WebSocketImpl.java)
       at DelegatingStreamSink.add(stream_sink.dart:35)
       at _CompleterSink.add(sink_completer.dart:88)
       at WebSocketChannelExtension.sendData(channel.dart:20)
       at Transport.sendAsyncMessage(transport.dart:162)
       at ClientImpl._onPing(client.dart:711)
       at ClientImpl._onPush(client.dart:719)
       at Transport._onData.<fn>.<fn>(transport.dart:266)
       at _GrowableList.forEach(_GrowableList.java)
       at Transport._onData.<fn>(transport.dart:262)

I think it is seen in the application that is pending in the background.

image

FZambia commented 1 year ago

You need to close client when app goes to the background. See https://github.com/centrifugal/centrifuge-dart#usage-in-background

furkanKotic commented 1 year ago

I should use disconnect when it goes to the background and use the connect function again when it goes to the foreground. Is it true?

Should I cancel all Stream when it goes to the background and recreate them when it goes to the foreground?

_imClient.connected.listen((event) {
  **my code
});
FZambia commented 1 year ago

I should use disconnect when it goes to the background and use the connect function again when it goes to the foreground. Is it true?

Yes

Should I cancel all Stream when it goes to the background and recreate them when it goes to the foreground?

I think you don't need to do this.

furkanKotic commented 1 year ago

Thank you for your help.