I already write a websocket based app, but when I back to home (both iOS and Android) the websocket are just not working anymore. How to make websocket still work on background? So that the service can always runing. Here is my stream and subscription:
channel = new IOWebSocketChannel.connect(wsUrl);
globalChannel = channel;
print("web socket channel connected.");
// add channel.stream to streamController
setState(() {
_streamController = StreamController.broadcast();
_streamController.addStream(channel.stream);
globalStreamController = _streamController;
});
// Here we listen to ws stream and add to global messages
// when enter chat page, globalSubscription should be stop
// if globalSub were canceled, how to reopen it??
globalSubscription = globalStreamController.stream.listen((data) {
}
How to let this streamcontroller still runing rather than limited in current page class?