mumlib.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "mumlib/Callback.hpp"
  3. #include <boost/asio.hpp>
  4. #include <boost/noncopyable.hpp>
  5. #include <string>
  6. #include <mumlib/enums.hpp>
  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> getListUser();
  46. vector<MumbleChannel> getListChannel();
  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, int channelId);
  53. void sendVoiceTarget(int targetId, std::string channelName);
  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 getListChannelIdBy(std::string channelName);
  59. };
  60. }