Skip to content
Merged
2 changes: 2 additions & 0 deletions cmake/compile_definitions/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ set(PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/windows/misc.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/misc.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/input.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/session_input.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/session_input.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_base.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_vram.cpp"
Expand Down
3 changes: 3 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ curl -u user:pass -H "X-CSRF-Token: your_token_here" \
## POST /api/clients/unpair
@copydoc confighttp::unpair()

## GET /api/streams
@copydoc confighttp::getActiveStreams()

## POST /api/clients/unpair-all
@copydoc confighttp::unpairAll()

Expand Down
36 changes: 36 additions & 0 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,41 @@ namespace confighttp {
send_response(response, output_tree);
}

/**
* @brief Get how many clients are streaming right now.
* @param response The HTTP response object.
* @param request The HTTP request object.
*
* The response counts Moonlight sessions and Moonlight WebRTC TV sessions separately:
* @code{.json}
* {
* "moonlight": 1,
* "webrtc": 0,
* "total": 1,
* "status": true
* }
* @endcode
*
* @api_examples{/api/streams|:| GET|:| null}
*/
void getActiveStreams(const resp_https_t &response, const req_https_t &request) {
if (!authenticate(response, request)) {
return;
}

print_req(request);

const int moonlight = rtsp_stream::session_count();
const int webrtc = webrtc_stream::session_count();

nlohmann::json output_tree;
output_tree["moonlight"] = moonlight;
output_tree["webrtc"] = webrtc;
output_tree["total"] = moonlight + webrtc;
output_tree["status"] = true;
send_response(response, output_tree);
}

/**
* @brief Enable or disable a client.
* @param response The HTTP response object.
Expand Down Expand Up @@ -2525,6 +2560,7 @@ namespace confighttp {
server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp;
server.resource["^/api/apps/close$"]["POST"] = closeApp;
server.resource["^/api/clients/list$"]["GET"] = getClients;
server.resource["^/api/streams$"]["GET"] = getActiveStreams;
server.resource["^/api/clients/unpair$"]["POST"] = unpair;
server.resource["^/api/clients/unpair-all$"]["POST"] = unpairAll;
server.resource["^/api/clients/update$"]["POST"] = updateClient;
Expand Down
8 changes: 8 additions & 0 deletions src/confighttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ namespace confighttp {
*/
void getPermissions(const resp_https_t &response, const req_https_t &request);

/**
* @brief Report how many clients are streaming right now.
*
* @param response HTTPS response receiving the stream counts JSON.
* @param request Authenticated HTTPS request.
*/
void getActiveStreams(const resp_https_t &response, const req_https_t &request);

/**
* @brief Initiate a native permission request from the Web UI.
*
Expand Down
52 changes: 52 additions & 0 deletions src/platform/virtualhid_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "src/logging.h"
#include "virtualhid_input.h"

#ifdef _WIN32
#include "windows/session_input.h"
#endif

using namespace std::literals;

namespace platf::virtualhid {
Expand Down Expand Up @@ -1152,34 +1156,82 @@ namespace platf {
#endif

void move_mouse(input_t &input, int deltaX, int deltaY) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::move_mouse(deltaX, deltaY);
return;
}
#endif
virtualhid::move_mouse(virtualhid::get_input_context(input), deltaX, deltaY);
}

void move_mouse(input_t &input, const touch_port_t &touch_port, int deltaX, int deltaY) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::move_mouse(deltaX, deltaY);
return;
}
#endif
virtualhid::move_mouse(virtualhid::get_input_context(input), touch_port, deltaX, deltaY);
}

void abs_mouse(input_t &input, const touch_port_t &touch_port, float x, float y) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::abs_mouse(touch_port, x, y);
return;
}
#endif
virtualhid::abs_mouse(virtualhid::get_input_context(input), touch_port, x, y);
}

void button_mouse(input_t &input, int button, bool release) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::button_mouse(button, release);
return;
}
#endif
virtualhid::button_mouse(virtualhid::get_input_context(input), button, release);
}

void scroll(input_t &input, int high_res_distance) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::scroll(high_res_distance);
return;
}
#endif
virtualhid::scroll(virtualhid::get_input_context(input), high_res_distance);
}

void hscroll(input_t &input, int high_res_distance) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::hscroll(high_res_distance);
return;
}
#endif
virtualhid::hscroll(virtualhid::get_input_context(input), high_res_distance);
}

void keyboard_update(input_t &input, uint16_t modcode, bool release, uint8_t flags, bool extended) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::keyboard_update(modcode, release, flags, extended);
return;
}
#endif
virtualhid::keyboard_update(virtualhid::get_input_context(input), modcode, release, flags, extended);
}

void unicode(input_t &input, const char *utf8, int size) {
#ifdef _WIN32
if (session_input::should_use()) {
session_input::unicode(utf8, size);
return;
}
#endif
virtualhid::unicode(virtualhid::get_input_context(input), utf8, size);
}

Expand Down
Loading
Loading