Skip to content
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

WSL Laravel Sail: Websocket not upgraded #227

Closed
TylerByte666 opened this issue Aug 8, 2022 · 4 comments
Closed

WSL Laravel Sail: Websocket not upgraded #227

TylerByte666 opened this issue Aug 8, 2022 · 4 comments

Comments

@TylerByte666
Copy link

Hi all.

I would really love to know how to get this working locally with laravel sail?

I have tried both laravel-websockets and soketi locally through sail but I keep getting this output:

WebSocketException: Connection to 'http://10.0.2.2:6001#' was not upgraded to websocket

I have this as my home widget, where the error originates:

class _MyHomePageState extends State<MyHomePage> {
  final _channel = IOWebSocketChannel.connect(
    Uri.parse('ws://10.0.2.2:6001'),
  );

  @override
  initState() {
    _channel.sink.add(json.encode({
      "event": "pusher:subscribe",
      "data": {"channel": "channel"}
    }));

    _channel.stream.listen((_data) {
      print(_data.toString());
    }, onError: (error) {
      print("Socket: error => " + error.toString());
    }, onDone: () {
      print("Socket: done");
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    _channel.sink.close(status.goingAway);
    super.dispose();
  }
}

I use WSL, Docker-Desktop and Windows 10. The channel I want to connect to is public and is called: channel, the event is called: App\Events\TestEvent.php

I have added http ability in the android/app/main/AndroidManifest.xml:

<application
       ...
        android:usesCleartextTraffic="true" >

The web sockets are working with Vue.js, Echo.js and Pusher.js so I really do not know what to do. Please help 🤕

@novas1r1
Copy link

@TylerByte666 have you found any solution for your problem since I'm facing the exact same one.

@snarcraft
Copy link

@TylerByte666 @novas1r1 try to connect to ws://10.0.2.2:6001/app/${YOUR_PUSHER_KEY} instead :)

@novas1r1
Copy link

Thanks @snarcraft . For me the issue was actually a wrong port I got from my backend dev :D... So the error message lead me here, but was unrelated to this issue.

@TylerByte666
Copy link
Author

@snarcraft Thanks matey, didn't work at all.
@novas1r1 Glad you fixed your issue. I tried this plugin this morning and all my problems are fine :) laravel_flutter_pusher 0.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants