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");
}
}
Aggregations