|
|
@@ -6,7 +6,7 @@ class SseSource {
|
|
|
private readonly onMessage: ((eventData: Array<any>) => void)
|
|
|
private readonly onClose: (() => void)
|
|
|
private readonly withCredentials: boolean
|
|
|
- private eventSource: EventSource | null = null
|
|
|
+ protected eventSource: EventSource | null = null
|
|
|
|
|
|
constructor(
|
|
|
mercureHubBaseUrl: string,
|
|
|
@@ -24,8 +24,18 @@ class SseSource {
|
|
|
this.withCredentials = withCredentials
|
|
|
}
|
|
|
|
|
|
- isConnected () {
|
|
|
- return this.eventSource !== null && this.eventSource.readyState === EventSource.OPEN
|
|
|
+ protected createEventSource(url: string, withCredentials: boolean): EventSourcePolyfill {
|
|
|
+ return new EventSourcePolyfill(
|
|
|
+ url,
|
|
|
+ {
|
|
|
+ withCredentials: withCredentials,
|
|
|
+ heartbeatTimeout: 45 * 1000 // in ms, timeout can not be disabled yet, so I set it very large instead
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public isConnected () {
|
|
|
+ return this.eventSource !== null && this.eventSource.readyState === EventSourcePolyfill.OPEN
|
|
|
}
|
|
|
|
|
|
public subscribe () {
|
|
|
@@ -36,13 +46,7 @@ class SseSource {
|
|
|
throw new Error('SSE - Cannot subscribe on server side')
|
|
|
}
|
|
|
|
|
|
- this.eventSource = new EventSourcePolyfill(
|
|
|
- this.url.toString(),
|
|
|
- {
|
|
|
- withCredentials: this.withCredentials,
|
|
|
- heartbeatTimeout: 45 * 1000 // in ms, timeout can not be disabled yet, so I set it very large instead
|
|
|
- }
|
|
|
- );
|
|
|
+ this.eventSource = this.createEventSource(this.url.toString(), this.withCredentials)
|
|
|
|
|
|
this.eventSource.onerror = (event) => {
|
|
|
console.error('SSE - An error happened')
|