From 6723cd1802183489b7ce38925e4d3fed83edc374 Mon Sep 17 00:00:00 2001 From: Ehsan Rezaei Date: Tue, 26 Nov 2024 15:20:33 +0100 Subject: [PATCH] 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 --- .../src/lib/services/web-socket.service.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/process-services-cloud/src/lib/services/web-socket.service.ts b/lib/process-services-cloud/src/lib/services/web-socket.service.ts index e19a162b79..4299328552 100644 --- a/lib/process-services-cloud/src/lib/services/web-socket.service.ts +++ b/lib/process-services-cloud/src/lib/services/web-socket.service.ts @@ -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() },