示例#1
0
 /**
  * Factory for connection class.
  *
  * @param Options $options Options object
  * @return static
  */
 public static function factory(Options $options)
 {
     $socket = new SocketClient($options->getAddress());
     $object = new static($socket);
     $object->setOptions($options);
     return $object;
 }
示例#2
0
 /**
  * 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);
 }
示例#3
0
 /**
  * Setup implementation.
  *
  * @return void
  */
 protected function setupImplementation()
 {
     $this->connection->setEventManager($this->eventManager);
     $this->connection->setOptions($this->options);
     $implementation = $this->options->getImplementation();
     $implementation->setEventManager($this->eventManager);
     $implementation->setOptions($this->options);
     $implementation->register();
     $implementation->registerListener(new Logger());
 }
示例#4
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());
     }
 }
示例#5
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;
 }
示例#6
0
                    }
                }
            }
        } 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();