我正在订阅客户端中的“我的频道”并绑定到“我的事件”。
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>
我通过消息“ 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的pusher进行处理。
谢谢!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句