开发者

JsJAC Subscription Request with Nickname

I am developing an internal chat system using OpenFire and JsJAC. I wanted everyone logged in to automatically be friends with one another, but since there is no good way to automatically make everyone friends I decided to use the subscription plugin and send along a subscription request to anyone not on your roster. The subscription plugin automatically accepts the request.

This is working now, however I'm unable to set the nickname for the new roster entry.

Here is the code I'm using:

    //Send friend request
    var subscribe_packet = "<presence to='"+this.sender+"@"+chatManager.args()['domain']+"' from='"+chatManager.args()['username']+"@"+chatManager.args()['domain']+"' type='subscribe'>";
    subscribe_packet += "<nick xmlns='http://jabber.org/protocol/nick'>TestTest</nick>";
    subscribe_packet += "</presence>";

    console.log("Subscribe packet: "+subscribe_packet);
    con._sendRaw(subscribe_packet);

This gives the following XML output as an example:

<presence to='targetuser@domain.com' from='sourceuser@domain.com'><nick xmlns='http://jabber.org/protocol/nick'>TestTest</nick>开发者_StackOverflow中文版</presence>

This sends the subscription request, but the nickname is either not sent or not properly interpreted by OpenFire.

Any thoughts?


This took me forever to find! I was using xmpphp, but got the solution from using jquery Strophe.

First do:

<iq type='set' xmlns='jabber:client' id='9155:sendIQ'>
        <query xmlns='jabber:iq:roster'>
                <item jid='user@localhost' name='usernickname'/>
        </query>
</iq>

Followed by:

<presence to='user@localhost' type='subscribe' xmlns='jabber:client'/>

Then to rename again:

<iq type='set' xmlns='jabber:client' id='9155:sendIQ'><query xmlns='jabber:iq:roster'><item jid='kafkav2@localhost' name='kafkav2RENAME'/></query></iq>

Hope this helps, because I was using the same XML you were using above and that did not work.


Jason, XEP 0172 doesn't involve any actions taken by the server. You need to make your client deal with the nickname. To do so check for a given nickname when receiving a subscription request and then use this nickname when adding the newly subscribed user to your roster.

Btw: It is not a good idea to use _sendRaw (it's a private method, thus the _). A more cleanly solution would be to extend the JSJaCPresence prototype with methods getNickname and setNickname.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