XMPPErrorException, NotConnectedException, InterruptedException { if (!connection.isConnected()) { return false; .getInstanceFor(connection); DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain()); for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) { if (identity.getName() != null && identity.getName().startsWith("rtpbridge")) {
private static void send(String messageString, XMPPConnection from, XMPPConnection to) throws NotConnectedException, InterruptedException { Message message = new Message(to.getUser()); message.setBody(messageString); from.sendStanza(message); }
/** * Private constructor. * * @param connection connection * @param deviceId deviceId */ private OmemoManager(XMPPConnection connection, Integer deviceId) { super(connection); service = OmemoService.getInstance(); this.deviceId = deviceId; if (connection.isAuthenticated()) { initBareJidAndDeviceId(this); } else { connection.addConnectionListener(new AbstractConnectionListener() { @Override public void authenticated(XMPPConnection connection, boolean resumed) { initBareJidAndDeviceId(OmemoManager.this); } }); } service.registerRatchetForManager(this); // StanzaListeners resumeStanzaAndPEPListeners(); // Announce OMEMO support ServiceDiscoveryManager.getInstanceFor(connection).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY); }
public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { XMPPConnection connection = connection(); ExtensionElement extensionElement = connection.getFeature(Registration.Feature.ELEMENT, Registration.Feature.NAMESPACE); if (extensionElement != null) { return true; } // Fallback to disco#info only if this connection is authenticated, as otherwise we won't have an full JID and // won't be able to do IQs. if (connection.isAuthenticated()) { return ServiceDiscoveryManager.getInstanceFor(connection).serverSupportsFeature(Registration.NAMESPACE); } return false; }
private PingManager(XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Ping.NAMESPACE); connection.registerIQRequestHandler(new AbstractIqRequestHandler(Ping.ELEMENT, Ping.NAMESPACE, Type.get, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { Ping ping = (Ping) iqRequest; return ping.getPong(); } }); connection.addConnectionListener(new AbstractConnectionClosedListener() { @Override public void authenticated(XMPPConnection connection, boolean resumed) { maybeSchedulePingServerTask(); } @Override public void connectionTerminated() { maybeStopPingServerTask(); } }); maybeSchedulePingServerTask(); }
public synchronized void sendTo(final String recipient, final String message) throws XMPPException { log.info(String.format("%s: %s", recipient, message)); XMPPConnection connection = new XMPPConnection(new ConnectionConfiguration("talk.google.com", 5222, "gmail.com")); if (connection.isConnected() == false) { connection.connect(); } if (connection.isAuthenticated() == false) { SASLAuthentication.supportSASLMechanism("PLAIN", 0); connection.login(userName, password); connection.sendPacket(new Presence(Presence.Type.available)); } Message jabberMessage = new Message(recipient, Message.Type.chat); jabberMessage.setBody(message); connection.sendPacket(jabberMessage); connection.disconnect(new Presence(Presence.Type.unavailable)); } }
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222); config.setSASLAuthenticationEnabled(true); config.setSecurityMode(SecurityMode.required); config.setRosterLoadedAtLogin(true); config.setTruststorePath("/system/etc/security/cacerts.bks"); xmpp.connect(); xmpp.login("facebookusername", "****"); // Here you have to used only facebookusername from facebookusername@chat.facebook.com Roster roster = xmpp.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); System.out.println("Connected!"); System.out.println("\n\n" + entries.size() + " buddy(ies):"); xmpp.disconnect(); e.printStackTrace();
connection.connect(); return true; } catch (XMPPException e) { e.printStackTrace(); connection.disconnect(); connection.disconnect(); connection.login(apiKey, accessToken); setPresenceState(Presence.Type.available, ""); connection.getRoster().addRosterListener(rosterListner); return true; } catch (XMPPException e) { connection.disconnect(); e.printStackTrace(); return connection.getRoster(); return connection.getChatManager().createChat(user, messageListner); connection.getChatManager().addChatListener(chatManagerListner); Presence presence = new Presence(precenseType); presence.setStatus(status); connection.sendPacket(presence); return connection.getRoster().getPresence(userId);
@Override protected synchronized void writeToXML(DataPacketExtension data) throws NotConnectedException, InterruptedException { // create message stanza containing data packet Message message = new Message(remoteJID); message.addExtension(data); connection.sendStanza(message); }
public void run() { ConnectionConfiguration connConfig = new ConnectionConfiguration( HOST, PORT); connConfig.setReconnectionAllowed(true); XMPPConnection connection = new XMPPConnection(connConfig); try { connection.connect(); Log.i("XMPPChatDemoActivity", "Connected to " + connection.getHost()); + connection.getHost()); Log.e("XMPPChatDemoActivity", ex.toString()); connection.login(USERNAME, PASSWORD); Log.i("XMPPChatDemoActivity", "Logged in as " + connection.getUser()); connection.sendPacket(presence); Roster roster = connection.getRoster(); Collection<RosterEntry> entries = roster.getEntries();
public void sendSubscriptionRequest(BareJid jid) throws NotLoggedInException, NotConnectedException, InterruptedException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); // Create a presence subscription packet and send. Presence presencePacket = new Presence(Presence.Type.subscribe); presencePacket.setTo(jid); connection.sendStanza(presencePacket); }
ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); XMPPConnection connection = new XMPPConnection(cc); try { connection.connect(); // You have to put this code before you login SASLAuthentication.supportSASLMechanism("PLAIN", 0); // You have to specify your gmail addres WITH @gmail.com at the end connection.login("some.account@gmail.com", "password", "resource"); // See if you are authenticated System.out.println(connection.isAuthenticated()); } catch (XMPPException e1) { e1.printStackTrace(); }
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222); config.setSASLAuthenticationEnabled(true); XMPPConnection xmpp = new XMPPConnection(config); try { SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM", SASLXFacebookPlatformMechanism.class); SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0); xmpp.connect(); xmpp.login(apiKey + "|" + sessionKey, sessionSecret, "Application"); } catch (XMPPException e) { xmpp.disconnect(); e.printStackTrace(); }
/** * Changes the occupant's availability status within the room. The presence type * will remain available but with a new status that describes the presence update and * a new presence mode (e.g. Extended away). * * @param status a text message describing the presence update. * @param mode the mode type for the presence update. * @throws NotConnectedException * @throws InterruptedException * @throws MucNotJoinedException */ public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException, InterruptedException, MucNotJoinedException { final EntityFullJid myRoomJid = this.myRoomJid; if (myRoomJid == null) { throw new MucNotJoinedException(this); } // Check that we already have joined the room before attempting to change the // availability status. if (!joined) { throw new MucNotJoinedException(this); } // We change the availability status by sending a presence packet to the room with the // new presence status and mode Presence joinPresence = new Presence(Presence.Type.available); joinPresence.setStatus(status); joinPresence.setMode(mode); joinPresence.setTo(myRoomJid); // Send join packet. connection.sendStanza(joinPresence); }
ConnectionConfiguration connConfig = new ConnectionConfiguration("ip", 5222); XMPPConnection connection = new XMPPConnection(connConfig); connection.connect(); connection.login("username", "password"); AccountManager accountManager = connection.getAccountManager(); accountManager.createAccount("adminCreated1", "123456"); connection.disconnect();
private void xmppConnect() throws KenaiException { firePropertyChange(new PropertyChangeEvent(this, PROP_XMPP_LOGIN_STARTED, null, null)); synchronized (this) { xmppConnection = new XMPPConnection(getUrl().getHost()); packetListener = new KenaiUser.KenaiPacketListener(); try { xmppConnection.removePacketListener(packetListener); xmppConnection.connect(); xmppConnection.addPacketListener(packetListener, new PacketTypeFilter(Presence.class)); xmppConnection.login(auth.getUserName(), new String(auth.getPassword()), "NetBeans"); //NOI18N } catch (XMPPException xMPPException) { xmppConnection = null; firePropertyChange(new PropertyChangeEvent(this, PROP_XMPP_LOGIN_FAILED, null, null)); throw new KenaiException(xMPPException); } catch (IllegalStateException ise) { xmppConnection = null; firePropertyChange(new PropertyChangeEvent(this, PROP_XMPP_LOGIN_FAILED, null, null)); throw new KenaiException(ise); } } firePropertyChange(new PropertyChangeEvent(this, PROP_XMPP_LOGIN, null, xmppConnection)); }
sdm.addDiscoverInfoTo(discoverInfo); if (lastLocalCapsVersions.size() > 10) { CapsVersionAndHash oldCapsVersion = lastLocalCapsVersions.poll(); sdm.removeNodeInformationProvider(entityNode + '#' + oldCapsVersion.version); JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion)); final List<Identity> identities = new LinkedList<>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities()); sdm.setNodeInformationProvider(localNodeVer, new AbstractNodeInformationProvider() { List<String> features = sdm.getFeatures(); if (connection != null && connection.isAuthenticated() && presenceSend != null) { try { connection.sendStanza(presenceSend.cloneWithNewId());
SASLAuthentication.supportSASLMechanism("PLAIN"); ConnectionConfiguration config = new ConnectionConfiguration( "talk.google.com", 5222, "gmail.com"); XMPPConnection conn = new XMPPConnection(config); conn.connect(); conn.login("yourid@gmail.com", "password"); Roster roster = conn.getRoster(); Collection<RosterEntry> set = roster.getEntries(); for (RosterEntry re: set) { System.out.println(">> " + re.getUser()); Presence pres = roster.getPresence(re.getUser()); //This is the status. System.out.println("\t> " + pres.getMode()); }
/** * Get a new STUN Server Address and port from the server. * If a error occurs or the server don't support STUN Service, null is returned. * * @param connection * @return the STUN server address * @throws NotConnectedException * @throws InterruptedException */ @SuppressWarnings("deprecation") public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException { if (!connection.isConnected()) { return null; } STUN stunPacket = new STUN(); stunPacket.setTo(DOMAIN + "." + connection.getXMPPServiceDomain()); StanzaCollector collector = connection.createStanzaCollectorAndSend(stunPacket); STUN response = collector.nextResult(); // Cancel the collector. collector.cancel(); return response; }
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222); config.setSASLAuthenticationEnabled(true); config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); XMPPConnection xmpp = new XMPPConnection(config); SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM",SASLXFacebookPlatformMechanism.class); SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0); xmpp.connect(); xmpp.login(appSecret, accessToken, "Application");