From f112cca4757da0189cada33ad43b902bf8588728 Mon Sep 17 00:00:00 2001 From: Scott Hardin Date: Sat, 20 May 2017 18:17:08 +0200 Subject: [PATCH] Add autodeaf so users in other groups see status This causes the user to be self_mute and self_deaf when there is no SIP call active. Users in other Mumble groups can then see whether the user is active without moving to same group. Note: this needs the updated mumlib with the self_mute and self_deaf methods --- MumbleCommunicator.cpp | 14 ++++++++++++++ MumbleCommunicator.hpp | 8 ++++++++ PjsuaCommunicator.cpp | 4 +++- PjsuaCommunicator.hpp | 2 ++ config.ini.example | 7 ++++++- main.cpp | 10 ++++++++++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/MumbleCommunicator.cpp b/MumbleCommunicator.cpp index 9a5c719..4915e5e 100644 --- a/MumbleCommunicator.cpp +++ b/MumbleCommunicator.cpp @@ -51,6 +51,8 @@ void mumble::MumbleCommunicator::connect(MumbleCommunicatorConfig &config) { callback.reset(new MumlibCallback()); + mumbleConf = config; + mumConfig = mumlib::MumlibConfiguration(); mumConfig.opusEncoderBitrate = config.opusEncoderBitrate; @@ -59,6 +61,7 @@ void mumble::MumbleCommunicator::connect(MumbleCommunicatorConfig &config) { callback->mum = mum; mum->connect(config.host, config.port, config.user, config.password); + mum->self_deaf(1); } void mumble::MumbleCommunicator::sendPcmSamples(int16_t *samples, unsigned int length) { @@ -75,4 +78,15 @@ void mumble::MumbleCommunicator::sendTextMessage(std::string message) { void mumble::MumbleCommunicator::joinChannel(int channel_id) { mum->joinChannel(channel_id); + if ( mumbleConf.autodeaf ) { + mum->self_mute(1); + mum->self_deaf(1); + } +} + +void mumble::MumbleCommunicator::mutedeaf(int status) { + if ( mumbleConf.autodeaf ) { + mum->self_mute(status); + mum->self_deaf(status); + } } diff --git a/MumbleCommunicator.hpp b/MumbleCommunicator.hpp index be04a4b..8fef318 100644 --- a/MumbleCommunicator.hpp +++ b/MumbleCommunicator.hpp @@ -8,8 +8,10 @@ #include #include + namespace mumble { + class Exception : public std::runtime_error { public: Exception(const char *message) : std::runtime_error(message) { } @@ -23,6 +25,7 @@ namespace mumble { std::string host; int opusEncoderBitrate; int port = 0; + bool autodeaf; }; class MumbleCommunicator : boost::noncopyable { @@ -54,11 +57,15 @@ namespace mumble { void joinChannel(int channel_id); + void mutedeaf(int status); + private: boost::asio::io_service &ioService; log4cpp::Category &logger; + MumbleCommunicatorConfig mumbleConf; + mumlib::MumlibConfiguration mumConfig; std::shared_ptr mum; @@ -66,5 +73,6 @@ namespace mumble { std::unique_ptr callback; friend class MumlibCallback; + }; } diff --git a/PjsuaCommunicator.cpp b/PjsuaCommunicator.cpp index 7a1e11e..6b98d21 100644 --- a/PjsuaCommunicator.cpp +++ b/PjsuaCommunicator.cpp @@ -144,6 +144,7 @@ namespace sip { communicator.logger.notice(msgText); communicator.onStateChange(msgText); + communicator.onMuteDeafChange(0); } else if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { auto &acc = dynamic_cast<_Account &>(account); @@ -154,6 +155,7 @@ namespace sip { communicator.logger.notice(msgText); communicator.onStateChange(msgText); + communicator.onMuteDeafChange(1); acc.available = true; } @@ -320,4 +322,4 @@ void sip::PjsuaCommunicator::registerAccount(string host, string user, string pa logger.info("Registering account for URI: %s.", uri.c_str()); account.reset(new _Account(*this)); account->create(accountConfig); -} \ No newline at end of file +} diff --git a/PjsuaCommunicator.hpp b/PjsuaCommunicator.hpp index 395fe5b..83b3dc0 100644 --- a/PjsuaCommunicator.hpp +++ b/PjsuaCommunicator.hpp @@ -80,6 +80,8 @@ namespace sip { std::function onStateChange; + std::function onMuteDeafChange; + pj_status_t mediaPortGetFrame(pjmedia_port *port, pjmedia_frame *frame); pj_status_t mediaPortPutFrame(pjmedia_port *port, pjmedia_frame *frame); diff --git a/config.ini.example b/config.ini.example index 5044909..d5a635c 100644 --- a/config.ini.example +++ b/config.ini.example @@ -23,6 +23,11 @@ user = mumsi password = foobar channelNameExpression = +# When here is no SIP connection, the mumble state is set to self_mute/self_deaf +# so the other users can easily see whether the SIP is connected even when not +# in the same group +autodeaf = 0 + # Bitrate of Opus encoder in B/s # Adjust it if you need to meet the specific bandwidth requirements of Murmur server -opusEncoderBitrate = 16000 \ No newline at end of file +opusEncoderBitrate = 16000 diff --git a/main.cpp b/main.cpp index bfd872a..d2ce848 100644 --- a/main.cpp +++ b/main.cpp @@ -64,6 +64,10 @@ int main(int argc, char *argv[]) { &mumble::MumbleCommunicator::sendTextMessage, &mumbleCommunicator, _1); + pjsuaCommunicator.onMuteDeafChange = std::bind( + &mumble::MumbleCommunicator::mutedeaf, + &mumbleCommunicator, _1); + mumbleCommunicator.onIncomingPcmSamples = std::bind( &sip::PjsuaCommunicator::sendPcmSamples, &pjsuaCommunicator, @@ -85,6 +89,12 @@ int main(int argc, char *argv[]) { mumbleConf.user = conf.getString("mumble.user"); mumbleConf.password = conf.getString("mumble.password"); mumbleConf.opusEncoderBitrate = conf.getInt("mumble.opusEncoderBitrate"); + /* default to 'false' if not found */ + try { + mumbleConf.autodeaf = conf.getBool("mumble.autodeaf"); + } catch (...) { + mumbleConf.autodeaf = false; + } mumbleCommunicator.connect(mumbleConf);