pusher / pusher-websocket-react-native

React Native official Pusher SDK
MIT License
62 stars 55 forks source link

onEvent won't work despite dispatching an event through Postman #109

Closed AntonioA-D-C closed 1 year ago

AntonioA-D-C commented 1 year ago
  const pusher = Pusher.getInstance();

    const onEvent = (event: PusherEvent)=>{
      console.log(`onEvent> ${event}`)
    }

    const onSubscriptionSucceeded = (channelName) => {
      console.log(channelName)
      console.log(
        `onSubscriptionSucceeded: ${channelName} data: ${JSON.stringify(data)}`
      );
      const channel= pusher.getChannel(channelName);

      if (!channel) {
       console.log("No Channel");
       return
      }
      const me = channel.me;
    //  onChangeMembers([...channel.members.values()]);
      console.log(me);
    }

    const onError = (message, code, error) => {
      console.log(`onError: ${message} code: ${code} exception: ${error}`);
    };

    const onSubscriptionError = (
      channelName,
      message,
      e
    ) => {
      log(`onSubscriptionError: ${message}, channelName: ${channelName} e: ${e}`);
    };

    const onDecryptionFailure = (eventName, reason) => {
      log(`onDecryptionFailure: ${eventName} reason: ${reason}`);
    };

    const onConnectionStateChange = (
      currentState,
      previousState
    ) => {
      console.log(
        `onConnectionStateChange. previousState=${previousState} newState=${currentState}`
      );
    };
    const getPusher = async()=>{
      try{
        await pusher.init({
          apiKey: APP_KEY,
          cluster: APP_CLUSTER,
          authEndpoint: "http://127.0.0.1:8000/pusher/broadcasting/auth",
          port: 6001,
          onConnectionStateChange,
          onError,
          onEvent,
          onSubscriptionSucceeded,
          onSubscriptionError,
          onDecryptionFailure
        }).catch(error=>console.log(error));

      await pusher.subscribe({channelName:'drivers',
    //  onEvent,
    //  onSubscriptionSucceeded
    });
      await pusher.connect();
       console.log(pusher)
      } catch(e){
        console.log(`ERROR> ${e}`)
      }
    }

When I press the button, it successfully subscribes to the "drivers" channel and fetches the data on the queue, however, when sending dispatching the laravel event in PostMan, it doesn't send anything to the "onEvent" function, almost like it didn't exist, please help.

I've tried using both ShouldBroadcast and ShouldBroadcastNow in Laravel, neither of them display data in React Native

The only difference is the former saves data in the queue which is not visible except when first subscribing to the "drivers" channel in pusher-websocket-react-native, and the latter is visible everywhere in the localhost:8000/laravel-websockets server as well as console.log when subscribing to the channel.

I've tried to read the documentation, but nothing shows up that would help me with onEvent not logging the data being updated after the dispatch.

benw-pusher commented 1 year ago

It appears you are using laravel-websockets, a Pusher replacement service. We aren't able to support custom/third party websocket servers and services. If you have a problem when using our official Pusher Channels service please let us know and we can investigate.