/** * The following code is modified based on * https://github.com/webpack/webpack-dev-server * * MIT Licensed * Author Tobias Koppers @sokra * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE */ import { log } from '../utils/log.js'; var WebSocketClient = /** @class */ (function () { function WebSocketClient(url) { this.client = new WebSocket(url); this.client.onerror = function (error) { log.error(error); }; } WebSocketClient.prototype.onOpen = function (fn) { this.client.onopen = fn; }; WebSocketClient.prototype.onClose = function (fn) { this.client.onclose = fn; }; // call fn with the message string as the first argument WebSocketClient.prototype.onMessage = function (fn) { this.client.onmessage = function (event) { fn(event.data); }; }; return WebSocketClient; }()); export default WebSocketClient;