简体   繁体   English

Xmpp MultiUserChat(MUC)组不保持稳定

[英]Xmpp MultiUserChat (MUC) Group Does not remain stable

I created an Xmpp Chat App where I have implemented the one-to-one and group chat. 我创建了一个Xmpp聊天应用程序,我已经实现了一对一和群聊。 The Chat itself is working fine. 聊天本身工作正常。 The issue is in Group chat. 问题出在群聊中。 I created a group with 2-3 members, again the chat is working fine, but when I kill the application and restart it, I'm not getting the group messsages from any of the groups I have created. 我创建了一个包含2-3个成员的组,再次聊天工作正常,但是当我杀死应用程序并重新启动它时,我没有从我创建的任何组中获取组的消息。 while I am connected to the XMPP Server and re-join any group then I get the messages. 当我连接到XMPP服务器并重新加入任何组时,我收到消息。 My problem is that I have to join into groups again every time after I kill the app completly. 我的问题是,每次我完全杀死应用程序后,我必须再次加入群组。

Please let me know How I can get the messages or join automatically in group when i open the application from killed state. 请让我知道当我从被杀死状态打开应用程序时,如何获取消息或自动加入群组。

You need to send presence to XMPP server once your application launched or come out from background. 一旦应用程序启动或从后台发出,您需要向XMPP服务器发送状态。 so the XMPP server understand that respective group is ready to handle event. 所以XMPP服务器了解相应的group已准备好处理事件。

Edit : you can send presence using following code. 编辑 :您可以使用以下代码发送状态。

- (void)goOnline {


    NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
    NSXMLElement *show = [NSXMLElement elementWithName:@"show"
                                           stringValue:@"dnd"];
    NSXMLElement *status = [NSXMLElement elementWithName:@"status" stringValue:@"available"];
    NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"24"];

    [presence addChild:show];
    [presence addChild:status];
    [presence addChild:priority];

    [_xmppStream sendElement:presence];

    [self createOrJoinRoom];

}
- (void)createOrJoinRoom {
    if ([appDelegate.xmppStream isConnected]) {

        NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:@"XMPPUserId"];

        NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
        [presence addAttributeWithName:@"from" stringValue:[[appDelegate.xmppStream myJID]full]];
        [presence addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@%@/%@", @"newone", GroupChatRoomName,myJID]];
        NSXMLElement *xelement = [NSXMLElement elementWithName:@"x" xmlns:XMPPMUCNamespace];
        [presence addChild:xelement];
        [appDelegate.xmppStream sendElement:presence];
    }

}

May this help you. 愿这对你有所帮助。

You have to join all your previous join/connected groups. 您必须加入以前的所有加入/连接组。 Because in iOS if you kill your app then you left from your created or joined groups. 因为在iOS中如果你杀了你的应用程序,那么你就离开了你创建或加入的组。

So every time in this section of the code 所以每次都在这段代码中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

you have to join your group again. 你必须再次加入你的小组。

Below is demo code for it : 下面是它的演示代码:

XMPPRoomHybridStorage *xmppRoomStorage1 = [XMPPRoomHybridStorage sharedInstance];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage1 jid:RoomName];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:appDelegate.Obj_xmppManager.xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"1"];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user history:nil];

Adding to the Presence answer, I would also check more basic things - 除了Presence答案,我还会检查更基本的东西 -

  1. Are the rooms (group chat) you create persistant? 您创建的房间(群聊)是否持续存在? or do you have to create the room again every time you connect? 或者你每次连接时都要再次创建房间吗? (notice the difference between 'openning' and 'creating'). (注意'开放'和'创造'之间的区别)。
    On some servers, rooms are temporary by default - you can check this by connecting with 2 seperate clients, send some messages, disconnect only one of them, and reconnect - if you do see the messages that were sent in your reconnected client - this might be your issue, can you show the parameters you pass to the server when you create the room?. 在某些服务器上,默认情况下房间是临时的 - 您可以通过连接2个单独的客户端,发送一些消息,仅断开其中一个消息并重新连接来检查这一点 - 如果您确实看到在重新连接的客户端中发送的消息 - 这可能是您的问题,您可以在创建房间时显示传递给服务器的参数吗?

  2. Is the server you are using configured to send history messages by default, and if so how many, again, server implementations may vary, could you share some information on the server you are using (openfire, ejabbered, prosody)? 您正在使用的服务器是否配置为默认发送历史消息,如果是这样,服务器实现的数量可能会有多少,您是否可以在您正在使用的服务器上共享一些信息(openfire,ejabbered,韵律)? or a snippet from you configuration file? 或者您配置文件中的片段?

  3. Is it possible you are getting the messages, but not showing them correctly, maybe not refreshing the screen\\view when first entering a room? 您是否有可能收到消息,但没有正确显示它们,可能在第一次进入房间时没有刷新屏幕\\视图? any log messages? 任何日志消息?

I am also facing this issue since a week and looking for solution and after a lot of search on google and stack overflow i got a clue which solve this issue. 我也面临这个问题,因为一周后寻找解决方案,经过大量搜索谷歌和堆栈溢出后,我得到了解决这个问题的线索。

In my case group created successfully and chat is working good with members and members can send me chat too but when any member of group logout or kill the app and then login again he is unable to send message is this group and group says in response Only occupants are allowed to send messages to the conference . 在我的情况下,小组成功创建并且聊天工作正常,会员和会员也可以发送给我聊天但是当群组的任何成员退出或杀死应用程序然后再次登录他无法发送消息时此群组和群组在回复时说允许占用者向会议发送消息

In my case when user tap on group to go into group and start chat i call this method to join group. 在我的情况下,当用户点击组进入组并开始聊天时,我将此方法称为加入组。

NSString *roomJID = [NSString stringWithFormat:@"%@@conference.yourHostName", roomJid];
XMPPJID *jid = [XMPPJID jidWithString:roomJID];

_xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomCoreDataStorage jid:jid dispatchQueue:dispatch_get_main_queue()];
[_xmppRoom activate:stream];
[_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_xmppRoom joinRoomUsingNickname:stream.myJID.bare history:nil];

Hope this will work for you too 希望这也适合你

By default a MUCRoom will send some history to newly joined user, the number is determined by config, under mod_muc: history_size: . 默认情况下,MUCRoom会向新加入的用户发送一些历史记录,该数字由config在mod_muc: history_size:下确定。 Or you need to explicitly request for some amount of history while sending the Presence, doc : 或者您需要在发送状态时明确请求一些历史记录, doc

<presence
    from='hag66@shakespeare.lit/pda'
    id='n13mt3l'
    to='coven@chat.shakespeare.lit/thirdwitch'>
  <x xmlns='http://jabber.org/protocol/muc'>
    <history maxstanzas='20'/>
  </x>
</presence>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM