Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ditto.live/llms.txt

Use this file to discover all available pages before exploring further.

Installing the C++ SDK

Linux

To install the C++ SDK:
1
Fetch and extract the Ditto package. (Downloading and Unpacking Ditto)
2
Configure your app to link to the Ditto library. (Linking to Ditto)

Downloading and Unpacking Ditto

Download Ditto.tar.gz and unpack an archive containing the libditto.a static library and Ditto header:
curl -O https://software.ditto.live/cpp-linux-x86_64/Ditto/5.0.0/dist/Ditto.tar.gz && tar xvfz Ditto.tar.gz

Linking to Ditto

Add -lditto as a compilation step in the main.cpp source file:
For instructions on adding cross-platform Bluetooth Low Energy (LE) capabilities, see Bluetooth on Linux.BlueZ is the official Bluetooth protocol stack implementation for Linux systems to communicate with other Bluetooth-enabled platforms.
# This command assumes:
# You have unzipped the Ditto.tar.gz in a relative directory ./sdk/
# Your main code entry point is in ./src/main.cpp

g++ -std=c++11 ./src/main.cpp -I ./sdk -lditto -ldl -lrt -pthread -L ./sdk -o dist/main;

 # Once executed, your output will be available at: ./dist/main

Importing and Initializing Ditto

From the source code of your app, using #include <ditto/ditto.h>, use the ditto namespace, and provide your access credentials:
C++
#include <ditto/ditto.h>

auto database_id = "YOUR_DATABASE_ID";
auto config = ditto::DittoConfig(
    database_id,
    ditto::DittoConnect::server("https://" + database_id + ".cloud.ditto.live")
);

auto ditto = ditto::Ditto::open(config);

ditto->auth()->set_expiration_handler([](ditto::Ditto& ditto, int64_t seconds_remaining) {
    ditto.auth()->login("YOUR_PLAYGROUND_TOKEN", ditto::Authenticator::development_provider(),
        [](const ditto::AuthenticationSuccess* success, const ditto::DittoError* error) {
            if (error) {
                std::cerr << "Auth error" << std::endl;
            }
        });
});

ditto->update_transport_config([&](ditto::TransportConfig &config) {
    config.enable_all_peer_to_peer();
});

ditto->get_sync()->start();