mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
ui: show a warning message when server can't bind to configured port
This commit is contained in:
parent
952f3a586a
commit
d76ff16162
29
WSServer.cpp
29
WSServer.cpp
@ -19,6 +19,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "WSServer.h"
|
||||
@ -54,9 +56,26 @@ void WSServer::Start(quint16 port) {
|
||||
|
||||
bool serverStarted = _wsServer->listen(QHostAddress::Any, port);
|
||||
if (serverStarted) {
|
||||
blog(LOG_INFO, "server started successfully on TCP port %d", port);
|
||||
|
||||
connect(_wsServer, SIGNAL(newConnection()),
|
||||
this, SLOT(onNewConnection()));
|
||||
}
|
||||
else {
|
||||
QString errorString = _wsServer->errorString();
|
||||
blog(LOG_ERROR,
|
||||
"error: failed to start server on TCP port %d: %s",
|
||||
port, errorString.toUtf8().constData());
|
||||
|
||||
QMainWindow* mainWindow = (QMainWindow*)obs_frontend_get_main_window();
|
||||
|
||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||
QString title = tr("OBSWebsocket.Server.StartFailed.Title");
|
||||
QString msg = tr("OBSWebsocket.Server.StartFailed.Message").arg(port);
|
||||
obs_frontend_pop_ui_translation();
|
||||
|
||||
QMessageBox::warning(mainWindow, title, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void WSServer::Stop() {
|
||||
@ -67,6 +86,8 @@ void WSServer::Stop() {
|
||||
locker.unlock();
|
||||
|
||||
_wsServer->close();
|
||||
|
||||
blog(LOG_INFO, "server stopped successfully");
|
||||
}
|
||||
|
||||
void WSServer::broadcast(QString message) {
|
||||
@ -102,14 +123,12 @@ void WSServer::onNewConnection() {
|
||||
clientIp.toUtf8().constData(), pSocket->peerPort());
|
||||
|
||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||
|
||||
QString title = tr("OBSWebsocket.NotifyConnect.Title");
|
||||
QString msg = tr("OBSWebsocket.NotifyConnect.Message")
|
||||
.arg(Utils::FormatIPAddress(clientAddr));
|
||||
obs_frontend_pop_ui_translation();
|
||||
|
||||
Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, title);
|
||||
|
||||
obs_frontend_pop_ui_translation();
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,13 +158,11 @@ void WSServer::onSocketDisconnected() {
|
||||
clientIp.toUtf8().constData(), pSocket->peerPort());
|
||||
|
||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||
|
||||
QString title = tr("OBSWebsocket.NotifyDisconnect.Title");
|
||||
QString msg = tr("OBSWebsocket.NotifyDisconnect.Message")
|
||||
.arg(Utils::FormatIPAddress(clientAddr));
|
||||
obs_frontend_pop_ui_translation();
|
||||
|
||||
Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, title);
|
||||
|
||||
obs_frontend_pop_ui_translation();
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,6 @@ OBSWebsocket.Settings.AlertsEnable="Enable System Tray Alerts"
|
||||
OBSWebsocket.NotifyConnect.Title="New WebSocket connection"
|
||||
OBSWebsocket.NotifyConnect.Message="Client %1 connected"
|
||||
OBSWebsocket.NotifyDisconnect.Title="WebSocket client disconnected"
|
||||
OBSWebsocket.NotifyDisconnect.Message="Client %1 disconnected"
|
||||
OBSWebsocket.NotifyDisconnect.Message="Client %1 disconnected"
|
||||
OBSWebsocket.Server.StartFailed.Title="WebSocket Server failure"
|
||||
OBSWebsocket.Server.StartFailed.Message="The obs-websocket server failed to start, maybe because:\n - TCP port %1 may currently be in use elsewhere on this system, possibly by another application. Try setting a different TCP port in the WebSocket server settings, or stop any application that could be using this port.\n - An unknown network error happened on your system. Try again by changing settings, restarting OBS or restarting your system."
|
@ -9,4 +9,6 @@ OBSWebsocket.Settings.AlertsEnable="Notifications de connexion/déconnexion"
|
||||
OBSWebsocket.NotifyConnect.Title="Nouvelle connexion WebSocket"
|
||||
OBSWebsocket.NotifyConnect.Message="Le client %1 s'est connecté"
|
||||
OBSWebsocket.NotifyDisconnect.Title="Déconnexion WebSocket"
|
||||
OBSWebsocket.NotifyDisconnect.Message="Le client %1 s'est déconnecté"
|
||||
OBSWebsocket.NotifyDisconnect.Message="Le client %1 s'est déconnecté"
|
||||
OBSWebsocket.Server.StartFailed.Title="Impossible de démarrer le serveur WebSocket"
|
||||
OBSWebsocket.Server.StartFailed.Message="Le serveur WebSocket n'a pas pu démarrer, peut-être parce que :\n - Le port TCP %1 est en cours d'utilisation sur ce système, certainement par un autre programme. Essayez un port différent dans les réglages du serveur WebSocket, ou arrêtez tout programme susceptible d'utiliser ce port.\n - Une erreur réseau inconnue est survenue. Essayez à nouveau en modifiant vos réglages, en redémarrant OBS ou en redémarrant votre ordinateur."
|
Loading…
x
Reference in New Issue
Block a user