XMPP持久化会议室存在感

7
我有一个XMPP服务器(openfire),有几个客户端(spark)分为几个组(部门)。我正在寻找将它们保留在会议室的能力。我的意思是类似于Skype的功能; 当用户关闭与组对话的窗口时,他的客户端会继续跟踪该房间的活动,并且当新消息出现时,用户会自动重新加入该会议。我已经发现Spark + Openfire中没有这样的功能,虽然有不错的自动加入功能的群聊书签功能,但它不能防止用户简单地离开房间而无法注意到后续事件。我想问一下是否有任何实现此功能的XMPP客户端。
我想到了设置具有管理权限的自己的机器人来坐在每个房间里,可能会强制踢/重新连接(例如通过Openfire的HTTP功能进行管理),当用户离开会议并且没有结束会话时,自动连接将使他回来。然而,如果有替代方案,我认为更容易和更好的方法是简单地更改客户端应用程序。
更新:我刚刚在Spark中找到了“自动接受群聊邀请”的选项,因此如果我重新配置所有客户端而不让他们知道,并设置此机器人仅在该人离开频道时发送邀请,那么它应该可以解决问题。还有其他想法吗?
更新2:
好的,伙计们,我已经成功测试了“Spark->首选项->群聊->自动接受群聊邀请”选项,它正在工作;我的Spark会自动加入我被邀请的每个会议。因此,我在基于JAXL 3.0的机器人中实现了会议观察->自动重新邀请功能。唯一的问题是jaxl-sent邀请对我不起作用。
以下是源代码:
<?php
###  JAXL message bot composed by ewilded
require 'JAXL-3.x/jaxl.php';
$jabber_conf=array('jid' => 'messagebot@localhost','host'=>'openfire','user'=>'messagebot','domain'=>'localhost','logLevel'=>4, 'strict'=>true, 'port'=>5222, 'pass'=>'somepass','log_level' => JAXL_INFO);
error_reporting(E_ALL);
$conference_rooms=array('tech@conference.localhost');
$client=null;

## Creating the object
$client = new JAXL($jabber_conf);
$client->require_xep(array(
      '0045', // MUC
      '0203', // Delayed Delivery
      '0199',  // XMPP Ping
      '0249'    // direct invite
));
## connect up callbacks
$client->add_cb('on_auth_success', function() use($client,$conference_rooms,$cron_interval) {
        echo "Auth success.\n";
    echo "My full jid: ".$client->full_jid->to_string()."\n";
        $client->set_status("Mesasge bot - available!");  // set your status
        $client->get_vcard();               // fetch your vcard
        $client->get_roster();              // fetch your roster list
        foreach($conference_rooms as $conference)
        {
            echo "Joining conference $conference.\n";
            $room_full_jid=new XMPPJid("$conference/messagebot");
            $client->xeps['0045']->join_room($room_full_jid);
       }
    });
$client->add_cb('on_chat_message', function($msg) use($client) {
            $to=$msg->from; 
          echo "Sending answer to: ".$to."\n";
            $client->send_chat_msg($to,"I am just simple bot written in PHP with JAXL XMPP library.");
        });
$client->add_cb('on_connect_error',function(){echo "Connection error :(\n";});
$client->add_cb('on_disconnect', function() {
     echo "Got disconnected.\n";
     _debug("got on_disconnect cb");
});

$client->add_cb('on_error_stanza',function($msg)
{    
    echo "Error stanza.";
    #print_r($msg);  
});
$client->add_cb('on_presence_stanza',function($msg) use($client)
{
    echo "Presence stanza.\n";
    ### joins and lefts are shown here, so here we simply send reinvite if we see that someone's left
    if(isset($msg->attrs['type'])&&$msg->attrs['type']=='unavailable')
    {
        if(isset($msg->childrens[0])&&isset($msg->childrens[0]->childrens[0])&&isset($msg->childrens[0]->childrens[0]->attrs['jid']))
        {
            echo "Sending invite.\n";
            $jid=$msg->childrens[0]->childrens[0]->attrs['jid'];
            $bare_jid=explode("/",$jid);
            $from_room=$msg->attrs['from'];
            $bare_from_room=explode("/",$from_room);
            echo $bare_jid[0]."\n";
            echo $bare_from_room[0]."\n";
            $client->xeps['0249']->invite($jid,$from_room); ### for some reason it does not work :(
            echo "Invite ($jid to $from_room) sent.\n";
        }
        else
        {
            echo "Ignoring.\n";
        }
    }
    echo "After presence stanza.\n";
});
$client->add_cb('on_normal_stanza',function()
{
    echo "Normal stanza.\n"; 
});
$client->add_cb('on_groupchat_message',function($msg) use ($client) {
echo "Groupchat event received.\n";
});

echo "Start called.\n";
$client->start();
?>

会议室上开启了“允许参与者邀请其他人”的选项,两个账户(一个是我朋友用来邀请我的账户,另一个是消息机器人使用的账户)都是Tech组的成员,没有管理员权限,所以我确定这不是设置/权限相关的问题。
现在,当我离开会议室时,机器人检测到并向我发送邀请,以下是它的输出: ... 存在状态信息。 发送邀请。 ewilded@localhost tech@conference.localhost 邀请(ewilded@localhost/Spark 2.6.3 to tech@conference.localhost/Ewil Ded)已发送。 在存在状态信息后。 ... 不幸的是,这个邀请没有生效。我想我可能在xep调用方面做错了什么,或者是它的参数: $client->xeps['0249']->invite($jid,$from_room);
如果有人在Jaxl中使用过有效的邀请,请帮忙,这是使它工作的唯一剩下的事情。

我相信唯一真实可行的方式来强制某人加入对话是创建自己的客户端,该客户端将自动加入并且不允许从该对话中断开连接。然后修改您的服务器,使其仅接受来自您的客户端的连接。 - Josh
1个回答

2

你是否在日志中看到了邀请数据包被发送出去的记录?

如果需要更深层次的调试,您可以直接调用$invite_pkt = $client->xeps['0249']->get_invite_pkt($to_bare_jid, $room_jid)。其中$to_bare_jid$room_jid都必须以字符串形式传递。 get_invite_pkt将根据直接MUC邀请XMPP扩展返回您需要发送的必要数据包。 如果您看到返回的数据包一切正常,则只需调用$client->send($invite_pkt)即可将其发送。

希望这能帮助您进行更好的调试并解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接