<commit_before>/*
Copyright 2013 <NAME>. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
*/
define(["json2", "backbone"], function() {

if (!window["WebSocket"]) {
	return null;
}

var Conn = Backbone.Model.extend({
	constructor: function(data, opts) {
		this.wsconn = null;
		this.queue = [];
		Backbone.Model.prototype.constructor.call(this, data, opts);
	},
	connect: function() {
		var c = this;
		if (c.urlRoot) {
			c.wsurl = c.url();
		}
		if (!c.wsurl) {
			c.wsurl = "ws://"+ location.host +"/ws";
		}
		console.log("connect", c.wsurl);
		c.trigger("connect", c.wsurl);
		var ws = c.wsconn = new WebSocket(c.wsurl);
		ws.onopen = function(e) {
			c.trigger("open", e);
			if (c.queue) {
				console.log("work", c.queue);
				_.each(c.queue, c.wsconn.send, c.wsconn);
				c.queue = [];
			}
		};
		ws.onclose = function(e) {
			c.wsconn = null;
			c.trigger("close", e);
		};
		ws.onmessage = function(e) {
			var msg = JSON.parse(e.data)
			console.log("msg", msg);
			c.trigger("msg", msg);
			c.trigger("msg:"+ msg.Head, msg.Data);
		};
		ws.onerror = function(e) {
			c.trigger("error", e.message);
		};
	},
	connected: function() {
		return this.wsconn != null;
	},
	send: function(head, data) {
		var msg = JSON.stringify({"Head":head, "Data":data});
		if (this.wsconn != null) {
			console.log("send", msg);<commit_msg>fixes websocket error.<commit_after>/*
Copyright 2013 <NAME>. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
*/
define(["json2", "backbone"], function() {

if (!window["WebSocket"]) {
	return null;
}

var Conn = Backbone.Model.extend({
	constructor: function(data, opts) {
		this.wsconn = null;
		this.queue = [];
		Backbone.Model.prototype.constructor.call(this, data, opts);
	},
	connect: function() {
		var c = this;
		if (c.urlRoot) {
			c.wsurl = c.url();
		}
		if (!c.wsurl) {
			c.wsurl = "ws://"+ location.host +"/ws";
		}
		console.log("connect", c.wsurl);
		c.trigger("connect", c.wsurl);
		var ws = c.wsconn = new WebSocket(c.wsurl);
		ws.onopen = function(e) {
			c.trigger("open", e);
			if (c.queue) {
				console.log("work", c.queue);
				_.each(c.queue, function(e) {
					c.wsconn.send(e);
				});
				c.queue = [];
			}
		};
		ws.onclose = function(e) {
			c.wsconn = null;
			c.trigger("close", e);
		};
		ws.onmessage = function(e) {
			var msg = JSON.parse(e.data)
			console.log("msg", msg);
			c.trigger("msg", msg);
			c.trigger("msg:"+ msg.Head, msg.Data);
		};
		ws.onerror = function(e) {
			c.trigger("error", e.message);
		};
	},
	connected: function() {
		return this.wsconn != null;
	},
	send: function(head, data) {
		var msg = JSON.stringify({"Head":head, "Data":data});
		if (this.wsconn != null) {
			console.log("send", msg);
{'fraction_non_alphanumeric': 0.19873150105708245, 'fraction_numerical': 0.0035236081747709656, 'mean_word_length': 3.237313432835821, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '6470401', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1069, 'n_words': 241}