feat: making SSE work on mobiles

This commit is contained in:
2025-05-12 20:11:58 +01:00
parent 636bd9df0e
commit 076e230a01
2 changed files with 13 additions and 25 deletions

View File

@ -144,14 +144,15 @@ func CreateEventsHandler(notifier *Notifier[Notification]) http.HandlerFunc {
w.Header().Set("Connection", "keep-alive") w.Header().Set("Connection", "keep-alive")
// w.(http.Flusher).Flush() // w.(http.Flusher).Flush()
if err := notifier.Create(userId.String()); err != nil { // if err := notifier.Create(userId.String()); err != nil {
// TODO: this could be better. // // TODO: this could be better.
// EG: The user could attempt to create many connections // // EG: The user could attempt to create many connections
// and they just get a 500, with no explanation. // // and they just get a 500, with no explanation.
w.WriteHeader(http.StatusInternalServerError) // fmt.Println(err)
// w.(http.Flusher).Flush() // w.WriteHeader(http.StatusInternalServerError)
return // // w.(http.Flusher).Flush()
} // return
// }
listener := notifier.Listeners[userId.String()] listener := notifier.Listeners[userId.String()]
@ -171,7 +172,7 @@ func CreateEventsHandler(notifier *Notifier[Notification]) http.HandlerFunc {
fmt.Printf("Sending msg %s\n", msg) fmt.Printf("Sending msg %s\n", msg)
fmt.Fprintf(w, "event: data\ndata: %s\n\n", string(msgString)) fmt.Fprintf(w, "event: data\ndata: %s\n\n", string(msgString))
// w.(http.Flusher).Flush() w.(http.Flusher).Flush()
} }
} }
} }

View File

@ -54,27 +54,14 @@ export const Notifications = (onCompleteImage: () => void) => {
return; return;
} }
console.log("SSE: ", processingImage);
const { ImageID, Status } = processingImage.output; const { ImageID, Status } = processingImage.output;
if (state.ProcessingImages[ImageID] != null) { if (Status === "complete") {
const localImageStatus = state.ProcessingImages[ImageID];
if (localImageStatus !== "in-progress" || Status !== "complete") {
console.error(
"Invalid state, an image present must always be in process",
);
return;
}
setState("ProcessingImages", ImageID, undefined); setState("ProcessingImages", ImageID, undefined);
onCompleteImage(); onCompleteImage();
} else { } else {
if (Status !== "in-progress") {
console.error(
"Invalid state, at this point a new image that isn't present should be in-progress",
);
return;
}
setState("ProcessingImages", ImageID, Status); setState("ProcessingImages", ImageID, Status);
} }
}; };