"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapWebSocket = wrapWebSocket;
const _1 = require("../Class/$");
function wrapWebSocket(webSocket, system) {
    const socket = new (class Socket extends _1.$ {
        constructor() {
            super(...arguments);
            this.__ = ['CH'];
        }
        async send(data) {
            const { api: { window: { WebSocket }, }, } = this.__system;
            if (webSocket.readyState === WebSocket.CONNECTING) {
                throw new Error('cannot send on web socket while still connecting');
            }
            if (webSocket.readyState === WebSocket.CLOSED) {
                throw new Error('cannot send on closed web socket');
            }
            webSocket.send(data);
            return;
        }
    })(system);
    return socket;
}
//# sourceMappingURL=WebSocket.js.map