mumlib.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // additional fields will be added in the future
  22. };
  23. struct MumbleUser {
  24. int32_t sessionId;
  25. string name;
  26. };
  27. struct MumbleChannel {
  28. int32_t channelId;
  29. string name;
  30. string description;
  31. };
  32. struct _Mumlib_Private;
  33. class Mumlib : boost::noncopyable {
  34. public:
  35. explicit Mumlib(Callback &callback);
  36. Mumlib(Callback &callback, io_service &ioService);
  37. Mumlib(Callback &callback, MumlibConfiguration &configuration);
  38. Mumlib(Callback &callback, io_service &ioService, MumlibConfiguration &configuration);
  39. virtual ~Mumlib();
  40. void connect(string host, int port, string user, string password);
  41. void disconnect();
  42. void run();
  43. ConnectionState getConnectionState();
  44. int getChannelId();
  45. vector<MumbleUser> getListAllUser();
  46. vector<MumbleChannel> getListAllChannel();
  47. void sendAudioData(int16_t *pcmData, int pcmLength);
  48. void sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength);
  49. void sendTextMessage(std::string message);
  50. void joinChannel(int channelId);
  51. void joinChannel(std::string channelName);
  52. void sendVoiceTarget(int targetId, mumlib::VoiceTargetType type, int sessionId);
  53. void sendVoiceTarget(int targetId, mumlib::VoiceTargetType type, std::string name, int &error);
  54. void sendUserState(mumlib::UserState state, bool val);
  55. void sendUserState(mumlib::UserState state, std::string value);
  56. private:
  57. _Mumlib_Private *impl;
  58. int getChannelIdBy(std::string channelName);
  59. int getUserIdBy(std::string userName);
  60. bool isSessionIdValid(int sessionId);
  61. bool isChannelIdValid(int channelId);
  62. };
  63. }