mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +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:
parent
d09b8daa3a
commit
76999ee830
@ -27,7 +27,7 @@ describe('WebSocketService', () => {
|
||||
let service: WebSocketService;
|
||||
const onLogoutSubject: Subject<void> = new Subject<void>();
|
||||
|
||||
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed']);
|
||||
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed', 'removeClient']);
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
|
@ -72,6 +72,12 @@ export class WebSocketService {
|
||||
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() {
|
||||
return this.appConfigService.get('bpmHost', '');
|
||||
}
|
||||
@ -155,10 +161,13 @@ export class WebSocketService {
|
||||
this.wsLink = new GraphQLWsLink(
|
||||
createClient({
|
||||
url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql',
|
||||
connectionParams: {
|
||||
connectionParams: () => ({
|
||||
Authorization: 'Bearer ' + this.authService.getToken()
|
||||
},
|
||||
}),
|
||||
on: {
|
||||
closed: () => {
|
||||
this.removeApolloClientIfExists(options.apolloClientName);
|
||||
},
|
||||
error: () => {
|
||||
this.apollo.removeClient(options.apolloClientName);
|
||||
this.initSubscriptions(options);
|
||||
|
Loading…
x
Reference in New Issue
Block a user