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 5, 2024
1 parent 649fe69 commit 2acb305
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/process-services-cloud/src/lib/services/web-socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { createClient } from 'graphql-ws';
import { inject, Inject, Injectable, Optional } from '@angular/core';
import { Inject, Injectable, Optional } from '@angular/core';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { WebSocketLink } from '@apollo/client/link/ws';
import {
Expand All @@ -38,8 +38,10 @@ 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, AppConfigService } from '@alfresco/adf-core';
import { 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 @@ -51,21 +53,20 @@ interface serviceOptions {
@Injectable({
providedIn: 'root'
})
export class WebSocketService {
private appConfigService = inject(AppConfigService);
private host = '';
export class WebSocketService extends BaseCloudService {
private subscriptionProtocol: 'graphql-ws' | 'transport-ws' = 'transport-ws';
private wsLink: GraphQLWsLink | WebSocketLink;
private httpLinkHandler: HttpLinkHandler;

constructor(
protected adfHttpClient: AdfHttpClient,
private readonly apollo: Apollo,
private readonly httpLink: HttpLink,
private readonly authService: AuthenticationService,
@Optional() @Inject(FeaturesServiceToken) private featuresService: IFeaturesService
) {
this.host = this.appConfigService.get('bpmHost', '');
console.error('WebSocketService host initialized:', this.host);
super(adfHttpClient);
console.error('WebSocketService service initialized! ', this.contextRoot);
}

public getSubscription<T>(options: serviceOptions): Observable<FetchResult<T>> {
Expand All @@ -92,16 +93,18 @@ export class WebSocketService {
}

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

console.error('WebSocket URL: ', url.href);
return url.href;
}

private createHttpUrl(serviceUrl: string): string {
const url = new URL(serviceUrl, this.host);
const url = new URL(serviceUrl, this.contextRoot);

console.error('HTTP URL: ', url.href);
return url.href;
}

Expand Down

0 comments on commit 2acb305

Please sign in to comment.