lahsivjar / react-stomp

React websocket component for STOMP protocol over SockJs
https://www.npmjs.com/package/react-stomp
MIT License
134 stars 41 forks source link

How to use it over https? #165

Closed ramkumar-hosalli closed 4 years ago

ramkumar-hosalli commented 4 years ago
Screen Shot 2020-07-09 at 12 33 46 PM Screen Shot 2020-07-09 at 12 35 32 PM
ramkumar-hosalli commented 4 years ago

Incompatibile SockJS! Main site uses: "1.4.0", the iframe: "1.0.0" websocket.js:6 WebSocket connection to ---------- failed: Error during WebSocket handshake: Unexpected response code: 400 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. in SockJsClient

lahsivjar commented 4 years ago

What is the sock-js version of your server?

ramkumar-hosalli commented 4 years ago

Hi, it is "sockjs-client": "1.4.0" and "react-stomp": "5.0.0" in client side. In the Server side, we are using the package called "spring-websocket": "4.2.4" and im not sure internally which version of sockjs that is using but it might be < 1.4.

lahsivjar commented 4 years ago

Looks like the WebSocket connection is not able to be established and it is falling back to iframe-based HTTP streaming. For iframe approach, the sockjs version is downloaded based on the URL that is specified. I suspect the URL for sockJs is pointing to version 1.0.0.

You can set the URL when registering the STOMP endpoint in spring. Something like:

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket").withSockJS()
                .setClientLibraryUrl("<sock_js_client_url>");
    }

Check this out for more detail: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#websocket-fallback-xhr-vs-iframe