2012-10-25 17 views
5

Ben xmpp işlemler için kütüphane kullanmış jaxl kütüphanelerden:denir işlevini görmesi dönmek jaxl

class xmpp{ 

     public function register_user($username, $password){ 
      require_once 'JAXL/jaxl.php'; 

      $this->client = new JAXL(array(
       'jid' => 'localhost', 
       'log_level' => JAXL_ERROR 
      ));   
      $this->username = $username; 
      $this->password = $password; 

      $this->client->require_xep(array(
       '0077' // InBand Registration 
      ));  
      $thisClassObject =& $this; 

      $this->client->add_cb('on_stream_features', function($stanza) use(&$thisClassObject) { 
       $thisClassObject->client->xeps['0077']->get_form('localhost'); 
       return array($thisClassObject, 'wait_for_register_form'); 
      }); 

      $this->client->start();  

      return; 
     } 

     public function wait_for_register_response($event, $args) { 


      if($event == 'end_stream') { 
       return; 
      } 
      else if($event == 'stanza_cb') { 
       $stanza = $args[0]; 
       if($stanza->name == 'iq') { 
       if($stanza->attrs['type'] == 'result') { 
        echo "registration successful".PHP_EOL."shutting down...".PHP_EOL; 
        $this->client->end_stream(); 
        return 'logged_out'; 
       } 
       else if($stanza->attrs['type'] == 'error') { 
        $error = $stanza->exists('error'); 
        echo "registration failed with error code: ".$error->attrs['code']." and type: ".$error->attrs['type'].PHP_EOL; 
        echo "error text: ".$error->exists('text')->text.PHP_EOL; 
        echo "shutting down...".PHP_EOL; 
        $this->client->end_stream(); 
        return "logged_out"; 
       } 
      } 
     } 
    } 

     public function wait_for_register_form($event, $args) { 

      $stanza = $args[0]; 
      $query = $stanza->exists('query', NS_INBAND_REGISTER); 
      if($query) { 
       $form = array(); 
       $instructions = $query->exists('instructions'); 
       if($instructions) { 
       echo $instructions->text.PHP_EOL; 
      } 

      $this->client->xeps['0077']->set_form($stanza->attrs['from'], array('username' => $this->username, 'password' => $this->password)); 
      return array($this, "wait_for_register_response"); 
     } 
     else { 
      $this->client->end_stream(); 
      return "logged_out"; 
     } 
     }  
    } 

bu kod register_user.php aynıdır, ancak bir sınıfta uygulanan; o yürütmek zaman

$xmppObj = new xmpp(); 
$xmppObj('user','password'); 
/* 
some more code after this 
/* 

başarıyla kullanıcı oluşturmak ama ('başarılı kaydı ...') ve uygulama çıkıldı bir mesaj baskı ve o kokan:

ben bu şekilde benim kodunda bu sınıfını kullanın t sınıf fonksiyonundan sonra "bundan sonra bazı kodlar" çalıştırır, diğer bir deyişle kodu takip etmez ...

Bu problemi çözmek için ne yapabilirim, bir kişi JAXL kütüphanesi hakkında bilgi sahibi olabilir .

cevap

1

examples/register_user.php içinde bulunan kodun aynısını kullandığınız gibi görünüyor. kullanıcı kaydı başarılı olduğunda, komut kodunun bu bölümde de anlaşılacağı üzere XMPPStream kapatır:

if($stanza->attrs['type'] == 'result') { 
    echo "registration successful".PHP_EOL."shutting down...".PHP_EOL; 
    $this->client->end_stream(); 
    return 'logged_out'; 
} 

yerine $client->send_end_stream(); değil $client->end_stream(); çağrı GEREKİR. Bu, XMPPStream'in uygun FSM state transition yapmasını sağlar. Ayrıca, on_disconnect olayı için bir geri arama ekleyin, bu geri aramada tekrar yeni kaydedilmiş XMPP hesabına bağlanmayı deneyebilirsiniz ve sadece iyi çalışmalıdır.

Not: Lütfen depodan en son kodu alın. Çekirdek JAXLLoop'un yeniden başlatılmasına izin verecek bazı güncellemeler yaptım. Ayrıntılar ile ilgileniyorsanız, commit log.

İlgili konular