Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kadet1090 committed Aug 19, 2016
1 parent 89514e2 commit 5f3a6cc
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Nucleus Logo](https://dl.dropboxusercontent.com/u/60020102/ShareX/2016-07/nucleus_Logo%20%2B%20Logotyp%20-%20Color.png)
# [WiP] Nucleus - XMPP Library for PHP
[![Packagist](https://img.shields.io/packagist/v/kadet/nucleus.svg?maxAge=2592000?style=flat-square)](https://packagist.org/packages/kadet/nucleus)
![Milestone](https://img.shields.io/badge/milestone-1-yellow.svg)
![Milestone](https://img.shields.io/badge/milestone-2-yellow.svg)
[![Travis](https://img.shields.io/travis/kadet1090/nucleus.svg?maxAge=2592000?style=flat-square)](https://travis-ci.org/kadet1090/nucleus)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/kadet1090/nucleus.svg?maxAge=2592000?style=flat-square)](https://scrutinizer-ci.com/g/kadet1090/nucleus/?branch=master)
![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/kadet1090/nucleus.svg?maxAge=2592000?style=flat-square)
Expand All @@ -10,32 +10,38 @@ Asynchronous XMPP library for PHP based on [React PHP](https://github.com/reactp
so I don't recommend using it. It obsoletes my old [`kadet/xmpp`](https://github.com/kadet1090/xmpp) package.

## Already available
### XMPP Stream handling
Stream handling is fully implemented, it can handle xml parsing, stream management (with errors), and writing data into
connection. XMPP stream acts like proxy for underlying connection stream.
### Modular Client class
By design client class (`\Kadet\Xmpp\XmppClient`) acts like stream - for sending and receiving packets over network,
event emitter to inform about events, and dependency container (what a wonderful violation of SRP) for managing modules.
It allows to move almost all logic outside of that class into proper and exchangeable components.

Basic client instance can be set up quite easily:
```php
$loop = React\EventLoop\Factory::create();
$connection = new \Kadet\Xmpp\Network\TcpStream(stream_socket_client('tcp://server.xmpp:5222'), $loop); // subject to change

$factory = new \Kadet\Xmpp\Xml\XmlFactory(); // Factory is used for xml element creation
$parser = new \Kadet\Xmpp\Xml\XmlParser($factory); // Parser converts received xml stream into `XmlElement`s

$stream = new \Kadet\Xmpp\XmppStream($parser, $connection); // Connection can be any object implementing DuplexStreamInterface from react

// declare events...

$stream->start([
'from' => 'test@jid.pl',
'to' => 'jid.pl'
$loop = React\EventLoop\Factory::create();
$client = new \Kadet\Xmpp\XmppClient(new \Kadet\Xmpp\Jid('local@domain.tld/resource'), [
'loop' => $loop,
'password' => 'epicpasspeoem',
]);

// Event declatation ...

$loop->run();
```

Options passed to second argument, are equivalent to C#'s property instantiation, so above example is same as calling:
```php
$client = new \Kadet\Xmpp\XmppClient(new \Kadet\Xmpp\Jid('local@domain.tld/resource'));
$client->loop = $loop;
$client->password = 'epicpasspoem';
```

With exception for `modules` and `default-modules` which are used for initial module setup. You can disable default
modules by setting `default-modules` to false, but it's highly not recommended for non-test purposes.

Available events are:
```php
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
Expand All @@ -44,7 +50,11 @@ 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
```
also, all default events from [`react/stream`] are applicable.

#### TLS Handling
Most of XMPP servers require TLS connection, by default React streams don't support encryption. Library will handle
Expand Down Expand Up @@ -89,3 +99,4 @@ each milestone API should be stable - but it's not guaranteed at the moment.
[Trello]: https://trello.com/b/WHQ6d3hw/xmpp
[rfc6120]: xmpp.org/rfcs/rfc6120.html
[`evenement/evenement`]: https://packagist.org/packages/evenement/evenement
[`react/stream`]: https://github.com/reactphp/stream

0 comments on commit 5f3a6cc

Please sign in to comment.