I am working on an app which has a chat feature which i have done using Rocket chat websocket. I have used okhttp connection to connect with rocket chat connection.
The app and the connection works perfectly in the chat activity. I want the websocket connection to be always open starting from when i login successfully yo the app, and thereafter always when there is internet so that i can get the notification for messages when i am at anywhere in the app other than chat page.
And also I want the websocket connection to be active when there is internet connection and connection to pause or close when app goes offline and re connect or resume to the connection when internet connection is back.
How can I achieve this?