org.jivesoftware.smackx.carbons.CarbonManager Java Examples

The following examples show how to use org.jivesoftware.smackx.carbons.CarbonManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OperationSetBasicInstantMessagingJabberImpl.java    From jitsi with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the carbon is supported by the server or not.
 * @return <tt>true</tt> if carbon is supported by the server and
 * <tt>false</tt> if not.
 */
private boolean isCarbonSupported()
{
    try
    {
        return CarbonManager.getInstanceFor(jabberProvider.getConnection())
            .isSupportedByServer();
    }
    catch (XMPPException
        | InterruptedException
        | NoResponseException
        | NotConnectedException e)
    {
       logger.warn("Failed to retrieve carbon support", e);
    }

    return false;
}
 
Example #2
Source File: OmemoManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Register stanza listeners needed for OMEMO.
 * This method is called automatically in the constructor and should only be used to restore the previous state
 * after {@link #stopStanzaAndPEPListeners()} was called.
 */
public void resumeStanzaAndPEPListeners() {
    CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());

    // Remove listeners to avoid them getting added twice
    connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
    carbonManager.removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);

    // Add listeners
    pepManager.addPepEventListener(OmemoConstants.PEP_NODE_DEVICE_LIST, OmemoDeviceListElement.class, pepOmemoDeviceListEventListener);
    connection().addAsyncStanzaListener(this::internalOmemoMessageStanzaListener, OmemoManager::isOmemoMessage);
    carbonManager.addCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
}
 
Example #3
Source File: OperationSetBasicInstantMessagingJabberImpl.java    From jitsi with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize carbons.
 */
private void initAdditionalServices()
{
    CarbonManager cm = CarbonManager.getInstanceFor(
        jabberProvider.getConnection());
    boolean enableCarbon
        = isCarbonSupported() && !jabberProvider.getAccountID()
        .getAccountPropertyBoolean(
            ProtocolProviderFactory.IS_CARBON_DISABLED,
            false);
    if(enableCarbon)
    {
        try
        {
            cm.enableCarbons();
            cm.addCarbonCopyReceivedListener(new CarbonCopyReceivedListener()
            {
                
                @Override
                public void onCarbonCopyReceived(Direction direction,
                    org.jivesoftware.smack.packet.Message carbonCopy,
                    org.jivesoftware.smack.packet.Message wrappingMessage)
                {
                    processMessage(carbonCopy, direction == Direction.sent);
                }
            });
        }
        catch (XMPPException | SmackException | InterruptedException e)
        {
            isCarbonEnabled = false;
            logger.warn("Could not enable carbons", e);
        }
    }
    else
    {
        isCarbonEnabled = false;
    }
}
 
Example #4
Source File: OmemoManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * Remove active stanza listeners needed for OMEMO.
 */
public void stopStanzaAndPEPListeners() {
    pepManager.removePepEventListener(pepOmemoDeviceListEventListener);
    connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
    CarbonManager.getInstanceFor(connection()).removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
}