From 3ee620b8b668b3299f8dc9db8fc72c926d81dc14 Mon Sep 17 00:00:00 2001 From: Jim Ramsay Date: Fri, 11 Nov 2022 01:43:02 -0500 Subject: [PATCH] Add example event-watcher script Signed-off-by: Jim Ramsay --- examples/event-watcher | 16 ++++++++++++++++ src/ctl-client.c | 2 +- wayvncctl.scd | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 examples/event-watcher 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: