text: (function() {
      'use strict';
      /* globals SockJS, Stomp */
  
      angular
          .module('frontendApp')
          .factory('JhiTrackerService', JhiTrackerService);
  
      JhiTrackerService.$inject = ['$rootScope', '$window', '$cookies', '$http', '$q', '$localStorage'];
  
      function JhiTrackerService ($rootScope, $window, $cookies, $http, $q, $localStorage) {
          var stompClient = null;
          var subscriber = null;
          var listener = $q.defer();
          var connected = $q.defer();
          var alreadyConnectedOnce = false;
  
          var service = {
              connect: connect,
              disconnect: disconnect,
              receive: receive,
              sendActivity: sendActivity,
              subscribe: subscribe,
              unsubscribe: unsubscribe
          };
  
          return service;
  
          function connect () {
              //building absolute path so that websocket doesnt fail when deploying with a context path
              var loc = $window.location;
              var url = '//' + loc.host+":4443" + loc.pathname + 'websocket/tracker';
              /*jshint camelcase: false */
              var authToken = angular.fromJson($localStorage.authenticationToken).access_token;
              url += '?access_token=' + authToken;
              var socket = new SockJS(url);
              stompClient = Stomp.over(socket);
              var stateChangeStart;
              var headers = {};
              headers['X-CSRF-TOKEN'] = $cookies[$http.defaults.xsrfCookieName];
              stompClient.connect(headers, function() {
                  connected.resolve('success');
                  sendActivity();
                  if (!alreadyConnectedOnce) {
                      stateChangeStart = $rootScope.$on('$stateChangeStart', function () {
                          sendActivity();
                      });
                      alreadyConnectedOnce = true;
                  }
              });
              $rootScope.$on('$destroy', function () {
                  if(angular.isDefined(stateChangeStart) && stateChangeStart !== null){
                      stateChangeStart();
                  }
              });
          }
  
          function disconnect () {
              if (stompClient !== null) {
                  stompClient.disconnect();
                  stompClient = null;
              }
          }
  
          function receive () {
              return listener.promise;
          }
  
          function sendActivity() {
              if (stompClient !== null && stompClient.connected) {
                  stompClient
                      .send('/topic/activity',
                      {},
                      angular.toJson({'page': $rootScope.toState.name}));
              }
          }
  
          function subscribe () {
              connected.promise.then(function() {
                  subscriber = stompClient.subscribe('/topic/tracker', function(data) {
                      listener.notify(angular.fromJson(data.body));
                  });
              }, null, null);
          }
  
          function unsubscribe () {
              if (subscriber !== null) {
                  subscriber.unsubscribe();
              }
              listener = $q.defer();
          }
      }
  })();
  