Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMPP multiple sessions of the same user issue

I've implemented a chrome extension which allow to use XMPP chat over BOSH connection with punjab server running on a remote server. It is implemented using javascript Strophe library. The issue I'm running into is when I have multiple sessions of the same user (e.g. two different browsers on the same machine) I can't receive and log to the second chat window the message I sent from first chat window. There needs to be some mechanism which allows that. Can I somehow receive messages I have sent to some other user? The issue can also be reproduced on 2 or more different machines so this needs to be solved too.

Thank you.

like image 607
vian Avatar asked Feb 27 '12 05:02

vian


2 Answers

If you want to have the entire conversation, including messages you send from your client(s) to show up on another session, then Carbons is the feature you're looking for. I've implemented this in a plugin for Prosody.

The required client part shouldn't be too hard to write, here's it done in the Verse library.

like image 196
Zash Avatar answered Nov 09 '22 23:11

Zash


You need to understand how JIDs work, what priorities are and how to send messages.

A JID is of the form: user@domain/resource

The JIDs of logged in users have to be unique. Typically when you use a web client you assign a random resource to each session so as to not have clashes.

Now, when a user sends a message the to attribute of the <message> stanza specifies the recipient of the message. If the resource is part of the recipient then only that JID will receive the message. If the recipient is a bare JID (user@domain) then priorities come into play (see here):

  1. The resource with the highest priority at any given time will be the one which receives incoming messages.
  2. If two or more resources have the same priority, all resources with said priority may receive incoming messages or depending on the server implementation one may receive depending to server-specific criteria.
  3. If all connected resources have a negative priority, incoming messages will be queued server-side until one of the resources resets priority to be positive.

You can set the priority (an integer in [-128, 127])when you send your presence (see the rfc for full spec) for example:

<presence>
  <status>Learning XMPP</status>
  <priority>1</priority>
</presence>
like image 27
ggozad Avatar answered Nov 09 '22 21:11

ggozad