Realm.Sync

Class for interacting with Realm Sync.

Realm.Sync._hasExistingSessions(app)
static

Returns true if Realm still has a reference to any sync sessions regardless of their state. If false is returned it means that no sessions currently exist.

Parameters:
  • app optional
    • Type: Realm.App
    • The app where the Realm was opened.

Realm.Sync.enableSessionMultiplexing(app)
static

Enable multiplexing multiple sync sessions over a single connection for a Realm app. When having a lot of synchronized realms open the system might run out of file descriptors because of all the open sockets to the server. Session multiplexing is designed to alleviate that, but it might not work with a server configured with fail-over. Only use if you're seeing errors about reaching the file descriptor limit and you know you are using many sync sessions.

Parameters:
Realm.Sync.getAllSyncSessions(user)[Realm.App.Sync.Session, ...]
static

Returns all sync sessions for a user.

Parameters:
Returns: [Realm.App.Sync.Session, ...] an array of sessions
Realm.Sync.getSyncSession(user, partitionValue)Realm.App.Sync.Session
static

Returns the session associated with a user and partition value.

Parameters:
  • partitionValue
    • Type: string or number or ObjectId or null
Returns: Realm.App.Sync.Session the session
Realm.Sync.initiateClientReset(app, path)
static

Initiate a client reset. The Realm must be closed prior to the reset.

Parameters:
  • app optional
    • Type: Realm.App
    • The app where the Realm was opened.

  • path optional
    • Type: string
    • The path to the Realm to reset. Throws error if reset is not possible.

Example:
{
  const config = { sync: { user, partitionValue } };
  config.sync.error = (sender, error) => {
    if (error.name === 'ClientReset') {
      Realm.Sync.initiateClientReset(app, original_path);
      // copy required objects from Realm at error.config.path
    }
  }
}
Realm.Sync.reconnect(app)
static

Calling this method will force Realm to attempt to reconnect the Realm App to the server immediately.

Realm will reconnect automatically, but by using exponential backoff. This means that if the device is offline for a long time, restoring the connection after it comes back online can take longer than expected. In situations where it is possible to detect the network condition (e.g. Airplane mode). Manually calling this method can provide a smoother user experience.

Parameters:
Realm.Sync.setLogger(app, logger)
static

Capture the sync client's log. You can only set the log level once, and you must do it after creating an App instance but before opening any Realms.

See: {Realm.App.Sync~setLogLevel}
Parameters:
  • logger
    • Type: logCallback
    • The log callback.

Example:
{
const app = new Realm.App(getAppConfig());
Realm.App.Sync.setLogger((level, message) => console.log(`[${level}] ${message}`);
const user = await app.logIn(credentials);
const realm = await Realm.open(getRealmConfig(user));
}
Realm.Sync.setLogLevel(app, level, level)
static

Set the sync log level. You can only set the log level once, and you must do it after creating an App instance but before opening any Realms.

Parameters:
  • level
    • Type: LogLevel
    • The new log level

Example:
{
const app = new Realm.App(getAppConfig());
Realm.App.Sync.setLogLevel("all");
const user = await app.logIn(credentials);
const realm = await Realm.open(getRealmConfig(user));
}
Realm.Sync.setUserAgent(the, the)
static

Set the application part of the User-Agent string that will be sent to the Realm Object Server when a session is created.

This method can only be called up to the point where the first Realm is opened. After that, the User-Agent can no longer be changed.

Parameters:
  • the
    • Type: string
    • user agent description