XMPPFramework icon indicating copy to clipboard operation
XMPPFramework copied to clipboard

Join to room, freeze app

Open CeccoCQ opened this issue 12 years ago • 16 comments

I'm trying to develop a method called -(void) autoJoin:(NSArray*) rooms

where into rooms array there are a list of active rooms related to the user.

If I execute a lot of join into users rooms, my application freezes for a while, then when the join is complete, the app works correctly. My purpose is to execute this autojoin method when user was authenticated at my xmpp server (currently is openfire).

Is there a way to execute this method within the global_queue and not in the main_queue?

CeccoCQ avatar Jun 09 '13 12:06 CeccoCQ

Anyone can help me?

CeccoCQ avatar Jun 20 '13 08:06 CeccoCQ

I haven't used the MUC code so I am probably not the best person to comment, but what does the code inside autoJoin: look like?

ObjColumnist avatar Jun 20 '13 08:06 ObjColumnist

It's a simply "for" :

for(NSString *roomRealJid in myRoomsJidArray) 
{ 
    XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomRealJid];
    [newXmppRoom fetchConfigurationForm];
    [newXmppRoom activate: xmppStream];
    [newXmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [newXmppRoom joinRoomUsingNickname:xmppStream.myJID.user history:nil];
}

This operation freezes my app, so I can't join automatically to all my room at login.

CeccoCQ avatar Jun 20 '13 08:06 CeccoCQ

All of the code looks like it should run on a background queue asynchronously, have you tried passing in the default high priority queue into the initWithRoomStorage method? You should call activate first (before calling fetchConfigurationForm).

You probably need to work out with one of those method calls is taken up the most time (e.g. put log statements, use instruments etc).

ObjColumnist avatar Jun 20 '13 09:06 ObjColumnist

Do you mean something like this snippet?

XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomRealJid dispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
[newXmppRoom activate: xmppStream];   
[newXmppRoom fetchConfigurationForm];
[newXmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[newXmppRoom joinRoomUsingNickname:xmppStream.myJID.user history:nil];

I didn't understan because I've to insert activate method before fetchConfigurationForm.

CeccoCQ avatar Jun 20 '13 10:06 CeccoCQ

Yeah, I meant like that :smile:

ObjColumnist avatar Jun 20 '13 10:06 ObjColumnist

I've tried, nothing. My ViewController still freezes!

This is my code:

- (void) autoJoin {
for(NSString *roomRealJid in myRoomsJidArray) 
        [self joinRoom:roomRealJid];
    }
}

- (XMPPRoom*) joinRoom:(NSString*) roomJid {

    if(!isXmppAuthenticated) {
        return nil;
    }

    XMPPJID *roomRealJid = [XMPPJID jidWithString:roomJid];
    XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomRealJid dispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
    [newXmppRoom activate: xmppStream];
    [newXmppRoom fetchConfigurationForm];
    [newXmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [newXmppRoom joinRoomUsingNickname:xmppStream.myJID.user history:nil];
    return newXmppRoom;
}

CeccoCQ avatar Jun 20 '13 10:06 CeccoCQ

Your code looks fine to me, I think you will need to profile the code and work out what method is actually locking the app up.

How many rooms are you trying to add?

ObjColumnist avatar Jun 20 '13 10:06 ObjColumnist

Hi,

I've 5 rooms. How can use instrument to find the statement where the app frezees?

CeccoCQ avatar Jun 25 '13 15:06 CeccoCQ

You can use the time profiler to measure how long each method takes.

I expect logging the date between each method call might be sufficient though.

ObjColumnist avatar Jun 25 '13 16:06 ObjColumnist

Did you manage to solve this?

ObjColumnist avatar Oct 12 '13 16:10 ObjColumnist

Did you get any solution for this ? Please share if you have some valuable solution. Thanks

HBIOSDev avatar Feb 20 '15 11:02 HBIOSDev

Hi All, I am facing same hanging issues, I have 100+ room to join, It is taking 25+ seconds to join all room. Can any one help in this?

Thanks.

Amitmundra avatar Aug 05 '16 09:08 Amitmundra

Hi ObjColumnist/CeccoCQ, I am facing same hanging issues, I have 100+ room to join, It is taking 25+ seconds to join all room. Can any one help in this?

I did same, and it work fast but, is there possibility if too many threads are joining in background and same time other one doing database operation then is there any possibility of crashing because i am facing issue in iOS10?

Thanks.

Amitmundra avatar Oct 14 '16 12:10 Amitmundra

Hi All I am facing same freeze issues,Can anyone solve this problem?

Thanks.

sandsame avatar Jul 24 '17 06:07 sandsame

can anyone tell me how to join a room I am not able to join a room I write this method when user get Authenticated, but interestingly delegates method of room not called

func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
        print("auth done")
    xmppMUC.activate(stream)
        xmppMUC?.addDelegate(self, delegateQueue: DispatchQueue.main)

        let roomJID = XMPPJID(string: "[email protected]")

        let roomStorage = XMPPRoomCoreDataStorage.sharedInstance()

        xmppRoom = XMPPRoom(roomStorage: roomStorage, jid: roomJID, dispatchQueue: DispatchQueue.main)!

        xmppRoom.activate(stream)

        xmppRoom.addDelegate(self, delegateQueue: DispatchQueue.main)

        xmppRoom.join(usingNickname: stream?.myJID.user, history: nil)

        print("xmppRoom.isJoined",xmppRoom.isJoined)
 }

Please help me and tell me where to add this snippets is it better to add after user get authenticated.

madBureaToT avatar Aug 24 '17 05:08 madBureaToT