mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
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:
@@ -37,7 +37,7 @@ import { Kind, OperationTypeNode } from 'graphql';
|
|||||||
import { Apollo } from 'apollo-angular';
|
import { Apollo } from 'apollo-angular';
|
||||||
import { onError } from '@apollo/client/link/error';
|
import { onError } from '@apollo/client/link/error';
|
||||||
import { RetryLink } from '@apollo/client/link/retry';
|
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 { switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { FeaturesServiceToken, IFeaturesService } from '@alfresco/adf-core/feature-flags';
|
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);
|
const url = new URL(serviceUrl, this.host);
|
||||||
url.protocol = protocol;
|
|
||||||
|
|
||||||
return url.href;
|
return url.href;
|
||||||
}
|
}
|
||||||
@@ -110,7 +116,7 @@ export class WebSocketService {
|
|||||||
|
|
||||||
this.httpLink = options.httpUrl
|
this.httpLink = options.httpUrl
|
||||||
? new HttpLink({
|
? new HttpLink({
|
||||||
uri: this.createUrl(options.httpUrl, 'https')
|
uri: this.createHttpUrl(options.httpUrl)
|
||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
@@ -172,7 +178,7 @@ export class WebSocketService {
|
|||||||
|
|
||||||
private createTransportWsLink(options: serviceOptions) {
|
private createTransportWsLink(options: serviceOptions) {
|
||||||
this.wsLink = new WebSocketLink({
|
this.wsLink = new WebSocketLink({
|
||||||
uri: this.createUrl(options.wsUrl, 'wss') + '/ws/graphql',
|
uri: this.createWsUrl(options.wsUrl) + '/ws/graphql',
|
||||||
options: {
|
options: {
|
||||||
reconnect: true,
|
reconnect: true,
|
||||||
lazy: true,
|
lazy: true,
|
||||||
@@ -187,7 +193,7 @@ export class WebSocketService {
|
|||||||
private createGraphQLWsLink(options: serviceOptions) {
|
private createGraphQLWsLink(options: serviceOptions) {
|
||||||
this.wsLink = new GraphQLWsLink(
|
this.wsLink = new GraphQLWsLink(
|
||||||
createClient({
|
createClient({
|
||||||
url: this.createUrl(options.wsUrl, 'wss') + '/v2/ws/graphql',
|
url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql',
|
||||||
connectionParams: {
|
connectionParams: {
|
||||||
Authorization: 'Bearer ' + this.authService.getToken()
|
Authorization: 'Bearer ' + this.authService.getToken()
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user