Merge pull request #6 from NerdyProjects/mumsi_join_channel

Mumsi join channel
This commit is contained in:
Michał Słomkowski 2015-12-02 00:20:12 +01:00
commit d1d8c91f14
7 changed files with 101 additions and 0 deletions

View File

@ -24,6 +24,8 @@ set(SOURCE_FILES
PjsuaCommunicator.hpp
MumbleCommunicator.cpp
MumbleCommunicator.hpp
MumbleChannelJoiner.cpp
MumbleChannelJoiner.hpp
Configuration.cpp
Configuration.hpp
IncomingConnectionValidator.cpp

25
MumbleChannelJoiner.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "MumbleChannelJoiner.hpp"
#include <boost/algorithm/string.hpp>
using namespace std;
mumble::MumbleChannelJoiner::MumbleChannelJoiner(std::string channelNameRegex) : channelNameRegex(boost::regex(channelNameRegex)),
logger(log4cpp::Category::getInstance("MumbleChannelJoiner")){
}
void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) {
boost::smatch s;
logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id);
if(boost::regex_match(channel_name, s, channelNameRegex)) {
this->channel_id = channel_id;
}
}
void mumble::MumbleChannelJoiner::maybeJoinChannel(mumble::MumbleCommunicator *mc) {
if(channel_id > -1) {
mc->joinChannel(channel_id);
}
}

23
MumbleChannelJoiner.hpp Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <boost/noncopyable.hpp>
#include <log4cpp/Category.hh>
#include <string>
#include <boost/regex.hpp>
#include "MumbleCommunicator.hpp"
namespace mumble {
class MumbleChannelJoiner : boost::noncopyable {
public:
MumbleChannelJoiner(std::string channelNameRegex);
void checkChannel(std::string channel_name, int channel_id);
void maybeJoinChannel(mumble::MumbleCommunicator *mc);
private:
log4cpp::Category &logger;
boost::regex channelNameRegex;
int channel_id;
};
}

View File

@ -17,6 +17,28 @@ namespace mumble {
uint32_t pcm_data_size) override {
communicator->onIncomingPcmSamples(sessionId, sequenceNumber, pcm_data, pcm_data_size);
}
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();
};
};
}
@ -51,3 +73,7 @@ mumble::MumbleCommunicator::~MumbleCommunicator() {
void mumble::MumbleCommunicator::sendTextMessage(std::string message) {
mum->sendTextMessage(message);
}
void mumble::MumbleCommunicator::joinChannel(int channel_id) {
mum->joinChannel(channel_id);
}

View File

@ -38,8 +38,18 @@ namespace mumble {
*/
std::function<void(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;
void sendTextMessage(std::string message);
void joinChannel(int channel_id);
public:
boost::asio::io_service &ioService;

View File

@ -13,3 +13,4 @@ host = example.org
port = 64738
user = mumsi
password = foobar
channelNameExpression =

View File

@ -1,6 +1,7 @@
#include "PjsuaCommunicator.hpp"
#include "MumbleCommunicator.hpp"
#include "IncomingConnectionValidator.hpp"
#include "MumbleChannelJoiner.hpp"
#include "Configuration.hpp"
#include <log4cpp/FileAppender.hh>
@ -32,6 +33,8 @@ int main(int argc, char *argv[]) {
mumble::MumbleCommunicator mumbleCommunicator(ioService);
mumble::MumbleChannelJoiner mumbleChannelJoiner(conf.getString("mumble.channelNameExpression"));
using namespace std::placeholders;
pjsuaCommunicator.onIncomingPcmSamples = std::bind(
&mumble::MumbleCommunicator::sendPcmSamples,
@ -47,6 +50,17 @@ int main(int argc, char *argv[]) {
&pjsuaCommunicator,
_1, _2, _3, _4);
mumbleCommunicator.onIncomingChannelState = std::bind(
&mumble::MumbleChannelJoiner::checkChannel,
&mumbleChannelJoiner,
_1, _2);
mumbleCommunicator.onServerSync = std::bind(
&mumble::MumbleChannelJoiner::maybeJoinChannel,
&mumbleChannelJoiner,
&mumbleCommunicator);
mumbleCommunicator.connect(
conf.getString("mumble.user"),
conf.getString("mumble.password"),