3

I am using Pusher for triggering an alert when data is inserted in my database. The server-side triggering is working, but on the client side, the trigger only works when I refreshes the page. Here's the App.js ->

    useEffect(() => {
    const pusher = new Pusher("xxxxxxxxxxxxxx", {
      cluster: "xxxxxxxx",
    });
    const channel = pusher.subscribe("xxxxxxx");
    channel.bind("xxxxxxxxxx", function (newMessage) {
      alert(newMessage);
    });
    return () => {
      channel.unbind_all();
      channel.unsubscribe();
    };
  }, [messages]);

Any help is greatly appreciated !

Ajit Kumar
  • 367
  • 1
  • 10
  • 35
  • 1
    Any update here? – Ajit Kumar Feb 20 '21 at 01:38
  • Do you see the events broadcast in the Pusher Dashboard debug console for your app? The error will lie either with your server not publishing correctly, or with your client not consuming correctly. If the events are shown in the debug console then we know your server is publishing as expected. – doydoy Feb 22 '21 at 16:32
  • I did `Pusher.log = (msg) => { console.log(msg); };` and found that the server is pushing correctly !! **But** the client is not receiving ! – Ajit Kumar Feb 23 '21 at 15:40
  • Is your client subscribing correctly, and i the subscription maintained? I'm not familiar with the React `useEffect` hook, but I can see that your return method unbinds and unsubscribes which would mean it no longer receives events. – doydoy Feb 24 '21 at 09:15
  • Even after removing the `return` method, it is not working !! – Ajit Kumar Feb 24 '21 at 12:26
  • Have you checked the subscription is completing correctly and is being maintained? Are you subscribing to the correct channel and binding to the same event? – doydoy Feb 25 '21 at 11:30

0 Answers0