private void waitForTransfer(FileTransfer transfer, long timeout) throws SmackException, InterruptedException { double prevProgress = 0; long counter = 0; Thread.sleep(timeout / WAITING_CYCLES / 10); // optimistic while (!transfer.isDone()) { if (transfer.getStatus().equals(FileTransfer.Status.error)) { throw new SmackException(transfer.getError().toString(), transfer.getException()); } else { log.debug("Status: " + transfer.getStatus() + " " + transfer.getProgress()); } if (transfer.getProgress() <= prevProgress) { if (counter >= WAITING_CYCLES) { throw new SmackException("File transfer timed out"); } counter++; Thread.sleep(timeout / WAITING_CYCLES); } else { counter = 0; prevProgress = transfer.getProgress(); } } if (transfer.getProgress() == 0) { throw new SmackException("No data transferred"); } }
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException { long time = 0; do { Iterator<Message> packets = responseMessages.iterator(); Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic while (packets.hasNext()) { Packet packet = packets.next(); Message response = (Message) packet; if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) { packets.remove(); res.setResponseData(response.toXML().toString().getBytes()); if (response.getError() != null) { res.setSuccessful(false); res.setResponseCode("500"); res.setResponseMessage(response.getError().toString()); } return res; } } time += conn.getPacketReplyTimeout() / 10; Thread.sleep(conn.getPacketReplyTimeout() / 10); } while (time < conn.getPacketReplyTimeout()); throw new SmackException.NoResponseException(); }
@Override public void processPacket(Packet packet) throws SmackException.NotConnectedException { if (packet instanceof Message) { Message inMsg = (Message) packet; if (inMsg.getBody() != null) { if (inMsg.getBody().endsWith(NEED_RESPONSE_MARKER)) { if (inMsg.getExtension(NS_DELAYED) == null) { log.debug("Will respond to message: " + inMsg.toXML()); sendResponseMessage(inMsg); } else { log.debug("Will not consider history message: " + inMsg.toXML()); } } else if (inMsg.getBody().endsWith(RESPONSE_MARKER)) { responseMessages.add(inMsg); } } } }
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException { Random random = new Random(timestamp + body.length() + chatJid.length()); Log.d(TAG, "Sending message to : " + chatJid); MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection) .getMultiUserChat(chatJid); chat.addMessageListener(this); Message message = new Message(); QuickbloxChatExtension extension = new QuickbloxChatExtension(); extension.setProperty("date_sent", timestamp + ""); message.setStanzaId(StanzaIdUtil.newStanzaId()); message.setBody(body); message.addExtension(extension); message.setType(Message.Type.chat); chat.sendMessage(message); }
public void sendDisplayedReceipt(String receiverJid, String stanzaId, String dialog_id) { Chat chat; if ((chat = privateChats.get(receiverJid)) == null) { chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this); privateChats.put(receiverJid, chat); } Message message = new Message(receiverJid); Displayed read = new Displayed(stanzaId); QuickbloxChatExtension extension = new QuickbloxChatExtension(); extension.setProperty("dialog_id", dialog_id); message.setStanzaId(StanzaIdUtil.newStanzaId()); message.setType(Message.Type.chat); message.addExtension(read); message.addExtension(extension); try { chat.sendMessage(message); } catch (SmackException.NotConnectedException ex) { Logger.logExceptionToFabric(ex); offlineMessages.add(message); } }
public void sendReceivedReceipt(String receiverJid, String stanzaId, String dialog_id) { Chat chat; if ((chat = privateChats.get(receiverJid)) == null) { chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this); privateChats.put(receiverJid, chat); } Message message = new Message(receiverJid); Received delivered = new Received(stanzaId); QuickbloxChatExtension extension = new QuickbloxChatExtension(); extension.setProperty("dialog_id", dialog_id); message.setStanzaId(StanzaIdUtil.newStanzaId()); message.setType(Message.Type.chat); message.addExtension(delivered); message.addExtension(extension); try { chat.sendMessage(message); } catch (SmackException.NotConnectedException ex) { offlineMessages.add(message); } }
public void sendPrivateMessage(String body, String receiverJid, long timestamp, String stanzaId) { Log.d(TAG, "Sending message to : " + receiverJid); Chat chat; if ((chat = privateChats.get(receiverJid)) == null) { chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this); privateChats.put(receiverJid, chat); } QuickbloxChatExtension extension = new QuickbloxChatExtension(); extension.setProperty("date_sent", timestamp + ""); extension.setProperty("save_to_history", "1"); Message message = new Message(receiverJid); message.setStanzaId(stanzaId); message.setBody(body); message.setType(Message.Type.chat); message.addExtension(new Markable()); message.addExtension(extension); try { chat.sendMessage(message); } catch (SmackException.NotConnectedException ex) { offlineMessages.add(message); } }
public void sendPublicMessage(String body, String chatJid, long timestamp, String stanzaId) { Log.d(TAG, "Sending message to : " + chatJid); MultiUserChat mucChat = publicChats.get(chatJid); QuickbloxChatExtension extension = new QuickbloxChatExtension(); extension.setProperty("date_sent", timestamp + ""); extension.setProperty("save_to_history", "1"); Message message = new Message(chatJid); message.setStanzaId(stanzaId); message.setBody(body); message.setType(Message.Type.groupchat); message.addExtension(extension); try { if (mucChat != null) { mucChat.sendMessage(message); } } catch (SmackException.NotConnectedException ex) { offlineMessages.add(message); } }
@Override public void reconnectionSuccessful() { connected = true; if (!offlineMessages.isEmpty()) { JobExecutor.getInstance().execute(() -> { while (!offlineMessages.isEmpty()) { try { if (!publicChatToLeave.isEmpty()) { publicChats.get(publicChatToLeave).leave(); publicChatToLeave = ""; } Message message = offlineMessages.peek(); privateChatConnection.sendStanza(message); } catch (SmackException ex) { Logger.logExceptionToFabric(ex); break; } offlineMessages.poll(); } }); } Log.d(TAG, "Reconnection successful"); }
@Test public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); PubSub errorIq = new PubSub(); XMPPError error = new XMPPError(Condition.forbidden); errorIq.setError(error); con.addIQReply(errorIq); try { node.getNodeConfiguration(); } catch (XMPPErrorException e) { Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType()); } }
private void controlNotificationAlarm(boolean torchMode) { final XMPPTCPConnection connection = mXmppManager.getXmppConnection(); final EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify(); if (fullThingJid == null) return; SetBoolData setTorch = new SetBoolData(Constants.NOTIFICATION_ALARM, torchMode); IoTControlManager ioTControlManager = IoTControlManager.getInstanceFor(connection); LOGGER.info("Trying to control " + fullThingJid + " set torchMode=" + torchMode); try { final IoTSetResponse ioTSetResponse = ioTControlManager.setUsingIq(fullThingJid, setTorch); } catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) { mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not control thing: " + e, Toast.LENGTH_LONG).show()); LOGGER.log(Level.SEVERE, "Could not set data", e); } }
public BlogPostComment sendBlogPostComment(String content, BlogPost blogPost) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Jid jid = XMPPSession.getInstance().getUser().asEntityBareJid(); String userName = XMPPUtils.fromJIDToUserName(jid.toString()); Jid pubSubServiceJid = XMPPSession.getInstance().getPubSubService(); // create stanza PublishCommentExtension publishCommentExtension = new PublishCommentExtension(blogPost.getId(), userName, jid, content, new Date()); PubSub publishCommentPubSub = PubSub.createPubsubPacket(pubSubServiceJid, IQ.Type.set, publishCommentExtension, null); // send stanza XMPPSession.getInstance().sendStanza(publishCommentPubSub); return new BlogPostComment(publishCommentExtension.getId(), blogPost.getId(), content, userName, jid.toString(), publishCommentExtension.getPublished()); }
@Override protected void loginAnonymously() throws XMPPException, SmackException, IOException { // Wait with SASL auth until the SASL mechanisms have been received saslFeatureReceived.checkIfSuccessOrWaitOrThrow(); if (saslAuthentication.hasAnonymousAuthentication()) { saslAuthentication.authenticateAnonymously(); } else { // Authenticate using Non-SASL throw new SmackException("No anonymous SASL authentication mechanism available"); } bindResourceAndEstablishSession(null); afterSuccessfulLogin(false); }
@Override protected void doStart() throws Exception { if (connection == null) { try { connection = endpoint.createConnection(); } catch (SmackException e) { if (endpoint.isTestConnectionOnStartup()) { throw new RuntimeException("Could not connect to XMPP server: " + endpoint.getConnectionDescription(), e); } else { LOG.warn("Could not connect to XMPP server. {} Producer will attempt lazy connection when needed.", e.getMessage()); } } } if (chat == null && connection != null) { initializeChat(); } super.doStart(); }
@Override public Transcript parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { String sessionID = parser.getAttributeValue("", "sessionID"); List<Stanza> packets = new ArrayList<Stanza>(); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("message")) { packets.add(PacketParserUtils.parseMessage(parser)); } else if (parser.getName().equals("presence")) { packets.add(PacketParserUtils.parsePresence(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("transcript")) { done = true; } } } return new Transcript(sessionID, packets); }
public void createNodeToAllowComments(String blogPostId) { String nodeName = PublishCommentExtension.NODE + "/" + blogPostId; PubSubManager pubSubManager = PubSubManager.getInstance(XMPPSession.getInstance().getXMPPConnection()); try { // create node ConfigureForm configureForm = new ConfigureForm(DataForm.Type.submit); configureForm.setPublishModel(PublishModel.open); configureForm.setAccessModel(AccessModel.open); Node node = pubSubManager.createNode(nodeName, configureForm); // subscribe to comments String myJIDString = getUser().toString(); node.subscribe(myJIDString); } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) { e.printStackTrace(); } }
public void removeContact(String jidString) throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException, XmppStringprepException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } BareJid jid = JidCreate.bareFrom(jidString); roster.removeEntry(roster.getEntry(jid)); Presence presence = new Presence(Presence.Type.unsubscribe); presence.setTo(JidCreate.from(jidString)); XMPPSession.getInstance().sendStanza(presence); }
@Override public TranscriptSearch parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { TranscriptSearch answer = new TranscriptSearch(); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { // Parse the packet extension PacketParserUtils.addExtensionElement(answer, parser); } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(ELEMENT_NAME)) { done = true; } } } return answer; }
/** * Send file to provided JID via a SOCKS5 Bytestream session (XEP-0065). * * @param file * @param jid * @throws SmackException * @throws InterruptedException * @throws IOException * @throws XMPPException */ public void sendFile(byte[] file, String jid) throws XMPPException, IOException, InterruptedException, SmackException { String jidFinal = getFullJid(jid); jidFinal += "/receiver"; Socks5BytestreamManager bytestreamManager = Socks5BytestreamManager.getBytestreamManager(connection); OutputStream outputStream = null; try { Socks5BytestreamSession session = bytestreamManager.establishSession(jidFinal); outputStream = session.getOutputStream(); outputStream.write(file); outputStream.flush(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error(e.getMessage(), e); } } } }
/** * @param jingle * @param jingleTransport * @return the iq * @throws SmackException */ private IQ receiveSessionInitiateAction(Jingle jingle) throws XMPPException, SmackException { IQ response = null; // Parse the Jingle and get any proposed transport candidates //addRemoteCandidates(obtainCandidatesList(jin)); // Start offering candidates sendTransportCandidatesOffer(); // All these candidates will be checked asyncronously. Wait for some // time and check if we have a valid candidate to use... delayedCheckBestCandidate(session, jingle); // Set the next state setNegotiatorState(JingleNegotiatorState.PENDING); return response; }
@Override public WorkgroupForm parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { WorkgroupForm answer = new WorkgroupForm(); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { // Parse the packet extension PacketParserUtils.addExtensionElement(answer, parser); } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(ELEMENT_NAME)) { done = true; } } } return answer; }
@Override public CarbonExtension parse(XmlPullParser parser, int initialDepth) throws SmackException, XmlPullParserException, IOException { Direction dir = Direction.valueOf(parser.getName()); Forwarded fwd = null; boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) { fwd = FORWARDED_PROVIDER.parse(parser); } else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName())) done = true; } if (fwd == null) throw new SmackException("sent/received must contain exactly one <forwarded> tag"); return new CarbonExtension(dir, fwd); }
/** * Parses Headers and Data elements. * * @param parser parser * @param elementName name of concrete implementation of this element * @param body parent Body element * @throws IOException * @throws XmlPullParserException * @throws SmackException */ protected void parseHeadersAndData(XmlPullParser parser, String elementName, AbstractHttpOverXmpp body) throws XmlPullParserException, IOException, SmackException { boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals(HeadersExtension.ELEMENT)) { HeadersExtension headersExtension = HeadersProvider.INSTANCE.parse(parser); body.setHeaders(headersExtension); } else if (parser.getName().endsWith(ELEMENT_DATA)) { AbstractHttpOverXmpp.Data data = parseData(parser); body.setData(data); } else { throw new IllegalArgumentException("unexpected tag:" + parser.getName() + "'"); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(elementName)) { done = true; } } } }
@Test public void testRange2() throws XmlPullParserException, IOException, SmackException { ValidateElement dv = new RangeValidateElement(null, null, null); assertNotNull( dv.toXML()); String output = dv.toXML().toString(); assertEquals(TEST_OUTPUT_RANGE2, output); XmlPullParser parser = getParser(output); dv = DataValidationProvider.parse(parser); assertNotNull(dv); assertEquals("xs:string", dv.getDatatype()); assertTrue(dv instanceof RangeValidateElement ); RangeValidateElement rdv = (RangeValidateElement) dv; assertEquals(null, rdv.getMin()); assertEquals(null, rdv.getMax()); assertNotNull( rdv.toXML()); output = rdv.toXML().toString(); assertEquals(TEST_OUTPUT_RANGE2, output); }
private final void authenticate() throws SmackException, NotConnectedException { byte[] authenticationBytes = getAuthenticationText(); String authenticationText; // Some SASL mechanisms do return an empty array (e.g. EXTERNAL from javax), so check that // the array is not-empty. Mechanisms are allowed to return either 'null' or an empty array // if there is no authentication text. if (authenticationBytes != null && authenticationBytes.length > 0) { authenticationText = Base64.encodeToString(authenticationBytes); } else { // RFC6120 6.4.2 "If the initiating entity needs to send a zero-length initial response, // it MUST transmit the response as a single equals sign character ("="), which // indicates that the response is present but contains no data." authenticationText = "="; } // Send the authentication to the server connection.send(new AuthMechanism(getName(), authenticationText)); }
/** * Parse a iq/jingle/description element. * * @param parser * the input to parse * @return a description element * @throws SmackException * @throws IOException * @throws XmlPullParserException */ public JingleDescription parse(XmlPullParser parser, int initialDepth) throws SmackException, XmlPullParserException, IOException { boolean done = false; JingleDescription desc = getInstance(); while (!done) { int eventType = parser.next(); String name = parser.getName(); if (eventType == XmlPullParser.START_TAG) { if (name.equals(PayloadType.NODENAME)) { desc.addPayloadType(parsePayload(parser)); } else { throw new SmackException("Unknow element \"" + name + "\" in content."); } } else if (eventType == XmlPullParser.END_TAG) { if (name.equals(JingleDescription.NODENAME)) { done = true; } } } return desc; }
private static Map<Character, String> parseAttributes(String string) throws SmackException { if (string.length() == 0) { return Collections.emptyMap(); } String[] keyValuePairs = string.split(","); Map<Character, String> res = new HashMap<Character, String>(keyValuePairs.length, 1); for (String keyValuePair : keyValuePairs) { if (keyValuePair.length() < 3) { throw new SmackException("Invalid Key-Value pair: " + keyValuePair); } char key = keyValuePair.charAt(0); if (keyValuePair.charAt(1) != '=') { throw new SmackException("Invalid Key-Value pair: " + keyValuePair); } String value = keyValuePair.substring(2); res.put(key, value); } return res; }
protected void runTest() throws NotConnectedException, SmackException { saslMechanism.authenticate("florian", "irrelevant", "xmpp.org", "secret"); byte[] response = saslMechanism.evaluateChallenge(challengeBytes); String responseString = new String(response); String[] responseParts = responseString.split(","); Map<String, String> responsePairs = new HashMap<String, String>(); for (String part : responseParts) { String[] keyValue = part.split("="); assertTrue(keyValue.length == 2); String key = keyValue[0]; String value = keyValue[1].replace("\"", ""); responsePairs.put(key, value); } assertMapValue("username", "florian", responsePairs); assertMapValue("realm", "xmpp.org", responsePairs); assertMapValue("digest-uri", "xmpp/xmpp.org", responsePairs); assertMapValue("qop", "auth", responsePairs); }
private void sendResponseMessage(Message inMsg) { Message outMsg = new Message(inMsg.getFrom()); outMsg.setType(inMsg.getType()); outMsg.addBody("", inMsg.getBody() + "\r\n" + System.currentTimeMillis() + "@" + RESPONSE_MARKER); log.debug("Responding to message: " + outMsg.toXML()); try { conn.sendPacket(outMsg); } catch (SmackException e) { log.error("Failed to send response", e); } }
@Override public void processPacket(Packet packet) throws SmackException.NotConnectedException { /** TODO: do we need to respond? if (packet instanceof Presence) { Presence presence = (Presence) packet; if (presence.getType() == Presence.Type.subscribe) { try { conn.getRoster().createEntry(presence.getFrom(), presence.getFrom(), new String[0]); } catch (SmackException.NotLoggedInException | SmackException.NoResponseException | XMPPException.XMPPErrorException e) { log.error("Failed to add to roster", e); } } } */ }
@Override public void processPacket(Packet packet) throws SmackException.NotConnectedException { try { log.debug("Packet recv [" + conn.getConnectionID() + "]: " + packet.toXML()); } catch (IllegalArgumentException e) { log.debug("Failed to log packet", e); log.debug("Packet recv [" + conn.getConnectionID() + "]: " + packet.getError()); } }
public void testTestStarted() throws NoSuchAlgorithmException, KeyManagementException, SmackException, InterruptedException { JMeterXMPPConnection obj = new JMeterXMPPConnection(); obj.setAddress("localhost"); obj.testStarted(""); obj.getConnection(); obj.testEnded(""); }
public void connect() throws IOException, XMPPException, SmackException { ProviderManager.addExtensionProvider(ReadReceipt.ELEMENT, ReadReceipt.NAMESPACE, new ReadReceipt.Provider()); receiptReceivedListener = (fromJid, toJid, receiptId, receipt) -> { // TODO Handle read event }; ReadReceiptManager.getInstanceFor(groupChatConnection).addReadReceivedListener(receiptReceivedListener); initGroupConnection(); groupChatConnection.connect(); groupChatConnection.login(); }
public void leavePublicChat(String chatJid) { MultiUserChat muc = publicChats.get(chatJid); try { if (publicChats.get(chatJid) != null) { muc.leave(); } } catch (SmackException.NotConnectedException ex){ Logger.logExceptionToFabric(ex); publicChatToLeave = chatJid; } }
@Override public int onStartCommand(Intent intent, int flags, int startId) { JobExecutor.getInstance().execute(() -> { try { privateConnection.connect(); }catch (XMPPException | SmackException | IOException ex){ Logger.logExceptionToFabric(ex); EventBus.getDefault().post(ex); } }); return START_STICKY; }
private void performReadOut() { XMPPTCPConnection connection = mXmppManager.getXmppConnection(); EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify(); if (fullThingJid == null) return; LOGGER.info("Requesting read out from " + fullThingJid); IoTDataManager iotDataManager = IoTDataManager.getInstanceFor(connection); final List<IoTFieldsExtension> res; try { res = iotDataManager.requestMomentaryValuesReadOut(fullThingJid); } catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException |InterruptedException e) { mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not perform read out: " + e, Toast.LENGTH_LONG).show()); LOGGER.log(Level.WARNING, "Could not perform read out", e); return; } final List<? extends IoTDataField> dataFields = res.get(0).getNodes().get(0).getTimestampElements().get(0).getDataFields(); mXmppManager.withMainActivity((ma) -> { ma.mIotSensorsLinearLayout.removeAllViews(); for (IoTDataField field : dataFields) { IotSensorView iotSensorView = new IotSensorView(ma, field.getName(), field.getValueString()); ma.mIotSensorsLinearLayout.addView(iotSensorView); } }); }
private void addChatGuyToContacts() { User userContact = new User(); userContact.setLogin(XMPPUtils.fromJIDToUserName(mChat.getJid())); try { RosterManager.getInstance().addContact(userContact); setMenuChatWithContact(); Toast.makeText(this, String.format(Locale.getDefault(), getString(R.string.user_added_to_contacts), userContact.getLogin()), Toast.LENGTH_SHORT).show(); } catch (SmackException.NotLoggedInException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | XmppStringprepException | SmackException.NoResponseException e) { e.printStackTrace(); } }
private void getSubject(Chat chatRoom) { try { MultiUserChatLight multiUserChatLight = XMPPSession.getInstance().getMUCLightManager().getMultiUserChatLight(JidCreate.from(chatRoom.getJid()).asEntityBareJidIfPossible()); MUCLightRoomConfiguration configuration = multiUserChatLight.getConfiguration(); chatRoom.setSubject(configuration.getSubject()); } catch (XmppStringprepException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) { e.printStackTrace(); } }
public List<String> loadMUCLightMembers(String roomJid) throws XmppStringprepException, SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException { MultiUserChatLightManager multiUserChatLightManager = MultiUserChatLightManager.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); MultiUserChatLight multiUserChatLight = multiUserChatLightManager.getMultiUserChatLight(JidCreate.from(roomJid).asEntityBareJidIfPossible()); HashMap<Jid, MUCLightAffiliation> occupants = multiUserChatLight.getAffiliations(); List<String> jids = new ArrayList<>(); for (Map.Entry<Jid, MUCLightAffiliation> pair : occupants.entrySet()) { Jid jid = pair.getKey(); if (jid != null) { jids.add(jid.toString()); } } return jids; }
public void getXOAUTHTokens() { TBRManager tbrManager = TBRManager.getInstanceFor(getXMPPConnection()); try { Preferences preferences = Preferences.getInstance(); TBRTokens tbrTokens = tbrManager.getTokens(); preferences.setXmppOauthAccessToken(tbrTokens.getAccessToken()); preferences.setXmppOauthRefreshToken(tbrTokens.getRefreshToken()); } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) { e.printStackTrace(); } }