Get Started
'Hello World' Sync
once you've set up your environment, try on ditto and perform your first peer to peer sync intended to get you oriented, this article provides a streamlined process for integrating sync functionality within your app if you prefer building and exploring through a chat app, and so on, see docid\ hml3nunwo5k313jku wyz integrating sync functionality i ntegrate the ditto sdk in your codebase, set up authentication, and then start syncing offline from the top most scope of your app's codebase, add the following to set up authentication and start syncing offline dittologger minimumloglevel = debug let ditto = ditto(identity onlineplayground( appid "replace me with your app id", token "replace me with your playground token" )) do { try ditto startsync() } catch (let err) { print(err localizeddescription) }try { val androiddependencies = defaultandroiddittodependencies(context) val identity = dittoidentity onlineplayground( androiddependencies, appid = "replace me with your app id", token = "replace me with your playground token" ) dittologger minimumloglevel = dittologlevel debug ditto = ditto(androiddependencies, identity) ditto startsync() } catch (e dittoerror) { log e("ditto error", e message!!) }import { init, ditto, logger } from "@dittolive/ditto" logger minimumloglevel = 'debug' const identity identity = { type 'onlineplayground', appid 'replace me with your app id', token 'replace me with your playground token' } const path = ' /your ditto application data path' const ditto = new ditto(identity, path) ditto startsync()import { init, ditto, logger } from "@dittolive/ditto" logger minimumloglevel = 'debug' const identity identity = { type 'onlineplayground', appid 'replace me with your app id', token 'replace me with your playground token' } const path = ' /your ditto application data path' const ditto = new ditto(identity, path) ditto startsync()dittodependencies androiddependencies = new defaultandroiddittodependencies(this context); dittologger setminimumloglevel(dittologlevel debug); dittoidentity identity = new dittoidentity onlineplayground(androiddependencies, "replace me with your app id", "your playground token here"); ditto ditto = new ditto(androiddependencies, identity); try { ditto startsync(); } catch(dittoerror e) { //handle error }try { dittologger setminimumloglevel(dittologlevel debug); var ditto = new ditto(dittoidentity onlineplayground("replace me with your app id", "replace me with your playground token", true), path); ditto startsync(); } catch (dittoexception ex) { console writeline($"ditto error {ex message}"); }auto identity = identity onlineplayground("replace me with your app id", "replace me with your playground token", true); try { ditto ditto = ditto(identity, dir); ditto set minimum log level(loglevel debug); ditto start sync(); } catch (const dittoerror \&err) { }let ditto = ditto builder() // creates a `ditto data` folder in the directory containing the executing process with root(arc new(persistentroot from current exe()?)) with identity(|ditto root| { // provided as an env var, may also be provided as hardcoded string let app id = appid from env("replace me with your app id")?; let shared token = std env var("replace me with a shared token") unwrap(); let enable cloud sync = true; let custom auth url = none; onlineplayground new( ditto root, app id, shared token, enable cloud sync, custom auth url, ) })? with minimum log level(loglevel debug) build()?; ditto start sync()?;# not supported by http api replace your app id and your playground token with your access credentials available from the portal creating subscriptions to register a new sync subscription in your app for example, the following snippet demonstrates how to establish a subscription to sync updates to documents in the cars collection with a field of color set to the value blue ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars");auto subscription = ditto sync() register subscription("select from cars");let subscription = ditto sync() register subscription("select from cars", none); sync subscriptions also support argument injection using the \ argument syntax in dql ditto sync registersubscription(""" select from cars where color = \ color """, \[ "color" "blue" ])ditto sync registersubscription(""" select from cars where color = \ color """, mapof("color" to "blue"))ditto sync registersubscription(` select from cars where color = \ color`, { color 'blue' })ditto sync registersubscription( "select from cars where color = \ color", collections singletonmap("color", "blue"))var queryarguments = new dictionary\<string, object>(){{"color", "blue" }}; ditto sync registersubscription( "select from cars where color = 'blue'", queryarguments);ditto sync() register subscription( "select from cars where color = \ color", {{"color", "blue"}});struct args { color string, } // let args = args { color "blue" to string(), }; ditto sync() register subscription( "select from cars where color = \ color", args); retrieving subscriptions retrieve active sync subscriptions by calling the subscriptions method on the ditto sync namespace let activesubscriptions = ditto sync subscriptions;val activesubscriptions = ditto sync subscriptionsconst activesubscriptions = ditto sync subscriptionsdittosyncsubscription\[] activesubscriptions = ditto sync subscriptions;var activesubscriptions = ditto sync subscriptions;// not supported hold the reference to the syncsubscription object // not supported hold the reference to the syncsubscription object canceling subscriptions to cancel a subscription, call cancel on the subscription object you set up to establish your subscription subscription cancel()subscription close()subscription cancel()subscription close()subscription cancel();// // you can check if a sync subscription is canceled by using the iscancelled field on the subscription object subscription iscancelledsubscription isclosedsubscription iscancelledsubscription iscancelledsubscription iscancelled// //