<commit_before>import Ember from 'ember';

export default Ember.Controller.extend({

  socketService: Ember.inject.service('websockets'),
  init: function () {
    this._super.apply(this, arguments);

    const location = `ws://${window.location.host}/state`;
    const socket = this.get('socketService').socketFor(location);

    socket.on('open', function() {
      this.set('content.connected',true);
      }, this);
    socket.on('close', function () {
      this.set('content.connected',false);
      }, this);
    socket.on('message', function (event) {
      const data = JSON.parse(event.data);
      this.set('content.uptime', data.uptime);
      this.set('content.memory.heapTotal',data.memory.heapTotal);
      this.set('content.memory.heapUsed',data.memory.heapUsed);
      this.set('content.memory.rss',data.memory.rss);
    }, this);
  }
});<commit_msg>feat: (not working) trying to reopen socket if connection gets lost<commit_after>import Ember from 'ember';

export default Ember.Controller.extend({

  socketService: Ember.inject.service('websockets'),
  init: function () {
    this._super.apply(this, arguments);

    const location = `ws://${window.location.host}/state`;
    let socket = this.get('socketService').socketFor(location);
    let intervalHandler;
    const myself = this;

    socket.on('open', function() {
      console.log(`(Re)open socket ${location}`);
      this.set('content.connected',true);
      clearInterval(intervalHandler);
      }, this);
    socket.on('close', function () {
      socket = undefined;
      this.set('content.connected',false);
      intervalHandler = setInterval(function() {
        socket = myself.get('socketService').socketFor(location);
        console.log(`Trying to reopen socket ${location} -> ${socket}`);
        }, 5000);
      }, this);
    socket.on('message', function (event) {
      const data = JSON.parse(event.data);
      this.set('content.uptime', data.uptime);
      this.set('content.memory.heapTotal',data.memory.heapTotal);
      this.set('content.memory.heapUsed',data.memory.heapUsed);
      this.set('content.memory.rss',data.memory.rss);
    }, this);
  }
});
{'fraction_non_alphanumeric': 0.16929499072356216, 'fraction_numerical': 0.0018552875695732839, 'mean_word_length': 3.5991471215351813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1273348', 'n_tokens_mistral': 643, 'n_tokens_neox': 630, 'n_words': 110}