mumlib/mumlib_example.cpp

69 lines
2.1 KiB
C++
Raw Permalink Normal View History

2015-10-25 14:40:16 +01:00
#include "mumlib.hpp"
#include "log4cpp/Category.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#include <chrono>
#include <thread>
#include <mumlib/Transport.hpp>
2015-10-28 00:19:42 +01:00
class MyCallback : public mumlib::BasicCallback {
public:
mumlib::Mumlib *mum;
2015-10-25 14:40:16 +01:00
virtual void audio(int target,
int sessionId,
int sequenceNumber,
int16_t *pcm_data,
uint32_t pcm_data_size) override {
2015-10-28 00:19:42 +01:00
mum->sendAudioData(pcm_data, pcm_data_size);
2015-10-25 14:40:16 +01:00
}
2015-10-30 02:15:02 +01:00
virtual void textMessage(
uint32_t actor,
std::vector<uint32_t> session,
std::vector<uint32_t> channel_id,
std::vector<uint32_t> tree_id,
std::string message) override {
2015-10-30 02:15:02 +01:00
mumlib::BasicCallback::textMessage(actor, session, channel_id, tree_id, message);
mum->sendTextMessage("someone said: " + message);
}
2015-10-28 00:19:42 +01:00
};
2015-10-25 14:40:16 +01:00
int main(int argc, char *argv[]) {
log4cpp::Appender *appender1 = new log4cpp::OstreamAppender("console", &std::cout);
appender1->setLayout(new log4cpp::BasicLayout());
log4cpp::Category &logger = log4cpp::Category::getRoot();
2015-10-27 23:31:45 +01:00
logger.setPriority(log4cpp::Priority::NOTICE);
2015-10-25 14:40:16 +01:00
logger.addAppender(appender1);
2017-05-28 21:02:45 +02:00
if (argc < 3 || argc == 4 || argc > 5) {
logger.crit("Usage: %s {server} {password} [{certfile} {keyfile}]", argv[0]);
2015-10-25 14:40:16 +01:00
return 1;
}
2015-10-28 00:19:42 +01:00
MyCallback myCallback;
2015-10-25 14:40:16 +01:00
while (true) {
try {
mumlib::MumlibConfiguration conf;
conf.opusEncoderBitrate = 32000;
2017-05-28 21:02:45 +02:00
if ( argc > 3 && argc <= 5 ) {
conf.cert_file = argv[3];
conf.privkey_file = argv[4];
}
mumlib::Mumlib mum(myCallback, conf);
myCallback.mum = &mum;
mum.connect(argv[1], 64738, "mumlib_example", argv[2]);
mum.run();
} catch (mumlib::TransportException &exp) {
logger.error("TransportException: %s.", exp.what());
logger.notice("Attempting to reconnect in 5 s.");
std::this_thread::sleep_for(std::chrono::seconds(5));
}
}
2017-05-28 21:02:45 +02:00
}