You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
1010 B

/**
* 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;