Search in sources :

Example 51 with LocalPreferences

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);
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) SmackException(org.jivesoftware.smack.SmackException) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 52 with LocalPreferences

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);
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) SmackException(org.jivesoftware.smack.SmackException) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid) ChatManager(org.jivesoftware.spark.ChatManager) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager)

Example 53 with LocalPreferences

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);
        }
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Affiliate(org.jivesoftware.smackx.muc.Affiliate) Resourcepart(org.jxmpp.jid.parts.Resourcepart) AbstractAction(javax.swing.AbstractAction) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) SmackException(org.jivesoftware.smack.SmackException) JPopupMenu(javax.swing.JPopupMenu) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

Example 54 with LocalPreferences

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);
}
Also used : JmfMediaManager(org.jivesoftware.smackx.jingleold.mediaimpl.jmf.JmfMediaManager) ICETransportManager(org.jivesoftware.smackx.jingleold.nat.ICETransportManager) JingleMediaManager(org.jivesoftware.smackx.jingleold.media.JingleMediaManager) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JingleManager(org.jivesoftware.smackx.jingleold.JingleManager) SpeexMediaManager(org.jivesoftware.smackx.jingleold.mediaimpl.jspeex.SpeexMediaManager) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) STUN(org.jivesoftware.smackx.jingleold.nat.STUN) JingleTransportManager(org.jivesoftware.smackx.jingleold.nat.JingleTransportManager) BridgedTransportManager(org.jivesoftware.smackx.jingleold.nat.BridgedTransportManager)

Example 55 with LocalPreferences

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);
        }
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) Affiliate(org.jivesoftware.smackx.muc.Affiliate) Resourcepart(org.jxmpp.jid.parts.Resourcepart) AbstractAction(javax.swing.AbstractAction) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) SmackException(org.jivesoftware.smack.SmackException) JPopupMenu(javax.swing.JPopupMenu) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)55 SmackException (org.jivesoftware.smack.SmackException)12 XMPPException (org.jivesoftware.smack.XMPPException)11 SwingWorker (org.jivesoftware.spark.util.SwingWorker)9 EntityBareJid (org.jxmpp.jid.EntityBareJid)9 File (java.io.File)8 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)8 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)7 Message (org.jivesoftware.smack.packet.Message)6 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 ActionEvent (java.awt.event.ActionEvent)5 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 ChatManager (org.jivesoftware.spark.ChatManager)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 Insets (java.awt.Insets)3 IOException (java.io.IOException)3 KeyManagementException (java.security.KeyManagementException)3 AbstractAction (javax.swing.AbstractAction)3