diff --git a/ts/sse-manager.ts b/ts/SSEManager.ts similarity index 100% rename from ts/sse-manager.ts rename to ts/SSEManager.ts diff --git a/ts/main.ts b/ts/main.ts index 8532c68d..000afa9e 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -2,7 +2,7 @@ import { createApp } from "vue"; import { createPinia } from "pinia"; import App from "./App.vue"; import router from "./router"; -import { SSEManager } from "./sse-manager"; +import { SSEManager } from "./SSEManager"; //import { SetupSidebar } from "./sidebar"; import "maplibre-gl/dist/maplibre-gl.css"; @@ -22,7 +22,11 @@ window.SSEManager = SSEManager; document.addEventListener("DOMContentLoaded", () => { SSEManager.connect("/api/events"); - //SetupSidebar(); + SSEManager.subscribe("*", (e) => { + if (e.type != "heartbeat") { + console.log("SSE", e); + } + }); }); document.addEventListener("init", () => { const user = { diff --git a/ts/store/communication.ts b/ts/store/communication.ts index 3371c403..89317141 100644 --- a/ts/store/communication.ts +++ b/ts/store/communication.ts @@ -1,7 +1,8 @@ import { defineStore } from "pinia"; import { ref, computed } from "vue"; -import { useUserStore } from "./user"; import { Communication } from "../types"; +import { SSEManager } from "../SSEManager"; +import { useUserStore } from "./user"; export const useCommunicationStore = defineStore("communication", () => { // State @@ -9,6 +10,12 @@ export const useCommunicationStore = defineStore("communication", () => { const loading = ref(false); const error = ref(null); + // Subscription + SSEManager.subscribe("*", (e) => { + if (e.resource.startsWith("rmo")) { + fetchAll(); + } + }); // Actions async function fetchAll() { const userStore = useUserStore();