chinloyal / pusher_client

A Pusher Channels Client for Fluttter (Fully supports Android and iOS)

Home Page:https://pusher.com/channels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't seem to work with Laravel Websockets self hosted pusher

nicolasvahidzein opened this issue · comments

I have been commenting on many issues and no one is responding.

I am not able to get this to work. While i was using an older deprecated package called flutter_pusher_client which is very similar in syntax it is working flawlessly.

What seems to be the problem with this package and laravel self hosted pusher option?

Does anyone have a working sample with the same stack as me?

Thanks.

Hello?

I have the same problem.
Can't read custom host in PusherOptions()

@apostle51 you can write to me if you need help. I migrated to this plugin

https://github.com/olubunmitosin/laravel_flutter_pusher

and it was a BREEZE! Stop using this one.

@apostle51 you can write to me if you need help. I migrated to this plugin

https://github.com/olubunmitosin/laravel_flutter_pusher

and it was a BREEZE! Stop using this one.

didn't work for me using laravel websockets and laravel passport
are you still using same code or other solution?

Yes. Works like a charm.

Yes. Works like a charm.

Would you give me a link of your code or some parts of it Flutter code and Laravel code
I will be thankful to you

Ok sure contact me on skype nzein19

Ok sure contact me on skype nzein19

I did thank you

Ok sure contact me on skype nzein19

So i used the code you have given to me and it still not workin, would you check my code to find any mistake
Knowing that am developing in local on my pc and i didn't see any request coming to my laravel app authendpoint but i can see it when using postman

it shows me this Log message

[log] event:Instance of 'ConnectionStateChange'RECONNECTING
[log] event:Instance of 'ConnectionStateChange'CONNECTING

the same message every while then next to that message it gives me this error that i open an issue for it
olubunmitosin/laravel_flutter_pusher#7

// Dart imports:
import 'dart:developer';

// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:get/get.dart';
import 'package:laravel_echo/laravel_echo.dart';

import 'package:laravel_flutter_pusher/laravel_flutter_pusher.dart';

const String PUSHER_KEY = 'MyUserLaravelWebSocketKey';
const String PUSHER_CLUSTER = 'mt1';
const String HOST = '10.144.231.XX';
const String AUTH_URL = 'http://10.144.231.XX/api/broadcasting/auth';
const String BEARER_TOKEN =
    'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiMmViOTNlNWExMDhjODJjNjgzOGZlNzhkYzVmYzc3ZDA0ZWMyYmQ5ZTFmZGJiM2NlZGMxYTk5NjhhMGI5MWE3ZjAzYTdhZmRlNzVkNGIxYTEiLCJpYXQiOjE2NDg3MTc2OTYuMTU1Mzg0LCJuYmYiOjE2NDg3MTc2OTYuMTU1Mzg3LCJleHAiOjE2ODAyNTM2OTYuMTI5NTU5LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.yjomT1hOjM57BfOi8iXCxj5GbV9nL6v5MKx9T6XvmZA8wXgMYsL08t0yrAfCMRiBBJzof-cgbTwl0JuKBl68YYFQBFJ2WY0MO-0aA7G1kkiRJUxQcb32oRySKu6cVmFI2mhcRZi_2zOBSQ78DFVOZg6ERMYoJ_YcE7DoJsW39jpMSo_aJGn-1vgEhpYS6e0qXjtuZ9mVo4BErlXvAc28CXWmHZQH7YXbes6a_aG1vB2m-eXUKZVmDOBvVhZdScb1kSvAK2DC3xMe4neXAUzxHZDU9-larj-vXr2loKr3SLXZZNnB-np-6wN5lVmBPTFxKr1mZoYQKBTLoet9UeYaigBFa3fZbtCmTXEpU6mLfauex5Iq5SSZbGVPq_lVv03tzLSZ2x25WMyyQitNWdkoSHQG8FFCWcnokaE6SLF0KOKFidyu6rBLCDEjiWU5oZW0SE9YEPGfETLrMPk-yotJayfbVGosrv6chp-TO3dRgKMQ8Pjc6WHSODP8eaZTw96EO2gZUqhH2f0ERrtygrqSvIafZzEAAk0IzJy4uSWCsjbjkyiCrHBjQ5prR_4enSbL2BcjsNSAQMe-GFKSqusPdHgt9xN6_8C8wPq0mWeHV0Tk-T7pEyizC_Y5KpvWuT7aMSV2S2BApre-MC2udU5eUrcvm3ecw3JOokhcxKSES1nzJU';


