diff options
| author | Kit La Touche <kit@transneptune.net> | 2024-09-30 23:14:36 -0400 |
|---|---|---|
| committer | Kit La Touche <kit@transneptune.net> | 2024-09-30 23:14:36 -0400 |
| commit | 01d995c731c296292cd3f1f9a4702eb96a0bf628 (patch) | |
| tree | a0bbe131a22afcf1b727a1769cfffe38cada0558 /hi-ui/src/apiServer.js | |
| parent | c0fead957c6433be1ddfbbe8a55276a4aa8fc4df (diff) | |
Absorb and display events
At least message-type ones, and at least without styling or memory-limit
concerns.
Diffstat (limited to 'hi-ui/src/apiServer.js')
| -rw-r--r-- | hi-ui/src/apiServer.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/hi-ui/src/apiServer.js b/hi-ui/src/apiServer.js index 92f4dcc..7365a36 100644 --- a/hi-ui/src/apiServer.js +++ b/hi-ui/src/apiServer.js @@ -1,4 +1,5 @@ import axios from 'axios'; +import { events } from './store'; export const apiServer = axios.create({ baseURL: '/api/', @@ -27,3 +28,18 @@ export async function listChannels() { export async function createChannel(name) { return apiServer.post('/channels', { name }); } + +export async function postToChannel(channelId, message) { + return apiServer.post(`/channels/${channelId}`, { message }); +} + +export function subscribeToEvents() { + const evtSource = new EventSource("/api/events"); + // TODO: this should process all incoming events and store them. + // TODO: eventually we'll need to handle expiring old info, so as not to use + // infinite browser memory. + evtSource.onmessage = (evt) => { + const data = JSON.parse(evt.data); + events.update((value) => [...value, data]); + } +} |
