PHP code example of kadet / nucleus

1. Go to this page and download the library: Download kadet/nucleus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kadet / nucleus example snippets


$loop   = React\EventLoop\Factory::create();
$client = new \Kadet\Xmpp\XmppClient(new \Kadet\Xmpp\Jid('[email protected]/resource'), [
    'loop'     => $loop,
    'password' => 'epicpasspeoem',
]);

// Event declatation ...

$client->connect();
$loop->run();

$client = new \Kadet\Xmpp\XmppClient(new \Kadet\Xmpp\Jid('[email protected]/resource'));
$client->loop = $loop;
$client->password = 'epicpasspoem';

element(Kadet\Xmpp\Xml\XmlElement $element) // element received
features(Kadet\Xmpp\StreamFeatures $features) // features received

send.element(Kadet\Xmpp\Xml\XmlElement $element) // element sent
send.text(string $data) // some text (non valid XmlElement) sent

stream.open(Kadet\Xmpp\Xml\XmlElement $stream) // Stream started
stream.close() // Stream closed

stream.error(Kadet\Xmpp\Stream\Error $error) // Stream errored

connect(StreamDuplexInterface $stream) // called when connection is ready
exception(Exception $exception) // called when otherwise unhandled exception happens

$emitter->on($event, $callback, $predicate = null, $priority = 0);

// Will fire event only if element belongs into self::TLS_NAMESPACE.
$stream->on('element', $callable, with\xmlns(self::TLS_NAMESPACE));

$stream->on('element', $second, null, 0);
$stream->on('element', $first, null, 1); // will fire first

$stream->on('element', $stream->reference($callable)); // Will fire $callable($stream, ...$arguments);