一旦建立,我想保持该websocket连接的状态。以下代码用于建立连接,但不能使其保持活动状态
connectWebSocket(token) {
const socket = new SockJS('url');
this.stompClient = Stomp.over(socket);
const _this = this;
_this.stompClient.connect({"token" : token, "api_version": 2}, function (frame) {
console.log('WebSocket: - ' + frame);
_this.stompClient.subscribe('/topic/notify/' + token, function(notification){
console.log('WebSocket: - Notification - ', notification.body);
_this.info.lastUpdateTime = new Date();
//ToDo: Need to wrinte a message service that will handle the web socket response.
_this.messageProcessorService.process(notification.body);
});
_this.announce(token);
});
}