mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Use browser build in EventSource for apiClient subscriptions
This commit is contained in:
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Update resteasy to version 4.5.2.Final
|
- 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
|
## 2.0.0-rc5 - 2020-03-12
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
"@scm-manager/ui-types": "^2.0.0-SNAPSHOT",
|
"@scm-manager/ui-types": "^2.0.0-SNAPSHOT",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"date-fns": "^2.4.1",
|
"date-fns": "^2.4.1",
|
||||||
"event-source-polyfill": "^1.0.9",
|
|
||||||
"gitdiff-parser": "^0.1.2",
|
"gitdiff-parser": "^0.1.2",
|
||||||
"lowlight": "^1.13.0",
|
"lowlight": "^1.13.0",
|
||||||
"query-string": "5",
|
"query-string": "5",
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { contextPath } from "./urls";
|
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";
|
import { createBackendError, ForbiddenError, isBackendError, UnauthorizedError, BackendErrorContent } from "./errors";
|
||||||
|
|
||||||
type SubscriptionEvent = {
|
type SubscriptionEvent = {
|
||||||
@@ -124,6 +122,10 @@ export function createUrl(url: string) {
|
|||||||
return `${contextPath}/api/v2${urlWithStartingSlash}`;
|
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 {
|
class ApiClient {
|
||||||
get(url: string): Promise<Response> {
|
get(url: string): Promise<Response> {
|
||||||
return fetch(createUrl(url), applyFetchOptions({})).then(handleFailure);
|
return fetch(createUrl(url), applyFetchOptions({})).then(handleFailure);
|
||||||
@@ -218,9 +220,8 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscribe(url: string, argument: SubscriptionArgument): Cancel {
|
subscribe(url: string, argument: SubscriptionArgument): Cancel {
|
||||||
const es = new EventSourcePolyfill(createUrl(url), {
|
const es = new EventSource(createUrlWithIdentifiers(url), {
|
||||||
withCredentials: true,
|
withCredentials: true
|
||||||
headers: createRequestHeaders()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let listeners: MessageListeners;
|
let listeners: MessageListeners;
|
||||||
@@ -228,9 +229,11 @@ class ApiClient {
|
|||||||
if ("onMessage" in argument) {
|
if ("onMessage" in argument) {
|
||||||
listeners = (argument as SubscriptionContext).onMessage;
|
listeners = (argument as SubscriptionContext).onMessage;
|
||||||
if (argument.onError) {
|
if (argument.onError) {
|
||||||
|
// @ts-ignore typing of EventSource is weird
|
||||||
es.onerror = argument.onError;
|
es.onerror = argument.onError;
|
||||||
}
|
}
|
||||||
if (argument.onOpen) {
|
if (argument.onOpen) {
|
||||||
|
// @ts-ignore typing of EventSource is weird
|
||||||
es.onopen = argument.onOpen;
|
es.onopen = argument.onOpen;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -238,6 +241,7 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const type in listeners) {
|
for (const type in listeners) {
|
||||||
|
// @ts-ignore typing of EventSource is weird
|
||||||
es.addEventListener(type, listeners[type]);
|
es.addEventListener(type, listeners[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6580,11 +6580,6 @@ etag@~1.8.1:
|
|||||||
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
||||||
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
|
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:
|
eventemitter3@^3.1.0:
|
||||||
version "3.1.2"
|
version "3.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"
|
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"
|
||||||
|
|||||||
Reference in New Issue
Block a user