kuzzleio / sdk-dart

Dart SDK developed for Flutter to interact with Kuzzle API for database storage and search, user authentication and realtime notifications
MIT License
17 stars 4 forks source link

Kuzzle not compatible with future update (Flutter beta branch) #58

Closed proformance closed 3 years ago

proformance commented 3 years ago

Hi!

The snippet below works well on the master branch of Flutter, but when using Flutter on the beta-branch it doesn't seem to work anymore, it complains about http not being supported.

@override
void initState() {
  _kuzzle = Kuzzle(WebSocketProtocol(Uri(
    scheme: 'ws',
    host: '10.0.2.2',
    port: 7512,
  )));
  // Etablish the connection
  _kuzzle.connect().then((_) {
    _initData();
    _fetchMessages();
    _subscribeToNewMessages();
  });
  super.initState();
}

Link to snippet in Kuzzle - Getting started guide

This is the flutter-commit that causes this issue: https://github.com/dart-lang/sdk/commit/ae0fbde71c23c9353b1095d1f480c5e239927abd

Best regards

proformance commented 3 years ago

I found a solution, the introduced restriction is that SSL needs to be used. In order to solve this wss (WebSocket Secure) needs to be used instead of ws (WebSocket).

So what I did was to create a certificate using letsencrypt, and then configure nginx according to https://blog.kuzzle.io/secure-kuzzle-nginx-and-ssl

Last but not least, instead of using

_kuzzle = Kuzzle(WebSocketProtocol(Uri(
    scheme: 'ws',
    host: 'yourdomain',
    port: 7512,
  )));

I used

    _kuzzle = Kuzzle(WebSocketProtocol(
      Uri.parse("wss://yourdomain.com:17512"),
    ));