import { log } from "../utils/log.js";
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
class WebSocketClient {
    onOpen(fn) {
        this.client.onopen = fn;
    }
    onClose(fn) {
        this.client.onclose = fn;
    }
    onMessage(fn) {
        this.client.onmessage = (event)=>{
            fn(event.data);
        };
    }
    constructor(url){
        _define_property(this, "client", void 0);
        this.client = new WebSocket(url);
        this.client.onerror = (error)=>{
            log.error(error);
        };
    }
}
export default WebSocketClient;
