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.
 
 
 
 
 

34 lines
1.1 KiB

/**
* 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 SockJS from '../modules/sockjs-client/index.js';
import { log } from '../utils/log.js';
var SockJSClient = /** @class */ (function () {
function SockJSClient(url) {
// SockJS requires `http` and `https` protocols
this.sock = new SockJS(url.replace(/^ws:/i, 'http:').replace(/^wss:/i, 'https:'));
this.sock.onerror = function (error) {
log.error(error);
};
}
SockJSClient.prototype.onOpen = function (fn) {
this.sock.onopen = fn;
};
SockJSClient.prototype.onClose = function (fn) {
this.sock.onclose = fn;
};
// call f with the message string as the first argument
SockJSClient.prototype.onMessage = function (fn) {
this.sock.onmessage = function (err) {
fn(err.data);
};
};
return SockJSClient;
}());
export default SockJSClient;