SettingsDialog: Add Identified column to session table

This commit is contained in:
tt2468 2021-04-30 11:24:09 -07:00
parent 997dc40d6c
commit 04f7b33755
5 changed files with 38 additions and 10 deletions

View File

@ -12,6 +12,7 @@ OBSWebSocket.Settings.DebugEnableHoverText="Changing this requires the WebSocket
OBSWebSocket.SessionTable.RemoteAddressColumnTitle="Remote Address"
OBSWebSocket.SessionTable.SessionDurationColumnTitle="Session Duration"
OBSWebSocket.SessionTable.MessagesInOutColumnTitle="Messages In/Out"
OBSWebSocket.SessionTable.IdentifiedTitle="Identified"
OBSWebSocket.SessionTable.KickButtonColumnTitle="Kick?"
OBSWebSocket.SessionTable.KickButtonText="Kick"

View File

@ -180,8 +180,9 @@ std::vector<WebSocketServer::WebSocketSessionState> WebSocketServer::GetWebSocke
uint64_t incomingMessages = session->IncomingMessages();
uint64_t outgoingMessages = session->OutgoingMessages();
std::string remoteAddress = session->RemoteAddress();
bool isIdentified = session->IsIdentified();
webSocketSessions.emplace_back(WebSocketSessionState{hdl, remoteAddress, connectedAt, incomingMessages, outgoingMessages});
webSocketSessions.emplace_back(WebSocketSessionState{hdl, remoteAddress, connectedAt, incomingMessages, outgoingMessages, isIdentified});
}
lock.unlock();
@ -276,8 +277,8 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
helloMessage["messageType"] = "Hello";
helloMessage["obsWebSocketVersion"] = OBS_WEBSOCKET_VERSION;
helloMessage["rpcVersion"] = OBS_WEBSOCKET_RPC_VERSION;
helloMessage["availableRequests"] = WebSocketProtocol::GetRequestList();
helloMessage["availableEvents"] = WebSocketProtocol::GetEventList();
//helloMessage["availableRequests"] = WebSocketProtocol::GetRequestList();
//helloMessage["availableEvents"] = WebSocketProtocol::GetEventList();
if (AuthenticationRequired) {
std::string sessionChallenge = Utils::Crypto::GenerateSalt();
session->SetChallenge(sessionChallenge);
@ -323,6 +324,7 @@ void WebSocketServer::onClose(websocketpp::connection_hdl hdl)
state.connectedAt = connectedAt;
state.incomingMessages = incomingMessages;
state.outgoingMessages = outgoingMessages;
state.isIdentified = isIdentified;
// Emit signals
emit ClientDisconnected(state, conn->get_local_close_code());

View File

@ -58,6 +58,7 @@ class WebSocketServer : QObject
uint64_t connectedAt;
uint64_t incomingMessages;
uint64_t outgoingMessages;
bool isIdentified;
};
WebSocketServer();

View File

@ -4,6 +4,8 @@
#include <QClipboard>
#include <QDateTime>
#include <QTime>
#include <QPixmap>
#include <QIcon>
#include "SettingsDialog.h"
#include "../obs-websocket.h"
@ -18,7 +20,8 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
sessionTableTimer(new QTimer)
{
ui->setupUi(this);
ui->websocketSessionTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
ui->websocketSessionTable->horizontalHeader()->resizeSection(3, 100);
ui->websocketSessionTable->horizontalHeader()->resizeSection(4, 100);
connect(ui->buttonBox, &QDialogButtonBox::accepted,
this, &SettingsDialog::FormAccepted);
@ -91,9 +94,16 @@ void SettingsDialog::FillSessionTable()
auto webSocketSessions = webSocketServer->GetWebSocketSessions();
size_t rowCount = webSocketSessions.size();
// Manually setting the pixmap size *might* break with highdpi. Not sure though
QIcon checkIcon = style()->standardIcon(QStyle::SP_DialogOkButton);
QPixmap checkIconPixmap = checkIcon.pixmap(QSize(25, 25));
QIcon crossIcon = style()->standardIcon(QStyle::SP_DialogCancelButton);
QPixmap crossIconPixmap = crossIcon.pixmap(QSize(25, 25));
obs_frontend_push_ui_translation(obs_module_get_string);
QString kickButtonText = QObject::tr("OBSWebSocket.SessionTable.KickButtonText");
obs_frontend_pop_ui_translation();
ui->websocketSessionTable->setRowCount(rowCount);
size_t i = 0;
for (auto session : webSocketSessions) {
@ -107,6 +117,15 @@ void SettingsDialog::FillSessionTable()
QTableWidgetItem *statsItem = new QTableWidgetItem(QString("%1/%2").arg(session.incomingMessages).arg(session.outgoingMessages));
ui->websocketSessionTable->setItem(i, 2, statsItem);
QLabel *identifiedLabel = new QLabel();
identifiedLabel->setAlignment(Qt::AlignCenter);
if (session.isIdentified) {
identifiedLabel->setPixmap(checkIconPixmap);
} else {
identifiedLabel->setPixmap(crossIconPixmap);
}
ui->websocketSessionTable->setCellWidget(i, 3, identifiedLabel);
QPushButton *invalidateButton = new QPushButton(kickButtonText, this);
QWidget *invalidateButtonWidget = new QWidget();
QHBoxLayout *invalidateButtonLayout = new QHBoxLayout(invalidateButtonWidget);
@ -114,7 +133,7 @@ void SettingsDialog::FillSessionTable()
invalidateButtonLayout->setAlignment(Qt::AlignCenter);
invalidateButtonLayout->setContentsMargins(0, 0, 0, 0);
invalidateButtonWidget->setLayout(invalidateButtonLayout);
ui->websocketSessionTable->setCellWidget(i, 3, invalidateButtonWidget);
ui->websocketSessionTable->setCellWidget(i, 4, invalidateButtonWidget);
connect(invalidateButton, &QPushButton::clicked, [=]() {
webSocketServer->InvalidateSession(session.hdl);
});

View File

@ -6,19 +6,19 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<width>675</width>
<height>437</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>437</height>
<width>675</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>600</width>
<width>675</width>
<height>16777215</height>
</size>
</property>
@ -156,7 +156,7 @@
<bool>false</bool>
</property>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>135</number>
<number>100</number>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>135</number>
@ -182,6 +182,11 @@
<string>OBSWebSocket.SessionTable.MessagesInOutColumnTitle</string>
</property>
</column>
<column>
<property name="text">
<string>OBSWebSocket.SessionTable.IdentifiedTitle</string>
</property>
</column>
<column>
<property name="text">
<string>OBSWebSocket.SessionTable.KickButtonColumnTitle</string>