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 Nov 18, 2024
1 parent 192b685 commit ea70478
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions lib/process-services-cloud/src/lib/services/web-socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,10 @@ export class WebSocketService {
private initSubscriptions(options: serviceOptions): void {
switch (this.subscriptionProtocol) {
case 'graphql-ws':
this.wsLink = new GraphQLWsLink(
createClient({
url: this.createUrl(options.wsUrl, 'wss') + '/v2/ws/graphql',
connectionParams: {
Authorization: 'Bearer ' + this.authService.getToken()
},
on: {
error: () => {
this.apollo.removeClient(options.apolloClientName);
this.initSubscriptions(options);
}
},
lazy: true
})
);
this.createGraphQLWsLink(options);
break;
case 'transport-ws':
this.wsLink = new WebSocketLink({
uri: this.createUrl(options.wsUrl, 'wss') + '/ws/graphql',
options: {
reconnect: true,
lazy: true,
connectionParams: {
kaInterval: 2000,
'X-Authorization': 'Bearer ' + this.authService.getToken()
}
}
});
this.createTransportWsLink(options);
break;
default:
throw new Error('Unknown subscription protocol');
Expand Down Expand Up @@ -193,4 +169,36 @@ export class WebSocketService {
cache: new InMemoryCache({ merge: true } as InMemoryCacheConfig)
});
}

private createTransportWsLink(options: serviceOptions) {
this.wsLink = new WebSocketLink({
uri: this.createUrl(options.wsUrl, 'wss') + '/ws/graphql',
options: {
reconnect: true,
lazy: true,
connectionParams: {
kaInterval: 2000,
'X-Authorization': 'Bearer ' + this.authService.getToken()
}
}
});
}

private createGraphQLWsLink(options: serviceOptions) {
this.wsLink = new GraphQLWsLink(
createClient({
url: this.createUrl(options.wsUrl, 'wss') + '/v2/ws/graphql',
connectionParams: {
Authorization: 'Bearer ' + this.authService.getToken()
},
on: {
error: () => {
this.apollo.removeClient(options.apolloClientName);
this.initSubscriptions(options);
}
},
lazy: true
})
);
}
}

0 comments on commit ea70478

Please sign in to comment.