mumlib.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include "mumlib/Callback.hpp"
  3. #include "mumlib/enums.hpp"
  4. #include <boost/asio.hpp>
  5. #include <boost/noncopyable.hpp>
  6. #include <string>
  7. namespace mumlib {
  8. constexpr int DEFAULT_OPUS_ENCODER_BITRATE = 16000;
  9. constexpr int DEFAULT_OPUS_SAMPLE_RATE = 48000;
  10. constexpr int DEFAULT_OPUS_NUM_CHANNELS = 1;
  11. using namespace std;
  12. using namespace boost::asio;
  13. class MumlibException : public runtime_error {
  14. public:
  15. MumlibException(string message) : runtime_error(message) { }
  16. };
  17. struct MumlibConfiguration {
  18. int opusEncoderBitrate = DEFAULT_OPUS_ENCODER_BITRATE;
  19. int opusSampleRate = DEFAULT_OPUS_SAMPLE_RATE;
  20. int opusChannels = DEFAULT_OPUS_NUM_CHANNELS;
  21. std::string cert_file = "";
  22. std::string privkey_file = "";
  23. // additional fields will be added in the future
  24. };
  25. struct MumbleUser {
  26. int32_t sessionId;
  27. string name;
  28. };
  29. struct MumbleChannel {
  30. int32_t channelId;
  31. string name;
  32. string description;
  33. };
  34. struct _Mumlib_Private;
  35. class Mumlib : boost::noncopyable {
  36. public:
  37. explicit Mumlib(Callback &callback);
  38. Mumlib(Callback &callback, io_service &ioService);
  39. Mumlib(Callback &callback, MumlibConfiguration &configuration);
  40. Mumlib(Callback &callback, io_service &ioService, MumlibConfiguration &configuration);
  41. virtual ~Mumlib();
  42. void connect(string host, int port, string user, string password);
  43. void disconnect();
  44. void run();
  45. ConnectionState getConnectionState();
  46. int getChannelId();
  47. vector<MumbleUser> getListAllUser();
  48. vector<MumbleChannel> getListAllChannel();
  49. void sendAudioData(int16_t *pcmData, int pcmLength);
  50. void sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength);
  51. void sendTextMessage(std::string message);
  52. void joinChannel(int channelId);
  53. void joinChannel(std::string channelName);
  54. void sendVoiceTarget(int targetId, mumlib::VoiceTargetType type, int sessionId);
  55. void sendVoiceTarget(int targetId, mumlib::VoiceTargetType type, std::string name, int &error);
  56. void sendUserState(mumlib::UserState state, bool val);
  57. void sendUserState(mumlib::UserState state, std::string value);
  58. private:
  59. _Mumlib_Private *impl;
  60. int getChannelIdBy(std::string channelName);
  61. int getUserIdBy(std::string userName);
  62. bool isSessionIdValid(int sessionId);
  63. bool isChannelIdValid(int channelId);
  64. };
  65. }