mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-30358 Remove client if already exists when connection is closed to use the refreshed token changing the page, turn connectionParams into a function to ensures that the latest token is always used for WebSocket connections
This commit is contained in:
@@ -27,7 +27,7 @@ describe('WebSocketService', () => {
|
|||||||
let service: WebSocketService;
|
let service: WebSocketService;
|
||||||
const onLogoutSubject: Subject<void> = new Subject<void>();
|
const onLogoutSubject: Subject<void> = new Subject<void>();
|
||||||
|
|
||||||
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed']);
|
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed', 'removeClient']);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ export class WebSocketService {
|
|||||||
return this.apollo.use(apolloClientName).subscribe<T>({ errorPolicy: 'all', ...subscriptionOptions });
|
return this.apollo.use(apolloClientName).subscribe<T>({ errorPolicy: 'all', ...subscriptionOptions });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private removeApolloClientIfExists(apolloClientName: string) {
|
||||||
|
if (this.apollo.use(apolloClientName)) {
|
||||||
|
this.apollo.removeClient(apolloClientName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private get contextRoot() {
|
private get contextRoot() {
|
||||||
return this.appConfigService.get('bpmHost', '');
|
return this.appConfigService.get('bpmHost', '');
|
||||||
}
|
}
|
||||||
@@ -155,10 +161,13 @@ export class WebSocketService {
|
|||||||
this.wsLink = new GraphQLWsLink(
|
this.wsLink = new GraphQLWsLink(
|
||||||
createClient({
|
createClient({
|
||||||
url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql',
|
url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql',
|
||||||
connectionParams: {
|
connectionParams: () => ({
|
||||||
Authorization: 'Bearer ' + this.authService.getToken()
|
Authorization: 'Bearer ' + this.authService.getToken()
|
||||||
},
|
}),
|
||||||
on: {
|
on: {
|
||||||
|
closed: () => {
|
||||||
|
this.removeApolloClientIfExists(options.apolloClientName);
|
||||||
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.apollo.removeClient(options.apolloClientName);
|
this.apollo.removeClient(options.apolloClientName);
|
||||||
this.initSubscriptions(options);
|
this.initSubscriptions(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user