Pusher returns no data for presenceAuth

673 views Asked by At

I am new to pusher and i am trying to create a "who's online using it" i followed the instructions carefully but i am having errors with the data ..

am i missing something ? pusher returns no data ..

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();
}

in the JS script , upon subscription_succeeded i logged members .. and get empty object .. am i missing something ? please help thank you ..

enter image description here

1

There are 1 answers

0
leggetter On BEST ANSWER

It looks like the name of the channel in this example is presence_channel. Presence channels need to have a presence- prefix. So just replace the underscore with a hyphen in the channel name.