Skip to content

Commit

Permalink
After Dial verb, Callee response 480, or accept and BYE the call. Nex…
Browse files Browse the repository at this point in the history
…t verb or action dial will be skiped.
  • Loading branch information
Hoan HL committed Apr 4, 2018
1 parent 468762c commit 372e101
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,13 @@ private void onCallStateChanged(Object message, ActorRef sender) throws Transiti
if (dialBranches != null && dialBranches.contains(sender)) {
dialBranches.remove(sender);
}
if (dialBranches == null || dialBranches.size() == 0){
// Stop playing the ringing tone from inbound call. There is race condifiton, If after Dial verb
// has Play or Say verb, NTFY for Stop media recouce will also stop Play or Say Verb. Better to
// stop it here.
msResponsePending = true;
call.tell(new StopMediaGroup(), self());
}
checkDialBranch(message,sender,action);
} else if (sender.equals(call)) {
fsm.transition(message, finished);
Expand Down Expand Up @@ -1512,7 +1519,11 @@ private void checkDialBranch(Object message, ActorRef sender, Attribute attribut
}
if (bridge != null) {
// Stop the bridge
bridge.tell(new StopBridge(liveCallModification), self());
if (logger.isDebugEnabled()) {
logger.debug("LivecallModification: " + liveCallModification + " Sender == call?: " + (sender != null && !sender.equals(call)));
}
bridge.tell(new StopBridge(liveCallModification ||
(sender != null && !sender.equals(call))), self());
recordingCall = false;
bridge = null;
}
Expand Down Expand Up @@ -2896,7 +2907,8 @@ public void execute(final Object message) throws Exception {
return;
} else {
if (callState == CallStateChanged.State.IN_PROGRESS) {
call.tell(new Hangup(), self());
// Finish Dialing, need to check for next verb or execute Dial Action link. Should not stop here.
checkDialBranch(message,sender,action);
} else {
if (logger.isInfoEnabled()) {
String msg = String.format("Didn't sent Hangup to call because current call state is: [%s]", callState.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,209 @@ public void testDialBusyTimeoutWithPlay() throws ParseException, InterruptedExce
assertEquals(0, mgcpEndpoints);
assertEquals(0, mgcpConnections);
}
private String dialForkTwoTimes = "<Response><Dial><Client>alice</Client></Dial><Dial><Client>bob</Client></Dial></Response>";
@Test
@Category(FeatureAltTests.class)
public void testDialForkTwoTime() throws ParseException, InterruptedException, MalformedURLException {
stubFor(get(urlPathEqualTo("/1111"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(dialForkTwoTimes)));

SipURI Alice_uri = aliceSipStack.getAddressFactory().createSipURI(null, restcommContact);
assertTrue(alicePhone.register(Alice_uri, "alice", "1234", aliceContact, 3600, 3600));

SipURI Bob_uri = bobSipStack.getAddressFactory().createSipURI(null, restcommContact);
assertTrue(bobPhone.register(Bob_uri, "bob", "1234", bobContact, 3600, 3600));

// Prepare Alice's phone to receive call
SipCall aliceCall = alicePhone.createSipCall();
aliceCall.listenForIncomingCall();

// Create outgoing call with first phone
final SipCall henriqueCall = henriquePhone.createSipCall();
henriqueCall.initiateOutgoingCall(henriqueContact, "sip:1111@" + restcommContact, null, body, "application", "sdp", null, null);
assertLastOperationSuccess(henriqueCall);
assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
final int response = henriqueCall.getLastReceivedResponse().getStatusCode();
assertTrue(response == Response.TRYING || response == Response.RINGING);

if (response == Response.TRYING) {
assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.RINGING, henriqueCall.getLastReceivedResponse().getStatusCode());
}

assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.OK, henriqueCall.getLastReceivedResponse().getStatusCode());
assertTrue(henriqueCall.sendInviteOkAck());

assertTrue(aliceCall.waitForIncomingCall(5000));
String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
assertTrue(aliceCall.sendIncomingCallResponse(Response.TRYING, "Alice-Trying", 3600));
assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Alice-Ringing", 3600));
assertTrue(aliceCall.sendIncomingCallResponse(Response.OK, "Alice-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(aliceCall.waitForAck(5000));

Thread.sleep(500);
assertTrue(aliceCall.disconnect());

// Prepare Bob's phone to receive call
SipCall bobCall = bobPhone.createSipCall();
bobCall.listenForIncomingCall();

assertTrue(bobCall.waitForIncomingCall(5000));
assertTrue(bobCall.sendIncomingCallResponse(Response.TRYING, "Bob-Trying", 3600));
assertTrue(bobCall.sendIncomingCallResponse(Response.RINGING, "Bob-Ringing", 3600));
assertTrue(bobCall.sendIncomingCallResponse(Response.OK, "Bob-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(bobCall.waitForAck(5000));

Thread.sleep(2000);
henriqueCall.listenForDisconnect();

assertTrue(bobCall.disconnect());
Thread.sleep(500);
assertTrue(henriqueCall.waitForDisconnect(5000));
assertTrue(henriqueCall.respondToDisconnect());

assertTrue(alicePhone.unregister(aliceContact, 3600));
assertTrue(bobPhone.unregister(aliceContact, 3600));

Thread.sleep(10000);

logger.info("About to check the Requests");
List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1111")));
assertTrue(requests.size() == 1);
// requests.get(0).g;
String requestBody = new URL(requests.get(0).getAbsoluteUrl()).getQuery();// .getQuery();// .getBodyAsString();
List<String> params = Arrays.asList(requestBody.split("&"));
String callSid = "";
for (String param : params) {
if (param.contains("CallSid")) {
callSid = param.split("=")[1];
}
}
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
JsonObject jsonObj = cdr.getAsJsonObject();
assertTrue(jsonObj.get("status").getAsString().equalsIgnoreCase("completed"));
assertTrue(MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(), adminAccountSid, adminAuthToken) == 0);
assertTrue(MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(), adminAccountSid, adminAuthToken) == 0);

JsonObject metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
Map<String, Integer> mgcpResources = MonitoringServiceTool.getInstance().getMgcpResources(metrics);
int mgcpEndpoints = mgcpResources.get("MgcpEndpoints");
int mgcpConnections = mgcpResources.get("MgcpConnections");

assertEquals(0, mgcpEndpoints);
assertEquals(0, mgcpConnections);
}

private String rcmlDailReturn = "<Response><Dial><Client>bob</Client></Dial></Response>";
@Test
@Category(FeatureAltTests.class)
public void testDialForkTwoTimeWithDialAction() throws ParseException, InterruptedException, MalformedURLException {
stubFor(get(urlPathEqualTo("/1111"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(dialTimeoutRcmlWithPlay)));

stubFor(post(urlEqualTo("/test"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(rcmlDailReturn)));

SipURI Alice_uri = aliceSipStack.getAddressFactory().createSipURI(null, restcommContact);
assertTrue(alicePhone.register(Alice_uri, "alice", "1234", aliceContact, 3600, 3600));

SipURI Bob_uri = bobSipStack.getAddressFactory().createSipURI(null, restcommContact);
assertTrue(bobPhone.register(Bob_uri, "bob", "1234", bobContact, 3600, 3600));

// Prepare Alice's phone to receive call
SipCall aliceCall = alicePhone.createSipCall();
aliceCall.listenForIncomingCall();

// Create outgoing call with first phone
final SipCall henriqueCall = henriquePhone.createSipCall();
henriqueCall.initiateOutgoingCall(henriqueContact, "sip:1111@" + restcommContact, null, body, "application", "sdp", null, null);
assertLastOperationSuccess(henriqueCall);
assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
final int response = henriqueCall.getLastReceivedResponse().getStatusCode();
assertTrue(response == Response.TRYING || response == Response.RINGING);

if (response == Response.TRYING) {
assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.RINGING, henriqueCall.getLastReceivedResponse().getStatusCode());
}

assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.OK, henriqueCall.getLastReceivedResponse().getStatusCode());
assertTrue(henriqueCall.sendInviteOkAck());

assertTrue(aliceCall.waitForIncomingCall(5000));
String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
assertTrue(aliceCall.sendIncomingCallResponse(Response.TRYING, "Alice-Trying", 3600));
assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Alice-Ringing", 3600));
assertTrue(aliceCall.sendIncomingCallResponse(Response.OK, "Alice-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(aliceCall.waitForAck(5000));

Thread.sleep(500);
assertTrue(aliceCall.disconnect());

// Prepare Bob's phone to receive call
SipCall bobCall = bobPhone.createSipCall();
bobCall.listenForIncomingCall();

assertTrue(bobCall.waitForIncomingCall(5000));
assertTrue(bobCall.sendIncomingCallResponse(Response.TRYING, "Bob-Trying", 3600));
assertTrue(bobCall.sendIncomingCallResponse(Response.RINGING, "Bob-Ringing", 3600));
assertTrue(bobCall.sendIncomingCallResponse(Response.OK, "Bob-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(bobCall.waitForAck(5000));

Thread.sleep(2000);
henriqueCall.listenForDisconnect();

assertTrue(bobCall.disconnect());
Thread.sleep(500);
assertTrue(henriqueCall.waitForDisconnect(5000));
assertTrue(henriqueCall.respondToDisconnect());

assertTrue(alicePhone.unregister(aliceContact, 3600));
assertTrue(bobPhone.unregister(aliceContact, 3600));

Thread.sleep(10000);

logger.info("About to check the Requests");
List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1111")));
assertTrue(requests.size() == 1);
// requests.get(0).g;
String requestBody = new URL(requests.get(0).getAbsoluteUrl()).getQuery();// .getQuery();// .getBodyAsString();
List<String> params = Arrays.asList(requestBody.split("&"));
String callSid = "";
for (String param : params) {
if (param.contains("CallSid")) {
callSid = param.split("=")[1];
}
}
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
JsonObject jsonObj = cdr.getAsJsonObject();
assertTrue(jsonObj.get("status").getAsString().equalsIgnoreCase("completed"));
assertTrue(MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(), adminAccountSid, adminAuthToken) == 0);
assertTrue(MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(), adminAccountSid, adminAuthToken) == 0);

JsonObject metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
Map<String, Integer> mgcpResources = MonitoringServiceTool.getInstance().getMgcpResources(metrics);
int mgcpEndpoints = mgcpResources.get("MgcpEndpoints");
int mgcpConnections = mgcpResources.get("MgcpConnections");

assertEquals(0, mgcpEndpoints);
assertEquals(0, mgcpConnections);
}

@Deployment(name = "DialForkTest", managed = true, testable = false)
public static WebArchive createWebArchiveNoGw() {
Expand Down

0 comments on commit 372e101

Please sign in to comment.