Skip to content

Commit aa1418a

Browse files
authored
Websocket support (#124)
* Refactor WebSocket client code and add WebSocket support to request handler * Refactor WebSocket client code and remove unnecessary forward declarations * Refactor WebSocket client code and add WebSocket support to request handler * Refactor UI layout and adjust tab stop distance
1 parent 6c296d9 commit aa1418a

File tree

7 files changed

+514
-231
lines changed

7 files changed

+514
-231
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE inja)
6868
include(cmake/BuildLexbor.cmake)
6969
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE liblexbor_internal)
7070

71+
include(cmake/FetchWebsocketpp.cmake)
72+
7173
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE vendor/nlohmann-json)
7274

7375
target_sources(
@@ -76,6 +78,7 @@ target_sources(
7678
src/obs-source-util.cpp
7779
src/mapping-data.cpp
7880
src/request-data.cpp
81+
src/websocket-client.cpp
7982
src/ui/CustomTextDocument.cpp
8083
src/ui/RequestBuilder.cpp
8184
src/ui/text-render-helper.cpp

cmake/FetchWebsocketpp.cmake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
if(WIN32 OR APPLE)
2+
# Windows and macOS are supported by the prebuilt dependencies
3+
4+
if(NOT buildspec)
5+
file(READ "${CMAKE_SOURCE_DIR}/buildspec.json" buildspec)
6+
endif()
7+
8+
string(
9+
JSON
10+
version
11+
GET
12+
${buildspec}
13+
dependencies
14+
prebuilt
15+
version)
16+
17+
if(MSVC)
18+
set(arch ${CMAKE_GENERATOR_PLATFORM})
19+
elseif(APPLE)
20+
set(arch universal)
21+
endif()
22+
23+
set(deps_root "${CMAKE_SOURCE_DIR}/.deps/obs-deps-${version}-${arch}")
24+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE "${deps_root}/include")
25+
else()
26+
# Linux requires fetching the dependencies
27+
include(FetchContent)
28+
29+
FetchContent_Declare(
30+
websocketpp
31+
URL https://github.com/zaphoyd/websocketpp/archive/refs/tags/0.8.2.tar.gz
32+
URL_HASH SHA256=6ce889d85ecdc2d8fa07408d6787e7352510750daa66b5ad44aacb47bea76755)
33+
34+
# Only download the content, don't configure or build it
35+
FetchContent_GetProperties(websocketpp)
36+
37+
if(NOT websocketpp_POPULATED)
38+
FetchContent_Populate(websocketpp)
39+
endif()
40+
41+
# Add WebSocket++ as an interface library
42+
add_library(websocketpp INTERFACE)
43+
target_include_directories(websocketpp INTERFACE ${websocketpp_SOURCE_DIR})
44+
45+
# Fetch ASIO
46+
FetchContent_Declare(
47+
asio
48+
URL https://github.com/chriskohlhoff/asio/archive/asio-1-28-0.tar.gz
49+
URL_HASH SHA256=226438b0798099ad2a202563a83571ce06dd13b570d8fded4840dbc1f97fa328)
50+
51+
FetchContent_MakeAvailable(websocketpp asio)
52+
53+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE websocketpp)
54+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${asio_SOURCE_DIR}/asio/include/)
55+
endif()
56+
57+
message(STATUS "WebSocket++ and ASIO have been added to the project")

0 commit comments

Comments
 (0)