Search in sources :

Example 46 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class RayoComponent method notifyConferenceMonitors.

public void notifyConferenceMonitors(ConferenceEvent conferenceEvent) {
    Log.info("RayoComponent notifyConferenceMonitors " + conferenceEvent.toString());
    if (defaultIncomingConferenceId.equals(conferenceEvent.getConferenceId()))
        return;
    ConferenceManager conferenceManager = null;
    try {
        if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT) || conferenceEvent.equals(ConferenceEvent.MEMBER_JOINED)) {
            Log.info("RayoComponent notifyConferenceMonitors looking for call " + conferenceEvent.getCallId() + " " + conferenceEvent.getMemberCount());
            try {
                conferenceManager = ConferenceManager.findConferenceManager(conferenceEvent.getConferenceId());
            } catch (Exception e) {
            }
            if (conferenceManager != null) {
                String groupName = conferenceManager.getGroupName();
                String callId = conferenceManager.getCallId();
                // special case of SIP incoming
                if (callId == null)
                    callId = conferenceEvent.getConferenceId();
                CallHandler farParty = CallHandler.findCall(callId);
                CallHandler callHandler = CallHandler.findCall(conferenceEvent.getCallId());
                if (callHandler != null) {
                    Log.info("RayoComponent notifyConferenceMonitors found call handler " + callHandler + " " + farParty);
                    CallParticipant callParticipant = callHandler.getCallParticipant();
                    ArrayList memberList = conferenceManager.getMemberList();
                    if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT) && callId.equals(conferenceEvent.getCallId())) {
                        if (// far party left
                        farParty != null && farParty.getCallParticipant().isHeld() == false) {
                            synchronized (memberList) {
                                for (int i = 0; i < memberList.size(); i++) {
                                    CallHandler participant = ((ConferenceMember) memberList.get(i)).getCallHandler();
                                    participant.cancelRequest("Far Party has left");
                                }
                            }
                        }
                    }
                    int memberCount = memberList.size();
                    if (groupName == null) {
                        if (isMixerMuc(conferenceEvent.getConferenceId())) {
                            MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService("conference").getChatRoom(conferenceEvent.getConferenceId());
                            Log.info("RayoComponent notifyConferenceMonitors routing to room occupants of " + conferenceEvent.getConferenceId());
                            for (MUCRole role : room.getOccupants()) {
                                String jid = role.getUserAddress().toString();
                                Log.info("RayoComponent notifyConferenceMonitors routing to room occupant " + jid);
                                Presence presence = new Presence();
                                presence.setFrom(conferenceEvent.getCallId() + "@" + getDomain());
                                presence.setTo(jid);
                                if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT)) {
                                    UnjoinedEvent event = new UnjoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
                                    presence.getElement().add(rayoProvider.toXML(event));
                                } else {
                                    JoinedEvent event = new JoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
                                    presence.getElement().add(rayoProvider.toXML(event));
                                }
                                sendPacket(presence);
                            }
                        } else {
                            Log.info("RayoComponent notifyConferenceMonitors routing to owner " + callParticipant.getCallOwner() + " " + memberCount);
                            routeJoinEvent(callParticipant.getCallOwner(), callParticipant, conferenceEvent, memberCount, groupName, callId, farParty, conferenceManager);
                        }
                    } else {
                        Group group = GroupManager.getInstance().getGroup(groupName);
                        for (JID memberJID : group.getMembers()) {
                            Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(memberJID.getNode());
                            for (ClientSession session : sessions) {
                                routeJoinEvent(session.getAddress().toString(), callParticipant, conferenceEvent, memberCount, groupName, callId, farParty, conferenceManager);
                            }
                        }
                    }
                    if (memberCount == 0 && conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT)) {
                        conferenceManager.recordConference(false, null, null);
                        conferenceManager.endConference(conferenceEvent.getConferenceId());
                        CallParticipant heldCall = conferenceManager.getHeldCall();
                        if (heldCall != null) {
                            JID target = getJID(heldCall.getCallId());
                            if (target != null) {
                                Presence presence = new Presence();
                                presence.setFrom(callId + "@" + getDomain());
                                presence.setTo(target);
                                presence.getElement().add(rayoProvider.toXML(new EndEvent(null, EndEvent.Reason.valueOf("HANGUP"), callParticipant.getHeaders())));
                                sendPacket(presence);
                            }
                        }
                    } else if (memberCount == 2) {
                        // reset after informing on redirect
                        conferenceManager.setTransferCall(false);
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.error("RayoComponent Error in notifyConferenceMonitors " + e);
        e.printStackTrace();
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) ComponentException(org.xmpp.component.ComponentException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) ParseException(java.text.ParseException) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Example 47 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class RayoComponent method findUser.

private JID findUser(String username) {
    Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
    JID foundUser = null;
    for (ClientSession session : sessions) {
        try {
            String userId = session.getAddress().getNode();
            if (username.equals(userId)) {
                Log.info("Incoming SIP, findUser " + session.getAddress());
                foundUser = session.getAddress();
                break;
            }
        } catch (Exception e) {
        }
    }
    return foundUser;
}
Also used : JID(org.xmpp.packet.JID) ClientSession(org.jivesoftware.openfire.session.ClientSession) ComponentException(org.xmpp.component.ComponentException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) ParseException(java.text.ParseException)

Example 48 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class SessionController method getUserSessions.

/**
	 * Gets the user sessions.
	 *
	 * @param username the username
	 * @return the user sessions
	 * @throws ServiceException the service exception
	 */
public SessionEntities getUserSessions(String username) throws ServiceException {
    Collection<ClientSession> clientSessions = SessionManager.getInstance().getSessions(username);
    SessionEntities sessionEntities = convertToSessionEntities(clientSessions);
    return sessionEntities;
}
Also used : LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) SessionEntities(org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)

Example 49 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class UserServiceController method disableUser.

/**
	 * Disable user.
	 *
	 * @param username
	 *            the username
	 * @throws ServiceException
	 *             the service exception
	 */
public void disableUser(String username) throws ServiceException {
    getAndCheckUser(username);
    lockOutManager.disableAccount(username, null, null);
    if (lockOutManager.isAccountDisabled(username)) {
        final StreamError error = new StreamError(StreamError.Condition.not_authorized);
        for (ClientSession sess : SessionManager.getInstance().getSessions(username)) {
            sess.deliverRawText(error.toXML());
            sess.close();
        }
    }
}
Also used : StreamError(org.xmpp.packet.StreamError) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Aggregations

ClientSession (org.jivesoftware.openfire.session.ClientSession)49 JID (org.xmpp.packet.JID)15 Element (org.dom4j.Element)14 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)14 IQ (org.xmpp.packet.IQ)12 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)8 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)7 PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)7 StreamError (org.xmpp.packet.StreamError)7 DataForm (org.xmpp.forms.DataForm)6 FormField (org.xmpp.forms.FormField)6 Message (org.xmpp.packet.Message)6 Presence (org.xmpp.packet.Presence)6 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)5 StringprepException (gnu.inet.encoding.StringprepException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 SessionEntities (org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)3 SQLException (java.sql.SQLException)2