diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java index 00e4ad6a2456953902fd7c118a55a5059c182d86..445d169314e2734ea80ede261535ceff3ffce736 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java @@ -22,10 +22,13 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; - import org.bigbluebutton.freeswitch.voice.events.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FreeswitchConferenceEventListener implements ConferenceEventListener { + private static Logger log = LoggerFactory.getLogger(FreeswitchConferenceEventListener.class); + private static final int SENDERTHREADS = 1; private static final Executor msgSenderExec = Executors.newFixedThreadPool(SENDERTHREADS); private static final Executor runExec = Executors.newFixedThreadPool(SENDERTHREADS); @@ -43,7 +46,7 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene messages.offer(event, 5, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception queueing message: ", e); } } @@ -103,7 +106,7 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene sendMessageToBigBlueButton(message); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception taking message form queue: ", e); } } } diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java index b63e0e0ade1f94d547856c81fc080345cbd74621..7302cbfadf434237f593163b1c1576db7df40559 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java @@ -54,6 +54,8 @@ public class ConnectionManager { private final ConferenceEventListener conferenceEventListener; private final ESLEventListener eslEventListener; + private long lastStatusCheck = 0L; + public ConnectionManager(ManagerConnection connManager, ESLEventListener eventListener, ConferenceEventListener confListener) { this.manager = connManager; @@ -62,6 +64,7 @@ public class ConnectionManager { } private void connect() { + //log.info("Connecting to FS ESL"); try { Client c = manager.getESLClient(); if (!c.canSend()) { @@ -74,10 +77,18 @@ public class ConnectionManager { c.cancelEventSubscriptions(); c.addEventListener(eslEventListener); c.setEventSubscriptions("plain", "all"); - c.addEventFilter(EVENT_NAME, "heartbeat"); + //c.addEventFilter(EVENT_NAME, "heartbeat"); c.addEventFilter(EVENT_NAME, "custom"); c.addEventFilter(EVENT_NAME, "background_job"); subscribed = true; + } else { + // Let's check for status every minute. + Long now = System.currentTimeMillis(); + if ((now - lastStatusCheck) > 60000) { + lastStatusCheck = now; + CheckFreeswitchStatusCommand fsStatusCmd = new CheckFreeswitchStatusCommand("foo", "bar"); + checkFreeswitchStatus(fsStatusCmd); + } } } } catch (InboundConnectionFailure e) { @@ -125,6 +136,7 @@ public class ConnectionManager { } public void checkIfConfIsRunningCommand(CheckIfConfIsRunningCommand command) { + log.info("Sending CheckIfConfIsRunningCommand to FreeSWITCH"); Client c = manager.getESLClient(); if (c.canSend()) { EslMessage response = c.sendSyncApiCommand(command.getCommand(), @@ -133,6 +145,15 @@ public class ConnectionManager { } } + public void checkFreeswitchStatus(CheckFreeswitchStatusCommand ccrc) { + Client c = manager.getESLClient(); + if (c.canSend()) { + EslMessage response = c.sendSyncApiCommand(ccrc.getCommand(), + ccrc.getCommandArgs()); + ccrc.handleResponse(response, conferenceEventListener); + } + } + public void checkIfConferenceIsRecording(ConferenceCheckRecordCommand ccrc) { Client c = manager.getESLClient(); if (c.canSend()) { diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java index 0a0dbdac62f090d103b311cac6f284c78ac19fad..5fe62e0dd7b9c3900ab627bd274bb1b293db2b48 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java @@ -44,6 +44,7 @@ public class ESLEventListener implements IEslEventListener { @Override public void exceptionCaught(ExceptionEvent e) { + log.warn("Exception caught: ", e); // setChanged(); // notifyObservers(e); } @@ -237,13 +238,14 @@ public class ESLEventListener implements IEslEventListener { @Override public void eventReceived(EslEvent event) { -// System.out.println("ESL Event Listener received event=[" + event.getEventName() + "]" + -// event.getEventHeaders().toString()); -// if (event.getEventName().equals(FreeswitchHeartbeatMonitor.EVENT_HEARTBEAT)) { + //System.out.println("ESL Event Listener received event=[" + event.getEventName() + "]" + + // event.getEventHeaders().toString()); + if (event.getEventName().equals("heartbeat")) { + log.info("Received heartbeat from FreeSWITCH"); //// setChanged(); // notifyObservers(event); // return; -// } + } } private Integer getMemberIdFromEvent(EslEvent e) { diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java index 46400c9085f865c8ecf8195d3c5b50468add88ea..ead6c0740c586e2a081ac5dc389be42eca20a00e 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java @@ -66,10 +66,11 @@ public class FreeswitchApplication implements IDelayedCommandListener{ private void queueMessage(FreeswitchCommand command) { try { + log.info("Queue message: " + command.getCommand() + " " + command.getCommandArgs()); messages.offer(command, 5, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception queueing message: ", e); } } @@ -94,7 +95,7 @@ public class FreeswitchApplication implements IDelayedCommandListener{ sendMessageToFreeswitch(message); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception taking message from queue: ", e); } } } @@ -153,6 +154,7 @@ public class FreeswitchApplication implements IDelayedCommandListener{ private void sendMessageToFreeswitch(final FreeswitchCommand command) { Runnable task = new Runnable() { public void run() { + log.info("Sending message: " + command.getCommand() + " " + command.getCommandArgs()); if (command instanceof GetAllUsersCommand) { GetAllUsersCommand cmd = (GetAllUsersCommand) command; manager.getUsers(cmd); diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java new file mode 100755 index 0000000000000000000000000000000000000000..d0d2aa67f04113bf15159a487845b929122d2996 --- /dev/null +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java @@ -0,0 +1,35 @@ +package org.bigbluebutton.freeswitch.voice.freeswitch.actions; + +import com.google.gson.Gson; +import org.apache.commons.lang3.StringUtils; +import org.bigbluebutton.freeswitch.voice.events.ConferenceEventListener; +import org.freeswitch.esl.client.transport.message.EslMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CheckFreeswitchStatusCommand extends FreeswitchCommand { + private static Logger log = LoggerFactory.getLogger(CheckFreeswitchStatusCommand.class); + + public CheckFreeswitchStatusCommand(String room, String requesterId) { + super(room, requesterId); + } + + @Override + public String getCommand() { + return "status"; + } + + @Override + public String getCommandArgs() { + log.debug("Check FreeSWITCH Status."); + return ""; + } + + public void handleResponse(EslMessage response, ConferenceEventListener eventListener) { + + Gson gson = new Gson(); + log.info(gson.toJson(response.getBodyLines())); + + } + +} diff --git a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala index 239045f1c6112c56bdab9dd3d47af832ee06884a..546c361cbbea807226d2b95426c5c515d237b449 100755 --- a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala +++ b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala @@ -32,7 +32,7 @@ class RxJsonMsgHdlrActor(val fsApp: FreeswitchApplication) extends Actor with Ac } def handle(envelope: BbbCoreEnvelope, jsonNode: JsonNode): Unit = { - log.debug("Route envelope name " + envelope.name) + //log.debug("Route envelope name " + envelope.name) envelope.name match { case GetUsersInVoiceConfSysMsg.NAME => routeGetUsersInVoiceConfSysMsg(envelope, jsonNode)