Skip to content

Commit

Permalink
Replace json11 by Nlohmann JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
tytan652 authored and Lain-B committed Jun 29, 2023
1 parent 5c8c9e7 commit 0f1ff75
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 1,081 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if(NOT ENABLE_BROWSER)
endif()

find_package(CEF REQUIRED)
find_package(nlohmann_json REQUIRED)

add_library(obs-browser MODULE)
add_library(OBS::browser ALIAS obs-browser)
Expand All @@ -33,8 +34,6 @@ target_sources(
browser-scheme.hpp
browser-version.h
cef-headers.hpp
deps/json11/json11.cpp
deps/json11/json11.hpp
deps/base64/base64.cpp
deps/base64/base64.hpp
deps/wide-string.cpp
Expand All @@ -46,7 +45,7 @@ target_sources(
target_include_directories(obs-browser PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/deps")

target_compile_features(obs-browser PRIVATE cxx_std_17)
target_link_libraries(obs-browser PRIVATE OBS::libobs OBS::frontend-api)
target_link_libraries(obs-browser PRIVATE OBS::libobs OBS::frontend-api nlohmann_json::nlohmann_json)

if(OS_WINDOWS)
include(cmake/os-windows.cmake)
Expand Down
13 changes: 5 additions & 8 deletions browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "browser-app.hpp"
#include "browser-version.h"
#include <json11/json11.hpp>
#include <nlohmann/json.hpp>

#ifdef _WIN32
#include <windows.h>
Expand All @@ -38,8 +38,6 @@
}
#endif

using namespace json11;

CefRefPtr<CefRenderProcessHandler> BrowserApp::GetRenderProcessHandler()
{
return this;
Expand Down Expand Up @@ -279,14 +277,13 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,

CefRefPtr<CefV8Value> globalObj = context->GetGlobal();

std::string err;
auto payloadJson =
Json::parse(args->GetString(1).ToString(), err);
nlohmann::json payloadJson = nlohmann::json::parse(
args->GetString(1).ToString(), nullptr, false);

Json::object wrapperJson;
nlohmann::json wrapperJson;
if (args->GetSize() > 1)
wrapperJson["detail"] = payloadJson;
std::string wrapperJsonString = Json(wrapperJson).dump();
std::string wrapperJsonString = wrapperJson.dump();
std::string script;

script += "new CustomEvent('";
Expand Down
17 changes: 6 additions & 11 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "browser-client.hpp"
#include "obs-browser-source.hpp"
#include "base64/base64.hpp"
#include "json11/json11.hpp"
#include <nlohmann/json.hpp>
#include <obs-frontend-api.h>
#include <obs.hpp>
#include <util/platform.h>
Expand All @@ -30,8 +30,6 @@
#include <IOSurface/IOSurface.h>
#endif

using namespace json11;

inline bool BrowserClient::valid() const
{
return !!bs && !bs->destroying;
Expand Down Expand Up @@ -119,7 +117,7 @@ bool BrowserClient::OnProcessMessageReceived(
{
const std::string &name = message->GetName();
CefRefPtr<CefListValue> input_args = message->GetArgumentList();
Json json;
nlohmann::json json;

if (!valid()) {
return false;
Expand Down Expand Up @@ -225,12 +223,10 @@ bool BrowserClient::OnProcessMessageReceived(
if (!name)
return false;

json = Json::object{
{"name", name},
{"width",
(int)obs_source_get_width(current_scene)},
json = {{"name", name},
{"width", obs_source_get_width(current_scene)},
{"height",
(int)obs_source_get_height(current_scene)}};
obs_source_get_height(current_scene)}};
} else if (name == "getTransitions") {
struct obs_frontend_source_list list = {};
obs_frontend_get_transitions(&list);
Expand All @@ -250,8 +246,7 @@ bool BrowserClient::OnProcessMessageReceived(
[[fallthrough]];
case ControlLevel::ReadObs:
if (name == "getStatus") {
json = Json::object{
{"recording", obs_frontend_recording_active()},
json = {{"recording", obs_frontend_recording_active()},
{"streaming", obs_frontend_streaming_active()},
{"recordingPaused",
obs_frontend_recording_paused()},
Expand Down
14 changes: 7 additions & 7 deletions cmake/legacy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ if(NOT TARGET CEF::Wrapper)
FATAL_ERROR "OBS: - Unable to find CEF Libraries - set CEF_ROOT_DIR or configure with ENABLE_BROWSER=OFF")
endif()

find_package(nlohmann_json REQUIRED)

add_library(obs-browser MODULE)
add_library(OBS::browser ALIAS obs-browser)

Expand Down Expand Up @@ -63,8 +65,6 @@ target_sources(
browser-scheme.hpp
browser-version.h
cef-headers.hpp
deps/json11/json11.cpp
deps/json11/json11.hpp
deps/base64/base64.cpp
deps/base64/base64.hpp
deps/wide-string.cpp
Expand All @@ -76,7 +76,7 @@ target_sources(

target_include_directories(obs-browser PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps ${CMAKE_BINARY_DIR}/config)

target_link_libraries(obs-browser PRIVATE OBS::libobs OBS::frontend-api)
target_link_libraries(obs-browser PRIVATE OBS::libobs OBS::frontend-api nlohmann_json::nlohmann_json)

target_compile_features(obs-browser PRIVATE cxx_std_17)

Expand All @@ -96,9 +96,9 @@ if(NOT OS_MACOS OR ENABLE_BROWSER_LEGACY)
add_executable(obs-browser-page)

target_sources(obs-browser-page PRIVATE cef-headers.hpp obs-browser-page/obs-browser-page-main.cpp browser-app.cpp
browser-app.hpp deps/json11/json11.cpp deps/json11/json11.hpp)
browser-app.hpp)

target_link_libraries(obs-browser-page PRIVATE CEF::Library)
target_link_libraries(obs-browser-page PRIVATE CEF::Library nlohmann_json::nlohmann_json)

target_include_directories(obs-browser-page PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/deps
${CMAKE_CURRENT_SOURCE_DIR}/obs-browser-page)
Expand Down Expand Up @@ -194,9 +194,9 @@ elseif(OS_MACOS)
add_executable(${_HELPER_TARGET} MACOSX_BUNDLE)
add_executable(OBS::browser-helper${_TARGET_SUFFIX} ALIAS ${_HELPER_TARGET})
target_sources(${_HELPER_TARGET} PRIVATE browser-app.cpp browser-app.hpp obs-browser-page/obs-browser-page-main.cpp
cef-headers.hpp deps/json11/json11.cpp deps/json11/json11.hpp)
cef-headers.hpp)

target_link_libraries(${_HELPER_TARGET} PRIVATE CEF::Wrapper)
target_link_libraries(${_HELPER_TARGET} PRIVATE CEF::Wrapper nlohmann_json::nlohmann_json)

target_include_directories(${_HELPER_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/deps
${CMAKE_CURRENT_SOURCE_DIR}/obs-browser-page)
Expand Down
3 changes: 0 additions & 3 deletions deps/json11/.clang-format

This file was deleted.

19 changes: 0 additions & 19 deletions deps/json11/LICENSE.txt

This file was deleted.

Loading

0 comments on commit 0f1ff75

Please sign in to comment.