mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
General: code and docs cleanup
This commit is contained in:
12
Config.cpp
12
Config.cpp
@ -47,11 +47,11 @@ Config::Config() :
|
|||||||
// OBS Config defaults
|
// OBS Config defaults
|
||||||
config_t* obs_config = obs_frontend_get_global_config();
|
config_t* obs_config = obs_frontend_get_global_config();
|
||||||
if (obs_config) {
|
if (obs_config) {
|
||||||
config_set_default_bool(obs_config,
|
config_set_default_bool(obs_config,
|
||||||
SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
||||||
config_set_default_uint(obs_config,
|
config_set_default_uint(obs_config,
|
||||||
SECTION_NAME, PARAM_PORT, ServerPort);
|
SECTION_NAME, PARAM_PORT, ServerPort);
|
||||||
|
|
||||||
config_set_default_bool(obs_config,
|
config_set_default_bool(obs_config,
|
||||||
SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
||||||
config_set_default_bool(obs_config,
|
config_set_default_bool(obs_config,
|
||||||
@ -82,7 +82,7 @@ void Config::Load() {
|
|||||||
|
|
||||||
ServerEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_ENABLE);
|
ServerEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_ENABLE);
|
||||||
ServerPort = config_get_uint(obs_config, SECTION_NAME, PARAM_PORT);
|
ServerPort = config_get_uint(obs_config, SECTION_NAME, PARAM_PORT);
|
||||||
|
|
||||||
DebugEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_DEBUG);
|
DebugEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_DEBUG);
|
||||||
AlertsEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_ALERT);
|
AlertsEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_ALERT);
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ void Config::Save() {
|
|||||||
|
|
||||||
config_set_bool(obs_config, SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
config_set_bool(obs_config, SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
||||||
config_set_uint(obs_config, SECTION_NAME, PARAM_PORT, ServerPort);
|
config_set_uint(obs_config, SECTION_NAME, PARAM_PORT, ServerPort);
|
||||||
|
|
||||||
config_set_bool(obs_config, SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
config_set_bool(obs_config, SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
||||||
config_set_bool(obs_config, SECTION_NAME, PARAM_ALERT, AlertsEnabled);
|
config_set_bool(obs_config, SECTION_NAME, PARAM_ALERT, AlertsEnabled);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ const char* Config::GenerateSecret(const char* password, const char* salt) {
|
|||||||
mbedtls_sha256(
|
mbedtls_sha256(
|
||||||
(unsigned char*)passAndSalt.c_str(), passAndSalt.length(),
|
(unsigned char*)passAndSalt.c_str(), passAndSalt.length(),
|
||||||
challengeHash, 0);
|
challengeHash, 0);
|
||||||
|
|
||||||
// Encode SHA256 hash to Base64
|
// Encode SHA256 hash to Base64
|
||||||
char* challenge = (char*)bzalloc(64);
|
char* challenge = (char*)bzalloc(64);
|
||||||
size_t challenge_bytes = 0;
|
size_t challenge_bytes = 0;
|
||||||
|
4
Config.h
4
Config.h
@ -37,7 +37,7 @@ class Config {
|
|||||||
|
|
||||||
bool ServerEnabled;
|
bool ServerEnabled;
|
||||||
uint64_t ServerPort;
|
uint64_t ServerPort;
|
||||||
|
|
||||||
bool DebugEnabled;
|
bool DebugEnabled;
|
||||||
bool AlertsEnabled;
|
bool AlertsEnabled;
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class Config {
|
|||||||
const char* Salt;
|
const char* Salt;
|
||||||
const char* SessionChallenge;
|
const char* SessionChallenge;
|
||||||
bool SettingsLoaded;
|
bool SettingsLoaded;
|
||||||
|
|
||||||
static Config* Current();
|
static Config* Current();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
64
WSEvents.cpp
64
WSEvents.cpp
@ -2,7 +2,7 @@
|
|||||||
* obs-websocket
|
* obs-websocket
|
||||||
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
* Copyright (C) 2017 Brendan Hagan <https://github.com/haganbmj>
|
* Copyright (C) 2017 Brendan Hagan <https://github.com/haganbmj>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -115,8 +115,6 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private
|
|||||||
if (!owner->_srv)
|
if (!owner->_srv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO : implement SourceOrderChanged and RepopulateSources
|
|
||||||
|
|
||||||
if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) {
|
if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) {
|
||||||
owner->OnSceneChange();
|
owner->OnSceneChange();
|
||||||
}
|
}
|
||||||
@ -669,25 +667,25 @@ void WSEvents::StreamStatus() {
|
|||||||
obs_output_release(stream_output);
|
obs_output_release(stream_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************************************
|
/**
|
||||||
* Heatbeat is emitted every 2 seconds, when enabled with request: SetHeartbeat *
|
* Emitted every 2 seconds after enabling it by calling SetHeartbeat.
|
||||||
* *
|
*
|
||||||
* @return {boolean} `pulse` Toggles between every JSON meassage as an "I am alive" indicator. *
|
* @return {boolean} `pulse` Toggles between every JSON meassage as an "I am alive" indicator.
|
||||||
* @return {string (optional)} `current-profile` Current active profile. *
|
* @return {string (optional)} `current-profile` Current active profile.
|
||||||
* @return {string (optional)} `current-scene` Current active scene. *
|
* @return {string (optional)} `current-scene` Current active scene.
|
||||||
* @return {boolean (optional)} `streaming` Current streaming state. *
|
* @return {boolean (optional)} `streaming` Current streaming state.
|
||||||
* @return {int (optional)} `total-stream-time` Total time (in seconds) since the stream started. *
|
* @return {int (optional)} `total-stream-time` Total time (in seconds) since the stream started.
|
||||||
* @return {int (optional)} `total-stream-bytes` Total bytes sent since the stream started. *
|
* @return {int (optional)} `total-stream-bytes` Total bytes sent since the stream started.
|
||||||
* @return {int (optional)} `total-stream-frames` Total frames streamed since the stream started. *
|
* @return {int (optional)} `total-stream-frames` Total frames streamed since the stream started.
|
||||||
* @return {boolean (optional)} `recording` Current recording state. *
|
* @return {boolean (optional)} `recording` Current recording state.
|
||||||
* @return {int (optional)} `total-record-time` Total time (in seconds) since recording started. *
|
* @return {int (optional)} `total-record-time` Total time (in seconds) since recording started.
|
||||||
* @return {int (optional)} `total-record-bytes` Total bytes recorded since the recording started. *
|
* @return {int (optional)} `total-record-bytes` Total bytes recorded since the recording started.
|
||||||
* @return {int (optional)} `total-record-frames` Total frames recorded since the recording started. *
|
* @return {int (optional)} `total-record-frames` Total frames recorded since the recording started.
|
||||||
* *
|
*
|
||||||
* @api events *
|
* @api events
|
||||||
* @name Heartbeat *
|
* @name Heartbeat
|
||||||
* @category general *
|
* @category general
|
||||||
************************************************************************ September 2017 *** by RainbowEK ***/
|
*/
|
||||||
void WSEvents::Heartbeat() {
|
void WSEvents::Heartbeat() {
|
||||||
|
|
||||||
if (!Heartbeat_active) return;
|
if (!Heartbeat_active) return;
|
||||||
@ -709,20 +707,20 @@ void WSEvents::Heartbeat() {
|
|||||||
obs_data_set_string(data, "current-scene", name);
|
obs_data_set_string(data, "current-scene", name);
|
||||||
|
|
||||||
obs_data_set_bool(data, "streaming", streaming_active);
|
obs_data_set_bool(data, "streaming", streaming_active);
|
||||||
if (streaming_active) {
|
if (streaming_active) {
|
||||||
uint64_t totalStreamTime = (os_gettime_ns() - _stream_starttime) / 1000000000;
|
uint64_t totalStreamTime = (os_gettime_ns() - _stream_starttime) / 1000000000;
|
||||||
obs_data_set_int(data, "total-stream-time", totalStreamTime);
|
obs_data_set_int(data, "total-stream-time", totalStreamTime);
|
||||||
obs_data_set_int(data, "total-stream-bytes", (uint64_t)obs_output_get_total_bytes(stream_output));
|
obs_data_set_int(data, "total-stream-bytes", (uint64_t)obs_output_get_total_bytes(stream_output));
|
||||||
obs_data_set_int(data, "total-stream-frames", obs_output_get_total_frames(stream_output));
|
obs_data_set_int(data, "total-stream-frames", obs_output_get_total_frames(stream_output));
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_data_set_bool(data, "recording", recording_active);
|
obs_data_set_bool(data, "recording", recording_active);
|
||||||
if (recording_active) {
|
if (recording_active) {
|
||||||
uint64_t totalRecordTime = (os_gettime_ns() - _rec_starttime) / 1000000000;
|
uint64_t totalRecordTime = (os_gettime_ns() - _rec_starttime) / 1000000000;
|
||||||
obs_data_set_int(data, "total-record-time", totalRecordTime);
|
obs_data_set_int(data, "total-record-time", totalRecordTime);
|
||||||
obs_data_set_int(data, "total-record-bytes", (uint64_t)obs_output_get_total_bytes(record_output));
|
obs_data_set_int(data, "total-record-bytes", (uint64_t)obs_output_get_total_bytes(record_output));
|
||||||
obs_data_set_int(data, "total-record-frames", obs_output_get_total_frames(record_output));
|
obs_data_set_int(data, "total-record-frames", obs_output_get_total_frames(record_output));
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcastUpdate("Heartbeat", data);
|
broadcastUpdate("Heartbeat", data);
|
||||||
obs_data_release(data);
|
obs_data_release(data);
|
||||||
|
@ -31,16 +31,16 @@ class WSEvents : public QObject {
|
|||||||
~WSEvents();
|
~WSEvents();
|
||||||
static void FrontendEventHandler(
|
static void FrontendEventHandler(
|
||||||
enum obs_frontend_event event, void* private_data);
|
enum obs_frontend_event event, void* private_data);
|
||||||
|
static WSEvents* Instance;
|
||||||
void connectTransitionSignals(obs_source_t* transition);
|
void connectTransitionSignals(obs_source_t* transition);
|
||||||
void connectSceneSignals(obs_source_t* scene);
|
void connectSceneSignals(obs_source_t* scene);
|
||||||
static WSEvents* Instance;
|
|
||||||
|
|
||||||
uint64_t GetStreamingTime();
|
uint64_t GetStreamingTime();
|
||||||
const char* GetStreamingTimecode();
|
const char* GetStreamingTimecode();
|
||||||
uint64_t GetRecordingTime();
|
uint64_t GetRecordingTime();
|
||||||
const char* GetRecordingTimecode();
|
const char* GetRecordingTimecode();
|
||||||
|
|
||||||
bool Heartbeat_active;
|
bool Heartbeat_active;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void deferredInitOperations();
|
void deferredInitOperations();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* obs-websocket
|
* obs-websocket
|
||||||
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
* Copyright (C) 2017 Mikhail Swift <https://github.com/mikhailswift>
|
* Copyright (C) 2017 Mikhail Swift <https://github.com/mikhailswift>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -243,8 +243,8 @@ void WSRequestHandler::HandleGetVersion(WSRequestHandler* req) {
|
|||||||
* and `salt` (see "Authentication" for more information).
|
* and `salt` (see "Authentication" for more information).
|
||||||
*
|
*
|
||||||
* @return {boolean} `authRequired` Indicates whether authentication is required.
|
* @return {boolean} `authRequired` Indicates whether authentication is required.
|
||||||
* @return {String (optional)} `challenge`
|
* @return {String (optional)} `challenge`
|
||||||
* @return {String (optional)} `salt`
|
* @return {String (optional)} `salt`
|
||||||
*
|
*
|
||||||
* @api requests
|
* @api requests
|
||||||
* @name GetAuthRequired
|
* @name GetAuthRequired
|
||||||
@ -300,45 +300,42 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************************************
|
/**
|
||||||
* Heatbeat update message is emitted every 2 seconds, when enabled with this request. *
|
* Enable/disable sending of the Heartbeat event
|
||||||
* When the Heartbeat is enabled it always sends a `pulse` to indicate that the host obs is alive. *
|
*
|
||||||
* Read comment from 'void WSEvents::Heartbeat()' for the total picture. *
|
* @param {boolean} `enable` Starts/Stops emitting heartbeat messages
|
||||||
* *
|
*
|
||||||
* @param {boolean} `enable` Starts/Stops emitting heartbeat messages *
|
* @api requests
|
||||||
* *
|
* @name HandleSetHeartbeat
|
||||||
* @api requests *
|
* @category general
|
||||||
* @name HandleSetHeartbeat *
|
*/
|
||||||
* @category general *
|
|
||||||
************************************************************************ September 2017 *** by RainbowEK ***/
|
|
||||||
void WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) {
|
void WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) {
|
||||||
if (!req->hasField("enable")) {
|
if (!req->hasField("enable")) {
|
||||||
req->SendErrorResponse("Heartbeat <enable> parameter missing");
|
req->SendErrorResponse("Heartbeat <enable> parameter missing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WSEvents::Instance->Heartbeat_active =
|
||||||
|
obs_data_get_bool(req->data, "enable");
|
||||||
|
|
||||||
obs_data_t* response = obs_data_create();
|
obs_data_t* response = obs_data_create();
|
||||||
|
obs_data_set_bool(response, "enable",
|
||||||
bool keyValue = obs_data_get_bool(req->data, "enable");
|
WSEvents::Instance->Heartbeat_active);
|
||||||
if (keyValue) WSEvents::Instance->Heartbeat_active = true;
|
|
||||||
else WSEvents::Instance->Heartbeat_active = false;
|
|
||||||
|
|
||||||
obs_data_set_bool(response, "enable", keyValue);
|
|
||||||
req->SendOKResponse(response);
|
req->SendOKResponse(response);
|
||||||
|
|
||||||
obs_data_release(response);
|
obs_data_release(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch to the specified scene.
|
* Switch to the specified scene.
|
||||||
*
|
*
|
||||||
* @param {String} `scene-name` Name of the scene to switch to.
|
* @param {String} `scene-name` Name of the scene to switch to.
|
||||||
*
|
*
|
||||||
* @api requests
|
* @api requests
|
||||||
* @name SetCurrentScene
|
* @name SetCurrentScene
|
||||||
* @category scenes
|
* @category scenes
|
||||||
* @since 0.3
|
* @since 0.3
|
||||||
*/
|
*/
|
||||||
void WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) {
|
void WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) {
|
||||||
if (!req->hasField("scene-name")) {
|
if (!req->hasField("scene-name")) {
|
||||||
req->SendErrorResponse("missing request parameters");
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
Reference in New Issue
Block a user