-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtask.cpp
89 lines (74 loc) · 2.34 KB
/
task.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "task.h"
Task::Task(QObject * parent) :
QObject(parent),
signaling_server_port(8118)
{
Utils::SetupTimestamp();
Utils::SetupProtocolVersionSignature();
signaling_server = new QWebSocketServer(QStringLiteral("Signaling Server"), QWebSocketServer::NonSecureMode, this);
if (signaling_server->listen(QHostAddress::Any, signaling_server_port)) {
connect(signaling_server, &QWebSocketServer::newConnection, this, &Task::Connect);
connect(signaling_server, &QWebSocketServer::closed, this, &Task::Disconnect);
}
}
Task::~Task()
{
for (int i = 0; i < hifi_connections.size(); i++)
{
hifi_connections[i]->Stop();
hifi_connections[i]->disconnect();
delete hifi_connections[i];
}
signaling_server->close();
}
void Task::ProcessCommandLineArguments(int argc, char * argv[])
{
for (int i=1; i<argc; ++i) {
const QString s = QString(argv[i]).toLower();
if (s.right(7) == "-iceserver" && i+2 < argc) {
Utils::SetDefaultIceServerAddress(QHostAddress(QString(argv[i+1])));
Utils::SetDefaultIceServerPort(QString(argv[i+2]).toInt());
i+=2;
}
else if (s.right(5) == "-help") {
qDebug() << "Usage: \n hifi_webrtc_relay [-iceserver address port] [-help]";
// Just exit after displaying this help message
exit(0);
}
}
}
void Task::run()
{
qDebug() << "Task::run() - Started HiFi WebRTC Relay";
// Application runs indefinitely (until terminated - e.g. Ctrl+C)
// Q_EMIT finished();
}
void Task::Connect()
{
QWebSocket *s = signaling_server->nextPendingConnection();
HifiConnection * h = new HifiConnection(s);
connect(h, SIGNAL(Disconnected()), this, SLOT(DisconnectHifiConnection()), Qt::QueuedConnection);
hifi_connections.push_back(h);
}
void Task::Disconnect()
{
}
void Task::ServerConnected()
{
//qDebug() << "Task::ServerConnected()";
}
void Task::ServerDisconnected()
{
//qDebug() << "Task::ServerDisconnected()";
}
void Task::DisconnectHifiConnection()
{
HifiConnection *s = qobject_cast<HifiConnection *>(sender());
if (hifi_connections.contains(s)) {
hifi_connections.removeAll(s);
qDebug() << "Task::DisconnectHifiConnection()" << s;
s->Stop();
s->disconnect();
//s->deleteLater();
}
}