-
Notifications
You must be signed in to change notification settings - Fork 179
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
Support WebAssembly compilation #528
Conversation
I should have the bandwidth to do some proper testing on this during this coming weekend (as well as resolve the conflict). I'm still not familiar enough with AWS to know rather the policy attachment code is still necessary/how to fix. |
Ok thanks leave AWS for now we can address this later when we know we have a good working package. |
@shamblett Hey Steve. I'm back on this again because we have returned to using MQTT at my work, so I am able to work on this as an extension of my work. I rebased this yesterday and reapplied the changes, but I'm noticing something very odd. We are using the nanomq broker (version 0.22.2), and I am unable to connect like normal on the web side at all (Not using webassembly yet - just the regular Flutter web compiler). My connection setup looks like: Future<void> initializeClient(String mClientID) async {
final connMessage = MqttConnectMessage()
.withClientIdentifier(mClientID)
.withWillTopic('will')
.withWillMessage('Client disconnected unexpectedly')
.withWillQos(MqttQos.atLeastOnce)
.startClean();
client = MqttBrowserClient('ws://127.0.0.1/mqtt', mClientID)
..onConnected = onConnected
..onDisconnected = onDisconnected
..onUnsubscribed = onUnsubscribed
..onSubscribed = onSubscribed
..onSubscribeFail = onSubscribeFail
..pongCallback = pong
..keepAlivePeriod = 60
..port = 8083
..connectionMessage = connMessage
..autoReconnect = true
..websocketProtocols = MqttClientConstants.protocolsSingleDefault
..setProtocolV311();
dPrint('MQTT_LOGS:: MQTT client connecting....');
try {
await client?.connect();
} catch (e) {
dPrint('MQTT_LOGS:: $e');
}
} I enabled logging, and I noticed the protocol version in the connection string was 3 instead of the expected 4. I changed the default in mqtt_client_protocol.dart to the V311 constants, and it instantly connected. Is there any reason it might not be respecting Aside from that, I'm still getting an exception when compiling to WebAssembly even with the local change to mqtt_client_protocol.dart, so this still isn't ready yet. I did clean up the AWS implementation to fully drop sigv4, but I don't have an environment to test this (yet). |
Hi Tyler. Setting the ..setProtocolV311(); should work however whilst checking I've noticed a bug in the code, this only works if you declare your connect message after creating your client, i.e. in your code above put the connmessage after the browserclient creation. I'll fix this, also I think I'll make 311 the default rather than 3, some brokers(as you have seen) are more sensitive to this than others. Most users/brokers will expect 311 these days. Thanks for the web assembly work BTW. Please post any client logs you may have if you want me to look at anything. |
Merged this, any further work identified will be carried out on branch issue503 |
This is a PR to address #503 and support WebAssembly compilation. Due to the testing required and additional work to be done, this PR was opened as a draft.
What this commit does:
MqttBrowserClient
is a class purely targeted for browsers, so it should not be handling non-browser environments. I am currently using mqtt_client in a monorepo solution that targets desktop + web, and was able to solve fix(lib/mqtt_browser_client): switch dart:html to universal_html #509 using conditional imports.example/aws_iot_cognito.dart
is deleted, and the sigv4 dependency is removed. AWS Amplify is the suggested framework for working with AWS now, along with it being first party. The recently addedaws_iot_cognito_amplify.dart
does a lot of heavy lifting and showcases how to use MQTT with AWS. Droppingexample/aws_iot_cognito.dart
is probably acceptable.What work still needs to get done:
Inexample/aws_iot_cognito_amplify.dart
, the portion regarding the policy attachment has been commented out as it relied on the now-removed sigv4 dependency. I'm not familiar enough with AWS or AWS Amplify to know if this portion is still necessary or how to update it with AWS Amplify functions.