如何将juggernaut推送消息显示在浏览器的html中?提前谢谢..
答案 0 :(得分:0)
这里记录了所有内容:https://github.com/maccman/juggernaut
假设您已经设置并运行了您的Juggernaut服务器,并且您的应用程序正在向Redis发布消息。
假设您要向channel1
您的HTML代码应包含以下javascript文件(随Juggernaut一起提供):
<script src="/javascripts/json.js" type="text/javascript"></script>
<script src="/javascripts/socket_io.js" type="text/javascript"></script>
<script src="/javascripts/juggernaut.js" type="text/javascript"></script>
然后你应该连接到Juggernaut服务器并处理传入消息
<script type="text/javascript" charset="utf-8">
// Connect to Juggernaut
var jug = new Juggernaut({secure: ('https:' == document.location.protocol)});
// Log the fact we have connected
jug.on("connect", function(){ log("Connected") });
// Log disconnection
jug.on("disconnect", function(){ log("Disconnected") });
// Log reconnection
jug.on("reconnect", function(){ log("Reconnecting") });
jug.subscribe("channel1", function(data){
// Your code to handle the incoming message
});
// Expose for debugging
window.jug = jug;
</script>
同样,在github上的README