2015-11-04 01:22:59 +01:00
|
|
|
#include "MumbleCommunicator.hpp"
|
|
|
|
|
2015-09-28 23:25:12 +02:00
|
|
|
#include <cstring>
|
|
|
|
#include <functional>
|
|
|
|
|
2015-10-30 13:43:06 +01:00
|
|
|
namespace mumble {
|
|
|
|
class MumlibCallback : public mumlib::BasicCallback {
|
|
|
|
public:
|
|
|
|
std::shared_ptr<mumlib::Mumlib> mum;
|
|
|
|
MumbleCommunicator *communicator;
|
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
// called by Mumlib when receiving audio from mumble server
|
2015-10-30 13:43:06 +01:00
|
|
|
virtual void audio(
|
2015-11-17 23:15:52 +01:00
|
|
|
int target,
|
|
|
|
int sessionId,
|
|
|
|
int sequenceNumber,
|
2015-10-30 13:43:06 +01:00
|
|
|
int16_t *pcm_data,
|
2015-11-17 23:15:52 +01:00
|
|
|
uint32_t pcm_data_size) override {
|
2017-05-24 22:38:45 +02:00
|
|
|
communicator->onIncomingPcmSamples(communicator->callId, sessionId, sequenceNumber, pcm_data, pcm_data_size);
|
2015-10-30 13:43:06 +01:00
|
|
|
}
|
2015-11-30 23:24:41 +01:00
|
|
|
|
|
|
|
virtual void channelState(
|
|
|
|
std::string name,
|
|
|
|
int32_t channel_id,
|
|
|
|
int32_t parent,
|
|
|
|
std::string description,
|
|
|
|
std::vector<uint32_t> links,
|
|
|
|
std::vector<uint32_t> inks_add,
|
|
|
|
std::vector<uint32_t> links_remove,
|
|
|
|
bool temporary,
|
|
|
|
int32_t position) override {
|
|
|
|
communicator->onIncomingChannelState(name, channel_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void serverSync(
|
|
|
|
std::string welcome_text,
|
|
|
|
int32_t session,
|
|
|
|
int32_t max_bandwidth,
|
|
|
|
int64_t permissions) override {
|
|
|
|
communicator->onServerSync();
|
|
|
|
};
|
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
/*
|
|
|
|
virtual void onUserState(
|
|
|
|
int32_t session,
|
|
|
|
int32_t actor,
|
|
|
|
std::string name,
|
|
|
|
int32_t user_id,
|
|
|
|
int32_t channel_id,
|
|
|
|
int32_t mute,
|
|
|
|
int32_t deaf,
|
|
|
|
int32_t suppress,
|
|
|
|
int32_t self_mute,
|
|
|
|
int32_t self_deaf,
|
|
|
|
std::string comment,
|
|
|
|
int32_t priority_speaker,
|
|
|
|
int32_t recording
|
|
|
|
) override {
|
|
|
|
communicator->onUserState();
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
2015-10-30 13:43:06 +01:00
|
|
|
};
|
2015-09-29 02:26:45 +02:00
|
|
|
}
|
2015-09-28 23:25:12 +02:00
|
|
|
|
2015-11-03 02:13:15 +01:00
|
|
|
mumble::MumbleCommunicator::MumbleCommunicator(boost::asio::io_service &ioService)
|
|
|
|
: ioService(ioService),
|
|
|
|
logger(log4cpp::Category::getInstance("MumbleCommunicator")) {
|
|
|
|
}
|
|
|
|
|
2016-04-18 01:22:36 +02:00
|
|
|
void mumble::MumbleCommunicator::connect(MumbleCommunicatorConfig &config) {
|
2015-10-16 22:41:37 +02:00
|
|
|
|
2015-10-30 13:43:06 +01:00
|
|
|
callback.reset(new MumlibCallback());
|
2015-09-28 23:25:12 +02:00
|
|
|
|
2017-05-20 18:17:08 +02:00
|
|
|
mumbleConf = config;
|
|
|
|
|
2016-04-18 01:22:36 +02:00
|
|
|
mumConfig = mumlib::MumlibConfiguration();
|
|
|
|
mumConfig.opusEncoderBitrate = config.opusEncoderBitrate;
|
|
|
|
|
|
|
|
mum.reset(new mumlib::Mumlib(*callback, ioService, mumConfig));
|
2015-10-30 13:43:06 +01:00
|
|
|
callback->communicator = this;
|
|
|
|
callback->mum = mum;
|
2015-09-28 23:25:12 +02:00
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
// IMPORTANT: comment these out when experimenting with onConnect
|
|
|
|
if ( ! MUM_DELAYED_CONNECT ) {
|
|
|
|
mum->connect(config.host, config.port, config.user, config.password);
|
|
|
|
if ( mumbleConf.autodeaf ) {
|
|
|
|
mum->sendUserState(mumlib::UserState::SELF_DEAF, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mumble::MumbleCommunicator::onConnect() {
|
|
|
|
if ( MUM_DELAYED_CONNECT ) {
|
|
|
|
mum->connect(mumbleConf.host, mumbleConf.port, mumbleConf.user, mumbleConf.password);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mumbleConf.comment.size() > 0 ) {
|
|
|
|
mum->sendUserState(mumlib::UserState::COMMENT, mumbleConf.comment);
|
|
|
|
}
|
|
|
|
if ( mumbleConf.autodeaf ) {
|
|
|
|
mum->sendUserState(mumlib::UserState::SELF_DEAF, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mumble::MumbleCommunicator::onDisconnect() {
|
|
|
|
if ( MUM_DELAYED_CONNECT ) {
|
|
|
|
mum->disconnect();
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mumble::MumbleCommunicator::onCallerAuth() {
|
|
|
|
//onServerSync();
|
2015-09-28 23:25:12 +02:00
|
|
|
}
|
|
|
|
|
2015-11-03 02:13:15 +01:00
|
|
|
void mumble::MumbleCommunicator::sendPcmSamples(int16_t *samples, unsigned int length) {
|
2015-11-02 23:41:49 +01:00
|
|
|
mum->sendAudioData(samples, length);
|
|
|
|
}
|
|
|
|
|
2015-09-28 23:25:12 +02:00
|
|
|
mumble::MumbleCommunicator::~MumbleCommunicator() {
|
2015-10-30 13:43:06 +01:00
|
|
|
mum->disconnect();
|
|
|
|
}
|
2015-11-04 00:53:52 +01:00
|
|
|
|
|
|
|
void mumble::MumbleCommunicator::sendTextMessage(std::string message) {
|
|
|
|
mum->sendTextMessage(message);
|
|
|
|
}
|
2015-11-30 23:24:41 +01:00
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
/*
|
|
|
|
void mumble::MumbleCommunicator::onUserState(
|
|
|
|
int32_t session,
|
|
|
|
int32_t actor,
|
|
|
|
std::string name,
|
|
|
|
int32_t user_id,
|
|
|
|
int32_t channel_id,
|
|
|
|
int32_t mute,
|
|
|
|
int32_t deaf,
|
|
|
|
int32_t suppress,
|
|
|
|
int32_t self_mute,
|
|
|
|
int32_t self_deaf,
|
|
|
|
std::string comment,
|
|
|
|
int32_t priority_speaker,
|
|
|
|
int32_t recording) {
|
|
|
|
|
|
|
|
logger::notice("Entered onUserState(...)");
|
|
|
|
|
|
|
|
userState.mute = mute;
|
|
|
|
userState.deaf = deaf;
|
|
|
|
userState.suppress = suppress;
|
|
|
|
userState.self_mute = self_mute;
|
|
|
|
userState.self_deaf = self_deaf;
|
|
|
|
userState.priority_speaker = priority_speaker;
|
|
|
|
userState.recording = recording;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-11-30 23:24:41 +01:00
|
|
|
void mumble::MumbleCommunicator::joinChannel(int channel_id) {
|
|
|
|
mum->joinChannel(channel_id);
|
2017-05-24 22:38:45 +02:00
|
|
|
|
2017-05-20 18:17:08 +02:00
|
|
|
if ( mumbleConf.autodeaf ) {
|
2017-05-24 22:38:45 +02:00
|
|
|
mum->sendUserState(mumlib::UserState::SELF_DEAF, true);
|
2017-05-20 18:17:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
|
|
|
|
void mumble::MumbleCommunicator::sendUserState(mumlib::UserState field, bool val) {
|
|
|
|
mum->sendUserState(field, val);
|
2015-11-30 23:24:41 +01:00
|
|
|
}
|
2017-05-21 16:03:19 +02:00
|
|
|
|