RingD.h 12.8 KB
Newer Older
1
/**************************************************************************
atraczyk's avatar
atraczyk committed
2
* Copyright (C) 2016 by Savoir-faire Linux                                *
3
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com>              *
4
* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
atraczyk's avatar
atraczyk committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18
*                                                                         *
* This program is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU General Public License as published by    *
* the Free Software Foundation; either version 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program 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 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/>.   *
**************************************************************************/
19
#include <dring.h>
atraczyk's avatar
atraczyk committed
20

atraczyk's avatar
atraczyk committed
21
#include "Ringtone.h"
22
#include "Utils.h"
atraczyk's avatar
atraczyk committed
23

atraczyk's avatar
atraczyk committed
24 25
using namespace concurrency;

atraczyk's avatar
atraczyk committed
26 27
using namespace Windows::UI::Notifications;
using namespace Windows::Data::Xml::Dom;
28
using namespace Windows::UI::ViewManagement;
atraczyk's avatar
atraczyk committed
29

atraczyk's avatar
atraczyk committed
30 31
namespace RingClientUWP
{
atraczyk's avatar
atraczyk committed
32

33
public enum class StartingStatus { NORMAL, REGISTERING_ON_THIS_PC, REGISTERING_THIS_DEVICE };
atraczyk's avatar
atraczyk committed
34

35
/* delegates */
atraczyk's avatar
atraczyk committed
36
delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
Nicolas Jager's avatar
Nicolas Jager committed
37
delegate void StateChange(String^ callId, CallStatus state, int code);
38
delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);
39
delegate void CallPlaced(String^ callId);
40
delegate void IncomingMessage(String^ callId, String^ payload);
41
delegate void DevicesListRefreshed(Map<String^, String^>^ deviceMap);
42
delegate void ExportOnRingEnded(String^ accountId, String^ pin);
43
delegate void SummonWizard();
44
delegate void AccountUpdated(Account^ account);
45
delegate void IncomingVideoMuted(String^ callId, bool state);
46
delegate void RegisteredNameFound(LookupStatus status, const std::string& accountId, const std::string& address, const std::string& name);
47
delegate void FinishCaptureDeviceEnumeration();
48
delegate void RegistrationStateErrorGeneric(const std::string& accountId);
49 50 51 52
delegate void RegistrationStateRegistered(const std::string& accountId);
delegate void RegistrationStateUnregistered(const std::string& accountId);
delegate void RegistrationStateTrying(const std::string& accountId);
delegate void SetOverlayStatusText(String^ statusText, String^ color);
53
delegate void CallsListRecieved(const std::vector<std::string>& callsList);
54
delegate void AudioMuted(const std::string& callId, bool state);
55
delegate void VideoMuted(const std::string& callId, bool state);
56
delegate void FullScreenToggled(bool state);
57 58 59 60 61
delegate void WindowResized(float width, float height);
delegate void NetworkChanged();
delegate void MessageDataLoaded();
delegate void UpdateSmartInfo(const std::map<std::string, std::string>& info);
delegate void MessageStatusUpdated(String^ messageId, int status);
Nicolas Jager's avatar
Nicolas Jager committed
62
delegate void VolatileDetailsChanged(const std::string& accountId, const std::map<std::string, std::string>& details);
63 64 65
delegate void NewBuddyNotification(const std::string& accountId, const std::string& uri, int status);
delegate void VCardUpdated(Contact^ owner);
delegate void ShareRequested();
66
delegate void NameRegistered(bool status, String^ accountId);
67

68 69
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
using namespace std::placeholders;
atraczyk's avatar
atraczyk committed
70 71 72 73 74

