Files
Hippy/packages/hippy-debug-server/webpack-dev-server/client-src/clients/WebSocketClient.js
T
chestershen ff9f763a45 feat(vue, react, debug-server, vue-loader, vue-css-loader): support HMR
- hippy-vue: ElementNode add repaintWithChildren API

- hippy-vue: support remove outdated style of HMR chunk

- hippy-vue-loader: support style hmr

- hippy-vue-css-loader: support remove outdated style of HMR chunk

- debug-server, vue-demo, react-demo, hippy-react: support hmr

- debug-server: add hippy-dev command
2022-01-05 01:03:18 +08:00

28 lines
524 B
JavaScript

import { log } from '../utils/log';
export default class WebSocketClient {
constructor(url) {
this.client = new global.WebSocket(url);
this.client.onerror = (error) => {
log.error(error);
};
}
onOpen(f) {
if (this.client) this.client.onopen = f;
}
onClose(f) {
if (this.client) this.client.onclose = f;
}
// call f with the message string as the first argument
onMessage(f) {
if (this.client) {
this.client.onmessage = (e) => {
f(e.data);
};
}
}
}