Skip to content
Advertisement

Can’t connect to pusher with react-native

Hello i am new to react native and im trying to create a realtime chat application using pusher-js so i installed the package npm install pusher-js @react-native-community/netinfo and put the following code in my useEffect

useEffect(() => {
    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;

    var pusher = new Pusher('REDACTED', {
        cluster:"eu"});

    var channel = pusher.subscribe('my-channel');
    channel.bind('my-event', function(data) {
        alert(JSON.stringify(data));
    });
    
}, [])

and im getting this in the console Link of the image

Im using react-native run-android to run and im using a physical device. Thanks in advance for all the help you can provide.

Advertisement

Answer

Have you given your app the necessary permissions to access the network? To do so you will need to add

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

to your android manifest. See https://developer.android.com/training/basics/network-ops/connecting

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement