`
bluky999
  • 浏览: 719615 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

关于XMPP和openfire中的消息回执和聊天状态

阅读更多

关于XMPP和openfire中的消息回执和聊天状态

 

1 协议层:

XMPP扩展协议已经定义了消息回执,参见 http://xmpp.org/extensions/xep-0184.html   

 

同样也定义了聊天状态,参见 http://xmpp.org/extensions/xep-0085.html 

 

 

 

XEP-0184: Message Delivery Receipts

 

XEP-0184 写道
The following is an example of a content message that includes a request for return receipt.

Example 3. A content message with receipt requested

<message
from='northumberland@shakespeare.lit/westminster'
id='richard2-4.1.247'
to='kingrichard@royalty.england.lit/throne'>
<body>My lord, dispatch; read o'er these articles.</body>
<request xmlns='urn:xmpp:receipts'/>
</message>
 

Note: A sender MUST include an 'id' attribute on every content message that requests a receipt, so that the sender can properly track ack messages.

The recipient shall generate an ack message if and only if (1) it supports the Message Delivery Receipts protocol and (2) it is configured to return receipts, either globally or for this recipient (otherwise it MUST NOT return a receipt and SHOULD NOT return an error).

Example 4. A message delivery receipt

<message
from='kingrichard@royalty.england.lit/throne'
id='bi29sg183b4v'
to='northumberland@shakespeare.lit/westminster'>
<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>
</message>
 

When the recipient sends an ack message, it SHOULD ensure that the message stanza contains only one child element, namely the <received/> element qualified by the 'urn:xmpp:receipts' namespace. In addition, it SHOULD include an 'id' attribute that echoes the 'id' attribute of the content message. Naturally, intermediate entities might add other extension elements to the message when routing or delivering the receipt message, e.g., a <delay/> element as specified in Delayed Delivery [11].

 

 

XEP-0085: Chat State Notifications

写道
In the following conversation, both User <bernardo@shakespeare.lit> and Contact <francisco@shakespeare.lit> support chat state notifications.

Example 3. User Sends Initial Content Message With <active/> Notification

<message
from='bernardo@shakespeare.lit/pda'
to='francisco@shakespeare.lit'
type='chat'>
<body>Who's there?</body>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message>

Example 4. Contact's Client Sends Content Message Reply With <active/> Notification

<message
from='francisco@shakespeare.lit/elsinore'
to='bernardo@shakespeare.lit/pda'
type='chat'>
<body>Nay, answer me: stand, and unfold yourself.</body>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message>

Because the User now knows that the Contact supports chat state notifications, the User can send other notification types.

Example 5. User Sends Standalone <composing/> Notification

<message
from='bernardo@shakespeare.lit/pda'
to='francisco@shakespeare.lit/elsinore'
type='chat'>
<composing xmlns='http://jabber.org/protocol/chatstates'/>
</message>

Example 6. User Sends a Content Message Reply With <active/> Notification

<message
from='bernardo@shakespeare.lit/pda'
to='francisco@shakespeare.lit/elsinore'
type='chat'>
<body>Long live the king!</body>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message>

And so forth.

 

Table 1: Chat States

State Definition Suggested Triggers
<active/> User is actively participating in the chat session. User accepts an initial content message, sends a content message, gives focus to the chat session interface (perhaps after being inactive), or is otherwise paying attention to the conversation.
<inactive/> User has not been actively participating in the chat session. User has not interacted with the chat session interface for an intermediate period of time (e.g., 2 minutes).
<gone/> User has effectively ended their participation in the chat session. User has not interacted with the chat session interface, system, or device for a relatively long period of time (e.g., 10 minutes).
<composing/> User is composing a message. User is actively interacting with a message input interface specific to this chat session (e.g., by typing in the input area of a chat window).
<paused/> User had been composing but now has stopped. User was composing but has not interacted with the message input interface for a short period of time (e.g., 30 seconds).

 

The following figure attempts to capture the most common state transitions in visual form (all four of the states shown can also transition to the GONE state).

 


                o (start)
                |
                |
INACTIVE <--> ACTIVE <--> COMPOSING <--> PAUSED
    |                                       |
    |                                       |
    +---<---<---<---<---<---<---<---<---<---+
  

Note: Other transitions are not forbidden if the developers of an implementation feel that such transitions are desirable (e.g., INACTIVE to PAUSED if a user returns to a chat session interface containing an unfinished message).

 

 

2 实现层

 

openfire项目中,今年(2011)3月已经有人提交了XEP0184的feature,参见 http://issues.igniterealtime.org/browse/OF-434


Add support for XEP-0184: Message Delivery Receipts

 

不过正如 wroot 对我的回复所述,此特性的release还遥遥无期:

 

wroot 写道
If nobody provides patches, probably never. We don't have active developers at the moment.

 

 

至于XEP-0085 ,目前主流的实现都是支持的 ,而且这个逻辑更多是在客户端,比较简单。

 

 

3 解决方案 

 

- 如果可能,自己修改openfire,实现此特性即可;或者使用插件的方式去实现。 其实难度不大,只是openfire是开源项目,多人异地协作,目前相对稳定,稳步发展;所以增加这种特性比自己实现还缓慢,需要有人推进才行。

 

- 曲线救国: 对于message消息,自己可以做一些私有的约定,比如服务器做一些响应,客户端额外发一些IQ等。当然不太推荐这种方式。

 

 

以上是两种思路,具体实现还要看产品或项目的具体需求,比如是否严格控制网络带宽,是否严格要求信息投递成功率等。

 

 

消息回执和聊天状态都是用户体验相关的feature,所以需要在功能稳定和流量等因素许可的前提下去优化和改进。 

 

同理,类似 geo-location 或 LBS 相关的feature,我们也可以自己去实现。

比如 openfireLBS 插件   https://github.com/node/openfireLBS 

0
1
分享到:
评论
3 楼 bluky999 2014-01-15  

XEP-0022: Message Events

http://xmpp.org/extensions/xep-0022.html



Example 1. Requesting notification of offline storage and delivery for a message

<message to='romeo@montague.net' id='message22'>
  <body>Art thou not Romeo, and a Montague?</body>
  <x xmlns='jabber:x:event'>
    <offline/>
    <delivered/>
    <composing/>
  </x>
</message>
2 楼 bluky999 2014-01-15  
Example 1. A disco#info query

<iq from='romeo@shakespeare.lit/orchard'
    id='disco1'
    to='juliet@capulet.com/balcony'
    type='get'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
 
Example 2. A disco#info response

<iq from='juliet@capulet.com/balcony'
    id='disco1'
    to='romeo@shakespeare.lit/orchard'
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <feature var='http://jabber.org/protocol/chatstates'/>
  </query>
</iq>
 
1 楼 bluky999 2013-12-25  
有朋友反馈了一些意见,这里回复下:


对于一个feature,客户端首先可以使用 http://xmpp.org/extensions/xep-0030.html  的 service discover 协议来探测服务器/对方知否支持此feature,若支持,则可以使用,若不支持,则肯定收不到回应的。


但在实践中,如果你只是希望不同客户端发送的message有消息回执功能,比如“已送达” “已读”等,那么不管服务器是否支持,直接发送带挥之请求的message吧, 如果服务器全部转发了,那么你只要在客户端监听message的时候处理下回执请求和响应即可! 

相关推荐

    openfire消息回执插件

    综上所述,Openfire消息回执插件通过DbChatLogsManager管理数据库中的聊天记录,ChatLogPlugin作为插件核心处理回执事件,并且ChatLogs提供对聊天记录数据的抽象和操作。这三者共同协作,实现了Openfire中的消息回执...

    基于openfire,XMPPFramework实现的iOS聊天应用

    XMPP是一种标准协议,广泛用于即时消息、在线状态管理以及群组聊天。Openfire支持多平台,易于安装和配置,可以快速搭建起一个稳定的IM服务器。 **二、XMPPFramework解析** XMPPFramework是iOS和Mac OS X上的一个...

    XMPP协议之消息回执解决方案.docx

    消息回执是指发送方在发送消息后,能够收到接收方关于消息是否成功接收的反馈信息。这种机制能够有效提高消息传递的可靠性,尤其是在网络环境复杂多变的情况下。实现消息回执的主要目的是为了确保即使在网络状况不佳...

    Android使用XMPP协议、OpenFire服务器和Smack类库实现即时通信

    在实际项目中,为了提供更好的用户体验,还需要考虑网络连接的断开重连、消息的存储和回执、离线消息的处理等细节。同时,考虑到Android的特性,如后台服务限制、电量优化等,可能需要采用Service或JobScheduler等...

    openfire防丢包插件及源码

    在实时通信中,丢包问题常常是影响用户体验的重要因素,为此,开发者们设计了一款专门针对Openfire的防丢包插件,以确保消息的完整性和可靠性。本文将详细介绍该防丢包插件的工作原理,并对源码进行深入解析。 首先...

    iOS 实现的即时聊天

    XMPP是一种基于XML的开放标准,广泛用于即时消息、在线状态管理和文件传输等场景。下面我们将详细探讨iOS上实现XMPP即时聊天涉及的关键知识点。 1. **XMPP框架选择**:在iOS开发中,常见的XMPP框架有XEPermissions...

    asmack通讯

    ASMack提供了一套API,使得开发者能够方便地创建XMPP连接,发送和接收消息,处理用户状态等。其主要功能包括: 1. **连接管理**:ASMack支持连接到XMPP服务器,建立TCP连接或使用SSL/TLS加密。 2. **会话管理**:...

    androidpn服务器推送

    4. **消息回执**:描述中提到了消息回执,这意味着服务器需要知道客户端是否已经成功接收到推送的消息。这通常通过客户端在接收到消息后向服务器发送一个确认回执来实现。服务器收到回执后,可以标记消息为已读,...

    WeChat:基于XMPP模仿微信App进行IM(即时聊天)开发,并适配iPad、iOS7。(暂停开发,有空再讲……)

    3. **实时消息传递**:使用XMPP框架的核心功能,实现实时文本、图片、文件等消息的发送与接收,同时支持消息撤回、已读回执等功能。 4. **群组聊天**:类似微信的微信群,可以创建和加入多人群聊,实现多用户间的...

    Android 仿QQ客户端及服务端源码

    - **消息回执**:发送消息已读、未读状态,确保信息传递的准确性。 - **群聊**:创建群组,支持多人同时在线聊天。 7. **性能优化**: - **数据缓存**:本地缓存常用数据,减少网络请求。 - **内存管理**:避免...

Global site tag (gtag.js) - Google Analytics