Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • Ditto

Index

Constructors

constructor

  • Initializes a new Ditto instance.

    NOTE: The sharedKey identity is only supported for Node environments, using this to create a Ditto instance in the web browser will throw an exception.

    see

    identity

    see

    path

    Parameters

    • identity: Identity

      Identity for the new Ditto instance.

    • Optional path: string

      On Node, path corresponds to a real directory on the file system (intermediate directories are created if needed). In the browser, path is used as an internal namespace into the backing storage (in-memory at the moment, support for IndexedDB is in development). Defaults to "ditto".

    Returns Ditto

Properties

Readonly auth

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

deviceName

deviceName: string

Configure a custom identifier for the current device.

When using observePeers(), 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. It does not need to be unique among peers. Configure the device name before calling startSync(). If it is too long it may be truncated.

Readonly identity

identity: Identity

The (validated) identity this Ditto instance was initialized with.

Readonly isActivated

isActivated: boolean

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

see

setLicenseToken()

Readonly isSyncEnabled

isSyncEnabled: boolean

Returns true if sync has been started, returns false if it has been stopped. Returns false if sync has never been started for this instance.

Readonly path

path: string

The path this Ditto instance was initialized with, if no path was given at construction time, the default value is returned (see constructor).

Readonly siteID

siteID: number | BigInt

The site ID that the instance of Ditto is using as part of its identity.

Readonly store

store: Store

Provides access to the SDK's store functionality.

Readonly transportConfig

transportConfig: TransportConfig

Returns the current transport configuration, frozen. If you want to modify the transport config, make a copy first. Or use the updateTransportConfig() convenience method.

see

setTransportConfig()

see

updateTransportConfig()

Accessors

sdkVersion

  • get sdkVersion(): string
  • Returns a string identifying the version of the Ditto SDK.

    Returns string

Methods

observePeers

  • Registers an observer for info about Ditto peers in range of this device.

    Parameters

    • callback: (peersData: RemotePeer[]) => void

      called immediately with the current state of peers in range and whenever that state changes. Then it will be invoked repeatedly when Ditto devices come and go, or the active connections to them change.

    Returns Observer

observeTransportConditions

runGarbageCollection

  • runGarbageCollection(): void
  • Removes all sync metadata for any remote peers which aren't currently connected. This method shouldn't usually be called. Manually running garbage collection often will result in slower sync times. Ditto automatically runs a garbage a collection process in the background at optimal times.

    Manually running garbage collection is typically only useful during testing if large amounts of data are being generated. Alternatively, if an entire data set is to be evicted and it's clear that maintaining this metadata isn't necessary, then garbage collection could be run after evicting the old data.

    Only available in Node environments at the moment, no-op in the browser.

    Returns void

setAccessLicense

  • setAccessLicense(accessLicense: string): void
  • deprecated

    use setLicenseToken() instead.

    Parameters

    • accessLicense: string

    Returns void

setLicenseToken

  • setLicenseToken(licenseToken: string): void
  • Activate a Ditto instance by setting a license token. You cannot sync with Ditto before you have activated it.

    Parameters

    • licenseToken: string

      the license token to activate the Ditto instance with. You can find yours on the Ditto portal (https://portal.ditto.live).

    Returns void

setTransportConfig

  • Assigns a new transports configuration. By default peer-to-peer transports (Bluetooth, WiFi, and AWDL) are enabled. You may use this method to alter the configuration at any time, however sync will not begin until startSync() is called.

    see

    transportConfig

    see

    updateTransportConfig()

    Parameters

    Returns void

startSync

  • startSync(): void
  • Starts the network transports. Ditto will connect to other devices.

    By default Ditto will enable all peer-to-peer transport types. On Node, this means Bluetooth, WiFi/LAN, and AWDL. The network configuration can be customized with setTransportConfig(). On the Web, only connecting via Websockets is supported.

    see

    isSyncEnabled

    see

    stopSync()

    Returns void

stopSync

  • stopSync(): void
  • Stops all network transports.

    You may continue to use the database locally but no data will sync to or from other devices.

    see

    isSyncEnabled

    see

    startSync()

    Returns void

tryStartSync

  • tryStartSync(): void
  • Alias for startSync().

    This method and startSync() are semantically equivalent in the JS SDK while differing for languages like Swift or ObjC. Therefore the alias.

    Returns void

updateTransportConfig

  • 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