public ref class RingD sealed
{
public:
    /* properties */
75 76
    static property RingD^ instance {
        RingD^ get() {
atraczyk's avatar
atraczyk committed
77 78 79 80 81
            static RingD^ instance_ = ref new RingD();
            return instance_;
        }
    }

82 83
    property bool daemonInitialized {
        bool get() {
84 85 86 87
            return daemonInitialized_;
        }
    }

88 89
    property bool daemonRunning {
        bool get() {
atraczyk's avatar
atraczyk committed
90 91 92
            return daemonRunning_;
        }
    }
93

94 95 96 97 98 99 100 101 102 103
    property bool _hasInternet {
        bool get() {
            return hasInternet_;
        }
    }

    property bool isInWizard;

    property bool isFullScreen {
        bool get() {
104 105 106 107
            return ApplicationView::GetForCurrentView()->IsFullScreenMode;
        }
    }

108 109
    property bool isOnXBox {
        bool get() {
110 111 112 113 114 115
            auto dev = Utils::toString(Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily);
            std::transform(dev.begin(), dev.end(), dev.begin(), ::tolower);
            return !dev.compare("windows.xbox");
        }
    }

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    property bool isInBackground {
        bool get() {
            return isInBackground_;
        }
        void set(bool value) {
            isInBackground_ = value;
            connectivityChanged();
        }
    }

    property bool isInvisible {
        bool get() {
            return isInvisible_;
        }
        void set(bool value) {
            isInvisible_ = value;
        }
    }

    property Ringtone^ ringtone {
        Ringtone^ get() {
            return ringtone_;
        }
    }

    property MainPage^ mainPage {
        MainPage^ get() {
            auto frame = dynamic_cast<Windows::UI::Xaml::Controls::Frame^>(Window::Current->Content);
            return dynamic_cast<RingClientUWP::MainPage^>(frame->Content);
        }
    }

148
    property StartingStatus _startingStatus;
atraczyk's avatar
atraczyk committed
149

150 151 152 153
    property bool isCtrlPressed;
    property bool isShiftPressed;

    /* functions */
154
    void cancelOutGoingCall2(String^ callId); // marche
155 156
    void raiseWindowResized(float width, float height);
    void raiseShareRequested();
157

158 159 160 161 162 163 164 165 166
internal: // why this property has to be internal and not public ?
    property Vector<String^>^ _callIdsList
    {
        Vector<String^>^ get()
        {
            return callIdsList_;
        }
    }

167
    std::map<String^, std::function<void(String^ username)>> unpoppedToasts;
168

169 170
    using AccountDetails = std::map<std::string, std::string>;
    using AccountDetailsBlob = std::map<std::string, AccountDetails>;
atraczyk's avatar
atraczyk committed
171
    /* functions */
172
    std::string getLocalFolder();
173 174
    void registerCallbacks();
    void initDaemon(int flags);
atraczyk's avatar
atraczyk committed
175
    void startDaemon();
176 177
    void init();
    void deinit();
178 179 180
    AccountDetailsBlob getAllAccountDetails();
    void parseAccountDetails(const AccountDetailsBlob& allAccountDetails);
    void subscribeBuddies();
181
    void sendAccountTextMessage(String^ message);
182
    void sendSIPTextMessage(String^ message);
183
    void sendSIPTextMessageVCF(std::string callID, std::map<std::string, std::string> message);
Nicolas Jager's avatar
Nicolas Jager committed
184
    void createRINGAccount(String^ alias, String^ archivePassword, bool upnp, String^ registeredName = "");
185
    void createSIPAccount(String^ alias, String^ sipPassword, String^ sipHostname, String^ sipusername);
186 187
    void refuseIncommingCall(String^ call);
    void acceptIncommingCall(String^ call);
Nicolas Jager's avatar
Nicolas Jager committed
188
    void placeCall(Contact^ contact);
189 190
    void pauseCall(const std::string& callId);
    void unPauseCall(const std::string& callId);
191
    CallStatus translateCallStatus(String^ state);
192
    String^ getUserName();
193 194 195
    void startSmartInfo(int refresh);
    void stopSmartInfo();
    void handleIncomingMessage( const std::string& callId,
196 197 198
                                const std::string& accountId,
                                const std::string& from,
                                const std::map<std::string, std::string>& payloads);
199

200 201 202
    void toggleFullScreen();
    void setWindowedMode();
    void setFullScreenMode();
203 204
    void connectivityChanged();
    void onStateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code);
205
    void hangUpCall2(String^ callId);
206 207
    void pauseCall(String ^ callId);
    void unPauseCall(String ^ callId);
208
    void getKnownDevices(String^ accountId);
209
    void ExportOnRing(String^ accountId, String^ password);
210
    void updateAccount(String^ accountId);
211
    void deleteAccount(String^ accountId);
212
    void registerThisDevice(String^ pin, String^ archivePassword);
213
    void muteVideo(String^ callId, bool muted);
214
    void muteAudio(const std::string& callId, bool muted);
215
    void subscribeBuddy(const std::string& accountId, const std::string& uri, bool flag);
Nicolas Jager's avatar
Nicolas Jager committed
216 217
    void registerName(String^ accountId, String^ password, String^ username);
    std::map<std::string, std::string> getVolatileAccountDetails(Account^ account);
218 219
    void lookUpName(const std::string& accountId, String^ name);
    void lookUpAddress(const std::string& accountId, String^ address);
Nicolas Jager's avatar
Nicolas Jager committed
220
    std::string registeredName(Account^ account);
221 222 223 224 225 226 227
    void removeContact(const std::string & accountId, const std::string& uri);
    void sendContactRequest(const std::string& accountId, const std::string& uri, const std::string& payload);
    void raiseMessageDataLoaded();
    void raiseVCardUpdated(Contact^ contact);
    void revokeDevice(const std::string& accountId, const std::string& password, const std::string& deviceId);
    void showLoadingOverlay(String^ text, String^ color);
    void hideLoadingOverlay(String^ text, String^ color, int delayInMilliseconds = 2000);
