use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatEntityIntegrationTest method mucTestForDiscoveringRoomItems.
/**
* Asserts that a MUC Service returns disco info for a room's items.
*
* <p>From XEP-0045 ยง 6.5:</p>
* <blockquote>
* An entity MAY also query a specific chat room for its associated items. An implementation MAY return a list
* of existing occupants if that information is publicly available, or return no list at all if this information is
* kept private.
* </blockquote>
*
* @throws Exception when errors occur
*/
@SmackIntegrationTest
public void mucTestForDiscoveringRoomItems() throws Exception {
EntityBareJid mucAddress = getRandomRoom("smack-inttest-discoitems");
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));
DiscoverItems roomItems;
try {
roomItems = ServiceDiscoveryManager.getInstanceFor(conTwo).discoverItems(mucAddress);
} finally {
tryDestroy(mucAsSeenByOne);
}
assertEquals(1, roomItems.getItems().size());
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class OmemoService method getMuc.
/**
* Return the joined MUC with EntityBareJid jid, or null if its not a room and/or not joined.
*
* @param connection xmpp connection
* @param jid jid (presumably) of the MUC
* @return MultiUserChat or null if not a MUC.
*/
private static MultiUserChat getMuc(XMPPConnection connection, Jid jid) {
EntityBareJid ebj = jid.asEntityBareJidIfPossible();
if (ebj == null) {
return null;
}
MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection);
Set<EntityBareJid> joinedRooms = mucm.getJoinedRooms();
if (joinedRooms.contains(ebj)) {
return mucm.getMultiUserChat(ebj);
}
return null;
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class OmemoManager method multiUserChatSupportsOmemo.
/**
* Returns true, if the MUC with the EntityBareJid multiUserChat is non-anonymous and members only (prerequisite
* for OMEMO encryption in MUC).
*
* @param multiUserChat MUC
* @return true if chat supports OMEMO
*
* @throws XMPPException.XMPPErrorException if there was an XMPP protocol level error
* @throws SmackException.NotConnectedException if the connection is not connected
* @throws InterruptedException if the thread is interrupted
* @throws SmackException.NoResponseException if the server does not respond
*/
public boolean multiUserChatSupportsOmemo(MultiUserChat multiUserChat) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
EntityBareJid jid = multiUserChat.getRoom();
RoomInfo roomInfo = MultiUserChatManager.getInstanceFor(connection()).getRoomInfo(jid);
return roomInfo.isNonanonymous() && roomInfo.isMembersOnly();
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class IoT method iotScenario.
public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString, String readingThingPassword, IotScenario scenario) throws Exception {
final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString);
final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString);
final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword).setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled).enableDefaultDebugger().build();
final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword).setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled).enableDefaultDebugger().build();
final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration);
final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration);
dataThingConnection.setReplyTimeout(TIMEOUT);
readingThingConnection.setReplyTimeout(TIMEOUT);
dataThingConnection.setUseStreamManagement(false);
readingThingConnection.setUseStreamManagement(false);
try {
dataThingConnection.connect().login();
readingThingConnection.connect().login();
scenario.iotScenario(dataThingConnection, readingThingConnection);
} finally {
dataThingConnection.disconnect();
readingThingConnection.disconnect();
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class OmemoClient method main.
public static void main(String[] args) throws XMPPException, SmackException, IOException, InterruptedException, CorruptedOmemoKeyException {
SmackConfiguration.DEBUG = true;
if (args.length != 2) {
print("Missing arguments: <jid> <password>");
return;
}
SignalOmemoService.acknowledgeLicense();
SignalOmemoService.setup();
SignalOmemoService omemoService = (SignalOmemoService) SignalOmemoService.getInstance();
Path omemoStoreDirectory = Files.createTempDirectory("omemo-store");
omemoService.setOmemoStoreBackend(new SignalCachingOmemoStore(new SignalFileBasedOmemoStore(omemoStoreDirectory.toFile())));
EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked(args[0]);
String password = args[1];
OmemoClient client = new OmemoClient(jid, password);
try {
client.start();
while (true) {
String input = scanner.nextLine();
if (input.startsWith("/quit")) {
break;
}
if (input.isEmpty()) {
continue;
}
client.handleInput(input);
}
} finally {
client.stop();
}
}
Aggregations