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

Connection lost without any trigger #135

Open
jahanzaib5244 opened this issue Feb 7, 2024 · 2 comments
Open

Connection lost without any trigger #135

jahanzaib5244 opened this issue Feb 7, 2024 · 2 comments

Comments

@jahanzaib5244
Copy link

jahanzaib5244 commented Feb 7, 2024

I am using two different simulators at the same time once the pusher is initialized and subscribe to a private channel it works perfectly but after one minute or more it stops listing without any trigger and sometimes I get an error and after some time it auto-reconnect what causes the problem and how I can resolve this

onError: Pong reply not received code: 4201 exception: <PusherSwift.PusherError: 0x600000d73db0>

first, it will work perfectly and after 30 or 40 seconds it stops listing for new events and does not give any state change event
Screenshot 2024-02-07 at 2 08 21 PM

but after some time I got a new console like
Screenshot 2024-02-07 at 2 10 18 PM

it automatically connects and disconnect again and again until I reset pusher
Screenshot 2024-02-07 at 2 15 28 PM

Here is my configuration code for the pusher

export const Connect = async () => {


 return await pusher.init({
    apiKey: PUSHER_API_KEY,
    cluster: PUSHER_CLUSTER,
    useTLS: false,
    onConnectionStateChange,
    onAuthorizer: onAuthorizer,
    onError,
    onEvent,
    onSubscriptionSucceeded,
    onSubscriptionError,
    onSubscriptionCount,
    onDecryptionFailure,
    onMemberAdded,
    onMemberRemoved,
    maxReconnectionAttempts: 100,
    maxReconnectGapInSeconds: 0.01,
  })
}

 const initPusher = async () => {
    if (pusher.channels.size > 0) {
      const promises: any[] = [];

      pusher.channels.forEach(({channelName}) =>
        promises.push(pusher.unsubscribe({channelName})),
      );

      await Promise.allSettled(promises);
    }
    try {
      await Connect();
      if (pusher?.connectionState !== 'CONNECTED') {
        await pusher.subscribe({
          channelName: `private-chatify.${current_user_id}`,
          onEvent: (event: PusherEvent) => {
            console.log(event.eventName, event);
            if (event?.eventName === 'messaging') {
              setMessages(pre => [JSON.parse(event.data)?.api_message, ...pre]);
            }
          },
        });
        await pusher.connect();
      }
    } catch (error) {
      console.log(error);
    }
  };


useFocusEffect(
    useCallback(() => {
     initPusher();   
   }, []),
  );

@pusher/pusher-websocket-react-native": "^1.3.0"
react native : "0.72.5"
x code Version 15.2

@benw-pusher
Copy link
Contributor

The error you are receieving (pong reply not received from server) would indicate that the client has been unable to check in with the server and so has terminated the connection. This would normally be expected when the network conditions have degraded, and certainly wouldn't be expected with as much frequency as you are experiencing.
It could be that there is a a proxy, or other network device, that is closing the connection uncleanly. Often this is because such devices detect the connection as being idle. If this is the case you can use the https://github.com/pusher/pusher-websocket-react-native?tab=readme-ov-file#activitytimeout-double option to ensure the connection is active. As you are experiencing the disconnection after 30-40 seconds it may be prudent to try a value of 20 seconds and see if this resolves the issue.

@jahanzaib5244
Copy link
Author

The error you are receieving (pong reply not received from server) would indicate that the client has been unable to check in with the server and so has terminated the connection. This would normally be expected when the network conditions have degraded, and certainly wouldn't be expected with as much frequency as you are experiencing. It could be that there is a a proxy, or other network device, that is closing the connection uncleanly. Often this is because such devices detect the connection as being idle. If this is the case you can use the https://github.com/pusher/pusher-websocket-react-native?tab=readme-ov-file#activitytimeout-double option to ensure the connection is active. As you are experiencing the disconnection after 30-40 seconds it may be prudent to try a value of 20 seconds and see if this resolves the issue.

thank you for your response let me check if is it working in my case or not.

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

2 participants