Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyncSession - ConnectionListener #429

Closed
sync-by-unito bot opened this issue Sep 2, 2021 · 2 comments · Fixed by #1213
Closed

SyncSession - ConnectionListener #429

sync-by-unito bot opened this issue Sep 2, 2021 · 2 comments · Fixed by #1213
Assignees

Comments

@sync-by-unito
Copy link

sync-by-unito bot commented Sep 2, 2021

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)
  var connectionState: ConnectionState 
  fun isConnected(): Boolean
} 
@cmelchior
Copy link
Contributor

cmelchior commented Sep 7, 2022

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

@rorbech
Copy link
Contributor

rorbech commented Jan 16, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants