Skip to content

Commit 33431eb

Browse files
feat: Add support for WASM (#191)
**Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** #182
1 parent 6c3d892 commit 33431eb

File tree

14 files changed

+60
-69
lines changed

14 files changed

+60
-69
lines changed

apps/flutter_client_contract_test_service/pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,28 +393,28 @@ packages:
393393
path: "../../packages/common_client"
394394
relative: true
395395
source: path
396-
version: "1.4.1"
396+
version: "1.5.0"
397397
launchdarkly_dart_common:
398398
dependency: "direct overridden"
399399
description:
400400
path: "../../packages/common"
401401
relative: true
402402
source: path
403-
version: "1.3.0"
403+
version: "1.4.0"
404404
launchdarkly_event_source_client:
405405
dependency: "direct overridden"
406406
description:
407407
path: "../../packages/event_source_client"
408408
relative: true
409409
source: path
410-
version: "1.0.0"
410+
version: "1.1.0"
411411
launchdarkly_flutter_client_sdk:
412412
dependency: "direct main"
413413
description:
414414
path: "../../packages/flutter_client_sdk"
415415
relative: true
416416
source: path
417-
version: "4.9.0"
417+
version: "4.10.0"
418418
lints:
419419
dependency: "direct dev"
420420
description:

apps/sse_contract_test_service/pubspec.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ packages:
311311
path: "../../packages/event_source_client"
312312
relative: true
313313
source: path
314-
version: "1.0.0"
314+
version: "1.1.0"
315315
lints:
316316
dependency: "direct dev"
317317
description:
@@ -632,6 +632,14 @@ packages:
632632
url: "https://pub.dev"
633633
source: hosted
634634
version: "1.1.0"
635+
web:
636+
dependency: transitive
637+
description:
638+
name: web
639+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
640+
url: "https://pub.dev"
641+
source: hosted
642+
version: "1.1.1"
635643
web_socket_channel:
636644
dependency: transitive
637645
description:

packages/common/lib/src/config/defaults/common_default_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '../../ld_logging.dart';
22
import 'stub_config.dart'
33
if (dart.library.io) 'io_config.dart'
4-
if (dart.library.html) 'js_config.dart';
4+
if (dart.library.js_interop) 'js_config.dart';
55

66
final class DefaultLoggingConfig {
77
final defaultLogLevel = LDLogLevel.info;

packages/common/lib/src/network/http_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '../config/defaults/common_default_config.dart';
44
import '../config/http_properties.dart';
55
import 'platform_client/stub_client.dart'
66
if (dart.library.io) 'platform_client/io_client.dart'
7-
if (dart.library.html) 'platform_client/js_client.dart';
7+
if (dart.library.js_interop) 'platform_client/js_client.dart';
88
import 'utils.dart';
99

1010
/// Http requests methods supported by the HTTP client.

packages/common_client/lib/src/config/defaults/default_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'stub_config.dart'
22
if (dart.library.io) 'io_config.dart'
3-
if (dart.library.html) 'js_config.dart';
3+
if (dart.library.js_interop) 'js_config.dart';
44

55
/// Configuration common to web and mobile is contained in this file.
66
///

packages/event_source_client/lib/launchdarkly_event_source_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'src/http_consts.dart';
77
import 'src/message_event.dart';
88
import 'src/sse_client_stub.dart'
99
if (dart.library.io) 'src/sse_client_http.dart'
10-
if (dart.library.html) 'src/sse_client_html.dart';
10+
if (dart.library.js_interop) 'src/sse_client_html.dart';
1111

1212
export 'src/message_event.dart' show MessageEvent;
1313

packages/event_source_client/lib/src/sse_client_html.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import 'dart:async';
2-
// ignore: deprecated_member_use
3-
import 'dart:html' as html;
2+
import 'dart:js_interop';
3+
import 'package:web/web.dart' as web;
44
import 'dart:math' as math;
55

66
import '../launchdarkly_event_source_client.dart';
77

88
import 'backoff.dart';
99
import 'message_event.dart' as ld_message_event;
1010

11-
/// An [SSEClient] that uses the [html.EventSource] available on most browsers for web platform support.
11+
/// An [SSEClient] that uses the [web.EventSource] available on most browsers for web platform support.
1212
class HtmlSseClient implements SSEClient {
1313
/// The underlying eventsource
14-
html.EventSource? _eventSource;
14+
web.EventSource? _eventSource;
1515

1616
/// This controller is for the events going to the subscribers of this client.
1717
late final StreamController<ld_message_event.MessageEvent>
@@ -54,27 +54,29 @@ class HtmlSseClient implements SSEClient {
5454
}
5555

5656
void _setupConnection() {
57-
_eventSource = html.EventSource(_uri.toString());
57+
_eventSource = web.EventSource(_uri.toString());
5858

5959
for (var eventType in _eventTypes) {
60-
_eventSource?.addEventListener(eventType, _handleMessageEvent);
60+
_eventSource?.addEventListener(eventType, _handleMessageEvent.toJS);
6161
}
62-
_eventSource?.addEventListener('error', _handleError);
62+
_eventSource?.addEventListener('error', _handleError.toJS);
6363
}
6464

65-
void _handleError(html.Event event) {
65+
void _handleError(web.Event event) {
6666
// The browser event source errors are reasonably opaque, if we could
6767
// determine the type of condition, then this is where we would
6868
// determine if this was a temporary or permanent failure.
6969
restart();
7070
}
7171

72-
void _handleMessageEvent(html.Event event) {
72+
void _handleMessageEvent(web.Event event) {
7373
_activeSince = DateTime.now().millisecondsSinceEpoch;
74-
final messageEvent = event as html.MessageEvent;
75-
final ldMessageEvent = ld_message_event.MessageEvent(
76-
messageEvent.type, messageEvent.data, messageEvent.lastEventId);
77-
_messageEventsController.sink.add(ldMessageEvent);
74+
final messageEvent = event as web.MessageEvent;
75+
if (messageEvent.data != null && messageEvent.data.typeofEquals('string')) {
76+
final ldMessageEvent = ld_message_event.MessageEvent(messageEvent.type,
77+
(messageEvent.data as JSString).toDart, messageEvent.lastEventId);
78+
_messageEventsController.sink.add(ldMessageEvent);
79+
}
7880
}
7981

8082
/// Subscribe to this [stream] to receive events and sometimes errors. The first

packages/event_source_client/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ environment:
99

1010
dependencies:
1111
http: ^1.1.0
12+
web: ^1.1.1
1213

1314
dev_dependencies:
1415
test: ^1.24.3

packages/flutter_client_sdk/example/.metadata

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: "0f7f08d5354856ea41930f2c178a96ca97518d5a"
8-
channel: "master"
7+
revision: "ea121f8859e4b13e47a8f845e4586164519588bc"
8+
channel: "stable"
99

1010
project_type: app
1111

1212
# Tracks metadata for the flutter migrate command
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
17-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
16+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
17+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
1818
- platform: android
19-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
20-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
19+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
20+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
2121
- platform: ios
22-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
23-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
22+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
23+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
2424
- platform: linux
25-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
26-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
25+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
26+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
2727
- platform: macos
28-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
29-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
28+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
29+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
3030
- platform: web
31-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
32-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
31+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
32+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
3333
- platform: windows
34-
create_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
35-
base_revision: 0f7f08d5354856ea41930f2c178a96ca97518d5a
34+
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
35+
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
3636

3737
# User provided section
3838

packages/flutter_client_sdk/example/web/index.html

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<meta name="description" content="A new Flutter project.">
2222

2323
<!-- iOS meta tags & icons -->
24-
<meta name="apple-mobile-web-app-capable" content="yes">
24+
<meta name="mobile-web-app-capable" content="yes">
2525
<meta name="apple-mobile-web-app-status-bar-style" content="black">
2626
<meta name="apple-mobile-web-app-title" content="example">
2727
<link rel="apple-touch-icon" href="icons/Icon-192.png">
@@ -31,29 +31,8 @@
3131

3232
<title>example</title>
3333
<link rel="manifest" href="manifest.json">
34-
35-
<script>
36-
// The value below is injected by flutter build, do not touch.
37-
const serviceWorkerVersion = null;
38-
</script>
39-
<!-- This script adds the flutter initialization JS code -->
40-
<script src="flutter.js" defer></script>
4134
</head>
4235
<body>
43-
<script>
44-
window.addEventListener('load', function(ev) {
45-
// Download main.dart.js
46-
_flutter.loader.loadEntrypoint({
47-
serviceWorker: {
48-
serviceWorkerVersion: serviceWorkerVersion,
49-
},
50-
onEntrypointLoaded: function(engineInitializer) {
51-
engineInitializer.initializeEngine().then(function(appRunner) {
52-
appRunner.runApp();
53-
});
54-
}
55-
});
56-
});
57-
</script>
36+
<script src="flutter_bootstrap.js" async></script>
5837
</body>
5938
</html>

0 commit comments

Comments
 (0)