我是Pusher的新手,我正在尝试创建一个"谁在线使用它"我仔细按照说明操作,但我的数据有误。
我错过了什么吗?推送器没有返回数据..JS:
var socket = new Pusher('MYKEY', {authEndpoint:'php/pusher/auth.php'});
var channel_name = 'presence_channel';
var pchannel = socket.subscribe(channel_name);
pchannel.bind('pusher:subscription_succeeded', function(members){
console.log(members);
$.each(members, function(members){
console.log(members.info.username);
});
});
pchannel.bind('pusher:member_added', function(member){
//add_user(member.info.username);
console.log(member);
});
Pusher.log = function(message) {
if (window.console && window.console.log) {
window.console.log(message);
}
};
PHP
if(session_id() == ''){ session_start(); }
header('Content-Type: application/json');
require_once 'Pusher.php';
require_once 'config.php';
if(isset($_SESSION['uid']))
{
$pusher = new Pusher($app_key, $app_secret, $app_id);
$presence_data = array('username' => $_SESSION['cname']);
$uid = $_SESSION['uid'];
echo $pusher->presence_auth($_POST['channel_name'], $_POST['socket_id'], $uid, $presence_data);
exit();
}
在JS脚本中,在subscription_succeeded上我记录了成员..并获取空对象..我错过了什么?请帮助谢谢..
答案 0 :(得分:2)
此示例中的频道名称似乎是presence_channel
。在线通道需要有presence-
前缀。所以只需用通道名称中的连字符替换下划线。