pusher / pusher/pusher-websocket-react-native

Connection lost without any trigger

Open
#135 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
76
Forks
64
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with initPusher and Connect in the configuration shown, then inspect the connection-state and error callbacks while reproducing the failure with two simulators. Check the behavior of pusher-websocket-react-native version 1.3.0 under the listed React Native and Xcode versions. Done means identifying the trigger for the lost connection and documenting a verified resolution or reproducible limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.