chinloyal / pusher_client

A Pusher Channels Client for Fluttter (Fully supports Android and iOS)
https://pusher.com/channels
MIT License
43 stars 175 forks source link

Pusher stuck in [CONNECTING] and produce a fatal exception. #4

Closed heshamerfan97 closed 3 years ago

heshamerfan97 commented 3 years ago

Steps to reproduce

I use pusher_client: ^1.1.0 with laravel_echo: ^0.2.8 I Initialize PusherClient as the example PusherOptions options = PusherOptions( host: '****-app.com', wssPort: 6001, wsPort: 6001, cluster: "mt1", ); PusherClient(appKey, options);

In initState I initialize my echo echo = new Echo({ 'broadcaster': 'pusher', 'crsfToken': $accessToken, 'X-CSRF-TOKEN': $accessToken, 'authEndpoint': '/broadcasting/auth', 'key': appKey, 'wsHost': '****-app.com', 'wsPort': 6001, 'wssPort': 6001, 'forceTLS': true, 'disableStats': false, 'enabledTransports': ['ws', 'wss'], 'cluster': 'mt1', 'client': pusherClient, 'auth': { 'headers': { 'Authorization': 'Bearer $accessToken' } } });

Expected behavior

As an expected behavior it should at least connect to the socket and proceed through the [CONNECTING] message so I can connect to the channel.

Actual behavior

PusherClient stuck in [CONNECTING] and produce a fatal exception as follow

FATAL EXCEPTION: pusher-java-client eventQueue E/AndroidRuntime( 5489): Process: com..**, PID: 5489 E/AndroidRuntime( 5489): java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter code E/AndroidRuntime( 5489): at com.github.chinloyal.pusher_client.pusher.listeners.ConnectionListener.onError(Unknown Source:7) E/AndroidRuntime( 5489): at com.pusher.client.connection.websocket.WebSocketConnection$5.run(WebSocketConnection.java:238) E/AndroidRuntime( 5489): at com.pusher.client.util.Factory$1.run(Factory.java:119) E/AndroidRuntime( 5489): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime( 5489): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime( 5489): at java.lang.Thread.run(Thread.java:919)

...

mghase commented 3 years ago

any solution please

OxayMint commented 3 years ago

Same here. Works well on iOS but I get the same error on android. @mghase @chinloyal Any solution yet?

heshamerfan97 commented 3 years ago

I gave up using this package, I tried flutter_pusher_client with laravel_echo and it worked for me.

chinloyal commented 3 years ago

@heshamerfan97 The issue was you are not using the full url for the authEndpoint, instead of "/broadcasting/auth" use "my-app.com/broadcasting/auth"

OxayMint commented 3 years ago

I'm using it with full url. With https://

chinloyal commented 3 years ago

@OxayMint Can you share your configuration?

OxayMint commented 3 years ago
PusherOptions options = PusherOptions(
      host: 'wss.{custom-hostname}',
      wsPort: 6001,
      wssPort: 6001,
      encrypted: true,
      auth: PusherAuth(
        'https://{custom-hostname}/broadcasting/auth',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + LocalData.getInstance.getToken()
        },
      ),
    );
    pusherClient = PusherClient('any', options, autoConnect: true);

    pusherClient.onConnectionStateChange((state) {
      print(state.currentState);
    });
OxayMint commented 3 years ago

the thing is that we use custom pusher server. And everything works like a charm when I run it on iOS, but fails on android both emulator and real device

heshamerfan97 commented 3 years ago

@chinloyal I already tried using the full link for auth. but the error is still there.

chinloyal commented 3 years ago

Can you try setting this:

pusherClient.onConnectionError((error) {
   log("error: ${error.message}");
});

Let me know what happens, also can you set the enableLogging to true on the PusherClient to true @OxayMint

OxayMint commented 3 years ago
D/PusherClientPlugin(13435): Pusher initialized
D/PusherClientPlugin(13435): [CONNECTING]
E/AndroidRuntime(13435): FATAL EXCEPTION: pusher-java-client eventQueue
E/AndroidRuntime(13435): Process: ventures.al.mashinal, PID: 13435
E/AndroidRuntime(13435): java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter code
E/AndroidRuntime(13435):    at com.github.chinloyal.pusher_client.pusher.listeners.ConnectionListener.onError(Unknown Source:7)
E/AndroidRuntime(13435):    at com.pusher.client.connection.websocket.WebSocketConnection$5.run(WebSocketConnection.java:238)
E/AndroidRuntime(13435):    at com.pusher.client.util.Factory$1.run(Factory.java:119)
E/AndroidRuntime(13435):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(13435):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(13435):    at java.lang.Thread.run(Thread.java:919)
D/PusherClientPlugin(13435): [RECONNECTING]
I/Process (13435): Sending signal. PID: 13435 SIG: 9
Lost connection to device.
chinloyal commented 3 years ago

