Skip to content

Instantly share code, notes, and snippets.

@kinlane
Created February 28, 2011 21:30
Show Gist options
  • Save kinlane/848079 to your computer and use it in GitHub Desktop.
Save kinlane/848079 to your computer and use it in GitHub Desktop.
Persisent XMPP Connection for Google Cloud Print XMPP Print Job Service Using XMPPHP Library
// Begin XMPP
$conn = new XMPPHP_XMPP('talk.google.com', 5222, $G_Email, $G_Pass, 'xmpphp', 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
$conn->autoSubscribe();
$vcard_request = array();
//var_dump($conn);
try {
$conn->connect();
while(!$conn->isDisconnected())
{
$payloads = $conn->processUntil(array('message', 'session_start'));
foreach($payloads as $event)
{
$pl = $event[1];
switch($event[0])
{
case 'message':
$Full_JID = $conn->fulljid;
$Bare_JID = $conn->jid;
echo "<hr />";
//echo "Message from: " . $pl['from'] . "<br />";
if($pl['from'] == 'cloudprint.google.com')
{
// We have received a push for this Print Proxy ID + User.
// Now we can /fetch print jobs for this Proxy, User, Printer ID
echo "Print Job Notification Received for " . $Printer_Proxy . " / " . $Bare_JID . "<br />";
}
break;
case 'session_start':
$Full_JID = $conn->fulljid;
$Bare_JID = $conn->jid;
echo "FULL JID: " . $conn->fulljid . "<br />";
echo "JID: " . $conn->jid . "<br />";
echo "<hr />";
$Body = "<iq from='" . $Full_JID . "' to='" . $Bare_JID . "' type='set' id='1'><subscribe xmlns='google:push'><item channel='cloudprint.google.com/proxy/" . $Printer_Proxy . "' from='cloudprint.google.com'/></subscribe></iq>";
$conn->subscription($Body);
break;
}
}
}
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment