Skip to content

Commit

Permalink
AAE-20808 Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-2019 committed Dec 6, 2024
1 parent 65936d3 commit 8ef1b92
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { createClient } from 'graphql-ws';
import { Inject, Injectable, Optional } from '@angular/core';
import { inject, Inject, Injectable, Optional } from '@angular/core';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { WebSocketLink } from '@apollo/client/link/ws';
import {
Expand All @@ -38,10 +38,8 @@ import { onError } from '@apollo/client/link/error';
import { RetryLink } from '@apollo/client/link/retry';
import { getMainDefinition } from '@apollo/client/utilities';
import { switchMap, take, tap } from 'rxjs/operators';
import { AuthenticationService } from '@alfresco/adf-core';
import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
import { FeaturesServiceToken, IFeaturesService } from '@alfresco/adf-core/feature-flags';
import { BaseCloudService } from './base-cloud.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';

interface serviceOptions {
apolloClientName: string;
Expand All @@ -53,20 +51,18 @@ interface serviceOptions {
@Injectable({
providedIn: 'root'
})
export class WebSocketService extends BaseCloudService {
export class WebSocketService {
private appConfigService = inject(AppConfigService);
private subscriptionProtocol: 'graphql-ws' | 'transport-ws' = 'transport-ws';
private wsLink: GraphQLWsLink | WebSocketLink;
private httpLinkHandler: HttpLinkHandler;

constructor(
adfHttpClient: AdfHttpClient,
private readonly apollo: Apollo,
private readonly httpLink: HttpLink,
private readonly authService: AuthenticationService,
@Optional() @Inject(FeaturesServiceToken) private featuresService: IFeaturesService
) {
super(adfHttpClient);
}
) {}

public getSubscription<T>(options: serviceOptions): Observable<FetchResult<T>> {
const { apolloClientName, subscriptionOptions } = options;
Expand All @@ -91,6 +87,10 @@ export class WebSocketService extends BaseCloudService {
);
}

private get contextRoot() {
return this.appConfigService.get('bpmHost', '');
}

private createWsUrl(serviceUrl: string): string {
const url = new URL(serviceUrl, this.contextRoot);
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
Expand Down

0 comments on commit 8ef1b92

Please sign in to comment.