pubnub = PUBNUB.secure({
subscribe_key : "#{config.subscribe_key}",
publish_key : "#{config.publish_key}",
origin : 'pubsub.pubnub.com',
ssl : true,
cipher_key : "#{config.publish_key}"
});
pubnub.subscribe({
restore : true,
channel : 'broadcast',
callback : function(data) {
debugger;
new_message_notification(data);
}
});
回调无效,但我在浏览器的NETWORK标签中看到了回复。 问题在哪里?
答案 0 :(得分:2)
那是因为你还没有打电话
PUBNUB.init
所以pubnub无法初始化。
所以..
pubnub = PUBNUB.init({
subscribe_key : "#{config.subscribe_key}",
publish_key : "#{config.publish_key}",
origin : 'pubsub.pubnub.com',
ssl : true,
cipher_key : "#{config.publish_key}"
});
应该更加正确。
答案 1 :(得分:0)
有一个新版本的PubNub JavaScript: JavaScript API Reference for Realtime Apps
使用以下代码示例建立具有SSL 2048加密的AES 256位。您可以在此处找到实时示例:http://pubnub.github.com/pubnub-api/crypto/index.html
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.3.min.js></script>
<script src=http://pubnub.github.com/pubnub-api/crypto/crypto.js></script>
<script src=http://pubnub.github.com/pubnub-api/crypto/encrypt-pubnub.js></script>
<script>(function(){
var publish_key = PUBNUB.$('pub').value;
var subscribe_key = PUBNUB.$('sub').value;
var channel = PUBNUB.$('channel').value;
var origin = PUBNUB.$('origin').value;
var message = PUBNUB.$('message');
var output = PUBNUB.$('output');
var cipher_key = PUBNUB.$('cipher_key')
.value.split(/\s/).join('');
var secure_pubnub = PUBNUB.secure({
publish_key : publish_key,
subscribe_key : subscribe_key,
origin : origin,
ssl : true,
cipher_key : cipher_key
});
secure_pubnub.subscribe({
channel : channel,
connect : send_message,
callback : alert
});
function send_message() {
secure_pubnub.publish({
channel : channel,
message : message.value
});
}
send_message();
})();</script>