diff --git a/examples/event-watcher b/examples/event-watcher new file mode 100755 index 0000000..a31b06b --- /dev/null +++ b/examples/event-watcher @@ -0,0 +1,16 @@ +#!/bin/bash + +WAYVNCCTL=${WAYVNCCTL:-wayvncctl} + +connection_count_now() { + echo "Total clients: $count" +} + +while IFS= read -r EVT; do + case "$(jq -r '.method' <<<"$EVT")" in + client-*onnected) + count=$(jq -r '.params.connection_count' <<<"$EVT") + connection_count_now "$count" + ;; + esac +done < <("$WAYVNCCTL" --json event-receive) diff --git a/src/ctl-client.c b/src/ctl-client.c index b6e01e9..20dde6c 100644 --- a/src/ctl-client.c +++ b/src/ctl-client.c @@ -47,7 +47,7 @@ struct ctl_client { char read_buffer[512]; size_t read_len; - + bool wait_for_events; int fd; diff --git a/wayvncctl.scd b/wayvncctl.scd index f7c4458..4501d74 100644 --- a/wayvncctl.scd +++ b/wayvncctl.scd @@ -122,6 +122,25 @@ $ wayvncctl --json version {"wayvnc":"v0.5.0","neatvnc":"v0.5.1","aml":"v0.2.2"} ``` +A script that takes an action for each client connect and disconnect event: + +``` +#!/bin/bash + +connection_count_now() { + echo "Total clients: $count" +} + +while IFS= read -r EVT; do + case "$(jq -r '.method' <<<"$EVT")" in + client-*onnected) + count=$(jq -r '.params.connection_count' <<<"$EVT") + connection_count_now "$count" + ;; + esac +done < <(wayvncctl --json event-receive) +``` + # ENVIRONMENT The following environment variables have an effect on wayvncctl: