Skip to content

refactor(java,kotlin): use updateTransportConfig lambda to configure transports #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ void initDitto() {
DITTO_AUTH_URL);
ditto = new Ditto(androidDependencies, identity);

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

// Enable all P2P transports
config.enableAllPeerToPeer();
ditto.setTransportConfig(config);
// lambda must return Kotlin Unit which corresponds to 'void' in Java
return kotlin.Unit.INSTANCE;
});

// disable sync with v3 peers, required for DQL
ditto.disableSyncWithV3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,10 @@ class TasksApplication : Application() {
)

ditto = Ditto(androidDependencies, identity)

// Set the Ditto Websocket URL
val transportConfig = DittoTransportConfig()
transportConfig.connect.websocketUrls.add(webSocketURL)

// Enable all P2P transports
transportConfig.enableAllPeerToPeer()
ditto.transportConfig = transportConfig
ditto.updateTransportConfig { config ->
// Set the Ditto Websocket URL
config.connect.websocketUrls.add(webSocketURL)
}

// disable sync with v3 peers, required for DQL
ditto.disableSyncWithV3()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,14 @@ public class DittoService implements DisposableBean {
// disable sync with v3 peers, required for DQL
this.ditto.disableSyncWithV3();

DittoTransportConfig transportConfig = new DittoTransportConfig.Builder()
.connect(connect -> {
// Set the Ditto Websocket URL
connect.addWebsocketUrls(DittoSecretsConfiguration.DITTO_WEBSOCKET_URL);
})
.build();

logger.info("Transport config: {}", transportConfig);

this.ditto.setTransportConfig(
transportConfig
);
this.ditto.updateTransportConfig(config -> {
config.connect(connect -> {
// Set the Ditto Websocket URL
connect.websocketUrls().add(DittoSecretsConfiguration.DITTO_WEBSOCKET_URL);
});

logger.info("Transport config: {}", config);
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a comment or further context on what aspects of the transport config are logged to improve the clarity and usefulness of the debug information.

Copilot uses AI. Check for mistakes.

});

presenceObserver = observePeersPresence();

Expand Down
Loading