MumbleCommunicator.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #include <mumlib.hpp>
  3. #include <log4cpp/Category.hh>
  4. #include <boost/noncopyable.hpp>
  5. #include <string>
  6. #include <stdexcept>
  7. // 0 = mumble users connected at start; 1 = connect at dial-in
  8. // TODO: fix mumlib::TransportException when this option is enabled
  9. #define MUM_DELAYED_CONNECT 0
  10. namespace mumble {
  11. class Exception : public std::runtime_error {
  12. public:
  13. Exception(const char *message) : std::runtime_error(message) { }
  14. };
  15. class MumlibCallback;
  16. struct MumbleCommunicatorConfig {
  17. std::string user;
  18. std::string password;
  19. std::string host;
  20. std::string cert_file;
  21. std::string privkey_file;
  22. int opusEncoderBitrate;
  23. int port = 0;
  24. bool autodeaf;
  25. std::string comment;
  26. int max_calls = 1;
  27. std::string authchan; // config.ini: channelAuthExpression
  28. };
  29. // This is the subset that is of interest to us
  30. struct MumbleUserState {
  31. int32_t mute;
  32. int32_t deaf;
  33. int32_t suppress;
  34. int32_t self_mute;
  35. int32_t self_deaf;
  36. int32_t priority_speaker;
  37. int32_t recording;
  38. };
  39. class MumbleCommunicator : boost::noncopyable {
  40. public:
  41. MumbleCommunicator(
  42. boost::asio::io_service &ioService);
  43. void connect(MumbleCommunicatorConfig &config);
  44. void onConnect();
  45. void onDisconnect();
  46. void onCallerAuth();
  47. //void onCallerUnauth();
  48. virtual ~MumbleCommunicator();
  49. void sendPcmSamples(int16_t *samples, unsigned int length);
  50. /**
  51. * This callback is called when communicator has received samples.
  52. * Arguments: call ID, session ID, sequence number, PCM samples, length of samples
  53. */
  54. std::function<void(int, int, int, int16_t *, int)> onIncomingPcmSamples;
  55. /**
  56. * This callback is called when a channel state message (e.g. Channel
  57. * information) is received. Arguments: channel_id, name
  58. */
  59. std::function<void(std::string, int)> onIncomingChannelState;
  60. std::function<void()> onServerSync;
  61. std::function<void()> onUserState;
  62. void sendTextMessage(std::string message);
  63. void joinChannel(int channel_id);
  64. void sendUserState(mumlib::UserState field, bool val);
  65. void sendUserState(mumlib::UserState field, std::string val);
  66. MumbleUserState userState;
  67. int callId;
  68. private:
  69. boost::asio::io_service &ioService;
  70. log4cpp::Category &logger;
  71. MumbleCommunicatorConfig mumbleConf;
  72. mumlib::MumlibConfiguration mumConfig;
  73. std::shared_ptr<mumlib::Mumlib> mum;
  74. std::unique_ptr<MumlibCallback> callback;
  75. friend class MumlibCallback;
  76. };
  77. }