Browse Source

Split lib from example

main
Tony Garnock-Jones 2 months ago
parent
commit
f060740f82
  1. 9
      README.md
  2. 59
      examples/chat.sh
  3. 58
      lib/syndicate.sh

9
README.md

@ -37,11 +37,12 @@ doesn't require nightly), so you can get it with:
## Running the demo
Start the server in one terminal, in the same directory as the
`syndicate.sh` file:
Start the server in one terminal, in the same directory as this
`README.md` file:
syndicate-server -s ./sock
Then, in one or more other terminals, run `syndicate.sh`:
Then, in one or more other terminals, run `chat.sh` from the same
directory:
./syndicate.sh
./examples/chat.sh

59
examples/chat.sh

@ -0,0 +1,59 @@
#!/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>"'

58
syndicate.sh → lib/syndicate.sh

@ -106,61 +106,3 @@ ds_object() {
ds_object_map[$oid]="$2"
printf -v $1 '%s' "#![0,$oid]"
}
demo() {
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>"'
}
demo
Loading…
Cancel
Save