use of com.sun.voip.CallEvent in project Openfire by igniterealtime.
the class IncomingCallHandler method run.
/*
* Thread to process this incoming call.
* Create a temporary conference and add this call.
*/
public void run() {
if (haveIncomingConferenceId == false) {
cp.setConferenceId(defaultIncomingConferenceId);
}
synchronized (ConferenceManager.getConferenceList()) {
conferenceManager = ConferenceManager.getConference(cp.getConferenceId());
if (conferenceManager == null) {
Logger.error("Couldn't start conference " + cp.getConferenceId());
sendCallEventNotification(new CallEvent(CallEvent.CANT_START_CONFERENCE));
return;
}
cp.setDisplayName(cp.getName());
cp.setDtmfDetection(true);
if (cp.getCallId() == null) {
cp.setCallId(getNewCallId());
}
cp.setCallAnsweredTreatment(incomingCallTreatment);
cp.setVoiceDetection(incomingCallVoiceDetection);
if (haveIncomingConferenceId == false) {
cp.setWhisperGroupId(cp.getCallId());
cp.setMuted(true);
}
if (Logger.logLevel >= Logger.LOG_INFO) {
Logger.println(cp.getCallSetupRequest());
}
try {
member = conferenceManager.joinConference(cp);
memberSender = member.getMemberSender();
memberReceiver = member.getMemberReceiver();
} catch (IOException e) {
CallEvent callEvent = new CallEvent(CallEvent.CANT_CREATE_MEMBER);
callEvent.setInfo(e.getMessage());
sendCallEventNotification(callEvent);
return;
}
Logger.println("Incoming Call " + cp + " joined conference " + cp.getConferenceId());
}
// add to list of active calls
addCall(this);
String protocol = Bridge.getDefaultProtocol();
if (cp.getProtocol() != null) {
protocol = cp.getProtocol();
}
if (protocol.equalsIgnoreCase("NS")) {
csa = new NSIncomingCallAgent(this);
try {
csa.initiateCall();
} catch (IOException e) {
Logger.println("initiateCall failed: " + e.getMessage());
CallEvent callEvent = new CallEvent(CallEvent.CANT_CREATE_MEMBER);
callEvent.setInfo(e.getMessage());
sendCallEventNotification(callEvent);
return;
}
} else if (protocol.equalsIgnoreCase("SIP")) {
csa = new SipIncomingCallAgent(this, requestEvent);
} else {
// XXX csa = new H323Agent(this);
Logger.println("H.323 support isn't implemented yet!");
sendCallEventNotification(new CallEvent(CallEvent.H323_NOT_IMPLEMENTED));
return;
}
if (haveIncomingConferenceId == false) {
new TransferTimer(member);
}
synchronized (stateChangeLock) {
if (csa.getState() != CallState.ENDED) {
try {
Logger.println("Call " + cp + " Waiting for call to end...");
// wait for call to end
stateChangeLock.wait();
} catch (InterruptedException e) {
}
}
}
try {
Logger.println("Call " + cp + " ended...");
// Remove member from conference.
conferenceManager.leave(member);
} catch (Exception e) {
e.printStackTrace();
}
Logger.println("Call " + cp + " removed...");
// remove from list of active calls
removeCall(this);
csa = null;
cancelRequest("Incoming call ended");
done = true;
}
use of com.sun.voip.CallEvent in project Openfire by igniterealtime.
the class MemberReceiver method treatmentDoneNotification.
public void treatmentDoneNotification(String treatment) {
synchronized (conferenceManager) {
if (Logger.logLevel >= Logger.LOG_MOREINFO) {
Logger.println("Input Treatment done " + treatment);
}
if (callHandler == null) {
Logger.println("Call " + cp + " treatment done but no call handler.");
return;
}
CallEvent callEvent = new CallEvent(CallEvent.TREATMENT_DONE);
callEvent.setTreatmentId(treatment);
callHandler.sendCallEventNotification(callEvent);
}
}
use of com.sun.voip.CallEvent in project Openfire by igniterealtime.
the class CallMigrator method migrateWithNoPreviousCall.
private void migrateWithNoPreviousCall(CallEventListener requestHandler, CallParticipant cp) {
cp.setPhoneNumber(cp.getSecondPartyNumber());
OutgoingCallHandler callHandler = new OutgoingCallHandler(requestHandler, cp);
synchronized (this) {
// call new party
callHandler.start();
/*
* Wait for call to be established
*/
if (callHandler.waitForCallToBeEstablished() == false) {
return;
}
}
// call is no longer migrating
cp.setMigrateCall(false);
CallEvent callEvent = new CallEvent(CallEvent.MIGRATED);
callEvent.setInfo("migrated to " + cp);
callHandler.sendCallEventNotification(callEvent);
}
use of com.sun.voip.CallEvent 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());
}
use of com.sun.voip.CallEvent in project Openfire by igniterealtime.
the class CallSetupAgent method setState.
protected void setState(int state, String info) {
callState = new CallState(state);
CallEvent callEvent = new CallEvent(CallEvent.STATE_CHANGED);
callEvent.setCallState(callState);
String s = "";
if (state == CallState.INVITED || state == CallState.ESTABLISHED) {
s += "ConferenceReceiverPort='" + callHandler.getReceiveAddress().getPort() + "'";
MediaInfo mediaInfo = callHandler.getConferenceManager().getMediaInfo();
s += " ConferencePayload='" + mediaInfo.getPayload() + "'";
s += " BridgeIPAddress='" + Bridge.getPrivateHost() + "'";
s += " BridgeInfo='" + Bridge.getPrivateHost() + ":" + Bridge.getPrivateControlPort() + ":" + Bridge.getPrivateSipPort() + ":" + Bridge.getPublicHost() + ":" + Bridge.getPublicControlPort() + ":" + Bridge.getPublicSipPort() + "'";
}
if (info != null) {
s = info + " " + s;
}
callEvent.setInfo(s);
Logger.println("Call " + callHandler + " " + callState);
sendCallEventNotification(callEvent);
if (state == CallState.ESTABLISHED) {
String treatment = cp.getCallEstablishedTreatment();
if (treatment != null) {
callEstablishedTreatment = initializeTreatment(treatment, 0);
if (callEstablishedTreatment != null) {
addTreatment(callEstablishedTreatment);
}
}
}
if (inviteTimeoutThread == null && state == CallState.INVITED) {
inviteTimeoutThread = new Thread(this);
// start invite timeout thread
inviteTimeoutThread.start();
}
}
Aggregations