Browse Source

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
Scott Hardin 7 years ago
parent
commit
f112cca475
6 changed files with 43 additions and 2 deletions
  1. 14 0
      MumbleCommunicator.cpp
  2. 8 0
      MumbleCommunicator.hpp
  3. 3 1
      PjsuaCommunicator.cpp
  4. 2 0
      PjsuaCommunicator.hpp
  5. 6 1
      config.ini.example
  6. 10 0
      main.cpp

+ 14 - 0
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);
+    }
 }

+ 8 - 0
MumbleCommunicator.hpp

@@ -8,8 +8,10 @@
 #include <string>
 #include <stdexcept>
 
+
 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<mumlib::Mumlib> mum;
@@ -66,5 +73,6 @@ namespace mumble {
         std::unique_ptr<MumlibCallback> callback;
 
         friend class MumlibCallback;
+
     };
 }

+ 3 - 1
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);
-}
+}

+ 2 - 0
PjsuaCommunicator.hpp

@@ -80,6 +80,8 @@ namespace sip {
 
         std::function<void(std::string)> onStateChange;
 
+        std::function<void(int)> onMuteDeafChange;
+
         pj_status_t mediaPortGetFrame(pjmedia_port *port, pjmedia_frame *frame);
 
         pj_status_t mediaPortPutFrame(pjmedia_port *port, pjmedia_frame *frame);

+ 6 - 1
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
+opusEncoderBitrate = 16000

+ 10 - 0
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);