Skip to content

Commit

Permalink
handled beep scenerios
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Farooq committed Oct 3, 2016
1 parent 7cdaa8f commit 2a87d64
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 37 deletions.
Expand Up @@ -214,6 +214,7 @@ public final class VoiceInterpreter extends BaseVoiceInterpreter {
// Call bridging
private final ActorRef bridgeManager;
private ActorRef bridge;
private boolean beep;

public VoiceInterpreter(final Configuration configuration, final Sid account, final Sid phone, final String version,
final URI url, final String method, final URI fallbackUrl, final String fallbackMethod, final URI statusCallback,
Expand Down Expand Up @@ -609,8 +610,8 @@ private void onConferenceResponse(Object message) throws TransitionFailedExcepti
self().tell(stop, self());
return;
}
if (logger.isDebugEnabled()) {
logger.debug("going to play conference-exit-audio beep");
if (logger.isInfoEnabled()) {
logger.info("going to play conference-exit-audio beep");
}
final Play play = new Play(uri, 1);
conference.tell(play, self());
Expand Down Expand Up @@ -2430,7 +2431,7 @@ public void execute(final Object message) throws Exception {

if (conferenceInfo.globalParticipants() < maxParticipantLimit) {
// Play beep.
boolean beep = true;
beep = true;
attribute = child.attribute("beep");
if (attribute != null) {
final String value = attribute.value();
Expand All @@ -2442,29 +2443,11 @@ public void execute(final Object message) throws Exception {
// Only play beep if conference is already running
// Do not play it while participants are listening to background music
if (beep && ConferenceStateChanged.State.RUNNING_MODERATOR_PRESENT.equals(conferenceInfo.state())) {
String path = configuration.subset("runtime-settings").getString("prompts-uri");
if (!path.endsWith("/")) {
path += "/";
}
String entryAudio = configuration.subset("runtime-settings").getString("conference-entry-audio");
path += entryAudio == null || entryAudio.equals("") ? "beep.wav" : entryAudio;
URI uri = null;
try {
uri = UriUtils.resolve(new URI(path));
} catch (final Exception exception) {
final Notification notification = notification(ERROR_NOTIFICATION, 12400, exception.getMessage());
final NotificationsDao notifications = storage.getNotificationsDao();
notifications.addNotification(notification);
sendMail(notification);
final StopInterpreter stop = new StopInterpreter();
source.tell(stop, source);
return;
}
if (logger.isDebugEnabled()) {
logger.debug("going to play conference-entry-audio beep");
playBeepOnEnter(source);
}else{
if (logger.isInfoEnabled()) {
logger.info("Wont play beep bcz: beep="+beep+" AND conferenceInfo.state()="+conferenceInfo.state());
}
final Play play = new Play(uri, 1);
conference.tell(play, source);
}
if (logger.isInfoEnabled()) {
logger.info("About to join call to Conference: "+conferenceInfo.name()+", with state: "+conferenceInfo.state()+", with moderator present: "+conferenceInfo.isModeratorPresent()+", and current participants: "+conferenceInfo.globalParticipants());
Expand Down Expand Up @@ -2652,7 +2635,13 @@ public void execute(final Object message) throws Exception {
// Tell the conference the moderator is now present
// Causes background music to stop playing and all participants will be unmuted
conference.tell(new ConferenceModeratorPresent(), source);

if (beep) {
playBeepOnEnter(source);
}else{
if (logger.isInfoEnabled()) {
logger.info("Wont play beep bcz: beep="+beep+" AND conferenceInfo.state()="+conferenceInfo.state());
}
}
// Check if moderator wants to record the conference
Attribute record = verb.attribute("record");
if (record != null && "true".equalsIgnoreCase(record.value())) {
Expand Down Expand Up @@ -2681,6 +2670,31 @@ public void execute(final Object message) throws Exception {
}
}

protected void playBeepOnEnter(ActorRef source){
String path = configuration.subset("runtime-settings").getString("prompts-uri");
if (!path.endsWith("/")) {
path += "/";
}
String entryAudio = configuration.subset("runtime-settings").getString("conference-entry-audio");
path += entryAudio == null || entryAudio.equals("") ? "beep.wav" : entryAudio;
URI uri = null;
try {
uri = UriUtils.resolve(new URI(path));
} catch (final Exception exception) {
final Notification notification = notification(ERROR_NOTIFICATION, 12400, exception.getMessage());
final NotificationsDao notifications = storage.getNotificationsDao();
notifications.addNotification(notification);
sendMail(notification);
final StopInterpreter stop = new StopInterpreter();
source.tell(stop, source);
return;
}
if (logger.isInfoEnabled()) {
logger.info("going to play conference-entry-audio beep");
}
final Play play = new Play(uri, 1);
conference.tell(play, source);
}
//Because of RMS issue https://github.com/RestComm/mediaserver/issues/158 we cannot have List<URI> for waitUrl
protected void playWaitUrl(final List<URI> waitUrls, final ActorRef source) {
conference.tell(new Play(waitUrls, Short.MAX_VALUE, confModeratorPresent), source);
Expand Down
Expand Up @@ -20,6 +20,8 @@
*/
package org.mobicents.servlet.restcomm.mgcp.mrb;

import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -31,17 +33,18 @@
import org.joda.time.DateTime;
import org.mobicents.servlet.restcomm.dao.ConferenceDetailRecordsDao;
import org.mobicents.servlet.restcomm.dao.DaoManager;
import org.mobicents.servlet.restcomm.dao.MediaResourceBrokerDao;
import org.mobicents.servlet.restcomm.entities.ConferenceDetailRecord;
import org.mobicents.servlet.restcomm.entities.MediaResourceBrokerEntity;
import org.mobicents.servlet.restcomm.entities.MediaResourceBrokerEntityFilter;
import org.mobicents.servlet.restcomm.entities.Sid;
import org.mobicents.servlet.restcomm.fsm.Action;
import org.mobicents.servlet.restcomm.fsm.FiniteStateMachine;
import org.mobicents.servlet.restcomm.fsm.State;
import org.mobicents.servlet.restcomm.fsm.Transition;
import org.mobicents.servlet.restcomm.mgcp.ConnectionStateChanged;
import org.mobicents.servlet.restcomm.mgcp.CreateBridgeEndpoint;
import org.mobicents.servlet.restcomm.dao.MediaResourceBrokerDao;
import org.mobicents.servlet.restcomm.entities.MediaResourceBrokerEntity;
import org.mobicents.servlet.restcomm.entities.MediaResourceBrokerEntityFilter;

import org.mobicents.servlet.restcomm.mgcp.CreateConferenceEndpoint;
import org.mobicents.servlet.restcomm.mgcp.CreateConnection;
import org.mobicents.servlet.restcomm.mgcp.DestroyEndpoint;
Expand Down Expand Up @@ -69,6 +72,7 @@
import org.mobicents.servlet.restcomm.patterns.Observe;
import org.mobicents.servlet.restcomm.patterns.Observing;
import org.mobicents.servlet.restcomm.patterns.StopObserving;
import org.mobicents.servlet.restcomm.util.UriUtils;

import akka.actor.ActorRef;
import akka.actor.Props;
Expand Down Expand Up @@ -219,6 +223,7 @@ public ConferenceMediaResourceController(final String localMsId, final Map<Strin
transitions.add(new Transition(acquiringMasterConferenceEndpoint, acquiringRemoteConnectionWithMasterMS));
transitions.add(new Transition(acquiringRemoteConnectionWithMasterMS, initializingRemoteConnectionWithMasterMS));
transitions.add(new Transition(initializingRemoteConnectionWithMasterMS, openingRemoteConnectionWithMasterMS));
transitions.add(new Transition(openingRemoteConnectionWithMasterMS, failed));
transitions.add(new Transition(openingRemoteConnectionWithMasterMS, updatingRemoteConnectionWithLocalMS));
transitions.add(new Transition(updatingRemoteConnectionWithLocalMS, creatingMediaGroup));
transitions.add(new Transition(creatingMediaGroup, preActive));
Expand Down Expand Up @@ -483,7 +488,7 @@ private void onMediaGroupStateChanged(MediaGroupStateChanged message, ActorRef s
}

private void onPlay(Play message, ActorRef self, ActorRef sender) {
if (is(active) && !playing) {
if (!playing) {
this.playing = Boolean.TRUE;
this.mediaGroup.tell(message, self);
}
Expand Down Expand Up @@ -512,7 +517,7 @@ private void onStopRecording(StopRecording message, ActorRef self, ActorRef send
}

private void onMediaGroupResponse(MediaGroupResponse<String> message, ActorRef self, ActorRef sender) throws Exception {
if (is(active) && this.playing) {
if (this.playing) {
this.playing = Boolean.FALSE;
}
}
Expand Down Expand Up @@ -952,8 +957,11 @@ public void execute(Object message) throws Exception {
updateConferenceStatus("COMPLETED");
// Destroy Media Group
mediaGroup.tell(new StopMediaGroup(), super.source);
}else{
playBeepOnExit(self());
}
}else{
playBeepOnExit(self());
logger.info("CMRC is STOPPING Slave NOW...");
removeSlaveRecord();
//check if it is last to leave in entire cluster then distroymaster conf EP as well
Expand All @@ -968,6 +976,17 @@ public void execute(Object message) throws Exception {
}
}

private void playBeepOnExit(final ActorRef source) throws URISyntaxException{
//TODO: read it from config after testing
String path = "/restcomm/audio/";
String entryAudio = "alert.wav";
path += entryAudio == null || entryAudio.equals("") ? "beep.wav" : entryAudio;
URI uri = null;
uri = UriUtils.resolve(new URI(path));
final Play play = new Play(uri, 1);
onPlay(play, self(), sender());
}

private abstract class FinalState extends AbstractAction {

public FinalState(ActorRef source) {
Expand Down
Expand Up @@ -37,9 +37,9 @@ public enum MediaServerControllerState {
private final MediaServerControllerState state;
private final String conferenceState;

public ConferenceMediaResourceControllerStateChanged(MediaServerControllerState state, final String ConferenceState) {
public ConferenceMediaResourceControllerStateChanged(MediaServerControllerState state, final String conferenceState) {
this.state = state;
this.conferenceState = ConferenceState;
this.conferenceState = conferenceState;
}

public MediaServerControllerState state() {
Expand Down
Expand Up @@ -94,6 +94,8 @@ public final class Conference extends UntypedActor {
private final DaoManager storage;
private int globalNoOfParticipants;

private ConferenceStateChanged.State waitingState;

public Conference(final String name, final ActorRef msController, final DaoManager storage) {
super();
final ActorRef source = self();
Expand Down Expand Up @@ -249,11 +251,11 @@ public void execute(final Object message) throws Exception {
String stateStr= mediaServerConferenceControllerStateChanged.conferenceState();

//this is to cover the scenario where initial state is not moderatorAbsent and maybe moderator is present on another node.
ConferenceStateChanged.State initialState = ConferenceStateChanged.translateState(stateStr, ConferenceStateChanged.State.RUNNING_MODERATOR_ABSENT);
waitingState = ConferenceStateChanged.translateState(stateStr, ConferenceStateChanged.State.RUNNING_MODERATOR_ABSENT);
if(logger.isInfoEnabled()) {
logger.info("################################## Conference " + name + " has sid: "+sid +" initial state: "+initialState);
logger.info("################################## Conference " + name + " has sid: "+sid +" stateStr: "+stateStr+" initial state: "+waitingState);
}
broadcast(new ConferenceStateChanged(name, initialState));
broadcast(new ConferenceStateChanged(name, waitingState));
}
}

Expand Down Expand Up @@ -364,7 +366,7 @@ private ConferenceInfo createConferenceInfo() throws Exception{
ConferenceInfo information = null;
int globalNoOfParticipants = getGlobalNoOfParticipants();
if (is(waiting)) {
information = new ConferenceInfo(sid, calls, ConferenceStateChanged.State.RUNNING_MODERATOR_ABSENT, name, moderatorPresent, globalNoOfParticipants);
information = new ConferenceInfo(sid, calls, waitingState, name, moderatorPresent, globalNoOfParticipants);
} else if (is(running)) {
information = new ConferenceInfo(sid, calls, ConferenceStateChanged.State.RUNNING_MODERATOR_PRESENT, name, moderatorPresent, globalNoOfParticipants);
} else if (is(stopped)) {
Expand Down

0 comments on commit 2a87d64

Please sign in to comment.