Locke
Locke

Reputation: 39

How can I tell the difference between the JID of a user and a JID of MUC?

Suppose I have two JIDs:

JID 2 clearly refers to the chat server, but the chat server isn't always going to have the word chat or conference in it.

Is there a way, using the Smack libraries, to tell which one is which?

Upvotes: 1

Views: 578

Answers (2)

Joe Hildebrand
Joe Hildebrand

Reputation: 10414

You cannot tell by looking at the JID. You have to keep enough context in a given protocol exchange to know what you are talking to.

Typically on startup, a client will send a disco#items query to the server:

<iq type='get'
    to='shakespeare.lit'
    id='items1'>
  <query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>

to find all of the local services, then send a disco#info query to each of those services to find out more about the service. Once you find a MUC server:

<iq from='chat.shakespeare.lit'
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <identity
        category='conference'
        name='Shakespearean Chat Service'
        type='text'/>
    <feature var='http://jabber.org/protocol/muc'/>
  </query>
</iq>

you know that all of the JIDs that include this domain name (chat.shakespeare.lit in the above example) are associated with MUC rooms.

Upvotes: 2

Mark S
Mark S

Reputation: 869

A user JID in a MUC will (should) have the username at the end and will look like:

[email protected]/username

Upvotes: 0

Related Questions