如何在角度6中使用stomp / sock js保持与wesocket连接的连接

时间:2019-02-25 17:39:35

标签: angular angular6 sockjs stompjs

一旦建立,我想保持该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);      

    });
  } 

0 个答案:

没有答案