mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
A bit of cleaning
This commit is contained in:
parent
5ca55fc13e
commit
d6091c83e2
@ -20,6 +20,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include <mbedtls/sha256.h>
|
||||
#include <obs-frontend-api.h>
|
||||
#include <util/config-file.h>
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#define SECTION_NAME "WebsocketAPI"
|
||||
|
1
Config.h
1
Config.h
@ -19,7 +19,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <obs-module.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
|
||||
|
@ -17,6 +17,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "Utils.h"
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
obs_data_array_t* Utils::GetSceneItems(obs_source_t *source) {
|
||||
obs_data_array_t *items = obs_data_array_create();
|
||||
|
1
Utils.h
1
Utils.h
@ -21,7 +21,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <obs-module.h>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
class Utils
|
||||
{
|
||||
|
@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License along
|
||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include <util/platform.h>
|
||||
#include <QTimer>
|
||||
|
||||
#include "WSEvents.h"
|
||||
|
||||
WSEvents::WSEvents(WSServer *srv) {
|
||||
|
@ -20,10 +20,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#ifndef WSEVENTS_H
|
||||
#define WSEVENTS_H
|
||||
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <QTimer>
|
||||
#include <obs-frontend-api.h>
|
||||
#include <util/platform.h>
|
||||
|
||||
#include "WSServer.h"
|
||||
|
||||
class WSEvents : public QObject
|
||||
|
@ -73,7 +73,7 @@ void WSRequestHandler::processIncomingMessage(QString textMessage)
|
||||
msg = "<null pointer>";
|
||||
}
|
||||
|
||||
blog(LOG_ERROR, "[obs-websockets] invalid JSON payload received for '%s'", msg);
|
||||
blog(LOG_ERROR, "invalid JSON payload received for '%s'", msg);
|
||||
SendErrorResponse("invalid JSON payload");
|
||||
return;
|
||||
}
|
||||
@ -181,18 +181,13 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler *owner)
|
||||
return;
|
||||
}
|
||||
|
||||
blog(LOG_INFO, "[obs-websocket] preauth : client_authenticated : %d", owner->_client->property(PROP_AUTHENTICATED).toBool());
|
||||
|
||||
if ((owner->_client->property(PROP_AUTHENTICATED).toBool() == false) && Config::Current()->CheckAuth(auth))
|
||||
{
|
||||
blog(LOG_INFO, "[obs-websocket] auth successful");
|
||||
|
||||
owner->_client->setProperty(PROP_AUTHENTICATED, true);
|
||||
owner->SendOKResponse();
|
||||
}
|
||||
else
|
||||
{
|
||||
blog(LOG_INFO, "[obs-websocket] auth refused");
|
||||
owner->SendErrorResponse("Authentication Failed.");
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#ifndef WSREQUESTHANDLER_H
|
||||
#define WSREQUESTHANDLER_H
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <QtWebSockets/QWebSocketServer>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
class WSRequestHandler : public QObject
|
||||
{
|
||||
|
14
WSServer.cpp
14
WSServer.cpp
@ -16,20 +16,18 @@ You should have received a copy of the GNU General Public License along
|
||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "WSServer.h"
|
||||
#include "WSRequestHandler.h"
|
||||
#include "Config.h"
|
||||
#include <QtWebSockets/QWebSocketServer>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "WSServer.h"
|
||||
#include "obs-websocket.h"
|
||||
#include "Config.h"
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
WSServer* WSServer::Instance = new WSServer();
|
||||
WSServer* WSServer::Instance = nullptr;
|
||||
|
||||
WSServer::WSServer(QObject *parent) :
|
||||
QObject(parent),
|
||||
@ -116,7 +114,7 @@ void WSServer::onNewConnection()
|
||||
_clMutex.unlock();
|
||||
|
||||
QByteArray client_ip = pSocket->peerAddress().toString().toUtf8();
|
||||
blog(LOG_INFO, "[obs-websockets] new client connection from %s:%d", client_ip.constData(), pSocket->peerPort());
|
||||
blog(LOG_INFO, "new client connection from %s:%d", client_ip.constData(), pSocket->peerPort());
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,6 +144,6 @@ void WSServer::socketDisconnected()
|
||||
pSocket->deleteLater();
|
||||
|
||||
QByteArray client_ip = pSocket->peerAddress().toString().toUtf8();
|
||||
blog(LOG_INFO, "[obs-websockets] client %s:%d disconnected", client_ip.constData(), pSocket->peerPort());
|
||||
blog(LOG_INFO, "client %s:%d disconnected", client_ip.constData(), pSocket->peerPort());
|
||||
}
|
||||
}
|
@ -22,13 +22,12 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QThread>
|
||||
#include "WSRequestHandler.h"
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
||||
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
||||
|
||||
#include "WSRequestHandler.h"
|
||||
|
||||
class WSServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -19,6 +19,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include <obs-module.h>
|
||||
#include <obs-frontend-api.h>
|
||||
#include <QAction>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "obs-websocket.h"
|
||||
#include "WSServer.h"
|
||||
@ -34,10 +35,14 @@ SettingsDialog *settings_dialog;
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
|
||||
|
||||
// Core setup
|
||||
Config* config = Config::Current();
|
||||
config->Load();
|
||||
|
||||
WSServer::Instance = new WSServer();
|
||||
|
||||
if (config->ServerEnabled)
|
||||
WSServer::Instance->Start(config->ServerPort);
|
||||
|
||||
@ -47,7 +52,8 @@ bool obs_module_load(void)
|
||||
QAction *menu_action = (QAction*)obs_frontend_add_tools_menu_qaction(obs_module_text("OBSWebsocket.Menu.SettingsItem"));
|
||||
|
||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||
settings_dialog = new SettingsDialog();
|
||||
QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window();
|
||||
settings_dialog = new SettingsDialog(main_window);
|
||||
obs_frontend_pop_ui_translation();
|
||||
|
||||
auto menu_cb = [] {
|
||||
@ -56,13 +62,13 @@ bool obs_module_load(void)
|
||||
menu_action->connect(menu_action, &QAction::triggered, menu_cb);
|
||||
|
||||
// Loading finished
|
||||
blog(LOG_INFO, "[obs-websockets] you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
|
||||
blog(LOG_INFO, "module loaded!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void obs_module_unload()
|
||||
{
|
||||
blog(LOG_INFO, "[obs-websockets] goodbye !");
|
||||
blog(LOG_INFO, "goodbye!");
|
||||
}
|
||||
|
||||
|
@ -22,4 +22,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#define PROP_AUTHENTICATED "wsclient_authenticated"
|
||||
#define OBS_WEBSOCKET_VERSION "4.0.0"
|
||||
|
||||
#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__)
|
||||
|
||||
#endif // OBSWEBSOCKET_H
|
Loading…
x
Reference in New Issue
Block a user