Giter VIP home page Giter VIP logo

Comments (3)

kum-deepak avatar kum-deepak commented on September 24, 2024

There is a specific sequence during STOMP disconnect. This library follows that sequence. So, not sure why this error is generated.

If you want to disconnect by closing the underlying WebSocket without going through the shutdown sequence, there a method - https://stomp-js.github.io/api-docs/latest/classes/Client.html#forceDisconnect. This was added to simulate error cases for test cases.

Just calling forceDisconnect will schedule reconnect. So, you would need to call Client.deactivate as well.

Please see if it works for you.

from stompjs.

WhiteHatTux avatar WhiteHatTux commented on September 24, 2024

Thanks for clarifying.

I had missed the forceDisconnect. It looks like it is working fine.
In the meantime I had also found a workaround on the server side (as it appears to be a server side bug) for spring users stranding here:


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;

public class CustomWebSocketHandlerDecorator
  extends WebSocketHandlerDecorator {

  private static final Logger logger = LoggerFactory.getLogger(CustomWebSocketHandlerDecorator.class);

  public CustomWebSocketHandlerDecorator(WebSocketHandler delegate) {
    super(delegate);
  }

  @Override
  public void handleMessage(final WebSocketSession session, final WebSocketMessage<?> message)
    throws Exception {
    if (message instanceof TextMessage) {
      TextMessage msg = (TextMessage) message;
      String payload = msg.getPayload();

      if (payload.contains("DISCONNECT")) {
        logger.info("ignore disconnect frame to avoid double disconnect: {}", message);
        return;
      }
    }

    super.handleMessage(session, message);
  }
}

and register it with your websocket:

@Configuration
@EnableJms
@EnableWebSocketMessageBroker
public class WebSocketConfig
  extends AbstractWebSocketMessageBrokerConfigurer {

  @Override
  public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.addDecoratorFactory(CustomWebSocketHandlerDecorator::new);
  }
  ....
} 

The issue is resolved for me with this. :-)

from stompjs.

kum-deepak avatar kum-deepak commented on September 24, 2024

Good to know that it works for you. However, I am not sure if it is correct handling as per STOMP protocol specifications (https://stomp.github.io/stomp-specification-1.2.html#DISCONNECT).

from stompjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.