Initial integration of event stream.

This doesn't do much yet but log the events I'm getting until I
understand them better.
This commit is contained in:
Eli Ribble 2024-09-03 10:11:02 -07:00
parent 5a36e46da5
commit dfca32eb36
2 changed files with 17 additions and 1 deletions

View File

@ -263,6 +263,10 @@ export default class Client {
if (!this.jclient) return;
const session = this.jclient.getSession();
// Subscribe to server-pushed events
if (session.eventSourceUrl) {
this._subscribeToEventSource(session.eventSourceUrl);
}
this.state.session = {
...session,
accounts: Object.fromEntries(
@ -277,4 +281,16 @@ export default class Client {
if (!this.state.session) return;
this._triggerChange("Session");
}
_subscribeToEventSource(url: string) {
// For typechecker
if (this.jclient === null) return;
const eventSourceUrl = url
.replace("{types}", "*")
.replace("{closeafter}", "no")
.replace("{ping}", "60");
this.jclient.subscribeToEvents(eventSourceUrl, (e) => {
console.log("Got an event!", e);
});
}
}

@ -1 +1 @@
Subproject commit d33318d3e1f7e838d9e9b828f233b98f6b21d88f
Subproject commit 2ef5f5b7fa0a22a499bd32831ac24622f17e10e6