2012-10-25 6 views
5

मैं xmpp लेनदेन के लिए पुस्तकालय का इस्तेमाल किया है jaxl पुस्तकालयों से:कार्य करने के लिए है कि यह कहा जाता है लौटने 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"; 
     } 
     }  
    } 

इन कोड register_user.php के रूप में ही हैं, लेकिन एक वर्ग में लागू;

मैं इस तरह से मेरी कोड में इस वर्ग का उपयोग करें:

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

जब यह निष्पादित, उपयोगकर्ता को सफलतापूर्वक बनाने लेकिन उसे प्रिंट संदेश ('पंजीकरण सफल ...') और आवेदन से बाहर निकल गया है और यह 'नहीं करता है क्लास फ़ंक्शन के बाद "इसके बाद कुछ कोड" निष्पादित करें, दूसरे शब्द में यह कोड का पालन नहीं करता है ...

इस समस्या को हल करने के लिए मैं क्या कर सकता हूं, कोई व्यक्ति JAXL लाइब्रेरी से परिचित होने में मेरी सहायता कर सकता है ।

उत्तर

1

ऐसा लगता है कि आप examples/register_user.php के अंदर पाए गए उसी कोड का उपयोग करके बहुत अधिक हैं। एक बार जब उपयोगकर्ता पंजीकरण सफल होता है, स्क्रिप्ट कोड के इस भाग से के रूप में स्पष्ट XMPPStream बंद कर देता है:

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

इसके बजाय आप कॉल करना होगा $client->send_end_stream(); और नहीं $client->end_stream();। यह सुनिश्चित करेगा कि अंतर्निहित XMPPStream उचित FSM state transition बनाता है। on_disconnect ईवेंट के लिए कॉलबैक भी जोड़ें, इस कॉलबैक के अंदर आप फिर से नए पंजीकृत एक्सएमपीपी खाते से जुड़ने का प्रयास कर सकते हैं और इसे ठीक काम करना चाहिए।

नोट: कृपया भंडार से नवीनतम कोड चेकआउट करें। मैंने कुछ अपडेट किए हैं जो कोर जेएक्सएलएलओप को फिर से शुरू करने की अनुमति देंगे। यदि आप विवरण में रुचि रखते हैं, तो यहां commit log है।

संबंधित मुद्दे