Ditto JS SDK v5.0.0
    Preparing search index...

    Class Ditto

    Ditto is the entry point for accessing Ditto-related functionality.

    Index

    Properties

    Provides access to authentication methods for logging on to Ditto Cloud.

    presence: Presence

    Provides access to the SDK's presence functionality.

    smallPeerInfo: SmallPeerInfo

    Provides access to the SDK's small peer info functionality.

    store: Store

    Provides access to the SDK's store functionality.

    sync: Sync

    Provides access to the SDK's sync functionality.

    Accessors

    • get absolutePersistenceDirectory(): string

      The persistence directory used by Ditto to persist data, represented by an absolute path.

      It is not recommended to directly read or write to this directory as its structure and contents are managed by Ditto and may change in future versions.

      When Logger is enabled, logs may be written to this directory even after a Ditto instance was deallocated. Please refer to the documentation of Logger for more information.

      In browsers, this string acts as a namespace for the in-memory data store and does not correspond to a file system directory.

      Returns string

    • get config(): Readonly<DittoConfig>

      The configuration used to initialize this Ditto instance.

      The returned value is frozen, use ditto.config.copy() to obtain a modifiable copy.

      Returns Readonly<DittoConfig>

      when accessed after this Ditto instance has been closed.

    • get deviceName(): string

      Configure a custom identifier for this peer.

      When using presence.observe(), each remote peer is represented by a short UTF-8 "device name". By default this will be a truncated version of the device's hostname.

      Changes to this property after ditto.sync.start() was called will only take effect after the next restart of sync. The value does not need to be unique among peers. Device names longer than 24 bytes will be truncated once ditto.sync.start() is called.

      Returns string

    • set deviceName(value: string): void

      Parameters

      • value: string

      Returns void

    • get isActivated(): boolean

      Returns true if an offline license token has been set, otherwise returns false.

      Returns boolean

    • get isClosed(): boolean

      true once Ditto.close() has been called, otherwise false.

      Returns boolean

    • get DEFAULT_ROOT_DIRECTORY(): string

      The default root directory used for Ditto data persistence.

      This property returns the platform-dependent directory where Ditto stores its data when a relative persistence directory path (or null) is provided.

      Node.js

      • On macOS, this is the ~/Library/Application Support/ditto directory.
      • On Windows, this is the ~/AppData/Roaming/ditto directory.
      • On Linux, this is the ~/.local/share/ditto directory.

      Note that sandboxed environments, such as Electron apps running under Apple's App Sandbox, can require setting a custom persistence directory as these default directories may not be accessible.

      React Native

      • On iOS and macOS, this is the Application Support directory.
      • On Android, this is the app's internal files directory.

      Browsers

      In browsers, this returns an empty string as there is no file system access.

      Returns string

      A string representing the default root directory.

      unsupported if the current environment is not supported by Ditto.

      DittoConfig.persistenceDirectory for more information on configuring the persistence directory.

    • get VERSION(): string

      A string containing the semantic version of the Ditto SDK. Example: 4.4.3

      Returns string

    Methods

    • Shut down Ditto and release all resources.

      Must be called before recreating a Ditto instance that uses the same persistence directory.

      Returns Promise<void>

    • Register observer for changes of underlying transport conditions.

      Ditto will prevent the process from exiting as long as there are active transport conditions observers (not relevant when running in the browser).

      Parameters

      • callback: (condition: TransportCondition, source: ConditionSource) => void

        called when underlying transport conditions change with the changed condition and its source.

      Returns Observer

    • Activate a Ditto instance by setting an offline only license token. You cannot initiate sync with Ditto before you have activated it. The offline license token is only valid for the smallPeersOnly mode.

      Parameters

      • licenseToken: string

        the license token to activate the Ditto instance with. You can find yours on the Ditto portal.

      Returns void

    • Convenience method for updating the transport config. Creates a copy of the current transport config, passes that copy to the update closure, allowing it to mutate as needed, and sets that updated copy afterwards.

      Parameters

      Returns Ditto

    • Don't terminate the process when callbacks are pending for a long time.

      Some methods in the Ditto library accept asynchronous functions as callback parameters. If these asynchronous functions do not resolve within a certain period of time after having been invoked by Ditto, deadlock detection gets triggered, resulting in the termination of the process.

      When Ditto is executed in a Node.js environment with an interactive debugger attached, this deadlock detection might get activated upon encountering a breakpoint. Calling Ditto.disableDeadlockDetection() disables this behavior, thus allowing the use of an interactive debugger without triggering the deadlock detection.

      This feature is only available in Node.js environments.

      Returns void

    • Returns true if deadlock detection is enabled.

      See Ditto.disableDeadlockDetection() for more information.

      When called outside of a Node.js environment, this method always returns false as deadlock detection is only available in Node.js.

      Returns boolean

      true if deadlock detection is enabled

    • Check if the current environment supports running Ditto.

      Required APIs include:

      • BigInt
      • FinalizationRegistry
      • WeakRef

      Internet Explorer is not supported.

      Returns boolean

      true if the environment is supported

    • Asynchronously creates and returns a new Ditto instance using the provided configuration.

      This is the recommended way to initialize Ditto in async environments.

      Parameters

      Returns Promise<Ditto>

      The newly created Ditto instance.

      DittoError with code persistenceDirectoryLocked if the chosen persistence directory is already in use by another Ditto instance.

      DittoError with code invalidDittoConfig if the passed in DittoConfig's contents do not meet the required validation criteria. For detailed information on the validation requirements, consult the documentation of the individual properties of DittoConfig.

      May throw other DittoErrors for other initialization failures.

      Ditto.openSync() for a blocking, non-async alternative.

    • Synchronously creates and returns a new Ditto instance using the provided configuration.

      This is a blocking convenience method for initializing Ditto, intended for use in non-async environments.

      Parameters

      Returns Ditto

      The newly created Ditto instance.

      DittoError with code persistenceDirectoryLocked if the chosen persistence directory is already in use by another Ditto instance.

      DittoError with code invalidDittoConfig if the passed in DittoConfig's contents do not meet the required validation criteria. For detailed information on the validation requirements, consult the documentation of the individual properties of DittoConfig.

      May throw other DittoErrors for other initialization failures.

      Ditto.open() for an async alternative.