- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在客户端订阅“my-channel”并绑定(bind)到“my-event”。
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>
我正在“我的 channel ”中触发“我的事件”,并发送一条消息“hello world”
server.js
var pusher = new Pusher({
appId: '****',
key: '****',
secret: '******',
cluster: 'ap2',
encrypted: true
});
pusher.trigger('my-channel', 'my-event', {
"message": "hello world"
});
对于此代码,我在客户端收到一条警报消息。即,我的服务器正在向客户端发送消息,但我的问题是我想要整个过程相反,我希望客户端向服务器发送消息以及如何在服务器中接收这些消息?如何使用 Node.js 通过推送器来做到这一点。
谢谢!
最佳答案
Channels 提供的客户端库只能订阅 channel 并消费事件(它们也可以向其他客户端发送事件) - 它们无法向服务器触发事件。服务器库只能触发事件 - 它们不能订阅 channel 。
可以通过使用 client events 来实现解决方案并配置必要的webhooks in your app 。
更多信息可以在 Pusher Channels documentation 中找到
关于javascript - 如何使用 Pusher 将用户的存款和取款详细信息从客户端发送到 Node.js (express) 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59839323/
我有一个银行余额文本字段,我想根据存款/取款不断更新。这是我的代码: Bank Balance: Deposit Withdraw var balance = document.getEl
我对让 BankAccount 类实现安全提款/存款功能有疑问。到目前为止,当您向bankAccount 类提款或存款时,它会打印日志。无论如何,我的问题是如何实现安全性,例如您提取的金额不得超过您银
假设我有一个合约函数,它期望通过某个交易发送一定数量的near,该函数称为create_order , create_order需要几个论点。 我在前端以 myContract 的名称设置了我的契约(
我有一个java作业。我的任务是建立一个可以取款、存款和查询余额的银行。我的问题是,我无法在存款和取款后更新我的余额......我已经尝试了我能做的一切,但仍然无法理解逻辑。有人可以帮助添加到我的程序
我用 WooCommerce Deposits插件并希望隐藏除“本地取货”运输方式之外的所有其他运输方式,如果客户选择支付定金。 客户可以在产品页面上选择是支付 10% 的定金还是支付订单的全额。运输
我有这个 Lua 脚本,它应该创建一个新类,创建一个实例并调用函数,但是在我实际调用方法时出现错误。 Account = { balance = 0, new = function(s
我是一名优秀的程序员,十分优秀!