/** * Send notification to a project * * @access public * @param array $project * @param string $event_name * @param array $event_data */ public function notifyProject(array $project, $event_name, array $event_data) { try { $room = $this->projectMetadata->get($project['id'], 'jabber_room'); if (!empty($room)) { $client = $this->getClient(); $channel = new Presence(); $channel->setTo($room)->setNickName($this->config->get('jabber_nickname')); $client->send($channel); $message = new Message(); $message->setMessage($this->getMessage($project, $event_name, $event_data))->setTo($room)->setType(Message::TYPE_GROUPCHAT); $client->send($message); $client->disconnect(); } } catch (Exception $e) { $this->logger->error('Jabber error: ' . $e->getMessage()); } }
/** * 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()); } }
$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; } catch (\Exception $e) { // reason: $e->getMessage() $notify_status['success'] = FALSE; } } else { // reason: Could not determine server hostname! $notify_status['success'] = FALSE; } unset($message); // EOF