I'm writing an app which communicates with clients via XMPP. I want to be able to use the users existing xmpp account (they all have google ID's) but I don't want my messages to appear in their regular IM stream.
I'm thinking that when my client pairs with the server it could use a custom resource id eg Fred.Bloggs#gmail.com/MYCUSTOMID then I can always send messages to that ID with the resource tag.
Is this the best approach, are Resource ID's tied to a specific install of a client or should they change on a per session basis?
Google will modify any resource you give it by adding a random identifier to the end.
If you're writing both the sender and the receiver, try using an XMPP extension:
<message to="fred.bloggs#gmail.com">
<x xmlns='http://my.domain.example.com/my_extension'>stuff</x>
</message>
If you need to be able to tell which of the resources is your client, try XEP-0115.
Related
I am developing Android Chat Application.
My requirement is to deliver messages to multiple devices.
Consider this scenario between two users User A and User B:
User A logs in and sends message to User B.
User B logs in from Device 1 and receives message from User A.
User B logs in from Device 2 but does not get message from User A.
According to my requirement User B should get message from User A in Device 2 as well.
How can I achieve this?
Thanks.
In XMPP, the message are only delivered in a single go either:
to the online resources sharing the highest priority,
to the first client that connect through offline message delivery.
However, if you want other clients to resync, you should rely on XEP-0313: Message Archive Management. This specifications describe how a client can access a message history and resync its state.
You can for example query the message archive for all messages after a given time. This will allow the client that connect to get all the messages it missed since it was last online:
<iq type='set' id='juliet1'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data'>
<field var='FORM_TYPE'>
<value>urn:xmpp:mam:0</value>
</field>
<field var='start'>
<value>2010-08-07T00:00:00Z</value>
</field>
</x>
</query>
</iq>
In addition to Mickael's answer, you should be aware of a few things. If you specify a full JID as your to address, then the message will only be delivered to that single endpoint.
Message deliver to multiple resources for the same user will only occur if
The to address is the bare JID
All connections have the same priority
The server is configured to deliver to multiple endpoints.
That last point is crucial. According to the specification, the server can handle messages sent to the bare JID in 2 ways.
Send to one of the connections with the highest priority. Which one is determined by the server, it could be the first one connected, the last one, or a random choice if there are multiple connections with the same priority.
Send to all of the connections with the highest priority.
So, unless you know your server supports and is configured to allow the second choice, you can't accomplish what you are trying to do anyway.
In order to participate in the instant messaging and presence activities, a client (i.e device) should establish a session on the server.
As given in XMPP Documentation
If there is already an active resource of the same name, the server
MUST either (1) terminate the active resource and allow the
newly-requested session, or (2) disallow the newly-requested session
and maintain the active resource. Which of these the server does is up
to the implementation, although it is RECOMMENDED to implement case #1. In case #1, the server SHOULD send a stream error to the active resource, terminate the XML stream and underlying TCP
connection for the active resource, and return a IQ stanza of type
"result" (indicating success) to the newly-requested session. In case #2, the server SHOULD send a stanza error to the newly-requested session but maintain the XML stream for that
connection so that the newly-requested session has an opportunity to
negotiate a non-conflicting resource identifier before sending another
request for session establishment.
(https://www.rfc-editor.org/rfc/rfc6120#section-7.7.2.2)
Therefore you should first decide the way you are going to handle the sessions, according to the app requirement.
Now since you are using Ejabberd you can configure it by defining the option resource_conflict
However, if you still want to use multiple sessions you can use Message Archive Management - XEP-0313
So you can store chat history on the server and then retrieve. This can be configured in ejabberd by using the option mod_mam
In our SaaS application each company (tenant) is given their custom domain like companyName.ourapp.com
We would like to provide some email services like:
Ability to send and receive email notifications from info#companyName.ourapp.com and similar addresses
Ability to create new email accounts in clients' subdamains at runtime, programmatically, when needed. For example we would have separate emails created for each "opening" so that emails sent to this address would be parsed info would be extracted
Similar tasks
For now I just don't even know on where to look and how this could possibly work.
As far as I understand email it should be some kind of custom mail server (SMTP) serving all sub-domains and having API we can use to send emails, list and retrieve messages etc.
Please suggest how it may work and is there any components out there we can use to implement this.
There are three options for this.
Create an email server and programatically configure it to accept or deny the specific accounts. Then use cron to poll via pop3 or imap and download the messages for the account. You can then send them on for the customer or handle them in your web app.
Create a script that is fired by the email server as it receives each email. The script can then handle what to do with the email as it's received.
Use a third party to receive the email via HTTP Post at your app. Using CloudMailin for example would allow you to create a custom authorization filter that would call your app in realtime and determine if the given account exists and messages should be accepted for it.
I wrote a blog post for Rails about receiving incoming email, however the principals would apply to any programming language and framework.
In my current project I want to communicate with people in a XMPP Multi User Chat. But also I need to send data to all participants in the conference, but this data should not be seen as a message.
Is it possible to send data (strings) to all participants in a MuC channel by not using a normal chat message?
I'm using Smack API, and I assume, that all participants use my program.
Thanks in advance!
The solution is to use a normal message (with type="groupchat"), but do not include a <body>.
I do not know how this is done in Smack, or if it is possible (I hope it is). An example message would be:
<message to="room#conference.server" type="groupchat">
<yourdata xmlns="your-xmlns">
<anything-you-want-here/>
</yourdata>
</message>
XMPP clients will ignore this message, as it has no <body> tag.
XMPP allows users to connect to the server from multiple clients simultaneously, using the same account. I built an application that does this but if the desktop client is enabled, I do not want the users to be able to connect using a mobile client. This is for a game and being connected to both causes problems.
So what I'm wondering is:
Is it possible to detect if there are other clients connected using the same account. If I can check for other clients, I can auto logout the user.
#Flow was on the right track. If all of your client instances use the same resource, in most servers, the later-connecting client will replace the older session. The older session will get a conflict stream error, and be disconnected. You MUST be careful not to auto-reconnect with the older client, or you will have written the "dueling resources" bug.
If you had control over your server, you have a chance at configuring it to allow a maximum of one resource for a given user, in which case the newer connection will fail with a conflict error, but you'll have worse user interface problems if you head down that path; there will be no way to get the second client logged in, even if you wanted to.
Finally, all resources for a given user are subscribed to that user's presence. As long as your client sends presence in:
<presence/>
you will receive presence from each of your other devices:
<presence to='user#example.com/resource1' from='user#example.com/resource2'/>
<presence to='user#example.com/resource1' from='user#example.com/resource3'/>
<presence to='user#example.com/resource1' from='user#example.com/resource4'/>
You could use this to decide which client is current, perhaps by adding an extension to the presence like XEP-0115.
Give the desktop and mobile client a fixed but different resource string. If the mobile client logs in, it can detect the presence of the desktop client by looking up the presence/availability of the resource of the desktop client and vice versa.
Then you only need to implement an custom XMPP ad-hoc command (XEP-0050) that tells the conflicting resource to log out.
It would be the servers responsibility: to reject a login from a client that is not accepted. I don't know if servers are able to blacklist xmpp clients but, in case you use openfire, you should be able to write an extension.
I am developing a XMPP application and will be doing a global shared roster so that I don't have to do presence subscription requests. I also need to get the presence of a certain range of JabberIDs and not the entire global roster. We do not want to do single directed presence stanzas, since that would require up to 15 presence calls each page load. Is there a method within XMPP for me to get presence of multiple, but specific JIDs at once?
Something like:
<presence from="user1#domain.tld,user2#domain.tld,user3#domain.tld" to="user4#domain.tld" />
Thanks in advance!
You could create a pubsub node where each item is about a user. The id would be the users bare JID, and the contents could be a dataform stating whether they are online or not.
A bot or xmpp module listens out for presence messages and then updates the pubsub node appropriately.
The clients can then query the pubsub node using whatever method they like: subscribe and get live updates, or query and use requests