Comments (2)
In complement, here is my listener definition
use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\EventListener\AbstractEventListener;
use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
use Fabiang\Xmpp\Protocol\User\User;
/**
* Listener
*
* @package Xmpp\EventListener
*/
class Mam extends AbstractEventListener implements BlockingEventListenerInterface
{
/**
* Blocking.
*
* @var boolean
*/
protected $blocking = false;
/**
* {@inheritDoc}
*/
public function attachEvents()
{
$this->getOutputEventManager()
->attach('{urn:xmpp:mam:0}query', array($this, 'query'));
$this->getInputEventManager()
->attach('{urn:xmpp:mam:0}fin', array($this, 'result'));
}
/**
* Sending a query request for roster sets listener to blocking mode.
*
* @return void
*/
public function query()
{
$this->blocking = true;
}
/**
* Result received.
*
* @param \Fabiang\Xmpp\Event\XMLEvent $event
* @return void
*/
public function result(XMLEvent $event)
{
global $mamResult;
$logger = $this->getOptions()->getLogger();
if ($event->isEndTag()) {
$xml = $event->getParameter(0)->ownerDocument;
$xml->formatOutput = true;
$logger->debug( $xml->saveXML() );
$this->blocking = false;
}
}
/**
* {@inheritDoc}
*/
public function isBlocking()
{
return $this->blocking;
}
}
from xmpp.
I come back!
In fact, I misunderstood how the listener event works! I thinked that it returned the entirely buffer since the start of the function....
And so the problem came from my listener 😋
The parsing is true cause the answer is divided into severals answers of the type :
<message><result><message>....</message></result></message>
So now I create an event foreach tag "result" in buffer and the tag "fin" just close the listener.
Here is my new listener if you want to use it and integrate it ;)
<?php
/**
* Listener
*
* @package Xmpp\EventListener
*/
class Mam extends AbstractEventListener implements BlockingEventListenerInterface
{
/**
* Blocking.
*
* @var boolean
*/
protected $blocking = false;
/**
* Stock.
*
* @var boolean
*/
protected $xmlResult;
/**
* {@inheritDoc}
*/
public function attachEvents()
{
$this->getOutputEventManager()
->attach('{urn:xmpp:mam:0}query', array($this, 'query'));
$input = $this->getInputEventManager();
$input->attach('{urn:xmpp:mam:0}result', array($this, 'result'));
$input->attach('{urn:xmpp:mam:0}fin', array($this, 'fin')); // dans le cas d'un set, renvoi une balise {urn:xmpp:mam:0}fin
}
/**
* Sending a query request for roster sets listener to blocking mode.
*
* @return void
*/
public function query()
{
$this->blocking = true;
$this->xmlResult = new \DOMDocument();
}
/**
* Result received.
*
* @param \Fabiang\Xmpp\Event\XMLEvent $event
* @return void
*/
public function result(XMLEvent $event)
{
if ($event->isEndTag()) {
$xml = $event->getParameter(0);
$node = $this->xmlResult->importNode($xml, true);
$this->xmlResult->appendChild($node);
}
}
/**
* Result received.
*
* @param \Fabiang\Xmpp\Event\XMLEvent $event
* @return void
*/
public function fin(XMLEvent $event)
{
global $mamResult;
$logger = $this->getOptions()->getLogger();
if ($event->isEndTag()) {
$xml = $event->getParameter(0);
$this->logDomElement($xml);
$this->xmlResult->formatOutput = true;
$mamResult = $this->xmlResult->saveXML();
$this->blocking = false;
}
}
/**
* {@inheritDoc}
*/
public function isBlocking()
{
return $this->blocking;
}
public function logDomElement(\DOMElement $xml)
{
$newdoc = new \DOMDocument();
$newdoc->appendChild($newdoc->importNode($xml,true));
$newdoc->formatOutput = true;
$logger = $this->getOptions()->getLogger();
$logger->debug("Contenu du DOMElement : \n".$newdoc->saveXML());
}
}
Thanks again for this library 👍
from xmpp.
Related Issues (20)
- How to stable login status?
- Prosody supports
- StanzasErrorException is not triggered
- Stream Error: "malformed-request" HOT 3
- Add user to group
- How can I subscribe to other users?
- Stream Error: \"host-""unknown\ HOT 2
- stream_socket_client(): Failed to enable crypto HOT 1
- Warning: Fabiang\Xmpp\Stream\XMLStream::clearDocument(): Invalid State Error
- XEPs and RFCs support page with version
- Openfire example
- Seems this repo is dead. Check my fork
- Send Message to All Users
- Bag In documentation
- Seems this repo is dead x2, check my repo
- Receive message HOT 4
- Compatibility with openssl1.1.1 HOT 3
- stream_socket_enable_crypto(): SSL: Success HOT 1
- Starttls error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xmpp.