<commit_before>var Node = require('./node');
var Vector = require('./vector.js');
var Key = require('../publickey.js');
var JWT = require('json-web-token');

function Observer (socket, reflector) {
  this.socket = socket;
  this.reflector = reflector;

  if (this.reflector) {
    this.document = this.reflector.scene.ownerDocument;
  }
}

Observer.prototype.destroy = function () {
  this.reflector = undefined;
  this.awareList = undefined;

  this.socket.close();

  delete this.player;
  delete this.socket;
};
<commit_msg>Check socket exists before closing it.<commit_after>var Node = require('./node');
var Vector = require('./vector.js');
var Key = require('../publickey.js');
var JWT = require('json-web-token');
var WebSocket = require('ws');

function Observer (socket, reflector) {
  this.socket = socket;
  this.reflector = reflector;

  if (this.reflector) {
    this.document = this.reflector.scene.ownerDocument;
  }
}

Observer.prototype.destroy = function () {
  this.reflector = undefined;
  this.awareList = undefined;

  if (this.socket && (this.socket.readyState !== WebSocket.CLOSED)) {
    this.socket.close();
  }

  delete this.player;
  delete this.socket;
};

{'fraction_non_alphanumeric': 0.15851602023608768, 'fraction_numerical': 0.0, 'mean_word_length': 3.9665271966527196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7080976', 'n_tokens_mistral': 377, 'n_tokens_neox': 369, 'n_words': 82}