228
    void OnaccountAdded(const std::string& accountId);
229 230 231 232 233 234
    void OnaccountUpdated();
    void OnaccountDeleted();

    void ShowCallToast(bool background, String^ callId, String^ name = nullptr);
    void ShowIMToast(bool background, String^ from, String^ payload, String^ name = nullptr);
    void HideToast(ToastNotification^ toast);
atraczyk's avatar
atraczyk committed
235 236

    /* TODO : move members */
237
    String ^ currentCallId; // to save ongoing call id during visibility change
atraczyk's avatar
atraczyk committed
238 239 240 241

    /* events */
    event IncomingCall^ incomingCall;
    event StateChange^ stateChange;
242
    event IncomingAccountMessage^ incomingAccountMessage;
243
    event IncomingMessage^ incomingMessage;
244
    event CallPlaced^ callPlaced;
245 246
    event DevicesListRefreshed^ devicesListRefreshed;
    event ExportOnRingEnded^ exportOnRingEnded;
247
    event SummonWizard^ summonWizard;
248
    event AccountUpdated^ accountUpdated;
249
    event IncomingVideoMuted^ incomingVideoMuted;
Nicolas Jager's avatar
Nicolas Jager committed
250
    event RegisteredNameFound^ registeredNameFound;
251
    event FinishCaptureDeviceEnumeration^ finishCaptureDeviceEnumeration;
252 253
    event RegistrationStateErrorGeneric^ registrationStateErrorGeneric;
    event RegistrationStateRegistered^ registrationStateRegistered;
254 255 256
    event RegistrationStateUnregistered^ registrationStateUnregistered;
    event RegistrationStateTrying^ registrationStateTrying;
    event SetOverlayStatusText^ setOverlayStatusText;
257
    event CallsListRecieved^ callsListRecieved; // est implemente a la base pour regler le probleme du boutton d'appel qui est present lorsqu'un appel est en cours, mais il n'est pas utilise. Voir si ca peut servir a autre chose
258
    event AudioMuted^ audioMuted;
259
    event VideoMuted^ videoMuted;
260 261
    event FullScreenToggled^ fullScreenToggled;
    event WindowResized^ windowResized;
262 263 264 265
    event NetworkChanged^ networkChanged;
    event MessageDataLoaded^ messageDataLoaded;
    event UpdateSmartInfo^ updateSmartInfo;
    event MessageStatusUpdated^ messageStatusUpdated;
Nicolas Jager's avatar
Nicolas Jager committed
266
    event VolatileDetailsChanged^ volatileDetailsChanged;
267 268 269
    event NewBuddyNotification^ newBuddyNotification;
    event VCardUpdated^ vCardUpdated;
    event ShareRequested^ shareRequested;
270
    event NameRegistered^ nameRegistered;
atraczyk's avatar
atraczyk committed
271 272

private:
273 274
    Vector<String^>^ callIdsList_;

atraczyk's avatar
atraczyk committed
275 276
    /* functions */
    RingD(); // singleton
277 278 279

    void InternetConnectionChanged(Platform::Object^ sender);
    //CallStatus translateCallStatus(String^ state);
atraczyk's avatar
atraczyk committed
280 281

    /* members */
282 283
    Windows::UI::Core::CoreDispatcher^ dispatcher;

284 285 286
    bool hasInternet_;
    bool isAddingDevice     = false;
    bool isAddingAccount    = false;
287 288
    bool shouldRegister     = false;
    String^ nameToRegister  = "";
289 290 291 292
    bool isUpdatingAccount  = false;
    bool isDeletingAccount  = false;
    bool isInBackground_    = false;
    bool isInvisible_       = false;
293
    bool daemonInitialized_ = false;
294 295 296 297 298
    bool daemonRunning_     = false;
    bool debugModeOn_       = true;
    bool callToastPopped_   = false;

    std::string localFolder_;
299
    Utils::task_queue tasks_;
300
    StartingStatus startingStatus_ = StartingStatus::NORMAL;
atraczyk's avatar
atraczyk committed
301
    Ringtone^ ringtone_;
302

303 304 305 306
    ToastNotification^ toastText;
    ToastNotification^ toastCall;
    Windows::UI::Notifications::ToastNotifier^ toaster;

307
    std::map<std::string, SharedCallback> callHandlers;
308 309 310
    std::map<std::string, SharedCallback> configurationHandlers;
    std::map<std::string, SharedCallback> presenceHandlers;
    std::map<std::string, SharedCallback> videoHandlers;
atraczyk's avatar
atraczyk committed
311
};
Nicolas Jager's avatar
Nicolas Jager committed
312
}