如何仅通过发送一个< presence>来加入多个房间邮件到ejabberd服务器 [英] How to join multiple rooms by just sending one <presence> message to ejabberd server

查看:87
本文介绍了如何仅通过发送一个< presence>来加入多个房间邮件到ejabberd服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有20个房间要加入.简单的解决方案是向每个房间ID发送20条消息.考虑到性能,这是不好的.

我只想发送一个<presence>消息就可以加入20个房间,如何实现呢?编写模块以挂接自定义<presence>消息?但是我不知道如何编写这种模块.

解决方案

XEP-0045多用户聊天,无法定义使用单个状态数据包加入20个聊天室的方法.

但是,通过将其他XMPP扩展与多用户聊天相结合,您绝对可以在纯XMPP中实现此目标,而无需编写自定义的ejabberd扩展.

您可以依靠 XEP-0033扩展节寻址,您可以发送XMPP包给几个收件人.

示例中所示.

ejabberd配置

XEP-0033由于 ejabberd 15.04 ,默认情况下支持扩展节寻址. .通过在ejabberd配置模块部分中添加mod_multicast来确保已启用该功能:

modules:
...
  mod_multicast: {}

启用该服务后,您应该在支持功能http://jabber.org/protocol/address的服务器上拥有一个新服务(默认名称为multicast.example.net):

<iq type='get'
    to='multicast.example.net'
    id='info1'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

,响应为:

<iq from="multicast.example.net" type="result" to="test@example.net/laptop" id="info1">
<query xmlns="http://jabber.org/protocol/disco#info">
<identity category="service" type="multicast" name="Multicast"/>
<feature var="http://jabber.org/protocol/disco#info"/>
<feature var="http://jabber.org/protocol/disco#items"/>
<feature var="vcard-temp"/>
<feature var="http://jabber.org/protocol/address"/>
</query>
</iq>

用法

启用后,很容易发送针对多个MUC房间的状态数据包:

<presence to='multicast.example.net'>
    <addresses xmlns='http://jabber.org/protocol/address'>
        <address type='bcc' jid='testroom@conference.example.net/Usernick'/>
        <address type='bcc' jid='testroom2@ conference.example.net/Usernick'/>
    </addresses>
</presence>

因此,您将看到您同时加入多个房间.

问题

XEP-0033没有特别提到用例,并且该模块尚未经过测试以加入多个房间.在编写此示例时,我发现断开连接时,用户没有正确离开他已加入的房间. 这意味着您必须等待解决以下Github问题,然后才能在生产中使用该功能:广播组播存在数据包后存在状态发生变化.

For example, I have 20 rooms to join. The simple solution is to send 20 message to each room id. Considering the performance, this is bad.

I want to join the 20 rooms by just sending one <presence> message, how to achieve this? Writing a module to hook the custom <presence> message? But I do not know how to write this kind of module.

解决方案

In XEP-0045 Multi User Chat, there is no way defined to join 20 chat rooms with a single presence packet.

However, by combining other XMPP Extension with Multi User Chat, you can definitely achieve this in pure XMPP, without the need to write custom ejabberd extensions.

You can rely on XEP-0033 Extended Stanza Addressing, you can send an XMPP packet to several recipient. It also works with presence as shown in this example.

ejabberd configuration

XEP-0033 Extending Stanza Addressing is supported as default since ejabberd 15.04. Make sure you have enable the feature by adding mod_multicast in ejabberd configuration modules section:

modules:
...
  mod_multicast: {}

When the service is enabled, you should have a new service (as default named multicast.example.net) on the server supporting the feature http://jabber.org/protocol/address:

<iq type='get'
    to='multicast.example.net'
    id='info1'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

and response is:

<iq from="multicast.example.net" type="result" to="test@example.net/laptop" id="info1">
<query xmlns="http://jabber.org/protocol/disco#info">
<identity category="service" type="multicast" name="Multicast"/>
<feature var="http://jabber.org/protocol/disco#info"/>
<feature var="http://jabber.org/protocol/disco#items"/>
<feature var="vcard-temp"/>
<feature var="http://jabber.org/protocol/address"/>
</query>
</iq>

Usage

Once enabled, it is easy to send a presence packet targeting several MUC rooms:

<presence to='multicast.example.net'>
    <addresses xmlns='http://jabber.org/protocol/address'>
        <address type='bcc' jid='testroom@conference.example.net/Usernick'/>
        <address type='bcc' jid='testroom2@ conference.example.net/Usernick'/>
    </addresses>
</presence>

You will thus see that you are joining several rooms at the same time.

Issues

XEP-0033 did not specifically mention that use case and the module had not been testing to join multiple rooms. While writing this example I found that when disconnecting, user does not properly leave the rooms he had joined. It means you have to wait for the following Github issue to be fixed before the feature is usable in production: Broadcast presence change after multicast presence packet.

这篇关于如何仅通过发送一个&lt; presence&gt;来加入多个房间邮件到ejabberd服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