diff --git a/CHANGELOG.md b/CHANGELOG.md index b5b6e83c67..cc4dcd3fac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update resteasy to version 4.5.2.Final +- Use browser build in EventSource for apiClient subscriptions + +### Removed +- EventSource Polyfill ## 2.0.0-rc5 - 2020-03-12 ### Added diff --git a/scm-ui/ui-components/package.json b/scm-ui/ui-components/package.json index 3864805706..e60bbfdea3 100644 --- a/scm-ui/ui-components/package.json +++ b/scm-ui/ui-components/package.json @@ -49,7 +49,6 @@ "@scm-manager/ui-types": "^2.0.0-SNAPSHOT", "classnames": "^2.2.6", "date-fns": "^2.4.1", - "event-source-polyfill": "^1.0.9", "gitdiff-parser": "^0.1.2", "lowlight": "^1.13.0", "query-string": "5", diff --git a/scm-ui/ui-components/src/apiclient.ts b/scm-ui/ui-components/src/apiclient.ts index c8990b000c..f7e32f46ef 100644 --- a/scm-ui/ui-components/src/apiclient.ts +++ b/scm-ui/ui-components/src/apiclient.ts @@ -1,6 +1,4 @@ import { contextPath } from "./urls"; -// @ts-ignore we have not types for event-source-polyfill -import { EventSourcePolyfill } from "event-source-polyfill"; import { createBackendError, ForbiddenError, isBackendError, UnauthorizedError, BackendErrorContent } from "./errors"; type SubscriptionEvent = { @@ -124,6 +122,10 @@ export function createUrl(url: string) { return `${contextPath}/api/v2${urlWithStartingSlash}`; } +export function createUrlWithIdentifiers(url: string): string { + return createUrl(url) + "?X-SCM-Client=WUI&X-SCM-Session-ID=" + sessionId; +} + class ApiClient { get(url: string): Promise { return fetch(createUrl(url), applyFetchOptions({})).then(handleFailure); @@ -218,9 +220,8 @@ class ApiClient { } subscribe(url: string, argument: SubscriptionArgument): Cancel { - const es = new EventSourcePolyfill(createUrl(url), { - withCredentials: true, - headers: createRequestHeaders() + const es = new EventSource(createUrlWithIdentifiers(url), { + withCredentials: true }); let listeners: MessageListeners; @@ -228,9 +229,11 @@ class ApiClient { if ("onMessage" in argument) { listeners = (argument as SubscriptionContext).onMessage; if (argument.onError) { + // @ts-ignore typing of EventSource is weird es.onerror = argument.onError; } if (argument.onOpen) { + // @ts-ignore typing of EventSource is weird es.onopen = argument.onOpen; } } else { @@ -238,6 +241,7 @@ class ApiClient { } for (const type in listeners) { + // @ts-ignore typing of EventSource is weird es.addEventListener(type, listeners[type]); } diff --git a/yarn.lock b/yarn.lock index 42d56ee047..a2d1ea2670 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6580,11 +6580,6 @@ etag@~1.8.1: resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= -event-source-polyfill@^1.0.9: - version "1.0.12" - resolved "https://registry.yarnpkg.com/event-source-polyfill/-/event-source-polyfill-1.0.12.tgz#38546c4fee76dcadae2560185610ae46c5a39520" - integrity sha512-WjOTn0LIbaN08z/8gNt3GYAomAdm6cZ2lr/QdvhTTEipr5KR6lds2ziUH+p/Iob4Lk6NClKhwPOmn1NjQEcJCg== - eventemitter3@^3.1.0: version "3.1.2" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"