realm-kotlin
realm-kotlin copied to clipboard
SyncSession - ConnectionListener
Add support for ConnectionListeners similar to Realm Java:
enum class ConnectionState {
DISCONNECTED,
CONNECTING,
CONNECTED
}
typealias ConnectionListener = (oldState: ConnectionState, newState: ConnectionState) -> Unit
class SyncSession {
fun addConnectionChangeListener(listener: ConnectionListener)
}
Something to consider before implementing this, is if the split between ConnectionState and SessionState actually makes sense, since individually both of them fail to answer the fundamental question "Are this Realm successfully connected to the server and can send/receive data".
The different SDK's do agree on the ConnectionStates available, but do not agree on the session state:
Java: ConnectionState: DISCONNECTED CONNECTING CONNECTED SessionState: INACTIVE ACTIVE DYING WAITING_FOR_ACCESS_TOKEN
.NET:
SessionState:
Active
Inactive
ConnectionState:
Disconnected
Connecting
Connected
JS: SessionState: "active": "inactive": "invalid": ConnectionState: "disconnected" "connecting" "connecting"
Swift: SessionState: Active Inactive Invalid ConnectionState: Disconnected Connecting Connected
Since SyncSession is already exposed in a public API and connection state is actually not varying across SDK (and is pretty much a 1-1 mapping of the connection state), I don't think it makes sense to rework the logic now. I think any effort to make a better "sync status"-indicator should go across SDKs and also clean up the SyncSession.State. Thus, I just made a PR to expose the connection state as is.