Search in sources :

Example 11 with CallParticipant

use of com.sun.voip.CallParticipant in project Openfire by igniterealtime.

the class CallHandler method setRemoteMediaInfo.

public static void setRemoteMediaInfo(String callId, String sdp) throws ParseException {
    synchronized (activeCalls) {
        for (int i = 0; i < activeCalls.size(); i++) {
            CallHandler call = (CallHandler) activeCalls.elementAt(i);
            CallParticipant cp = call.getCallParticipant();
            if (match(cp, callId)) {
                call.setRemoteMediaInfo(sdp);
                return;
            }
        }
    }
    throw new ParseException("Invalid callId: " + callId, 0);
}
Also used : CallParticipant(com.sun.voip.CallParticipant) ParseException(java.text.ParseException)

Example 12 with CallParticipant

use of com.sun.voip.CallParticipant in project Openfire by igniterealtime.

the class SipServer method processRequest.

/**
     * Process requests received.  Forwards the request to
     * the appropriate SipListener.
     * @param requestEvent the request event
     */
public void processRequest(RequestEvent requestEvent) {
    try {
        Request request = requestEvent.getRequest();
        CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
        String sipCallId = callIdHeader.getCallId();
        SipListener sipListener = findSipListener(requestEvent);
        /*
	     * If there's an existing listener pass the request there.
	     */
        if (sipListener != null) {
            if (request.getMethod().equals(Request.INVITE)) {
                duplicateInvite(request);
                return;
            }
            sipListener.processRequest(requestEvent);
            return;
        } else {
            if (request.getMethod().equals(Request.REGISTER)) {
                handleRegister(request, requestEvent);
            } else if (request.getMethod().equals(Request.OPTIONS)) {
                Response res = messageFactory.createResponse(Response.OK, request);
                sipProvider.sendResponse(res);
                return;
            } else if (!request.getMethod().equals(Request.INVITE)) {
                Logger.writeFile("sipListener could not be found for " + sipCallId + " " + request.getMethod() + ".  Ignoring");
                return;
            }
        }
        /*
	     * An INVITE for an incoming call goes to the IncomingCallHandler.
	     */
        if (request.getMethod().equals(Request.INVITE)) {
            if (SipIncomingCallAgent.addSipCallId(sipCallId) == false) {
                FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
                ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
                String from = fromHeader.getAddress().toString();
                String to = toHeader.getAddress().toString();
                Logger.writeFile("SipServer:  duplicate INVITE from " + from + " to " + to);
                return;
            }
            CallParticipant cp = new CallParticipant();
            String s = SipUtil.getCallIdFromSdp(request);
            if (s != null) {
                if (Logger.logLevel >= Logger.LOG_MOREINFO) {
                    Logger.println("Using callId from SDP in INVITE: " + s);
                }
                cp.setCallId(s);
            }
            s = SipUtil.getConferenceIdFromSdp(request);
            if (s != null) {
                String[] tokens = s.split(":");
                cp.setConferenceId(tokens[0].trim());
                if (tokens.length > 1) {
                    cp.setMediaPreference(tokens[1]);
                }
                if (tokens.length > 2) {
                    cp.setConferenceDisplayName(tokens[2]);
                }
            }
            if (SipUtil.getUserNameFromSdp(request) != null) {
                cp.setName(SipUtil.getUserNameFromSdp(request));
            } else {
                cp.setName(SipUtil.getFromName(requestEvent));
            }
            cp.setDistributedBridge(SipUtil.getDistributedBridgeFromSdp(request));
            cp.setPhoneNumber(SipUtil.getFromPhoneNumber(requestEvent));
            cp.setToPhoneNumber(SipUtil.getToPhoneNumber(requestEvent));
            new IncomingCallHandler(cp, requestEvent);
            return;
        }
    } catch (Exception e) {
        /*
	     * FIXME: if any exception happens at this stage,
             * we should send back a 500 Internal Server Error
             */
        Logger.exception("processRequest", e);
        e.printStackTrace();
    }
}
Also used : CallParticipant(com.sun.voip.CallParticipant) UnknownHostException(java.net.UnknownHostException) ParseException(java.text.ParseException)

Example 13 with CallParticipant

use of com.sun.voip.CallParticipant in project Openfire by igniterealtime.

the class NSIncomingCallAgent method initiateCall.

