|
|
@@ -34,7 +34,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import {defineComponent, onBeforeMount, onBeforeUnmount, onMounted, onServerPrefetch, onUnmounted, Ref, ref, useContext} from "@nuxtjs/composition-api";
|
|
|
+import {defineComponent, onBeforeUnmount, onMounted, Ref, ref, useContext} from "@nuxtjs/composition-api";
|
|
|
import {HTTP_METHOD, QUERY_TYPE} from "~/types/enums";
|
|
|
import DataPersister from "~/services/data/dataPersister";
|
|
|
import {DataPersisterArgs} from "~/types/interfaces";
|
|
|
@@ -47,10 +47,10 @@ export default defineComponent({
|
|
|
|
|
|
let pending: Ref<boolean> = ref(false)
|
|
|
let fileUrl: Ref<string | null> = ref(null)
|
|
|
- let eventSource: Ref<EventSource | null> = ref(null)
|
|
|
+ let eventSource: EventSource | null = null
|
|
|
|
|
|
const sseOpened = () => {
|
|
|
- return eventSource.value !== null && eventSource.value?.readyState === EventSource.OPEN
|
|
|
+ return eventSource !== null && eventSource.readyState === EventSource.OPEN
|
|
|
}
|
|
|
|
|
|
const submit = async () => {
|
|
|
@@ -68,11 +68,11 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
const unsubscribe = async () => {
|
|
|
- if (eventSource.value === null || eventSource.value.readyState === EventSource.CLOSED) {
|
|
|
+ if (eventSource === null || eventSource.readyState === EventSource.CLOSED) {
|
|
|
return
|
|
|
}
|
|
|
console.log('SSE - Close subscription')
|
|
|
- eventSource.value.close()
|
|
|
+ eventSource.close()
|
|
|
}
|
|
|
|
|
|
const subscribe = async () => {
|
|
|
@@ -88,32 +88,36 @@ export default defineComponent({
|
|
|
const url = new URL($config.baseUrl_mercure)
|
|
|
url.searchParams.append('topic', "access/" + store.state.profile.access.id)
|
|
|
|
|
|
- eventSource.value = new EventSourcePolyfill(
|
|
|
+ eventSource = new EventSourcePolyfill(
|
|
|
url.toString(),
|
|
|
- { withCredentials: true, heartbeatTimeout: 3600 * 1000 }
|
|
|
+ { withCredentials: true }
|
|
|
);
|
|
|
|
|
|
- eventSource.value.onerror = (event) => {
|
|
|
+ eventSource.onerror = (event) => {
|
|
|
console.error('SSE - An error happened : ' + JSON.stringify(event))
|
|
|
- eventSource.value?.close()
|
|
|
+ eventSource?.close()
|
|
|
}
|
|
|
- eventSource.value.onopen = () => {
|
|
|
+ eventSource.onopen = () => {
|
|
|
console.log('SSE - Listening for events...')
|
|
|
}
|
|
|
- eventSource.value.onmessage = event => {
|
|
|
+ eventSource.onmessage = event => {
|
|
|
const data = JSON.parse(event.data)
|
|
|
fileUrl.value = data.url
|
|
|
pending.value = false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- onMounted(() => {
|
|
|
- subscribe()
|
|
|
- })
|
|
|
-
|
|
|
- onBeforeUnmount(() => {
|
|
|
- unsubscribe()
|
|
|
- })
|
|
|
+ // onMounted(() => {
|
|
|
+ // subscribe()
|
|
|
+ // })
|
|
|
+ //
|
|
|
+ // onBeforeUnmount(() => {
|
|
|
+ // unsubscribe()
|
|
|
+ // })
|
|
|
+ //
|
|
|
+ // if (process.browser) {
|
|
|
+ // window.addEventListener('beforeunload', unsubscribe)
|
|
|
+ // }
|
|
|
|
|
|
return {
|
|
|
submit,
|