提交 5f52979f authored 作者: João Mesquita's avatar João Mesquita

Receive and make several calls. Double-click to switch between them. Needs…

Receive and make several calls. Double-click to switch between them. Needs mod_portaudio patch on MODENDP-277.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@16114 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 186cc87f
...@@ -19,6 +19,7 @@ public: ...@@ -19,6 +19,7 @@ public:
QString getCidNumber(void) { return _cid_number; } QString getCidNumber(void) { return _cid_number; }
int getCallID(void) { return _call_id; } int getCallID(void) { return _call_id; }
QString getUUID(void) { return _uuid; } QString getUUID(void) { return _uuid; }
fsphone_call_direction_t getDirection() { return _direction; }
private: private:
int _call_id; int _call_id;
......
...@@ -58,6 +58,38 @@ void FSHost::run(void) ...@@ -58,6 +58,38 @@ void FSHost::run(void)
void FSHost::generalEventHandler(switch_event_t *event) void FSHost::generalEventHandler(switch_event_t *event)
{ {
QString uuid = switch_event_get_header_nil(event, "Unique-ID");
if (_active_calls.contains(uuid))
{
switch(event->event_id) {
case SWITCH_EVENT_CHANNEL_ANSWER:
case SWITCH_EVENT_CHANNEL_BRIDGE:
{
emit answered(uuid);
break;
}
case SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:
{
emit hungup(uuid);
break;
}
case SWITCH_EVENT_CUSTOM:
{
/* We dont want to treat this anymore */
if (strcmp(event->subclass_name, "portaudio::ringing") == 0)
{
return;
}
}
default:
{
printf("Untreated event from an UUID we have: %s -> %s | %s\n", switch_event_name(event->event_id), (!zstr(event->subclass_name) ? event->subclass_name : "NULL"), uuid.toAscii().constData());
}
}
}
/* This is how we identify new calls, inbound and outbound */
switch(event->event_id) { switch(event->event_id) {
case SWITCH_EVENT_CUSTOM: case SWITCH_EVENT_CUSTOM:
{ {
...@@ -67,8 +99,18 @@ void FSHost::generalEventHandler(switch_event_t *event) ...@@ -67,8 +99,18 @@ void FSHost::generalEventHandler(switch_event_t *event)
switch_event_get_header_nil(event, "Caller-Caller-ID-Name"), switch_event_get_header_nil(event, "Caller-Caller-ID-Name"),
switch_event_get_header_nil(event, "Caller-Caller-ID-Number"), switch_event_get_header_nil(event, "Caller-Caller-ID-Number"),
FSPHONE_CALL_DIRECTION_INBOUND, FSPHONE_CALL_DIRECTION_INBOUND,
switch_event_get_header_nil(event, "Unique-ID")); uuid);
emit ringing(call); _active_calls.insert(uuid, call);
emit ringing(uuid);
}
else if (strcmp(event->subclass_name, "portaudio::makecall") == 0)
{
Call *call = new Call(atoi(switch_event_get_header_nil(event, "call_id")),NULL,
switch_event_get_header_nil(event, "Caller-Destination-Number"),
FSPHONE_CALL_DIRECTION_INBOUND,
uuid);
_active_calls.insert(uuid, call);
emit newOutgoingCall(uuid);
} }
else else
{ {
...@@ -76,10 +118,6 @@ void FSHost::generalEventHandler(switch_event_t *event) ...@@ -76,10 +118,6 @@ void FSHost::generalEventHandler(switch_event_t *event)
} }
break; break;
} }
default:
{
printf("Untreated event: %s -> %s\n", switch_event_name(event->event_id), (!zstr(event->subclass_name) ? event->subclass_name : "NULL"));
}
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define FSHOST_H #define FSHOST_H
#include <QThread> #include <QThread>
#include <QHash>
#include <switch.h> #include <switch.h>
class Call; class Call;
...@@ -13,14 +14,20 @@ public: ...@@ -13,14 +14,20 @@ public:
explicit FSHost(QObject *parent = 0); explicit FSHost(QObject *parent = 0);
switch_status_t sendCmd(const char *cmd, const char *args, QString *res); switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(switch_event_t *event); void generalEventHandler(switch_event_t *event);
Call * getCallByUUID(QString uuid) { return _active_calls.value(uuid, NULL); }
protected: protected:
void run(void); void run(void);
signals: signals:
void ready(void); void ready(void);
void ringing(Call *call); void ringing(QString);
void answered(QString);
void newOutgoingCall(QString);
void hungup(QString);
private:
QHash<QString, Call*> _active_calls;
}; };
extern FSHost g_FSHost; extern FSHost g_FSHost;
...@@ -35,7 +42,7 @@ static void eventHandlerCallback(switch_event_t *event) ...@@ -35,7 +42,7 @@ static void eventHandlerCallback(switch_event_t *event)
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
g_FSHost.generalEventHandler(clone); g_FSHost.generalEventHandler(clone);
} }
/*switch_safe_free(event);*/ switch_safe_free(clone);
} }
#endif // FSHOST_H #endif // FSHOST_H
#include <QInputDialog>
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
...@@ -8,7 +9,12 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -8,7 +9,12 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady())); connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
connect(&g_FSHost, SIGNAL(ringing(Call *)), this, SLOT(ringing(Call *))); connect(&g_FSHost, SIGNAL(ringing(QString)), this, SLOT(ringing(QString)));
connect(&g_FSHost, SIGNAL(answered(QString)), this, SLOT(answered(QString)));
connect(&g_FSHost, SIGNAL(hungup(QString)), this, SLOT(hungup(QString)));
connect(&g_FSHost, SIGNAL(newOutgoingCall(QString)), this, SLOT(newOutgoingCall(QString)));
connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer())); connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer()));
connect(ui->hangupBtn, SIGNAL(clicked()), this, SLOT(paHangup())); connect(ui->hangupBtn, SIGNAL(clicked()), this, SLOT(paHangup()));
connect(ui->listCalls, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(callListDoubleClick(QListWidgetItem*))); connect(ui->listCalls, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(callListDoubleClick(QListWidgetItem*)));
...@@ -26,7 +32,7 @@ MainWindow::~MainWindow() ...@@ -26,7 +32,7 @@ MainWindow::~MainWindow()
void MainWindow::callListDoubleClick(QListWidgetItem *item) void MainWindow::callListDoubleClick(QListWidgetItem *item)
{ {
Call *call = _lines.value(item->data(Qt::UserRole).toString()); Call *call = g_FSHost.getCallByUUID(item->data(Qt::UserRole).toString());
QString switch_str = QString("switch %1").arg(call->getCallID()); QString switch_str = QString("switch %1").arg(call->getCallID());
QString result; QString result;
if (g_FSHost.sendCmd("pa", switch_str.toAscii(), &result) == SWITCH_STATUS_FALSE) { if (g_FSHost.sendCmd("pa", switch_str.toAscii(), &result) == SWITCH_STATUS_FALSE) {
...@@ -36,9 +42,22 @@ void MainWindow::callListDoubleClick(QListWidgetItem *item) ...@@ -36,9 +42,22 @@ void MainWindow::callListDoubleClick(QListWidgetItem *item)
ui->hangupBtn->setEnabled(true); ui->hangupBtn->setEnabled(true);
} }
void MainWindow::makeCall()
{
bool ok;
QString dialstring = QInputDialog::getText(this, tr("Make new call"),
tr("Number to dial:"), QLineEdit::Normal, NULL,&ok);
if (ok && !dialstring.isEmpty())
{
paCall(dialstring);
}
}
void MainWindow::fshostReady() void MainWindow::fshostReady()
{ {
ui->statusBar->showMessage("Ready", 0); ui->statusBar->showMessage("Ready", 0);
ui->newCallBtn->setEnabled(true);
ui->textEdit->setEnabled(true); ui->textEdit->setEnabled(true);
ui->textEdit->setText("Click on line to dial number..."); ui->textEdit->setText("Click on line to dial number...");
} }
...@@ -55,11 +74,11 @@ void MainWindow::paAnswer() ...@@ -55,11 +74,11 @@ void MainWindow::paAnswer()
ui->answerBtn->setEnabled(false); ui->answerBtn->setEnabled(false);
} }
void MainWindow::paCall() void MainWindow::paCall(QString dialstring)
{ {
QString result; QString result;
QString callstring = QString("call %1").arg(ui->textEdit->toPlainText()); QString callstring = QString("call %1").arg(dialstring);
if (g_FSHost.sendCmd("pa", callstring.toAscii(), &result) == SWITCH_STATUS_FALSE) { if (g_FSHost.sendCmd("pa", callstring.toAscii(), &result) == SWITCH_STATUS_FALSE) {
ui->textEdit->setText("Error sending that command"); ui->textEdit->setText("Error sending that command");
...@@ -80,20 +99,57 @@ void MainWindow::paHangup() ...@@ -80,20 +99,57 @@ void MainWindow::paHangup()
ui->hangupBtn->setEnabled(false); ui->hangupBtn->setEnabled(false);
} }
void MainWindow::ringing(Call *call) void MainWindow::newOutgoingCall(QString uuid)
{
Call *call = g_FSHost.getCallByUUID(uuid);
ui->textEdit->setText(QString("Calling %1 (%2)").arg(call->getCidName(), call->getCidNumber()));
QListWidgetItem *item = new QListWidgetItem(tr("%1 (%2) - Calling").arg(call->getCidName(), call->getCidNumber()));
item->setData(Qt::UserRole, uuid);
ui->listCalls->addItem(item);
ui->hangupBtn->setEnabled(true);
}
void MainWindow::ringing(QString uuid)
{
Call *call = g_FSHost.getCallByUUID(uuid);
ui->textEdit->setText(QString("Call from %1 (%2)").arg(call->getCidName(), call->getCidNumber()));
QListWidgetItem *item = new QListWidgetItem(tr("%1 (%2) - Ringing").arg(call->getCidName(), call->getCidNumber()));
item->setData(Qt::UserRole, uuid);
ui->listCalls->addItem(item);
ui->answerBtn->setEnabled(true);
}
void MainWindow::answered(QString uuid)
{ {
if (_lines.contains(call->getUUID())) Call *call = g_FSHost.getCallByUUID(uuid);
for (int i=0; i<ui->listCalls->count(); i++)
{ {
delete call; QListWidgetItem *item = ui->listCalls->item(i);
if (item->data(Qt::UserRole).toString() == uuid)
{
item->setText(tr("%1 (%2) - Active").arg(call->getCidName(), call->getCidNumber()));
break;
} }
else }
}
void MainWindow::hungup(QString uuid)
{
Call *call = g_FSHost.getCallByUUID(uuid);
for (int i=0; i<ui->listCalls->count(); i++)
{
QListWidgetItem *item = ui->listCalls->item(i);
if (item->data(Qt::UserRole).toString() == uuid)
{ {
_lines.insert(call->getUUID(), call); delete ui->listCalls->takeItem(i);
ui->textEdit->setText(QString("Number: %1\nName: %3").arg(call->getCidNumber(), call->getCidName())); break;
QListWidgetItem *item = new QListWidgetItem(tr("%1 - %2 (Ringing)").arg(call->getCidName(), call->getCidNumber()), ui->listCalls);
item->setData(Qt::UserRole, call->getUUID());
} }
ui->answerBtn->setEnabled(true); }
ui->textEdit->setText(tr("Call with %1 (%2) hungup.").arg(call->getCidName(), call->getCidNumber()));
/* TODO: Will cause problems if 2 calls are received at the same time */
ui->answerBtn->setEnabled(false);
ui->hangupBtn->setEnabled(false);
} }
void MainWindow::changeEvent(QEvent *e) void MainWindow::changeEvent(QEvent *e)
......
...@@ -54,15 +54,18 @@ protected: ...@@ -54,15 +54,18 @@ protected:
private slots: private slots:
void callListDoubleClick(QListWidgetItem *); void callListDoubleClick(QListWidgetItem *);
void makeCall();
void fshostReady(); void fshostReady();
void paAnswer(); void paAnswer();
void paCall(); void paCall(QString);
void paHangup(); void paHangup();
void ringing(Call *); void newOutgoingCall(QString);
void ringing(QString);
void answered(QString);
void hungup(QString);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QHash<QString, Call *> _lines;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论