public void initiateCall() {
    setState(CallState.INVITED);
    CallParticipant cp = callHandler.getCallParticipant();
    String remoteMediaInfo = cp.getRemoteMediaInfo();
    if (Logger.logLevel >= Logger.LOG_MOREINFO) {
        Logger.println("Call " + cp + ":   NSIncomingCallAgent remoteMediaInfo " + remoteMediaInfo);
    }
    String[] tokens = remoteMediaInfo.split("\\+");
    /*
		 * The remote media info is the SDP info but instead of
		 * new line as the separator, it has "+".
		 * Reformat the SDP with \r\n.
		 */
    String sdp = "";
    for (int i = 0; i < tokens.length; i++) {
        sdp += tokens[i] + "\r\n";
    }
    if (Logger.logLevel >= Logger.LOG_MOREINFO) {
        Logger.println("Call " + cp + ":  NSIncomingCallAgent Sdp\n" + sdp);
    }
    SdpInfo sdpInfo = null;
    try {
        sdpInfo = sipUtil.getSdpInfo(sdp, true);
        String remoteHost = sdpInfo.getRemoteHost();
        int remotePort = sdpInfo.getRemotePort();
        Logger.println("Call " + cp + ":  NSIncomingCallAgent:  remote socket " + remoteHost + " " + remotePort + " mediaInfo " + sdpInfo.getMediaInfo());
        InetSocketAddress isa = new InetSocketAddress(remoteHost, remotePort);
        setEndpointAddress(isa, sdpInfo.getMediaInfo().getPayload(), sdpInfo.getTransmitMediaInfo().getPayload(), sdpInfo.getTelephoneEventPayload());
    } catch (ParseException e) {
        Logger.println("Call " + cp + ":  NSIncomingCallAgent couldn't parse sdp");
        cancelRequest("NSIncomingCallAgent couldn't parse sdp");
        return;
    }
    setState(CallState.ANSWERED);
    setState(CallState.ESTABLISHED);
}
Also used : CallParticipant(com.sun.voip.CallParticipant) InetSocketAddress(java.net.InetSocketAddress) SdpInfo(com.sun.voip.SdpInfo) ParseException(java.text.ParseException)

Example 14 with CallParticipant

use of com.sun.voip.CallParticipant in project Openfire by igniterealtime.

the class ConferenceReceiver method addMember.

public void addMember(ConferenceMember member) throws IOException {
    CallParticipant cp = member.getCallParticipant();
    if (loneReceiverChannel != null && cp.getPhoneNumber().indexOf("@") >= 0) {
        return;
    }
    synchronized (membersToRegister) {
        if (selector == null) {
            return;
        }
        membersToRegister.add(member);
        Logger.writeFile("ConferenceReceiver Adding member to register " + member + " size " + membersToRegister.size());
        selector.wakeup();
    }
}
Also used : CallParticipant(com.sun.voip.CallParticipant)

Example 15 with CallParticipant

use of com.sun.voip.CallParticipant in project Openfire by igniterealtime.

the class IncomingCallHandler method transferCall.

public static ConferenceManager transferCall(CallHandler callHandler, String conferenceId) throws IOException {
    /*
	 * Get current conference manager and member.
	 */
    ConferenceMember member = callHandler.getMember();
    ConferenceManager conferenceManager = callHandler.getConferenceManager();
    ConferenceManager newConferenceManager = ConferenceManager.getConference(conferenceId);
    if (newConferenceManager == null) {
        throw new NoSuchElementException("Can't create conference " + conferenceId);
    }
    CallParticipant cp = callHandler.getCallParticipant();
    //
    // XXX maybe we should have yet more commands to specify
    // the treatments for incoming calls.
    // Jon suggested a mode for setting up incoming call parameters
    // similar to how call setup is done for outgoing calls.
    //
    //cp.setConferenceJoinTreatment("joinCLICK.au");
    //cp.setConferenceLeaveTreatment("leaveCLICK.au");
    cp.setConferenceId(conferenceId);
    conferenceManager.transferMember(newConferenceManager, member);
    callHandler.setConferenceManager(newConferenceManager);
    try {
        newConferenceManager.addTreatment("joinCLICK.au");
    } catch (IOException e) {
        Logger.println("Call " + cp + " unable to play joinCLICK.au " + e.getMessage());
    }
    CallEvent event = new CallEvent(CallEvent.CALL_TRANSFERRED);
    event.setInfo("ConferenceReceiverPort='" + callHandler.getReceiveAddress().getPort() + "'" + " ConferencePayload='" + newConferenceManager.getMediaInfo().getPayload() + "'" + " BridgeIPAddress='" + Bridge.getPrivateHost() + "'");
    callHandler.sendCallEventNotification(event);
    // now, we monitor direct conferences as we know conf
    Application.notifyConferenceMonitors(event);
    return newConferenceManager;
}
Also used : CallParticipant(com.sun.voip.CallParticipant) CallEvent(com.sun.voip.CallEvent) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

CallParticipant (com.sun.voip.CallParticipant)25 ParseException (java.text.ParseException)4 CallEvent (com.sun.voip.CallEvent)2 Vector (java.util.Vector)2 CallEventListener (com.sun.voip.CallEventListener)1 CallState (com.sun.voip.CallState)1 MediaInfo (com.sun.voip.MediaInfo)1 SdpInfo (com.sun.voip.SdpInfo)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1