RingD.h 10.6 KB
Newer Older
1
/**************************************************************************
atraczyk's avatar
atraczyk committed
2
* Copyright (C) 2016 by Savoir-faire Linux                                *
3
4
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <traczyk.andreas@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"
atraczyk's avatar
atraczyk committed
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
28
using namespace Windows::UI::Notifications;
using namespace Windows::Data::Xml::Dom;

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

32
33
34
35
// its ok to keep this enum here and to use it with the wizard, because in pch.h headers are a-z sorted,
// but it would be much more consistent to move this enum in globals.h when merged

public enum class StartingStatus { NORMAL, REGISTERING_ON_THIS_PC, REGISTERING_THIS_DEVICE };
atraczyk's avatar
atraczyk committed
36
37
38

/* delegate */
delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
Nicolas Jager's avatar
Nicolas Jager committed
39
delegate void StateChange(String^ callId, CallStatus state, int code);
40
delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);
41
delegate void CallPlaced(String^ callId);
Nicolas Jager's avatar
Nicolas Jager committed
42
delegate void IncomingMessage(String^ callId, String^ payload);
43
44
delegate void DevicesListRefreshed(Vector<String^>^ devicesList);
delegate void ExportOnRingEnded(String^ accountId, String^ pin);
45
delegate void SummonWizard();
46
delegate void AccountUpdated(Account^ account);
47
delegate void IncomingVideoMuted(String^ callId, bool state);
48
delegate void RegisteredNameFound(LookupStatus status, const std::string& address, const std::string& name);
49
delegate void FinishCaptureDeviceEnumeration();
50
51
delegate void RegistrationStateErrorGeneric(const std::string& accountId);
delegate void RegistrationStateRegistered();
52
delegate void SetLoadingStatusText(String^ statusText, String^ color);
Nicolas Jager's avatar
Nicolas Jager committed
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);
Nicolas Jager's avatar
Nicolas Jager committed
56
delegate void NameRegistred(bool status);
57
delegate void ToggleFullScreen(bool state);
Nicolas Jager's avatar
Nicolas Jager committed
58
delegate void VolatileDetailsChanged(const std::string& accountId, const std::map<std::string, std::string>& details);
59

60
61
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
using namespace std::placeholders;
atraczyk's avatar
atraczyk committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

