Skip to content

Commit

Permalink
Add example event-watcher script
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ramsay <[email protected]>
  • Loading branch information
lack authored and any1 committed Nov 12, 2022
1 parent d823910 commit 3ee620b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions examples/event-watcher
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/ctl-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ctl_client {

char read_buffer[512];
size_t read_len;

bool wait_for_events;

int fd;
Expand Down
19 changes: 19 additions & 0 deletions wayvncctl.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3ee620b

Please sign in to comment.