<commit_before>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * WebSocketClient.js                                     *
 *                                                        *
 * hprose websocket client for HTML5.                     *
 *                                                        *
 * LastModified: May 17, 2015                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

(function (global) {
    'use strict';

    var Exception = global.hprose.Exception;
    var Client = global.hprose.Client;
    var BytesIO = global.hprose.BytesIO;
    var Completer = global.hprose.Completer;

    function noop(){}
    var s_id = 0;
    var s_completers = [];
    var s_timeoutId = [];
    var s_messages = [];

    global.hprose.WebSocketClient = function WebSocketClient(uri, functions) {
        if (this.constructor !== WebSocketClient) return new WebSocketClient(uri, functions);
        Client.call(this, uri, functions);
        this.timeout = 0;
        var self = this;
        var ready = false;
        var ws;
        function send(id, request) {
            var bytes = new BytesIO();
            bytes.writeByte((id >> 24) & 0xff);
            bytes.writeByte((id >> 16) & 0xff);
            bytes.writeByte((id >> 8) & 0xff);
            bytes.writeByte(id & 0xff);
            if (request.constructor === String) {
                bytes.writeString(request);
            }
            else {
                bytes.write(request);
            }
            var message = bytes.bytes;
            if (ArrayBuffer.isView) {
                ws.send(message);
            }
            else if (message.buffer.slice) {
                ws.send(message.buffer.slice(0, message.length));
            }
            else {
                ws.send(message.buffer);
            }
        }
        function onopen(e) {
            ready = true;
            if (s_messages.length > 0) {
                for (var id in s_messages) {
                    send(id, s_messages[id]);
                }
                s_messages = [];
            }
        }
        function onmessage(e) {
            var bytes = new BytesIO(e.data);
            var id = bytes.readByte() << 24;
            id = id | bytes.readByte() << 16;
            id = id | bytes.readByte() << 8;
            id = id | bytes.readByte();
            var timeoutId = s_timeoutId[id];
            var completer = s_completers[id];
            delete s_timeoutId[id];
            delete s_completers[id];
            if (timeoutId !== undefined) {
                global.clearTimeout(timeoutId);
                timeoutId = undefined;
            }
            completer.complete(bytes.read(bytes.length - 4));
        }
        function onclose(e) {
            connect();
        }
        function onerror(e) {
            self.onerror("WebSocket", new Exception(e.data));
        }
        function connect() {
            ready = false;
            ws = new WebSocket(self.uri);
            ws.binaryType = "arraybuffer";
            ws.onopen = onopen;
            ws.onmessage = onmessage;
            ws.onerror = onerror;
            ws.onclose = onclose;
        }
        function sendAndReceive(request) {
            var completer = new Completer();
            var timeoutId = undefined;
            if (self.timeout > 0) {
                timeoutId = global.setTimeout((function (id) {
                    return function() {
                        delete s_completers[id];
                        delete s_timeoutId[id];
                        delete s_messages[id];
                        ws.close();
                        completer.completeError(new Exception('timeout'));
                    }
                })(s_id), self.timeout);
            }
            s_completers[s_id] = completer;
            s_timeoutId[s_id] = timeoutId;
            if (ready) {
                send(s_id, request);
            }
            else {
                s_messages[s_id] = request;
            }
            if (s_id < 0x7fffffff) {
                ++s_id;
            }
            else {
                s_id = 0;
            }
            return completer.future;
        }
        Object.defineProperties(this, {
            sendAndReceive: { value: sendAndReceive }
        });
        connect();<commit_msg>Removed unnecessary code<commit_after>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * WebSocketClient.js                                     *
 *                                                        *
 * hprose websocket client for HTML5.                     *
 *                                                        *
 * LastModified: May 17, 2015                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

(function (global) {
    'use strict';

    var Exception = global.hprose.Exception;
    var Client = global.hprose.Client;
    var BytesIO = global.hprose.BytesIO;
    var Completer = global.hprose.Completer;

    function noop(){}
    var s_id = 0;
    var s_completers = [];
    var s_timeoutId = [];
    var s_messages = [];

    global.hprose.WebSocketClient = function WebSocketClient(uri, functions) {
        if (this.constructor !== WebSocketClient) return new WebSocketClient(uri, functions);
        Client.call(this, uri, functions);
        this.timeout = 0;
        var self = this;
        var ready = false;
        var ws;
        function send(id, request) {
            var bytes = new BytesIO();
            bytes.writeByte((id >> 24) & 0xff);
            bytes.writeByte((id >> 16) & 0xff);
            bytes.writeByte((id >> 8) & 0xff);
            bytes.writeByte(id & 0xff);
            if (request.constructor === String) {
                bytes.writeString(request);
            }
            else {
                bytes.write(request);
            }
            var message = bytes.bytes;
            if (ArrayBuffer.isView) {
                ws.send(message);
            }
            else if (message.buffer.slice) {
                ws.send(message.buffer.slice(0, message.length));
            }
            else {
                ws.send(message.buffer);
            }
        }
        function onopen(e) {
            ready = true;
            if (s_messages.length > 0) {
                for (var id in s_messages) {
                    send(id, s_messages[id]);
                }
                s_messages = [];
            }
        }
        function onmessage(e) {
            var bytes = new BytesIO(e.data);
            var id = bytes.readByte() << 24;
            id = id | bytes.readByte() << 16;
            id = id | bytes.readByte() << 8;
            id = id | bytes.readByte();
            var timeoutId = s_timeoutId[id];
            var completer = s_completers[id];
            delete s_timeoutId[id];
            delete s_completers[id];
            if (timeoutId !== undefined) {
                global.clearTimeout(timeoutId);
                timeoutId = undefined;
            }
            completer.complete(bytes.read(bytes.length - 4));
        }
        function onclose(e) {
            connect();
        }
        function onerror(e) {
            self.onerror("WebSocket", new Exception(e.data));
        }
        function connect() {
            ready = false;
            ws = new WebSocket(self.uri);
            ws.binaryType = "arraybuffer";
            ws.onopen = onopen;
            ws.onmessage = onmessage;
            ws.onerror = onerror;
            ws.onclose = onclose;
        }
        function sendAndReceive(request) {
            var completer = new Completer();
            var timeoutId;
            if (self.timeout > 0) {
                timeoutId = global.setTimeout((function (id) {
                    return function() {
                        delete s_completers[id];
                        delete s_timeoutId[id];
                        delete s_messages[id];
                        ws.close();
                        completer.completeError(new Exception('timeout'));
                    };
                })(s_id), self.timeout);
            }
            s_completers[s_id] = completer;
            s_timeoutId[s_id] = timeoutId;
            if (ready) {
                send(s_id, request);
            }
            else {
                s_messages[s_id] = request;
            }
            if (s_id < 0x7fffffff) {
                ++s_id;
            }
            else {
                s_id = 0;
            }
            return completer.future;
        }
        Object.defineProperties(this, {
            sendAndReceive: { value: sendAndReceive }
        });
        connect();
{'fraction_non_alphanumeric': 0.14294270313435817, 'fraction_numerical': 0.005989219405070872, 'mean_word_length': 1.0894681960375392, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6307362', 'n_tokens_mistral': 2540, 'n_tokens_neox': 2363, 'n_words': 478}