mumsi/MumbleCommunicator.cpp

80 lines
2.2 KiB
C++
Raw Normal View History

2015-11-04 01:22:59 +01:00
#include "MumbleCommunicator.hpp"
#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;
virtual void audio(
int target,
int sessionId,
int sequenceNumber,
2015-10-30 13:43:06 +01:00
int16_t *pcm_data,
uint32_t pcm_data_size) override {
communicator->onIncomingPcmSamples(sessionId, sequenceNumber, pcm_data, pcm_data_size);
2015-10-30 13:43:06 +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();
};
2015-10-30 13:43:06 +01:00
};
2015-09-29 02:26:45 +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")) {
}
void mumble::MumbleCommunicator::connect(
2015-09-29 02:26:45 +02:00
std::string user,
std::string password,
std::string host,
2015-11-03 02:13:15 +01:00
int port) {
2015-10-16 22:41:37 +02:00
2015-10-30 13:43:06 +01:00
callback.reset(new MumlibCallback());
2015-10-30 13:43:06 +01:00
mum.reset(new mumlib::Mumlib(*callback, ioService));
callback->communicator = this;
callback->mum = mum;
2015-10-30 13:43:06 +01:00
mum->connect(host, port, user, password);
}
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);
}
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);
}
void mumble::MumbleCommunicator::joinChannel(int channel_id) {
mum->joinChannel(channel_id);
}