|
|
@@ -0,0 +1,15 @@
|
|
|
+import {Plugin} from "@nuxt/types";
|
|
|
+import SseSource from "~/services/sse/sseSource";
|
|
|
+
|
|
|
+/**
|
|
|
+ * Setup SSE EventSource, allowing the app to listen for Mercure updates
|
|
|
+ * @param ctx
|
|
|
+ */
|
|
|
+const ssePlugin: Plugin = ({ $config, store }) => {
|
|
|
+ const sseSource = new SseSource($config.baseUrl_mercure, store.state.profile.access.id)
|
|
|
+
|
|
|
+ sseSource.subscribe()
|
|
|
+ window.addEventListener('beforeunload', () => { sseSource.unsubscribe() })
|
|
|
+}
|
|
|
+
|
|
|
+export default ssePlugin
|