Search in sources :

Example 11 with CallEvent

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

the class CallHandler method speakingChanged.

public void speakingChanged(boolean isSpeaking) {
    if (isSpeaking) {
        totalSpeaking++;
        CallEvent callEvent = new CallEvent(CallEvent.STARTED_SPEAKING);
        callEvent.setStartedSpeaking();
        sendCallEventNotification(callEvent);
    } else {
        totalSpeaking--;
        CallEvent callEvent = new CallEvent(CallEvent.STOPPED_SPEAKING);
        callEvent.setStoppedSpeaking();
        sendCallEventNotification(callEvent);
    }
}
Also used : CallEvent(com.sun.voip.CallEvent)

Example 12 with CallEvent

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

the class SipTPCCallAgent method processResponse.

public synchronized void processResponse(ResponseEvent responseReceivedEvent) {
    try {
        Response response = (Response) responseReceivedEvent.getResponse();
        ClientTransaction clientTransaction = responseReceivedEvent.getClientTransaction();
        int statusCode = response.getStatusCode();
        FromHeader fromHeader = (FromHeader) response.getHeader(FromHeader.NAME);
        String displayName = fromHeader.getAddress().getDisplayName();
        if (Logger.logLevel >= Logger.LOG_SIP) {
            Logger.println("Response:  statusCode " + statusCode + " state " + getCallState() + " fromHeader " + displayName + " call participant " + cp.getName());
        }
        if (reasonCallTerminated != null) {
            /*
		 * Ignore OK and Request Terminated.
		 * XXX what's the symbol for 487?
		 */
            if (statusCode != Response.OK && statusCode != 487) {
                if (Logger.logLevel >= Logger.LOG_SIP) {
                    Logger.println("Call " + cp + ":  request cancelled, ignoring response");
                }
            }
            CallIdHeader callIdHeader = (CallIdHeader) response.getHeader("Call-Id");
            String sipCallId = callIdHeader.getCallId();
            sipServerCallback.removeSipListener(sipCallId);
            return;
        }
        /*
	     * Some type of global failure that prevents the
             * CallParticipant from being contacted, report failure.
             */
        if (forceGatewayError) {
            statusCode = 500;
            forceGatewayError = false;
        }
        if (statusCode >= 500 && getState() == CallState.INVITED) {
            Logger.error("Call " + cp + " gateway error:  " + statusCode + " " + response.getReasonPhrase());
            cancelRequest("gateway error: " + statusCode + " " + response.getReasonPhrase());
            return;
        } else if (statusCode == Response.PROXY_AUTHENTICATION_REQUIRED || statusCode == Response.UNAUTHORIZED) {
            if (cp.getProxyCredentials() != null) {
                try {
                    SipServer.handleChallenge(response, clientTransaction, cp.getProxyCredentials()).sendRequest();
                } catch (Exception e) {
                    Logger.println("Proxy authentification failed  " + e);
                }
            }
            return;
        } else if (statusCode >= 400) {
            // if we get a busy or an unknown error, play busy.
            Logger.println("Call " + cp + " got status code :" + statusCode);
            cp.setCallEndTreatment(null);
            cp.setConferenceJoinTreatment(null);
            cp.setConferenceLeaveTreatment(null);
            if (statusCode == Response.BUSY_HERE) {
                try {
                    if (busyTreatment != null) {
                        addTreatment(busyTreatment);
                    //busyTreatment.waitForTreatment();
                    } else {
                        Logger.println("Unable to play busy treatment!!!");
                    }
                } catch (Exception e) {
                    Logger.error("can't start busy treatment!" + sdpBody);
                }
                CallEvent callEvent = new CallEvent(CallEvent.BUSY_HERE);
                callEvent.setInfo(response.getReasonPhrase());
                sendCallEventNotification(callEvent);
            }
            //sipUtil.sendBye(clientTransaction);
            cancelRequest(response.getReasonPhrase());
            return;
        }
        /* state machine */
        switch(getState()) {
            /*
	     * CallParticipant picked up, send treatment if any,
	     * and wait for it to finish.
	     */
            case CallState.INVITED:
                if (rejectCall) {
                    Logger.error("Call " + cp + " gateway error:  " + statusCode + " " + response.getReasonPhrase());
                    cancelRequest("gateway error: " + statusCode + " " + response.getReasonPhrase());
                    return;
                }
                handleCallParticipantInvited(response, clientTransaction);
                break;
            /*
	     * Call established, the ACK needs to be resent.
	     * According to Ranga, this is done by the NIST SIP Stack.
	     */
            case CallState.ESTABLISHED:
                if (statusCode == Response.OK) {
                    gotOk = true;
                    Logger.writeFile("Call " + cp + " Got OK, ESTABLISHED");
                    if (ackSent == false) {
                        sipUtil.sendAck(clientTransaction);
                        ackSent = true;
                    }
                }
                break;
            case CallState.ENDED:
                // ignore the response
                break;
            default:
                Logger.error("Process Response bad state " + getState() + "\n" + response);
        }
    } catch (SipException e) {
        Logger.exception("Call " + cp + " SIP Stack error ", e);
        cancelRequest("processResponse:  SIP Stack error " + e.getMessage());
    } catch (Exception e) {
        Logger.exception("processResponse:  " + cp, e);
        cancelRequest("processResponse:  SIP Stack error " + e.getMessage());
    }
}
Also used : CallEvent(com.sun.voip.CallEvent) IOException(java.io.IOException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException)

