Implemented connectionstate_updated and connection_error callbacks

I added the connectionstate_updated callback and implemented the connection_error callback, so we can track online/offline status, and act on connection interruptions.