Setting up pusher_client with laravel_echo

Viewed 42

Im currently making a app that needs to have live updates, Im using pusher_client: ^2.0.0 and laravel_echo: ^0.2.2. I created a function which I call on initState :

    PusherOptions options = PusherOptions(
      host: 'reservegcc.com',
      wsPort: 6001,
      encrypted: false,
    );

    PusherClient pusher = PusherClient('11111', options, autoConnect: false);
    Echo echo = Echo({
      'broadcaster': 'pusher',
      'client': pusher,
      "wsHost": 'reservegcc.com',
      "wsPort": 6001,
      "disableStats": true,
      'wssPort': 6001,
      'forceTLS': true,
      'enabledTransports': ['ws', 'wss']
    });
    echo.channel('restaurant-transactions').listen('Transaction', (e) {
      print(e);
    });
    echo.connector.pusher.onConnectionStateChange((state) {
      print(state!.currentState.toString());
    });
    echo.connector.pusher.connect();
  }```

Im getting connecting and reconning on the onConnectionStateChange, Can someone please help me what is lacking on my code. I have done a lot of research but still cannot connect.

1 Answers

Bro I have spent a lot of time on this subject and I discovered a weird issue that the pusher package doesn't affect when you hot restart / reload the project. So you must exit and debug your project again and review the result of your changes.

And another hand I didn't use the echo package and I wrote channel and event names manually like this;

_pusher.subscribe("private-user.call.$userId").bind(
  "App\\Events\\callUser",
  (PusherEvent event) {
    var data = jsonDecode(event.data);
    switch (data["type"]) {
      case "bla bla":
        // do something
        break;
      case "bla bla":
        // do something
        break;
    }
  },
);
Related