didReceiveInvitation() is not being called in XMPPFramework and Swift 2
Asked Answered
B

2

1

I am creating chatting application like Whatsapp.
I have successfully write the functionality of Text chat, Image, Audio, Video Transfer. Now I am creating the Multi user chat. After a long R&D I am asking this question. Please tell me what I am doing wrong in my code. I have followed all these tutorials but not luck

https://github.com/robbiehanson/XMPPFramework/issues/640

MUC How-to with XMPPFramework

Accepting chatroom invitation

Ok Below is my Code

1. After setting the STREAM successfully i set the XMPPMUC delegate for Invitation in goOnline Method

private func goOnline() {
    let presence = XMPPPresence()
    let domain = xmppStream.myJID.domain

    if domain == "gmail.com" || domain == "gtalk.com" || domain == "talk.google.com"
        //        || domain == "chat.alqatech.com"
    {
        let priority = DDXMLElement.elementWithName("priority", stringValue: "24") as! DDXMLElement
        presence.addChild(priority)
    }
    xmppMUC = XMPPMUC(dispatchQueue: dispatch_get_main_queue())
    xmppMUC!.activate(self.xmppStream)
    xmppMUC!.addDelegate(self, delegateQueue: dispatch_get_main_queue())

    xmppStream.sendElement(presence)
}

2. Create a group

func createGroupChat(members:[String],groupName:String){
        membersToInvite = members
        xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
        let xmppJid = XMPPJID.jidWithString("\(groupName)@conference.chat.xxxxxx.com")
        let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: xmppJid)
        xmppRoom.activate(xmppStream)
        xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
        xmppRoom.joinRoomUsingNickname(xmppStream.myJID.user, history: nil)
    }

3. Group Created Successfully

func xmppRoomDidCreate(sender: XMPPRoom!) {
        print(sender)
    }

4. xmppRoomDidJoin called successfully then here i invite users

func xmppRoomDidJoin(sender: XMPPRoom!) {
        sender.fetchConfigurationForm()
        for JID in membersToInvite! {
            sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
            sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")

        }

    }

5. didFetchConfigurationForm called successfully

func xmppRoom(sender: XMPPRoom!, didFetchConfigurationForm configForm: DDXMLElement!) 
{

        let newConfig: DDXMLElement = configForm.copy() as! DDXMLElement
        let fields: [AnyObject] = newConfig.elementsForName("field")
        for field in fields {
            let vars: String = field.attributeStringValueForName("var")
            // Make Room Persistent
            if (vars == "muc#roomconfig_persistentroom") {
                field.removeChildAtIndex(0)
                field.addChild(DDXMLElement(name: "value", stringValue : "1"))
            }
        }
        sender.configureRoomUsingOptions(newConfig)


    }

6. didReceiveInvitation it is not being called.

func xmppMUC(sender: XMPPMUC!, roomJID: XMPPJID!, didReceiveInvitation message: XMPPMessage!) {
        print(roomJID)
        xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
        let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: roomJID)
        xmppRoom.activate(xmppStream)
        xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
        xmppRoom.joinRoomUsingNickname(xmppStream.myJID.user, history: nil)

    }
Broom answered 11/8, 2016 at 11:23 Comment(0)
B
-2

Problem was in this code. Actually i was sending the bare id every time when i was inviting any user.

func xmppRoomDidJoin(sender: XMPPRoom!) {
        sender.fetchConfigurationForm()
        for JID in membersToInvite! {
            sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
            sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")

        }

    }

BUT TO INVITE ANY USER YOU HAVE TO USE FULL ID.

For those who dont know

BareID = username@domain FullID = username@domain/resource

To resolve this

I hardcode the resource = APPNAME everywhere in JIDs in whole app.

Broom answered 15/8, 2016 at 11:30 Comment(4)
I have the same problem, can you please tell me where to code?Peppergrass
please read my answer again and check your code specialy how you are managing the resource thingBroom
I am stuck in saving the group in xmppUserCoreDateStoregeObject, what did you do to save the group in the OpenChatViewController. Here is my question : #41038676Peppergrass
@UsamaSadiq, bro can you help me to find out this problem #44173352 ?Sol
L
0

If you set a breakpoint in file XMPPMUC.m line 317

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

Is that method being called when an invitation is sent to your user? If so keep debugging and check if line 382 is being executed.

That line has this:

[multicastDelegate xmppMUC:self roomJID:roomJID didReceiveInvitation:message];
Leadership answered 11/8, 2016 at 16:40 Comment(2)
Thanks you @Leadership I resolved my problem and i have posted the my answer . actually i was using BareID instead of FullIDBroom
Line 317 is executed but not 382, invite and direct invite both found nil for my caseSill
B
-2

Problem was in this code. Actually i was sending the bare id every time when i was inviting any user.

func xmppRoomDidJoin(sender: XMPPRoom!) {
        sender.fetchConfigurationForm()
        for JID in membersToInvite! {
            sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
            sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")

        }

    }

BUT TO INVITE ANY USER YOU HAVE TO USE FULL ID.

For those who dont know

BareID = username@domain FullID = username@domain/resource

To resolve this

I hardcode the resource = APPNAME everywhere in JIDs in whole app.

Broom answered 15/8, 2016 at 11:30 Comment(4)
I have the same problem, can you please tell me where to code?Peppergrass
please read my answer again and check your code specialy how you are managing the resource thingBroom
I am stuck in saving the group in xmppUserCoreDateStoregeObject, what did you do to save the group in the OpenChatViewController. Here is my question : #41038676Peppergrass
@UsamaSadiq, bro can you help me to find out this problem #44173352 ?Sol

© 2022 - 2024 — McMap. All rights reserved.