0

My issue is that once I open a page I get the data from the web-socket but while testing when I close my internet connection and then reconnect it, i see a message saying "Woops...Connection lost undefined". I want to reconnect to the web-socket automatically. My code is :

var socket = new SockJS("${createLink(uri: '/stomp')}");
        var client = Stomp.over(socket);
            client.connect({}, function () {
                client.subscribe("/topic/${userInstance?.username}", function (message) {
                    console.log("Data on##....." + message.body);
                    var data = jQuery.parseJSON(message.body.toString());
                    var deviceId = $('#deviceId').find(":selected").val();
                    if (data.type == "balance") {
                        showDataBalance(data);
                    } else if (liveTrack == true && data.deviceId == deviceId && data.type == "event") {
                        var latLog = {
                            lat: parseFloat(data.eventData.latitude),
                            lng: parseFloat(data.eventData.longitude)
                        };
                        drawMarkerForLiveTracking(latLog, data.eventData);
                    }

                });
            });

And my STOMP.JS code is :

this.ws.onclose = function() {
        var msg;
        msg = "Whoops! Lost connection to " + _this.ws.url;
        if (typeof _this.debug === "function") {
          _this.debug(msg);
        }
        _this._cleanUp();
        return typeof errorCallback === "function" ? errorCallback(msg) : void 0;
      };
      return this.ws.onopen = function() {
        if (typeof _this.debug === "function") {
          _this.debug('Web Socket Opened...');
        }
        headers["accept-version"] = Stomp.VERSIONS.supportedVersions();
        headers["heart-beat"] = [_this.heartbeat.outgoing, _this.heartbeat.incoming].join(',');
        return _this._transmit("CONNECT", headers);
      };

What changes should I do in my connection establishment to make it auto re-connect?

Ishaan Nigam
  • 83
  • 1
  • 10
  • does this help? http://stackoverflow.com/questions/22361917/automatic-reconnect-with-stomp-js-in-node-js-application – zyro Jan 04 '16 at 15:00
  • Possible duplicate of [Reconnection of Client when server reboots in WebSocket](http://stackoverflow.com/questions/3780511/reconnection-of-client-when-server-reboots-in-websocket) – tylerwal Jan 04 '16 at 17:08

0 Answers0