org.jivesoftware.smack.ChatManager Java Examples
The following examples show how to use
org.jivesoftware.smack.ChatManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Friend.java From League-of-Legends-XMPP-Chat-Library with MIT License | 6 votes |
private Chat getChat() { if (chat == null) { chat = ChatManager.getInstanceFor(con).createChat(getUserId(), new MessageListener() { @Override public void processMessage(Chat c, Message m) { if (chat != null && listener != null) { listener.onMessage(instance, m.getBody()); } } }); } return chat; }
Example #2
Source File: SmackConnection.java From SmackAndroidDemo with Apache License 2.0 | 5 votes |
private void sendMessage(String body, String toJid) { Log.i(TAG, "sendMessage()"); Chat chat = ChatManager.getInstanceFor(mConnection).createChat(toJid, this); try { chat.sendMessage(body); } catch (SmackException.NotConnectedException | XMPPException e) { e.printStackTrace(); } }
Example #3
Source File: MPAuthenticationProvider.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Read the PIN number sent by the user as the reply. * * @param connection * @param userName * @return */ public boolean getUserResponse(XMPPConnection connection, String userName) { String response = null; Presence presence = connection.getRoster().getPresence(userName); if (presence.isAvailable()) { try { ChatManager chatManager = connection.getChatManager(); Chat chat = chatManager.createChat(userName, null); PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class), new FromContainsFilter(userName)); XmppResponseListener chatListener = new XmppResponseListener(); connection.addPacketListener(chatListener, filter); if (isPINEnabled) { chat.sendMessage("Please reply with your PIN Number here."); if (log.isInfoEnabled()) { log.info("User PIN is sent to the user and awaiting for the response."); } while (!chatListener.isResponseReceived()) { Thread.sleep(100); } response = chatListener.getResponse(); if (response != null) { return userPIN.contentEquals(response.trim()); } } else { chat.sendMessage( "You are about to get authenticated for your OpenID. Do you want to continue: [Yes] or [No]"); if (log.isInfoEnabled()) { log.info("User PIN is sent to the user and awaiting for the response."); } while (!chatListener.isResponseReceived()) { Thread.sleep(100); } response = chatListener.getResponse(); if (response != null) { if ("YES".equalsIgnoreCase(response.trim())) { return true; } else if ("NO".equalsIgnoreCase(response.trim())) { return false; } else { pinDisabledResponse = false; return false; } } } } catch (Exception e) { log.error("Error while getting user response", e); } } else { return false; } return false; }
Example #4
Source File: SmackConnection.java From SmackAndroidDemo with Apache License 2.0 | 3 votes |
public void connect() throws IOException, XMPPException, SmackException { Log.i(TAG, "connect()"); XMPPTCPConnectionConfiguration.XMPPTCPConnectionConfigurationBuilder builder = XMPPTCPConnectionConfiguration.builder(); builder.setServiceName(mServiceName); builder.setResource("SmackAndroidTestClient"); builder.setUsernameAndPassword(mUsername, mPassword); builder.setRosterLoadedAtLogin(true); mConnection = new XMPPTCPConnection(builder.build()); //Set ConnectionListener here to catch initial connect(); mConnection.addConnectionListener(this); mConnection.connect(); mConnection.login(); PingManager.setDefaultPingInterval(600); //Ping every 10 minutes PingManager pingManager = PingManager.getInstanceFor(mConnection); pingManager.registerPingFailedListener(this); setupSendMessageReceiver(); ChatManager.getInstanceFor(mConnection).addChatListener(this); mConnection.getRoster().addRosterListener(this); }