Java - trying to prebind converse.js using bosh but not able to get the sid and rid…using the smack bosh

后端 未结 2 735
忘了有多久
忘了有多久 2020-12-21 18:16

I am trying to connect to the open fire using the smack bosh and trying to prebind the converse.js in the web page. My bosh code

BOSHConfiguration config =          


        
相关标签:
2条回答
  • 2020-12-21 18:39

    I managed to do this by adding the following functions in the Smack BOSHConnection library class:

    public class BOSHConnection extends Connection {
        ...
        public String getSid() {
            return client.getSid();
        }
    
        public Long getRid() {
            return client.getRid();
        }
        ...
    }
    

    you then need to remember that the Rid is the last id used by the Smack library and for your pre-bind you need to increment this for next request.

    Jid is already available via BOSHConnection.getUser();

    I should also flag that to get converse pre-bind working with Smack I also had to change the BOSHConnection.login functon.

    // Changed: preserve current api - call new pre-bind aware function
    public void login(String username, String password, String resource)
            throws XMPPException {
        login(username, password, resource, false);         
    
    }
    
    // Added: Using original login function with prebind awareness
    public void login(String username, String password, String resource, boolean preBind)         
            throws XMPPException {
        if (!isConnected()) {
            throw new IllegalStateException("Not connected to server.");
        }
    
        ... unchanged
    
        // Indicate that we're now authenticated.
        authenticated = true;
        anonymous = false;
    
        // Added: Prebind only requires connect and authenticate
        if (preBind) {
            return;
        }
    

    then in Web app

    // login with pre-bind only
    connection.login(userName, password, "", true);
    

    This is required as the first thing converse does is perform all the roster and presence stuff that the later half of the login function does. My reasoning here is that the XMPP server will actually see two connections (one from SMACK and one from converse) and it's the one that sends the presence which will end up being target for XMPP messages - and we want that to be converse.

    Edit: Longer code sample for this is in this other StackOverflow answer

    0 讨论(0)
  • 2020-12-21 18:55

    I allready give this tip here and apparently it worked for him to so here it is :

    I neither did have access to client.getRid/Sid. I check in jbosh sources and discover these methods didn't exist so I had to add them.

    I used jbosh sources (uncompiled then recompiled after changes) and add following lines :

    In com.kenai.jbosh.BOSHClient class
    //I introduced a new property
    private Long rid;
    
    //commented the following code
    //long rid = requestIDSeq.getNextRID();
    //and at that place added
    this.rid = requestIDSeq.getNextRID();
    
    //and finally added a new getter for rid
    public Long getRid() {
        return rid;}
    

    Then in smack-bosh :

    In BOSHConnection.java
    public Long getRid() {
        return client.getRid();}
    public String getSid() {
        return sessionID;}
    
    0 讨论(0)
提交回复
热议问题