audiocallmanager.cpp 3,8 КБ
Newer Older
Denis Grigorev's avatar
Denis Grigorev включено в состав коммита
1
2
3
4
5
#include <callfactoryinterface.h>

#include "audiocallmanager.h"
#include "audiocall.h"

Denis Grigorev's avatar
Denis Grigorev включено в состав коммита
6
using ru::auroraos::call::AudioContext;
Denis Grigorev's avatar
Denis Grigorev включено в состав коммита
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using ru::auroraos::call::Call;
using ru::auroraos::call::CallManager;
using ru::auroraos::call::CallFactoryInterface;

static const auto SCHEME = QStringLiteral("ruauroraosaudiocallexample.://");

class AudioCallFactory : public CallFactoryInterface
{
    Call *newCall(CallManager *manager,
                 const QString &id,
                 const QVariantMap &parameters,
                 QObject *parent) override {
        return new AudioCall(manager, id, parameters, parent);
    }
};

Q_GLOBAL_STATIC(AudioCallFactory, audioCallFactory);

AudioCallManager::AudioCallManager(const QString &accountId, QObject *parent)
Denis Grigorev's avatar
Denis Grigorev включено в состав коммита
26
    : CallManager(accountId, parent)
Denis Grigorev's avatar
Denis Grigorev включено в состав коммита
27
    , m_audioContext(this)
Denis Grigorev's avatar
Denis Grigorev включено в состав коммита
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    , m_callId(1)
    , m_holdable(true)
    , m_redialable(true)
{
    setCallFactory(audioCallFactory);
}

Call *AudioCallManager::newCall(QVariantMap &properties)
{
    // Do not allow calls with empty remoteHandle (who do we call?).
    QString remoteHandle = properties[QStringLiteral("remoteHandle")].value<QString>();
    if (remoteHandle.isEmpty())
        return nullptr;

    // Display remoteHandle if a human-readable remoteId is not provided.
    QString remoteId = properties[QStringLiteral("remoteId")].value<QString>();
    if (remoteId.isEmpty())
        properties[QStringLiteral("remoteId")] = remoteHandle;

    // Whether SetHold() calls are welcome.
    properties[QStringLiteral("holdable")] = m_holdable;

    // Fill local account name.
    properties[QStringLiteral("localHandle")] = QStringLiteral("CallExample");
    properties[QStringLiteral("localId")] = QStringLiteral("CallExample");

    if (m_redialable)
        properties[QStringLiteral("uri")] = SCHEME + remoteHandle;

    QString id = QString::number(m_callId++);

    return CallManager::newCall(id, properties);
}

Call *AudioCallManager::initiateCall(const QVariantMap &props)
{
    QVariantMap properties(props);
    properties[QStringLiteral("incoming")] = false;

    return newCall(properties);
}

Call *AudioCallManager::reportIncomingCall(const QVariantMap &props)
{
    QVariantMap properties(props);
    properties[QStringLiteral("incoming")] = true;

    return newCall(properties);
}

void AudioCallManager::openUri(const QString &uri)
{
    qInfo() << uri;

    if (uri.startsWith(SCHEME)) {
        QString tmp(uri);
        const QString handle = tmp.replace(SCHEME, QStringLiteral(""));
        if (!handle.isEmpty()) {
            for (const auto &call : calls()) {
                if (uri == getCall(call)->uri()) {
                    // The call is already set up. Show the corresponding UI page.
                    qInfo() << "display the current call" << getCall(call)->callId();
                    return;
                }
            }

            QVariantMap properties;
            properties[QStringLiteral("incoming")] = false;
            properties[QStringLiteral("remoteHandle")] = handle;
            // FIXME: Parse remoteId from URI.
            properties[QStringLiteral("remoteId")] = QStringLiteral("Outgoing call ") + handle;

            newCall(properties);
            return;
        }
    }
    qWarning() << "Invalid URI" << uri;
}

bool AudioCallManager::holdable() const
{
    return m_holdable;
}

void AudioCallManager::setHoldable(bool on)
{
    if (on != m_holdable) {
        m_holdable = on;
        emit holdableChanged(on);
    }
}

bool AudioCallManager::redialable() const
{
    return m_redialable;
}

void AudioCallManager::setRedialable(bool on)
{
    if (m_redialable != on) {
        m_redialable = on;
        emit redialableChanged(on);
    }
}

AudioCall *AudioCallManager::getAudioCall(const QString &callId) const
{
    return qobject_cast<AudioCall*>(getCall(callId));
}