diff --git a/snippets.json b/snippets.json index 2dbe480c17..890ce75ee6 100644 --- a/snippets.json +++ b/snippets.json @@ -55,7 +55,7 @@ "network-listen": "DITMutableTransportConfig *transportConfig = [[DITMutableTransportConfig alloc] init];\n[transportConfig.listen.tcp setEnabled:true];\n[transportConfig.listen.tcp setInterfaceIp:@\"0.0.0.0\"];\n[transportConfig.listen.tcp setPort:4000];\n[ditto setTransportConfig:transportConfig];\nNSError *err = nil;\n[ditto startSync:&err];\n\n", "network-multiple-transports": "DITMutableTransportConfig *transportConfig = [[DITMutableTransportConfig alloc] init];\n// 1. Enable Local Area Network Connections\n[transportConfig enableAllPeerToPeer];\n// 2. Listen for incoming connections on port 4000\n[transportConfig.listen.tcp setEnabled:true];\n[transportConfig.listen.tcp setInterfaceIp:@\"0.0.0.0\"];\n[transportConfig.listen.tcp setPort:4000];\n// 3. Connect explicitly to remote devices\n[transportConfig.connect.tcpServers addObject:@\"135.1.5.5:12345\"];\n[transportConfig.connect.tcpServers addObject:@\"185.1.5.5:12345\"];\n\n[ditto setTransportConfig:transportConfig];\nNSError *err = nil;\n[ditto startSync:&err];\n\n", "network-monitor-conditions": "// Setting up inside a ViewController\nDITIdentity *identity = [[DITIdentity alloc] initOnlinePlaygroundWithAppID:@\"REPLACE_WITH_APP_ID\" token:@\"REPLACE_WITH_PLAYGROUND_TOKEN\"];\nDITDitto *ditto = [[DITDitto alloc] initWithIdentity:identity];\nditto.delegate = self;\n[ditto startSync:nil];\n \n// Now you can observe real time changes to the transport conditions:\n@interface ViewController () \n\n@end\n\n@implementation ViewController\n\n- (void)transportConditionChanged:(enum DITTransportCondition)condition forSubsystem:(enum DITConditionSource)source {\n if (condition == DITTransportConditionBleDisabled) {\n NSLog(@\"BLE disabled\");\n } else if (condition == DITTransportConditionNoBleCentralPermission) {\n NSLog(@\"Permission missing for BLE\");\n } else if (condition == DITTransportConditionNoBlePeripheralPermission) {\n NSLog(@\"Permission missing for BLE\");\n }\n}\n\n@end\n\n", - "network-query-overlap-group": "NSString * const orders = @\"orders\";\n\n// The passenger only observes orders that they created\n[[[passenger.store collection:orders] find:@\"user_id==abc123\"] observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n // render my orders in a list UI\n}];\n\n// Crew member devices observe all orders that everyone created\n[[[crewA.store collection:orders] findAll] observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n // render all orders in a list UI\n}];\n\n[[[crewB.store collection:orders] findAll] observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n // render all orders\n}];\n\n// Set up our query overlap group and priorities such that the crew members\n// will construct multihop connections with each other.\n[DITExperimental setQueryOverlapGroup:2 ditto:crewA];\n[DITExperimental setQueryOverlapGroup:2 ditto:crewB];\n\n// Query overlap groups should be set before tryStartSync\n[crewA tryStartSync:nil];\n[crewB tryStartSync:nil];\n[passenger tryStartSync:nil];\n\n", + "network-query-overlap-group": "NSString *const orders = @\"orders\";\n\n// The passenger only observes orders that they created\n[[[passenger.store collection:orders] find:@\"user_id==abc123\"] observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n // render my orders in a list UI\n}];\n\n// Crew member devices observe all orders that everyone created\n[[[crewA.store collection:orders] findAll] observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n // render all orders in a list UI\n}];\n\n[[[crewB.store collection:orders] findAll] observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n // render all orders\n}];\n\n// Set up our query overlap group and priorities such that the crew members\n// will construct multihop connections with each other.\n[DITExperimental setQueryOverlapGroup:2 ditto:crewA];\n[DITExperimental setQueryOverlapGroup:2 ditto:crewB];\n\n// Query overlap groups should be set before startSync\n[crewA startSync:nil];\n[crewB startSync:nil];\n[passenger startSync:nil];\n\n", "network-set-priority": "[DITExperimental setPriority:DITConnectionPriorityHigh\n forQueryOverlapGroup:2 ditto:crewA];\n[DITExperimental setPriority:DITConnectionPriorityHigh\n forQueryOverlapGroup:2 ditto:crewB];\n\n", "evict": "NSArray *evictedIDs = [[collection find:@\"make == 'Honda'\"] evict];\n\n" }, @@ -80,13 +80,13 @@ "sync-observe-local": "// --- Action somewhere in your application\nfunc userDidInsertCar() {\n _ = try! ditto.store.collection(\"cars\").upsert([\n \"model\": \"Ford\",\n \"color\": \"black\"\n ])\n}\n\n// Register live query to update UI\nlet liveQuery = ditto.store.collection(\"cars\").find(\"color == 'red'\")\n .observeLocal { cars, event in\n // do something\n }\n\n", "sync-observe": "// Register live query to update UI\nlet example = ditto.store.collection(\"cars\").find(\"color == 'red'\")\n .observe { cars, event in\n // do something\n}\n\n", "subscribe": "// Register live query to update UI\nlet subscription = ditto.store.collection(\"cars\").find(\"color == 'red'\").subscribe()\n\n", - "network-query-overlap-group": "// The passenger only observes orders that they created\npassenger.store.collection(\"orders\").find(\"user_id==abc123\").observe { docs, event in\n // render passenger orders in a list UI\n}\n\n// Crew member devices observe all orders that everyone created\ncrewA.store.collection(\"orders\").findAll().observe { docs, event in\n // render all orders in a list UI\n}\ncrewB.store.collection(\"orders\").findAll().observe { docs, event in\n // render all orders in a list UI\n}\n\n// Set up our query overlap group and priorities such that the crew members\n// will construct multihop connections with each other.\nDittoExperimental.setQueryOverlapGroup(queryOverlapGroup: 2, ditto: crewA)\nDittoExperimental.setQueryOverlapGroup(queryOverlapGroup: 2, ditto: crewB)\n\n// Query overlap groups should be set before tryStartSync\ntry! crewA.tryStartSync()\ntry! crewB.tryStartSync()\ntry! passenger.tryStartSync()\n\n", - "network-set-priority": "DittoExperimental.setPriority(DittoConnectionPriority.high, forQueryOverlapGroup: 2, ditto: crewA)\nDittoExperimental.setPriority(DittoConnectionPriority.high, forQueryOverlapGroup: 2, ditto: crewB)\n\n", "network-remote-ditto": "let config = DittoTransportConfig()\n// Connect explicitly to a remote devices\nconfig.connect.tcpServers.add(\"135.1.5.5:12345\")\nconfig.connect.tcpServers.add(\"185.1.5.5:12345\")\n\nditto.transportConfig = config\n\ndo {\n try ditto.startSync()\n} catch (let err) {\n print(err.localizedDescription)\n}\n\n", "device-name": "ditto.deviceName = \"Susan B.\"\nlet observer = ditto.observePeersV2 { json in\n let peers = DittoPeerV2Parser.parseJson(json: json)!\n if !peers.isEmpty {\n // render peers\n }\n}\n\ndo {\n try ditto.startSync()\n} catch (let err) {\n print(err.localizedDescription)\n}\n\n", "network-listen": "let config = DittoTransportConfig()\n\n// Listen for incoming connections on port 4000\nconfig.listen.tcp.isEnabled = true\nconfig.listen.tcp.interfaceIp = \"0.0.0.0\"\nconfig.listen.tcp.port = 4000\n\nditto.transportConfig = config\n\ndo {\n try ditto.startSync()\n} catch (let err) {\n print(err.localizedDescription)\n}\n\n", "network-multiple-transports": "var config = DittoTransportConfig()\n// 1. Enable All Peer to Peer Connections\nconfig.enableAllPeerToPeer()\n\n// 2. Listen for incoming connections on port 4000\nconfig.listen.tcp.isEnabled = true\nconfig.listen.tcp.interfaceIp = \"0.0.0.0\"\nconfig.listen.tcp.port = 4000\n\n// 3. Connect explicitly to remote devices\nconfig.connect.tcpServers.add(\"135.1.5.5:12345\")\nconfig.connect.tcpServers.add(\"185.1.5.5:12345\")\n\nditto.transportConfig = config\n\ndo {\n try ditto.startSync()\n} catch (let err) {\n print(err.localizedDescription)\n}\n\n", "network-monitor-conditions": "// Setting up inside a ViewController\nlet ditto = Ditto(identity: DittoIdentity.onlinePlayground(appID: \"00000000-0000-4000-0000-000000000000\", token: \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\"))\nditto.delegate = self\ntry! ditto.startSync()\n\n// Now you can observe real time changes to the transport conditions:\nextension ViewController: DittoDelegate {\n func transportConditionDidChange(transportID: Int64, condition: TransportCondition) {\n if condition == .BleDisabled {\n print(\"BLE disabled\")\n } else if condition == .NoBleCentralPermission {\n print(\"Permission missing for BLE\")\n } else if condition == .NoBlePeripheralPermission {\n print(\"Permission missing for BLE\")\n }\n }\n\n\n", + "network-query-overlap-group": "// The passenger only observes orders that they created\npassenger.store.collection(\"orders\").find(\"user_id==abc123\").observe { docs, event in\n // render passenger orders in a list UI\n}\n\n// Crew member devices observe all orders that everyone created\ncrewA.store.collection(\"orders\").findAll().observe { docs, event in\n // render all orders in a list UI\n}\ncrewB.store.collection(\"orders\").findAll().observe { docs, event in\n // render all orders in a list UI\n}\n\n// Set up our query overlap group and priorities such that the crew members\n// will construct multihop connections with each other.\nDittoExperimental.setQueryOverlapGroup(queryOverlapGroup: 2, ditto: crewA)\nDittoExperimental.setQueryOverlapGroup(queryOverlapGroup: 2, ditto: crewB)\n\n// Query overlap groups should be set before startSync\ntry! crewA.startSync()\ntry! crewB.startSync()\ntry! passenger.startSync()\n\n", + "network-set-priority": "DittoExperimental.setPriority(DittoConnectionPriority.high, forQueryOverlapGroup: 2, ditto: crewA)\nDittoExperimental.setPriority(DittoConnectionPriority.high, forQueryOverlapGroup: 2, ditto: crewB)\n\n", "evict": "collection.find(\"owner == 'Bob'\").evict()\n\n", "remove-query": "collection.find(\"owner == 'Bob'\").remove()\n\n", "remove-id": "collection.findByID(docID).remove()\n\n", @@ -163,7 +163,7 @@ "sync-basic": "try\n{\n onlineDitto.StartSync();\n}\ncatch (DittoException ex)\n{\n // handle exception\n}\n\n", "remove-query": "ditto.Store.Collection(\"people\").Find(\"age <= 32\").Remove();\n\n", "remove-id": "var wasRemoved = coll.FindById(docID).Remove();\n\n", - "counter": "var results = coll.FindById(docID).Update(mutableDoc =>\n{\n mutableDoc[\"color\"].Set(\"yellow\");\n mutableDoc[\"mileage\"].Counter.Increment(99);\n});\n\n", + "counter": "var counter = new DittoCounter();\n\nvar docID = coll.Upsert(new Dictionary {\n { \"make\", \"Honda\" }, { \"mileage\", counter }\n});\n\n_ = coll.FindById(docID).Update(mutableDoc =>\n{\n mutableDoc[\"mileage\"].Counter.Increment(100);\n});\n\n", "update": "var content = new Dictionary\n{\n { \"name\", \"Bob\" },\n { \"age\", 40 },\n { \"ownedCars\", new DittoCounter() }\n};\n\nvar docId = Ditto.Store.Collection(\"people\").Upsert(content);\nDitto.Store.Collection(\"people\").FindById(docId).Update(mutableDoc =>\n{\n mutableDoc[\"age\"].Set(32);\n mutableDoc[\"ownedCars\"].Counter.Increment(1);\n});\n\n", "evict": "Ditto.Store.Collection(\"people\").Find(\"age <= 32\").Evict();\n\n", "attachment": "string attachmentImagePath = Path.Combine(Directory.GetCurrentDirectory(), \"attachment_test.png\");\n\nvar originalBytes = File.ReadAllBytes(attachmentImagePath);\n\nvar metadata = new Dictionary { { \"name\", \"my_image.png\" } };\nvar attachment = coll.NewAttachment(attachmentImagePath, metadata);\n\nvar docId = coll.Upsert(new Dictionary { { \"some\", \"string\" }, { \"my_attachment\", attachment } });\n\nvar doc = coll.FindById(docId).Exec();\nvar attachmentToken = doc[\"my_attachment\"].AttachmentToken;\nusing var fetcher = coll.FetchAttachment(attachmentToken, ev =>\n{\n switch (ev)\n {\n case DittoAttachmentFetchEvent.Completed e:\n // Do something with attachment\n break;\n default:\n Console.WriteLine(\"Unable to fetch attachment\");\n break;\n }\n});\n\n", @@ -185,7 +185,7 @@ "sync-observe-local": "// --- Register live query to update UI\nvar localLiveQuery = ditto.Store.Collection(\"cars\").Find(\"color == 'red'\")\n .ObserveLocal((docs, dittoLiveQueryEvent) =>\n{\n // Do something...\n});\n\n", "network-remote-ditto": "DittoTransportConfig transportConfig = new DittoTransportConfig();\n// Connect explicitly to a remote device on\ntransportConfig.Connect.TcpServers.Add(\"135.1.5.5:12345\");\n// you can add as many TcpServers as you would like.\ntransportConfig.Connect.TcpServers.Add(\"185.1.5.5:4567\");\n// set the transport config\nDitto.TransportConfig = transportConfig;\n// now you can start ditto's sync\nDitto.StartSync();\n\n", "network-listen": "DittoTransportConfig transportConfig = new DittoTransportConfig();\ntransportConfig.Listen.Tcp = new DittoTcpListenConfig();\n// By default Listen.Tcp.Enabled is false, be sure to set it to true.\ntransportConfig.Listen.Tcp.Enabled = true;\n// if you want to listen on localhost, most likely you will use 0.0.0.0\n// do not use \"localhost\" as a string\ntransportConfig.Listen.Tcp.InterfaceIp = \"0.0.0.0\";\n// specify your port.\ntransportConfig.Listen.Tcp.Port = 4000;\nDitto.TransportConfig = transportConfig;\n\n// now you can call `ditto.StartSync()`\nDitto.StartSync();\n\n", - "network-multiple-transports": "DittoTransportConfig transportConfig = new DittoTransportConfig();\n\n// 1. Enable Local Area Network Connections\ntransportConfig.EnableAllPeerToPeer();\n\n// 2. Listen for incoming connections on port 4000\ntransportConfig.Listen.Tcp.Enabled = true;\ntransportConfig.Listen.Tcp.InterfaceIp = \"0.0.0.0\";\ntransportConfig.Listen.Tcp.Port = 4000;\n\n// 3. Connect explicitly to remote devices\ntransportConfig.Connect.TcpServers.Add(\"135.1.5.5:12345\");\ntransportConfig.Connect.TcpServers.Add(\"185.1.5.5:12345\");\n\nDitto.TransportConfig = transportConfig;\n\nDitto.StartSync();\n\n", + "network-multiple-transports": "DittoTransportConfig transportConfig = new DittoTransportConfig();\n\n// 1. Enable Local Area Network Connections\ntransportConfig.EnableAllPeerToPeer();\n\n// 2. Listen for incoming connections on port 4000\ntransportConfig.Listen.Tcp.Enabled = true;\ntransportConfig.Listen.Tcp.InterfaceIp = \"0.0.0.0\";\ntransportConfig.Listen.Tcp.Port = 4000;\n\n// 3. Connect explicitly to remote devices\ntransportConfig.Connect.TcpServers.Add(\"135.1.5.5:12345\");\ntransportConfig.Connect.TcpServers.Add(\"185.1.5.5:12345\");\n\nditto.TransportConfig = transportConfig;\n\nditto.StartSync();\n\n", "network-set-priority": "DittoExperimental.SetPriorityForQueryOverlapGroup(DittoConnectionPriority.High, 2, crewB);\nDittoExperimental.SetPriorityForQueryOverlapGroup(DittoConnectionPriority.High, 2, crewA);\n\n" }, "kotlin": { @@ -197,7 +197,8 @@ "upsert-datatypes": "ditto.store[\"foo\"].upsert(mapOf(\n \"boolean\" to true,\n \"string\" to \"Hello World\",\n \"number\" to 10,\n \"map\" to mapOf(\"key\" to \"value\"),\n \"array\" to listOf(1,2,3),\n \"null\" to null\n))\n\n", "write-transaction": "val results = ditto.store.write { transaction ->\n val cars = transaction.scoped(\"cars\")\n val people = transaction.scoped(\"people\")\n val docId = \"abc123\"\n people.upsert(mapOf(\"_id\" to docId, \"name\" to \"Susan\"))\n cars.upsert(mapOf(\"make\" to \"Hyundai\", \"color\" to \"red\", \"owner\" to docId))\n cars.upsert(mapOf(\"make\" to \"Jeep\", \"color\" to \"pink\", \"owner\" to docId))\n people.findByID(DittoDocumentID(docId)).evict()\n}\n\n", "counter": "val docID = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Frank\",\n \"ownedCars\" to DittoCounter()\n))\n\nditto.store.collection(\"people\").findByID(docID).update { mutableDoc ->\n mutableDoc!![\"ownedCars\"].counter!!.increment(amount = 1.0)\n}\n\n", - "update": "val frankId = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Frank\",\n \"age\" to 31,\n \"ownedCars\" to DittoCounter()\n))\n\nditto.store.collection(\"people\").findByID(frankId).update { mutableDoc ->\n mutableDoc?.let {\n it[\"age\"].set(32)\n it[\"ownedCars\"].counter!!.increment(amount = 1.0)\n }\n}\n\n", + "counter-upsert": "val frankId = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Frank\",\n \"age\" to 31,\n \"ownedCars\" to DittoCounter()\n))\n\n", + "update": "ditto.store.collection(\"people\").findByID(frankId).update { mutableDoc ->\n mutableDoc?.let {\n it[\"age\"].set(32)\n it[\"ownedCars\"].counter!!.increment(amount = 1.0)\n }\n}\n\n", "evict": "ditto.store[\"people\"].find(\"age <= 32\").evict()\n\n", "upsert-default-data": "val docId = ditto.store.collection(\"people\").upsert(mapOf(\n \"name\" to \"Susan\",\n \"age\" to 31\n), DittoWriteStrategy.InsertDefaultIfAbsent)\n\n", "device-name": "ditto.deviceName = \"Susan B.\"\nditto.startSync()\nditto.observePeersV2 { peers ->\n // render peer list\n}\n\n", @@ -209,15 +210,15 @@ "sync-observe": "// --- DittoRegister live query to update UI\nval liveQuery = ditto.store.collection(\"cars\")\n .findAll()\n .observe { docs, event ->\n // Do something...\n }\n\n", "sync-observe-local": "// --- Action somewhere in your application\nfun userDidInsertCar() {\n ditto.store.collection(\"cars\").upsert(mapOf(\n \"model\" to \"Ford\",\n \"color\" to \"black\"\n ))\n}\n\n// --- DittoRegister live query to update UI\nval observeLocalQuery = ditto.store.collection(\"cars\")\n .findAll()\n .observeLocal { docs, event ->\n // Do something...\n}\n\n", "subscribe": "// --- DittoRegister live query to update UI\nval subscription = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .subscribe()\n\n", - "online-playground": "try {\n val androidDependencies = DefaultAndroidDittoDependencies(context)\n val identity = DittoIdentity.OnlinePlayground(androidDependencies, appID = \"00000000-0000-4000-0000-000000000000\", token = \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\")\n val ditto = Ditto(androidDependencies, identity)\n ditto.startSync()\n} catch(e: DittoError) {\n Log.e(\"Ditto error\", e.message!!)\n}\n\n", - "offline-playground": "try {\n val androidDependencies = DefaultAndroidDittoDependencies(context)\n val identity = DittoIdentity.OfflinePlayground(androidDependencies, appID = \"00000000-0000-4000-0000-000000000000\")\n val ditto = Ditto(androidDependencies, identity)\n ditto.setOfflineOnlyLicenseToken(validLicense)\n ditto.startSync()\n} catch(e: DittoError) {\n Log.e(\"Ditto error\", e.message!!)\n}\n\n", + "online-playground": "try {\n val androidDependencies = DefaultAndroidDittoDependencies(context)\n val identity = DittoIdentity.OnlinePlayground(androidDependencies, appID = \"00000000-0000-4000-0000-000000000000\", token = \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\")\n val ditto = Ditto(androidDependencies, identity)\n ditto.startSync()\n} catch(e: DittoError) {\n Log.e(\"Ditto error\", e.message!!)\n}\n\n", + "offline-playground": "try {\n val androidDependencies = AndroidDittoDependencies(context)\n val identity = DittoIdentity.OfflinePlayground(androidDependencies, appID = \"00000000-0000-4000-0000-000000000000\")\n val ditto = Ditto(androidDependencies, identity)\n ditto.setOfflineOnlyLicenseToken(validLicense)\n ditto.startSync()\n} catch(e: DittoError) {\n Log.e(\"Ditto error\", e.message!!)\n}\n\n", "shared-key": "// This is just an example. You should use OpenSSL to generate a unique shared key for every application.\nval p256DerB64 = \"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFUUrOkOH52QN+Rr6uDSDsk4hUTcD1eW4mT0UnGGptFehRANCAATJ3fG8TVLQcDwUV18BJJI8efK0hQAjzB3VJeYOVbfOlqnfukVId0V25r/abxwjD3HfHuPsCGEiefzzmkMbjPo9\"\nval androidDependencies = DefaultAndroidDittoDependencies(context)\nval identity = DittoIdentity.SharedKey(\"app\", p256DerB64, null)\nval ditto = Ditto(androidDependencies, identity)\nditto.setOfflineOnlyLicenseToken(validLicense)\n\n", - "network-query-overlap-group": "// The passenger only observes orders that they created\npassenger.store.collection(\"orders\").find(\"user_id==abc123\").observe({ docs, event ->\n // render passenger orders in a list UI\n})\n\n// Crew member devices observe all orders that everyone created\ncrewA.store.collection(\"orders\").findAll().observe({ docs, event ->\n // render all orders in a list UI\n})\ncrewB.store.collection(\"orders\").findAll().observe({ docs, event ->\n // render all orders in a list UI\n})\n\nDittoExperimental.setQueryOverlapGroup(2u, crewA)\nDittoExperimental.setQueryOverlapGroup(2u, crewB)\n\ncrewA.tryStartSync()\ncrewB.tryStartSync()\npassenger.tryStartSync()\n\n", - "network-set-priority": "DittoExperimental.setPriorityForQueryOverlapGroup(DittoConnectionPriority.High, 2u, crewA)\nDittoExperimental.setPriorityForQueryOverlapGroup(DittoConnectionPriority.High, 2u, crewB)\n\n", "network-remote-ditto": "val transportConfig = DittoTransportConfig()\n\ntransportConfig.connect.tcpServers.add(\"135.1.5.5:12345\")\ntransportConfig.connect.tcpServers.add(\"185.1.5.5:12345\")\n\nditto.startSync()\n\n", "network-listen": "val transportConfig = DittoTransportConfig()\ntransportConfig.connect.tcpServers.add(\"135.1.5.5:12345\")\ntransportConfig.connect.tcpServers.add(\"185.1.5.5:12345\")\nditto.startSync()\n\n", "network-multiple-transports": "val transportConfig = DittoTransportConfig()\n// 1. Enable All Peer to Peer Connections\ntransportConfig.enableAllPeerToPeer()\n// 2. Listen for incoming connections on port 4000\ntransportConfig.listen.tcp.enabled = true\ntransportConfig.listen.http.enabled = false\ntransportConfig.listen.tcp.interfaceIp = \"0.0.0.0\"\ntransportConfig.listen.tcp.port = 4000\n// 3. Connect explicitly to remote devices\ntransportConfig.connect.tcpServers.add(\"135.1.5.5:12345\")\ntransportConfig.connect.tcpServers.add(\"185.1.5.5:12345\")\n\nditto.startSync()\n\n", "network-monitor-conditions": "// ... Setting up inside an Activity\nval androidDependencies = DefaultAndroidDittoDependencies(applicationContext)\nval ditto = Ditto(androidDependencies, DittoIdentity.OnlinePlayground(androidDependencies, appID = \"REPLACE_WITH_APP_ID\", token = \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\"))\nditto.callback = this\nditto.startSync()\n\n// Now you can observe real time changes to the transport conditions:\n\nclass MainActivity : AppCompatActivity(), DittoCallback {\n\n override fun transportConditionDidChange(transportId: Long, condition: TransportCondition) {\n var toastText: String? = null\n if (condition == TransportCondition.TRANSPORT_CONDITION_BLE_DISABLED) {\n toastText = \"BLE disabled\"\n } else if (condition == TransportCondition.TRANSPORT_CONDITION_NO_BLE_CENTRAL_PERMISSION) {\n toastText = \"Permission missing for BLE\"\n } else if (condition == TransportCondition.TRANSPORT_CONDITION_NO_BLE_PERIPHERAL_PERMISSION) {\n toastText = \"Permission missing for BLE\"\n }\n toastText?.let {\n Handler(mainLooper).post {\n Toast.makeText(this, it, Toast.LENGTH_LONG).show()\n }\n }\n }\n}\n\n", + "network-query-overlap-group": "// The passenger only observes orders that they created\npassenger.store.collection(\"orders\").find(\"user_id==abc123\").observe({ docs, event ->\n // render passenger orders in a list UI\n})\n\n// Crew member devices observe all orders that everyone created\ncrewA.store.collection(\"orders\").findAll().observe({ docs, event ->\n // render all orders in a list UI\n})\ncrewB.store.collection(\"orders\").findAll().observe({ docs, event ->\n // render all orders in a list UI\n})\n\nDittoExperimental.setQueryOverlapGroup(2u, crewA)\nDittoExperimental.setQueryOverlapGroup(2u, crewB)\n\ncrewA.startSync()\ncrewB.startSync()\npassenger.startSync()\n\n", + "network-set-priority": "DittoExperimental.setPriorityForQueryOverlapGroup(DittoConnectionPriority.High, 2u, crewA)\nDittoExperimental.setPriorityForQueryOverlapGroup(DittoConnectionPriority.High, 2u, crewB)\n\n", "remove-id": "coll.findByID(docID).remove()\n\n", "remove-query": "val removedDocIDs = coll.find(\"make == 'Honda'\").remove()\n\n" }, @@ -232,7 +233,8 @@ "evict": "ditto.store.collection(\"people\").find(\"age <= 32\").evict();\n\n", "upsert-datatypes": "// Insert JSON-compatible data into Ditto\nMap content = new HashMap<>();\ncontent.put(\"boolean\", true);\ncontent.put(\"string\", \"Hello World\");\ncontent.put(\"number\", 10);\nMap innerMap = new HashMap<>();\ninnerMap.put(\"key\", \"value\");\ncontent.put(\"map\", innerMap);\ncontent.put(\"array\", Arrays.asList(1, 2, 3));\ncontent.put(\"null\", null);\nditto.store.collection(\"foo\").upsert(content);\n\n", "counter": "Map content = new HashMap<>();\ncontent.put(\"name\", \"Frank\");\ncontent.put(\"ownedCars\", new DittoCounter());\nDittoDocumentID docID = ditto.store.collection(\"people\").upsert(content);\n\nditto.store.collection(\"people\").findByID(docID).update(mutDoc -> {\n assertThat(mutDoc).isNotNull();\n DittoMutableCounter counter = mutDoc.get(\"ownedCars\").getCounter();\n assertThat(counter).isNotNull();\n counter.increment(1);\n});\n\n", - "update": "Map content = new HashMap<>();\ncontent.put(\"name\", \"Frank\");\ncontent.put(\"age\", 31);\ncontent.put(\"ownedCars\", new DittoCounter());\nDittoDocumentID docId = ditto.store.collection(\"people\").upsert(content);\n\nditto.store.collection(\"people\").findByID(docId).update(doc -> {\n try {\n doc.get(\"age\").set(32);\n doc.get(\"ownedCars\").getCounter().increment(1);\n } catch (DittoError err) {\n // Do something with error\n }\n});\n\n", + "counter-upsert": "Map content = new HashMap<>();\ncontent.put(\"name\", \"Frank\");\ncontent.put(\"age\", 31);\ncontent.put(\"ownedCars\", new DittoCounter());\nDittoDocumentID docId = ditto.store.collection(\"people\").upsert(content);\n\n", + "update": "ditto.store.collection(\"people\").findByID(docId).update(doc -> {\n try {\n doc.get(\"age\").set(32);\n doc.get(\"ownedCars\").getCounter().increment(1);\n } catch (DittoError err) {\n // Do something with error\n }\n});\n\n", "device-name": "ditto.deviceName = \"Susan B.\";\ntry {\n ditto.startSync();\n} catch(DittoError e) {\n // handle error\n}\nditto.observePeersV2(peers -> {\n // render peers\n});\n\n", "upsert-default-data": "Map content = new HashMap<>();\ncontent.put(\"name\", \"Susan\");\ncontent.put(\"age\", 31);\nDittoDocumentID docId = ditto.store\n .collection(\"people\")\n .upsert(content, DittoWriteStrategy.InsertDefaultIfAbsent);\n\n", "query-basic": "List results = ditto.store.collection(\"people\")\n .find(\"favoriteBook.title == 'The Great Gatsby'\")\n .exec();\n\n",