pusher / pusher-channels-flutter

Pusher Channels client library for Flutter targeting IOS, Android, and WEB
MIT License
74 stars 133 forks source link

pusher-java-client eventQueue #106

Closed AbdallahMohamed220 closed 1 year ago

AbdallahMohamed220 commented 1 year ago

E/AndroidRuntime(13063): FATAL EXCEPTION: pusher-java-client eventQueue E/AndroidRuntime(13063): Process: com.example.fix_infinity, PID: 13063 E/AndroidRuntime(13063): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.pusher.client.channel.impl.message.AuthResponse.getChannelData()' on a null object reference E/AndroidRuntime(13063): at com.pusher.client.channel.impl.PrivateChannelImpl.authorize(PrivateChannelImpl.java:84) E/AndroidRuntime(13063): at com.pusher.client.channel.impl.PrivateChannelImpl.toSubscribeMessage(PrivateChannelImpl.java:101) E/AndroidRuntime(13063): at com.pusher.client.channel.impl.PresenceChannelImpl.toSubscribeMessage(PresenceChannelImpl.java:78) E/AndroidRuntime(13063): at com.pusher.client.channel.impl.ChannelManager.lambda$sendOrQueueSubscribeMessage$0$com-pusher-client-channel-impl-ChannelManager(ChannelManager.java:134) E/AndroidRuntime(13063): at com.pusher.client.channel.impl.ChannelManager$$ExternalSyntheticLambda0.run(Unknown Source:4) E/AndroidRuntime(13063): at com.pusher.client.util.Factory.lambda$queueOnEventThread$0(Factory.java:140) E/AndroidRuntime(13063): at com.pusher.client.util.Factory$$ExternalSyntheticLambda0.run(Unknown Source:2) E/AndroidRuntime(13063): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) E/AndroidRuntime(13063): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) E/AndroidRuntime(13063): at java.lang.Thread.run(Thread.java:764)

benw-pusher commented 1 year ago

Could you share the code used when this was encountered?

AbdallahMohamed220 commented 1 year ago

@benw-pusher

@override
  void initState() {
    super.initState();
    initConnection();
  }

  void initConnection() async {
    try {
      await pusher.init(
        apiKey: '81ds955css4b9f5ddd52e664a4',
        cluster: 'mt1',
        onConnectionStateChange: onConnectionStateChange,
        onError: onError,
        onSubscriptionSucceeded: onSubscriptionSucceeded,
        onEvent: onEvent,
        onSubscriptionError: onSubscriptionError,
        onDecryptionFailure: onDecryptionFailure,
        onMemberAdded: onMemberAdded,
        onMemberRemoved: onMemberRemoved,
        onSubscriptionCount: onSubscriptionCount,
        authEndpoint: "$baseurl/broadcasting/auth",
         onAuthorizer: onAuthorizer,
         authParams: {
          'headers': {'Authorization': '${CacheHelper.getData(key: 'token')}'}
        },
      );
      await pusher.subscribe(channelName: 'presence-chat.${widget.orderId}');

      await pusher.connect();
    } catch (e) {
      log("ERROR: $e");
    }
  }

  dynamic onAuthorizer(
      String channelName, String socketId, dynamic options) async {
    log("channelName: $channelName socketId: $socketId");
    String token = CacheHelper.getData(key: 'token');
    print('token');
    print(token);
    var authUrl = "$baseurl/broadcasting/auth";
    var result = await Dio().post(
      authUrl,
      options: Options(
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Authorization': 'Bearer $token',
        },
      ),
      data: 'socket_id=$socketId&channel_name=$channelName',
    );
    print('result');
    print(result);
    var json = jsonDecode(result.data);
    return json;
  }
OmarYehiaDev commented 1 year ago

Anything new about this?

AbdallahMohamed220 commented 1 year ago

I didn't find answer so I use this packages :

pusher_client: git: url: https://github.com/thijskuilman/pusher_client.git ref: master laravel_echo: git: url: https://github.com/kakajansh/echo.git ref: master

OmarYehiaDev commented 1 year ago

And did it work? I don't know Laravel_echo but pusher_client is supposed to be discontinued :(

AbdallahMohamed220 commented 1 year ago

it work work with me and if you need I can send post configuration

OmarYehiaDev commented 1 year ago

Okay, please if you can, share with me the code as a gist or a repo You can send it over to my mail if you can't share it publicly

mail: omaryahiatawfiek@gmail.com

AbdallahMohamed220 commented 1 year ago

very sorry for my late response here is my initstate for configure pusher
all data below you can ask backend for it if you have any problem you can send me email to : dev.fluttery@gmail.com and we can have meeting to check the problem

late PusherClient pusherClient; @override void initState() { super.initState();

PusherOptions options = PusherOptions(
  cluster: 'set here cluster name',
  auth: PusherAuth(
    'ser here api endpoint for auth',
    headers: {
      'Authorization': 'Bearer $token',
    },
  ),
);

pusherClient = PusherClient(
  'here put app id',
  options,
  autoConnect: false,
  enableLogging: true,
);

pusherClient.subscribe('set her channel name');

Echo echo = Echo(
  client: pusherClient,
);

echo.channel(''}').listen('NewMessageSent',
    (e) {
  Map<String, dynamic> data = json.decode(jsonEncode(e));

});

}

benjamin-tang-pusher commented 1 year ago

I've you're getting this error every time, we've seen in the past NullPointerException on AuthResponse.getChannelData() is because of an incorrect auth response from your backend that isn't handled well by our library. Could you provide yours?

benw-pusher commented 1 year ago

We haven't had a response here so closing. If you need further support please get in touch with us via https://messagebird.com/support-center/Pusher-request-new