Search in sources :

Example 6 with ServiceDiscoveryResult

use of eu.siacs.conversations.entities.ServiceDiscoveryResult in project Conversations by siacs.

the class JingleFileTransferConnection method getRemoteFeatures.

private List<String> getRemoteFeatures() {
    final String resource = Strings.nullToEmpty(this.id.with.getResource());
    final Presence presence = this.id.account.getRoster().getContact(id.with).getPresences().get(resource);
    final ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null;
    return result == null ? Collections.emptyList() : result.getFeatures();
}
Also used : ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Presence(eu.siacs.conversations.entities.Presence)

Example 7 with ServiceDiscoveryResult

use of eu.siacs.conversations.entities.ServiceDiscoveryResult in project Conversations by siacs.

the class RtpCapability method check.

public static Capability check(final Presence presence) {
    final ServiceDiscoveryResult disco = presence.getServiceDiscoveryResult();
    final List<String> features = disco == null ? Collections.emptyList() : disco.getFeatures();
    if (features.containsAll(BASIC_RTP_REQUIREMENTS)) {
        if (features.containsAll(VIDEO_REQUIREMENTS)) {
            return Capability.VIDEO;
        }
        if (features.contains(Namespace.JINGLE_FEATURE_AUDIO)) {
            return Capability.AUDIO;
        }
    }
    return Capability.NONE;
}
Also used : ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult)

Example 8 with ServiceDiscoveryResult

use of eu.siacs.conversations.entities.ServiceDiscoveryResult in project Conversations by siacs.

the class XmppConnection method sendServiceDiscoveryInfo.

private void sendServiceDiscoveryInfo(final Jid jid) {
    mPendingServiceDiscoveries.incrementAndGet();
    final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
    iq.setTo(jid);
    iq.query("http://jabber.org/protocol/disco#info");
    this.sendIqPacket(iq, (account, packet) -> {
        if (packet.getType() == IqPacket.TYPE.RESULT) {
            boolean advancedStreamFeaturesLoaded;
            synchronized (XmppConnection.this.disco) {
                ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet);
                if (jid.equals(account.getDomain())) {
                    mXmppConnectionService.databaseBackend.insertDiscoveryResult(result);
                }
                disco.put(jid, result);
                advancedStreamFeaturesLoaded = disco.containsKey(account.getDomain()) && disco.containsKey(account.getJid().asBareJid());
            }
            if (advancedStreamFeaturesLoaded && (jid.equals(account.getDomain()) || jid.equals(account.getJid().asBareJid()))) {
                enableAdvancedStreamFeatures();
            }
        } else if (packet.getType() == IqPacket.TYPE.ERROR) {
            Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco info for " + jid.toString());
            final boolean serverOrAccount = jid.equals(account.getDomain()) || jid.equals(account.getJid().asBareJid());
            final boolean advancedStreamFeaturesLoaded;
            if (serverOrAccount) {
                synchronized (XmppConnection.this.disco) {
                    disco.put(jid, ServiceDiscoveryResult.empty());
                    advancedStreamFeaturesLoaded = disco.containsKey(account.getDomain()) && disco.containsKey(account.getJid().asBareJid());
                }
            } else {
                advancedStreamFeaturesLoaded = false;
            }
            if (advancedStreamFeaturesLoaded) {
                enableAdvancedStreamFeatures();
            }
        }
        if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
            if (mPendingServiceDiscoveries.decrementAndGet() == 0 && mWaitForDisco.compareAndSet(true, false)) {
                finalizeBind();
            }
        }
    });
}
Also used : ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 9 with ServiceDiscoveryResult

use of eu.siacs.conversations.entities.ServiceDiscoveryResult in project Conversations by siacs.

the class DatabaseBackend method findDiscoveryResult.

public ServiceDiscoveryResult findDiscoveryResult(final String hash, final String ver) {
    SQLiteDatabase db = this.getReadableDatabase();
    String[] selectionArgs = { hash, ver };
    Cursor cursor = db.query(ServiceDiscoveryResult.TABLENAME, null, ServiceDiscoveryResult.HASH + "=? AND " + ServiceDiscoveryResult.VER + "=?", selectionArgs, null, null, null);
    if (cursor.getCount() == 0) {
        cursor.close();
        return null;
    }
    cursor.moveToFirst();
    ServiceDiscoveryResult result = null;
    try {
        result = new ServiceDiscoveryResult(cursor);
    } catch (JSONException e) {
    /* result is still null */
    }
    cursor.close();
    return result;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) JSONException(org.json.JSONException) Cursor(android.database.Cursor)

Aggregations

ServiceDiscoveryResult (eu.siacs.conversations.entities.ServiceDiscoveryResult)9 Presence (eu.siacs.conversations.entities.Presence)3 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)3 Pair (android.util.Pair)2 Element (eu.siacs.conversations.xml.Element)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 JabberIdContact (eu.siacs.conversations.android.JabberIdContact)1 Account (eu.siacs.conversations.entities.Account)1 Bookmark (eu.siacs.conversations.entities.Bookmark)1 Contact (eu.siacs.conversations.entities.Contact)1 MucOptions (eu.siacs.conversations.entities.MucOptions)1 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 EnablePacket (eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket)1 JSONException (org.json.JSONException)1