Skip to content

Connection lost without any trigger  #135

@jahanzaib5244

Description

@jahanzaib5244

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions