newcallmodel.h 5.88 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1 2
/****************************************************************************
 *   Copyright (C) 2017 Savoir-faire Linux                                  *
Nicolas Jager's avatar
Nicolas Jager committed
3 4
 *   Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com>             *
 *   Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>           *
Nicolas Jager's avatar
Nicolas Jager committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 of the License, or (at your option) any later version.     *
 *                                                                          *
 *   This library is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#pragma once

// Std
#include <memory>
#include <string>
#include <map>

// Qt
#include <qobject.h>

29 30 31 32 33 34 35 36
// Data
#include "api/call.h"
#include "api/account.h"

namespace Video {
class Renderer;
}

Nicolas Jager's avatar
Nicolas Jager committed
37 38 39
namespace lrc
{

40
class CallbacksHandler;
Nicolas Jager's avatar
Nicolas Jager committed
41 42 43 44 45 46 47 48 49
class NewCallModelPimpl;

namespace api
{

namespace account { struct Info; }
namespace call { struct Info; }
class NewAccountModel;

50 51 52
/**
  *  @brief Class that manages call informations.
  */
Nicolas Jager's avatar
Nicolas Jager committed
53 54
class NewCallModel : public QObject {
    Q_OBJECT
55

Nicolas Jager's avatar
Nicolas Jager committed
56 57 58 59 60 61 62 63 64 65 66
public:
    using CallInfoMap = std::map<std::string, std::shared_ptr<call::Info>>;

    const account::Info& owner;

    enum class Media {
        NONE,
        AUDIO,
        VIDEO
    };

67
    NewCallModel(const account::Info& owner, const CallbacksHandler& callbacksHandler);
Nicolas Jager's avatar
Nicolas Jager committed
68 69
    ~NewCallModel();

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    /**
     * Create a new call with a contact
     * @param  url of the contact to call
     * @return the call uid created
     */
    std::string createCall(const std::string& url);
    /**
     * Get the call from its call id
     * @param  uid
     * @return the callInfo
     * @throw out_of_range exception if not found
     */
    const call::Info& getCall(const std::string& uid) const;
    /**
     * Get the call from the peer uri
     * @param  uri
     * @return the callInfo
     * @throw out_of_range exception if not found
     */
89
    const call::Info& getCallFromURI(const std::string& uri) const;
90 91 92 93 94 95 96 97 98 99 100
    /**
     * @param  callId to test
     * @return true if callId is presend else false.
     */
    bool hasCall(const std::string& callId);
    /**
     * Send a text message to a SIP call
     * @param callId
     * @param body of the message
     */
    void sendSipMessage(const std::string& callId, const std::string& body) const;
Nicolas Jager's avatar
Nicolas Jager committed
101

102 103 104 105 106 107 108 109 110
    /**
     * Accept a call
     * @param callId
     */
    void accept(const std::string& callId) const;
    /**
     * Hang up a call
     * @param callId
     */
Nicolas Jager's avatar
Nicolas Jager committed
111
    void hangUp(const std::string& callId) const;
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    /**
     * Toggle audio record on a call
     * @param callId
     */
    void toggleAudioRecord(const std::string& callId) const;
    /**
     * Play DTMF in a call
     * @param callId
     * @param value to play
     */
    void playDTMF(const std::string& callId, const std::string& value) const;
    /**
     * Toggle pause on a call
     * @param callId
     */
Nicolas Jager's avatar
Nicolas Jager committed
127
    void togglePause(const std::string& callId) const;
128 129 130 131 132 133 134 135 136 137
    /**
     * Toggle a media on a call
     * @param callId
     * @param media {AUDIO, VIDEO}
     * @param flag is muted
     */
    void toggleMedia(const std::string& callId, const NewCallModel::Media media, bool flag) const;
    /**
     * Not implemented yet
     */
Nicolas Jager's avatar
Nicolas Jager committed
138
    void setQuality(const std::string& callId, const double quality) const;
139 140 141
    /**
     * Not implemented yet
     */
Nicolas Jager's avatar
Nicolas Jager committed
142
    void transfer(const std::string& callId, const std::string& to) const;
143
    /**
144 145 146
     * Create a conference from 2 calls.
     * @param callIdA uid of the call A
     * @param callIdB uid of the call B
147
     */
148
    void joinCalls(const std::string& callIdA, const std::string& callIdB) const;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    /**
     * Not implemented yet
     */
    void removeParticipant(const std::string& callId, const std::string& participant) const;
    /**
     * @param  callId
     * @return the renderer linked to a call
     */
    Video::Renderer* getRenderer(const std::string& callId) const;
    /**
     * @param  callId
     * @return a human readable call duration (M:ss)
     */
    std::string getFormattedCallDuration(const std::string& callId) const;

Q_SIGNALS:
    /**
     * Emitted when a call state changes
     * @param callId
     */
    void callStatusChanged(const std::string& callId) const;
    /**
     * Emitted when a call starts
     * @param callId
     */
    void callStarted(const std::string& callId) const;
    /**
     * Emitted when a call is over
     * @param callId
     */
    void callEnded(const std::string& callId) const;
    /**
     * Emitted when a call is incoming
     * @param callId
     * @param fromId the peer uri
     */
    void newIncomingCall(const std::string& callId, const std::string& fromId) const;
    /**
     * Emitted when the renderer starts
     * @param callId
     * @param renderer
     */
    void remotePreviewStarted(const std::string& callId, Video::Renderer* renderer) const;
192 193 194 195 196 197
    /**
     * Emitted when a call is added to a conference
     * @param callId
     * @param confId
     */
    void callAddedToConference(const std::string& callId, const std::string& confId) const;
Nicolas Jager's avatar
Nicolas Jager committed
198 199 200 201 202 203 204

private:
    std::unique_ptr<NewCallModelPimpl> pimpl_;
};

} // namespace api
} // namespace lrc