madeorsk/xmpp

XMPP协议(Jabber)连接库

v0.8.1 2021-09-28 15:17 UTC

This package is auto-updated.

Last update: 2024-09-28 21:43:46 UTC


README

PHP的XMPP协议(Jabber)连接库。

系统要求

  • PHP至少7.0或至少8.0
  • psr/log
  • (可选) psr/log-implementation - 例如monolog/monolog用于日志记录

安装

Composer新手?请阅读简介。将以下内容添加到您的composer文件中

composer require madeorsk/xmpp

文档

此库使用一个对象来保存选项

use Fabiang\Xmpp\Options;
$options = new Options($address);
$options->setUsername($username)
    ->setPassword($password);

服务器地址必须是格式 tcp://myjabber.com:5222
如果服务器支持TLS,连接将自动加密。

您还可以传递一个PSR-2兼容的对象给选项对象

$options->setLogger($logger)

客户端管理与Jabber服务器的连接,并需要选项对象

use Fabiang\Xmpp\Client;
$client = new Client($options);
// optional connect manually
$client->connect();

对于发送数据,您只需传递一个实现Fabiang\Xmpp\Protocol\ProtocolImplementationInterface的对象

use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;

// fetch roster list; users and their groups
$client->send(new Roster);
// set status to online
$client->send(new Presence);

// send a message to another user
$message = new Message;
$message->setMessage('test')
    ->setTo('nickname@myjabber.com')
$client->send($message);

// join a channel
$channel = new Presence;
$channel->setTo('channelname@conference.myjabber.com')
    ->setPassword('channelpassword')
    ->setNickName('mynick');
$client->send($channel);

// send a message to the above channel
$message = new Message;
$message->setMessage('test')
    ->setTo('channelname@conference.myjabber.com')
    ->setType(Message::TYPE_GROUPCHAT);
$client->send($message);

最后,您应该断开连接

$client->disconnect();

开发

如果您喜欢这个库并想贡献,请确保单元测试和集成测试正在运行。Composer将帮助您安装正确的PHPUnit和Behat版本。

composer install

之后

./vendor/bin/phpunit
./vendor/bin/behat

新功能应始终使用Behat进行测试。

许可

BSD-2-Clause。请参阅LICENSE

待办事项

  • 更好地集成通道
  • 服务器地址的工厂方法
  • 改进文档