catapush/xmpp

用于与 XMPP 服务器通信的客户端库。

v1.2 2024-08-28 17:20 UTC

This package is auto-updated.

Last update: 2024-09-29 10:38:26 UTC


README

在创建此仓库之前,我已经评估了以下 PHP 的 XMPP 库

不幸的是,以上都没有满足我的需求。这就是我基于 Nikita 的工作创建此仓库的原因。

功能

  • 以下功能已经从 Nikita 的分支 中提供
    • 连接并验证(使用 DIGEST-MD5)到 XMPP 服务器(已针对 Openfire 和 jabberd2 进行测试)
    • 支持 SSL/TLS 连接
    • 允许加入 MUC 房间
    • 向个人和 MUC 房间发送消息。
  • 以下功能是我添加的,以及各种重构等
    • 使用 PLAIN 连接并验证。
    • XEP-0045(多用户聊天)相关实现,包括创建聊天室、销毁聊天室、授权成员、撤销成员和获取成员列表。

示例代码

use Xmpp\Xep\Xep0045;

$roomId = 'YourHouse';
$userId = 'Tom';

$options = array(
    'username'  => 'your_username',
    'password'  => 'your_password',
    'host'      => 'example.com',
    'ssl'       => false,
    'port'      => 5222,
    'resource'  => uniqid('', true),
    'mucServer' => 'conference.example.com',
);
$xmpp = new Xep0045($options, $logger);

$xmpp->createRoom($roomId);            // Create the room.
$xmpp->grantMember($roomId, $userId);  // Add a member to the room.
$xmpp->getMemberList($roomId);         // Get member list and there should be only one member.
$xmpp->revokeMember($roomId, $userId); // Remove the only member out from the room.
$xmpp->getMemberList($roomId);         // Get member list and there should be nobody in the room.
$xmpp->destroyRoom($roomId);           // Destroy the room.
$xmpp->disconnect();                   // Disconnect from the server. Important for heavy-loaded servers.

已知限制

  • 只实现了 XEP-0045(多用户聊天)协议扩展的一部分。
  • 尽管代码是根据 FIG PSR 标准 重构/编写的,但它仅在某些项目和环境下的特定条件下开发和测试。

致谢

  • Nikita 的分支.
  • 同事 Jose(所有人都知道他叫 Tachu)、Jakub 和 Jerry 宝贵的建议,帮助改进性能和测试。

许可

MIT 许可证。