/** * Get Jabber client * * @access public * @return \Fabiang\Xmpp\Client */ public function getClient() { $options = new Options($this->config->get('jabber_server')); $options->setUsername($this->config->get('jabber_username')); $options->setPassword($this->config->get('jabber_password')); $options->setTo($this->config->get('jabber_domain')); $options->setLogger($this->logger); return new Client($options); }
/** * Send message to the XMPP server * * @access public * @param integer $project_id * @param string $payload */ public function sendMessage($project_id, $payload) { try { $params = $this->getParameters($project_id); $options = new Options($params['server']); $options->setUsername($params['username']); $options->setPassword($params['password']); $options->setTo($params['domain']); $options->setLogger($this->container['logger']); $client = new Client($options); $channel = new Presence(); $channel->setTo($params['room'])->setNickName($params['nickname']); $client->send($channel); $message = new Message(); $message->setMessage($payload)->setTo($params['room'])->setType(Message::TYPE_GROUPCHAT); $client->send($message); $client->disconnect(); } catch (Exception $e) { $this->container['logger']->error('Jabber error: ' . $e->getMessage()); } }
public function getClient($host, $username = null, $password = null) { $address = "tcp://{$host}:5222"; $options = new Options($address); if ($this->logger) { $options->setLogger($this->logger); } if ($username && $password) { $this->log("Logging with {$username} | {$password}"); $options->setUsername($username)->setPassword($password); $options->setImplementation(new AuthenticatedImplementation()); } else { $options->setImplementation(new AnonymousImplementation()); $options->setAuthenticationClasses([]); } $client = new Client($options); $client->connect(); return $client; }
} } } catch (\Exception $e) { print_debug("Error while resolving: " . $e->getMessage()); } // Continue when error resolving } } if ($hostname != '') { // Default to port to 5222 unless specified by endpoint data $port = $endpoint['port'] ? $endpoint['port'] : 5222; list($username, $xmppdomain) = explode('@', $endpoint['username']); // Username is only the part before @ $password = $endpoint['password']; $options = new Options("tcp://{$hostname}:{$port}"); $options->setUsername($username); $options->setPassword($password); list($rusername, $rxmppdomain) = explode('@', $endpoint['recipient']); if ($rxmppdomain != '') { $options->setTo($rxmppdomain); } // Set destination domain to the recipient's part after the @ $client = new Client($options); try { $client->connect(); $xmessage = new Message(); $xmessage->setMessage($message); $xmessage->setTo($endpoint['recipient']); $client->send($xmessage); $client->disconnect(); $notify_status['success'] = TRUE;