如何使用Pusher将用户的存款和取款详细信息从客户端发送到Node.js(快速)服务器?



我正在订阅"my-channel"并绑定到客户端中的"my-event"。

推杆.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>

我在"我的频道"中触发"我的事件",并显示一条消息 hello world

服务器.js

var pusher = new Pusher({
appId: '****',
key: '****',
secret: '******',
cluster: 'ap2',
encrypted: true
});
pusher.trigger('my-channel', 'my-event', {
"message": "hello world"
});

对于此代码,我在客户端收到一条警报消息,即我的服务器正在向客户端发送消息,但我的问题是我希望整个过程以另一种方式进行,我希望客户端向服务器发送消息以及如何在服务器中接收这些消息?如何使用节点.js的推送器来做到这一点。

谢谢!

通道提供的客户端库只能订阅通道并使用事件(它们也可以向其他客户端发送事件( - 它们不能触发事件到服务器。 服务器库只能触发事件 - 它们不能订阅频道。

可以通过使用客户端事件并在应用中配置必要的 Webhook 来实现解决方案。

有关详细信息,请参阅推入式通道文档

最新更新