<commit_before>/*
 * Cordova WebSocket Server Plugin
 *
 * WebSocket Server plugin for Cordova/Phonegap 
 * by <NAME>
 */

'use strict';
var exec = require('cordova/exec');

var fail = function(o) {
    console.error("Error " + JSON.stringify(o));
};

var connections = null;

var WebSocketServer = {

    getInterfaces : function(success, failure) {
        return exec(success, failure, "WebSocketServer", "getInterfaces", []);
    },

    start : function(port, options) {
        return exec(function(result) {
            switch (result.action) {
            case 'onStart':
            case 'onDidNotStart':
            case 'onStop':
                var callback = options[result.action];
                if (callback) {
                    callback(result.addr, result.port);
                }
                connections = [];
                break;
            case 'onOpen':
                var conn = result.conn;
                connections[conn.uuid] = conn;
                var callback = options[result.action];
                if (callback) {
                    callback(conn);
                }
                break;
            case 'onMessage':
                var conn = connections[result.uuid];
                if (conn) {
                    var callback = options[result.action];
                    if (callback) {
                        callback(conn, result.msg);
                    }
                }
                break;
            case 'onClose':
                var conn = connections[result.uuid];
                if (conn) {
                    delete connections[conn.uuid];
                    var callback = options[result.action];
                    if (callback) {
                        callback(conn, result.code, result.reason, result.wasClean);
                    }
                }
                break;
            default:
                console.log('unknown action: ' + result.action);<commit_msg>adding state 'open' or 'closed' to connection instance<commit_after>/*
 * Cordova WebSocket Server Plugin
 *
 * WebSocket Server plugin for Cordova/Phonegap 
 * by <NAME>
 */

'use strict';
var exec = require('cordova/exec');

var fail = function(o) {
    console.error("Error " + JSON.stringify(o));
};

var connections = null;

var WebSocketServer = {

    getInterfaces : function(success, failure) {
        return exec(success, failure, "WebSocketServer", "getInterfaces", []);
    },

    start : function(port, options) {
        return exec(function(result) {
            switch (result.action) {
            case 'onStart':
            case 'onDidNotStart':
            case 'onStop':
                var callback = options[result.action];
                if (callback) {
                    callback(result.addr, result.port);
                }
                connections = [];
                break;
            case 'onOpen':
                var conn = result.conn;
                conn.state = 'open';
                connections[conn.uuid] = conn;
                var callback = options[result.action];
                if (callback) {
                    callback(conn);
                }
                break;
            case 'onMessage':
                var conn = connections[result.uuid];
                if (conn) {
                    var callback = options[result.action];
                    if (callback) {
                        callback(conn, result.msg);
                    }
                }
                break;
            case 'onClose':
                var conn = connections[result.uuid];
                conn.state = 'closed';
                if (conn) {
                    delete connections[conn.uuid];
                    var callback = options[result.action];
                    if (callback) {
                        callback(conn, result.code, result.reason, result.wasClean);
                    }
                }
                break;
            default:
                console.log('unknown action: ' + result.action);
{'fraction_non_alphanumeric': 0.10364492933300273, 'fraction_numerical': 0.0, 'mean_word_length': 1.2662921348314606, 'pattern_counts': {'":': 0, '<': 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': '1252654', 'n_tokens_mistral': 1006, 'n_tokens_neox': 931, 'n_words': 228}