class WebSocketsController extends GetxController {
  final GlobalKey scaffoldKey = GlobalKey<ScaffoldState>();

  Echo? _echo;

  @override
  void onInit() {
    initialize();
  }

  @override
  void onClose() {
    disconnect();
  }

  Future<void> initialize() async {
    String? myUserId = '1';

    PusherOptions options = PusherOptions(
      host: HOST,
      port: 6001,
      cluster: PUSHER_CLUSTER,
      encrypted: false,
      auth: PusherAuth(
        AUTH_URL,
        headers: {'Authorization': 'Bearer ' + BEARER_TOKEN, 'Content-Type': 'application/json', 'Accept': 'application/json'},
      ),
    );

    LaravelFlutterPusher pusher = LaravelFlutterPusher(
      PUSHER_KEY,
      options,
      enableLogging: true,
    );

    _echo = Echo(
      broadcaster: EchoBroadcasterType.Pusher,
      client: pusher,
    );

    pusher.connect(onConnectionStateChange: _onConnectionStateChange).onError((error, stackTrace) {
      log('error: $error');
    });

    _echo!.private('user.${myUserId}').listen('UserStatusChange', (event) {
      log(event);
    });
  }

  void _onConnectionStateChange(ConnectionStateChange event) {
    log('event:' + event.toString() + event.currentState);
  }

  void disconnect() {
    _echo!.disconnect();
  }
}

Seems perfect. You most likely have an issue on the laravel side then. BTW, i'm using an older version of laravel and passport because i haven't had time to update. What are you using?

Also, what error do you get in websockets when you try connecting?

Laravel 9.X and passport 10.3, i dont think it's alaravel issue because i can get the authendpoit (http://10.144.231.XX/api/broadcasting/auth) from postman wich i dont see when using this plugin in my app

Also, what error do you get in websockets when you try connecting?

if you mean Laravel websockets Dashboard it's working

You should move your issue to the flutter package, it is creating noise here for now reason. You get an error message in flutter and that should be your starting point. Reproduce the print statements i sent you in my sample code. We can do a zoom session tonight, i can spare an hour.

You should move your issue to the flutter package, it is creating noise here for now reason. You get an error message in flutter and that should be your starting point. Reproduce the print statements i sent you in my sample code. We can do a zoom session tonight, i can spare an hour.

I can't at night, i have day only nowadays, i'll search it tomorrow and update you here.

@nicolasvahidzein would you comment on the issue olubunmitosin/laravel_flutter_pusher#7 to close this one.
after a lot of searches i found that it's an Null safety issue that appears in lot of packages since my app is a null safetey app
so can i know what versions of packages you use in the code you have sent to me?

mine is as follow

laravel_echo: ^1.0.0-beta.1

laravel_flutter_pusher: ^0.0.4

laravel_echo: ^1.0.0-beta.1
laravel_flutter_pusher: ^0.0.4

same for me.

laravel_echo: ^1.0.0-beta.1
laravel_flutter_pusher: ^0.0.4

same for me.

So it's bizzare that it doesn't work for me since it's the same

You are using a more recent version of laravel, i'm still on 5.8. Send me your laravel echo and websockets versions you are using on the backend.

You are using a more recent version of laravel, i'm still on 5.8. Send me your laravel echo and websockets versions you are using on the backend.

, i don't have my pc right now but they are the Latest versions