Access remote actors, publish services, subscribe to messages and state updates etc., via the Syndicate network protocol from bash (and perhaps other shells).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

#!/bin/bash
set -euo pipefail
. $(dirname "$0")/../lib/syndicate.sh
demo_ds_resolved() {
local oid="$(ds_project "$ds_event" '^ assert . 0 .embedded . 1')"
if [ -n "$oid" ]
then
ds_ref="#![1 $oid]"
echo "Dataspace: $ds_ref"
username="user$$"
declare -A demo_user_presence
demo_presence() {
case $(ds_project "$ds_event" .^) in
assert)
local h="$(ds_project "$ds_event" '. 1')"
local who="$(ds_project "$ds_event" '. 0 . 0')"
demo_user_presence[$h]="$who"
echo "JOIN: $who"
;;
retract)
local h="$(ds_project "$ds_event" '. 0')"
local who="${demo_user_presence[$h]}"
echo "PART: $who"
unset 'demo_user_presence[$h]'
;;
esac
}
ds_object presence demo_presence
ds_assert "$ds_ref" "<Observe <compound <rec Present 1> {0: <bind <_>>}> $presence>"
ds_assert "$ds_ref" "<Present \"$username\">"
demo_utterance() {
ds_project "$ds_event" '^ message . 0'
}
ds_object utterance demo_utterance
ds_assert "$ds_ref" "<Observe <compound <rec Says 2> {0: <bind <_>> 1: <bind <_>>}> $utterance>"
ds_flush
ds_mainloop </dev/null &
mainloop_pid=$!
while read line
do
ds_message "$ds_ref" "<Says \"$username\" \"$line\">"
ds_flush
done </dev/tty
kill $mainloop_pid
exit 0
fi
}
ds_object bootk demo_ds_resolved
ds_connect \
'<unix "./sock">' \
'ds_assert "#![1 0]" "<resolve <ref \"syndicate\" [] #x\"a6480df5306611ddd0d3882b546e1977\"> $bootk>"'