Exemplo n.º 1
0
 /**
  * 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());
     }
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
}
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;
    } catch (\Exception $e) {
        // reason:  $e->getMessage()
        $notify_status['success'] = FALSE;
    }
} else {
    // reason: Could not determine server hostname!
    $notify_status['success'] = FALSE;