public ref class RingD sealed
{
public:
    /* functions */

    /* properties */
    static property RingD^ instance
    {
        RingD^ get()
        {
            static RingD^ instance_ = ref new RingD();
            return instance_;
        }
    }

78
79
80
81
82
83
84
85
    property bool daemonInitialized
    {
        bool get()
        {
            return daemonInitialized_;
        }
    }

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

atraczyk's avatar
atraczyk committed
94
95
96
97
98
99
100
101
102
103
    property bool isOnXBox
    {
        bool get()
        {
            auto dev = Utils::toString(Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily);
            std::transform(dev.begin(), dev.end(), dev.begin(), ::tolower);
            return !dev.compare("windows.xbox");
        }
    }

atraczyk's avatar
atraczyk committed
104
    property bool isInBackground;
105
    property StartingStatus _startingStatus;
atraczyk's avatar
atraczyk committed
106

107
108
    void cancelOutGoingCall2(String^ callId); // marche

109
110
111
112
113
114
115
116
117
internal: // why this property has to be internal and not public ?
    property Vector<String^>^ _callIdsList
    {
        Vector<String^>^ get()
        {
            return callIdsList_;
        }
    }

118

atraczyk's avatar
atraczyk committed
119
120
internal:
    /* functions */
atraczyk's avatar
atraczyk committed
121
    std::string getLocalFolder();
122
123
    void registerCallbacks();
    void initDaemon(int flags);
atraczyk's avatar
atraczyk committed
124
    void startDaemon();
125
126
    void init();
    void deinit();
atraczyk's avatar
atraczyk committed
127
    void reloadAccountList();
Nicolas Jager's avatar
Nicolas Jager committed
128
    void sendAccountTextMessage(String^ message);
129
    void sendSIPTextMessage(String^ message);
atraczyk's avatar
atraczyk committed
130
    void sendSIPTextMessageVCF(std::string callID, std::map<std::string, std::string> message);
Nicolas Jager's avatar
Nicolas Jager committed
131
    void createRINGAccount(String^ alias, String^ archivePassword, bool upnp, String^ registeredName = "");
132
    void createSIPAccount(String^ alias, String^ sipPassword, String^ sipHostname, String^ sipusername);
133
134
    void refuseIncommingCall(String^ call);
    void acceptIncommingCall(String^ call);
Nicolas Jager's avatar
Nicolas Jager committed
135
    void placeCall(Contact^ contact);
136
137
    void pauseCall(const std::string& callId);
    void unPauseCall(const std::string& callId);
138
    /*void cancelOutGoingCall2(String^ callId);*/ // marche pas
Nicolas Jager's avatar
Nicolas Jager committed
139
    CallStatus translateCallStatus(String^ state);
atraczyk's avatar
atraczyk committed
140
    String^ getUserName();
Nicolas Jager's avatar
Nicolas Jager committed
141
    Vector<String^>^ translateKnownRingDevices(const std::map<std::string, std::string> devices);
142

143
144
    void raiseToggleFullScreen();

145
    void hangUpCall2(String^ callId);
146
147
    void pauseCall(String ^ callId);
    void unPauseCall(String ^ callId);
Nicolas Jager's avatar
Nicolas Jager committed
148
    void askToRefreshKnownDevices(String^ accountId);
149
    void askToExportOnRing(String^ accountId, String^ password);
150
    void eraseCacheFolder();
151
    void updateAccount(String^ accountId);
152
    void deleteAccount(String^ accountId);
153
    void registerThisDevice(String^ pin, String^ archivePassword);
154
155
156
    void getCallsList();
    void killCall(String^ callId);
    void switchDebug();
157
    void muteVideo(String^ callId, bool muted);
158
    void muteAudio(const std::string& callId, bool muted);
Nicolas Jager's avatar
Nicolas Jager committed
159
160
161
162
163
164
    void lookUpName(String^ name);
    void registerName(String^ accountId, String^ password, String^ username);
    void registerName_new(const std::string& accountId, const std::string& password, const std::string& username);
    std::map<std::string, std::string> getVolatileAccountDetails(Account^ account);
    void lookUpAddress(String^ address);
    std::string registeredName(Account^ account);
atraczyk's avatar
atraczyk committed
165
166

    /* TODO : move members */
167
    String ^ currentCallId; // to save ongoing call id during visibility change
atraczyk's avatar
atraczyk committed
168
169
170
171

    /* events */
    event IncomingCall^ incomingCall;
    event StateChange^ stateChange;
172
    event IncomingAccountMessage^ incomingAccountMessage;
173
    event IncomingMessage^ incomingMessage;
174
    event CallPlaced^ callPlaced;
175
176
    event DevicesListRefreshed^ devicesListRefreshed;
    event ExportOnRingEnded^ exportOnRingEnded;
177
    event SummonWizard^ summonWizard;
178
    event AccountUpdated^ accountUpdated;
179
    event IncomingVideoMuted^ incomingVideoMuted;
Nicolas Jager's avatar
Nicolas Jager committed
180
    event RegisteredNameFound^ registeredNameFound;
181
    event FinishCaptureDeviceEnumeration^ finishCaptureDeviceEnumeration;
182
183
    event RegistrationStateErrorGeneric^ registrationStateErrorGeneric;
    event RegistrationStateRegistered^ registrationStateRegistered;
184
    event SetLoadingStatusText^ setLoadingStatusText;
Nicolas Jager's avatar
Nicolas Jager committed
185
    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
186
    event AudioMuted^ audioMuted;
187
    event VideoMuted^ videoMuted;
Nicolas Jager's avatar
Nicolas Jager committed
188
    event NameRegistred^ nameRegistred;
189
    event ToggleFullScreen^ toggleFullScreen;
Nicolas Jager's avatar
Nicolas Jager committed
190
    event VolatileDetailsChanged^ volatileDetailsChanged;
atraczyk's avatar
atraczyk committed
191
192
193

private:
    /* sub classes */
194
195
196
    enum class Request {
        None,
        AddRingAccount,
197
198
        AddSIPAccount,
        RefuseIncommingCall,
Nicolas Jager's avatar
Nicolas Jager committed
199
        AcceptIncommingCall,
200
        CancelOutGoingCall,
201
        PlaceCall,
202
        HangUpCall,
203
204
        PauseCall,
        UnPauseCall,
Nicolas Jager's avatar
Nicolas Jager committed
205
        RegisterDevice,
206
        GetKnownDevices,
207
        ExportOnRing,
208
        UpdateAccount,
209
210
211
212
        DeleteAccount,
        GetCallsList,
        KillCall,
        switchDebug,
Nicolas Jager's avatar
Nicolas Jager committed
213
        MuteVideo,
214
        MuteAudio,
Nicolas Jager's avatar
Nicolas Jager committed
215
216
217
        LookUpName,
        LookUpAddress,
        RegisterName
218
    };
219
220
221
222


    Vector<String^>^ callIdsList_;

atraczyk's avatar
atraczyk committed
223
224
    ref class Task
    {
225
    internal:
226
227
228
        Task(Request r) {
            request = r;
        }
229
        Task(Request r, String^ c) {
230
231
232
            request = r;
            _callId = c;
        }
233
234
235
236
237
        Task(Request r, String^ p, String^ P) {
            request = r;
            _pin = p;
            _password = P;
        }
atraczyk's avatar
atraczyk committed
238
239
    public:
        property Request request;
240
        property String^ _alias;
241
        property String^ _callId;
242
        property String^ _pin;
243
        property String^ _password; // refacto : is it safe ? are tasks destroy quickly after been used ?
Nicolas Jager's avatar
Nicolas Jager committed
244
        property String^ _accountId;
245
246
247
248
        property bool _upnp;
        property String^ _sipPassword;
        property String^ _sipHostname;
        property String^ _sipUsername;
249
        property bool _muted;
Nicolas Jager's avatar
Nicolas Jager committed
250
251
252
253
254
255
256
        property String^ _registeredName; // public username
        property String^ _address; // ringId

    internal:
        std::string _accountId_new;
        std::string _password_new;
        std::string _publicUsername_new;
257
258
        std::string _callid_new;
        std::string _ringId_new;
259
        bool _audioMuted_new;
atraczyk's avatar
atraczyk committed
260
261
262
263
264
    };

    /* functions */
    RingD(); // singleton
    void dequeueTasks();
Nicolas Jager's avatar
Nicolas Jager committed
265
//    CallStatus translateCallStatus(String^ state);
atraczyk's avatar
atraczyk committed
266
267

    /* members */
268
269
    Windows::UI::Core::CoreDispatcher^ dispatcher;

atraczyk's avatar
atraczyk committed
270
    std::string localFolder_;
271
    bool daemonInitialized_ = false;
atraczyk's avatar
atraczyk committed
272
273
    bool daemonRunning_ = false;
    std::queue<Task^> tasksList_;
274
    StartingStatus startingStatus_ = StartingStatus::NORMAL;
275
    bool editModeOn_ = false;
276
    bool debugModeOn_ = true;
atraczyk's avatar
atraczyk committed
277
    Ringtone^ ringtone_;
278
279
280
281
282
283
284

    std::map<std::string, SharedCallback> callHandlers;
    std::map<std::string, SharedCallback> getAppPathHandler;
    std::map<std::string, SharedCallback> getAppUserNameHandler;
    std::map<std::string, SharedCallback> incomingVideoHandlers;
    std::map<std::string, SharedCallback> outgoingVideoHandlers;
    std::map<std::string, SharedCallback> nameRegistrationHandlers;
atraczyk's avatar
atraczyk committed
285
};
Nicolas Jager's avatar
Nicolas Jager committed
286
}