Add example event-watcher script

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/183/head
Jim Ramsay 2022-11-11 01:43:02 -05:00 committed by Andri Yngvason
parent d8239109e5
commit 3ee620b8b6
3 changed files with 36 additions and 1 deletions

View File

@ -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)

View File

@ -47,7 +47,7 @@ struct ctl_client {
char read_buffer[512]; char read_buffer[512];
size_t read_len; size_t read_len;
bool wait_for_events; bool wait_for_events;
int fd; int fd;

View File

@ -122,6 +122,25 @@ $ wayvncctl --json version
{"wayvnc":"v0.5.0","neatvnc":"v0.5.1","aml":"v0.2.2"} {"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 # ENVIRONMENT
The following environment variables have an effect on wayvncctl: The following environment variables have an effect on wayvncctl: