Detecting other clients using the same account in XMPP - xmpp

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.

Related

Sharing Jabber chat session between multiple clients

I'm using Jitsi on client side and ejabberd on server.
It seems that the chat sessions are specific to clients, i.e. if I'm logged in to the same account from 2 different clients, there will be 2 separate sessions, and one can't see what's happening in another.
Is it possible to share the sessions for the same account on all clients? Like Skype or GTalk.
If yes, is it a server configuration or client?
Thank you.
I think what you're looking for is XEP-0280 Message Carbons. Basically the server takes care of relaying the chat to all of your online resources so that you have the same chat session across all devices.
You even get chatstates from all of your other resources so you can infer whether or not you should show an unread IM notification to the user on your resource or not. You'll need client and server support for this, and it looks like ejabberd has implemented it via this module.

XMPP double message receiver Ios

I'm writing an app that use xmpp to exchange messagge between users. If I have two devices logged with the same account,any xmpp message is received only by one device, maybe the one with the fast connection? Anyway how I can do to ensure that any message will be send to any device connected with the receiver account? I'm using ejabberd server and XMPPFramework for ios.
You can login simultaneously in two different devices provided you are using different resource names when logging in. You can check sessions and resources the user has used to sign in on the server

How does Google Talk replicate messages across devices?

I'm wondering how (official) GTalk clients manage to show all messages received - even if it was originally consumed by another client. For example: I'm logged into GTalk on gmail.com on my laptop and, at the same time, via the official GTalk app on my Android device. A friend sends me a message, which is displayed on both the gmail.com client and the Android client. (I think it's originally only forwarded to one of either clients, but the second client fetches the message later on)
I recently found out that there's a very similar XMPP feature, called Carbons. However, after a quick service discovery request Google's servers didn't advertise this feature. XEP-0313 and XEP-0136 look good too, but the servers don't advertise them either.
Possibly related question: Deliver Google Talk message to all logged in clients using XMPPPY
When you initiate a new chat then you should send the first message to the users bare Jid. This is what most clients are doing. When the GTalk server retrieves a chat message to a bare Jid it routes the message to all available resources. For all following messages in this conversation the clients normally pick up the Resource and send them to full Jids. The messages should not be replicated then.
Many other servers don't route message to bare Jids to all resources, but to the most available resource which is the client with the highest priority.
Here is a quote form the RFC:
If there is more than one resource with a non-negative presence priority then the
server MUST either
(a) deliver the message to the "most available" resource or
resources (according to the server's implementation-specific algorithm, e.g., treating
the resource or resources with the highest presence priority as "most available") or
(b) deliver the message to all of the non-negative resources.
XEP-0280 defines this. As I understand, it defines the mechanism to notify all the resources from same user when one of them sends a message to anyone. I mean, Alice/pda sends a message to Bob, so Alice/mobile and Alice/PC will receive a copy of the message sent be Alice/pda.
Hope it helps. I am currently looking for a server that implements this, and also for a client library. If not, I will implement it by myself in both jabberd2 and gloox xmpp library.
Cheers,

connect private XMPP account through gtalk

Recently started at a new small company that has the following infrastructure:
Private XMPP Openfire server that hosts #chat..com
Google Apps for email, chat, docs, etc. with account of #.com
The company uses the private/internal chat server heavily for communication. However that requires me to install and run a client on my machine like Adium/Psi and then chat history is stored locally etc.
Since getting the entire company to move away from their beloved internal chat server and use gtalk that comes built-in with google apps is not an option, the hope was to register the #chat..com account with gtalk and then handle all communication through gtalk similar to what folks have done with AIM, Facebook, and other transports. Benefit would be the following:
All chat history stored server side on gtalk side and serchable
Other people in the company do not need to change behavior
Android phone that is already sync'd with Google services will not be able to leverage the chats without the need to install another XMPP client.
No need to have a thick client installed on the desktop/laptop
I have researched the XMPP transports and tried to the registering but they do not seem to cover my situation. I have investigated two routes thus far with no luck:
Transport plugin for Openfire
Use public transport at http://jabberd.eu
Guidance and/or experience from someone who has accomplished this would be appreciated.
I've used Spectrum (v1 and v2) to connect Openfire to Gmail and Facebook. It shows up in the users' clients as a discoverable service. It requires that a remote roster plugin be added to Openfire and that Spectrum be run on the same box as Openfire.
In short, it acts similar to a web proxy. Your users don't have to change their account on your system but to Gtalk users, your users appear to be other Gtalk users. Any of your users who access Gtalk will be using their own Gtalk authentication so you don't need to maintain any extra authentication schemes.
Take a look at it at http://spectrum.im. The remote roster plugin for Openfire is attached to the bottom of the first message in http://community.igniterealtime.org/thread/46580 (it's filename is "gojara.jar").

XMPP Chat States with Pidgin

I am writing a chat support application that connects to an XMPP server using the SASL Anonymous mechanism. When a user opens my website in their browser, using Socket.IO and NodeJS the server will initiate the anonymous connection with my XMPP server.
This is all working fine. I can connect and communicate with the browser, and it is very cool.
The support team connects to the server using Pidgin. I'd like to be able to display to the browser when the support techs are typing in Pidgin. I set up chat state notifications to work with the browser using AJAX and such, however I am having issues with Pidgin/Adium. Everything seems to work perfectly when I connect from iChat. I get 'active' and 'composing' chat states when the tech is typing. For some reason, however, both Pidgin and Adium are not sending these chat states to the browser client. I've made sure that the proper setting is enabled, as the chat states are being sent between two Pidgin users.
I read something about sending a stanza to report which features a client supports, but the Pidgin client never attempts to request this from the browser.
What am I missing here?
EDIT: I guess I should add that the anonymous browser client is initiating the chat with the Pidgin user, which may be part of the problem here.
Does your client implement XEP-0115, and claim support for the http://jabber.org/protocol/chatstates feature, as specified in section 4 of XEP-0085?
Once you implement that, you'll merely need to deal with libpurple's bugginess.