mumlib.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 _Mumlib_Private;
  24. class Mumlib : boost::noncopyable {
  25. public:
  26. explicit Mumlib(Callback &callback);
  27. Mumlib(Callback &callback, io_service &ioService);
  28. Mumlib(Callback &callback, MumlibConfiguration &configuration);
  29. Mumlib(Callback &callback, io_service &ioService, MumlibConfiguration &configuration);
  30. virtual ~Mumlib();
  31. void connect(string host, int port, string user, string password);
  32. void disconnect();
  33. void run();
  34. ConnectionState getConnectionState();
  35. int getChannelId();
  36. void sendAudioData(int16_t *pcmData, int pcmLength);
  37. void sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength);
  38. void sendTextMessage(std::string message);
  39. void joinChannel(int channelId);
  40. void sendVoiceTarget(int targetId, int channelId);
  41. void sendUserState(mumlib::UserState state, bool val);
  42. void sendUserState(mumlib::UserState state, std::string value);
  43. private:
  44. _Mumlib_Private *impl;
  45. };
  46. }