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

Crashed com.facebook.react.PusherWebsocketReactNativeQueue #171

Open
AbdulkarimTaha opened this issue Dec 24, 2024 · 1 comment
Open

Crashed com.facebook.react.PusherWebsocketReactNativeQueue #171

AbdulkarimTaha opened this issue Dec 24, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@AbdulkarimTaha
Copy link

hello all,
am using this to connect and subscribe

const pusher = await connect();


  await pusher.subscribe({
    channelName,
    onEvent: (event: PusherEvent) => {
      debugLog('Pusher-Event', event);
      Constants.PusherChannel.forEach(item => {
        if (event.channelName === item.channelName) {
          item.callback(event);
        }
      });
    },
    onSubscriptionSucceeded: (data: any) => {
      debugLog('Pusher-Subscription-Succeeded', {
        data,
        channelName,
      });
    },
    onSubscriptionError: (name: string, message: string) => {
      debugLog('Pusher-subscription-error', {
        channelName: name,
        status: 'error',
        message,
      });
    },
  });

const connect = async () => {
 const pusher = Pusher.getInstance();
 if (pusher.connectionState !== 'CONNECTED') {
   await pusher.connect();
  }
  return pusher;
}; 

and i got a lot of crashes in android and ios on crashlytics

android :

Fatal Exception: java.lang.NullPointerException
com.pusherwebsocketreactnative.PusherWebsocketReactNativeModule.connect (PusherWebsocketReactNativeModule.kt:7)

ios:
Crashed: com.facebook.react.PusherWebsocketReactNativeQueue
PusherWebsocketReactNative.swift - Line 196
@objc PusherWebsocketReactNative.connect(_:reject:) + 196

any idea what could be the issue

pusher-websocket-react-native: 1.3.1
react-native 0.75.3

@evgeniibreikin
Copy link

Hey, @AbdulkarimTaha
I can't understand the execution context of your code example.

This example works for me

// other imports
import { useMemo } from 'react';
import {
  Pusher,
  PusherChannel,
  PusherEvent,
} from '@pusher/pusher-websocket-react-native';

const pusher = Pusher.getInstance();

export default function HomeScreen() {
  useMemo(async () => {
    try {
      await pusher.init({
        apiKey: '...',
        cluster: '...',
      });

      await pusher.connect();

      await pusher.subscribe({
        channelName: "my-channel",
        onSubscriptionSucceeded: (channel: PusherChannel) => {
          console.log(`SUBSCRIBED TO CHANNEL`);
        },
        onEvent: (event: PusherEvent) => {
          console.log('Pusher-Event', event);
        },
      });

    } catch (e) {
      console.log(`ERROR: ${e}`);
    }
  }, []);

  return (<View></View>);
}

@evgeniibreikin evgeniibreikin added the question Further information is requested label Jan 6, 2025
@evgeniibreikin evgeniibreikin self-assigned this Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants