{"id":1910,"date":"2022-08-30T15:20:28","date_gmt":"2022-08-30T15:20:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/02\/multiplechatuser-xmpp-asmack-join-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:20:28","modified_gmt":"2022-08-30T15:20:28","slug":"multiplechatuser-xmpp-asmack-join-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/multiplechatuser-xmpp-asmack-join-collection-of-common-programming-errors\/","title":{"rendered":"MultipleChatUser XMPP asmack join-Collection of common programming errors"},"content":{"rendered":"<p>I am new to this OpenFire and asmack, i want the user to have a functionality of Multi Users Chatting so i searched around and i found MUC i have implemented this for creating a room and sending invitation to other users these works, other user receives the invitation but the other user is not able to join the room.<\/p>\n<p>I am doing this on other user invitation receiving<\/p>\n<p>Here connection is the connection of this user and room is the room name that we getting in invitation.<\/p>\n<p><strong>MultiUserChat muc3 = new MultiUserChat(connection,room);<\/strong><\/p>\n<p><strong>muc3.join(&#8220;testbot3&#8221;);<\/strong><\/p>\n<p>testbot3 is just some random name.<\/p>\n<p><strong>But this throws 404 error.<\/strong><\/p>\n<p>Do i need to join the user before sending the invitation i.e if A user sending invitation to B , before invitation sent do A needs to join these users by default to room and then it depends on B to decline or just keep quite.<\/p>\n<p>What i am doing is B receives invitation from A in that InvitationListner of B i am trying to join with the above code.<\/p>\n<p>I have been trying for long now i am not sure what is going wrong, some one can give a sample code of how to do this it would be great help for me.<\/p>\n<p>Thanks<\/p>\n<p>Here is more information on my issue<\/p>\n<p>As i go and check on Openfire i can see the room created by the user and he has been added himself as an owner so i dont think so it would be an issue with room getting created.<\/p>\n<p><em><strong>May be this can be an issue with room getting locked, as i have read through the room is locked when the room is not completely created , i guess this is an issue with form filling when we create the room, i am not filling in the password in the form can this be an issue ?<\/strong><\/em><\/p>\n<p><strong>Please see the following code below inside the handler i am calling a method &#8220;checkInvitation&#8221; which does the same as above code posted still i get 404. Can you please tell me what i wrong in my code.<\/strong><\/p>\n<p>Do the nickname that needs to be added can be anything or it needs to something user specific ?<\/p>\n<p>public void createChatroom(){<\/p>\n<pre><code>    MultiUserChat muc = null;\n\n    try {\n      muc = new MultiUserChat(connection, \"myroom@conference.localhost\");\n      muc.create(\"testbot\");\n\n      \/\/ Get the the room's configuration form\n      Form form = muc.getConfigurationForm();\n      \/\/ Create a new form to submit based on the original form\n      Form submitForm = form.createAnswerForm();\n      \/\/ Add default answers to the form to submit\n      for (Iterator fields = form.getFields(); fields.hasNext();) {\n          FormField field = (FormField) fields.next();\n          if (!FormField.TYPE_HIDDEN.equals(field.getType()) &amp;&amp; field.getVariable() != null) {\n              \/\/ Sets the default value as the answer\n              submitForm.setDefaultAnswer(field.getVariable());\n          }\n      }\n      \/\/ Sets the new owner of the room\n      List owners = new ArrayList();\n      owners.add(\"admin@localhost\");\n      submitForm.setAnswer(\"muc#roomconfig_roomowners\", owners);\n      \/\/ Send the completed form (with default values) to the server to configure the room\n      muc.sendConfigurationForm(submitForm);\n      muc.join(\"d\");\n\n      muc.invite(\"b@localhost\", \"Meet me in this excellent room\");\n\n      muc.addInvitationRejectionListener(new InvitationRejectionListener() {\n          public void invitationDeclined(String invitee, String reason) {\n              \/\/ Do whatever you need here...\n              System.out.println(\"Initee \"+invitee+\" reason\"+reason);\n          }\n      });\n\n    } catch (XMPPException e) {\n        \/\/ TODO Auto-generated catch block\n        e.printStackTrace();\n    }\n}\n\n    public void setConnection(XMPPConnection connection) {\n    this.connection = connection;\n    if (connection != null) {\n        \/\/ Add a packet listener to get messages sent to us\n        PacketFilter filter = new MessageTypeFilter(Message.Type.chat);\n        connection.addPacketListener(new PacketListener() {\n            public void processPacket(Packet packet) {\n                Message message = (Message) packet;\n                if (message.getBody() != null) {\n                    String fromName = StringUtils.parseBareAddress(message\n                            .getFrom());\n                    Log.i(\"XMPPClient\", \"Got text [\" + message.getBody()\n                            + \"] from [\" + fromName + \"]\");\n                    messages.add(fromName + \":\");\n                    messages.add(message.getBody());\n                    \/\/ Add the incoming message to the list view\n                    mHandler.post(new Runnable() {\n                        public void run() {\n                            setListAdapter();\n                            checkInvitation();\n                        }\n                    });\n                }\n            }\n        }, filter);\n\n\n        mHandler.post(new Runnable() {\n            public void run() {\n                checkInvitation();\n            }\n        });\n    }\n}\n<\/code><\/pre>\n<ol>\n<li>\n<p>The 404 error indicates that:<\/p>\n<pre><code>404 error can occur if the room does not exist or is locked\n<\/code><\/pre>\n<p>So, ensure that your room is not locked or existed! The code below is how I join the room when there&#8217;s an in-comming invitation:<\/p>\n<pre><code>private void setChatRoomInvitationListener() {\n    MultiUserChat.addInvitationListener(mXmppConnection,\n            new InvitationListener() {\n\n                @Override\n                public void invitationReceived(Connection connection,\n                        String room, String inviter, String reason,\n                        String unKnown, Message message) {\n\n                    \/\/MultiUserChat.decline(mXmppConnection, room, inviter,\n                        \/\/  \"Don't bother me right now\");\n                    \/\/ MultiUserChat.decline(mXmppConnection, room, inviter,\n                    \/\/ \"Don't bother me right now\");\n                    try {\n                       muc.join(\"test-nick-name\");\n                       Log.e(\"abc\",\"join room successfully\");\n                       muc.sendMessage(\"I joined this room!! Bravo!!\");\n                    } catch (XMPPException e) {\n                       e.printStackTrace();\n                       Log.e(\"abc\",\"join room failed!\");\n                    }\n                }\n            });\n}\n<\/code><\/pre>\n<p>Hope this helps your error!<\/p>\n<p><b>Edit:<\/b>this is how I config the room:<\/p>\n<pre><code> \/*\n         * Create room\n         *\/\n        muc.create(roomName);\n\n        \/\/ muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));\n        Form form = muc.getConfigurationForm();\n        Form submitForm = form.createAnswerForm();\n\n        for (Iterator fields = form.getFields(); fields.hasNext();) {\n            FormField field = (FormField) fields.next();\n            if (!FormField.TYPE_HIDDEN.equals(field.getType())\n                    &amp;&amp; field.getVariable() != null) {\n                show(\"field: \" + field.getVariable());\n                \/\/ Sets the default value as the answer\n                submitForm.setDefaultAnswer(field.getVariable());\n            }\n        }\n\n        List owners = new ArrayList();\n        owners.add(DataConfig.USERNAME + \"@\" + DataConfig.SERVICE);\n        submitForm.setAnswer(\"muc#roomconfig_roomowners\", owners);\n        submitForm.setAnswer(\"muc#roomconfig_roomname\", roomName);\n        submitForm.setAnswer(\"muc#roomconfig_persistentroom\", true);\n\n        muc.sendConfigurationForm(submitForm);\n        \/\/ submitForm.\n        show(\"created room!\");\n        muc.addMessageListener(new PacketListener() {\n            @Override\n            public void processPacket(Packet packet) {\n                show(packet.toXML());\n                Message mess = (Message) packet;\n                showMessageToUI(mess.getFrom() + \": \" + mess.getBody());\n            }\n        });\n<\/code><\/pre>\n<p>With this cofiguration, I can join a room easily without password.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-12-02 21:17:29. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am new to this OpenFire and asmack, i want the user to have a functionality of Multi Users Chatting so i searched around and i found MUC i have implemented this for creating a room and sending invitation to other users these works, other user receives the invitation but the other user is not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1910","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1910"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1910\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}