I'm using XMPPHP to retrieve the roster of my application users GMail account.
Can XMPPHP also tell me the roster contacts online status?
I can't seem to find how to do that...
cheers.
I'm using XMPPHP to retrieve the roster of my application users GMail account.
Can XMPPHP also tell me the roster contacts online status?
I can't seem to find how to do that...
cheers.
Here is an example of roster list and the online presence of GMail users;
$user_name = 'ENTER_EMAIL_ID';
$password = 'ENTER_PASSWORD';
$end_loop = 0;
$conn = new XMPPHP_XMPP('talk.google.com', 5222, $user_name,$password, "xmpphp", 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
$conn->autoSubscribe();
try {
$conn->connect();
while($end_loop <=0) {
$payloads = $conn->processUntil(array('end_stream', 'session_start','roster_received'));
foreach($payloads as $event) {
$pl = $event[1];
switch($event[0]) {
case 'session_start':
$conn->getRoster();
$conn->presence('I m presence'.time());
break;
case 'roster_received':
$array_contact=$pl;
foreach($array_contact as $user => $friends_name){
echo "<li>".$user.'_NAME_'.$friends_name['name'].'</li>';
}
$end_loop++;
break;
}
}
}
while(1)
{
$payloads = $conn->processUntil(array('presence'));
echo "<li>".$payloads[0][1]['from']."_Show_". $payloads[0][1]['show']."</li>";
$_SESSION[$payloads[0][1]['from']] = "~~";
}
$conn->disconnect();
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}
I haven't tried it with Google Talk, but generally you're looking for
$roster->getPresence($jid)['status']
$uStatus = $conn->roster->getPresence($jid);
echo "Online status: " . $uStatus['show']; // tells whether available or unavailable or dnd
echo "Status message: " . $uStatus['status']; // shows the user's status message
I posted an answer to a similar question here: XMPPHP GTalk Status
Here are the keys to getting it to work:
The other key for me was turning on verbose logging. You do that in your initial object construction:
$conn = new XMPPHP_XMPP('talk.google.com', 5222, $user_name,$password, "xmpphp", 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
This will output a verbose log to whatever your output is (browser window in my case).