5

Im trying to authenticate a private broadcast using the following React Native script.

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Pusher from 'pusher-js/react-native';

export default class App extends React.Component {
  componentWillMount() {
    Pusher.logToConsole = true;
    var pusher = new Pusher('*********', {
      authEndpoint: 'http://app.pgm/api/authtest',
      cluster: 'eu',
      encrypted: true
    });

    const channel = pusher.subscribe('private-chat-1');

  }

The above is being posted to the function below, the function below returns an auth token when tested from Postman. However when I run the app through React Native I get the following response.

  public function pusher(Request $request){
        $pusher = new Pusher(config('broadcasting.connections.pusher.key'), config('broadcasting.connections.pusher.secret'), config('broadcasting.connections.pusher.app_id'));

        echo $pusher->socket_auth($request->channel_name, $request->socket_id);
  }

[exp] Pusher : Couldn't retrieve authentication info. 0Clients must be authenticated to join private or presence channels. See: https://pusher.com/docs/authenticating_users [exp] Pusher : No callbacks on private-chat-1 for pusher:subscription_error

It leads me to think Laravel isn't receiving the post data. I do not currently have any middleware that could block the request.

Can anyone see where I am going wrong?

1
  • Have you find any solution for this, I'm facing the same problem Commented May 8, 2020 at 10:44

1 Answer 1

3

It's working fine on my side on both Postman and React Native ends. I used following piece of code. In my case I'm not using key encrypted: true.

I'm listening event successfully.

Code

    // Pusher Logging
    Pusher.logToConsole = true;
    
    // Initialization & Configuration
    const pusher = new Pusher('****************', {
      cluster: '***',
      authEndpoint:
        'http://domain/products/chat/public/api/authtest',
    });

    // Making Connection
    pusher.connection.bind('connected', function (data) {
      console.log(data.socket_id);
    });

    // Subscribe Channel
    var channel = pusher.subscribe('private-channel-name', (data) => {
      console.log('Subscribe Channel');
      console.log(data);
    });

    // Accessing Channel
    const channelInfo = pusher.channel('private-chatify');
    console.log('channel Info');
    console.log(channelInfo);

    // Listen Event
    channel.bind('yourevent', function (data) {
      console.log('An event was triggered with message');
      console.log(data);
      console.log(data.message);
    });

Hope it may help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.