2

I am subscribing to "my-channel" and binding to "my-event" in client.

pusher.html

<!DOCTYPE html>
<head>
  <title>Pusher Test</title>
  <script src="https://js.pusher.com/5.0/pusher.min.js"></script>
  <script>

    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;

    var pusher = new Pusher('******', {
      cluster: 'ap2',
      forceTLS: true
    });

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

  </script>
</head>
<body>
  <h1>Pusher Test</h1>
  <p>
    Try publishing an event to channel <code>my-channel</code>
    with event name <code>my-event</code>.
  </p>
</body>

I am triggering "my-event" in "my-channel" with a message hello world

server.js

        var pusher = new Pusher({
            appId: '****',
            key: '****',
            secret: '******',
            cluster: 'ap2',
            encrypted: true
        });

        pusher.trigger('my-channel', 'my-event', {
            "message": "hello world"
        });

For this code i get an alert message in client side . i.e., my server is sending messages to client but my problem is i want the whole process other way around , i want client sending messages to the server and how to receive those in server?.How to do it with pusher using node.js.

thanks!

1 Answers1

1

Client libraries provided by Channels can only subscribe to channels and consume events (they can also send events to other clients) - they cannot trigger events to the server. Server libraries can only trigger events - they cannot subscribe to channels.

A solution could be achieved by using client events and configuring the necessary webhooks in your app.

More info can be found in Pusher Channels documentation

doydoy
  • 4,021
  • 3
  • 20
  • 33