<commit_before>angular.module('mrlapp.wsconn', [])
        .service('wsconnService', [function () {
                //refactor this - more generalization & probably using .provide to inject a config & a callback before creation of the service
                
                var callback;
                
                this.subscribeToMessages = function (cb) {
                    callback = cb;
                };

                this.sendMessage = function (message) {
                    var json = jQuery.stringifyJSON(message);
                    this.sendDirectMessage(json);
                };

                this.sendDirectMessage = function (message) {
                    socket.push(message);
                    console.log('Sent message: ' + message);
                };
                
                var transport = 'websocket';
                var socket = null;

                this.connect = function (host) {
                    var request = {url: host,
                        transport: 'websocket',
                        enableProtocol: true,
                        trackMessageLength: true,
                        logLevel: 'debug'};

                    request.onOpen = function (response) {
                        // Socket open ...
                        console.log('Info: ' + transport + ' connection opened.');
                    };

                    request.onClose = function (response) {
                        console.log('websocket, onclose');
                        if (response.state == "unsubscribe") {
                            console.log('Info: ' + transport + ' closed.');
                        }
                    };

                    request.onTransportFailure = function (errorMsg, request) {
                        jQuery.atmosphere.info(errorMsg);
                        if (window.EventSource) {
                            request.fallbackTransport = "sse";
                        } else {
                            request.fallbackTransport = 'long-polling';
                        }
                        transport = request.fallbackTransport;

                        console.log('Error: falling back to ' + transport + ' ' + errorMsg);
                    };

                    request.onMessage = function (response) {
                        var body = response.responseBody;
                        var msg;
                        try {
                            msg = jQuery.parseJSON(body);
                        } catch (e) {
                            console.log('Error onMessage: ', e, body);
                            return;
                        }
                        callback(msg);
                    };
                    socket = $.atmosphere.subscribe(request);
                };
            }]);<commit_msg>WebUI - filter out heartbeats<commit_after>angular.module('mrlapp.wsconn', [])
        .service('wsconnService', [function () {
                //refactor this - more generalization & probably using .provide to inject a config & a callback before creation of the service

                var callback;

                this.subscribeToMessages = function (cb) {
                    callback = cb;
                };

                this.sendMessage = function (message) {
                    var json = jQuery.stringifyJSON(message);
                    this.sendDirectMessage(json);
                };

                this.sendDirectMessage = function (message) {
                    socket.push(message);
                    console.log('Sent message: ' + message);
                };

                var transport = 'websocket';
                var socket = null;

                this.connect = function (host) {
                    var request = {url: host,
                        transport: 'websocket',
                        enableProtocol: true,
                        trackMessageLength: true,
                        logLevel: 'debug'};

                    request.onOpen = function (response) {
                        // Socket open ...
                        console.log('Info: ' + transport + ' connection opened.');
                    };

                    request.onClose = function (response) {
                        console.log('websocket, onclose');
                        if (response.state == "unsubscribe") {
                            console.log('Info: ' + transport + ' closed.');
                        }
                    };

                    request.onTransportFailure = function (errorMsg, request) {
                        jQuery.atmosphere.info(errorMsg);
                        if (window.EventSource) {
                            request.fallbackTransport = "sse";
                        } else {
                            request.fallbackTransport = 'long-polling';
                        }
                        transport = request.fallbackTransport;

                        console.log('Error: falling back to ' + transport + ' ' + errorMsg);
                    };

                    request.onMessage = function (response) {
                        var body = response.responseBody;
                        if (body == 'X') {
                            console.log("heartbeat:", body);
                        } else {
                            var msg;
                            try {
                                msg = jQuery.parseJSON(body);
                            } catch (e) {
                                console.log('Error onMessage: ', e, body);
                                return;
                            }
                            callback(msg);
                        }
                    };
                    socket = $.atmosphere.subscribe(request);
                };
            }]);
{'fraction_non_alphanumeric': 0.08991265627675972, 'fraction_numerical': 0.0, 'mean_word_length': 0.9060052219321149, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7652782', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1132, 'n_words': 257}