function test_xmpp_jid_construct() { $jid = new XMPPJid("1@domain.tld/res"); $this->assertEquals('1@domain.tld/res', $jid->to_string()); $jid = new XMPPJid("domain.tld/res"); $this->assertEquals('domain.tld/res', $jid->to_string()); $jid = new XMPPJid("component.domain.tld"); $this->assertEquals('component.domain.tld', $jid->to_string()); $jid = new XMPPJid("*****@*****.**"); $this->assertEquals('*****@*****.**', $jid->to_string()); }
$client->add_cb('on_groupchat_message', function ($stanza) { global $client; $from = new XMPPJid($stanza->from); $delay = $stanza->exists('delay', NS_DELAYED_DELIVERY); if ($from->resource) { echo "message stanza rcvd from " . $from->resource . " saying... " . $stanza->body . ($delay ? ", delay timestamp " . $delay->attrs['stamp'] : ", timestamp " . gmdate("Y-m-dTH:i:sZ")) . PHP_EOL; } else { $subject = $stanza->exists('subject'); if ($subject) { echo "room subject: " . $subject->text . ($delay ? ", delay timestamp " . $delay->attrs['stamp'] : ", timestamp " . gmdate("Y-m-dTH:i:sZ")) . PHP_EOL; } } }); $client->add_cb('on_presence_stanza', function ($stanza) { global $client, $room_full_jid; $from = new XMPPJid($stanza->from); // self-stanza received, we now have complete room roster if (strtolower($from->to_string()) == strtolower($room_full_jid->to_string())) { if (($x = $stanza->exists('x', NS_MUC . '#user')) !== false) { if (($status = $x->exists('status', null, array('code' => '110'))) !== false) { $item = $x->exists('item'); _info("xmlns #user exists with x " . $x->ns . " status " . $status->attrs['code'] . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role']); } else { _info("xmlns #user have no x child element"); } } else { _warning("=======> odd case 1"); } } else { if (strtolower($from->bare) == strtolower($room_full_jid->bare)) { if (($x = $stanza->exists('x', NS_MUC . '#user')) !== false) {
public function __set($prop, $val) { switch ($prop) { // access to jaxl xml properties case 'name': case 'ns': case 'text': case 'attrs': case 'children': return $this->xml->{$prop} = $val; break; // access to common xml attributes // access to common xml attributes case 'to': case 'from': case 'id': case 'type': $this->xml->attrs[$prop] = $val; return true; break; // access to parts of common xml attributes // access to parts of common xml attributes case 'to_node': case 'to_domain': case 'to_resource': case 'from_node': case 'from_domain': case 'from_resource': list($attr, $key) = explode('_', $prop); $val1 = isset($this->xml->attrs[$attr]) ? $this->xml->attrs[$attr] : null; if (!$val1) { $val1 = ''; } $val1 = new XMPPJid($val1); $val1->{$key} = $val; $this->xml->attrs[$attr] = $val1->to_string(); return true; break; // access to first child element text // access to first child element text case 'status': case 'show': case 'priority': case 'body': case 'thread': case 'subject': $val1 = $this->xml->exists($prop); if (!$val1) { $this->xml->c($prop)->t($val)->up(); } else { $this->xml->update($prop, $val1->ns, $val1->attrs, $val); } return true; break; default: return null; break; } }
function on_presence_stanza_callback($stanza) { global $client, $room_full_jid; $from = new XMPPJid($stanza->from); // self-stanza received, we now have complete room roster if (strtolower($from->to_string()) == strtolower($room_full_jid->to_string())) { if (($x = $stanza->exists('x', XEP0045::NS_MUC . '#user')) !== false) { if (($status = $x->exists('status', null, array('code' => '110'))) !== false) { $item = $x->exists('item'); JAXLLogger::info("xmlns #user exists with x " . $x->ns . " status " . $status->attrs['code'] . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role']); } else { JAXLLogger::info("xmlns #user have no x child element"); } } else { JAXLLogger::warning("=======> odd case 1"); } } elseif (strtolower($from->bare) == strtolower($room_full_jid->bare)) { // stanza from other users received if (($x = $stanza->exists('x', XEP0045::NS_MUC . '#user')) !== false) { $item = $x->exists('item'); echo "presence stanza of type " . ($stanza->type ? $stanza->type : "available") . " received from " . $from->resource . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role'] . PHP_EOL; } else { JAXLLogger::warning("=======> odd case 2"); } } else { JAXLLogger::warning("=======> odd case 3"); } }
} $config['sim_prefix'] .= $nick; l("[JAXL] Loading JAXL and connecting..."); $client = new \JAXL($config['jaxl']); $client->require_xep(array('0045', '0203', '0199')); $client->add_cb('on_auth_success', function () { global $client, $config, $rooms; l("[JAXL] Connected with jid " . $client->full_jid->to_string()); $client->get_vcard(); $client->get_roster(); $client->set_status("", "chat", 10); $ctrl = new \XMPPJid($config['LCN_control'] . '/' . $config['sim_prefix']); l("[JAXL] Joining room " . $ctrl->to_string()); $client->xeps['0045']->join_room($ctrl); l("[JAXL] Joined room " . $ctrl->to_string()); $rooms = new \XMPPJid($config['sim'] . '/' . $config['sim_prefix']); l("[JAXL] Joining room " . $rooms->to_string()); $client->xeps['0045']->join_room($rooms); l("[JAXL] Joined room " . $rooms->to_string()); }); $client->add_cb('on_auth_failure', function ($reason) { global $client; $client->send_end_stream(); l("[JAXL] Auth failure: " . $reason, L_WARN); }); // Where the magic happens. "Magic" "Happens". I dunno why I type this either. $client->add_cb('on_groupchat_message', function ($stanza) { global $config, $client, $source, $nick; if (LCN::isLWT($stanza->body)) { $p = new LCN($stanza->body); if (!array_key_exists('LCNerror', $p->res) && $p->res['aud'] == 'loungesim_' . $config['sim_prefix']) {
/** * @dataProvider jidPositiveProvider */ public function test_xmpp_jid_construct($jidText) { $jid = new XMPPJid($jidText); $this->assertEquals($jidText, $jid->to_string()); }