Skip to content

Commit

Permalink
Extend OperationFailedException and lobby support (#699)
Browse files Browse the repository at this point in the history
* Add DataObject for OperationFailedException

* Handle XMPP registration exception

* Add lobby jid null check

Co-authored-by: Cristian Florin Ghita <cristian.ghita@8x8.com>
  • Loading branch information
theunafraid and cristifg committed Jul 10, 2020
1 parent 7ff39b0 commit 034233f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,47 @@ public ChatRoomJabberImpl(MultiUserChat multiUserChat,
new StanzaTypeFilter(org.jivesoftware.smack.packet.Message.class));
}

/**
* Returns a Jid for associated lobby room with this chat room.
*
* @return <tt>Jid</tt> lobby room Jid.
*/
private Jid getLobbyJidFromPacket(Stanza packet)
{
Jid lobbyJid = null;

/**
* This method is used to get a Jid that represents the lobby room that the user joins when trying
* to join a meeting with lobby enabled. The custom <lobbyroom></lobbyroom> field is added to the error
* in case the user is not yet a member of the meeting that was joined initially.
*/

try
{
if (packet != null)
{
ExtensionElement lobbyExtension = packet.getExtension("lobbyroom", "jabber:client");

if (lobbyExtension instanceof StandardExtensionElement)
{
StandardExtensionElement lobbyStandardExtension = (StandardExtensionElement) lobbyExtension;

String lobbyJidString = lobbyStandardExtension.getText();

EntityBareJid lobbyFullJid = JidCreate.entityBareFrom(lobbyJidString);

lobbyJid = lobbyFullJid;
}
}
}
catch(Exception ex)
{
logger.error(ex.toString());
}

return lobbyJid;
}

/**
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
*
Expand Down Expand Up @@ -727,10 +768,30 @@ else if(ex.getXMPPError().getCondition() == registration_required)

logger.error(errorMessage, ex);

throw new OperationFailedException(
OperationFailedException operationFailedException = new OperationFailedException(
errorMessage,
OperationFailedException.REGISTRATION_REQUIRED,
ex);

DataObject dataObject = operationFailedException.getDataObject();

if (dataObject != null)
{
Stanza stanzaError = ex.getXMPPError().getStanza();

Jid lobbyJid = getLobbyJidFromPacket(stanzaError);

if (lobbyJid != null)
{
dataObject.setData("lobbyroomjid", lobbyJid);
}
else
{
logger.warn("No lobby Jid! But registration required!");
}
}

throw operationFailedException;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package net.java.sip.communicator.service.protocol;

import net.java.sip.communicator.util.*;

/**
* <tt>OperationFailedException</tt> indicates an exception that occurred in the
* API.
Expand Down Expand Up @@ -160,6 +162,11 @@ public class OperationFailedException
*/
private final int errorCode;

/**
* Map that can be used for additional info about the failure.
*/
private final DataObject dataObject = new DataObject();

/**
* Creates an exception with the specified error message and error code.
* @param message A message containing details on the error that caused the
Expand Down Expand Up @@ -199,4 +206,13 @@ public int getErrorCode()
{
return errorCode;
}

/**
* Obtain the <tt>DataObject</tt> that may contain additional info.
*
* @return <tt>DataObject</tt> additional info.
*/
public DataObject getDataObject() {
return dataObject;
}
}

0 comments on commit 034233f

Please sign in to comment.