Adonis js websocket in flutter app

I am trying to use websocket in flutter. Not sure how it’s going on. There are a web socket package in flutter. Please read. I think you guys can help even if you don’t know flutter :smiley: .

Ok so here is the flutter package https://pub.dev/packages/web_socket_channel#-readme-tab-

here is the example set up https://flutter.dev/docs/cookbook/networking/web-sockets

I connected it in my adonis url ws://localhost:8181/adonis-ws

I have a code like this

widget.channel.sink.add((json.encode({
            't': 1,
            'd': { 'topic': 'chat' }
        })));

and in my socket controller’s constructor method I was able to console. it shows connected successfully!

My connection code looks like this

new StreamBuilder(
              stream: widget.channel.stream,
              builder: (context, snapshot) {
                return new Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: new Text(snapshot.hasData ? '${snapshot.data}' : ''),
                 
                );
              },
            )

so when connecting i get these data from adonis server

Then when send data to server like this

widget.channel.sink.add((json.encode({
            't': 1,
            'd': { 'topic': 'chat' }
        })));

I get this data back and also console.log in adonis server works. but onMessage is never called in adonis.

Now how can I send actual data to adonis server and send back data from adonis server? Any idea help would be appreciated. Thank you.

2 Likes

i was wondering after a recommendation to re-build my apps in flutter
how much would it take, and is it really worthy
thanks
https://www.msayed.net/mobile