diff --git a/WSServer.cpp b/WSServer.cpp index af330a42..5d0d9f02 100644 --- a/WSServer.cpp +++ b/WSServer.cpp @@ -19,6 +19,8 @@ with this program. If not, see #include #include #include +#include +#include #include #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(); } } diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 1387db63..f51633f3 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -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" \ No newline at end of file +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." \ No newline at end of file diff --git a/data/locale/fr-FR.ini b/data/locale/fr-FR.ini index 1f37623c..4f83f31a 100644 --- a/data/locale/fr-FR.ini +++ b/data/locale/fr-FR.ini @@ -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é" \ No newline at end of file +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." \ No newline at end of file