The Client
class of STOMP has a method called deactivate()
. Is it going to terminate all active WS connections, or do I need to manually unsubscribe from subscriptions made inside the onConnect
callback?
public setWebSocketConnections(loggedUser) {
let scope = this;
console.info('Obtaining WS connection...');
this.stompClient = new Client({
webSocketFactory: () => new SockJS(scope.runtimeEnvironment.WEBSOCKET_ENDPOINT),
connectHeaders: {
'ctx-jwt': loggedUser.temporaryToken.match(/ctx-jwt=[^;]+/)[0].split('=')[1]
},
onConnect: frame => this.onConnectionSuccess(scope),
reconnectDelay: 10000,
heartbeatIncoming: 10000,
heartbeatOutgoing: 10000
});
if (!this.runtimeEnvironment.PRODUCTION)
this.stompClient.debug = console.log;
this.stompClient.activate();
}
private onConnectionSuccess(scope) {
let liveContextFn = response => this.liveContextInProgress.next(response);
// Live context modification endpoint
this.subscriptions.push(scope.stompClient.subscribe('/topic/contexts/live', message => liveContextFn(JSON.parse(JSON.parse(message.body).content))));
}
// Closes all active connections of the logged user
public disconnect() {
this.subscriptions.forEach(s => s.unsubscribe()); // Is this needed?
if (this.stompClient)
this.stompClient.deactivate();
}