In Ditto, synchronization happens over a variety of network transports — including local peer-to-peer connections (Bluetooth, LAN, AWDL, WI-FI Aware, and Wi-Fi), as well as cloud-based sync via the Ditto Server. While Ditto handles these connections automatically by default, you may want more control over which transports are used, how they’re configured, or when they’re enabled. This guide walks you through how to customize these transport settings to suit your app’s specific connectivity and sync requirements.
DittoTransportConfig
does not enable this feature by default. Rather, you manually enable peer-to-peer connections using EnableAllPeerToPeer()
.This is only true if you provide a custom instance of the DittoTransportConfig
object. If you do not provide a custom instance, Ditto will automatically enable all peer-to-peer transports by default.The best way to ensure that you are using the correct transport configuration is to use the updateTransportConfig
API to update the DittoTransportConfig
object. This will ensure that you are using the correct transport configuration and that you are not missing any transports.DittoTransportConfig
object.
updateTransportConfig
API after
sync has been started will instantly apply the changes without the need to manually stop and start sync.websocketURL
to the DittoTransportConfig
object. You can do this by calling updateTransportConfig
and adding the websocketURL
to the connect.websocketURLs
array.
updateTransportConfig
API to remove all webSocketURLs
from the connect object will disable sync with the Ditto Server instantly without needing to call stop and start sync on the Ditto instance.transportConfig.connect.tcpServers
for equivalent behavior.updateTransportConfig
API. This system configuration can be updated at any time, though changes will only take effect while sync is active.
Suppose you have a device in your mesh that acts as a connection hub, and you want every other device to connect to the hub.
12345
) as described in Listening for Connections.10.0.0.143
.TRANSPORTS_DISCOVERED_PEERS
on all the other devices in the mesh to make them connect to the hub. See code examples below:address
field supports domain names, IPv4 addresses, and IPv6 addresses. tcp
is the only supported scheme. The following are all valid addresses:tcp://192.168.1.86:12345
tcp://[2001:db8::1:0]:12345
tcp://mydevice.local:12345
type
field supports two options:candidate
(default): Ditto will use this peer as a connection candidate when forming an optimal mesh. If this peer is removed from the list, the connection may persist.force
: Ditto will always attempt to connect to this peer. If this peer is removed from the list, the connection will immediately be dropped.TransportConfig
.discovery_hint
using the following DQL query:SELECT * FROM system:transports_info WHERE _id = 'discovery_hint'
discovery_hint
to every other peer in the mesh. (This information must be sent on channels outside Ditto because we assume that all peers start disconnected from each other.)TRANSPORTS_DISCOVERED_PEERS
with the full list of discovered peers as the device receives discovery information from other devices.discovery_hint
:TRANSPORTS_DISCOVERED_PEERS
.startSync()
is called.