I believe a recent PR fixes this issue. I haven't created a release for it yet but you can test it out by linking to master in your pubspec.yaml file by doing:

dependencies:
  pusher_client:
    git:
      url: https://github.com/chinloyal/pusher_client
      ref: master

Let me know if that works @OxayMint

OxayMint commented 3 years ago

Yay! It worked. Thank you so much for this package and for resolving the issue! Should we just wait for the new version of the package then?

chinloyal commented 3 years ago

@heshamerfan97 can you also try this as well? I want to confirm this works so I can create a new release

chinloyal commented 3 years ago

Yay! It worked. Thank you so much for this package and for resolving the issue! Should we just wait for the new version of the package then?

Yes, I'll create the new release today

chinloyal commented 3 years ago

This new release v1.1.1 fixes this issue as confirmed by @OxayMint so I am closing this issue for now.

mghase commented 3 years ago

still geting fatal error. it work fine on debug mode but in release fails in Android

E/AndroidRuntime(15468): FATAL EXCEPTION: pusher-java-client eventQueue E/AndroidRuntime(15468): Process: com.xxxx.xxxx, PID: 15468
E/AndroidRuntime(15468): java.lang.NoClassDefFoundError
E/AndroidRuntime(15468): at i.a.a.b.a(Unknown Source:8)
E/AndroidRuntime(15468): at i.a.a.b.(Unknown Source:6)
E/AndroidRuntime(15468): at i.a.a.h.(Unknown Source:2)
E/AndroidRuntime(15468): at i.a.a.h.b(Unknown Source:0)
E/AndroidRuntime(15468): at i.c.g.b.(Unknown Source:10)
E/AndroidRuntime(15468): at i.c.g.c.(Unknown Source:5)
E/AndroidRuntime(15468): at i.c.g.c.(Unknown Source:2)
E/AndroidRuntime(15468): at i.c.g.c.c(Unknown Source:0)
E/AndroidRuntime(15468): at i.c.c.a(Unknown Source:14)
E/AndroidRuntime(15468): at i.c.c.g(Unknown Source:0)
E/AndroidRuntime(15468): at i.c.c.e(Unknown Source:14)
E/AndroidRuntime(15468): at i.c.c.a(Unknown Source:0)
E/AndroidRuntime(15468): at i.c.c.a(Unknown Source:4)
E/AndroidRuntime(15468): at i.b.g.b.(Unknown Source:5)
E/AndroidRuntime(15468): at i.b.g.b.(Unknown Source:3)
E/AndroidRuntime(15468): at i.b.g.b.(Unknown Source:11)
E/AndroidRuntime(15468): at i.b.g.b.(Unknown Source:4)
E/AndroidRuntime(15468): at i.b.f.b.(Unknown Source:2)
E/AndroidRuntime(15468): at c.h.a.g.f.a.(Unknown Source:0) E/AndroidRuntime(15468): at c.h.a.i.b.a(Unknown Source:2)
E/AndroidRuntime(15468): at c.h.a.g.f.b.h(Unknown Source:6)
E/AndroidRuntime(15468): at c.h.a.g.f.b.b(Unknown Source:0)
E/AndroidRuntime(15468): at c.h.a.g.f.b$a.run(Unknown Source:12) E/AndroidRuntime(15468): at c.h.a.i.b$a.run(Unknown Source:7)
E/AndroidRuntime(15468): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime(15468): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime(15468): at java.lang.Thread.run(Thread.java:764) E/AndroidRuntime(15468): Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category E/AndroidRuntime(15468): at java.lang.Class.classForName(Native Method) E/AndroidRuntime(15468): at java.lang.Class.forName(Class.java:453) E/AndroidRuntime(15468): at java.lang.Class.forName(Class.java:378) E/AndroidRuntime(15468): at i.a.a.b.a(Unknown Source:0)
E/AndroidRuntime(15468): ... 26 more
E/AndroidRuntime(15468): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.log4j.Category" on path: DexPathList[[zip file "/data/app/com.xxx.xxx-RF5Xws02UKrIBerUdhtOYQ==/base.apk"],nativeLibraryDirectories=[/data

chinloyal commented 3 years ago

@mghase That is a completely different issue, I believe it's related to issue #3