diff --git a/CMakeLists.txt b/CMakeLists.txt index 77a6e96..ee6dbd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(SOURCE_FILES PjsuaCommunicator.hpp MumbleCommunicator.cpp MumbleCommunicator.hpp + MumbleChannelJoiner.cpp + MumbleChannelJoiner.hpp Configuration.cpp Configuration.hpp IncomingConnectionValidator.cpp diff --git a/MumbleCommunicator.cpp b/MumbleCommunicator.cpp index 5a72378..55009a5 100644 --- a/MumbleCommunicator.cpp +++ b/MumbleCommunicator.cpp @@ -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 links, + std::vector inks_add, + std::vector 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); +} diff --git a/MumbleCommunicator.hpp b/MumbleCommunicator.hpp index 6eb752e..0b6be5b 100644 --- a/MumbleCommunicator.hpp +++ b/MumbleCommunicator.hpp @@ -38,8 +38,18 @@ namespace mumble { */ std::function onIncomingPcmSamples; + /** + * This callback is called when a channel state message (e.g. Channel + * information) is received. Arguments: channel_id, name + */ + std::function onIncomingChannelState; + + std::function onServerSync; + void sendTextMessage(std::string message); + void joinChannel(int channel_id); + public: boost::asio::io_service &ioService; diff --git a/main.cpp b/main.cpp index 443f3be..a31b416 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include "PjsuaCommunicator.hpp" #include "MumbleCommunicator.hpp" #include "IncomingConnectionValidator.hpp" +#include "MumbleChannelJoiner.hpp" #include "Configuration.hpp" #include @@ -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"),