|
|
@@ -30,36 +30,39 @@
|
|
|
</v-btn>
|
|
|
</div>
|
|
|
</v-form>
|
|
|
+ <!-- <<< for debugging purposes, TODO: remove before deploying -->
|
|
|
+ <ul>
|
|
|
+ <li v-for="event in events">{{ event }}</li>
|
|
|
+ </ul>
|
|
|
+ <!-- >>> for debugging purposes -->
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import {defineComponent, onBeforeUnmount, onMounted, Ref, ref, useContext} from "@nuxtjs/composition-api";
|
|
|
+import {defineComponent, 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";
|
|
|
-import { EventSourcePolyfill } from "event-source-polyfill";
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'OrganizationCmfLicence',
|
|
|
setup() {
|
|
|
- const { $config, store } = useContext()
|
|
|
+ const { store } = useContext()
|
|
|
|
|
|
let pending: Ref<boolean> = ref(false)
|
|
|
let fileUrl: Ref<string | null> = ref(null)
|
|
|
- let eventSource: EventSource | null = null
|
|
|
|
|
|
- const sseOpened = () => {
|
|
|
- return eventSource !== null && eventSource.readyState === EventSource.OPEN
|
|
|
- }
|
|
|
+ const async = () => { return store.state.sse.connected }
|
|
|
+
|
|
|
+ let events: Ref<Array<Array<any>>> = ref(store.state.sse.events)
|
|
|
|
|
|
const submit = async () => {
|
|
|
const response = await DataPersister.request(
|
|
|
'/api/export/cmf-licence/organization',
|
|
|
HTTP_METHOD.POST,
|
|
|
- { type: QUERY_TYPE.DEFAULT, data: { format: 'pdf', async: sseOpened() }, withCredentials: true } as DataPersisterArgs
|
|
|
+ { type: QUERY_TYPE.DEFAULT, data: { format: 'pdf', async: true }, withCredentials: true } as DataPersisterArgs
|
|
|
)
|
|
|
- if (sseOpened()) {
|
|
|
+ if (async()) {
|
|
|
pending.value = true
|
|
|
} else {
|
|
|
console.warn('File downloaded synchronously')
|
|
|
@@ -67,63 +70,21 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const unsubscribe = async () => {
|
|
|
- if (eventSource === null || eventSource.readyState === EventSource.CLOSED) {
|
|
|
- return
|
|
|
- }
|
|
|
- console.log('SSE - Close subscription')
|
|
|
- eventSource.close()
|
|
|
- }
|
|
|
-
|
|
|
- const subscribe = async () => {
|
|
|
- if (sseOpened()) {
|
|
|
- console.error('SSE - Already subscribed to the event source')
|
|
|
- return
|
|
|
- }
|
|
|
- if (process.server) {
|
|
|
- console.error('SSE - Cannot subscribe on server side')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- const url = new URL($config.baseUrl_mercure)
|
|
|
- url.searchParams.append('topic', "access/" + store.state.profile.access.id)
|
|
|
-
|
|
|
- eventSource = new EventSourcePolyfill(
|
|
|
- url.toString(),
|
|
|
- { withCredentials: true }
|
|
|
- );
|
|
|
-
|
|
|
- eventSource.onerror = (event) => {
|
|
|
- console.error('SSE - An error happened : ' + JSON.stringify(event))
|
|
|
- eventSource?.close()
|
|
|
- }
|
|
|
- eventSource.onopen = () => {
|
|
|
- console.log('SSE - Listening for events...')
|
|
|
- }
|
|
|
- eventSource.onmessage = event => {
|
|
|
- const data = JSON.parse(event.data)
|
|
|
- fileUrl.value = data.url
|
|
|
- pending.value = false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // onMounted(() => {
|
|
|
- // subscribe()
|
|
|
- // })
|
|
|
- //
|
|
|
- // onBeforeUnmount(() => {
|
|
|
- // unsubscribe()
|
|
|
- // })
|
|
|
- //
|
|
|
- // if (process.browser) {
|
|
|
- // window.addEventListener('beforeunload', unsubscribe)
|
|
|
+ // const onMessage = (eventData) => {
|
|
|
+ // fileUrl.value = eventData.url
|
|
|
+ // pending.value = false
|
|
|
// }
|
|
|
|
|
|
return {
|
|
|
submit,
|
|
|
pending,
|
|
|
- fileUrl
|
|
|
+ fileUrl,
|
|
|
+ events
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+function useSse(): { sseConnected: any; } {
|
|
|
+ throw new Error("Function not implemented.");
|
|
|
+}
|
|
|
</script>
|