从XMPP获取脱机消息而不在线 [英] Get Offline Messages From XMPP Without Becoming Online

查看:120
本文介绍了从XMPP获取脱机消息而不在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将ejabberd服务器用于我们的移动聊天应用程序。
并且我们正在为IOS应用程序使用IOS XMPP-Framework( https://github.com/robbiehanson / XMPPFramework



但是我们在实现上遇到了一个问题,即找不到解决方案。
我们已经实现了XMPP消息传递的各个方面,除了一件事情外,其他所有方面都很好:



虽然我们的应用程序在后台运行,但是ejabberd服务器向我们发送了推送通知通知我们有关离线消息的信息。 (仅发送脱机消息的通知)



然后,我们决定实现IOS后台推送通知功能,以在应用程序处于后台时获取脱机消息。

>

但问题是我们必须联机(发送状态)才能获取脱机消息。
但是,这样做时,会造成2个不良后果:


  1. 发送邮件的一方认为我们的在线状态(甚至尽管我们在后台)

  2. 仅因为我们在应用程序在后台时正在联机,所以我们的服务器无法发送针对其他人的消息的推送通知,因为我们在线并且服务器只能发送

要解决该问题,我唯一想到的就是,如果有一种方法可以检索到离线来自xmpp服务器的消息,但不联机。
有人知道有没有办法使用XMPP-framework for iOS




让我澄清一下问题多一点:



问题不只一个:



问题1-推送通知问题:

  1.1-服务器检查邮件是发送给在线用户还是离线用户。如果用户处于脱机状态,则服务器发送推送通知以通知用户,但是如果用户处于脱机状态,则服务器不发送任何内容。 
1.2-当应用程序处于后台并收到脱机消息的通知时,应用程序变为活动状态(仍在后台)并变为联机状态以获取脱机消息
1.3-由于客户端变为联机状态,因此服务器未不再发送推送通知,但应用程序仍处于后台,因此无法通知用户他/她收到的消息。

因此,为了解决这些问题,我需要找到一种不发送脱机邮件来接收脱机邮件的方法服务器上的在线状态



问题2-邮件接收问题

  2.1 -服务器检查邮件是发送给在线用户还是离线用户。如果用户处于脱机状态,则服务器发送推送通知以通知用户,但是如果用户处于脱机状态,则服务器不发送任何内容。 
2.2-当应用程序处于后台并收到脱机消息的通知时,应用程序变为活动状态(仍在后台)并变为联机状态以获取脱机消息
2.3-当应用程序变为联机时,服务器将发送所有脱机消息发送给客户端,但不发送脱机消息的总数(至少我无法通过IOS XMPPFramework获得它)
2.4-我不知道客户端应该在后台存活多长时间,因为我不知道脱机消息的总数,因此在收到2-3条消息后,我必须在后台挂起该应用程序。但是在那种情况下,可能会出现错误的情况,例如XMPP Framework接收到脱机消息,但是在将其写入数据库之前,我暂停了客户端应用程序,等等。

为了找到解决这些问题的方法:


  1. 我需要找到一种方法当我想从服务器上获得仅1条脱机消息

  2. 如果可能的话,我还需要获取那些脱机消息而不使其联机


解决方案

查看 ejabberd_mod_offline_post


  1. 首先配置会议室必须是仅会员会议室,并在创建后立即将所有用户添加为会员,这样才能获得

  2. 将以上模块添加到ejabberd模块中。

  3. 实施回调服务以处理回调帖子。

这个想法是当用户下线时:




  • 在一对一的情况下,将引发offline_message_hook

  • 在MUC的情况下,将引起muc_filter_message,而没有在线状态离线。





在16.06上使用它。并且在以下行的源代码中存在错误:

  ... 

Body = xml :get_path_s(Stanza,[{elem,list_to_binary( body)},cdata]),

...

Type = xml:get_tag_attr_s(list_to_binary( type ),数据包),

主体= xml:get_path_s(Packet,[{elem,list_to_binary( body)},cdata]),

...

我通过将 f 添加到 xml:,例如
正文= f xml:get_path_s(节,[{elem,list_to_binary( body)},cdata]),



对于MUC,脱机用户位于脱机字段中,其格式为 user1..user2..user3 ..,您需要执行以下操作将其从字符串中分离出来。


We are using ejabberd server for our mobile chat application. And we are using IOS XMPP-Framework for our IOS application ( https://github.com/robbiehanson/XMPPFramework)

But we have a problem on implementation that we couldn't find a solution. We've implemented every aspect of XMPP messaging and all works good besides one thing:

While our application is on background, our ejabberd server sends us push notifications to inform us about offline messages. (Only sends notification for offline messages)

Then we've decided to implement the IOS background push notification functionality to get offline messages while the application is on background.

But the problem is we have to become online(send presence) in order to get offline messages. But when we do that it creates 2 unwanted consequences:

  1. The party who sends the message saw our presence as Online (Even though we are in the background)
  2. Just because we are becoming online while the application is on background , our server cannot send push notification for other people's messages becuase we are online and server can only send notification for offline messages.

For solving that problem, only thing that I can think of is, if there is a way to retrieve offline messages from xmpp server without becoming online. Does anyone know if Is there any way to do that with XMPP-Framework for ios

[EDIT] Let me clarify the issue a little bit more:

Problems are more than just one:

Problem 1 - Push notification problem:

1.1 - Server check if the message is sending to an online or offline user. If the user is offline server sends push notification to inform user but if the user is online server doesnt send anything. 
1.2 - When the application is in background and receive notification for offline messages, application become alive(still in background) and become online in order to get offline messages
1.3 - Because the client became online, server doesnt send the push notifications anymore but the application is still in background so the user cannot be informed about the message he/she received.

So In order to fix those problem I need to find a way to receive offline messages by not sending the online presence to server

Problem 2 - Message Receive Problem

2.1 - Server check if the message is sending to an online or offline user. If the user is offline server sends push notification to inform user but if the user is online server doesnt send anything. 
2.2 - When the application is in background and receive notification for offline messages, application become alive(still in background) and become online in order to get offline messages
2.3 - When the application became online server sends all offline messages to client but doesnt send the total count of offline messages(At least I cannot get it with IOS XMPPFramework)
2.4 - So I dont know how much longer the client should stay alive in the background because I dont know the total count of offline messages, so after getting 2-3 messages I have to suspend the application in the background. But in that case there might be buggy situations such as XMPP Framework receive the offline message but I suspend the client application before writing it to database etc...

In order to find a solution to those problems:

  1. I need to find a way to get only 1 offline message when I want from server
  2. If possible I also need to get those offline messages without becoming online

解决方案

Look into ejabberd_mod_offline_post

  1. First config the Room must be a Member-Only room, and add all users as members right after you created it, so that be able to get a total.
  2. Add above module into ejabberd modules.
  3. Implement a Callback Service to handle the callback post.

The idea is when User go offline:

  • In one-to-one case, offline_message_hook will be raised
  • In MUC case, muc_filter_message will be raised, and any one not Presence-Available is offline.

[Edited]:

I was using it on 16.06. And there was an error in the source code at lines:

...

Body = xml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),

...

 Type = xml:get_tag_attr_s(list_to_binary("type"), Packet),

 Body = xml:get_path_s(Packet, [{elem, list_to_binary("body")}, cdata]),

...

I fixed them by adding f to xml:, e.g. Body = fxml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),

And for MUC, the offline users is in the 'Offline' field as this format, 'user1..user2..user3..', what you need to do it to split them out from the string.

这篇关于从XMPP获取脱机消息而不在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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