realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

SyncSession - ConnectionListener

Open sync-by-unito[bot] opened this issue 4 years ago • 1 comments

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)
} 

sync-by-unito[bot] avatar Sep 02 '21 11:09 sync-by-unito[bot]

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

cmelchior avatar Sep 07 '22 09:09 cmelchior

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.

rorbech avatar Jan 16 '23 09:01 rorbech