Skip to content

Commit

Permalink
reestablish sse connection on language change
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed Jul 31, 2023
1 parent 2fec745 commit b078644
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/web-pkg/src/composables/sse/useServerSentEvents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventSourceMessage, fetchEventSource } from '@microsoft/fetch-event-source'
import { ref, unref } from 'vue'
import { ref, unref, watch } from 'vue'
import { v4 as uuidV4 } from 'uuid'
import { useGettext } from 'vue3-gettext'
import { configurationManager, useAccessToken, useStore } from 'web-pkg/src'
Expand All @@ -16,6 +16,14 @@ export const useServerSentEvents = (options: ServerSentEventsOptions) => {
const accessToken = useAccessToken({ store })
const ctrl = new AbortController()
const retryCounter = ref(0)

watch(
() => language.current,
() => {
ctrl.abort()
setupServerSentEvents()
}
)
const setupServerSentEvents = () => {
if (unref(retryCounter) >= 5) {
ctrl.abort()
Expand Down

0 comments on commit b078644

Please sign in to comment.