stomp-js / ng2-stompjs

Angular 6 and 7 - Stomp service over Websockets
https://stomp-js.github.io/
Apache License 2.0
182 stars 32 forks source link

WS not reconnecting after wifi is turned off and on. #238

Closed ajayshah1992 closed 2 years ago

ajayshah1992 commented 3 years ago

When I disconnect wifi and after few mins reconnect it by that time WS stops receiving message but still It is able to send msgs to other clients WS.

this.config = {

        //  url: new SockJS(environment.STOMP_ENDPOINT + '/?access_token=' + this.storage.get(STORAGE_KEY)),
        beforeConnect: () => {
            tkn = this.storage.get(STORAGE_KEY);
            console.log('%c called before connect', 'color: blue');
        },
        onDisconnect: () => {
            console.log("on disconnect")
        },
        webSocketFactory: () => {
            return new SockJS(
                environment.STOMP_ENDPOINT +
                    '/?access_token=' + tkn
            );
        },
        headers: {
            userId: userConfig.id,
            companyId: userConfig.company,
        },
        heartbeatIncoming: 0, // Typical value 0 - disabled
        heartbeatOutgoing: 20000, // Typical value 20000 - every 20 seconds
        reconnectDelay: 3000,
        connectionTimeout:1000,
        logRawCommunication: false,
        debug: (msg: string): void => {
             console.log(new Date(), msg);
        },
        discardWebsocketOnCommFailure: false
    };

console prints when wifi is not off

internet State>>>> {hasInternetAccess: true, hasNetworkConnection: true} STOMP broker false client is active false called before connect Stomp connection status CLOSED Thu May 20 2021 17:48:16 GMT+0545 (Nepal Time) "Not connected, queueing" Thu May 20 2021 17:48:16 GMT+0545 (Nepal Time) "Opening Web Socket..." Thu May 20 2021 17:48:16 GMT+0545 (Nepal Time) "Web Socket Opened..." Thu May 20 2021 17:48:16 GMT+0545 (Nepal Time) ">>> CONNECT

Thu May 20 2021 17:48:16 GMT+0545 (Nepal Time) ">>> SEND destination:/topic/588aff69f866f2577f5262e2/global priority:low custom:userLiveNotice content-length:86

Stomp connection status TRYING


Console after wifi on and off

internet State>>>> {hasInternetAccess: false, hasNetworkConnection: false} STOMP broker true client is active true some api failing after disconnection GET https://dev-api.sparkworksoftware.com/api/chats/sync/u net::ERR_INTERNET_DISCONNECTED after wifi is turned ON internet State>>>> {hasInternetAccess: true, hasNetworkConnection: true} STOMP broker true client is active true

So there is no attempt to reconnect.

kum-deepak commented 3 years ago

SockJS is known to cause issues during automated reconnects. Please see https://stomp-js.github.io/guide/stompjs/rx-stomp/ng2-stompjs/using-stomp-with-sockjs.html

Switch to directly using Websockets and see if that resolves the issue.