Search in sources :

Example 6 with CallParticipant

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

the class CallMigrator method run.

/*
     * Migrate a call.  Set up the new call, join the conference and
     * terminate the original call.
     */
public void run() {
    // call to migrate
    String callId = cp.getCallId();
    CallHandler callHandler = CallHandler.findMigratingCall(callId);
    if (callHandler != null) {
        /*
	     * Call migration is in progess.
	     * Cancel previous migration request.
	     */
        callHandler.cancelRequest("new migration requested");
    }
    CallHandler previousCall = CallHandler.findCall(callId);
    if (previousCall == null) {
        if (cp.getConferenceId() == null) {
            Logger.println("Call migrator can't find call Id " + callId);
            return;
        }
        /*
	     * Treat it like a new call
	     */
        migrateWithNoPreviousCall(requestHandler, cp);
        return;
    }
    if (false) {
        if (previousCall.isCallEstablished() == false) {
            Logger.println("Call migrator can't migrate call which is not established");
            return;
        }
    }
    CallParticipant previousCp = previousCall.getCallParticipant();
    String previousEndTreatment = previousCp.getCallEndTreatment();
    String previousLeaveTreatment = previousCp.getConferenceLeaveTreatment();
    previousCp.setCallEndTreatment(null);
    previousCp.setConferenceLeaveTreatment(null);
    // preserve mute
    cp.setMuted(previousCp.isMuted());
    Logger.println("Call migrating " + previousCp + " preserving mute " + previousCp.isMuted());
    if (cp.getConferenceId() == null) {
        cp.setConferenceId(previousCp.getConferenceId());
    }
    if (cp.getName() == null) {
        cp.setName(previousCp.getName());
    }
    /*
	 * SecondPartyNumber is the new number to call.
	 * If it starts with "Id-", it's a callId of
	 * a call already in progress.  Otherwise, it's a phone number to call.
	 */
    String secondParty = cp.getSecondPartyNumber();
    if (secondParty.indexOf("Id-") == 0) {
        callHandler = CallHandler.findCall(secondParty.substring(3));
        if (callHandler == null) {
            Logger.println("Can't find existing call to " + secondParty);
            //Logger.logLevel = logLevel;
            return;
        }
        cp = callHandler.getCallParticipant();
        cp.setCallId(previousCp.getCallId());
    } else {
        /*
	     * Invite the secondParty if call is not already setup.
	     * After the party answers terminate the previous call.
	     */
        cp.setPhoneNumber(cp.getSecondPartyNumber());
        cp.setConferenceJoinTreatment(null);
        /*
	     * Use the request handler from the previous call (if there
	     * is one) so that status changes will be sent to the same socket
	     * as the previous call.  This will make the migration seemless.
	     */
        CallEventListener previousCallEventListener = (CallEventListener) previousCall.getRequestHandler();
        if (previousCallEventListener != null) {
            requestHandler = previousCallEventListener;
        }
        /*
	     * Previous call is migrating.  It will probably be
	     * common for someone to hangup their cell phone before
	     * answering the new call.  In this case we need to
	     * suppress status from the previous call.
	     * However, if the previous call ends and then migration fails,
	     * we need to send call ending status back.
	     */
        previousCall.suppressStatus = true;
        OutgoingCallHandler newCall = new OutgoingCallHandler(requestHandler, cp);
        previousCall.getMember().migrating();
        synchronized (this) {
            newCall.suppressStatus = true;
            // call new party
            newCall.start();
            /*
	         * Wait for call to be established
	         */
            if (newCall.waitForCallToBeEstablished() == false) {
                String reason = newCall.getReasonCallEnded();
                Logger.println("Migration failed: " + reason);
                previousCp.setConferenceLeaveTreatment(previousLeaveTreatment);
                previousCp.setCallEndTreatment(previousEndTreatment);
                CallEvent callEvent = new CallEvent(CallEvent.STATE_CHANGED);
                callEvent.setCallState(new CallState(CallState.ENDED));
                callEvent.setInfo("Migration failed: " + reason);
                newCall.suppressStatus = false;
                newCall.sendCallEventNotification(callEvent);
                previousCall.suppressStatus = false;
                if (!previousCall.isCallEstablished()) {
                    previousCall.sendCallEventNotification(callEvent);
                }
                //Logger.logLevel = logLevel;
                return;
            }
            newCall.suppressStatus = false;
        }
        if (previousCall.isCallEstablished() == true) {
            Logger.println("migrate mix descriptors for " + previousCall);
            newCall.getMember().migrate(previousCall.getMember());
        } else {
            Logger.println("migrate:  previous call is not established " + previousCall);
        }
    }
    Logger.println("Call " + previousCp + " migrated to " + cp.getPhoneNumber());
    previousCall.suppressStatus = false;
    // call is no longer migrating
    cp.setMigrateCall(false);
    /*
	 * If the previous call ended early, we need to re-add
	 * it as a call status listener so that it will get the MIGRATED status
	 */
    if (!previousCall.isCallEstablished()) {
        previousCall.addCallEventListener(previousCall.getRequestHandler());
    }
    CallEvent callEvent = new CallEvent(CallEvent.MIGRATED);
    callEvent.setInfo(previousCp + " migrated to " + cp);
    previousCall.sendCallEventNotification(callEvent);
    previousCall.suppressStatus = true;
    /*
	 * Suppress conference leave treatment.  No other calls should
	 * know that this call migrated.
	 */
    previousCp.setCallEndTreatment(null);
    previousCp.setConferenceLeaveTreatment(null);
    previousCall.cancelRequest("Call " + previousCp + " migrated to " + cp.getPhoneNumber());
}
Also used : CallEventListener(com.sun.voip.CallEventListener) CallParticipant(com.sun.voip.CallParticipant) CallEvent(com.sun.voip.CallEvent) CallState(com.sun.voip.CallState)

