Best way to use NKN client on Flutter (Android)?

Hi,

A little bit of background first.
In my house i have an MQTT server running which in turn is my endpoint to control certain aspects of my house (lights, power, music, …).

What i want to do is:

  1. Expose MQTT data over “a protocol” that can be used with Android.
  2. Add controls for that data in a flutter based app to control my house.

I can make this work when it’s in a local network as i can just do direct http calls.

I’m searching for a way to make this work when i’m not locally connected. In the pre-nkn-era times one would make a REST or even GraphQL API with some authentication on top to access that data securely.

To me it seems like this would be a perfectly fine usecase to use NKN to get that data.
But how? As far as i’m aware there is no NKN client library written in Dart (flutter is made in Dart).

On a related note. Can NKN also be used as “proxy” and if so, how? As it would be totally awesome if i can use NKN as a secured proxy and basically thread url’s as if i’m calling them locally. That would prevent the need to make a wrapper API in this case. Then again, once there is a connection between <app> and <home> it’s not that difficult to make a wrapper function that executes url’s (send from <app>) in <home> and send the result back to <app> thus in effect a (kind of) proxy too.

I’m curious what you folks think of this.
Perhaps there are wildly different possibilities that i haven’t even thought of yet?

Cheers,
Mark

You got this question just on time! You probably know that we are going to release new nMobile very soon. The new nMobile is written using Flutter. Currently the main function of nMobile is chatting, which uses NKN client to send and receive messages.

We didn’t use Dart SDK because of efficiency: each message sent by NKN client needs to be cryptographically signed, but signing in Dart is way too slow, only around 1/100 of the native speed, kind of similar to js. So sending a message in a large group (many signatures are required) will take a non-trivial amount of time, slowing down the application significantly.

The way we use NKN client in Flutter is to use iOS/Android native SDK + Flutter message channel. This way performance is no longer an issue. In the future we can probably wrap everything into a single Flutter plugin to make it easier for other people to use it, but we haven’t done it yet.

The iOS/Android native SDK can be get by using gomobile to compile the Go SDK: https://github.com/nknorg/nkn-sdk-go#compiling-to-iosandroid-native-library

If you want to give it a try, please let me know if you have any problems :slight_smile:

That is exactly the kind of functionality i need to get this implemented! Awesome :smiley:

Oh my :stuck_out_tongue:
So, i’m new to flutter and new to android development in general. I’m still googling a LOT of that and easily get lost in errors. So now i need to:

  1. compile the nkn sdk to android native (the command is there, yay!)
  2. somehow get that installed with my app
  3. somehow interact with it though that flutter message channel

I don’t just see “problems” :stuck_out_tongue: I see mountains!
Looks like i’m going to be learning a lot of new stuff!