Skip to content

Commit

Permalink
Minor clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Jul 11, 2016
1 parent 154bac4 commit ff84b21
Showing 1 changed file with 45 additions and 44 deletions.
89 changes: 45 additions & 44 deletions src/main/java/org/jitsi/jicofo/recording/jibri/JibriRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ public class JibriRecorder
*/
static private final int NUM_RETRIES = 3;

/**
* Returns <tt>true> if given <tt>status</tt> precedes the <tt>RETRYING</tt>
* status or <tt>false</tt> otherwise.
*/
static private boolean isPreRetryStatus(JibriIq.Status status)
{
return JibriIq.Status.ON.equals(status)
|| JibriIq.Status.RETRYING.equals(status);
}

/**
* Returns <tt>true</tt> if given <tt>status</tt> indicates that Jibri is in
* the middle of starting of the recording process.
*/
static private boolean isStartingStatus(JibriIq.Status status)
{
return JibriIq.Status.PENDING.equals(status)
|| JibriIq.Status.RETRYING.equals(status);
}

/**
* Recorded <tt>JitsiMeetConference</tt>.
*/
Expand Down Expand Up @@ -114,26 +134,6 @@ public class JibriRecorder
*/
private Future<?> timeoutTrigger;

/**
* Returns <tt>true> if given <tt>status</tt> precedes the <tt>RETRYING</tt>
* status or <tt>false</tt> otherwise.
*/
static private boolean isPreRetryStatus(JibriIq.Status status)
{
return JibriIq.Status.ON.equals(status)
|| JibriIq.Status.RETRYING.equals(status);
}

/**
* Returns <tt>true</tt> if given <tt>status</tt> indicates that Jibri is in
* the middle of starting of the recording process.
*/
static private boolean isStartingStatus(JibriIq.Status status)
{
return JibriIq.Status.PENDING.equals(status)
|| JibriIq.Status.RETRYING.equals(status);
}

/**
* Creates new instance of <tt>JibriRecorder</tt>.
* @param conference <tt>JitsiMeetConference</tt> to be recorded by new
Expand Down Expand Up @@ -246,22 +246,17 @@ public boolean accept(Packet packet)
private void startJibri(final String jibriJid)
{
logger.info("Starting Jibri " + jibriJid + " for stream ID: "
+ this.streamID + " in room: " + getRoomName());
+ streamID + " in room: " + getRoomName());

final JibriIq startIq = new JibriIq();
startIq.setTo(jibriJid);
startIq.setType(IQ.Type.SET);
startIq.setAction(JibriIq.Action.START);
startIq.setStreamId(this.streamID);
startIq.setStreamId(streamID);

// Insert name of the room into Jibri START IQ
startIq.setRoom(getRoomName());

if (logger.isDebugEnabled())
{
logger.debug("Starting Jibri recording: " + startIq.toXML());
}

// Store Jibri JID to make the packet filter accept the response
recorderComponentJid = jibriJid;

Expand Down Expand Up @@ -322,6 +317,11 @@ private void cancelTimeoutTrigger()
@Override
synchronized public void processPacket(Packet packet)
{
if (logger.isDebugEnabled())
{
logger.debug("Processing an IQ from Jibri: " + packet.toXML());
}

IQ iq = (IQ) packet;

String from = iq.getFrom();
Expand All @@ -330,12 +330,8 @@ synchronized public void processPacket(Packet packet)
{
JibriIq jibriIq = (JibriIq) iq;

if (logger.isDebugEnabled())
logger.debug("Got Jibri packet: " + packet.toXML());

if (recorderComponentJid != null &&
(from.equals(recorderComponentJid) ||

(from + "/").startsWith(recorderComponentJid)))
{
processJibriIqFromJibri(jibriIq);
Expand All @@ -345,13 +341,14 @@ synchronized public void processPacket(Packet packet)
String roomName = MucUtil.extractRoomNameFromMucJid(from);
if (roomName == null)
{
logger.warn("Could not extract room name from jid:" + from);
return;
}

String actualRoomName = getRoomName();
if (!actualRoomName.equals(roomName))
{
logger.debug(
logger.warn(
"Ignored packet from: " + roomName
+ ", my room: " + actualRoomName
+ " p: " + packet.toXML());
Expand All @@ -361,7 +358,7 @@ synchronized public void processPacket(Packet packet)
XmppChatMember chatMember = conference.findMember(from);
if (chatMember == null)
{
logger.error("ERROR chat member not found for: " + from
logger.warn("ERROR chat member not found for: " + from
+ " in " + roomName);
return;
}
Expand All @@ -372,30 +369,27 @@ synchronized public void processPacket(Packet packet)
else
{
// We're processing Jibri response, probably an error
logger.debug("Response from Jibri: " + iq.toXML());
if (IQ.Type.ERROR.equals(iq.getType()))
{
processError(iq.getError());
processJibriError(iq.getError());
}
}
}

private void processJibriIqFromMeet(final JibriIq iq,
final XmppChatMember sender)
{
JibriIq.Action action = iq.getAction();

if (JibriIq.Action.UNDEFINED.equals(action))
return;

String senderMucJid = sender.getContactAddress();

if (logger.isDebugEnabled())
{
logger.debug(
"Jibri request from " + senderMucJid + " iq: " + iq.toXML());
}

JibriIq.Action action = iq.getAction();
if (JibriIq.Action.UNDEFINED.equals(action))
return;

// verifyModeratorRole sends 'not_allowed' error on false
if (!verifyModeratorRole(iq))
{
Expand Down Expand Up @@ -438,6 +432,8 @@ else if (JibriIq.Action.STOP.equals(action) &&
(JibriIq.Status.ON.equals(jibriStatus) ||
isStartingStatus(jibriStatus)))
{
// XXX FIXME: this is synchronous and will probably block the smack
// thread that executes processPacket().
XMPPError error = sendStopIQ();
sendPacket(
error == null
Expand All @@ -457,7 +453,10 @@ else if (JibriIq.Action.STOP.equals(action) &&
+ "' in state: '" + jibriStatus + "'");
}

private void processError(XMPPError error)
/**
* Processes an error received from Jibri.
*/
private void processJibriError(XMPPError error)
{
if (recorderComponentJid != null)
{
Expand Down Expand Up @@ -570,7 +569,7 @@ private void processJibriIqFromJibri(JibriIq iq)
XMPPError.Condition.interna_server_error,
"Unknown error");
}
processError(error);
processJibriError(error);
}
else
{
Expand Down Expand Up @@ -625,7 +624,9 @@ private void setJibriStatus(JibriIq.Status newStatus, XMPPError error)
}
}

// Send stop IQ when recording initiator leaves the room
/**
* Sends a "stop" command to jibri.
*/
private XMPPError sendStopIQ()
{
if (recorderComponentJid == null)
Expand Down

0 comments on commit ff84b21

Please sign in to comment.