"use strict";

// polyfill websockets in Node
if (typeof(WebSocket) == "undefined") global.WebSocket = require('ws');

function Transport(ip, port, logger) {
    var host = ip + ":" + port;
    this.ws = new WebSocket('ws://' + host + '/api');
    if (typeof(window) != "undefined") this.ws.binaryType = 'arraybuffer';
    this.logger = logger;
    
    this.ws.onopen = () => {
        this._isonopencalled = true;
        this.onopen();
    };

    this.ws.onclose = () => {
        this.close();
    };

    this.ws.onmessage = (event) => {
        if (!this._isopencalled) return;
        var msg = this.moo.parse(event.data);
        if (!msg) {
            this.close();
            return;
        }
        this.onmessage(msg);
    };
}

Transport.prototype.send = function(buf) {
    this.ws.send(buf, { binary: true, mask: true});
};

Transport.prototype.close = function() {
    if (this.ws) {
        this.ws.close();
        this.ws = undefined;
    }

    if (!this._onclosecalled && this._isopencalled) {
        this._onclosecalled = true;
        this.onclose();
    }

    if (this.moo) {
        this.moo.close();
        this.moo = undefined;
    }
};

Transport.prototype.onopen = function() { };
Transport.prototype.onclose = function() { };
Transport.prototype.onmessage = function() { };

exports = module.exports = Transport;

@@ -541,49 +541,8 @@
 %3E %7B%0A
-        if (!this._isopencalled) return;%0A
     
@@ -959,16 +959,18 @@
 his._iso
+no
 pencalle

fix typos