private void tryToConnect(boolean create_account) throws ClientException { try { if (extXMPPConnection.isConnected()) { try { streamHandler.quickShutdown(); } catch (Exception e) { Log.d(TAG, "conn.shutdown() failed: " + e); } } registerRosterListener(); boolean need_bind = !streamHandler.isResumePossible(); if (connectionListener != null) extXMPPConnection.removeConnectionListener(connectionListener); connectionListener = new ConnectionListener() { public void connectionClosedOnError(Exception e) { onDisconnected(e); } public void connectionClosed() { updateConnectionState(ConnectionState.OFFLINE); } public void reconnectingIn(int seconds) {} public void reconnectionFailed(Exception e) {} public void reconnectionSuccessful() {} }; extXMPPConnection.addConnectionListener(connectionListener); extXMPPConnection.connect(need_bind); if (!extXMPPConnection.isAuthenticated()) { if (create_account) { AccountManager am = new AccountManager(extXMPPConnection); am.createAccount(configuration.userName, configuration.password); } extXMPPConnection.login( configuration.userName, configuration.password, configuration.ressource); } if (need_bind) { streamHandler.notifyInitialLogin(); setStatusFromConfig(); } } catch (Exception e) { throw new ClientException("tryToConnect failed", e); } }
public void sendServerPing() { if (extXMPPConnection == null || !extXMPPConnection.isAuthenticated()) { requestConnectionState(ConnectionState.ONLINE, false); return; } if (pingID != null) { return; } if (streamHandler.isIfEnabled()) { pingID = "" + streamHandler.requestAck(); } else { Ping ping = new Ping(); ping.setType(Type.GET); ping.setTo(configuration.server); pingID = ping.getPacketID(); extXMPPConnection.sendPacket(ping); } registerPongTimeout(PACKET_TIMEOUT + 3000, pingID); }
public void setUserWatching(boolean user_watching) { if (isUserWatching == user_watching) return; isUserWatching = user_watching; if (extXMPPConnection != null && extXMPPConnection.isAuthenticated()) sendUserWatching(); }
public boolean isAuthenticated() { if (extXMPPConnection != null) { return (extXMPPConnection.isConnected() && extXMPPConnection.isAuthenticated()); } return false; }