Skip to content

Commit

Permalink
Fixing recording for Dial cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hrosa committed Jun 10, 2015
1 parent e515f41 commit faee379
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.mobicents.servlet.restcomm.interpreter.rcml.Verbs.say;
import static org.mobicents.servlet.restcomm.interpreter.rcml.Verbs.sms;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -63,10 +62,8 @@
import org.mobicents.servlet.restcomm.dao.CallDetailRecordsDao;
import org.mobicents.servlet.restcomm.dao.DaoManager;
import org.mobicents.servlet.restcomm.dao.NotificationsDao;
import org.mobicents.servlet.restcomm.dao.RecordingsDao;
import org.mobicents.servlet.restcomm.entities.CallDetailRecord;
import org.mobicents.servlet.restcomm.entities.Notification;
import org.mobicents.servlet.restcomm.entities.Recording;
import org.mobicents.servlet.restcomm.entities.Sid;
import org.mobicents.servlet.restcomm.fax.FaxResponse;
import org.mobicents.servlet.restcomm.fsm.Action;
Expand Down Expand Up @@ -121,7 +118,6 @@
import org.mobicents.servlet.restcomm.telephony.StopConference;
import org.mobicents.servlet.restcomm.tts.api.SpeechSynthesizerResponse;
import org.mobicents.servlet.restcomm.util.UriUtils;
import org.mobicents.servlet.restcomm.util.WavUtils;

import scala.concurrent.Await;
import scala.concurrent.Future;
Expand Down Expand Up @@ -885,7 +881,7 @@ List<NameValuePair> parameters() {
if (invite != null)
processCustomHeaders(invite, "SipHeader_", parameters);
} else {
processCustomHeaders(lastResponse, "SipHeader_", parameters);
processCustomHeaders(lastResponse, "SipHeader_", parameters);
}

return parameters;
Expand Down Expand Up @@ -1667,8 +1663,8 @@ public void execute(final Object message) throws Exception {
}
}
branch.tell(new Cancel(), source);
// No need to destroy here. // Call will get Cancel and then FSM will move to Completed where finally we
// destroy calls
// No need to destroy here.
// Call will get Cancel and then FSM will move to Completed where finally we destroy calls
// callManager.tell(new DestroyCall(branch), source);
}
call.tell(new StopMediaGroup(), null);
Expand All @@ -1693,32 +1689,6 @@ public void execute(final Object message) throws Exception {
}

if (recordingCall && sender == call) {
Configuration runtimeSettings = configuration.subset("runtime-settings");
//Its the initial call that sent BYE so we can create the recording object here
if (recordingUri != null) {
Double duration = WavUtils.getAudioDuration(recordingUri);
if (duration.equals(0.0)) {
logger.info("At finishDialing. File doesn't exist since duration is 0");
final DateTime end = DateTime.now();
duration = new Double((end.getMillis() - callInfo.dateCreated().getMillis()) / 1000);
} else {
logger.info("At finishDialing. File already exists, length: "+ (new File(recordingUri).length()));
}
final Recording.Builder builder = Recording.builder();
builder.setSid(recordingSid);
builder.setAccountSid(accountId);
builder.setCallSid(callInfo.sid());
builder.setDuration(duration);
builder.setApiVersion(runtimeSettings.getString("api-version"));
StringBuilder buffer = new StringBuilder();
buffer.append("/").append(runtimeSettings.getString("api-version")).append("/Accounts/")
.append(accountId.toString());
buffer.append("/Recordings/").append(recordingSid.toString());
builder.setUri(URI.create(buffer.toString()));
final Recording recording = builder.build();
RecordingsDao recordsDao = storage.getRecordingsDao();
recordsDao.addRecording(recording);
}
recordingCall = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ private void onMediaGroupStateChanged(MediaGroupStateChanged message, ActorRef s
if (fail) {
this.fsm.transition(message, failed);
} else {
// Save record info in the database
if (recordStarted != null) {
saveRecording();
recordStarted = null;
recordingRequest = null;
}
// Move to inactive state
this.fsm.transition(message, inactive);
}
}
Expand Down Expand Up @@ -407,13 +414,14 @@ public DestroyingMediaGroup(final ActorRef source) {

@Override
public void execute(Object message) throws Exception {
// Stop Media Group
// Note: Recording will be added to DB after getting response from MG
if (recording) {
mediaGroup.tell(new Stop(), super.source);
saveRecording();
recording = Boolean.FALSE;
recordStarted = null;
recordingRequest = null;
}

// Destroy Media Group
mediaGroup.tell(new StopMediaGroup(), super.source);
}
}
Expand Down
Loading

0 comments on commit faee379

Please sign in to comment.