XMPP 协议(Jabber)连接库

0.7.0 2018-12-18 20:41 UTC

This package is auto-updated.

Last update: 2024-09-15 20:43:31 UTC


README

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

License Latest Stable Version Total Downloads Dependency Status Build Status Coverage Status Scrutinizer Quality Score SensioLabsInsight

系统需求

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

安装

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

composer require fabiang/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

待办事项

  • 改善通道的集成
  • 为服务器地址提供工厂方法
  • 改进文档