Try to rejoin a client to a specific room after reconnect - xmpp

I successfully created a muc service and create a room.
After i create the room "testroom#conference.xmpp.messenger.local" i enter the room with my client "client#xmpp.messenger.local".
(My client is also the owner of the muc room)
in this case it works and i am able to send any messages to the muc room.
My problem came up if i reload the page and reconnect to my ejabberd server.
After reconnect i read all rooms of a client and try to join the room with the following presence stanza (described in XEP-0045 // 16.7.1):
<presence to='testroom#conference.xmpp.messenger.local'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
Now i get the error code 409 which contains the following error message:
"That nickname is registered by another person"
i can't understand why it says i registered this nickname by another person -> it is the same person
btw i also tried to re-enter with:
<presence
from='client#xmpp.messenger.local'
id='n13mt3l'
to='testroom#conference.xmpp.messenger.local'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
At least i tried to enter the room with different nicknames, but this causes an instant disconnect without any error message.
I hope anyone else can figure out the problem and could help me to find a solution.

I solved my problem.
I had to choose an resource while connecting any client to the ejabberd server.
I thought this is not required, but now it works.

Related

How to allow Ejabberd external XMPP component to send presence packets on behalf of a user

I wrote an external component for Ejabberd, but when trying to send presence stanzas on behalf of a user i get a 400 error.
The component's name is bot.domain.com and the host name in Ejabberd is domain.com and I have set the "check_from" flag to false for my component.
Below is an example of a presence stanza I am trying to send from the component on behalf of a user:
<presence from="user#domain.com">
<status>Test status</status>
<show>dnd</show>
</presence>
And this is the error message that is returned by Ejabberd:
<presence type="error" to="user#domain.com">
<status>Test status</status>
<show>dnd</show>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</presence>
If I add to="user2#domain.com" in the package I'm sending, the destination user actually receives the package.
If I add to="domain.com", I don't get the 400 error anymore, but the presence is not broadcast to anyone in the user's roster.
The actual problem seems to be that Ejabberd is not broadcasting the presence packet to everyone in the user's roster.
Any ideas what I might be missing or why I get the 400 error when not specifying the "to" field?
You cannot broadcast roster presence on behalf of a user from a component. Component service does not load the user roster. Only the ejabberd_c2s is taking care of loading roster to broadcast presence. It also takes care of checking privacy list and many important features of XMPP.
As a side note, I do not know what you expect to do with that approach, but you can split presence from user session in XMPP. A user is online first because he has a session open on XMPP and only secondarily because he sent a presence. By faking presence sending from component for a users, you are not guaranteed that that user will have a session opened. In that case, the overall behaviour will certainly not the one you expect.

strophe js MUC room

I have created room from desktop client. And want to send message and receive messages on this room using strophejs. I have already set muc plugin, but I don't see any documentation of it.
1) how to subscribe on messages in room
2) how to send messages to room
First, read http://xmpp.org/extensions/xep-0045.html if you haven't already.
By joining a room, you should get the messages, when sending messages, you send the message to the room jid instead of an individual.
To join a room (after attaching/connecting to jabber server):
connection.muc.join(room, nick, msg_handler_cb, pres_handler_cb,
roster_cb, password, history_attrs);
room is the jid of the room and nick is your nickname.
You will need to write callback functions for handling the messages, rosters and presences (msg_handler_cb, pres_handler_cb,roster_cb). Password can be null if one is not required. Your history attributes define things line maxstanzas, which define how far back to get messages when loading.

XMPP receive history without rejoining the MUC

Suppose A has already joined into the MUC. At the time of join A will receive complete history. But after that is there any way for A to receive the complete history any number of times by doing some query to MUC.
Leaving and Rejoining the MUC is not acceptable. :(
I have seen How to re-request room roster and history from a muc in ejabberd
But the last comment with is not working for me.
Please help me, if this is even possible or not. If yes can you give me the stanza that needs to be sent to muc. BTW I am using smack API and openfire
Thanks,
Nitiraj

How can I find the real user JID of user in MUC?

When I join in a room XMPP xmpp, usually the other user see my JID as myconference#conference.localhost/myname instead of myname#localhost.
Pidgin is able to recover also my real JID when I talk with some of my friends (myname#localhost).
How is it possible? What kind of request should I make to the server?
This is important for me, because when I start talking with someone, I don't want to open two tabs, only because my client believes that my friend that I can see both in my roster and in the group roster, isn't the same guy.
See XEP-0045, section 7.2.4. In a non-anonymous room, the server will send all participants' jids in their presence stanzas:
<presence
from='coven#chat.shakespeare.lit/thirdwitch'
id='17232D15-134F-43C8-9A29-61C20A64B236'
to='crone1#shakespeare.lit/desktop'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='none'
jid='hag66#shakespeare.lit/pda'
role='participant'/>
</x>
</presence>

Problem creating a chat room with XMPP in an iOS app

I have an iphone app where I want to use chat rooms. I've installed an XMPP server (ejabberd) and downloaded the XMPP framework for iOS from google code (http://code.google.com/p/xmppframework/). The server and client work as expected, since I'm able to log in and send chat messages between two users.
However, when I try to create a chat room using the createOrJoinRoom method of the XMPPRoom class (in XEP-0045), I don't get any reply from the server and the chat room is not created.
I've debugged to see what kind of package is sent to the server and it looks like this:
<presence from="test2#beta.bogus.net/mynick" to="muumit15#conference.beta.bogus.net">
<x xmlns="http://jabber.org/protocol/muc"/>
</presence>
I get no error message back but the chat room (muumit15) is not created. At the same time I can use e.g. Adium client to create a chat room and it succeeds. The server has been configured so that every user has a right to create chat rooms.
Any ideas? I even tried sniffing the TCP/IP traffic sent by the Adium client but that was encrypted/compressed/binary so I couldn't see what kind of packages it is sending.
See section 7.2.2 of XEP-0045, particularly Example 18:
<presence
from='hag66#shakespeare.lit/pda'
to='coven#chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
Note that the to address MUST contain a resource, and yours doesn't. The resource is the string after the /, which is used as your nickname in the room. For more information on the XMPP address format, see RFC 6122.