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KAAK,KAAK,QAAS,IAAI,MAAM,EAAM,aAClE,KAAK,OAAO,UAAY,GAChB,EAAM,gBAAgB,YACf,KAAK,KAAK,UAAW,SAAS,OAAO,KAAK,EAAM,OAElD,EAAM,gBAAgB,SAAS,OAC7B,KAAK,KAAK,UAAW,EAAM,MAE7B,MAAM,QAAQ,EAAM,WACrB,EAAM,gBAAgB,SAAS,QAC/B,EAAM,KAAK,SAAQ,IACf,KAAK,KAAK,UAAW,EAAK,KAK3B,KAAK,KAAK,UAAW,SAAS,OAAO,KAAK,EAAM,MAGnE,CACA,MAAO,UACI,KAAK,OACZ,KAAK,KAAK,QAAS,IAAI,MAAM,EAAM,YACvC,CACJ,CAIA,OAAA,GACI,OAAO,KAAK,MAChB,CAOA,KAAA,CAAM,EAAM,GACJ,KAAK,SAEL,KAAK,OAAO,QAAU,IAAM,KAAK,KAAK,SACtC,KAAK,OAAO,MAAM,EAAM,GAEhC,CAMA,IAAA,CAAK,GACD,IAAI,EAEA,KAAK,aAAe,eAAe,KACnC,KAAK,wBAAwB,KAAK,GAGX,QAAtB,EAAK,KAAK,cAA2B,IAAP,GAAyB,EAAG,KAAK,EAExE,EAEJ,QAAQ,UAAY,UACpB,QAAQ,gBAAkB,UAC1B,QAAQ,QAAU","file":"/npm/@gibme/websocket@20.0.3/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@gibme/websocket@20.0.3/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n// Copyright (c) 2024, Brandon Lehmann <brandonlehmann@gmail.com>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.WebSocketClient = exports.WebSocket = exports.Buffer = void 0;\nconst events_1 = require(\"events\");\nconst buffer_1 = require(\"buffer\");\nObject.defineProperty(exports, \"Buffer\", { enumerable: true, get: function () { return buffer_1.Buffer; } });\nconst timer_1 = __importDefault(require(\"@gibme/timer\"));\nconst isomorphic_ws_1 = __importDefault(require(\"isomorphic-ws\"));\nvar WebSocketState;\n(function (WebSocketState) {\n    WebSocketState[WebSocketState[\"CONNECTING\"] = 0] = \"CONNECTING\";\n    WebSocketState[WebSocketState[\"OPEN\"] = 1] = \"OPEN\";\n    WebSocketState[WebSocketState[\"CLOSING\"] = 2] = \"CLOSING\";\n    WebSocketState[WebSocketState[\"CLOSED\"] = 3] = \"CLOSED\";\n})(WebSocketState || (WebSocketState = {}));\nclass WebSocket extends events_1.EventEmitter {\n    /**\n     * Constructs a new instance of the class\n     * @param options\n     */\n    constructor(options) {\n        var _a;\n        var _b;\n        super();\n        this.options = options;\n        this.pre_ready_sent_messages = [];\n        (_a = (_b = this.options).binaryType) !== null && _a !== void 0 ? _a : (_b.binaryType = 'arraybuffer');\n    }\n    /**\n     * Returns the underlying WebSocket's binary type\n     */\n    get binaryType() {\n        var _a;\n        return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.binaryType) || 'arraybuffer';\n    }\n    /**\n     * Sets the underlying WebSocket's binary type\n     *\n     * @param value\n     */\n    set binaryType(value) {\n        if (this.socket && this.socket.binaryType) {\n            this.socket.binaryType = value;\n        }\n    }\n    /**\n     * Returns the amount of data buffered by the underlying WebSocket\n     */\n    get bufferedAmount() {\n        var _a;\n        return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.bufferedAmount) || 0;\n    }\n    /**\n     * Returns any extensions currently enabled in the underlying WebSocket\n     */\n    get extensions() {\n        var _a;\n        return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.extensions) || '';\n    }\n    /**\n     * Returns the underlying WebSocket protocol\n     */\n    get protocol() {\n        var _a;\n        return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.protocol) || '';\n    }\n    /**\n     * Returns the underlying WebSocket's ready state\n     */\n    get readyState() {\n        var _a;\n        return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) || 3;\n    }\n    /**\n     * Returns the underlying WebSocket's remote URL\n     */\n    get url() {\n        var _a;\n        return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.url) || this.options.url;\n    }\n    /** @ignore */\n    on(event, listener) {\n        return super.on(event, listener);\n    }\n    /** @ignore */\n    once(event, listener) {\n        return super.on(event, listener);\n    }\n    /** @ignore */\n    off(event, listener) {\n        return super.on(event, listener);\n    }\n    /**\n     * Attempts to connect the underlying WebSocket to the remote URL\n     *\n     * This method also allows us to re-use the class instance, so we do not have\n     * to recreate it if we need to 'reconnect' the WebSocket later\n     */\n    open() {\n        try {\n            this.socket = new isomorphic_ws_1.default(this.options.url, this.options.protocols);\n            this.binaryType = this.options.binaryType || 'arraybuffer';\n            this.timer = new timer_1.default(10, false);\n            this.timer.on('tick', () => {\n                var _a;\n                if (this.readyState === WebSocketState.OPEN) {\n                    (_a = this.timer) === null || _a === void 0 ? void 0 : _a.destroy();\n                    this.emit('ready');\n                    // if we tried to send messages before we were ready, send them now\n                    const messages = this.pre_ready_sent_messages.slice(0);\n                    this.pre_ready_sent_messages = [];\n                    for (const message of messages) {\n                        this.send(message);\n                    }\n                }\n            });\n            this.socket.onopen = () => {\n                var _a;\n                this.emit('open');\n                (_a = this.timer) === null || _a === void 0 ? void 0 : _a.start();\n                if (this.socket) {\n                    this.socket.onclose = () => {\n                        this.emit('close');\n                        if (this.options.autoReconnect) {\n                            this.open();\n                        }\n                    };\n                }\n            };\n            this.socket.onclose = () => {\n                if (this.options.autoReconnect) {\n                    this.open();\n                }\n            };\n            this.socket.onerror = error => this.emit('error', new Error(error.toString()));\n            this.socket.onmessage = event => {\n                if (event.data instanceof ArrayBuffer) {\n                    return this.emit('message', buffer_1.Buffer.from(event.data));\n                }\n                else if (event.data instanceof buffer_1.Buffer) {\n                    return this.emit('message', event.data);\n                }\n                else if (Array.isArray(event.data)) {\n                    if (event.data instanceof buffer_1.Buffer) {\n                        event.data.forEach(item => {\n                            this.emit('message', item);\n                        });\n                    }\n                }\n                else {\n                    return this.emit('message', buffer_1.Buffer.from(event.data));\n                }\n            };\n        }\n        catch (error) {\n            delete this.socket;\n            this.emit('error', new Error(error.toString()));\n        }\n    }\n    /**\n     * Alias for `open()`\n     */\n    connect() {\n        return this.open();\n    }\n    /**\n     * Closes the underlying WebSocket\n     *\n     * @param code\n     * @param reason\n     */\n    close(code, reason) {\n        if (this.socket) {\n            // stomp over the auto-reconnect if we told it to close\n            this.socket.onclose = () => this.emit('close');\n            this.socket.close(code, reason);\n        }\n    }\n    /**\n     * Sends the specified data via the underlying WebSocket\n     *\n     * @param data\n     */\n    send(data) {\n        var _a;\n        // if we try to send before we are ready, stack them up\n        if (this.readyState !== WebSocketState.OPEN) {\n            this.pre_ready_sent_messages.push(data);\n        }\n        else {\n            (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(data);\n        }\n    }\n}\nexports.WebSocket = WebSocket;\nexports.WebSocketClient = WebSocket;\nexports.default = WebSocket;\n"]}