diff --git a/packages/flutter_client_sdk/lib/launchdarkly_flutter_client_sdk.dart b/packages/flutter_client_sdk/lib/launchdarkly_flutter_client_sdk.dart index 04bb27a2..67b443c1 100644 --- a/packages/flutter_client_sdk/lib/launchdarkly_flutter_client_sdk.dart +++ b/packages/flutter_client_sdk/lib/launchdarkly_flutter_client_sdk.dart @@ -80,7 +80,9 @@ export 'package:launchdarkly_common_client/launchdarkly_common_client.dart' StreamingInitializer, PollingSynchronizer, StreamingSynchronizer, - Fdv1FallbackConfig; + Fdv1FallbackConfig, + SSEClient, + SseClientBuilder; export 'src/ld_client.dart' show LDClient; export 'src/config/ld_config.dart' show LDConfig, ApplicationEvents; diff --git a/packages/flutter_client_sdk/lib/src/config/ld_config.dart b/packages/flutter_client_sdk/lib/src/config/ld_config.dart index b5b7493f..f3925cf5 100644 --- a/packages/flutter_client_sdk/lib/src/config/ld_config.dart +++ b/packages/flutter_client_sdk/lib/src/config/ld_config.dart @@ -94,6 +94,16 @@ final class LDConfig extends LDCommonConfig { /// [dataSystem] opts the SDK into the FDv2 data acquisition protocol. /// This feature is not stable, and not subject to any backwards /// compatibility guarantees or semantic versioning. It is in early access. + /// + /// [eventSource] builds the SSE client that the SDK uses for streaming. + /// When it is null, the SDK uses the default client for the platform. On + /// web, that is the browser `EventSource`. It cannot send a request body + /// or report an HTTP error, so [DataSourceConfig.useReport] falls back to + /// GET and [DataSystemConfig.usePost] falls back to polling. Pass + /// `SSEClient.http` to stream with `fetch()` instead. Both methods then + /// work on web. Pass only a client that can send a request body. Most + /// applications do not need this option. A web build that leaves it null + /// does not include the HTTP-based client. LDConfig(super.sdkCredential, super.autoEnvAttributes, {super.applicationInfo, super.httpProperties, @@ -108,7 +118,8 @@ final class LDConfig extends LDCommonConfig { ApplicationEvents? applicationEvents, super.hooks, List? plugins, - super.dataSystem}) + super.dataSystem, + super.eventSource}) : applicationEvents = applicationEvents ?? ApplicationEvents(), plugins = plugins != null ? UnmodifiableListView(List.from(plugins)) : null; diff --git a/packages/flutter_client_sdk/pubspec.yaml b/packages/flutter_client_sdk/pubspec.yaml index a6e3918b..c3a480b7 100644 --- a/packages/flutter_client_sdk/pubspec.yaml +++ b/packages/flutter_client_sdk/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: sdk: flutter package_info_plus: ">=4.2.0 <11.0.0" device_info_plus: ">=9.1.1 <14.0.0" - launchdarkly_common_client: 1.15.1 + launchdarkly_common_client: 1.16.0 shared_preferences: ^2.2.2 connectivity_plus: ">=5.0.2 <8.0.0" web: ^1.1.1 diff --git a/packages/flutter_client_sdk/test/ld_config_streaming_test.dart b/packages/flutter_client_sdk/test/ld_config_streaming_test.dart new file mode 100644 index 00000000..dabbacca --- /dev/null +++ b/packages/flutter_client_sdk/test/ld_config_streaming_test.dart @@ -0,0 +1,17 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:launchdarkly_flutter_client_sdk/launchdarkly_flutter_client_sdk.dart'; + +void main() { + test('eventSource is null by default', () { + final config = LDConfig('credential', AutoEnvAttributes.disabled); + + expect(config.eventSource, isNull); + }); + + test('eventSource is stored in the configuration', () { + final config = LDConfig('credential', AutoEnvAttributes.disabled, + eventSource: SSEClient.http); + + expect(config.eventSource, same(SSEClient.http)); + }); +}