Search in sources :

Example 1 with ReconnectionManager

use of org.jivesoftware.smack.ReconnectionManager in project Zom-Android by zom.

the class XmppConnection method initConnectionAndLogin.

private void initConnectionAndLogin(Imps.ProviderSettings.QueryMap providerSettings, String userName) throws InterruptedException, IOException, SmackException, XMPPException, KeyManagementException, NoSuchAlgorithmException, IllegalStateException, RuntimeException {
    // Roster.SubscriptionMode.accept_all;//load this from a preference
    Roster.SubscriptionMode subMode = Roster.SubscriptionMode.manual;
    // only activates if Debug TRUE is set, so you can leave this in!
    Debug.onConnectionStart();
    initConnection(providerSettings, userName);
    if (mConnection.isConnected() && mConnection.isSecureConnection() && (!mConnection.isAuthenticated())) {
        mResource = providerSettings.getXmppResource();
        mRoster = Roster.getInstanceFor(mConnection);
        mRoster.setRosterLoadedAtLogin(true);
        mRoster.setSubscriptionMode(subMode);
        getContactListManager().listenToRoster(mRoster);
        ReconnectionManager manager = ReconnectionManager.getInstanceFor(mConnection);
        manager.disableAutomaticReconnection();
        mChatManager = ChatManager.getInstanceFor(mConnection);
        mPingManager = PingManager.getInstanceFor(mConnection);
        mPingManager.setPingInterval(PING_INTERVAL);
        if (mUser == null)
            mUser = makeUser(providerSettings, mContext.getContentResolver());
        try {
            getOmemo();
        } catch (Exception e) {
            debug(TAG, "error init'ing omemo during connectoin", e);
        }
        MultiUserChatManager.getInstanceFor(mConnection).addInvitationListener(new InvitationListener() {

            @Override
            public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, EntityJid entityJid, String reason, String password, org.jivesoftware.smack.packet.Message message, MUCUser.Invite invite) {
                try {
                    getChatGroupManager().acceptInvitationAsync(invite.getFrom().toString());
                    XmppAddress xa = new XmppAddress(muc.getRoom().toString());
                    mChatGroupManager.joinChatGroupAsync(xa, reason);
                    ChatSession session = mSessionManager.findSession(muc.getRoom());
                    // create a session
                    if (session == null) {
                        ImEntity participant = findOrCreateParticipant(xa.getAddress(), true);
                        if (participant != null)
                            session = mSessionManager.createChatSession(participant, false);
                        if (session != null)
                            ((ChatGroup) session.getParticipant()).setName(muc.getSubject());
                    }
                } catch (Exception se) {
                    Log.e(TAG, "error accepting invite", se);
                }
            }
        });
        mConnection.login(mUsername, mPassword, Resourcepart.from(mResource));
        mStreamHandler.notifyInitialLogin();
        initServiceDiscovery();
        getContactListManager().loadContactListsAsync();
        execute(new Runnable() {

            public void run() {
                sendPresencePacket();
                sendVCard();
            }
        });
    } else {
        // throw some meaningful error message here
        throw new SmackException("Unable to securely conenct to server");
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) ReconnectionManager(org.jivesoftware.smack.ReconnectionManager) SmackException(org.jivesoftware.smack.SmackException) ChatGroup(org.awesomeapp.messenger.model.ChatGroup) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException) ChatSession(org.awesomeapp.messenger.model.ChatSession) IChatSession(org.awesomeapp.messenger.service.IChatSession) EntityJid(org.jxmpp.jid.EntityJid) Roster(org.jivesoftware.smack.roster.Roster) InvitationListener(org.jivesoftware.smackx.muc.InvitationListener) ImEntity(org.awesomeapp.messenger.model.ImEntity)

Aggregations

RemoteException (android.os.RemoteException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ChatGroup (org.awesomeapp.messenger.model.ChatGroup)1 ChatSession (org.awesomeapp.messenger.model.ChatSession)1 ImEntity (org.awesomeapp.messenger.model.ImEntity)1 ImException (org.awesomeapp.messenger.model.ImException)1 IChatSession (org.awesomeapp.messenger.service.IChatSession)1 AbstractXMPPConnection (org.jivesoftware.smack.AbstractXMPPConnection)1 ReconnectionManager (org.jivesoftware.smack.ReconnectionManager)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Roster (org.jivesoftware.smack.roster.Roster)1 InvitationListener (org.jivesoftware.smackx.muc.InvitationListener)1