Reputation: 307
i am currently working on a 'Add Roster Contact" functionality.
1) I add a new Contact to my Roster with:
var iq = $iq({type: "set"}).c("query", {xmlns: "jabber:iq:roster"}).c("item" {jid:"[email protected]/test",name:"test"});
Chat.connection.sendIQ(iq);
The Contact is added successfully to my Roster.
2) Send presence stanza of type 'subscribe' to the new contact ('test'):
var subscribe = $pres({to: [email protected]/test, type: "subscribe"});
Chat.connection.send(subscribe);
That works, but not every time:
When the person i am adding to my roster ('test') has currently no active session (is not logged in), i get a subscription type of 'none' for the sender, and also a subscription type of 'none' for 'test'.
So:
Receiver 'Test': Subscription 'None'
Sender 'me': Subscription 'None'
When the person iam adding to my roster has an active session, the expected subscription-types 'to' and 'from' are successfully set.
Any idea ?
Upvotes: 3
Views: 2460
Reputation: 10414
Don't use a resource on the to address in the subscription request:
var subscribe = $pres({to: "[email protected]", type: "subscribe"});
Chat.connection.send(subscribe);
When the user comes online later, they should get notified of your request, and can reply with a <presence type="subscribed"/>
stanza. If you put a resource on the to address, odd routing rules may come into play that don't cause your request to be stored.
Upvotes: 5