Add text message sending.

This commit is contained in:
Michał Słomkowski 2015-10-30 02:15:02 +01:00
parent d289bf3134
commit 5e060ead33
3 changed files with 27 additions and 7 deletions

View File

@ -29,8 +29,6 @@ namespace mumlib {
~Mumlib(); ~Mumlib();
void setCallback(Callback &callback);
void connect(string host, int port, string user, string password); void connect(string host, int port, string user, string password);
void disconnect(); void disconnect();
@ -41,6 +39,8 @@ namespace mumlib {
void sendAudioData(int16_t *pcmData, int pcmLength); void sendAudioData(int16_t *pcmData, int pcmLength);
void sendTextMessage(std::string message);
private: private:
_Mumlib_Private *impl; _Mumlib_Private *impl;
}; };

View File

@ -11,6 +11,16 @@ public:
virtual void audio(int16_t *pcm_data, uint32_t pcm_data_size) { virtual void audio(int16_t *pcm_data, uint32_t pcm_data_size) {
mum->sendAudioData(pcm_data, pcm_data_size); mum->sendAudioData(pcm_data, pcm_data_size);
} }
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) {
mumlib::BasicCallback::textMessage(actor, session, channel_id, tree_id, message);
mum->sendTextMessage("someone said: " + message);
}
}; };
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

View File

@ -30,6 +30,8 @@ namespace mumlib {
Audio audio; Audio audio;
int sessionId = 0;
int channelId = 0;
_Mumlib_Private(Callback &callback) _Mumlib_Private(Callback &callback)
: _Mumlib_Private(callback, *(new io_service())) { : _Mumlib_Private(callback, *(new io_service())) {
@ -80,6 +82,9 @@ namespace mumlib {
case MessageType::SERVERSYNC: { case MessageType::SERVERSYNC: {
MumbleProto::ServerSync serverSync; MumbleProto::ServerSync serverSync;
serverSync.ParseFromArray(buffer, length); serverSync.ParseFromArray(buffer, length);
sessionId = serverSync.session();
callback.serverSync( callback.serverSync(
serverSync.welcome_text(), serverSync.welcome_text(),
serverSync.session(), serverSync.session(),
@ -116,6 +121,8 @@ namespace mumlib {
std::copy(channelState.links_remove().begin(), channelState.links_remove().end(), std::copy(channelState.links_remove().begin(), channelState.links_remove().end(),
links_remove.begin()); links_remove.begin());
this->channelId = channel_id;
callback.channelState( callback.channelState(
channelState.name(), channelState.name(),
channel_id, channel_id,
@ -310,15 +317,10 @@ namespace mumlib {
delete impl; delete impl;
} }
ConnectionState Mumlib::getConnectionState() { ConnectionState Mumlib::getConnectionState() {
return impl->transport.getConnectionState(); return impl->transport.getConnectionState();
} }
void Mumlib::setCallback(Callback &callback) {
impl->callback = callback;
}
void Mumlib::connect(string host, int port, string user, string password) { void Mumlib::connect(string host, int port, string user, string password) {
impl->transport.connect(host, port, user, password); impl->transport.connect(host, port, user, password);
} }
@ -340,4 +342,12 @@ namespace mumlib {
int length = impl->audio.encodeAudioPacket(0, pcmData, pcmLength, encodedData, 5000); int length = impl->audio.encodeAudioPacket(0, pcmData, pcmLength, encodedData, 5000);
impl->transport.sendEncodedAudioPacket(encodedData, length); impl->transport.sendEncodedAudioPacket(encodedData, length);
} }
void Mumlib::sendTextMessage(string message) {
MumbleProto::TextMessage textMessage;
textMessage.set_actor(impl->sessionId);
textMessage.add_channel_id(impl->channelId);
textMessage.set_message(message);
impl->transport.sendControlMessage(MessageType::TEXTMESSAGE, textMessage);
}
} }