Merge pull request #6 from NerdyProjects/mumsi_join_channel
Mumsi join channel
This commit is contained in:
commit
d1d8c91f14
@ -24,6 +24,8 @@ set(SOURCE_FILES
|
|||||||
PjsuaCommunicator.hpp
|
PjsuaCommunicator.hpp
|
||||||
MumbleCommunicator.cpp
|
MumbleCommunicator.cpp
|
||||||
MumbleCommunicator.hpp
|
MumbleCommunicator.hpp
|
||||||
|
MumbleChannelJoiner.cpp
|
||||||
|
MumbleChannelJoiner.hpp
|
||||||
Configuration.cpp
|
Configuration.cpp
|
||||||
Configuration.hpp
|
Configuration.hpp
|
||||||
IncomingConnectionValidator.cpp
|
IncomingConnectionValidator.cpp
|
||||||
|
25
MumbleChannelJoiner.cpp
Normal file
25
MumbleChannelJoiner.cpp
Normal 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
23
MumbleChannelJoiner.hpp
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
@ -17,6 +17,28 @@ namespace mumble {
|
|||||||
uint32_t pcm_data_size) override {
|
uint32_t pcm_data_size) override {
|
||||||
communicator->onIncomingPcmSamples(sessionId, sequenceNumber, pcm_data, pcm_data_size);
|
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) {
|
void mumble::MumbleCommunicator::sendTextMessage(std::string message) {
|
||||||
mum->sendTextMessage(message);
|
mum->sendTextMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mumble::MumbleCommunicator::joinChannel(int channel_id) {
|
||||||
|
mum->joinChannel(channel_id);
|
||||||
|
}
|
||||||
|
@ -38,8 +38,18 @@ namespace mumble {
|
|||||||
*/
|
*/
|
||||||
std::function<void(int, int, int16_t *, int)> onIncomingPcmSamples;
|
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 sendTextMessage(std::string message);
|
||||||
|
|
||||||
|
void joinChannel(int channel_id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
boost::asio::io_service &ioService;
|
boost::asio::io_service &ioService;
|
||||||
|
|
||||||
|
@ -13,3 +13,4 @@ host = example.org
|
|||||||
port = 64738
|
port = 64738
|
||||||
user = mumsi
|
user = mumsi
|
||||||
password = foobar
|
password = foobar
|
||||||
|
channelNameExpression =
|
||||||
|
14
main.cpp
14
main.cpp
@ -1,6 +1,7 @@
|
|||||||
#include "PjsuaCommunicator.hpp"
|
#include "PjsuaCommunicator.hpp"
|
||||||
#include "MumbleCommunicator.hpp"
|
#include "MumbleCommunicator.hpp"
|
||||||
#include "IncomingConnectionValidator.hpp"
|
#include "IncomingConnectionValidator.hpp"
|
||||||
|
#include "MumbleChannelJoiner.hpp"
|
||||||
#include "Configuration.hpp"
|
#include "Configuration.hpp"
|
||||||
|
|
||||||
#include <log4cpp/FileAppender.hh>
|
#include <log4cpp/FileAppender.hh>
|
||||||
@ -32,6 +33,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
mumble::MumbleCommunicator mumbleCommunicator(ioService);
|
mumble::MumbleCommunicator mumbleCommunicator(ioService);
|
||||||
|
|
||||||
|
mumble::MumbleChannelJoiner mumbleChannelJoiner(conf.getString("mumble.channelNameExpression"));
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
pjsuaCommunicator.onIncomingPcmSamples = std::bind(
|
pjsuaCommunicator.onIncomingPcmSamples = std::bind(
|
||||||
&mumble::MumbleCommunicator::sendPcmSamples,
|
&mumble::MumbleCommunicator::sendPcmSamples,
|
||||||
@ -47,6 +50,17 @@ int main(int argc, char *argv[]) {
|
|||||||
&pjsuaCommunicator,
|
&pjsuaCommunicator,
|
||||||
_1, _2, _3, _4);
|
_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(
|
mumbleCommunicator.connect(
|
||||||
conf.getString("mumble.user"),
|
conf.getString("mumble.user"),
|
||||||
conf.getString("mumble.password"),
|
conf.getString("mumble.password"),
|
||||||
|
Loading…
Reference in New Issue
Block a user