use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ConferenceUtils method inviteUsersToRoom.
/**
* Invites users to an existing room.
*
* @param serviceName the service name to use.
* @param roomName the name of the room.
* @param jids a collection of the users to invite.
*/
public static void inviteUsersToRoom(DomainBareJid serviceName, String roomName, Collection<Jid> jids, boolean randomName) {
final LocalPreferences pref = SettingsManager.getLocalPreferences();
boolean useTextField = pref.isUseAdHocRoom();
Collection<BookmarkedConference> rooms = null;
if (!useTextField) {
try {
rooms = retrieveBookmarkedConferences();
} catch (Exception ex) {
Log.error(ex);
}
useTextField = !randomName || (rooms == null || rooms.size() == 0);
}
InvitationDialog inviteDialog = new InvitationDialog(useTextField);
inviteDialog.inviteUsersToRoom(serviceName, rooms, roomName, jids);
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ConferenceUtils method createPrivateConference.
/**
* Creates a private conference.
*
* @param serviceName the service name to use for the private conference.
* @param message the message sent to each individual invitee.
* @param roomName the name of the room to create.
* @param jids a collection of the user JIDs to invite.
* @throws SmackException thrown if an error occurs during room creation.
* @throws InterruptedException
*/
public static void createPrivateConference(DomainBareJid serviceName, String message, String roomName, Collection<EntityBareJid> jids) throws SmackException, InterruptedException {
final EntityBareJid roomJID = JidCreate.entityBareFromUnescapedOrThrowUnchecked(roomName + "@" + serviceName);
final MultiUserChat multiUserChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
final LocalPreferences pref = SettingsManager.getLocalPreferences();
final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(multiUserChat);
try {
// Attempt to create room.
multiUserChat.create(pref.getNickname());
} catch (XMPPException e) {
// TODO: Simply let this method throw XMPPException, instead of wrapping it here.
throw new SmackException.SmackWrappedException(e);
}
try {
// Since this is a private room, make the room not public and set user as owner of the room.
FillableForm submitForm = multiUserChat.getConfigurationForm().getFillableForm();
submitForm.setAnswer("muc#roomconfig_publicroom", false);
submitForm.setAnswer("muc#roomconfig_roomname", roomName);
final List<String> owners = new ArrayList<>();
owners.add(SparkManager.getSessionManager().getUserBareAddress().toString());
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
multiUserChat.sendConfigurationForm(submitForm);
} catch (XMPPException | SmackException e1) {
Log.error("Unable to send conference room chat configuration form.", e1);
}
ChatManager chatManager = SparkManager.getChatManager();
// Check if room already is open
try {
chatManager.getChatContainer().getChatRoom(room.getBareJid());
} catch (ChatRoomNotFoundException e) {
chatManager.getChatContainer().addChatRoom(room);
chatManager.getChatContainer().activateChatRoom(room);
}
for (EntityBareJid jid : jids) {
multiUserChat.invite(jid, message);
room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.waiting.for.user.to.join", jid), ChatManager.NOTIFICATION_COLOR);
}
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class AgentConversations method checkPopup.
private void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
// Check if monitor
try {
AgentConversation item = list.getSelectedValue();
boolean isMonitor = FastpathPlugin.getAgentSession().hasMonitorPrivileges(SparkManager.getConnection());
if (isMonitor) {
JPopupMenu menu = new JPopupMenu();
final String sessionID = item.getSessionID();
Action joinAction = new AbstractAction() {
private static final long serialVersionUID = 8239167390330425891L;
public void actionPerformed(ActionEvent actionEvent) {
// Get Conference
try {
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
List<DomainBareJid> col = multiUserChatManager.getMucServiceDomains();
if (col.size() == 0) {
return;
}
DomainBareJid serviceName = col.iterator().next();
EntityBareJid roomName = JidCreate.entityBareFrom(sessionID + "@" + serviceName);
LocalPreferences pref = SettingsManager.getLocalPreferences();
final Resourcepart nickname = pref.getNickname();
MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
ConferenceUtils.enterRoom(muc, roomName, nickname, null);
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection<Affiliate> owners;
try {
owners = muc.getOwners();
} catch (XMPPException | SmackException e1) {
return;
}
Iterator<Affiliate> iter = owners.iterator();
List<Jid> list = new ArrayList<>();
while (iter.hasNext()) {
Affiliate affilitate = iter.next();
Jid jid = affilitate.getJid();
if (!jid.equals(SparkManager.getSessionManager().getUserBareAddress())) {
list.add(jid);
}
}
if (list.size() > 0) {
FillableForm form = muc.getConfigurationForm().getFillableForm();
List<String> listStrings = JidUtil.toStringList(list);
form.setAnswer("muc#roomconfig_roomowners", listStrings);
// new DataFormDialog(groupChat, form);
muc.sendConfigurationForm(form);
}
}
} catch (Exception e1) {
Log.error(e1);
}
}
};
joinAction.putValue(Action.NAME, FpRes.getString("menuitem.join.chat"));
menu.add(joinAction);
Action monitorAction = new AbstractAction() {
private static final long serialVersionUID = -2072254190661466657L;
public void actionPerformed(ActionEvent actionEvent) {
// Make user an owner.
try {
FastpathPlugin.getAgentSession().makeRoomOwner(SparkManager.getConnection(), sessionID);
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
List<DomainBareJid> col = multiUserChatManager.getMucServiceDomains();
if (col.size() == 0) {
return;
}
DomainBareJid serviceName = col.iterator().next();
EntityBareJid roomName = JidCreate.entityBareFrom(sessionID + "@" + serviceName);
LocalPreferences pref = SettingsManager.getLocalPreferences();
final Resourcepart nickname = pref.getNickname();
MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
ConferenceUtils.enterRoom(muc, roomName, nickname, null);
} catch (XMPPException | SmackException | InterruptedException | XmppStringprepException e1) {
Log.error(e1);
}
}
};
monitorAction.putValue(Action.NAME, FpRes.getString("menuitem.monitor.chat"));
menu.add(monitorAction);
menu.show(list, e.getX(), e.getY());
}
} catch (XMPPException | SmackException | InterruptedException e1) {
Log.error(e1);
}
}
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class JinglePlugin method initialize.
public void initialize() {
// Add Jingle to discovered items list.
SparkManager.addFeature(JINGLE_NAMESPACE);
final LocalPreferences localPref = SettingsManager.getLocalPreferences();
// If there is a server entered in spark.properties use it as fallback
if (!localPref.getStunFallbackHost().equals("")) {
fallbackStunEnabled = true;
}
// Get the default port
stunPort = localPref.getStunFallbackPort();
// Set Jingle Enabled
JingleManager.setJingleServiceEnabled();
JingleManager.setServiceEnabled(SparkManager.getConnection(), true);
// Add to PhoneManager
PhoneManager.getInstance().addPhone(this);
// Adds a tab handler.
SparkManager.getChatManager().addSparkTabHandler(new JingleTabHandler());
final SwingWorker jingleLoadingThread = new SwingWorker() {
public Object construct() {
if (fallbackStunEnabled) {
stunServer = localPref.getStunFallbackHost();
readyToConnect = true;
}
try {
if (STUN.serviceAvailable(SparkManager.getConnection())) {
STUN stun = STUN.getSTUNServer(SparkManager.getConnection());
if (stun != null) {
List<STUN.StunServerAddress> servers = stun.getServers();
if (servers.size() > 0) {
stunServer = servers.get(0).getServer();
stunPort = Integer.parseInt(servers.get(0).getPort());
readyToConnect = true;
}
}
}
if (readyToConnect) {
JingleTransportManager transportManager = new ICETransportManager(SparkManager.getConnection(), stunServer, stunPort);
List<JingleMediaManager> mediaManagers = new ArrayList<>();
// Get the Locator from the Settings
String locator = SettingsManager.getLocalPreferences().getAudioDevice();
mediaManagers.add(new JmfMediaManager(locator, transportManager));
mediaManagers.add(new SpeexMediaManager(transportManager));
// mediaManagers.add(new ScreenShareMediaManager(transportManager));
jingleManager = new JingleManager(SparkManager.getConnection(), mediaManagers);
if (transportManager instanceof BridgedTransportManager) {
jingleManager.addCreationListener((BridgedTransportManager) transportManager);
} else if (transportManager instanceof ICETransportManager) {
jingleManager.addCreationListener((ICETransportManager) transportManager);
}
}
} catch (XMPPException | SmackException e) {
Log.error("Unable to initialize", e);
}
return true;
}
public void finished() {
addListeners();
}
};
jingleLoadingThread.start();
// Add Presence listener for better service discovery.
addPresenceListener();
SparkManager.getConnection().addConnectionListener(this);
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class CurrentActivity method checkPopup.
private void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
// Check if monitor
try {
boolean isMonitor = FastpathPlugin.getAgentSession().hasMonitorPrivileges(SparkManager.getConnection());
if (isMonitor) {
JPopupMenu menu = new JPopupMenu();
int location = list.locationToIndex(e.getPoint());
list.setSelectedIndex(location);
ConversationItem item = list.getSelectedValue();
final String sessionID = item.getSessionID();
Action joinAction = new AbstractAction() {
private static final long serialVersionUID = -3198414924157880065L;
public void actionPerformed(ActionEvent actionEvent) {
// Get Conference
try {
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
List<DomainBareJid> col = multiUserChatManager.getMucServiceDomains();
if (col.size() == 0) {
return;
}
DomainBareJid serviceName = col.iterator().next();
EntityBareJid roomName = JidCreate.entityBareFromOrThrowUnchecked(sessionID + "@" + serviceName);
final LocalPreferences pref = SettingsManager.getLocalPreferences();
final Resourcepart nickname = pref.getNickname();
MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
ConferenceUtils.enterRoom(muc, roomName, nickname, null);
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection<Affiliate> owners;
try {
owners = muc.getOwners();
} catch (XMPPException | SmackException e1) {
return;
}
Iterator<Affiliate> iter = owners.iterator();
List<Jid> list = new ArrayList<>();
while (iter.hasNext()) {
Affiliate affiliate = iter.next();
Jid jid = affiliate.getJid();
if (!jid.equals(SparkManager.getSessionManager().getUserBareAddress())) {
list.add(jid);
}
}
if (list.size() > 0) {
FillableForm form = muc.getConfigurationForm().getFillableForm();
List<String> jidStrings = new ArrayList<>(list.size());
JidUtil.toStrings(list, jidStrings);
form.setAnswer("muc#roomconfig_roomowners", jidStrings);
// new DataFormDialog(groupChat, form);
muc.sendConfigurationForm(form);
}
}
} catch (Exception e1) {
Log.error(e1);
}
}
};
joinAction.putValue(Action.NAME, FpRes.getString("menuitem.join.chat"));
menu.add(joinAction);
Action monitorAction = new AbstractAction() {
private static final long serialVersionUID = 7292337790553806820L;
public void actionPerformed(ActionEvent actionEvent) {
// Make user an owner.
try {
FastpathPlugin.getAgentSession().makeRoomOwner(SparkManager.getConnection(), sessionID);
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
List<DomainBareJid> col = manager.getMucServiceDomains();
if (col.size() == 0) {
return;
}
DomainBareJid serviceName = col.iterator().next();
EntityBareJid roomName = JidCreate.entityBareFromOrThrowUnchecked(sessionID + "@" + serviceName);
LocalPreferences pref = SettingsManager.getLocalPreferences();
final Resourcepart nickname = pref.getNickname();
MultiUserChat muc = manager.getMultiUserChat(roomName);
ConferenceUtils.enterRoom(muc, roomName, nickname, null);
} catch (XMPPException | SmackException | InterruptedException e1) {
Log.error(e1);
}
}
};
monitorAction.putValue(Action.NAME, FpRes.getString("menuitem.monitor.chat"));
menu.add(monitorAction);
menu.show(list, e.getX(), e.getY());
}
} catch (XMPPException | SmackException | InterruptedException e1) {
Log.error(e1);
}
}
}
Aggregations