Example 13 with CallEvent

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

the class OutgoingCallHandler method placeCall.

private void placeCall() {
    String protocol = Bridge.getDefaultProtocol();
    if (cp.getProtocol() != null) {
        protocol = cp.getProtocol();
    }
    if (protocol.equalsIgnoreCase("SIP")) {
        csa = new SipTPCCallAgent(this);
    } else if (protocol.equalsIgnoreCase("NS")) {
        csa = new NSOutgoingCallAgent(this);
    } else if (protocol.equalsIgnoreCase("WebRtc")) {
        csa = new WebRtcCallAgent(this);
    } else if (protocol.equalsIgnoreCase("Speaker")) {
        csa = new SpeakerCallAgent(this);
    } else if (protocol.equalsIgnoreCase("Rtmfp")) {
        csa = new RtmfpCallAgent(this);
    } else {
        //csa = new H323TPCCallAgent(this);
        reasonCallEnded = CallEvent.getEventString(CallEvent.H323_NOT_IMPLEMENTED);
        sendCallEventNotification(new CallEvent(CallEvent.H323_NOT_IMPLEMENTED));
        Logger.println("Call " + cp + ":  " + reasonCallEnded);
        return;
    }
    try {
        csa.initiateCall();
        synchronized (callInitiatedLock) {
            callInitiatedLock.notifyAll();
        }
        synchronized (stateChangeLock) {
            if (reasonCallEnded == null) {
                try {
                    // wait for call to end
                    stateChangeLock.wait();
                } catch (InterruptedException e) {
                }
            }
        }
    } catch (IOException e) {
        synchronized (callInitiatedLock) {
            callInitiatedLock.notifyAll();
        }
        if (reasonCallEnded == null) {
            cancelRequest(e.getMessage());
        }
        Logger.println("Call " + this + " Exception " + e.getMessage());
    }
}
Also used : CallEvent(com.sun.voip.CallEvent) IOException(java.io.IOException)

Example 14 with CallEvent

use of com.sun.voip.CallEvent 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)

Example 15 with CallEvent

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

the class BridgeConnector method run.

public void run() {
    connected = true;
    while (!done) {
        String s = null;
        try {
            s = bufferedReader.readLine();
        } catch (IOException e) {
            if (done == false) {
                System.err.println("can't read socket! " + socket + " " + e.getMessage());
            }
            break;
        }
        if (s == null && done == false) {
            Logger.println("can't read socket! " + socket);
            break;
        }
        callEventNotification(new CallEvent(s));
    }
    connected = false;
}
Also used : CallEvent(com.sun.voip.CallEvent) IOException(java.io.IOException)

Aggregations

CallEvent (com.sun.voip.CallEvent)15 IOException (java.io.IOException)6 CallParticipant (com.sun.voip.CallParticipant)2 CallState (com.sun.voip.CallState)2 ParseException (java.text.ParseException)2 NoSuchElementException (java.util.NoSuchElementException)2 CallEventListener (com.sun.voip.CallEventListener)1 MediaInfo (com.sun.voip.MediaInfo)1 SocketException (java.net.SocketException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1