forked from slomkowski/mumsi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMumbleCommunicator.hpp
110 lines (78 loc) · 2.85 KB
/
MumbleCommunicator.hpp
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
106
107
108
109
110
#pragma once
#include <mumlib.hpp>
#include <log4cpp/Category.hh>
#include <boost/noncopyable.hpp>
#include <string>
#include <stdexcept>
// 0 = mumble users connected at start; 1 = connect at dial-in
// TODO: fix mumlib::TransportException when this option is enabled
#define MUM_DELAYED_CONNECT 0
namespace mumble {
class Exception : public std::runtime_error {
public:
Exception(const char *message) : std::runtime_error(message) { }
};
class MumlibCallback;
struct MumbleCommunicatorConfig {
std::string user;
std::string password;
std::string host;
std::string cert_file;
std::string privkey_file;
int opusEncoderBitrate;
int port = 0;
bool autodeaf;
std::string comment;
int max_calls = 1;
std::string authchan; // config.ini: channelAuthExpression
};
// This is the subset that is of interest to us
struct MumbleUserState {
int32_t mute;
int32_t deaf;
int32_t suppress;
int32_t self_mute;
int32_t self_deaf;
int32_t priority_speaker;
int32_t recording;
};
class MumbleCommunicator : boost::noncopyable {
public:
MumbleCommunicator(
boost::asio::io_service &ioService);
void connect(MumbleCommunicatorConfig &config);
void onConnect(const std::string& address);
void onDisconnect();
void onCallerAuth();
//void onCallerUnauth();
virtual ~MumbleCommunicator();
void sendPcmSamples(int16_t *samples, unsigned int length);
/**
* This callback is called when communicator has received samples.
* Arguments: call ID, session ID, sequence number, PCM samples, length of samples
*/
std::function<void(int, int, int, int16_t *, int)> onIncomingPcmSamples;
/**
* This callback is called when a channel state message (e.g. Channel
* information) is received. Arguments: channel_id, name
*/
std::function<void(std::string, int)> onIncomingChannelState;
std::function<void()> onServerSync;
std::function<void()> onUserState;
void sendTextMessage(std::string message);
void sendTextMessageStr(mumlib::MessageType field, std::string message);
void joinChannel(int channel_id);
void sendUserState(mumlib::UserState field, bool val);
void sendUserState(mumlib::UserState field, std::string val);
MumbleUserState userState;
int callId;
private:
boost::asio::io_service &ioService;
log4cpp::Category &logger;
MumbleCommunicatorConfig mumbleConf;
mumlib::MumlibConfiguration mumConfig;
std::shared_ptr<mumlib::Mumlib> mum;
std::unique_ptr<MumlibCallback> callback;
friend class MumlibCallback;
};
}