Example 7 with CallParticipant

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

the class CallHandler method setVoiceDetectionWhileMuted.

/**
     * Set flag to do voice detection while muted
     */
public static void setVoiceDetectionWhileMuted(String callId, boolean voiceDetectionWhileMuted) {
    if (callId == null) {
        return;
    }
    synchronized (activeCalls) {
        for (int i = 0; i < activeCalls.size(); i++) {
            CallHandler call = (CallHandler) activeCalls.elementAt(i);
            CallParticipant cp = call.getCallParticipant();
            if (match(cp, callId)) {
                cp.setVoiceDetectionWhileMuted(voiceDetectionWhileMuted);
                if (Logger.logLevel >= Logger.LOG_DETAIL) {
                    Logger.println(cp.getCallId() + " voice detection while muted is " + voiceDetectionWhileMuted);
                }
            }
        }
    }
}
Also used : CallParticipant(com.sun.voip.CallParticipant)

Example 8 with CallParticipant

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

the class CallHandler method setConferenceSilenced.

/**
     * Mute or unmute the main conference from a particular call.
     */
public static void setConferenceSilenced(String callId, boolean isSilenced) {
    synchronized (activeCalls) {
        for (int i = 0; i < activeCalls.size(); i++) {
            CallHandler call = (CallHandler) activeCalls.elementAt(i);
            CallParticipant cp = call.getCallParticipant();
            if (match(cp, callId)) {
                if (Logger.logLevel >= Logger.LOG_DETAIL) {
                    String s = "";
                    if (isSilenced == false) {
                        s = "un";
                    }
                    Logger.println(cp.getCallId() + ":  silenceMainonference " + s + "muted");
                }
                ConferenceMember member = call.getMember();
                if (member != null) {
                    member.setConferenceSilenced(isSilenced);
                }
            }
        }
    }
}
Also used : CallParticipant(com.sun.voip.CallParticipant)

Example 9 with CallParticipant

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

the class CallHandler method findMigratingCall.

/**
     * Find the new call of a call migration.
     */
public static CallHandler findMigratingCall(String callId) {
    synchronized (activeCalls) {
        for (int i = 0; i < activeCalls.size(); i++) {
            CallHandler call = (CallHandler) activeCalls.elementAt(i);
            CallParticipant cp = call.getCallParticipant();
            if (match(cp, callId) && cp.migrateCall()) {
                if (Logger.logLevel >= Logger.LOG_DETAIL) {
                    Logger.println("findMigratingCall:  found " + callId);
                }
                return call;
            }
        }
    }
    return null;
}
Also used : CallParticipant(com.sun.voip.CallParticipant)

Example 10 with CallParticipant

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

the class CallHandler method findCall.

/**
     * Find a call by callId.
     *
     * Calls are kept in the activeCalls list and uniquely identified
     * by <callId>::<name>@<phoneNumber> for a phone call and
     *
     * This method searches for a call with the callId.
     */
public static CallHandler findCall(String callId) {
    if (Logger.logLevel >= Logger.LOG_DETAIL) {
        Logger.println("findCall:  looking for " + callId + ", " + activeCalls.size() + " active calls");
    }
    synchronized (activeCalls) {
        for (int i = 0; i < activeCalls.size(); i++) {
            CallHandler call = (CallHandler) activeCalls.elementAt(i);
            CallParticipant cp = call.getCallParticipant();
            if (Logger.logLevel >= Logger.LOG_DETAIL) {
                Logger.println("findCall:  looking for " + callId + " got " + cp.getCallId());
            }
            if (match(cp, callId)) {
                if (Logger.logLevel >= Logger.LOG_DETAIL) {
                    Logger.println("findCall:  found " + callId);
                }
                return call;
            }
        }
    }
    return null;
}
Also used : CallParticipant(com.sun.voip.CallParticipant)

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