How to always connect to socket.io even when shutdown or exit the application to be able to receive notifications from calls or messages(React Native)

538 views Asked by At

I'm having a problem with react native

my app can let you video call each other using webRTC and socket.io, the technologies i use are WebRTC, React Native, Socket.io , socket.io-client, react-native-webrtc

Basically the way my app works is when you open the app you automatically connect to socket.io to listen and make calls but when I turn off the phone screen or exit the app I can't hear and receive calls can call again because at that time the socket has automatically disconnected.

I want my application can still work properly even if I exit the application my application can still receive notifications of incoming calls from another person, can say I want my application Works like Messenger App

My current workaround is to find a way for each user's socket to always be connected to listen for incoming calls from others.

Has anyone encountered this problem or have a solution for this please let me know, I really appreciate it

Thank you guys, Have a nice day <3

1

There are 1 answers

1
Akshay Bhimani On

Move your socket to the Background service and then you can add the socket events in the service.

Note: This will increase your battery consumption.