-
Notifications
You must be signed in to change notification settings - Fork 5
/
PjsuaManager.h
105 lines (85 loc) · 3.12 KB
/
PjsuaManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
/**********************************************************\
Original Author: Andrew Ofisher (zaltar)
License: GNU General Public License, version 3.0
http://www.gnu.org/licenses/gpl-3.0.txt
Copyright 2012 Andrew Ofisher
\**********************************************************/
#ifndef H_PjsuaManagerPLUGIN
#define H_PjsuaManagerPLUGIN
#include "JSAPIAuto.h"
#include <string>
#include <map>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <pjlib.h>
#include <pjlib-util.h>
#include <pjnath.h>
#include <pjsip.h>
#include <pjsip_ua.h>
#include <pjsip_simple.h>
#include <pjsua-lib/pjsua.h>
#include <pjmedia.h>
#include <pjmedia-codec.h>
FB_FORWARD_PTR(BlabbleCall)
FB_FORWARD_PTR(BlabbleAccount)
FB_FORWARD_PTR(BlabbleAudioManager)
FB_FORWARD_PTR(PjsuaManager)
typedef std::map<int, BlabbleAccountPtr> BlabbleAccountMap;
/*! @class PjsuaManager
*
* @brief Singleton used to manage accounts, audio, and callbacks from PJSIP.
*
* @author Andrew Ofisher (zaltar)
*/
class PjsuaManager : public boost::enable_shared_from_this<PjsuaManager>
{
public:
static PjsuaManagerPtr GetManager(const std::string& path, bool enableIce,
const std::string& stunServer);
virtual ~PjsuaManager();
/*! @Brief Retrive the current audio manager.
* The audio manager allows control of ringing, busy signals, and ringtones.
*/
BlabbleAudioManagerPtr audio_manager() { return audio_manager_; }
void AddAccount(const BlabbleAccountPtr &account);
void RemoveAccount(pjsua_acc_id acc_id);
BlabbleAccountPtr FindAcc(int accId);
/*! Return true if we have TLS/SSL capability.
*/
bool has_tls() { return has_tls_; }
public:
/*! @Brief Callback for PJSIP.
* Called when an incoming call comes in on an account.
*/
static void OnIncomingCall(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata);
/*! @Brief Callback for PJSIP.
* Called when the media state of a call changes.
*/
static void OnCallMediaState(pjsua_call_id call_id);
/*! @Brief Callback for PJSIP.
* Called when the state of a call changes.
*/
static void OnCallState(pjsua_call_id call_id, pjsip_event *e);
/*! @Brief Callback for PJSIP.
* Called when the registration status of an account changes.
*/
static void OnRegState(pjsua_acc_id acc_id);
/*! @Brief Callback for PJSIP.
* Called if there is a change in the transport. This is usually for TLS.
*/
static void OnTransportState(pjsip_transport *tp, pjsip_transport_state state, const pjsip_transport_state_info *info);
/*! @Brief Callback for PJSIP.
* Called after a call is transfer to report the status.
*/
static void OnCallTransferStatus(pjsua_call_id call_id, int st_code, const pj_str_t *st_text, pj_bool_t final, pj_bool_t *p_cont);
private:
BlabbleAccountMap accounts_;
BlabbleAudioManagerPtr audio_manager_;
pjsua_transport_id udp_transport, tls_transport;
bool has_tls_;
static PjsuaManagerWeakPtr instance_;
//PjsuaManager is a singleton. Only one should ever exist so that PjSip callbacks work.
PjsuaManager(const std::string& executionPath, bool enableIce,
const std::string& stunServer);
};
#endif // H_PjsuaManagerPLUGIN