diff options
author | paweldomas <pawel.domas@jitsi.org> | 2016-05-13 12:50:09 -0500 |
---|---|---|
committer | paweldomas <pawel.domas@jitsi.org> | 2016-05-13 12:51:42 -0500 |
commit | 8446ee2895b6223abd238e8c92a068f7808acc87 (patch) | |
tree | a17b5b246d23a023cdd3a08cc5bc6fa845129bc6 | |
parent | a07c8181f07d1e5874b3cd3de76f0558a39db6f6 (diff) | |
download | jitsi-8446ee2895b6223abd238e8c92a068f7808acc87.zip jitsi-8446ee2895b6223abd238e8c92a068f7808acc87.tar.gz jitsi-8446ee2895b6223abd238e8c92a068f7808acc87.tar.bz2 |
Add "error" and "busy" state to Jibri
4 files changed, 195 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIq.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIq.java index 87abf9a..c49774b 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIq.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIq.java @@ -83,6 +83,11 @@ public class JibriIq private Action action = Action.UNDEFINED; /** + * XMPPError stores error details for {@link Status#ERROR}. + */ + private XMPPError error; + + /** * Holds recording status. */ private Status status = Status.UNDEFINED; @@ -232,6 +237,28 @@ public class JibriIq } /** + * 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. * * @author lishunyang @@ -312,6 +339,17 @@ public class JibriIq 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. */ UNDEFINED("undefined"); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIqProvider.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIqProvider.java index ad3a134..155853c 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIqProvider.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/JibriIqProvider.java @@ -21,6 +21,7 @@ import org.jitsi.util.*; 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 class JibriIqProvider { 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(); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/RecordingStatus.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/RecordingStatus.java index 80e6c42..13177cf 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/RecordingStatus.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/RecordingStatus.java @@ -19,6 +19,10 @@ package net.java.sip.communicator.impl.protocol.jabber.extensions.jibri; 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 class RecordingStatus { 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()); + } + } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/XMPPErrorPE.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/XMPPErrorPE.java new file mode 100644 index 0000000..a72f310 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jibri/XMPPErrorPE.java @@ -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(); + } +} |