Skip to content

Commit 3929c87

Browse files
committed
refactor: use updateTransportConfig closure/lambda to configure transports
refactor: use updateTransportConfig closure/lambda to configure transports
1 parent 7e8eaed commit 3929c87

File tree

7 files changed

+58
-48
lines changed

7 files changed

+58
-48
lines changed

android-java/app/src/main/java/com/example/dittotasks/MainActivity.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ void initDitto() {
105105
DITTO_AUTH_URL);
106106
ditto = new Ditto(androidDependencies, identity);
107107

108-
// Set the Ditto Websocket URL
109-
DittoTransportConfig config = new DittoTransportConfig();
110-
config.getConnect().getWebsocketUrls().add(DITTO_WEBSOCKET_URL);
108+
ditto.updateTransportConfig(config -> {
109+
config.getConnect().getWebsocketUrls().add(DITTO_WEBSOCKET_URL);
111110

112-
// Enable all P2P transports
113-
config.enableAllPeerToPeer();
114-
ditto.setTransportConfig(config);
111+
// Enable all P2P transports
112+
config.enableAllPeerToPeer();
113+
114+
return null;
115+
});
115116

116117
// disable sync with v3 peers, required for DQL
117118
ditto.disableSyncWithV3();

android-kotlin/QuickStartTasks/app/src/main/java/live/ditto/quickstart/tasks/TasksApplication.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ class TasksApplication : Application() {
5353
)
5454

5555
ditto = Ditto(androidDependencies, identity)
56+
ditto.updateTransportConfig { config ->
57+
// Set the Ditto Websocket URL
58+
config.connect.websocketUrls.add(webSocketURL)
5659

57-
// Set the Ditto Websocket URL
58-
val transportConfig = DittoTransportConfig()
59-
transportConfig.connect.websocketUrls.add(webSocketURL)
60-
61-
// Enable all P2P transports
62-
transportConfig.enableAllPeerToPeer()
63-
ditto.transportConfig = transportConfig
60+
// Enable all P2P transports
61+
config.enableAllPeerToPeer()
62+
}
6463

6564
// disable sync with v3 peers, required for DQL
6665
ditto.disableSyncWithV3()

dotnet-maui/DittoMauiTasksApp/MauiProgram.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ private static Ditto SetupDitto()
5050
PlaygroundToken,
5151
false, // This is required to be set to false to use the correct URLs
5252
authUrl));
53-
54-
ditto.TransportConfig.Connect.WebsocketUrls.Add(websocketUrl);
55-
// Optionally enable all P2P transports if using P2P Sync
56-
// Do not call this if only using Ditto Cloud Sync
57-
ditto.TransportConfig.Connect.WebsocketUrls.Add(websocketUrl);
53+
54+
ditto.UpdateTransportConfig(config =>
55+
{
56+
// Add the websocket URL to the transport configuration.
57+
config.Connect.WebsocketUrls.Add(websocketUrl);
58+
59+
// Optionally enable all P2P transports if using P2P Sync
60+
// Do not call this if only using Ditto Cloud Sync
61+
config.EnableAllPeerToPeer();
62+
});
5863

5964
// disable sync with v3 peers, required for DQL
6065
ditto.DisableSyncWithV3();

dotnet-tui/DittoDotNetTasksConsole/TasksPeer.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ public TasksPeer(string appId, string playgroundToken, string authUrl, string we
7373
authUrl);
7474

7575
ditto = new Ditto(identity, tempDir);
76-
77-
// Optionally enable all P2P transports if using P2P Sync
78-
// Do not call this if only using Ditto Cloud Sync
79-
ditto.TransportConfig.EnableAllPeerToPeer();
80-
81-
// Add the websocket URL to the transport configuration.
82-
ditto.TransportConfig.Connect.WebsocketUrls.Add(websocketUrl);
76+
77+
ditto.UpdateTransportConfig(config =>
78+
{
79+
// Add the websocket URL to the transport configuration.
80+
config.Connect.WebsocketUrls.Add(websocketUrl);
81+
82+
// Optionally enable all P2P transports if using P2P Sync
83+
// Do not call this if only using Ditto Cloud Sync
84+
config.EnableAllPeerToPeer();
85+
});
8386

8487
// disable sync with v3 peers, required for DQL
8588
ditto.DisableSyncWithV3();

dotnet-winforms/TasksApp/TasksPeer.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ public TasksPeer(string appId, string playgroundToken, string authUrl, string we
7070
authUrl);
7171

7272
ditto = new Ditto(identity, dir);
73-
74-
// Optionally enable all P2P transports if using P2P Sync
75-
// Do not call this if only using Ditto Cloud Sync
76-
ditto.TransportConfig.EnableAllPeerToPeer();
77-
78-
// Add the websocket URL to the transport configuration.
79-
ditto.TransportConfig.Connect.WebsocketUrls.Add(websocketUrl);
73+
74+
ditto.UpdateTransportConfig(config =>
75+
{
76+
// Add the websocket URL to the transport configuration.
77+
config.Connect.WebsocketUrls.Add(websocketUrl);
78+
79+
// Optionally enable all P2P transports if using P2P Sync
80+
// Do not call this if only using Ditto Cloud Sync
81+
config.EnableAllPeerToPeer();
82+
});
8083

8184
// disable sync with v3 peers, required for DQL
8285
ditto.DisableSyncWithV3();

java-spring/src/main/java/com/ditto/example/spring/quickstart/service/DittoService.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,16 @@ public class DittoService implements DisposableBean {
6868
// disable sync with v3 peers, required for DQL
6969
this.ditto.disableSyncWithV3();
7070

71-
DittoTransportConfig transportConfig = new DittoTransportConfig.Builder()
72-
.connect(connect -> {
73-
// Set the Ditto Websocket URL
74-
connect.addWebsocketUrls(DittoSecretsConfiguration.DITTO_WEBSOCKET_URL);
75-
})
76-
.build();
71+
this.ditto.updateTransportConfig(config -> {
72+
config.connect(connect -> {
73+
connect.websocketUrls().add(DittoSecretsConfiguration.DITTO_WEBSOCKET_URL);
74+
});
7775

78-
logger.info("Transport config: {}", transportConfig);
76+
// Enable all P2P transports
77+
config.peerToPeer();
7978

80-
this.ditto.setTransportConfig(
81-
transportConfig
82-
);
79+
logger.info("Transport config: {}", config);
80+
});
8381

8482
presenceObserver = observePeersPresence();
8583

swift/tasks/tasks/DittoManager.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ class DittoManager: ObservableObject {
1818
customAuthURL: URL(string: Env.DITTO_AUTH_URL)
1919
)
2020
)
21-
// Set the Ditto Websocket URL
22-
var config = DittoTransportConfig()
23-
config.connect.webSocketURLs.insert(Env.DITTO_WEBSOCKET_URL)
2421

25-
// Enable all P2P transports
26-
config.enableAllPeerToPeer()
27-
ditto.transportConfig = config
22+
ditto.updateTransportConfig { config in
23+
// Set the Ditto Websocket URL
24+
config.connect.webSocketURLs.insert(Env.DITTO_WEBSOCKET_URL)
25+
26+
// Enable all P2P transports
27+
config.enableAllPeerToPeer()
28+
}
2829

2930
// disable sync with v3 peers, required for DQL
3031
do {

0 commit comments

Comments
 (0)