Add "error" and "busy" state to Jibri

sip-call-params
paweldomas 10 years ago
parent a07c8181f0
commit 8446ee2895

@ -82,6 +82,11 @@ public class JibriIq
*/
private Action action = Action.UNDEFINED;
/**
* XMPPError stores error details for {@link Status#ERROR}.
*/
private XMPPError error;
/**
* Holds recording status.
*/
@ -231,6 +236,28 @@ public Status getStatus()
return status;
}
/**
* Sets the <tt>XMPPError</tt> which will provide details about Jibri
* failure. It is expected to be set when this IQ's status value is
* {@link Status#ERROR}.
*
* @param error <tt>XMPPError</tt> to be set on this <tt>JibriIq</tt>
* instance.
*/
public void setXMPPError(XMPPError error)
{
this.error = error;
}
/**
* Returns {@link XMPPError} with Jibri error details when the status is
* {@link Status#ERROR}.
*/
public XMPPError getError()
{
return error;
}
/**
* Enumerative value of attribute "action" in recording extension.
*
@ -311,6 +338,17 @@ public enum Status
*/
PENDING("pending"),
/**
* An error occurred any point during startup, recording or shutdown.
*/
ERROR("error"),
/**
* There are Jibri instances connected to the system, but all of them
* are currently busy.
*/
BUSY("busy"),
/**
* Unknown/uninitialized.
*/

@ -21,6 +21,7 @@
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.*;
@ -82,6 +83,17 @@ public IQ parseIQ(XmlPullParser parser)
{
switch (parser.next())
{
case XmlPullParser.START_TAG:
{
String name = parser.getName();
if ("error".equals(name))
{
XMPPError error = PacketParserUtils.parseError(parser);
iq.setXMPPError(error);
}
break;
}
case XmlPullParser.END_TAG:
{
String name = parser.getName();

@ -19,6 +19,10 @@
import net.java.sip.communicator.impl.protocol.jabber.extensions.*;
import org.jivesoftware.smack.packet.*;
import java.util.*;
/**
* The packet extension added to Jicofo MUC presence to broadcast current
* recording status to all conference participants.
@ -71,4 +75,52 @@ public void setStatus(JibriIq.Status status)
{
setAttribute(STATUS_ATTRIBUTE, String.valueOf(status));
}
/**
* Returns <tt>XMPPError</tt> associated with current
* {@link RecordingStatus}.
*/
public XMPPError getError()
{
XMPPErrorPE errorPe = getErrorPE();
return errorPe != null ? errorPe.getError() : null;
}
/**
* Gets <tt>{@link XMPPErrorPE}</tt> from the list of child packet
* extensions.
* @return {@link XMPPErrorPE} or <tt>null</tt> if not found.
*/
private XMPPErrorPE getErrorPE()
{
List<? extends PacketExtension> errorPe
= getChildExtensionsOfType(XMPPErrorPE.class);
return (XMPPErrorPE) (!errorPe.isEmpty() ? errorPe.get(0) : null);
}
/**
* Sets <tt>XMPPError</tt> on this <tt>RecordingStatus</tt>.
* @param error <tt>XMPPError</tt> to add error details to this
* <tt>RecordingStatus</tt> instance or <tt>null</tt> to have it removed.
*/
public void setError(XMPPError error)
{
if (error != null)
{
// Wrap and add XMPPError as packet extension
XMPPErrorPE errorPe = getErrorPE();
if (errorPe == null)
{
errorPe = new XMPPErrorPE(error);
addChildExtension(errorPe);
}
errorPe.setError(error);
}
else
{
// Remove error PE
getChildExtensions().remove(getErrorPE());
}
}
}

@ -0,0 +1,93 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.jibri;
import org.jivesoftware.smack.packet.*;
import java.util.*;
/**
* Wraps Smack's <tt>XMPPError</tt> into <tt>PacketExtension</tt>, so that it
* can be easily inserted into {@link RecordingStatus}.
*/
public class XMPPErrorPE
implements PacketExtension
{
/**
* <tt>XMPPError</tt> wrapped into this <tt>XMPPErrorPE</tt>.
*/
private XMPPError error;
/**
* Creates new instance of <tt>XMPPErrorPE</tt>.
* @param xmppError the instance of <tt>XMPPError</tt> that will be wrapped
* by the newly created <tt>XMPPErrorPE</tt>.
*/
public XMPPErrorPE(XMPPError xmppError)
{
setError(xmppError);
}
/**
* Returns the underlying instance of <tt>XMPPError</tt>.
*/
public XMPPError getError()
{
return error;
}
/**
* Sets new instance of <tt>XMPPError</tt> to be wrapped by this
* <tt>XMPPErrorPE</tt>.
* @param error <tt>XMPPError</tt> that will be wrapped by this
* <TT>XMPPErrorPE</TT>.
*/
public void setError(XMPPError error)
{
Objects.requireNonNull(error, "error");
this.error = error;
}
/**
* {@inheritDoc}
*/
@Override
public String getElementName()
{
return "error";
}
/**
* {@inheritDoc}
*/
@Override
public String getNamespace()
{
return "";
}
/**
* {@inheritDoc}
*/
@Override
public String toXML()
{
return error.toXML();
}
}
Loading…
Cancel
Save