Realm.Sync

Class for interacting with Realm Sync.

Related Classes

AsyncOpenTask
AuthError
IncompatibleSyncedRealmError
Session
Realm.Sync._hasExistingSessions()
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.

Realm.Sync.enableSessionMultiplexing()
static

Enable multiplexing multiple sync sessions over a single connection. 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.

Realm.Sync.initiateClientReset(path)
static

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

Parameters:
  • 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(original_path);
      // copy required objects from Realm at error.config.path
    }
  }
}
Realm.Sync.reconnect()
static

Calling this method will force Realm to attempt to reconnect 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.

Realm.Sync.setLogger(logger)
static

Capture the sync client's log.

Parameters:
Realm.Sync.setLogLevel(level)
static

Set the sync log level.

Parameters:
  • level
Realm.Sync.setUserAgent(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

downloadBeforeOpenBehavior

The default behavior settings if you want to wait for downloading a synchronized Realm to complete before opening it.

logCallback(level, message)

A callback passed to Realm.Sync.setLogger when instrumenting the Realm Sync client with a custom logger.

Parameters:
  • level
    • Type: number
    • The level of the log entry between 0 and 8 inclusively. Use this as an index into ['all', 'trace', 'debug', 'detail', 'info', 'warn', 'error', 'fatal', 'off'] to get the name of the level.

  • message
    • Type: string
    • The message of the log entry.

LogLevel
Type:
"all" or "trace" or "debug" or "detail" or "info" or "warn" or "error" or "fatal" or "off"
openLocalRealmBehavior

The default behavior settings if you want to open a synchronized Realm immediately and start working on it. If this is the first time you open the Realm, it will be empty while the server data is being downloaded in the background.

OpenRealmBehaviorConfiguration

Specify how to open a synced Realm.

Type:
Object
Properties:
  • type
    • Type: string
    • how to open a Realm - 'downloadBeforeOpen' to wait for download to complete or 'openImmediately' to open the local Realm

  • timeOut optional
    • Type: number
    • how long to wait for a download (in ms). Default: infinity

  • timeOutBehavior optional
    • Type: string
    • what to do when download times out - 'openLocalRealm' to open the local Realm or 'throwException' to throw an exception.

SyncConfiguration

This describes the different options used to create a Realm instance with Realm Cloud synchronization.

Type:
Object
Properties:
  • partitionValue
    • Type: string or number or BSON.ObjectId
    • The value of the partition key.

  • error optional
    • Type: function
    • A callback function which is called in error situations. The error callback can take up to five optional arguments: name, message, isFatal, category, and code.

  • customHttpHeaders optional
    • Type: Object
    • A map (string, string) of custom HTTP headers.

  • newRealmFileBehavior optional
    • Type: OpenRealmBehaviorConfiguration
    • Whether to create a new file and sync in background or wait for the file to be synced. If not set, the Realm will be downloaded before opened.

  • existingRealmFileBehavior optional
    • Type: OpenRealmBehaviorConfiguration
    • Whether to open existing file and sync in background or wait for the sync of the file to complete and then open. If not set, the Realm will be downloaded before opened.