AAE-20808 Adding support for ws protocol in websocket service (#10432)

* AAE-20808 Adding support for ws protocol in websocket service

* AAE-20808 Fixed import
This commit is contained in:
Ehsan Rezaei
2024-11-26 15:20:33 +01:00
committed by GitHub
parent b63a68dd37
commit 6723cd1802

View File

@@ -37,7 +37,7 @@ import { Kind, OperationTypeNode } from 'graphql';
import { Apollo } from 'apollo-angular';
import { onError } from '@apollo/client/link/error';
import { RetryLink } from '@apollo/client/link/retry';
import { Observable } from 'rxjs/internal/Observable';
import { Observable } from 'rxjs';
import { switchMap, take, tap } from 'rxjs/operators';
import { FeaturesServiceToken, IFeaturesService } from '@alfresco/adf-core/feature-flags';
@@ -89,9 +89,15 @@ export class WebSocketService {
);
}
private createUrl(serviceUrl: string, protocol: 'https' | 'wss' = 'wss'): string {
private createWsUrl(serviceUrl: string): string {
const url = new URL(serviceUrl, this.host);
url.protocol = url.protocol === 'https' ? 'wss' : 'ws';
return url.href;
}
private createHttpUrl(serviceUrl: string): string {
const url = new URL(serviceUrl, this.host);
url.protocol = protocol;
return url.href;
}
@@ -110,7 +116,7 @@ export class WebSocketService {
this.httpLink = options.httpUrl
? new HttpLink({
uri: this.createUrl(options.httpUrl, 'https')
uri: this.createHttpUrl(options.httpUrl)
})
: undefined;
@@ -172,7 +178,7 @@ export class WebSocketService {
private createTransportWsLink(options: serviceOptions) {
this.wsLink = new WebSocketLink({
uri: this.createUrl(options.wsUrl, 'wss') + '/ws/graphql',
uri: this.createWsUrl(options.wsUrl) + '/ws/graphql',
options: {
reconnect: true,
lazy: true,
@@ -187,7 +193,7 @@ export class WebSocketService {
private createGraphQLWsLink(options: serviceOptions) {
this.wsLink = new GraphQLWsLink(
createClient({
url: this.createUrl(options.wsUrl, 'wss') + '/v2/ws/graphql',
url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql',
connectionParams: {
Authorization: 'Bearer ' + this.authService.getToken()
},