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);
}
}
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());
}
}
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());
}
}
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;
}
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;
}
Aggregations