on master help sign in
airlock/README.md
43 lines 1.4 kB history raw
1# Airlock
3![](res/airlock.jpeg)
5## Usage
7### Demo
9[![DEMO](https://img.youtube.com/vi/tynCzifvIzE/0.jpg)](https://www.youtube.com/watch?v=tynCzifvIzE)
12## Getting started
14The easiest way of using this library is by using the [airlock template](https://github.com/ilyakooo0/airlock-template).
16### FFI
18This is for setting up this library from scratch.
20Urbit subscriptions require [server-side event (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
21Unfortunately, Elm does not provide a native implementation.
22This means that we will need to use [JS FFI (aka ports)](https://guide.elm-lang.org/interop/ports.html).
24#### Setting up the Elm side
26You would need to declare two ports for Airlock to use:
281. `port createEventSource : String -> Cmd msg`
30 This sets up the SSE channel.
312. `port onEventSourceMessage : (JD.Value -> msg) -> Sub msg`
32 This recieves the actual messages from the SSE channel.
34These two functions need to be passed to one of the functions from `Ur.Run` module.
35The functions in `Ur.Run` are the same as functions from `Browser`, but have a couple of extra urbit-specific fields.
37#### Setting up the JS side
39The SSE JS code is neatly packed into [example/fetch-event-source.js](example/fetch-event-source.js).
40All you need to do is pass them to Elm ports like in [example/script.js](example/script.js).
42You can see a full working example in [example](example).