src/modules/chat/qbChat.js
function(callback, isInitialConnect) {
        Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());

        var self = this,
            xmppClient = Utils.getEnv().browser ? self.connection : self.Client,
            presence = Utils.getEnv().browser ? $pres() : chatUtils.createStanza(XMPP.Stanza, null, 'presence');
                
        if (config.streamManagement.enable && config.chatProtocol.active === 2) {
            self.streamManagement.enable(self.connection, null);
            self.streamManagement.sentMessageCallback = self._sentMessageCallback;
        }

        self.helpers.setUserCurrentJid(self.helpers.userCurrentJid(xmppClient));
        
        self.isConnected = true;
        self._isConnecting = false;

        self._enableCarbons();

        if (isInitialConnect) {
            self.roster.get(function(contacts) {
                xmppClient.send(presence);

                self.roster.contacts = contacts;
                callback(self.roster.contacts);
            });
        } else {
            var rooms = Object.keys(self.muc.joinedRooms);
            
            xmppClient.send(presence);

            Utils.QBLog('[QBChat]', 'Re-joining ' + rooms.length + " rooms...");

            for (var i = 0, len = rooms.length; i < len; i++) {
                self.muc.join(rooms[i]);
            }

            if (typeof self.onReconnectListener === 'function') {
                Utils.safeCallbackCall(self.onReconnectListener);
            }
        }
    }
function(callback, isInitialConnect) {
        Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());

        var self = this,
            xmppClient = Utils.getEnv().browser ? self.connection : self.Client,
            presence = Utils.getEnv().browser ? $pres() : chatUtils.createStanza(XMPP.Stanza, null, 'presence');
                
        if (config.streamManagement.enable && config.chatProtocol.active === 2) {
            self.streamManagement.enable(self.connection, null);
            self.streamManagement.sentMessageCallback = self._sentMessageCallback;
        }

        self.helpers.setUserCurrentJid(self.helpers.userCurrentJid(xmppClient));
        
        self.isConnected = true;
        self._isConnecting = false;

        self._enableCarbons();

        if (isInitialConnect) {
            self.roster.get(function(contacts) {
                xmppClient.send(presence);

                self.roster.contacts = contacts;
                callback(self.roster.contacts);
            });
        } else {
            var rooms = Object.keys(self.muc.joinedRooms);
            
            xmppClient.send(presence);

            Utils.QBLog('[QBChat]', 'Re-joining ' + rooms.length + " rooms...");

            for (var i = 0, len = rooms.length; i < len; i++) {
                self.muc.join(rooms[i]);
            }

            if (typeof self.onReconnectListener === 'function') {
                Utils.safeCallbackCall(self.onReconnectListener);
            }
        }
    }
function ( callback , isInitialConnect ) { Utils . QBLog ( '[QBChat]' , 'Status.CONNECTED at ' + chatUtils . getLocalTime ( ) ) ; var self = this , xmppClient = Utils . getEnv ( ) . browser ? self . connection : self . Client , presence = Utils . getEnv ( ) . browser ? $pres ( ) : chatUtils . createStanza ( XMPP . Stanza , null , 'presence' ) ; if ( config . streamManagement . enable && config . chatProtocol . active === 2 ) { self . streamManagement . enable ( self . connection , null ) ; self . streamManagement . sentMessageCallback = self . _sentMessageCallback ; } self . helpers . setUserCurrentJid ( self . helpers . userCurrentJid ( xmppClient ) ) ; self . isConnected = true ; self . _isConnecting = false ; self . _enableCarbons ( ) ; if ( isInitialConnect ) { self . roster . get ( function ( contacts ) { xmppClient . send ( presence ) ; self . roster . contacts = contacts ; callback ( self . roster . contacts ) ; } ) ; } else { var rooms = Object . keys ( self . muc . joinedRooms ) ; xmppClient . send ( presence ) ; Utils . QBLog ( '[QBChat]' , 'Re-joining ' + rooms . length + " rooms..." ) ; for ( var i = 0 , len = rooms . length ; i < len ; i ++ ) { self . muc . join ( rooms [ i ] ) ; } if ( typeof self . onReconnectListener === 'function' ) { Utils . safeCallbackCall ( self . onReconnectListener ) ; } } }
Actions after the connection is established

- enable stream management (the configuration setting);
- save user's JID;
- enable carbons;
- get and storage the user's roster (if the initial connect);
- recover the joined rooms and fire 'onReconnectListener' (if the reconnect);
- send initial presence to the chat server.
Actions after the connection is established