38 lines
1.3 KiB
Markdown
38 lines
1.3 KiB
Markdown
|
# websocket_actor
|
||
|
|
||
|
A [syndicated actor](https://syndicate-lang.org/) for communicating JSON to websocket servers.
|
||
|
|
||
|
The actor observes `{dataspace: #!any url: string }` assertions and connects to a websocket endpoint. During the lifetime of the connection a `<connected $URL>` assertion is made. Messages recieved from the server are sent to the dataspace wrapped in `<recv …>` records and messages observed as `<send …>` are sent to the server.
|
||
|
|
||
|
Unfortunately this utility is only as useful and reasonable as the websocket server it is connected to.
|
||
|
|
||
|
## Example:
|
||
|
|
||
|
### Syndicate server configuration:
|
||
|
```
|
||
|
<require-service <daemon websocket_actor>>
|
||
|
<daemon websocket_actor {
|
||
|
argv: ["/bin/websocket_actor"]
|
||
|
protocol: application/syndicate
|
||
|
env: { BUILD_SUM: $sum }
|
||
|
}>
|
||
|
|
||
|
let ?exported-dataspace = dataspace
|
||
|
<service-object <daemon websocket_actor> ?cap> [
|
||
|
$cap { dataspace: $exported-dataspace url: "ws://127.0.0.1:5225/" }
|
||
|
]
|
||
|
|
||
|
<bind <ref { oid: "syndicate" key: #x"" }> $exported-dataspace #f>
|
||
|
```
|
||
|
|
||
|
### Shell
|
||
|
```
|
||
|
# Use the "syndump" utility to log '<recv …>' records from the background.
|
||
|
syndump '<recv ?>' &
|
||
|
|
||
|
# Use the "msg" utilite to send '<send …>' records.
|
||
|
# The message command wraps its arguments in a record with a label set to argv[0].
|
||
|
cp $(which msg) send
|
||
|
send '{ type: "command" body: { type: "body" text: "fuck off webdevs"} }'
|
||
|
```
|