Skip to content

Commit 5b980ab

Browse files
kinyoklionjoker23
andauthored
feat: add an initial connection mode to the FDv2 data system config (#318)
Adds `DataSystemConfig.initialConnectionMode` so an application can choose the connection mode the FDv2 data system starts in. Setting it is equivalent to calling `setConnectionMode` with that mode immediately after the client is created: it is a sticky override. While a mode is set this way the SDK stays in it and does not switch automatically in response to application lifecycle or network changes. Clearing the override (`setConnectionMode(null)`) resumes automatic resolution. When the option is null (the default) the SDK resolves the mode automatically, starting in streaming while in the foreground. It is typed as `ConnectionModeId` rather than the FDv1 `ConnectionMode` enum so it can reach the FDv2 built-in modes (including `background`) and, later, custom modes. When a data system is configured, the FDv1 `DataSourceConfig.initialConnectionMode` no longer influences the connection mode. The SDK now starts in streaming and lets the data system configuration and connection manager resolve the effective mode, and the FDv1 option is documented as having no effect under FDv2. The Flutter wiring that consumes this option (`setConnectionMode(ConnectionModeId)` and applying the initial override) stacks on top of this PR. SDK-2187 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > FDv2-enabled clients that previously relied on DataSourceConfig.initialConnectionMode will now always bootstrap in streaming until data-system resolution runs, which is a deliberate behavior shift in connection startup. > > **Overview** > Adds **`DataSystemConfig.initialConnectionMode`** (`ConnectionModeId?`) so FDv2 apps can pick the connection mode at startup. Documented behavior matches a post-create **`setConnectionMode`** sticky override: while set, the SDK does not auto-switch on lifecycle/network; **`null`** restores automatic resolution (default: auto, foreground streaming). > > When **`dataSystem`** is configured, **`LDCommonClient`** no longer seeds **`DataSourceManager`** from **`DataSourceConfig.initialConnectionMode`**; it always starts in **streaming** and defers effective mode to the FDv2 data system / connection manager. **`DataSourceConfig.initialConnectionMode`** is documented as **ignored under FDv2** in favor of the new field. > > Applying the config value at runtime is expected in follow-on Flutter wiring; this change is the config surface and FDv1/FDv2 split at client construction. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a546858. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: joker23 <2494686+joker23@users.noreply.github.com>
1 parent df64f8e commit 5b980ab

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/common_client/lib/src/config/data_system_config.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,21 @@ final class DataSystemConfig {
7373
/// their built-in definition.
7474
final Map<ConnectionModeId, ModeDefinition> connectionModes;
7575

76+
/// The connection mode the SDK starts in.
77+
///
78+
/// Setting this is equivalent to calling `setConnectionMode` with the
79+
/// same mode immediately after the client is created.
80+
/// While a mode is set this way the SDK stays in it and does
81+
/// not switch automatically in response to application lifecycle or
82+
/// network changes. Call `setConnectionMode(null)` to clear the override
83+
/// and resume automatic mode resolution.
84+
///
85+
/// When null (the default) the SDK resolves the connection mode
86+
/// automatically, starting in streaming while in the foreground.
87+
final ConnectionModeId? initialConnectionMode;
88+
7689
const DataSystemConfig({
7790
this.connectionModes = const {},
91+
this.initialConnectionMode,
7892
});
7993
}

packages/common_client/lib/src/ld_common_client.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ final class LDCommonClient {
284284
_dataSourceManager = DataSourceManager(
285285
startingMode: _config.offline
286286
? ConnectionMode.offline
287-
: _config.dataSourceConfig.initialConnectionMode,
287+
// Under the FDv2 data system the connection mode is governed by
288+
// the data system configuration (and the connection manager),
289+
// not the FDv1 data source options; start in streaming and let
290+
// that machinery resolve the effective mode.
291+
: _config.dataSystem != null
292+
? ConnectionMode.streaming
293+
: _config.dataSourceConfig.initialConnectionMode,
288294
statusManager: _dataSourceStatusManager,
289295
dataSourceEventHandler: dataSourceEventHandler,
290296
logger: _logger);

packages/common_client/lib/src/ld_common_config.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ final class DataSourceConfig {
4949
bool evaluationReasons;
5050

5151
/// The mode to use for connections when the SDK is initialized.
52+
///
53+
/// This has no effect when the FDv2 data system is enabled (a
54+
/// [DataSystemConfig] is provided). In that case use
55+
/// [DataSystemConfig.initialConnectionMode] instead.
5256
ConnectionMode initialConnectionMode;
5357

5458
/// Settings for the SDK polling data source.
@@ -69,6 +73,10 @@ final class DataSourceConfig {
6973
/// [ConnectionMode.offline] then the data source will not request data from
7074
/// LaunchDarkly, but the sending of events will be unaffected. In order
7175
/// to completely disable network activity use [LDConfig.offline].
76+
///
77+
/// This option has no effect when the FDv2 data system is enabled (a
78+
/// [DataSystemConfig] is provided); use
79+
/// [DataSystemConfig.initialConnectionMode] in that case.
7280
DataSourceConfig(
7381
{bool? useReport,
7482
bool? evaluationReasons,

0 commit comments

Comments
 (0)