2012-02-25 13:15:36 -05:00
|
|
|
#include <iostream>
|
2012-02-25 16:03:06 -05:00
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <interface/rsvoip.h>
|
2012-02-25 13:15:36 -05:00
|
|
|
#include "PluginGUIHandler.h"
|
2012-02-25 16:03:06 -05:00
|
|
|
#include <gui/chat/ChatDialog.h>
|
2014-07-13 09:57:25 -04:00
|
|
|
#include <gui/VOIPChatWidgetHolder.h>
|
2014-01-01 19:56:46 -05:00
|
|
|
#include "gui/chat/ChatWidget.h"
|
2012-02-25 13:15:36 -05:00
|
|
|
|
2012-09-30 05:38:13 -04:00
|
|
|
void PluginGUIHandler::ReceivedInvitation(const QString& /*peer_id*/)
|
2012-02-25 13:15:36 -05:00
|
|
|
{
|
2012-02-26 15:31:16 -05:00
|
|
|
std::cerr << "****** Plugin GUI handler: received Invitation!" << std::endl;
|
2012-02-25 13:15:36 -05:00
|
|
|
}
|
|
|
|
|
2012-09-30 05:38:13 -04:00
|
|
|
void PluginGUIHandler::ReceivedVoipHangUp(const QString& /*peer_id*/)
|
2012-02-26 10:49:07 -05:00
|
|
|
{
|
|
|
|
std::cerr << "****** Plugin GUI handler: received HangUp!" << std::endl;
|
|
|
|
}
|
|
|
|
|
2012-09-30 05:38:13 -04:00
|
|
|
void PluginGUIHandler::ReceivedVoipAccept(const QString& /*peer_id*/)
|
2012-02-26 10:49:07 -05:00
|
|
|
{
|
|
|
|
std::cerr << "****** Plugin GUI handler: received VoipAccept!" << std::endl;
|
|
|
|
}
|
|
|
|
|
2014-04-20 10:21:53 -04:00
|
|
|
void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id)
|
2012-02-25 13:15:36 -05:00
|
|
|
{
|
2014-07-15 16:04:31 -04:00
|
|
|
RsPeerId peer_id(qpeer_id.toStdString()) ;
|
2012-02-25 16:03:06 -05:00
|
|
|
std::vector<RsVoipDataChunk> chunks ;
|
|
|
|
|
2014-07-15 16:04:31 -04:00
|
|
|
if(!rsVoip->getIncomingData(peer_id,chunks))
|
2012-02-25 16:03:06 -05:00
|
|
|
{
|
|
|
|
std::cerr << "PluginGUIHandler::ReceivedVoipData(): No data chunks to get. Weird!" << std::endl;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2014-07-15 16:04:31 -04:00
|
|
|
ChatDialog *di = ChatDialog::getExistingChat(peer_id) ;
|
2014-01-01 19:56:46 -05:00
|
|
|
if (di) {
|
|
|
|
ChatWidget *cw = di->getChatWidget();
|
|
|
|
if (cw) {
|
|
|
|
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
|
|
|
|
|
2014-07-15 16:04:31 -04:00
|
|
|
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
|
|
|
|
{
|
2014-07-13 09:57:25 -04:00
|
|
|
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
|
2014-01-01 19:56:46 -05:00
|
|
|
|
|
|
|
if (acwh) {
|
|
|
|
for (unsigned int i = 0; i < chunks.size(); ++i) {
|
2014-07-15 16:04:31 -04:00
|
|
|
for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++)
|
|
|
|
{
|
2014-01-01 19:56:46 -05:00
|
|
|
QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);
|
2014-07-15 16:04:31 -04:00
|
|
|
|
|
|
|
if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
|
|
|
|
acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb);
|
|
|
|
else if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
|
|
|
|
acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb);
|
|
|
|
else
|
|
|
|
std::cerr << "Unknown data type received. type=" << chunks[chunkIndex].type << std::endl;
|
2014-01-01 19:56:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std::cerr << "Error: received audio data for a chat dialog that does not stand Audio (Peer id = " << peer_id.toStdString() << "!" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
|
|
|
|
free(chunks[chunkIndex].data);
|
|
|
|
}
|
2012-02-25 13:15:36 -05:00
|
|
|
}
|
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
void PluginGUIHandler::ReceivedVoipBandwidthInfo(const QString& qpeer_id,int bytes_per_sec)
|
|
|
|
{
|
|
|
|
RsPeerId peer_id(qpeer_id.toStdString()) ;
|
|
|
|
|
|
|
|
ChatDialog *di = ChatDialog::getExistingChat(peer_id) ;
|
|
|
|
|
|
|
|
std::cerr << "PluginGUIHandler::received bw info for peer " << qpeer_id.toStdString() << ": " << bytes_per_sec << " Bps" << std::endl;
|
|
|
|
if(!di)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: received bandwidth info for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatWidget *cw = di->getChatWidget();
|
|
|
|
if(!cw)
|
|
|
|
{
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
|
|
|
|
|
|
|
|
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
|
|
|
|
{
|
|
|
|
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
|
|
|
|
|
|
|
|
if (acwh)
|
|
|
|
acwh->setAcceptedBandwidth(QString::fromStdString(peer_id.toStdString()),bytes_per_sec);
|
|
|
|
}
|
|
|
|
}
|