sse.ts 454 B

123456789101112131415
  1. import {Plugin} from "@nuxt/types";
  2. import SseSource from "~/services/sse/sseSource";
  3. /**
  4. * Setup SSE EventSource, allowing the app to listen for Mercure updates
  5. * @param ctx
  6. */
  7. const ssePlugin: Plugin = ({ $config, store }) => {
  8. const sseSource = new SseSource($config.baseUrl_mercure, store.state.profile.access.id)
  9. sseSource.subscribe()
  10. window.addEventListener('beforeunload', () => { sseSource.unsubscribe() })
  11. }
  12. export default ssePlugin