I'm using socket.io-client in react-native to start a chat room, when the app enters in background mode the socket keeps working, no problem, but when I disconnect the socket yet the foreground mode still stays active. I have tried a lot of ways but none deactivated the background service.
Follow the code who call the socket:
socket = null;
socketConnection = (url) => {
socket = io(url, { forceNew: true });
socket.on('connect', () => {
console.warn("Connected: ", socket.connected);
});
socket.on('disconnect', () => {
console.warn("Disconnected: ", socket.disconnected);
});
}
socketDisconnect = () => {
socket.disconnect();
socket.off("connect");
socket.off("disconnect");
}