mirror of
https://github.com/ilyakooo0/airlock.git
synced 2024-09-11 10:35:26 +03:00
* Got basic subscriptions working * Refactored urbit requests * Added elm.json back in * Added int64 * Switched to bigint * Added pokes * Retry critical failed requests * Cleaned up * Expose proper modules * Refactored subscriptions * Minor refactors
28 lines
756 B
JavaScript
28 lines
756 B
JavaScript
import { fetchEventSource } from "/fetch-event-source.js"
|
|
|
|
const uid = `${Math.floor(Date.now() / 1000)}-${Math.random()}`;
|
|
|
|
let app = Elm.Main.init({ node: document.getElementById("elm"), flags: { uid } });
|
|
|
|
app.ports.createEventSource.subscribe((url) => {
|
|
fetchEventSource(url, {
|
|
headers: {
|
|
Accept: 'application/x-urb-jam',
|
|
"x-channel-format": 'application/x-urb-jam',
|
|
"content-type": 'application/x-urb-jam'
|
|
},
|
|
credentials: 'include',
|
|
responseTimeout: 25000,
|
|
openWhenHidden: true,
|
|
onmessage(ev) {
|
|
console.log(ev)
|
|
app.ports.onEventSourceMessage.send({ message: ev.data });
|
|
},
|
|
onerror(err) {
|
|
console.log(err)
|
|
app.ports.onEventSourceMessage.send({ error: err });
|
|
}
|
|
});
|
|
|
|
});
|