main: Add websockets
parent
b927394490
commit
014e33625c
42
src/main.c
42
src/main.c
|
@ -72,6 +72,12 @@
|
||||||
|
|
||||||
#define MAYBE_UNUSED __attribute__((unused))
|
#define MAYBE_UNUSED __attribute__((unused))
|
||||||
|
|
||||||
|
enum socket_type {
|
||||||
|
SOCKET_TYPE_TCP = 0,
|
||||||
|
SOCKET_TYPE_UNIX,
|
||||||
|
SOCKET_TYPE_WEBSOCKET,
|
||||||
|
};
|
||||||
|
|
||||||
struct wayvnc {
|
struct wayvnc {
|
||||||
bool do_exit;
|
bool do_exit;
|
||||||
|
|
||||||
|
@ -705,14 +711,27 @@ static int blank_screen(struct wayvnc* self)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port, bool is_unix)
|
int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port,
|
||||||
|
enum socket_type socket_type)
|
||||||
{
|
{
|
||||||
self->nvnc = is_unix ? nvnc_open_unix(addr) : nvnc_open(addr, port);
|
switch (socket_type) {
|
||||||
|
case SOCKET_TYPE_TCP:
|
||||||
|
self->nvnc = nvnc_open(addr, port);
|
||||||
|
break;
|
||||||
|
case SOCKET_TYPE_UNIX:
|
||||||
|
self->nvnc = nvnc_open_unix(addr);
|
||||||
|
break;
|
||||||
|
case SOCKET_TYPE_WEBSOCKET:
|
||||||
|
self->nvnc = nvnc_open_websocket(addr, port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
if (!self->nvnc) {
|
if (!self->nvnc) {
|
||||||
nvnc_log(NVNC_LOG_ERROR, "Failed to bind to address. Add -Ldebug to the argument list for more info.");
|
nvnc_log(NVNC_LOG_ERROR, "Failed to bind to address. Add -Ldebug to the argument list for more info.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (is_unix)
|
if (socket_type == SOCKET_TYPE_UNIX)
|
||||||
nvnc_log(NVNC_LOG_INFO, "Listening for connections on %s", addr);
|
nvnc_log(NVNC_LOG_INFO, "Listening for connections on %s", addr);
|
||||||
else
|
else
|
||||||
nvnc_log(NVNC_LOG_INFO, "Listening for connections on %s:%d", addr, port);
|
nvnc_log(NVNC_LOG_INFO, "Listening for connections on %s:%d", addr, port);
|
||||||
|
@ -1333,6 +1352,7 @@ int main(int argc, char* argv[])
|
||||||
const char* address = NULL;
|
const char* address = NULL;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
bool use_unix_socket = false;
|
bool use_unix_socket = false;
|
||||||
|
bool use_websocket = false;
|
||||||
|
|
||||||
const char* output_name = NULL;
|
const char* output_name = NULL;
|
||||||
const char* seat_name = NULL;
|
const char* seat_name = NULL;
|
||||||
|
@ -1385,6 +1405,8 @@ int main(int argc, char* argv[])
|
||||||
"Show version info." },
|
"Show version info." },
|
||||||
{ 'v', "verbose", NULL,
|
{ 'v', "verbose", NULL,
|
||||||
"Be more verbose. Same as setting --log-level=info" },
|
"Be more verbose. Same as setting --log-level=info" },
|
||||||
|
{ 'w', "websocket", NULL,
|
||||||
|
"Create a websocket." },
|
||||||
{ 'L', "log-level", "<level>",
|
{ 'L', "log-level", "<level>",
|
||||||
"Set log level. The levels are: error, warning, info, debug trace and quiet.",
|
"Set log level. The levels are: error, warning, info, debug trace and quiet.",
|
||||||
.default_ = "warning" },
|
.default_ = "warning" },
|
||||||
|
@ -1416,6 +1438,7 @@ int main(int argc, char* argv[])
|
||||||
overlay_cursor = !!option_parser_get_value(&option_parser, "render-cursor");
|
overlay_cursor = !!option_parser_get_value(&option_parser, "render-cursor");
|
||||||
show_performance = !!option_parser_get_value(&option_parser, "performance");
|
show_performance = !!option_parser_get_value(&option_parser, "performance");
|
||||||
use_unix_socket = !!option_parser_get_value(&option_parser, "unix-socket");
|
use_unix_socket = !!option_parser_get_value(&option_parser, "unix-socket");
|
||||||
|
use_websocket = !!option_parser_get_value(&option_parser, "websocket");
|
||||||
disable_input = !!option_parser_get_value(&option_parser, "disable-input");
|
disable_input = !!option_parser_get_value(&option_parser, "disable-input");
|
||||||
log_level = option_parser_get_value(&option_parser, "verbose")
|
log_level = option_parser_get_value(&option_parser, "verbose")
|
||||||
? NVNC_LOG_INFO : NVNC_LOG_WARNING;
|
? NVNC_LOG_INFO : NVNC_LOG_WARNING;
|
||||||
|
@ -1452,6 +1475,11 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (use_unix_socket && use_websocket) {
|
||||||
|
nvnc_log(NVNC_LOG_ERROR, "websocket and unix-socket are conflicting options");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
int cfg_rc = cfg_load(&self.cfg, cfg_file);
|
int cfg_rc = cfg_load(&self.cfg, cfg_file);
|
||||||
if (cfg_rc != 0 && (cfg_file || errno != ENOENT)) {
|
if (cfg_rc != 0 && (cfg_file || errno != ENOENT)) {
|
||||||
|
@ -1537,7 +1565,13 @@ int main(int argc, char* argv[])
|
||||||
if (init_main_loop(&self) < 0)
|
if (init_main_loop(&self) < 0)
|
||||||
goto main_loop_failure;
|
goto main_loop_failure;
|
||||||
|
|
||||||
if (init_nvnc(&self, address, port, use_unix_socket) < 0)
|
enum socket_type socket_type = SOCKET_TYPE_TCP;
|
||||||
|
if (use_unix_socket)
|
||||||
|
socket_type = SOCKET_TYPE_UNIX;
|
||||||
|
else if (use_websocket)
|
||||||
|
socket_type = SOCKET_TYPE_WEBSOCKET;
|
||||||
|
|
||||||
|
if (init_nvnc(&self, address, port, socket_type) < 0)
|
||||||
goto nvnc_failure;
|
goto nvnc_failure;
|
||||||
|
|
||||||
if (self.screencopy.manager)
|
if (self.screencopy.manager)
|
||||||
|
|
Loading…
Reference in New Issue